From 416384956d1ac646b7c1fe48733652439f98abba Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Mon, 4 Jun 2018 06:47:39 -0300 Subject: [PATCH] Use a protected Downloaded bindable instead of abstract methods. --- .../UserInterface/BeatmapSetDownloadButton.cs | 33 +++++-------------- osu.Game/Overlays/Direct/DownloadButton.cs | 22 +++++-------- 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/BeatmapSetDownloadButton.cs b/osu.Game/Graphics/UserInterface/BeatmapSetDownloadButton.cs index 39bbc8216a..d55a133d18 100644 --- a/osu.Game/Graphics/UserInterface/BeatmapSetDownloadButton.cs +++ b/osu.Game/Graphics/UserInterface/BeatmapSetDownloadButton.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Configuration; @@ -16,29 +15,15 @@ public abstract class BeatmapSetDownloadButton : OsuClickableContainer { private readonly BeatmapSetInfo set; private readonly bool noVideo; - private readonly BindableBool downloaded = new BindableBool(); private BeatmapManager beatmaps; - private Action action; - public Action Action - { - get => action; - set => action = value; - } + protected readonly BindableBool Downloaded = new BindableBool(); protected BeatmapSetDownloadButton(BeatmapSetInfo set, bool noVideo = false) { this.set = set; this.noVideo = noVideo; - - downloaded.ValueChanged += e => - { - if (e) - Disable(); - else - Enable(); - }; } [BackgroundDependencyLoader] @@ -49,8 +34,8 @@ private void load(BeatmapManager beatmaps, APIAccess api) beatmaps.ItemAdded += setAdded; beatmaps.ItemRemoved += setRemoved; - // initial downloaded value - downloaded.Value = beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending).Count() != 0; + // initial value + Downloaded.Value = beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending).Count() != 0; Action = () => { @@ -66,7 +51,7 @@ private void load(BeatmapManager beatmaps, APIAccess api) protected override bool OnClick(InputState state) { - if (!downloaded.Value) + if (Enabled.Value && !Downloaded.Value) Action?.Invoke(); return true; } @@ -82,20 +67,20 @@ protected override void Dispose(bool isDisposing) } } - protected abstract void Enable(); - protected abstract void Disable(); - protected abstract void AlreadyDownloading(); + protected virtual void AlreadyDownloading() + { + } private void setAdded(BeatmapSetInfo s) { if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID) - downloaded.Value = true; + Downloaded.Value = true; } private void setRemoved(BeatmapSetInfo s) { if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID) - downloaded.Value = false; + Downloaded.Value = false; } } } diff --git a/osu.Game/Overlays/Direct/DownloadButton.cs b/osu.Game/Overlays/Direct/DownloadButton.cs index a6d7a4215d..1b072a4101 100644 --- a/osu.Game/Overlays/Direct/DownloadButton.cs +++ b/osu.Game/Overlays/Direct/DownloadButton.cs @@ -26,6 +26,14 @@ public DownloadButton(BeatmapSetInfo set, bool noVideo = false) : base(set, noVi Icon = FontAwesome.fa_osu_chevron_down_o, }, }; + + Downloaded.ValueChanged += e => + { + if (e) + this.FadeOut(200); + else + this.FadeIn(200); + }; } protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) @@ -50,19 +58,5 @@ protected override void OnHoverLost(InputState state) { icon.ScaleTo(1f, 500, Easing.OutElastic); } - - protected override void Enable() - { - this.FadeIn(200); - } - - protected override void Disable() - { - this.FadeOut(200); - } - - protected override void AlreadyDownloading() - { - } } }