From 219c590b8ab11b1a3fd4c2b81c9aedb8657ff121 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 13 May 2019 16:24:32 +0900 Subject: [PATCH] Initial pass to make work with real API --- .../API/Requests/GetChangelogBuildRequest.cs | 1 - .../API/Requests/GetChangelogChartRequest.cs | 2 -- .../GetChangelogLatestBuildsRequest.cs | 7 +------ .../Online/API/Requests/GetChangelogRequest.cs | 3 +-- .../Requests/Responses/APIChangelogBuild.cs | 9 ++++++--- .../Requests/Responses/APIChangelogIndex.cs | 14 ++++++++++++++ osu.Game/Overlays/Changelog/ChangelogBadges.cs | 16 ++++++++-------- .../Overlays/Changelog/ChangelogContent.cs | 3 ++- osu.Game/Overlays/Changelog/StreamBadge.cs | 18 ++++++++++-------- osu.Game/Overlays/ChangelogOverlay.cs | 4 ++-- 10 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 osu.Game/Online/API/Requests/Responses/APIChangelogIndex.cs diff --git a/osu.Game/Online/API/Requests/GetChangelogBuildRequest.cs b/osu.Game/Online/API/Requests/GetChangelogBuildRequest.cs index 6c32abee42..baa15c70c4 100644 --- a/osu.Game/Online/API/Requests/GetChangelogBuildRequest.cs +++ b/osu.Game/Online/API/Requests/GetChangelogBuildRequest.cs @@ -17,6 +17,5 @@ namespace osu.Game.Online.API.Requests } protected override string Target => $@"changelog/{name}/{version}"; - protected override string Uri => $@"https://houtarouoreki.github.io/fake-api/{Target}"; // for testing } } diff --git a/osu.Game/Online/API/Requests/GetChangelogChartRequest.cs b/osu.Game/Online/API/Requests/GetChangelogChartRequest.cs index cf5dc5a65a..66e7d198c2 100644 --- a/osu.Game/Online/API/Requests/GetChangelogChartRequest.cs +++ b/osu.Game/Online/API/Requests/GetChangelogChartRequest.cs @@ -21,7 +21,5 @@ namespace osu.Game.Online.API.Requests protected override string Target => $@"changelog/{(!string.IsNullOrEmpty(updateStream) ? updateStream + "/" : "")}chart-config"; - - protected override string Uri => $@"https://houtarouoreki.github.io/fake-api/{Target}"; // for testing } } diff --git a/osu.Game/Online/API/Requests/GetChangelogLatestBuildsRequest.cs b/osu.Game/Online/API/Requests/GetChangelogLatestBuildsRequest.cs index 087d4bb49c..dd50701e39 100644 --- a/osu.Game/Online/API/Requests/GetChangelogLatestBuildsRequest.cs +++ b/osu.Game/Online/API/Requests/GetChangelogLatestBuildsRequest.cs @@ -1,14 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Game.Online.API.Requests.Responses; -using System.Collections.Generic; - namespace osu.Game.Online.API.Requests { - public class GetChangelogLatestBuildsRequest : APIRequest> + public class GetChangelogLatestBuildsRequest : GetChangelogRequest { - protected override string Target => @"changelog/latest-builds"; - protected override string Uri => $@"https://houtarouoreki.github.io/fake-api/{Target}"; // for testing } } diff --git a/osu.Game/Online/API/Requests/GetChangelogRequest.cs b/osu.Game/Online/API/Requests/GetChangelogRequest.cs index 483182e720..97799ff66a 100644 --- a/osu.Game/Online/API/Requests/GetChangelogRequest.cs +++ b/osu.Game/Online/API/Requests/GetChangelogRequest.cs @@ -5,9 +5,8 @@ using osu.Game.Online.API.Requests.Responses; namespace osu.Game.Online.API.Requests { - public class GetChangelogRequest : APIRequest + public class GetChangelogRequest : APIRequest { protected override string Target => @"changelog"; - protected override string Uri => $@"https://houtarouoreki.github.io/fake-api/{Target}/index"; // for testing } } diff --git a/osu.Game/Online/API/Requests/Responses/APIChangelogBuild.cs b/osu.Game/Online/API/Requests/Responses/APIChangelogBuild.cs index 3ae992c22d..64b62e1f73 100644 --- a/osu.Game/Online/API/Requests/Responses/APIChangelogBuild.cs +++ b/osu.Game/Online/API/Requests/Responses/APIChangelogBuild.cs @@ -21,9 +21,6 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty("users")] public long Users { get; set; } - [JsonProperty("is_featured")] - public bool IsFeatured { get; set; } - [JsonProperty("created_at")] public DateTimeOffset CreatedAt { get; set; } @@ -114,7 +111,13 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("is_featured")] + public bool IsFeatured { get; set; } + [JsonProperty("display_name")] public string DisplayName { get; set; } + + [JsonProperty("latest_build")] + public APIChangelogBuild LatestBuild { get; set; } } } diff --git a/osu.Game/Online/API/Requests/Responses/APIChangelogIndex.cs b/osu.Game/Online/API/Requests/Responses/APIChangelogIndex.cs new file mode 100644 index 0000000000..957694b887 --- /dev/null +++ b/osu.Game/Online/API/Requests/Responses/APIChangelogIndex.cs @@ -0,0 +1,14 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; + +namespace osu.Game.Online.API.Requests.Responses +{ + public class APIChangelogIndex + { + public List Builds; + + public List Streams; + } +} diff --git a/osu.Game/Overlays/Changelog/ChangelogBadges.cs b/osu.Game/Overlays/Changelog/ChangelogBadges.cs index f5a7737896..cf14ddbb01 100644 --- a/osu.Game/Overlays/Changelog/ChangelogBadges.cs +++ b/osu.Game/Overlays/Changelog/ChangelogBadges.cs @@ -45,9 +45,9 @@ namespace osu.Game.Overlays.Changelog }; } - public void Populate(List latestBuilds) + public void Populate(List streams) { - foreach (APIChangelogBuild updateStream in latestBuilds) + foreach (UpdateStream updateStream in streams) { var streamBadge = new StreamBadge(updateStream); streamBadge.Selected += onBadgeSelected; @@ -75,9 +75,9 @@ namespace osu.Game.Overlays.Changelog { foreach (StreamBadge streamBadge in badgesContainer) { - if (streamBadge.LatestBuild.UpdateStream.Name == updateStream) + if (streamBadge.Stream.Name == updateStream) { - selectedStreamId = streamBadge.LatestBuild.UpdateStream.Id; + selectedStreamId = streamBadge.Stream.Id; streamBadge.Activate(); } else @@ -87,13 +87,13 @@ namespace osu.Game.Overlays.Changelog private void onBadgeSelected(StreamBadge source, EventArgs args) { - selectedStreamId = source.LatestBuild.UpdateStream.Id; + selectedStreamId = source.Stream.Id; OnSelected(source); } protected virtual void OnSelected(StreamBadge source) { - Selected?.Invoke(source.LatestBuild, EventArgs.Empty); + Selected?.Invoke(source.Stream.LatestBuild, EventArgs.Empty); } protected override bool OnHover(HoverEvent e) @@ -102,7 +102,7 @@ namespace osu.Game.Overlays.Changelog { if (selectedStreamId >= 0) { - if (selectedStreamId != streamBadge.LatestBuild.UpdateStream.Id) + if (selectedStreamId != streamBadge.Stream.Id) streamBadge.Deactivate(); else streamBadge.EnableDim(); @@ -120,7 +120,7 @@ namespace osu.Game.Overlays.Changelog { if (selectedStreamId < 0) streamBadge.Activate(); - else if (streamBadge.LatestBuild.UpdateStream.Id == selectedStreamId) + else if (streamBadge.Stream.Id == selectedStreamId) streamBadge.DisableDim(); } diff --git a/osu.Game/Overlays/Changelog/ChangelogContent.cs b/osu.Game/Overlays/Changelog/ChangelogContent.cs index 1f1bfae40a..e71769595f 100644 --- a/osu.Game/Overlays/Changelog/ChangelogContent.cs +++ b/osu.Game/Overlays/Changelog/ChangelogContent.cs @@ -6,6 +6,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Game.Online.API.Requests.Responses; using System; +using System.Collections.Generic; using osuTK.Graphics; namespace osu.Game.Overlays.Changelog @@ -26,7 +27,7 @@ namespace osu.Game.Overlays.Changelog Padding = new MarginPadding { Bottom = 100 }; } - public void ShowListing(APIChangelogBuild[] changelog) + public void ShowListing(List changelog) { DateTime currentDate = new DateTime(); Clear(); diff --git a/osu.Game/Overlays/Changelog/StreamBadge.cs b/osu.Game/Overlays/Changelog/StreamBadge.cs index c9ed04168c..424c344e91 100644 --- a/osu.Game/Overlays/Changelog/StreamBadge.cs +++ b/osu.Game/Overlays/Changelog/StreamBadge.cs @@ -32,14 +32,16 @@ namespace osu.Game.Overlays.Changelog private SampleChannel sampleClick; private SampleChannel sampleHover; - public readonly APIChangelogBuild LatestBuild; + public readonly UpdateStream Stream; + private readonly FillFlowContainer text; - public StreamBadge(APIChangelogBuild latestBuild) + public StreamBadge(UpdateStream stream) { - LatestBuild = latestBuild; + Stream = stream; + Height = badge_height; - Width = LatestBuild.IsFeatured ? badge_width * 2 : badge_width; + Width = stream.IsFeatured ? badge_width * 2 : badge_width; Padding = new MarginPadding(5); isActivated = true; Children = new Drawable[] @@ -53,18 +55,18 @@ namespace osu.Game.Overlays.Changelog { new SpriteText { - Text = LatestBuild.UpdateStream.DisplayName, + Text = stream.DisplayName, Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14), // web: 12, Margin = new MarginPadding { Top = 6 }, }, new SpriteText { - Text = LatestBuild.DisplayVersion, + Text = stream.LatestBuild.DisplayVersion, Font = OsuFont.GetFont(weight: FontWeight.Light, size: 20), // web: 16, }, new SpriteText { - Text = LatestBuild.Users > 0 ? $"{LatestBuild.Users:N0} users online" : null, + Text = stream.LatestBuild.Users > 0 ? $"{stream.LatestBuild.Users:N0} users online" : null, Font = OsuFont.GetFont(weight: FontWeight.Regular, size: 12), // web: 10, Colour = new Color4(203, 164, 218, 255), }, @@ -73,7 +75,7 @@ namespace osu.Game.Overlays.Changelog lineBadge = new LineBadge(false) { Anchor = Anchor.TopCentre, - Colour = StreamColour.FromStreamName(LatestBuild.UpdateStream.Name), + Colour = StreamColour.FromStreamName(stream.Name), UncollapsedSize = 4, CollapsedSize = 2, }, diff --git a/osu.Game/Overlays/ChangelogOverlay.cs b/osu.Game/Overlays/ChangelogOverlay.cs index 8f77862c99..aa32b8dae4 100644 --- a/osu.Game/Overlays/ChangelogOverlay.cs +++ b/osu.Game/Overlays/ChangelogOverlay.cs @@ -111,7 +111,7 @@ namespace osu.Game.Overlays protected override void LoadComplete() { var req = new GetChangelogLatestBuildsRequest(); - req.Success += badges.Populate; + req.Success += res => badges.Populate(res.Streams); api.Queue(req); fetchListing(); base.LoadComplete(); @@ -168,7 +168,7 @@ namespace osu.Game.Overlays isAtListing = true; var req = new GetChangelogRequest(); badges.SelectNone(); - req.Success += listing.ShowListing; + req.Success += res => listing.ShowListing(res.Builds); api.Queue(req); }