mirror of
https://github.com/osukey/osukey.git
synced 2025-06-22 03:38:01 +09:00
Propagate BeatmapSetInfo to tab items with bindable
This commit is contained in:
parent
6985249d90
commit
60133ba0c3
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
@ -13,23 +14,17 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
{
|
{
|
||||||
public class BeatmapRulesetSelector : RulesetSelector
|
public class BeatmapRulesetSelector : RulesetSelector
|
||||||
{
|
{
|
||||||
private BeatmapSetInfo beatmapSet;
|
private readonly Bindable<BeatmapSetInfo> beatmapSet = new Bindable<BeatmapSetInfo>();
|
||||||
|
|
||||||
public BeatmapSetInfo BeatmapSet
|
public BeatmapSetInfo BeatmapSet
|
||||||
{
|
{
|
||||||
get => beatmapSet;
|
get => beatmapSet.Value;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == beatmapSet)
|
// propagate value to tab items first to enable only available rulesets.
|
||||||
return;
|
beatmapSet.Value = value;
|
||||||
|
|
||||||
beatmapSet = value;
|
SelectTab(TabContainer.TabItems.FirstOrDefault(t => t.Enabled.Value));
|
||||||
|
|
||||||
foreach (var tab in TabContainer.TabItems.OfType<BeatmapRulesetTabItem>())
|
|
||||||
tab.SetBeatmaps(beatmapSet?.Beatmaps.FindAll(b => b.Ruleset.Equals(tab.Value)));
|
|
||||||
|
|
||||||
var firstRuleset = beatmapSet?.Beatmaps.OrderBy(b => b.Ruleset.ID).FirstOrDefault()?.Ruleset;
|
|
||||||
SelectTab(TabContainer.TabItems.FirstOrDefault(t => t.Value.Equals(firstRuleset)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +33,10 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new BeatmapRulesetTabItem(value);
|
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new BeatmapRulesetTabItem(value)
|
||||||
|
{
|
||||||
|
BeatmapSet = { BindTarget = beatmapSet }
|
||||||
|
};
|
||||||
|
|
||||||
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -15,8 +16,7 @@ using osu.Game.Graphics.UserInterface;
|
|||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapSet
|
namespace osu.Game.Overlays.BeatmapSet
|
||||||
{
|
{
|
||||||
@ -25,6 +25,8 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
private readonly OsuSpriteText name, count;
|
private readonly OsuSpriteText name, count;
|
||||||
private readonly Box bar;
|
private readonly Box bar;
|
||||||
|
|
||||||
|
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
|
||||||
|
|
||||||
public override bool PropagatePositionalInputSubTree => Enabled.Value && !Active.Value && base.PropagatePositionalInputSubTree;
|
public override bool PropagatePositionalInputSubTree => Enabled.Value && !Active.Value && base.PropagatePositionalInputSubTree;
|
||||||
|
|
||||||
public BeatmapRulesetTabItem(RulesetInfo value)
|
public BeatmapRulesetTabItem(RulesetInfo value)
|
||||||
@ -90,6 +92,15 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
new HoverClickSounds(),
|
new HoverClickSounds(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BeatmapSet.BindValueChanged(setInfo =>
|
||||||
|
{
|
||||||
|
var beatmapsCount = setInfo.NewValue?.Beatmaps.Count(b => b.Ruleset.Equals(Value)) ?? 0;
|
||||||
|
count.Text = beatmapsCount.ToString();
|
||||||
|
|
||||||
|
count.Alpha = beatmapsCount > 0 ? 1f : 0f;
|
||||||
|
Enabled.Value = beatmapsCount > 0;
|
||||||
|
}, true);
|
||||||
|
|
||||||
Enabled.BindValueChanged(v => nameContainer.Alpha = v.NewValue ? 1f : 0.5f, true);
|
Enabled.BindValueChanged(v => nameContainer.Alpha = v.NewValue ? 1f : 0.5f, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,17 +117,6 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBeatmaps(List<BeatmapInfo> beatmaps)
|
|
||||||
{
|
|
||||||
Trace.Assert(beatmaps?.TrueForAll(b => b.Ruleset.Equals(Value)) ?? true, "A beatmap has a ruleset not of this tab value");
|
|
||||||
|
|
||||||
count.Text = beatmaps?.Count.ToString();
|
|
||||||
|
|
||||||
var hasBeatmaps = (beatmaps?.Count ?? 0) > 0;
|
|
||||||
count.Alpha = hasBeatmaps ? 1f : 0f;
|
|
||||||
Enabled.Value = hasBeatmaps;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateState()
|
private void updateState()
|
||||||
{
|
{
|
||||||
var isHoveredOrActive = IsHovered || Active.Value;
|
var isHoveredOrActive = IsHovered || Active.Value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user