Use a protected Downloaded bindable instead of abstract methods.

This commit is contained in:
DrabWeb 2018-06-04 06:47:39 -03:00
parent 7eeba2cf9a
commit 416384956d
2 changed files with 17 additions and 38 deletions

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
@ -16,29 +15,15 @@ namespace osu.Game.Graphics.UserInterface
{ {
private readonly BeatmapSetInfo set; private readonly BeatmapSetInfo set;
private readonly bool noVideo; private readonly bool noVideo;
private readonly BindableBool downloaded = new BindableBool();
private BeatmapManager beatmaps; private BeatmapManager beatmaps;
private Action action; protected readonly BindableBool Downloaded = new BindableBool();
public Action Action
{
get => action;
set => action = value;
}
protected BeatmapSetDownloadButton(BeatmapSetInfo set, bool noVideo = false) protected BeatmapSetDownloadButton(BeatmapSetInfo set, bool noVideo = false)
{ {
this.set = set; this.set = set;
this.noVideo = noVideo; this.noVideo = noVideo;
downloaded.ValueChanged += e =>
{
if (e)
Disable();
else
Enable();
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -49,8 +34,8 @@ namespace osu.Game.Graphics.UserInterface
beatmaps.ItemAdded += setAdded; beatmaps.ItemAdded += setAdded;
beatmaps.ItemRemoved += setRemoved; beatmaps.ItemRemoved += setRemoved;
// initial downloaded value // initial value
downloaded.Value = beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending).Count() != 0; Downloaded.Value = beatmaps.QueryBeatmapSets(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending).Count() != 0;
Action = () => Action = () =>
{ {
@ -66,7 +51,7 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnClick(InputState state) protected override bool OnClick(InputState state)
{ {
if (!downloaded.Value) if (Enabled.Value && !Downloaded.Value)
Action?.Invoke(); Action?.Invoke();
return true; return true;
} }
@ -82,20 +67,20 @@ namespace osu.Game.Graphics.UserInterface
} }
} }
protected abstract void Enable(); protected virtual void AlreadyDownloading()
protected abstract void Disable(); {
protected abstract void AlreadyDownloading(); }
private void setAdded(BeatmapSetInfo s) private void setAdded(BeatmapSetInfo s)
{ {
if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID) if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID)
downloaded.Value = true; Downloaded.Value = true;
} }
private void setRemoved(BeatmapSetInfo s) private void setRemoved(BeatmapSetInfo s)
{ {
if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID) if (s.OnlineBeatmapSetID == set.OnlineBeatmapSetID)
downloaded.Value = false; Downloaded.Value = false;
} }
} }
} }

View File

@ -26,6 +26,14 @@ namespace osu.Game.Overlays.Direct
Icon = FontAwesome.fa_osu_chevron_down_o, 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) protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
@ -50,19 +58,5 @@ namespace osu.Game.Overlays.Direct
{ {
icon.ScaleTo(1f, 500, Easing.OutElastic); icon.ScaleTo(1f, 500, Easing.OutElastic);
} }
protected override void Enable()
{
this.FadeIn(200);
}
protected override void Disable()
{
this.FadeOut(200);
}
protected override void AlreadyDownloading()
{
}
} }
} }