From 61a8b98d32fe7a3295354ac6c1fc2787b14feec6 Mon Sep 17 00:00:00 2001 From: HoutarouOreki Date: Sun, 22 Jul 2018 20:27:50 +0200 Subject: [PATCH] Rewrite improvements --- osu.Game/Overlays/Changelog/ChangelogChart.cs | 14 +-- .../Overlays/Changelog/ChangelogContent.cs | 20 ++-- .../Overlays/Changelog/ChangelogStreams.cs | 98 ------------------- osu.Game/Overlays/ChangelogOverlay.cs | 10 +- 4 files changed, 24 insertions(+), 118 deletions(-) delete mode 100644 osu.Game/Overlays/Changelog/ChangelogStreams.cs diff --git a/osu.Game/Overlays/Changelog/ChangelogChart.cs b/osu.Game/Overlays/Changelog/ChangelogChart.cs index b8df166a19..91e2aa5e49 100644 --- a/osu.Game/Overlays/Changelog/ChangelogChart.cs +++ b/osu.Game/Overlays/Changelog/ChangelogChart.cs @@ -43,15 +43,9 @@ namespace osu.Game.Overlays.Changelog }; } - /// - /// Draw the graph with all builds - /// - public void ShowChart() => fetchAndShowChangelogChart(); - /// /// Draw the graph for a specific build /// - public void ShowChart(APIChangelog releaseStream) => fetchAndShowChangelogChart(releaseStream); private bool isEmpty(APIChangelogChart changelogChart) { @@ -81,14 +75,14 @@ namespace osu.Game.Overlays.Changelog this.api = api; } - private void fetchAndShowChangelogChart(APIChangelog build) + public void ShowUpdateStream(string updateStream) { - var req = new GetChangelogChartRequest(build.UpdateStream.Name); - req.Success += res => showChart(res, build.UpdateStream.Name); + var req = new GetChangelogChartRequest(updateStream); + req.Success += res => showChart(res, updateStream); api.Queue(req); } - private void fetchAndShowChangelogChart() + public void ShowAllUpdateStreams() { var req = new GetChangelogChartRequest(); req.Success += res => showChart(res); diff --git a/osu.Game/Overlays/Changelog/ChangelogContent.cs b/osu.Game/Overlays/Changelog/ChangelogContent.cs index d06ef32420..5eb19119ec 100644 --- a/osu.Game/Overlays/Changelog/ChangelogContent.cs +++ b/osu.Game/Overlays/Changelog/ChangelogContent.cs @@ -10,6 +10,7 @@ using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; using System; +using System.Collections.Generic; namespace osu.Game.Overlays.Changelog { @@ -30,7 +31,7 @@ namespace osu.Game.Overlays.Changelog Padding = new MarginPadding{ Bottom = 100, }; } - private void add(APIChangelog[] changelog) + public void ShowListing(List changelog) { DateTime currentDate = new DateTime(); @@ -52,7 +53,7 @@ namespace osu.Game.Overlays.Changelog } // watch out for this? Add(changelogContentGroup = new ChangelogContentGroup(build, true)); - changelogContentGroup.BuildSelected += OnBuildSelected; + changelogContentGroup.BuildSelected += onBuildSelected; changelogContentGroup.GenerateText(build.ChangelogEntries); currentDate = build.CreatedAt.Date; } @@ -66,20 +67,21 @@ namespace osu.Game.Overlays.Changelog Margin = new MarginPadding { Top = 30, }, }); Add(changelogContentGroup = new ChangelogContentGroup(build, false)); - changelogContentGroup.BuildSelected += OnBuildSelected; + changelogContentGroup.BuildSelected += onBuildSelected; changelogContentGroup.GenerateText(build.ChangelogEntries); } } } - private void OnBuildSelected(string updateStream, string version, EventArgs args) - { - throw new NotImplementedException(); - } - - private void add(APIChangelog changelogBuild) + public void ShowBuild(APIChangelog changelogBuild) { Child = changelogContentGroup = new ChangelogContentGroup(changelogBuild); } + + protected virtual void onBuildSelected(string updateStream, string version, EventArgs args) + { + if (BuildSelected != null) + BuildSelected(updateStream, version, EventArgs.Empty); + } } } diff --git a/osu.Game/Overlays/Changelog/ChangelogStreams.cs b/osu.Game/Overlays/Changelog/ChangelogStreams.cs deleted file mode 100644 index 1e6e9e1e51..0000000000 --- a/osu.Game/Overlays/Changelog/ChangelogStreams.cs +++ /dev/null @@ -1,98 +0,0 @@ -// 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.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Input; -using osu.Game.Online.API.Requests.Responses; -using System; - -namespace osu.Game.Overlays.Changelog -{ - public class ChangelogStreams : Container - { - private const float container_height = 106.5f; - private const float padding_y = 20; - private const float padding_x = 85; - public Action OnSelection; - - public APIChangelog SelectedRelease; - // not using SelectedRelease as a Bindable and then using .OnValueChange instead of OnSelection - // because it doesn't "refresh" the selection if the same stream is chosen - - public readonly FillFlowContainer BadgesContainer; - - public ChangelogStreams() - { - RelativeSizeAxes = Axes.X; - AutoSizeAxes = Axes.Y; - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = new Color4(32, 24, 35, 255), - }, - BadgesContainer = new FillFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Padding = new MarginPadding - { - Top = padding_y, - Bottom = padding_y, - Left = padding_x, - Right = padding_x, - }, - }, - }; - // ok, so this is probably not the best. - // how else can this be done? - BadgesContainer.OnUpdate = d => - { - foreach (StreamBadge streamBadge in BadgesContainer.Children) - { - streamBadge.OnActivation = () => - { - SelectedRelease = streamBadge.ChangelogEntry; - foreach (StreamBadge item in BadgesContainer.Children) - if (item.ChangelogEntry.Id != streamBadge.ChangelogEntry.Id) - item.Deactivate(); - OnSelection?.Invoke(); - }; - } - }; - } - - protected override bool OnHover(InputState state) - { - foreach (StreamBadge streamBadge in BadgesContainer.Children) - { - if (SelectedRelease != null) - { - if (SelectedRelease.UpdateStream.Id != streamBadge.ChangelogEntry.UpdateStream.Id) - streamBadge.Deactivate(); - else - streamBadge.EnableDim(); - } - else - streamBadge.Deactivate(); - } - return base.OnHover(state); - } - - protected override void OnHoverLost(InputState state) - { - foreach (StreamBadge streamBadge in BadgesContainer.Children) - { - if (SelectedRelease == null) - streamBadge.Activate(true); - else if (streamBadge.ChangelogEntry.UpdateStream.Id == SelectedRelease.UpdateStream.Id) - streamBadge.DisableDim(); - } - base.OnHoverLost(state); - } - } -} diff --git a/osu.Game/Overlays/ChangelogOverlay.cs b/osu.Game/Overlays/ChangelogOverlay.cs index 4359741354..2ae5bbdd78 100644 --- a/osu.Game/Overlays/ChangelogOverlay.cs +++ b/osu.Game/Overlays/ChangelogOverlay.cs @@ -14,6 +14,7 @@ using osu.Game.Input.Bindings; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Overlays.Changelog; +using System; namespace osu.Game.Overlays { @@ -78,6 +79,8 @@ namespace osu.Game.Overlays }, }, }; + + badges.Selected += onBuildSelected; // content.ShowListing(); // if (!Streams.IsHovered) // foreach (StreamBadge item in Streams.BadgesContainer.Children) @@ -117,6 +120,11 @@ namespace osu.Game.Overlays FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out); } + private void onBuildSelected(string updateStream, string version, EventArgs e) + { + FetchAndShowBuild(updateStream, version); + } + [BackgroundDependencyLoader] private void load(APIAccess api) { @@ -144,7 +152,7 @@ namespace osu.Game.Overlays { var req = new GetChangelogBuildRequest(updateStream, version); header.ShowBuild(updateStream, version); - badges.SelectBadge(updateStream); + badges.SelectUpdateStream(updateStream); chart.ShowUpdateStream(updateStream); req.Success += content.ShowBuild; api.Queue(req);