Skip to content

Commit

Permalink
Improve game lobby launch game button state updating
Browse files Browse the repository at this point in the history
- The button is now disabled if there is no game mode or map currently selected if in skirmish lobby or MP lobby as host
- The button now visibly changes to disabled state if current tunnel server is invalid instead of simply becoming unclickable.
  • Loading branch information
Starkku committed Apr 22, 2023
1 parent 3fe512f commit c61319b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
18 changes: 16 additions & 2 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/CnCNetGameLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ DiscordHandler discordHandler
/// </summary>
private string lastGameMode;

/// <summary>
/// Set to true if host has selected invalid tunnel server.
/// </summary>
private bool tunnelErrorMode;

public override void Initialize()
{
IniNameOverride = nameof(CnCNetGameLobby);
Expand Down Expand Up @@ -941,6 +946,7 @@ private void ApplyPlayerOptions(string sender, string message)

pInfo.Ready = readyStatus > 0;
pInfo.AutoReady = readyStatus > 1;

if (pInfo.Name == ProgramConstants.PLAYERNAME)
btnLaunchGame.Text = pInfo.Ready ? BTN_LAUNCH_NOT_READY : BTN_LAUNCH_READY;

Expand Down Expand Up @@ -1557,16 +1563,18 @@ private void HandleTunnelServerChangeMessage(string sender, string tunnelAddress
CnCNetTunnel tunnel = tunnelHandler.Tunnels.Find(t => t.Address == tunnelAddress && t.Port == tunnelPort);
if (tunnel == null)
{
tunnelErrorMode = true;
AddNotice(("The game host has selected an invalid tunnel server! " +
"The game host needs to change the server or you will be unable " +
"to participate in the match.").L10N("Client:Main:HostInvalidTunnel"),
Color.Yellow);
btnLaunchGame.AllowClick = false;
UpdateLaunchGameButtonStatus();
return;
}

tunnelErrorMode = false;
HandleTunnelServerChange(tunnel);
btnLaunchGame.AllowClick = true;
UpdateLaunchGameButtonStatus();
}

/// <summary>
Expand All @@ -1580,6 +1588,12 @@ private void HandleTunnelServerChange(CnCNetTunnel tunnel)
UpdatePing();
}

protected override bool UpdateLaunchGameButtonStatus()
{
btnLaunchGame.Enabled = base.UpdateLaunchGameButtonStatus() && !tunnelErrorMode;
return btnLaunchGame.Enabled;
}

#region CnCNet map sharing

private void MapSharer_MapDownloadFailed(object sender, SHA1EventArgs e)
Expand Down
11 changes: 11 additions & 0 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,8 @@ protected virtual void ChangeMap(GameModeMap gameModeMap)
{
GameModeMap = gameModeMap;

_ = UpdateLaunchGameButtonStatus();

if (GameMode == null || Map == null)
{
lblMapName.Text = "Map: Unknown".L10N("Client:Main:MapUnknown");
Expand Down Expand Up @@ -2456,6 +2458,15 @@ public bool LoadGameOptionPreset(string name)
return true;
}

/// <summary>
/// Checks if launch game button can stay enabled or not and updates the state accordingly.
/// </summary>
/// <returns>True if launch game button is enabled, false if not.</returns>
protected virtual bool UpdateLaunchGameButtonStatus()
{
return true;
}

protected abstract bool AllowPlayerOptionsChange();
}
}
14 changes: 12 additions & 2 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ private void TbChatInput_EnterPressed(object sender, EventArgs e)

private void ChkAutoReady_CheckedChanged(object sender, EventArgs e)
{
btnLaunchGame.Enabled = !chkAutoReady.Checked;
UpdateLaunchGameButtonStatus();
RequestReadyStatus();
}

Expand All @@ -391,7 +391,7 @@ protected void ResetAutoReadyCheckbox()
chkAutoReady.CheckedChanged -= ChkAutoReady_CheckedChanged;
chkAutoReady.Checked = false;
chkAutoReady.CheckedChanged += ChkAutoReady_CheckedChanged;
btnLaunchGame.Enabled = true;
UpdateLaunchGameButtonStatus();
}

private void SetFrameSendRate(string value)
Expand Down Expand Up @@ -1166,5 +1166,15 @@ protected override void UpdateMapPreviewBoxEnabledStatus()
MapPreviewBox.EnableStartLocationSelection = true;
}
}

protected override bool UpdateLaunchGameButtonStatus()
{
if (IsHost)
btnLaunchGame.Enabled = base.UpdateLaunchGameButtonStatus() && GameMode != null && Map != null;
else
btnLaunchGame.Enabled = base.UpdateLaunchGameButtonStatus() && !chkAutoReady.Checked;

return btnLaunchGame.Enabled;
}
}
}
6 changes: 6 additions & 0 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/SkirmishLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,11 @@ protected override void UpdateMapPreviewBoxEnabledStatus()
MapPreviewBox.EnableContextMenu = !((Map != null && Map.ForceRandomStartLocations) || (GameMode != null && GameMode.ForceRandomStartLocations) || GetPlayerExtraOptions().IsForceRandomStarts);
MapPreviewBox.EnableStartLocationSelection = MapPreviewBox.EnableContextMenu;
}

protected override bool UpdateLaunchGameButtonStatus()
{
btnLaunchGame.Enabled = base.UpdateLaunchGameButtonStatus() && GameMode != null && Map != null;
return btnLaunchGame.Enabled;
}
}
}

0 comments on commit c61319b

Please sign in to comment.