tidy readiness checks in lobby
This commit is contained in:
@@ -37,12 +37,7 @@ namespace OpenRA.Network
|
|||||||
return Slots.FirstOrDefault(s => !s.Value.Closed && ClientInSlot(s.Key) == null).Key;
|
return Slots.FirstOrDefault(s => !s.Value.Closed && ClientInSlot(s.Key) == null).Key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ClientState
|
public enum ClientState { NotReady, Ready, Disconnected = 1000 }
|
||||||
{
|
|
||||||
NotReady,
|
|
||||||
Ready,
|
|
||||||
Disconnected = 1000
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Client
|
public class Client
|
||||||
{
|
{
|
||||||
@@ -55,6 +50,8 @@ namespace OpenRA.Network
|
|||||||
public int Team;
|
public int Team;
|
||||||
public string Slot; // slot ID, or null for observer
|
public string Slot; // slot ID, or null for observer
|
||||||
public string Bot; // Bot type, null for real clients
|
public string Bot; // Bot type, null for real clients
|
||||||
|
|
||||||
|
public bool IsReady { get { return State == ClientState.Ready; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Slot
|
public class Slot
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
var allowCheats = lobby.GetWidget<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
|
var allowCheats = lobby.GetWidget<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
|
||||||
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
|
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
|
||||||
allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null
|
allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null
|
||||||
|| orderManager.LocalClient.State == Session.ClientState.Ready;
|
|| orderManager.LocalClient.IsReady;
|
||||||
allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
|
allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||||
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
|
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
{
|
{
|
||||||
template = EmptySlotTemplate.Clone();
|
template = EmptySlotTemplate.Clone();
|
||||||
Func<string> getText = () => slot.Closed ? "Closed" : "Open";
|
Func<string> getText = () => slot.Closed ? "Closed" : "Open";
|
||||||
var ready = orderManager.LocalClient.State == Session.ClientState.Ready;
|
var ready = orderManager.LocalClient.IsReady;
|
||||||
|
|
||||||
if (Game.IsHost)
|
if (Game.IsHost)
|
||||||
{
|
{
|
||||||
@@ -326,9 +326,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
(client.Bot != null && Game.IsHost))
|
(client.Bot != null && Game.IsHost))
|
||||||
{
|
{
|
||||||
template = EditablePlayerTemplate.Clone();
|
template = EditablePlayerTemplate.Clone();
|
||||||
var botReady = (client.Bot != null && Game.IsHost
|
var botReady = client.Bot != null && Game.IsHost && orderManager.LocalClient.IsReady;
|
||||||
&& orderManager.LocalClient.State == Session.ClientState.Ready);
|
var ready = botReady || client.IsReady;
|
||||||
var ready = botReady || client.State == Session.ClientState.Ready;
|
|
||||||
|
|
||||||
if (client.Bot != null)
|
if (client.Bot != null)
|
||||||
{
|
{
|
||||||
@@ -397,11 +396,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
team.GetText = () => (client.Team == 0) ? "-" : client.Team.ToString();
|
team.GetText = () => (client.Team == 0) ? "-" : client.Team.ToString();
|
||||||
|
|
||||||
template.GetWidget<ImageWidget>("STATUS_IMAGE").IsVisible = () =>
|
template.GetWidget<ImageWidget>("STATUS_IMAGE").IsVisible = () =>
|
||||||
client.Bot != null || client.State == Session.ClientState.Ready;
|
client.Bot != null || client.IsReady;
|
||||||
|
|
||||||
var kickButton = template.GetWidget<ButtonWidget>("KICK");
|
var kickButton = template.GetWidget<ButtonWidget>("KICK");
|
||||||
kickButton.IsVisible = () => Game.IsHost && client.Index != orderManager.LocalClient.Index;
|
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));
|
kickButton.OnClick = () => orderManager.IssueOrder(Order.Command("kick " + client.Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,7 +413,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
{
|
{
|
||||||
Widget template;
|
Widget template;
|
||||||
var c = client;
|
var c = client;
|
||||||
var ready = c.State == Session.ClientState.Ready;
|
var ready = c.IsReady;
|
||||||
|
|
||||||
// Editable spectator
|
// Editable spectator
|
||||||
if (c.Index == orderManager.LocalClient.Index)
|
if (c.Index == orderManager.LocalClient.Index)
|
||||||
{
|
{
|
||||||
@@ -442,12 +442,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
var color = template.GetWidget<ColorBlockWidget>("COLOR");
|
var color = template.GetWidget<ColorBlockWidget>("COLOR");
|
||||||
color.GetColor = () => c.ColorRamp.GetColor(0);
|
color.GetColor = () => c.ColorRamp.GetColor(0);
|
||||||
|
|
||||||
template.GetWidget<ImageWidget>("STATUS_IMAGE").IsVisible = () =>
|
template.GetWidget<ImageWidget>("STATUS_IMAGE").IsVisible = () => c.Bot != null || c.IsReady;
|
||||||
c.Bot != null || c.State == Session.ClientState.Ready;
|
|
||||||
|
|
||||||
var kickButton = template.GetWidget<ButtonWidget>("KICK");
|
var kickButton = template.GetWidget<ButtonWidget>("KICK");
|
||||||
kickButton.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
|
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));
|
kickButton.OnClick = () => orderManager.IssueOrder(Order.Command("kick " + c.Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,7 +460,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
var spec = NewSpectatorTemplate.Clone();
|
var spec = NewSpectatorTemplate.Clone();
|
||||||
var btn = spec.GetWidget<ButtonWidget>("SPECTATE");
|
var btn = spec.GetWidget<ButtonWidget>("SPECTATE");
|
||||||
btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate"));
|
btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate"));
|
||||||
btn.IsDisabled = () => orderManager.LocalClient.State == Session.ClientState.Ready;
|
btn.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||||
spec.IsVisible = () => true;
|
spec.IsVisible = () => true;
|
||||||
Players.AddChild(spec);
|
Players.AddChild(spec);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
void UpdatePlayerColor(Session.Client client, float hf, float sf, float lf, float r)
|
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));
|
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.Player.ColorRamp = ramp;
|
||||||
Game.Settings.Save();
|
Game.Settings.Save();
|
||||||
@@ -246,17 +246,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
if (join != null)
|
if (join != null)
|
||||||
{
|
{
|
||||||
join.OnClick = () => orderManager.IssueOrder(Order.Command("slot " + s.PlayerReference));
|
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();
|
template = LocalPlayerTemplate.Clone();
|
||||||
|
|
||||||
var botReady = (c.Bot != null && Game.IsHost
|
var botReady = (c.Bot != null && Game.IsHost
|
||||||
&& orderManager.LocalClient.State == Session.ClientState.Ready);
|
&& orderManager.LocalClient.IsReady);
|
||||||
var ready = botReady || c.State == Session.ClientState.Ready;
|
var ready = botReady || c.IsReady;
|
||||||
|
|
||||||
if (c.Bot == null)
|
if (c.Bot == null)
|
||||||
{
|
{
|
||||||
@@ -294,7 +294,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
||||||
|
|
||||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||||
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
status.IsChecked = () => c.IsReady;
|
||||||
status.OnClick = CycleReady;
|
status.OnClick = CycleReady;
|
||||||
status.IsVisible = () => c.Bot == null;
|
status.IsVisible = () => c.Bot == null;
|
||||||
}
|
}
|
||||||
@@ -316,7 +316,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
||||||
|
|
||||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||||
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
status.IsChecked = () => c.IsReady;
|
||||||
if (c.Index == orderManager.LocalClient.Index)
|
if (c.Index == orderManager.LocalClient.Index)
|
||||||
status.OnClick = CycleReady;
|
status.OnClick = CycleReady;
|
||||||
status.IsVisible = () => c.Bot == null;
|
status.IsVisible = () => c.Bot == null;
|
||||||
@@ -336,7 +336,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
var c = client;
|
var c = client;
|
||||||
Widget template;
|
Widget template;
|
||||||
// Editable spectator
|
// Editable spectator
|
||||||
if (c.Index == orderManager.LocalClient.Index && c.State != Session.ClientState.Ready)
|
if (c.Index == orderManager.LocalClient.Index && !c.IsReady)
|
||||||
{
|
{
|
||||||
template = LocalSpectatorTemplate.Clone();
|
template = LocalSpectatorTemplate.Clone();
|
||||||
LobbyUtils.SetupNameWidget(orderManager, c, template.GetWidget<TextFieldWidget>("NAME"));
|
LobbyUtils.SetupNameWidget(orderManager, c, template.GetWidget<TextFieldWidget>("NAME"));
|
||||||
@@ -348,7 +348,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
colorBlock.GetColor = () => c.ColorRamp.GetColor(0);
|
colorBlock.GetColor = () => c.ColorRamp.GetColor(0);
|
||||||
|
|
||||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||||
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
status.IsChecked = () => c.IsReady;
|
||||||
status.OnClick += CycleReady;
|
status.OnClick += CycleReady;
|
||||||
}
|
}
|
||||||
// Non-editable spectator
|
// Non-editable spectator
|
||||||
@@ -360,7 +360,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
color.GetColor = () => c.ColorRamp.GetColor(0);
|
color.GetColor = () => c.ColorRamp.GetColor(0);
|
||||||
|
|
||||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||||
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
status.IsChecked = () => c.IsReady;
|
||||||
if (c.Index == orderManager.LocalClient.Index)
|
if (c.Index == orderManager.LocalClient.Index)
|
||||||
status.OnClick += CycleReady;
|
status.OnClick += CycleReady;
|
||||||
|
|
||||||
@@ -374,7 +374,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Spectate button
|
// 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 spec = NewSpectatorTemplate.Clone();
|
||||||
var btn = spec.GetWidget<ButtonWidget>("SPECTATE");
|
var btn = spec.GetWidget<ButtonWidget>("SPECTATE");
|
||||||
|
|||||||
Reference in New Issue
Block a user