Clean up lobby logic and visuals.
This commit is contained in:
@@ -377,7 +377,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
// get template for possible reuse
|
||||
if (idx < Players.Children.Count)
|
||||
template = Players.Children [idx];
|
||||
template = Players.Children[idx];
|
||||
|
||||
// Empty slot
|
||||
if (client == null)
|
||||
@@ -385,29 +385,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
if (template == null || template.Id != EmptySlotTemplate.Id)
|
||||
template = EmptySlotTemplate.Clone();
|
||||
|
||||
Func<string> getText = () => slot.Closed ? "Closed" : "Open";
|
||||
var ready = orderManager.LocalClient.IsReady;
|
||||
|
||||
if (Game.IsHost)
|
||||
{
|
||||
var name = template.Get<DropDownButtonWidget>("NAME_HOST");
|
||||
name.IsVisible = () => true;
|
||||
name.IsDisabled = () => ready;
|
||||
name.GetText = getText;
|
||||
name.OnMouseDown = _ => LobbyUtils.ShowSlotDropDown(name, slot, client, orderManager);
|
||||
}
|
||||
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager);
|
||||
else
|
||||
{
|
||||
var name = template.Get<LabelWidget>("NAME");
|
||||
name.IsVisible = () => true;
|
||||
name.GetText = getText;
|
||||
}
|
||||
LobbyUtils.SetupSlotWidget(template, slot, client);
|
||||
|
||||
var join = template.Get<ButtonWidget>("JOIN");
|
||||
join.IsVisible = () => !slot.Closed;
|
||||
join.IsDisabled = () => ready;
|
||||
join.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||
join.OnClick = () => orderManager.IssueOrder(Order.Command("slot " + key));
|
||||
}
|
||||
|
||||
// Editable player in slot
|
||||
else if ((client.Index == orderManager.LocalClient.Index) ||
|
||||
(client.Bot != null && Game.IsHost))
|
||||
@@ -415,92 +403,33 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
if (template == null || template.Id != EditablePlayerTemplate.Id)
|
||||
template = EditablePlayerTemplate.Clone();
|
||||
|
||||
var botReady = client.Bot != null && Game.IsHost && orderManager.LocalClient.IsReady;
|
||||
var ready = botReady || client.IsReady;
|
||||
LobbyUtils.SetupAdminPingWidget(template, slot, client, orderManager, client.Bot == null);
|
||||
|
||||
if (client.Bot != null)
|
||||
{
|
||||
var name = template.Get<DropDownButtonWidget>("BOT_DROPDOWN");
|
||||
name.IsVisible = () => true;
|
||||
name.IsDisabled = () => ready;
|
||||
name.GetText = () => client.Name;
|
||||
name.OnMouseDown = _ => LobbyUtils.ShowSlotDropDown(name, slot, client, orderManager);
|
||||
}
|
||||
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager);
|
||||
else
|
||||
{
|
||||
var name = template.Get<TextFieldWidget>("NAME");
|
||||
name.IsVisible = () => true;
|
||||
name.IsDisabled = () => ready;
|
||||
LobbyUtils.SetupNameWidget(orderManager, client, name);
|
||||
}
|
||||
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);
|
||||
|
||||
var color = template.Get<DropDownButtonWidget>("COLOR");
|
||||
color.IsDisabled = () => slot.LockColor || ready;
|
||||
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, client, orderManager, colorPreview);
|
||||
|
||||
var colorBlock = color.Get<ColorBlockWidget>("COLORBLOCK");
|
||||
colorBlock.GetColor = () => client.ColorRamp.GetColor(0);
|
||||
|
||||
var faction = template.Get<DropDownButtonWidget>("FACTION");
|
||||
faction.IsDisabled = () => slot.LockRace || ready;
|
||||
faction.OnMouseDown = _ => LobbyUtils.ShowRaceDropDown(faction, client, orderManager, CountryNames);
|
||||
|
||||
var factionname = faction.Get<LabelWidget>("FACTIONNAME");
|
||||
factionname.GetText = () => CountryNames[client.Country];
|
||||
var factionflag = faction.Get<ImageWidget>("FACTIONFLAG");
|
||||
factionflag.GetImageName = () => client.Country;
|
||||
factionflag.GetImageCollection = () => "flags";
|
||||
|
||||
var team = template.Get<DropDownButtonWidget>("TEAM");
|
||||
team.IsDisabled = () => slot.LockTeam || ready;
|
||||
team.OnMouseDown = _ => LobbyUtils.ShowTeamDropDown(team, client, orderManager, Map);
|
||||
team.GetText = () => (client.Team == 0) ? "-" : client.Team.ToString();
|
||||
LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, colorPreview);
|
||||
LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, CountryNames);
|
||||
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map.GetSpawnPoints().Length);
|
||||
LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager);
|
||||
|
||||
if (slot.LockTeam || client.Team > 0)
|
||||
TeamGame = true;
|
||||
|
||||
if (client.Bot == null)
|
||||
{
|
||||
// local player
|
||||
var status = template.Get<CheckboxWidget>("STATUS_CHECKBOX");
|
||||
status.IsChecked = () => ready;
|
||||
status.IsVisible = () => true;
|
||||
status.OnClick = CycleReady;
|
||||
}
|
||||
else // Bot
|
||||
template.Get<ImageWidget>("STATUS_IMAGE").IsVisible = () => true;
|
||||
}
|
||||
else
|
||||
{ // Non-editable player in slot
|
||||
if (template == null || template.Id != NonEditablePlayerTemplate.Id)
|
||||
template = NonEditablePlayerTemplate.Clone();
|
||||
|
||||
template.Get<LabelWidget>("NAME").GetText = () => client.Name;
|
||||
if (client.IsAdmin)
|
||||
template.Get<LabelWidget>("NAME").Font = "Bold";
|
||||
if (client.Ping > -1)
|
||||
template.Get<LabelWidget>("NAME").GetColor = () => LobbyUtils.GetPingColor(client.Ping);
|
||||
|
||||
var color = template.Get<ColorBlockWidget>("COLOR");
|
||||
color.GetColor = () => client.ColorRamp.GetColor(0);
|
||||
|
||||
var faction = template.Get<LabelWidget>("FACTION");
|
||||
var factionname = faction.Get<LabelWidget>("FACTIONNAME");
|
||||
factionname.GetText = () => CountryNames[client.Country];
|
||||
var factionflag = faction.Get<ImageWidget>("FACTIONFLAG");
|
||||
factionflag.GetImageName = () => client.Country;
|
||||
factionflag.GetImageCollection = () => "flags";
|
||||
|
||||
var team = template.Get<LabelWidget>("TEAM");
|
||||
team.GetText = () => (client.Team == 0) ? "-" : client.Team.ToString();
|
||||
|
||||
template.Get<ImageWidget>("STATUS_IMAGE").IsVisible = () =>
|
||||
client.Bot != null || client.IsReady;
|
||||
|
||||
var kickButton = template.Get<ButtonWidget>("KICK");
|
||||
kickButton.IsVisible = () => Game.IsHost && client.Index != orderManager.LocalClient.Index;
|
||||
kickButton.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||
kickButton.OnClick = () => orderManager.IssueOrder(Order.Command("kick " + client.Index));
|
||||
LobbyUtils.SetupAdminPingWidget(template, slot, client, orderManager, client.Bot == null);
|
||||
LobbyUtils.SetupNameWidget(template, slot, client);
|
||||
LobbyUtils.SetupKickWidget(template, slot, client, orderManager);
|
||||
LobbyUtils.SetupColorWidget(template, slot, client);
|
||||
LobbyUtils.SetupFactionWidget(template, slot, client, CountryNames);
|
||||
LobbyUtils.SetupTeamWidget(template, slot, client);
|
||||
LobbyUtils.SetupReadyWidget(template, slot, client);
|
||||
}
|
||||
|
||||
template.IsVisible = () => true;
|
||||
@@ -518,7 +447,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
Widget template = null;
|
||||
var c = client;
|
||||
var ready = c.IsReady;
|
||||
|
||||
// get template for possible reuse
|
||||
if (idx < Players.Children.Count)
|
||||
@@ -530,20 +458,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
if (template == null || template.Id != EditableSpectatorTemplate.Id)
|
||||
template = EditableSpectatorTemplate.Clone();
|
||||
|
||||
var name = template.Get<TextFieldWidget>("NAME");
|
||||
name.IsDisabled = () => ready;
|
||||
LobbyUtils.SetupNameWidget(orderManager, c, name);
|
||||
|
||||
var color = template.Get<DropDownButtonWidget>("COLOR");
|
||||
color.IsDisabled = () => ready;
|
||||
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, colorPreview);
|
||||
|
||||
var colorBlock = color.Get<ColorBlockWidget>("COLORBLOCK");
|
||||
colorBlock.GetColor = () => c.ColorRamp.GetColor(0);
|
||||
|
||||
var status = template.Get<CheckboxWidget>("STATUS_CHECKBOX");
|
||||
status.IsChecked = () => ready;
|
||||
status.OnClick = CycleReady;
|
||||
LobbyUtils.SetupEditableNameWidget(template, null, c, orderManager);
|
||||
LobbyUtils.SetupEditableColorWidget(template, null, c, orderManager, colorPreview);
|
||||
LobbyUtils.SetupEditableReadyWidget(template, null, client, orderManager);
|
||||
}
|
||||
// Non-editable spectator
|
||||
else
|
||||
@@ -551,20 +468,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
if (template == null || template.Id != NonEditableSpectatorTemplate.Id)
|
||||
template = NonEditableSpectatorTemplate.Clone();
|
||||
|
||||
template.Get<LabelWidget>("NAME").GetText = () => c.Name;
|
||||
if (client.IsAdmin)
|
||||
template.Get<LabelWidget>("NAME").Font = "Bold";
|
||||
var color = template.Get<ColorBlockWidget>("COLOR");
|
||||
color.GetColor = () => c.ColorRamp.GetColor(0);
|
||||
|
||||
template.Get<ImageWidget>("STATUS_IMAGE").IsVisible = () => c.Bot != null || c.IsReady;
|
||||
|
||||
var kickButton = template.Get<ButtonWidget>("KICK");
|
||||
kickButton.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
|
||||
kickButton.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||
kickButton.OnClick = () => orderManager.IssueOrder(Order.Command("kick " + c.Index));
|
||||
LobbyUtils.SetupNameWidget(template, null, client);
|
||||
LobbyUtils.SetupKickWidget(template, null, client, orderManager);
|
||||
LobbyUtils.SetupColorWidget(template, null, client);
|
||||
LobbyUtils.SetupReadyWidget(template, null, client);
|
||||
}
|
||||
|
||||
LobbyUtils.SetupAdminPingWidget(template, null, c, orderManager, true);
|
||||
template.IsVisible = () => true;
|
||||
|
||||
if (idx >= Players.Children.Count)
|
||||
@@ -575,7 +485,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
||||
// Spectate button
|
||||
if (orderManager.LocalClient.Slot != null)
|
||||
{
|
||||
@@ -602,11 +511,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
Players.RemoveChild(Players.Children[idx]);
|
||||
}
|
||||
|
||||
void CycleReady()
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("ready"));
|
||||
}
|
||||
|
||||
class DropDownOption
|
||||
{
|
||||
public string Title;
|
||||
|
||||
@@ -21,31 +21,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public static class LobbyUtils
|
||||
{
|
||||
public static void SetupNameWidget(OrderManager orderManager, Session.Client c, TextFieldWidget name)
|
||||
{
|
||||
if (c.IsAdmin)
|
||||
name.Font = "Bold";
|
||||
name.Text = c.Name;
|
||||
if (c.Ping > -1)
|
||||
name.TextColor = GetPingColor(c.Ping);
|
||||
name.OnEnterKey = () =>
|
||||
{
|
||||
name.Text = name.Text.Trim();
|
||||
if (name.Text.Length == 0)
|
||||
name.Text = c.Name;
|
||||
|
||||
name.LoseFocus();
|
||||
if (name.Text == c.Name)
|
||||
return true;
|
||||
|
||||
orderManager.IssueOrder(Order.Command("name " + name.Text));
|
||||
Game.Settings.Player.Name = name.Text;
|
||||
Game.Settings.Save();
|
||||
return true;
|
||||
};
|
||||
name.OnLoseFocus = () => name.OnEnterKey();
|
||||
}
|
||||
|
||||
class SlotDropDownOption
|
||||
{
|
||||
public string Title;
|
||||
@@ -92,7 +67,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
}
|
||||
|
||||
public static void ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Client client,
|
||||
OrderManager orderManager, Map map)
|
||||
OrderManager orderManager, int teamCount)
|
||||
{
|
||||
Func<int, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, itemTemplate) =>
|
||||
{
|
||||
@@ -103,7 +78,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
return item;
|
||||
};
|
||||
|
||||
var options = Exts.MakeArray(map.GetSpawnPoints().Length + 1, i => i).ToList();
|
||||
var options = Exts.MakeArray(teamCount + 1, i => i).ToList();
|
||||
dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem);
|
||||
}
|
||||
|
||||
@@ -192,13 +167,151 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetPingColor(int ping)
|
||||
static Color GetPingColor(Session.Client c)
|
||||
{
|
||||
if (ping > 720) // OrderLag > 6
|
||||
if (c.Ping < 0) // Ping unknown
|
||||
return Color.Gray;
|
||||
if (c.Ping > 720) // OrderLag > 6
|
||||
return Color.Red;
|
||||
if (ping > 360) // OrderLag > 3
|
||||
if (c.Ping > 360) // OrderLag > 3
|
||||
return Color.Orange;
|
||||
|
||||
return Color.LimeGreen;
|
||||
}
|
||||
|
||||
public static void SetupAdminPingWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, bool visible)
|
||||
{
|
||||
parent.Get("ADMIN_INDICATOR").IsVisible = () => c.IsAdmin;
|
||||
var block = parent.Get("PING_BLOCK");
|
||||
block.IsVisible = () => visible;
|
||||
|
||||
if (visible)
|
||||
block.Get<ColorBlockWidget>("PING_COLOR").GetColor = () => GetPingColor(c);
|
||||
}
|
||||
|
||||
public static void SetupEditableNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager)
|
||||
{
|
||||
var name = parent.Get<TextFieldWidget>("NAME");
|
||||
name.IsVisible = () => true;
|
||||
name.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||
|
||||
name.Text = c.Name;
|
||||
name.OnEnterKey = () =>
|
||||
{
|
||||
name.Text = name.Text.Trim();
|
||||
if (name.Text.Length == 0)
|
||||
name.Text = c.Name;
|
||||
|
||||
name.LoseFocus();
|
||||
if (name.Text == c.Name)
|
||||
return true;
|
||||
|
||||
orderManager.IssueOrder(Order.Command("name " + name.Text));
|
||||
Game.Settings.Player.Name = name.Text;
|
||||
Game.Settings.Save();
|
||||
return true;
|
||||
};
|
||||
|
||||
name.OnLoseFocus = () => name.OnEnterKey();
|
||||
}
|
||||
|
||||
public static void SetupNameWidget(Widget parent, Session.Slot s, Session.Client c)
|
||||
{
|
||||
var name = parent.Get<LabelWidget>("NAME");
|
||||
name.GetText = () => c.Name;
|
||||
}
|
||||
|
||||
public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager)
|
||||
{
|
||||
var slot = parent.Get<DropDownButtonWidget>("SLOT_OPTIONS");
|
||||
slot.IsVisible = () => true;
|
||||
slot.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||
slot.GetText = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";
|
||||
slot.OnMouseDown = _ => LobbyUtils.ShowSlotDropDown(slot, s, c, orderManager);
|
||||
|
||||
// Ensure Name selector (if present) is hidden
|
||||
var name = parent.GetOrNull("NAME");
|
||||
if (name != null)
|
||||
name.IsVisible = () => false;
|
||||
}
|
||||
|
||||
public static void SetupSlotWidget(Widget parent, Session.Slot s, Session.Client c)
|
||||
{
|
||||
var name = parent.Get<LabelWidget>("NAME");
|
||||
name.IsVisible = () => true;
|
||||
name.GetText = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";
|
||||
|
||||
// Ensure Slot selector (if present) is hidden
|
||||
var slot = parent.GetOrNull("SLOT_OPTIONS");
|
||||
if (slot != null)
|
||||
slot.IsVisible = () => false;
|
||||
}
|
||||
|
||||
public static void SetupKickWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager)
|
||||
{
|
||||
var button = parent.Get<ButtonWidget>("KICK");
|
||||
button.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
|
||||
button.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||
button.OnClick = () => orderManager.IssueOrder(Order.Command("kick " + c.Index));
|
||||
}
|
||||
|
||||
public static void SetupEditableColorWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, ColorPreviewManagerWidget colorPreview)
|
||||
{
|
||||
var color = parent.Get<DropDownButtonWidget>("COLOR");
|
||||
color.IsDisabled = () => (s != null && s.LockColor) || orderManager.LocalClient.IsReady;
|
||||
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, colorPreview);
|
||||
|
||||
SetupColorWidget(color, s, c);
|
||||
}
|
||||
|
||||
public static void SetupColorWidget(Widget parent, Session.Slot s, Session.Client c)
|
||||
{
|
||||
var color = parent.Get<ColorBlockWidget>("COLORBLOCK");
|
||||
color.GetColor = () => c.ColorRamp.GetColor(0);
|
||||
}
|
||||
|
||||
public static void SetupEditableFactionWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, Dictionary<string,string> countryNames)
|
||||
{
|
||||
var dropdown = parent.Get<DropDownButtonWidget>("FACTION");
|
||||
dropdown.IsDisabled = () => s.LockRace || orderManager.LocalClient.IsReady;
|
||||
dropdown.OnMouseDown = _ => LobbyUtils.ShowRaceDropDown(dropdown, c, orderManager, countryNames);
|
||||
SetupFactionWidget(dropdown, s, c, countryNames);
|
||||
}
|
||||
|
||||
public static void SetupFactionWidget(Widget parent, Session.Slot s, Session.Client c, Dictionary<string,string> countryNames)
|
||||
{
|
||||
var factionname = parent.Get<LabelWidget>("FACTIONNAME");
|
||||
factionname.GetText = () => countryNames[c.Country];
|
||||
var factionflag = parent.Get<ImageWidget>("FACTIONFLAG");
|
||||
factionflag.GetImageName = () => c.Country;
|
||||
factionflag.GetImageCollection = () => "flags";
|
||||
}
|
||||
|
||||
public static void SetupEditableTeamWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, int teamCount)
|
||||
{
|
||||
var dropdown = parent.Get<DropDownButtonWidget>("TEAM");
|
||||
dropdown.IsDisabled = () => s.LockTeam || orderManager.LocalClient.IsReady;
|
||||
dropdown.OnMouseDown = _ => LobbyUtils.ShowTeamDropDown(dropdown, c, orderManager, teamCount);
|
||||
dropdown.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
||||
}
|
||||
|
||||
public static void SetupTeamWidget(Widget parent, Session.Slot s, Session.Client c)
|
||||
{
|
||||
parent.Get<LabelWidget>("TEAM").GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
||||
}
|
||||
|
||||
public static void SetupEditableReadyWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager)
|
||||
{
|
||||
var status = parent.Get<CheckboxWidget>("STATUS_CHECKBOX");
|
||||
status.IsChecked = () => orderManager.LocalClient.IsReady || c.Bot != null;
|
||||
status.IsVisible = () => true;
|
||||
status.IsDisabled = () => c.Bot != null;
|
||||
status.OnClick = () => orderManager.IssueOrder(Order.Command("ready"));
|
||||
}
|
||||
|
||||
public static void SetupReadyWidget(Widget parent, Session.Slot s, Session.Client c)
|
||||
{
|
||||
parent.Get<ImageWidget>("STATUS_IMAGE").IsVisible = () => c.IsReady || c.Bot != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user