From 58660480d95d602c9e4c46138fe71b5d78c1e800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=88=B0=E9=98=9F=E7=9A=84=E5=81=B6=E5=83=8F-=E5=B2=9B?= =?UTF-8?q?=E9=A3=8E=E9=85=B1!?= Date: Sun, 2 Jun 2024 18:27:02 +0800 Subject: [PATCH] Update MultiplayerGameLobby controls visibility logic. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 舰队的偶像-岛风酱! --- .../GameLobby/MultiplayerGameLobby.cs | 109 +++++++++--------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs b/DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs index cd0b6b8a7..502fc365c 100644 --- a/DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs +++ b/DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs @@ -35,9 +35,9 @@ public MultiplayerGameLobby(WindowManager windowManager, string iniName, chatBoxCommands = new List { new ChatBoxCommand("HIDEMAPS", "Hide map list (game host only)".L10N("Client:Main:ChatboxCommandHideMapsHelp"), true, - s => HideMapList()), + s => ChangeControls(false)), new ChatBoxCommand("SHOWMAPS", "Show map list (game host only)".L10N("Client:Main:ChatboxCommandShowMapsHelp"), true, - s => ShowMapList()), + s => ChangeControls(true)), new ChatBoxCommand("FRAMESENDRATE", "Change order lag / FrameSendRate (default 7) (game host only)".L10N("Client:Main:ChatboxCommandFrameSendRateHelp"), true, s => SetFrameSendRate(s)), new ChatBoxCommand("MAXAHEAD", "Change MaxAhead (default 0) (game host only)".L10N("Client:Main:ChatboxCommandMaxAheadHelp"), true, @@ -613,9 +613,9 @@ protected void Refresh(bool isHost) btnLaunchGame.Text = IsHost ? BTN_LAUNCH_GAME : BTN_LAUNCH_READY; + ChangeControls(IsHost); if (IsHost) { - ShowMapList(); btnSaveLoadGameOptions?.Enable(); btnLockGame.Text = "Lock Game".L10N("Client:Main:ButtonLockGame"); @@ -639,7 +639,6 @@ protected void Refresh(bool isHost) } else { - HideMapList(); btnSaveLoadGameOptions?.Disable(); btnLockGame.Enabled = false; @@ -668,60 +667,60 @@ protected void Refresh(bool isHost) } } - private void HideMapList() + /// + /// Change MapList and other controls visibility.
+ /// And apply some controls properties. + ///
+ /// Visibility + private void ChangeControls(bool isHost) { - lbChatMessages.Name = "lbChatMessages_Player"; - tbChatInput.Name = "tbChatInput_Player"; - MapPreviewBox.Name = "MapPreviewBox"; - lblMapName.Name = "lblMapName"; - lblMapAuthor.Name = "lblMapAuthor"; - lblGameMode.Name = "lblGameMode"; - lblMapSize.Name = "lblMapSize"; + const string HostSuffix = "_Host"; + const string PlayerSuffix = "_Player"; + string sourceSuffix; // The name of the target control may have a suffix. e.g. lbChatMessages_Player + string targetSuffix; // Change the name of the control to match the new suffix. + List controlsToUpdate = new(); + if (!isHost) + { + sourceSuffix = HostSuffix; + targetSuffix = PlayerSuffix; + + ddGameModeMapFilter.Disable(); + lblGameModeSelect.Disable(); + lbGameModeMapList.Disable(); + tbMapSearch.Disable(); + btnPickRandomMap.Disable(); + btnMapSortAlphabetically.Disable(); + } + else + { + sourceSuffix = PlayerSuffix; + targetSuffix = HostSuffix; + + ddGameModeMapFilter.Enable(); + lblGameModeSelect.Enable(); + lbGameModeMapList.Enable(); + tbMapSearch.Enable(); + btnPickRandomMap.Enable(); + btnMapSortAlphabetically.Enable(); + } - ReadINIForControl(btnPickRandomMap); - ReadINIForControl(lbChatMessages); - ReadINIForControl(tbChatInput); - ReadINIForControl(lbGameModeMapList); - ReadINIForControl(lblMapName); - ReadINIForControl(lblMapAuthor); - ReadINIForControl(lblGameMode); - ReadINIForControl(lblMapSize); - ReadINIForControl(btnMapSortAlphabetically); - - ddGameModeMapFilter.Disable(); - lblGameModeSelect.Disable(); - lbGameModeMapList.Disable(); - tbMapSearch.Disable(); - btnPickRandomMap.Disable(); - btnMapSortAlphabetically.Disable(); - } + foreach (string targetName in ConfigIni.GetSections().Where(s => s.EndsWith(targetSuffix))) + { + // Get name without suffix. + string nameWithoutSuffix = targetName.Replace(targetSuffix, string.Empty); - private void ShowMapList() - { - lbChatMessages.Name = "lbChatMessages_Host"; - tbChatInput.Name = "tbChatInput_Host"; - MapPreviewBox.Name = "MapPreviewBox"; - lblMapName.Name = "lblMapName"; - lblMapAuthor.Name = "lblMapAuthor"; - lblGameMode.Name = "lblGameMode"; - lblMapSize.Name = "lblMapSize"; - - ddGameModeMapFilter.Enable(); - lblGameModeSelect.Enable(); - lbGameModeMapList.Enable(); - tbMapSearch.Enable(); - btnPickRandomMap.Enable(); - btnMapSortAlphabetically.Enable(); - - ReadINIForControl(btnPickRandomMap); - ReadINIForControl(lbChatMessages); - ReadINIForControl(tbChatInput); - ReadINIForControl(lbGameModeMapList); - ReadINIForControl(lblMapName); - ReadINIForControl(lblMapAuthor); - ReadINIForControl(lblGameMode); - ReadINIForControl(lblMapSize); - ReadINIForControl(btnMapSortAlphabetically); + // When no control is found without a suffix. Try using a name with a suffix. + var control = FindChild(nameWithoutSuffix, true) + ?? FindChild(nameWithoutSuffix + sourceSuffix, true); + + if (control != null) + { + control.Name = targetName; + controlsToUpdate.Add(control); + } + } + + controlsToUpdate.ForEach(ReadINIForControl); } private void MapPreviewBox_LocalStartingLocationSelected(object sender, LocalStartingLocationEventArgs e)