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>.
// 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;
}
}
}

View File

@ -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()
{
}
}
}