From 323d7f8e2dabbd090c29b51926338cece1a94f64 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 23 Feb 2024 16:59:08 +0300 Subject: [PATCH] Change `BeatmapAttributesDisplay` retrieval to proper method --- osu.Game/Overlays/Mods/ModSelectOverlay.cs | 16 +++--- .../OnlinePlay/Match/RoomModSelectOverlay.cs | 56 +++++++++---------- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 8a3b1954ed..99981c28d5 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -130,13 +130,6 @@ namespace osu.Game.Overlays.Mods private RankingInformationDisplay? rankingInformationDisplay; private BeatmapAttributesDisplay? beatmapAttributesDisplay; - protected virtual BeatmapAttributesDisplay GetBeatmapAttributesDisplay => new BeatmapAttributesDisplay - { - Anchor = Anchor.BottomRight, - Origin = Anchor.BottomRight, - BeatmapInfo = { Value = Beatmap?.BeatmapInfo } - }; - protected ShearedButton BackButton { get; private set; } = null!; protected ShearedToggleButton? CustomisationButton { get; private set; } protected SelectAllModsButton? SelectAllModsButton { get; set; } @@ -283,7 +276,12 @@ namespace osu.Game.Overlays.Mods Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight }, - beatmapAttributesDisplay = GetBeatmapAttributesDisplay + beatmapAttributesDisplay = CreateBeatmapAttributesDisplay().With(b => + { + b.Anchor = Anchor.BottomRight; + b.Origin = Anchor.BottomRight; + b.BeatmapInfo.Value = Beatmap?.BeatmapInfo; + }), } }); } @@ -293,6 +291,8 @@ namespace osu.Game.Overlays.Mods textSearchStartsActive = configManager.GetBindable(OsuSetting.ModSelectTextSearchStartsActive); } + protected virtual BeatmapAttributesDisplay CreateBeatmapAttributesDisplay() => new BeatmapAttributesDisplay(); + public override void Hide() { base.Hide(); diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomModSelectOverlay.cs b/osu.Game/Screens/OnlinePlay/Match/RoomModSelectOverlay.cs index 5406912f49..4bf8e22d4e 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomModSelectOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomModSelectOverlay.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Graphics; using osu.Game.Online.Rooms; using osu.Game.Overlays; using osu.Game.Overlays.Mods; @@ -28,13 +27,6 @@ namespace osu.Game.Screens.OnlinePlay.Match [Resolved] private RulesetStore rulesets { get; set; } = null!; - protected override BeatmapAttributesDisplay GetBeatmapAttributesDisplay => new RoomBeatmapAttributesDisplay - { - Anchor = Anchor.BottomRight, - Origin = Anchor.BottomRight, - BeatmapInfo = { Value = Beatmap?.BeatmapInfo } - }; - private readonly List roomMods = new List(); protected override void LoadComplete() @@ -57,37 +49,39 @@ namespace osu.Game.Screens.OnlinePlay.Match } protected override IEnumerable AllSelectedMods => roomMods.Concat(base.AllSelectedMods); - } - public partial class RoomBeatmapAttributesDisplay : BeatmapAttributesDisplay - { - [Resolved(CanBeNull = true)] - private IBindable? selectedItem { get; set; } + protected override BeatmapAttributesDisplay CreateBeatmapAttributesDisplay() => new RoomBeatmapAttributesDisplay(); - [Resolved] - private RulesetStore rulesets { get; set; } = null!; - - private readonly List roomMods = new List(); - - protected override void LoadComplete() + private partial class RoomBeatmapAttributesDisplay : BeatmapAttributesDisplay { - base.LoadComplete(); + [Resolved(CanBeNull = true)] + private IBindable? selectedItem { get; set; } - selectedItem?.BindValueChanged(_ => + [Resolved] + private RulesetStore rulesets { get; set; } = null!; + + private readonly List roomMods = new List(); + + protected override void LoadComplete() { - roomMods.Clear(); + base.LoadComplete(); - if (selectedItem?.Value != null) + selectedItem?.BindValueChanged(_ => { - var rulesetInstance = rulesets.GetRuleset(selectedItem.Value.RulesetID)?.CreateInstance(); - Debug.Assert(rulesetInstance != null); - roomMods.AddRange(selectedItem.Value.RequiredMods.Select(m => m.ToMod(rulesetInstance))); - } + roomMods.Clear(); - Mods.TriggerChange(); - }); + if (selectedItem?.Value != null) + { + var rulesetInstance = rulesets.GetRuleset(selectedItem.Value.RulesetID)?.CreateInstance(); + Debug.Assert(rulesetInstance != null); + roomMods.AddRange(selectedItem.Value.RequiredMods.Select(m => m.ToMod(rulesetInstance))); + } + + Mods.TriggerChange(); + }); + } + + protected override IEnumerable SelectedMods => roomMods.Concat(base.SelectedMods); } - - protected override IEnumerable SelectedMods => roomMods.Concat(base.SelectedMods); } }