From bc930e8fd32eab12f1bcdf6e57236433ad7ebe40 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 29 Jan 2025 20:02:01 +0900 Subject: [PATCH] Minimal clean-up to get things bearable I plan to do a full refactor of `RoomSubScreen` at first opportunity. --- .../Screens/OnlinePlay/Match/RoomSubScreen.cs | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index 428f0e9ed8..c9c9c3eca7 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -49,18 +50,18 @@ namespace osu.Game.Screens.OnlinePlay.Match /// A container that provides controls for selection of user mods. /// This will be shown/hidden automatically when applicable. /// - protected Drawable? UserModsSection; + protected Drawable UserModsSection = null!; /// /// A container that provides controls for selection of the user style. /// This will be shown/hidden automatically when applicable. /// - protected Drawable? UserStyleSection; + protected Drawable UserStyleSection = null!; /// /// A container that will display the user's style. /// - protected Container? UserStyleDisplayContainer; + protected Container UserStyleDisplayContainer = null!; private Sample? sampleStart; @@ -448,40 +449,44 @@ namespace osu.Game.Screens.OnlinePlay.Match Mods.Value = GetGameplayMods().Select(m => m.ToMod(rulesetInstance)).ToArray(); Ruleset.Value = GetGameplayRuleset(); - if (!item.AllowedMods.Any()) + bool freeMod = item.AllowedMods.Any(); + bool freeStyle = item.FreeStyle; + + // For now, the game can never be in a state where freemod and freestyle are on at the same time. + // This will change, but due to the current implementation if this was to occur drawables will overlap so let's assert. + Debug.Assert(!freeMod || !freeStyle); + + if (freeMod) { - UserModsSection?.Hide(); + UserModsSection.Show(); + UserModsSelectOverlay.IsValidMod = m => allowedMods.Any(a => a.GetType() == m.GetType()); + } + else + { + UserModsSection.Hide(); UserModsSelectOverlay.Hide(); UserModsSelectOverlay.IsValidMod = _ => false; } - else - { - UserModsSection?.Show(); - UserModsSelectOverlay.IsValidMod = m => allowedMods.Any(a => a.GetType() == m.GetType()); - } - if (item.FreeStyle) + if (freeStyle) { - UserStyleSection?.Show(); + UserStyleSection.Show(); - if (UserStyleDisplayContainer != null) + PlaylistItem gameplayItem = SelectedItem.Value.With(ruleset: GetGameplayRuleset().OnlineID, beatmap: new Optional(GetGameplayBeatmap())); + PlaylistItem? currentItem = UserStyleDisplayContainer.SingleOrDefault()?.Item; + + if (gameplayItem.Equals(currentItem)) + return; + + UserStyleDisplayContainer.Child = new DrawableRoomPlaylistItem(gameplayItem, true) { - PlaylistItem gameplayItem = SelectedItem.Value.With(ruleset: GetGameplayRuleset().OnlineID, beatmap: new Optional(GetGameplayBeatmap())); - PlaylistItem? currentItem = UserStyleDisplayContainer.SingleOrDefault()?.Item; - - if (gameplayItem.Equals(currentItem)) - return; - - UserStyleDisplayContainer.Child = new DrawableRoomPlaylistItem(gameplayItem, true) - { - AllowReordering = false, - AllowEditing = item.FreeStyle, - RequestEdit = _ => OpenStyleSelection() - }; - } + AllowReordering = false, + AllowEditing = freeStyle, + RequestEdit = _ => OpenStyleSelection() + }; } else - UserStyleSection?.Hide(); + UserStyleSection.Hide(); }); protected virtual APIMod[] GetGameplayMods() => UserMods.Value.Select(m => new APIMod(m)).Concat(SelectedItem.Value!.RequiredMods).ToArray();