From 60133ba0c3fa62ef7f7cc6f8f14ea47f886b2015 Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Tue, 15 Oct 2019 23:33:50 +0300 Subject: [PATCH] Propagate BeatmapSetInfo to tab items with bindable --- .../BeatmapSet/BeatmapRulesetSelector.cs | 22 +++++++--------- .../BeatmapSet/BeatmapRulesetTabItem.cs | 26 +++++++++---------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapRulesetSelector.cs b/osu.Game/Overlays/BeatmapSet/BeatmapRulesetSelector.cs index bfb188a83b..a0bedc848e 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapRulesetSelector.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapRulesetSelector.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.UserInterface; @@ -13,23 +14,17 @@ namespace osu.Game.Overlays.BeatmapSet { public class BeatmapRulesetSelector : RulesetSelector { - private BeatmapSetInfo beatmapSet; + private readonly Bindable beatmapSet = new Bindable(); public BeatmapSetInfo BeatmapSet { - get => beatmapSet; + get => beatmapSet.Value; set { - if (value == beatmapSet) - return; + // propagate value to tab items first to enable only available rulesets. + beatmapSet.Value = value; - beatmapSet = value; - - foreach (var tab in TabContainer.TabItems.OfType()) - 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))); + SelectTab(TabContainer.TabItems.FirstOrDefault(t => t.Enabled.Value)); } } @@ -38,7 +33,10 @@ namespace osu.Game.Overlays.BeatmapSet AutoSizeAxes = Axes.Both; } - protected override TabItem CreateTabItem(RulesetInfo value) => new BeatmapRulesetTabItem(value); + protected override TabItem CreateTabItem(RulesetInfo value) => new BeatmapRulesetTabItem(value) + { + BeatmapSet = { BindTarget = beatmapSet } + }; protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer { diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs b/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs index 19c9af13d5..5227bec92a 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs @@ -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; @@ -15,8 +16,7 @@ using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets; using osuTK; using osuTK.Graphics; -using System.Collections.Generic; -using System.Diagnostics; +using System.Linq; namespace osu.Game.Overlays.BeatmapSet { @@ -25,6 +25,8 @@ namespace osu.Game.Overlays.BeatmapSet private readonly OsuSpriteText name, count; private readonly Box bar; + public readonly Bindable BeatmapSet = new Bindable(); + public override bool PropagatePositionalInputSubTree => Enabled.Value && !Active.Value && base.PropagatePositionalInputSubTree; public BeatmapRulesetTabItem(RulesetInfo value) @@ -90,6 +92,15 @@ namespace osu.Game.Overlays.BeatmapSet 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); } @@ -106,17 +117,6 @@ namespace osu.Game.Overlays.BeatmapSet updateState(); } - public void SetBeatmaps(List 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() { var isHoveredOrActive = IsHovered || Active.Value;