Merge pull request #4365 from nekodex/beatmapsetoverlay-bindables

Refactor BeatmapSetOverlay to use chained bindables
This commit is contained in:
Dean Herbert 2019-02-28 20:08:44 +09:00 committed by GitHub
commit a716e5b265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 43 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -21,30 +22,10 @@ namespace osu.Game.Overlays.BeatmapSet
private const float metadata_width = 225;
private const float spacing = 20;
private readonly MetadataSection source, tags;
private readonly Box successRateBackground;
private readonly SuccessRate successRate;
private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get => beatmapSet;
set
{
if (value == beatmapSet) return;
beatmapSet = value;
updateDisplay();
}
}
private void updateDisplay()
{
source.Text = BeatmapSet?.Metadata.Source ?? string.Empty;
tags.Text = BeatmapSet?.Metadata.Tags ?? string.Empty;
}
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
public BeatmapInfo Beatmap
{
@ -54,6 +35,7 @@ namespace osu.Game.Overlays.BeatmapSet
public Info()
{
MetadataSection source, tags;
RelativeSizeAxes = Axes.X;
Height = 220;
Masking = true;
@ -131,14 +113,18 @@ namespace osu.Game.Overlays.BeatmapSet
},
},
};
BeatmapSet.ValueChanged += b =>
{
source.Text = b.NewValue?.Metadata.Source ?? string.Empty;
tags.Text = b.NewValue?.Metadata.Tags ?? string.Empty;
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
successRateBackground.Colour = colours.GrayE;
updateDisplay();
}
private class MetadataSection : FillFlowContainer

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;
@ -29,32 +30,20 @@ namespace osu.Game.Overlays
public const float RIGHT_WIDTH = 275;
private readonly Header header;
private readonly Info info;
private APIAccess api;
private RulesetStore rulesets;
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;
public BeatmapSetOverlay()
{
Info info;
ScoresContainer scores;
Waves.FirstWaveColour = OsuColour.Gray(0.4f);
Waves.SecondWaveColour = OsuColour.Gray(0.3f);
@ -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);
}