From 80808bddbf049e66e5b38c7e1c899a935d5b857c Mon Sep 17 00:00:00 2001 From: HoutarouOreki Date: Sun, 22 Jul 2018 05:28:43 +0200 Subject: [PATCH] Add changelog listing --- .../API/Requests/GetChangelogRequest.cs | 2 +- .../Overlays/Changelog/ChangelogContent.cs | 66 ++++++++++++++++-- .../Changelog/ChangelogContentGroup.cs | 69 +++++++++++++++++-- osu.Game/Overlays/ChangelogOverlay.cs | 3 +- 4 files changed, 124 insertions(+), 16 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetChangelogRequest.cs b/osu.Game/Online/API/Requests/GetChangelogRequest.cs index 2f2e0ffe67..ec8536c607 100644 --- a/osu.Game/Online/API/Requests/GetChangelogRequest.cs +++ b/osu.Game/Online/API/Requests/GetChangelogRequest.cs @@ -8,6 +8,6 @@ namespace osu.Game.Online.API.Requests public class GetChangelogRequest : APIRequest { protected override string Target => @"changelog"; - protected override string Uri => $@"https://houtarouoreki.github.io/fake-api/{Target}"; // for testing + protected override string Uri => $@"https://houtarouoreki.github.io/fake-api/{Target}/index"; // for testing } } diff --git a/osu.Game/Overlays/Changelog/ChangelogContent.cs b/osu.Game/Overlays/Changelog/ChangelogContent.cs index 363b251383..a4797d6f7c 100644 --- a/osu.Game/Overlays/Changelog/ChangelogContent.cs +++ b/osu.Game/Overlays/Changelog/ChangelogContent.cs @@ -1,9 +1,11 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using OpenTK.Graphics; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; @@ -11,7 +13,7 @@ using System; namespace osu.Game.Overlays.Changelog { - public class ChangelogContent : FillFlowContainer + public class ChangelogContent : FillFlowContainer { public APIChangelog CurrentBuild { get; private set; } public Action OnBuildChanged; @@ -23,11 +25,52 @@ namespace osu.Game.Overlays.Changelog RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; Direction = FillDirection.Vertical; - Padding = new MarginPadding + Padding = new MarginPadding{ Bottom = 100, }; + } + + private void add(APIChangelog[] changelog) + { + DateTime currentDate = new DateTime(); + + Clear(); + + foreach (APIChangelog build in changelog) { - Horizontal = 70, - Bottom = 100, - }; + if (build.CreatedAt.Date != currentDate) + { + if (Children.Count != 0) + { + Add(new Box + { + RelativeSizeAxes = Axes.X, + Height = 2, + Colour = new Color4(17, 17, 17, 255), + Margin = new MarginPadding { Top = 30, }, + }); + } + Add(changelogContentGroup = new ChangelogContentGroup(build, true) + { + BuildRequested = () => showBuild(build), + }); + changelogContentGroup.GenerateText(build.ChangelogEntries); + currentDate = build.CreatedAt.Date; + } + else + { + changelogContentGroup.Add(new Box + { + RelativeSizeAxes = Axes.X, + Height = 1, + Colour = new Color4(32, 24, 35, 255), + Margin = new MarginPadding { Top = 30, }, + }); + Add(changelogContentGroup = new ChangelogContentGroup(build, false) + { + BuildRequested = () => ShowBuild(build), + }); + changelogContentGroup.GenerateText(build.ChangelogEntries); + } + } } private void add(APIChangelog changelogBuild) @@ -41,10 +84,12 @@ namespace osu.Game.Overlays.Changelog public void ShowBuild(APIChangelog changelog) { + fetchAndShowChangelogBuild(changelog); CurrentBuild = changelog; - fetchChangelogBuild(changelog); } + public void ShowListing() => fetchAndShowChangelog(); + private void showBuild(APIChangelog changelog) { ShowBuild(changelog); @@ -75,7 +120,14 @@ namespace osu.Game.Overlays.Changelog this.api = api; } - private void fetchChangelogBuild(APIChangelog build) + private void fetchAndShowChangelog() + { + var req = new GetChangelogRequest(); + req.Success += res => add(res); + api.Queue(req); + } + + private void fetchAndShowChangelogBuild(APIChangelog build) { var req = new GetChangelogBuildRequest(build.UpdateStream.Name, build.Version); req.Success += res => diff --git a/osu.Game/Overlays/Changelog/ChangelogContentGroup.cs b/osu.Game/Overlays/Changelog/ChangelogContentGroup.cs index 4a6eb27cc7..0fc4c31bbe 100644 --- a/osu.Game/Overlays/Changelog/ChangelogContentGroup.cs +++ b/osu.Game/Overlays/Changelog/ChangelogContentGroup.cs @@ -21,7 +21,7 @@ namespace osu.Game.Overlays.Changelog private readonly SortedDictionary> categories = new SortedDictionary>(); - public Action NextRequested, PreviousRequested; + public Action NextRequested, PreviousRequested, BuildRequested; public readonly FillFlowContainer ChangelogEntries; public ChangelogContentGroup(APIChangelog build) @@ -29,6 +29,7 @@ namespace osu.Game.Overlays.Changelog RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; Direction = FillDirection.Vertical; + Padding = new MarginPadding { Horizontal = 70 }; Children = new Drawable[] { // build version, arrows @@ -111,6 +112,67 @@ namespace osu.Game.Overlays.Changelog }; } + public ChangelogContentGroup(APIChangelog build, bool newDate = false) + { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + Direction = FillDirection.Vertical; + Padding = new MarginPadding { Horizontal = 70 }; + Children = new Drawable[] + { + new SpriteText + { + // do we need .ToUniversalTime() here? + // also, this should be a temporary solution to weekdays in >localized< date strings + Text = build.CreatedAt.Date.ToLongDateString().Replace(build.CreatedAt.ToString("dddd") + ", ", ""), + TextSize = 28, // web: 24, + Colour = OsuColour.FromHex(@"FD5"), + Font = @"Exo2.0-Light", + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Margin = new MarginPadding{ Top = 20, }, + Alpha = newDate ? 1 : 0, + }, + new FillFlowContainer + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Margin = new MarginPadding{ Top = 20, }, + Spacing = new Vector2(5), + Children = new Drawable[] + { + new SpriteText + { + Text = build.UpdateStream.DisplayName, + TextSize = 20, // web: 18, + Font = @"Exo2.0-Medium", + }, + new SpriteText + { + Text = build.DisplayVersion, + TextSize = 20, // web: 18, + Font = @"Exo2.0-Light", + Colour = StreamColour.FromStreamName(build.UpdateStream.Name), + }, + new ClickableText + { + Text = " ok ", + TextSize = 20, + Action = BuildRequested, + }, + } + }, + ChangelogEntries = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + }, + }; + } + public void UpdateChevronTooltips(string previousVersion, string nextVersion) { if (!string.IsNullOrEmpty(previousVersion)) @@ -138,10 +200,6 @@ namespace osu.Game.Overlays.Changelog foreach (KeyValuePair> category in categories) { - // textflowcontainer is unusable for formatting text - // this has to be a placeholder before we get a - // proper markdown/html formatting.. - // it can't handle overflowing properly ChangelogEntries.Add(new SpriteText { Text = category.Key, @@ -183,6 +241,5 @@ namespace osu.Game.Overlays.Changelog } } } - //public ChangelogContentGroup() { } // for listing } } diff --git a/osu.Game/Overlays/ChangelogOverlay.cs b/osu.Game/Overlays/ChangelogOverlay.cs index cfa669534d..0a2c5e9b6f 100644 --- a/osu.Game/Overlays/ChangelogOverlay.cs +++ b/osu.Game/Overlays/ChangelogOverlay.cs @@ -93,8 +93,7 @@ namespace osu.Game.Overlays header.OnListingActivated += () => { Streams.SelectedRelease = null; - content.Clear(); - // should add listing to content here + content.ShowListing(); if (!Streams.IsHovered) foreach (StreamBadge item in Streams.BadgesContainer.Children) item.Activate(true);