From eaa4d060528985bf5f3838e19c867983790d3ecb Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 1 Nov 2011 21:42:54 +1300 Subject: [PATCH] tidy readiness checks in lobby --- OpenRA.Game/Network/Session.cs | 9 +++----- .../Widgets/Logic/CncLobbyLogic.cs | 23 +++++++++---------- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 22 +++++++++--------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index d45b456704..d9e25285b6 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -37,12 +37,7 @@ namespace OpenRA.Network return Slots.FirstOrDefault(s => !s.Value.Closed && ClientInSlot(s.Key) == null).Key; } - public enum ClientState - { - NotReady, - Ready, - Disconnected = 1000 - } + public enum ClientState { NotReady, Ready, Disconnected = 1000 } public class Client { @@ -55,6 +50,8 @@ namespace OpenRA.Network public int Team; public string Slot; // slot ID, or null for observer public string Bot; // Bot type, null for real clients + + public bool IsReady { get { return State == ClientState.Ready; } } } public class Slot diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs index decb68306c..0e296ba87a 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs @@ -153,7 +153,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var allowCheats = lobby.GetWidget("ALLOWCHEATS_CHECKBOX"); allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats; allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null - || orderManager.LocalClient.State == Session.ClientState.Ready; + || orderManager.LocalClient.IsReady; allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command( "allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats))); @@ -299,7 +299,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { template = EmptySlotTemplate.Clone(); Func getText = () => slot.Closed ? "Closed" : "Open"; - var ready = orderManager.LocalClient.State == Session.ClientState.Ready; + var ready = orderManager.LocalClient.IsReady; if (Game.IsHost) { @@ -326,9 +326,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic (client.Bot != null && Game.IsHost)) { template = EditablePlayerTemplate.Clone(); - var botReady = (client.Bot != null && Game.IsHost - && orderManager.LocalClient.State == Session.ClientState.Ready); - var ready = botReady || client.State == Session.ClientState.Ready; + var botReady = client.Bot != null && Game.IsHost && orderManager.LocalClient.IsReady; + var ready = botReady || client.IsReady; if (client.Bot != null) { @@ -397,11 +396,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic team.GetText = () => (client.Team == 0) ? "-" : client.Team.ToString(); template.GetWidget("STATUS_IMAGE").IsVisible = () => - client.Bot != null || client.State == Session.ClientState.Ready; + client.Bot != null || client.IsReady; var kickButton = template.GetWidget("KICK"); kickButton.IsVisible = () => Game.IsHost && client.Index != orderManager.LocalClient.Index; - kickButton.IsDisabled = () => orderManager.LocalClient.State == Session.ClientState.Ready; + kickButton.IsDisabled = () => orderManager.LocalClient.IsReady; kickButton.OnClick = () => orderManager.IssueOrder(Order.Command("kick " + client.Index)); } @@ -414,7 +413,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { Widget template; var c = client; - var ready = c.State == Session.ClientState.Ready; + var ready = c.IsReady; + // Editable spectator if (c.Index == orderManager.LocalClient.Index) { @@ -442,12 +442,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var color = template.GetWidget("COLOR"); color.GetColor = () => c.ColorRamp.GetColor(0); - template.GetWidget("STATUS_IMAGE").IsVisible = () => - c.Bot != null || c.State == Session.ClientState.Ready; + template.GetWidget("STATUS_IMAGE").IsVisible = () => c.Bot != null || c.IsReady; var kickButton = template.GetWidget("KICK"); kickButton.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index; - kickButton.IsDisabled = () => orderManager.LocalClient.State == Session.ClientState.Ready; + kickButton.IsDisabled = () => orderManager.LocalClient.IsReady; kickButton.OnClick = () => orderManager.IssueOrder(Order.Command("kick " + c.Index)); } @@ -461,7 +460,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var spec = NewSpectatorTemplate.Clone(); var btn = spec.GetWidget("SPECTATE"); btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate")); - btn.IsDisabled = () => orderManager.LocalClient.State == Session.ClientState.Ready; + btn.IsDisabled = () => orderManager.LocalClient.IsReady; spec.IsVisible = () => true; Players.AddChild(spec); } diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 100a2a5873..03bdbf1c71 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -158,7 +158,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic void UpdatePlayerColor(Session.Client client, float hf, float sf, float lf, float r) { var ramp = new ColorRamp((byte)(hf * 255), (byte)(sf * 255), (byte)(lf * 255), (byte)(r * 255)); - if (client.Index == orderManager.LocalClient.Index) + if (client == orderManager.LocalClient) { Game.Settings.Player.ColorRamp = ramp; Game.Settings.Save(); @@ -246,17 +246,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (join != null) { join.OnClick = () => orderManager.IssueOrder(Order.Command("slot " + s.PlayerReference)); - join.IsVisible = () => !s.Closed && c == null && orderManager.LocalClient.State != Session.ClientState.Ready; + join.IsVisible = () => !s.Closed && c == null && !orderManager.LocalClient.IsReady; } } - else if ((c.Index == orderManager.LocalClient.Index && c.State != Session.ClientState.Ready) || (c.Bot != null && Game.IsHost)) + else if ((c.Index == orderManager.LocalClient.Index && !c.IsReady) || (c.Bot != null && Game.IsHost)) { template = LocalPlayerTemplate.Clone(); var botReady = (c.Bot != null && Game.IsHost - && orderManager.LocalClient.State == Session.ClientState.Ready); - var ready = botReady || c.State == Session.ClientState.Ready; + && orderManager.LocalClient.IsReady); + var ready = botReady || c.IsReady; if (c.Bot == null) { @@ -294,7 +294,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString(); var status = template.GetWidget("STATUS"); - status.IsChecked = () => c.State == Session.ClientState.Ready; + status.IsChecked = () => c.IsReady; status.OnClick = CycleReady; status.IsVisible = () => c.Bot == null; } @@ -316,7 +316,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString(); var status = template.GetWidget("STATUS"); - status.IsChecked = () => c.State == Session.ClientState.Ready; + status.IsChecked = () => c.IsReady; if (c.Index == orderManager.LocalClient.Index) status.OnClick = CycleReady; status.IsVisible = () => c.Bot == null; @@ -336,7 +336,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var c = client; Widget template; // Editable spectator - if (c.Index == orderManager.LocalClient.Index && c.State != Session.ClientState.Ready) + if (c.Index == orderManager.LocalClient.Index && !c.IsReady) { template = LocalSpectatorTemplate.Clone(); LobbyUtils.SetupNameWidget(orderManager, c, template.GetWidget("NAME")); @@ -348,7 +348,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic colorBlock.GetColor = () => c.ColorRamp.GetColor(0); var status = template.GetWidget("STATUS"); - status.IsChecked = () => c.State == Session.ClientState.Ready; + status.IsChecked = () => c.IsReady; status.OnClick += CycleReady; } // Non-editable spectator @@ -360,7 +360,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic color.GetColor = () => c.ColorRamp.GetColor(0); var status = template.GetWidget("STATUS"); - status.IsChecked = () => c.State == Session.ClientState.Ready; + status.IsChecked = () => c.IsReady; if (c.Index == orderManager.LocalClient.Index) status.OnClick += CycleReady; @@ -374,7 +374,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic } // Spectate button - if (orderManager.LocalClient.Slot != null && orderManager.LocalClient.State != Session.ClientState.Ready) + if (orderManager.LocalClient.Slot != null && !orderManager.LocalClient.IsReady) { var spec = NewSpectatorTemplate.Clone(); var btn = spec.GetWidget("SPECTATE");