Skip to content

Commit

Permalink
Update MultiplayerGameLobby controls visibility logic.
Browse files Browse the repository at this point in the history
Signed-off-by: 舰队的偶像-岛风酱! <[email protected]>
  • Loading branch information
frg2089 committed Jun 2, 2024
1 parent 260ec47 commit 5866048
Showing 1 changed file with 54 additions and 55 deletions.
109 changes: 54 additions & 55 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public MultiplayerGameLobby(WindowManager windowManager, string iniName,
chatBoxCommands = new List<ChatBoxCommand>
{
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,
Expand Down Expand Up @@ -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");
Expand All @@ -639,7 +639,6 @@ protected void Refresh(bool isHost)
}
else
{
HideMapList();
btnSaveLoadGameOptions?.Disable();

btnLockGame.Enabled = false;
Expand Down Expand Up @@ -668,60 +667,60 @@ protected void Refresh(bool isHost)
}
}

private void HideMapList()
/// <summary>
/// Change MapList and other controls visibility. <br/>
/// And apply some controls properties.
/// </summary>
/// <param name="isHost">Visibility</param>
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<XNAControl> 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<XNAControl>(nameWithoutSuffix, true)
?? FindChild<XNAControl>(nameWithoutSuffix + sourceSuffix, true);

if (control != null)
{
control.Name = targetName;
controlsToUpdate.Add(control);
}
}

controlsToUpdate.ForEach(ReadINIForControl);
}

private void MapPreviewBox_LocalStartingLocationSelected(object sender, LocalStartingLocationEventArgs e)
Expand Down

0 comments on commit 5866048

Please sign in to comment.