Overhaul lobby layout.
This commit is contained in:
@@ -20,6 +20,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class LobbyLogic
|
||||
{
|
||||
enum PanelType { Players, Options, Kick }
|
||||
PanelType panel = PanelType.Players;
|
||||
|
||||
Widget lobby;
|
||||
Widget EditablePlayerTemplate, NonEditablePlayerTemplate, EmptySlotTemplate,
|
||||
EditableSpectatorTemplate, NonEditableSpectatorTemplate, NewSpectatorTemplate;
|
||||
@@ -37,8 +40,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
readonly Action onExit;
|
||||
readonly OrderManager orderManager;
|
||||
|
||||
public bool TeamGame;
|
||||
|
||||
// Listen for connection failures
|
||||
void ConnectionStateChanged(OrderManager om)
|
||||
{
|
||||
@@ -103,6 +104,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
UpdateCurrentMap();
|
||||
Players = Ui.LoadWidget<ScrollPanelWidget>("LOBBY_PLAYER_BIN", lobby, new WidgetArgs());
|
||||
Players.IsVisible = () => panel == PanelType.Players;
|
||||
|
||||
EditablePlayerTemplate = Players.Get("TEMPLATE_EDITABLE_PLAYER");
|
||||
NonEditablePlayerTemplate = Players.Get("TEMPLATE_NONEDITABLE_PLAYER");
|
||||
EmptySlotTemplate = Players.Get("TEMPLATE_EMPTY");
|
||||
@@ -145,31 +148,36 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
CountryNames.Add("random", "Any");
|
||||
|
||||
var gameStarting = false;
|
||||
Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting || panel == PanelType.Kick ||
|
||||
orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
|
||||
|
||||
var mapButton = lobby.Get<ButtonWidget>("CHANGEMAP_BUTTON");
|
||||
mapButton.OnClick = () =>
|
||||
var mapButton = lobby.GetOrNull<ButtonWidget>("CHANGEMAP_BUTTON");
|
||||
if (mapButton != null)
|
||||
{
|
||||
var onSelect = new Action<Map>(m =>
|
||||
mapButton.IsDisabled = configurationDisabled;
|
||||
mapButton.OnClick = () =>
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("map " + m.Uid));
|
||||
Game.Settings.Server.Map = m.Uid;
|
||||
Game.Settings.Save();
|
||||
});
|
||||
var onSelect = new Action<Map>(m =>
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("map " + m.Uid));
|
||||
Game.Settings.Server.Map = m.Uid;
|
||||
Game.Settings.Save();
|
||||
});
|
||||
|
||||
Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
|
||||
{
|
||||
{ "initialMap", Map.Uid },
|
||||
{ "onExit", () => {} },
|
||||
{ "onSelect", onSelect }
|
||||
});
|
||||
};
|
||||
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
|
||||
Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
|
||||
{
|
||||
{ "initialMap", Map.Uid },
|
||||
{ "onExit", () => {} },
|
||||
{ "onSelect", onSelect }
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
|
||||
if (slotsButton != null)
|
||||
{
|
||||
slotsButton.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null ||
|
||||
orderManager.LocalClient.IsReady || !orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots || !s.LockTeam);
|
||||
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
|
||||
!orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots || !s.LockTeam);
|
||||
|
||||
var aiModes = Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name);
|
||||
slotsButton.OnMouseDown = _ =>
|
||||
@@ -213,7 +221,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
});
|
||||
}
|
||||
|
||||
options.Add("Bots", botOptions);
|
||||
options.Add("Configure Bots", botOptions);
|
||||
}
|
||||
|
||||
var teamCount = (orderManager.LobbyInfo.Slots.Count(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null) + 1) / 2;
|
||||
@@ -226,7 +234,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
OnClick = () => orderManager.IssueOrder(Order.Command("assignteams {0}".F(d.ToString())))
|
||||
});
|
||||
|
||||
options.Add("Teams", teamOptions);
|
||||
options.Add("Configure Teams", teamOptions);
|
||||
}
|
||||
|
||||
Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||
@@ -239,42 +247,59 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
};
|
||||
}
|
||||
|
||||
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
|
||||
disconnectButton.OnClick = () => { CloseWindow(); onExit(); };
|
||||
var optionsBin = Ui.LoadWidget("LOBBY_OPTIONS_BIN", lobby, new WidgetArgs());
|
||||
optionsBin.IsVisible = () => panel == PanelType.Options;
|
||||
|
||||
var allowCheats = lobby.Get<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
|
||||
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
|
||||
allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null
|
||||
|| orderManager.LocalClient.IsReady;
|
||||
allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||
var optionsButton = lobby.Get<ButtonWidget>("OPTIONS_BUTTON");
|
||||
optionsButton.IsDisabled = () => panel == PanelType.Kick;
|
||||
optionsButton.GetText = () => panel == PanelType.Options ? "Players" : "Options";
|
||||
optionsButton.OnClick = () => panel = (panel == PanelType.Options) ? PanelType.Players : PanelType.Options;
|
||||
|
||||
var startGameButton = lobby.GetOrNull<ButtonWidget>("START_GAME_BUTTON");
|
||||
if (startGameButton != null)
|
||||
{
|
||||
startGameButton.IsDisabled = () => configurationDisabled() ||
|
||||
orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null);
|
||||
startGameButton.OnClick = () =>
|
||||
{
|
||||
gameStarting = true;
|
||||
orderManager.IssueOrder(Order.Command("startgame"));
|
||||
};
|
||||
}
|
||||
|
||||
// Options panel
|
||||
var allowCheats = optionsBin.GetOrNull<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
|
||||
if (allowCheats != null)
|
||||
{
|
||||
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
|
||||
allowCheats.IsDisabled = configurationDisabled;
|
||||
allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
|
||||
}
|
||||
|
||||
var crates = lobby.GetOrNull<CheckboxWidget>("CRATES_CHECKBOX");
|
||||
var crates = optionsBin.GetOrNull<CheckboxWidget>("CRATES_CHECKBOX");
|
||||
if (crates != null)
|
||||
{
|
||||
crates.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Crates;
|
||||
crates.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null
|
||||
|| orderManager.LocalClient.IsReady; // maybe disable the checkbox if a map forcefully removes CrateDrop?
|
||||
crates.IsDisabled = configurationDisabled;
|
||||
crates.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||
"crates {0}".F(!orderManager.LobbyInfo.GlobalSettings.Crates)));
|
||||
}
|
||||
|
||||
var fragileAlliance = lobby.GetOrNull<CheckboxWidget>("FRAGILEALLIANCES_CHECKBOX");
|
||||
var fragileAlliance = optionsBin.GetOrNull<CheckboxWidget>("FRAGILEALLIANCES_CHECKBOX");
|
||||
if (fragileAlliance != null)
|
||||
{
|
||||
fragileAlliance.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.FragileAlliances;
|
||||
fragileAlliance.IsDisabled = () => !Game.IsHost || gameStarting
|
||||
|| orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
|
||||
fragileAlliance.IsDisabled = configurationDisabled;
|
||||
fragileAlliance.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||
"fragilealliance {0}".F(!orderManager.LobbyInfo.GlobalSettings.FragileAlliances)));
|
||||
};
|
||||
|
||||
|
||||
var difficulty = lobby.GetOrNull<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON");
|
||||
var difficulty = optionsBin.GetOrNull<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON");
|
||||
if (difficulty != null)
|
||||
{
|
||||
difficulty.IsVisible = () => Map != null && Map.Difficulties != null && Map.Difficulties.Any();
|
||||
difficulty.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
|
||||
difficulty.IsDisabled = configurationDisabled;
|
||||
difficulty.GetText = () => orderManager.LobbyInfo.GlobalSettings.Difficulty;
|
||||
difficulty.OnMouseDown = _ =>
|
||||
{
|
||||
@@ -292,17 +317,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
};
|
||||
difficulty.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
|
||||
};
|
||||
|
||||
var difficultyDesc = optionsBin.GetOrNull<LabelWidget>("DIFFICULTY_DESC");
|
||||
difficultyDesc.IsVisible = difficulty.IsVisible;
|
||||
}
|
||||
|
||||
var startGameButton = lobby.Get<ButtonWidget>("START_GAME_BUTTON");
|
||||
startGameButton.IsVisible = () => Game.IsHost;
|
||||
startGameButton.IsDisabled = () => gameStarting
|
||||
|| orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null);
|
||||
startGameButton.OnClick = () =>
|
||||
{
|
||||
gameStarting = true;
|
||||
orderManager.IssueOrder(Order.Command("startgame"));
|
||||
};
|
||||
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
|
||||
disconnectButton.OnClick = () => { CloseWindow(); onExit(); };
|
||||
|
||||
bool teamChat = false;
|
||||
var chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE");
|
||||
@@ -401,8 +422,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
void UpdatePlayerList()
|
||||
{
|
||||
var idx = 0;
|
||||
TeamGame = false;
|
||||
|
||||
foreach (var kv in orderManager.LobbyInfo.Slots)
|
||||
{
|
||||
var key = kv.Key;
|
||||
@@ -449,9 +468,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
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;
|
||||
}
|
||||
else
|
||||
{ // Non-editable player in slot
|
||||
@@ -460,7 +476,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null);
|
||||
LobbyUtils.SetupNameWidget(template, slot, client);
|
||||
LobbyUtils.SetupKickWidget(template, slot, client, orderManager, lobby);
|
||||
LobbyUtils.SetupKickWidget(template, slot, client, orderManager, lobby,
|
||||
() => panel = PanelType.Kick, () => panel = PanelType.Players);
|
||||
LobbyUtils.SetupColorWidget(template, slot, client);
|
||||
LobbyUtils.SetupFactionWidget(template, slot, client, CountryNames);
|
||||
LobbyUtils.SetupTeamWidget(template, slot, client);
|
||||
@@ -502,7 +519,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
template = NonEditableSpectatorTemplate.Clone();
|
||||
|
||||
LobbyUtils.SetupNameWidget(template, null, client);
|
||||
LobbyUtils.SetupKickWidget(template, null, client, orderManager, lobby);
|
||||
LobbyUtils.SetupKickWidget(template, null, client, orderManager, lobby,
|
||||
() => panel = PanelType.Kick, () => panel = PanelType.Players);
|
||||
}
|
||||
|
||||
LobbyUtils.SetupClientWidget(template, null, c, orderManager, true);
|
||||
|
||||
Reference in New Issue
Block a user