Refactor BeatmapSetOverlay to use chained bindables instead of accessors to distribute changes

This commit is contained in:
Jamie Taylor
2019-02-28 18:44:40 +09:00
parent bfe3d5708d
commit b7f7174055
2 changed files with 19 additions and 41 deletions

View File

@ -3,6 +3,7 @@
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -36,19 +37,7 @@ namespace osu.Game.Overlays
private readonly ScrollContainer scroll;
private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get => beatmapSet;
set
{
if (value == beatmapSet)
return;
header.BeatmapSet.Value = info.BeatmapSet = beatmapSet = value;
}
}
private readonly Bindable<BeatmapSetInfo> beatmapSet = new Bindable<BeatmapSetInfo>();
// receive input outside our bounds so we can trigger a close event on ourselves.
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
@ -101,6 +90,9 @@ namespace osu.Game.Overlays
},
};
header.BeatmapSet.BindTo(beatmapSet);
info.BeatmapSet.BindTo(beatmapSet);
header.Picker.Beatmap.ValueChanged += b =>
{
info.Beatmap = b.NewValue;
@ -124,7 +116,7 @@ namespace osu.Game.Overlays
protected override void PopOut()
{
base.PopOut();
FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out).OnComplete(_ => BeatmapSet = null);
FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out).OnComplete(_ => beatmapSet.Value = null);
}
protected override bool OnClick(ClickEvent e)
@ -135,11 +127,11 @@ namespace osu.Game.Overlays
public void FetchAndShowBeatmap(int beatmapId)
{
BeatmapSet = null;
beatmapSet.Value = null;
var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);
req.Success += res =>
{
BeatmapSet = res.ToBeatmapSet(rulesets);
beatmapSet.Value = res.ToBeatmapSet(rulesets);
header.Picker.Beatmap.Value = header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId);
};
api.Queue(req);
@ -148,16 +140,16 @@ namespace osu.Game.Overlays
public void FetchAndShowBeatmapSet(int beatmapSetId)
{
BeatmapSet = null;
beatmapSet.Value = null;
var req = new GetBeatmapSetRequest(beatmapSetId);
req.Success += res => BeatmapSet = res.ToBeatmapSet(rulesets);
req.Success += res => beatmapSet.Value = res.ToBeatmapSet(rulesets);
api.Queue(req);
Show();
}
public void ShowBeatmapSet(BeatmapSetInfo set)
{
BeatmapSet = set;
beatmapSet.Value = set;
Show();
scroll.ScrollTo(0);
}