Merge pull request #9744 from pchote/serverbrowser

Redesign the MP server browser.
This commit is contained in:
Matthias Mailänder
2015-10-25 07:32:04 +01:00
44 changed files with 1295 additions and 917 deletions

View File

@@ -566,7 +566,6 @@
<Compile Include="Widgets\Logic\ConnectionLogic.cs" />
<Compile Include="Widgets\Logic\FactionTooltipLogic.cs" />
<Compile Include="Widgets\Logic\CreditsLogic.cs" />
<Compile Include="Widgets\Logic\DirectConnectLogic.cs" />
<Compile Include="Widgets\Logic\DisconnectWatcherLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\AddFactionSuffixLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\ClassicProductionLogic.cs" />
@@ -620,7 +619,6 @@
<Compile Include="Widgets\Logic\MusicPlayerLogic.cs" />
<Compile Include="Widgets\Logic\PerfDebugLogic.cs" />
<Compile Include="Widgets\Logic\ReplayBrowserLogic.cs" />
<Compile Include="Widgets\Logic\ServerBrowserLogic.cs" />
<Compile Include="Widgets\Logic\ServerCreationLogic.cs" />
<Compile Include="Widgets\Logic\SettingsLogic.cs" />
<Compile Include="Widgets\Logic\SimpleTooltipLogic.cs" />
@@ -706,6 +704,7 @@
<Compile Include="Widgets\Logic\GlobalChatLogic.cs" />
<Compile Include="Lint\CheckChromeLogic.cs" />
<Compile Include="Lint\CheckMapMetadata.cs" />
<Compile Include="Widgets\Logic\MultiplayerLogic.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

View File

@@ -1,43 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
public class DirectConnectLogic : ChromeLogic
{
[ObjectCreator.UseCtor]
public DirectConnectLogic(Widget widget, Action onExit, Action openLobby)
{
var panel = widget;
var ipField = panel.Get<TextFieldWidget>("IP");
var portField = panel.Get<TextFieldWidget>("PORT");
var last = Game.Settings.Player.LastServer.Split(':');
ipField.Text = last.Length > 1 ? last[0] : "localhost";
portField.Text = last.Length == 2 ? last[1] : "1234";
panel.Get<ButtonWidget>("JOIN_BUTTON").OnClick = () =>
{
var port = Exts.WithDefault(1234, () => Exts.ParseIntegerInvariant(portField.Text));
Game.Settings.Player.LastServer = "{0}:{1}".F(ipField.Text, port);
Game.Settings.Save();
Ui.CloseWindow();
ConnectionLogic.Connect(ipField.Text, port, "", openLobby, onExit);
};
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
}
}
}

View File

@@ -179,7 +179,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var spawnSize = new float2(ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed").Bounds.Size);
var selectedSpawn = preview.SpawnPoints
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(sp), i))
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(sp, preview.GridType), i))
.Where(a => ((a.First - mi.Location).ToFloat2() / spawnSize * 2).LengthSquared <= 1)
.Select(a => a.Second + 1)
.FirstOrDefault();

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("SERVERBROWSER_PANEL", new WidgetArgs
Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs
{
{ "onStart", RemoveShellmapUI },
{ "onExit", () => menuType = MenuType.Main },
@@ -220,7 +220,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.OnRemoteDirectConnect += (host, port) =>
{
menuType = MenuType.None;
Ui.OpenWindow("SERVERBROWSER_PANEL", new WidgetArgs
Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs
{
{ "onStart", RemoveShellmapUI },
{ "onExit", () => menuType = MenuType.Main },

View File

@@ -20,10 +20,14 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
public class ServerBrowserLogic : ChromeLogic
public class MultiplayerLogic : ChromeLogic
{
static readonly Action DoNothing = () => { };
enum PanelType { Browser, DirectConnect, CreateServer }
PanelType panel = PanelType.Browser;
readonly Color incompatibleVersionColor;
readonly Color incompatibleProtectedGameColor;
readonly Color protectedGameColor;
readonly Color incompatibleWaitingGameColor;
@@ -31,18 +35,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly Color incompatibleGameStartedColor;
readonly Color gameStartedColor;
readonly Color incompatibleGameColor;
readonly Color cantJoinGameColor;
GameServer currentServer;
MapPreview currentMap;
ScrollItemWidget serverTemplate;
ScrollItemWidget headerTemplate;
Action onStart;
Action onExit;
enum SearchStatus { Fetching, Failed, NoGames, Hidden }
SearchStatus searchStatus = SearchStatus.Fetching;
Download currentQuery;
Widget panel, serverList;
Widget serverList;
bool showWaiting = true;
bool showEmpty = true;
@@ -55,87 +61,52 @@ namespace OpenRA.Mods.Common.Widgets.Logic
switch (searchStatus)
{
case SearchStatus.Failed: return "Failed to contact master server.";
case SearchStatus.NoGames: return "No games found.";
case SearchStatus.NoGames: return "No games found. Try changing filters.";
default: return "";
}
}
[ObjectCreator.UseCtor]
public ServerBrowserLogic(Widget widget, Action onStart, Action onExit, string directConnectHost, int directConnectPort)
public MultiplayerLogic(Widget widget, Action onStart, Action onExit, string directConnectHost, int directConnectPort)
{
panel = widget;
this.onStart = onStart;
this.onExit = onExit;
incompatibleVersionColor = ChromeMetrics.Get<Color>("IncompatibleVersionColor");
incompatibleGameColor = ChromeMetrics.Get<Color>("IncompatibleGameColor");
cantJoinGameColor = ChromeMetrics.Get<Color>("CantJoinGameColor");
protectedGameColor = ChromeMetrics.Get<Color>("ProtectedGameColor");
incompatibleProtectedGameColor = ChromeMetrics.Get<Color>("IncompatibleProtectedGameColor");
protectedGameColor = ChromeMetrics.Get<Color>("ProtectedGameColor");
waitingGameColor = ChromeMetrics.Get<Color>("WaitingGameColor");
incompatibleWaitingGameColor = ChromeMetrics.Get<Color>("IncompatibleWaitingGameColor");
gameStartedColor = ChromeMetrics.Get<Color>("GameStartedColor");
incompatibleGameStartedColor = ChromeMetrics.Get<Color>("IncompatibleGameStartedColor");
serverList = panel.Get<ScrollPanelWidget>("SERVER_LIST");
headerTemplate = serverList.Get<ScrollItemWidget>("HEADER_TEMPLATE");
serverTemplate = serverList.Get<ScrollItemWidget>("SERVER_TEMPLATE");
LoadBrowserPanel(widget);
LoadDirectConnectPanel(widget);
LoadCreateServerPanel(widget);
// Menu buttons
var refreshButton = panel.Get<ButtonWidget>("REFRESH_BUTTON");
refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching;
refreshButton.GetText = () => searchStatus == SearchStatus.Fetching ? "Refreshing..." : "Refresh";
refreshButton.OnClick = RefreshServerList;
// Filter and refresh buttons act on the browser panel,
// but remain visible (disabled) on the other panels
var refreshButton = widget.Get<ButtonWidget>("REFRESH_BUTTON");
refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching || panel != PanelType.Browser;
panel.Get<ButtonWidget>("DIRECTCONNECT_BUTTON").OnClick = OpenDirectConnectPanel;
panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = OpenCreateServerPanel;
var filtersButton = widget.GetOrNull<DropDownButtonWidget>("FILTERS_DROPDOWNBUTTON");
filtersButton.IsDisabled = () => searchStatus == SearchStatus.Fetching || panel != PanelType.Browser;
var join = panel.Get<ButtonWidget>("JOIN_BUTTON");
join.IsDisabled = () => currentServer == null || !currentServer.IsJoinable;
join.OnClick = () => Join(currentServer);
var browserTab = widget.Get<ButtonWidget>("BROWSER_TAB");
browserTab.IsHighlighted = () => panel == PanelType.Browser;
browserTab.OnClick = () => panel = PanelType.Browser;
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
var directConnectTab = widget.Get<ButtonWidget>("DIRECTCONNECT_TAB");
directConnectTab.IsHighlighted = () => panel == PanelType.DirectConnect;
directConnectTab.OnClick = () => panel = PanelType.DirectConnect;
// Display the progress label over the server list
// The text is only visible when the list is empty
var progressText = panel.Get<LabelWidget>("PROGRESS_LABEL");
progressText.IsVisible = () => searchStatus != SearchStatus.Hidden;
progressText.GetText = ProgressLabelText;
var createServerTab = widget.Get<ButtonWidget>("CREATE_TAB");
createServerTab.IsHighlighted = () => panel == PanelType.CreateServer;
createServerTab.OnClick = () => panel = PanelType.CreateServer;
var showWaitingCheckbox = panel.GetOrNull<CheckboxWidget>("WAITING_FOR_PLAYERS");
if (showWaitingCheckbox != null)
{
showWaitingCheckbox.IsChecked = () => showWaiting;
showWaitingCheckbox.OnClick = () => { showWaiting ^= true; RefreshServerList(); };
}
var showEmptyCheckbox = panel.GetOrNull<CheckboxWidget>("EMPTY");
if (showEmptyCheckbox != null)
{
showEmptyCheckbox.IsChecked = () => showEmpty;
showEmptyCheckbox.OnClick = () => { showEmpty ^= true; RefreshServerList(); };
}
var showAlreadyStartedCheckbox = panel.GetOrNull<CheckboxWidget>("ALREADY_STARTED");
if (showAlreadyStartedCheckbox != null)
{
showAlreadyStartedCheckbox.IsChecked = () => showStarted;
showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; RefreshServerList(); };
}
var showProtectedCheckbox = panel.GetOrNull<CheckboxWidget>("PASSWORD_PROTECTED");
if (showProtectedCheckbox != null)
{
showProtectedCheckbox.IsChecked = () => showProtected;
showProtectedCheckbox.OnClick = () => { showProtected ^= true; RefreshServerList(); };
}
var showIncompatibleCheckbox = panel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION");
if (showIncompatibleCheckbox != null)
{
showIncompatibleCheckbox.IsChecked = () => showIncompatible;
showIncompatibleCheckbox.OnClick = () => { showIncompatible ^= true; RefreshServerList(); };
}
Game.LoadWidget(null, "GLOBALCHAT_PANEL", panel.Get("GLOBALCHAT_ROOT"), new WidgetArgs());
widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
Game.LoadWidget(null, "GLOBALCHAT_PANEL", widget.Get("GLOBALCHAT_ROOT"), new WidgetArgs());
RefreshServerList();
@@ -152,6 +123,158 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
}
void LoadBrowserPanel(Widget widget)
{
var browserPanel = Game.LoadWidget(null, "MULTIPLAYER_BROWSER_PANEL", widget.Get("TOP_PANELS_ROOT"), new WidgetArgs());
browserPanel.IsVisible = () => panel == PanelType.Browser;
serverList = browserPanel.Get<ScrollPanelWidget>("SERVER_LIST");
headerTemplate = serverList.Get<ScrollItemWidget>("HEADER_TEMPLATE");
serverTemplate = serverList.Get<ScrollItemWidget>("SERVER_TEMPLATE");
var join = widget.Get<ButtonWidget>("JOIN_BUTTON");
join.IsDisabled = () => currentServer == null || !currentServer.IsJoinable;
join.OnClick = () => Join(currentServer);
// Display the progress label over the server list
// The text is only visible when the list is empty
var progressText = widget.Get<LabelWidget>("PROGRESS_LABEL");
progressText.IsVisible = () => searchStatus != SearchStatus.Hidden;
progressText.GetText = ProgressLabelText;
var filtersPanel = Ui.LoadWidget("MULTIPLAYER_FILTER_PANEL", null, new WidgetArgs());
var showWaitingCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("WAITING_FOR_PLAYERS");
if (showWaitingCheckbox != null)
{
showWaitingCheckbox.IsChecked = () => showWaiting;
showWaitingCheckbox.OnClick = () => { showWaiting ^= true; RefreshServerList(); };
}
var showEmptyCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("EMPTY");
if (showEmptyCheckbox != null)
{
showEmptyCheckbox.IsChecked = () => showEmpty;
showEmptyCheckbox.OnClick = () => { showEmpty ^= true; RefreshServerList(); };
}
var showAlreadyStartedCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("ALREADY_STARTED");
if (showAlreadyStartedCheckbox != null)
{
showAlreadyStartedCheckbox.IsChecked = () => showStarted;
showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; RefreshServerList(); };
}
var showProtectedCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("PASSWORD_PROTECTED");
if (showProtectedCheckbox != null)
{
showProtectedCheckbox.IsChecked = () => showProtected;
showProtectedCheckbox.OnClick = () => { showProtected ^= true; RefreshServerList(); };
}
var showIncompatibleCheckbox = filtersPanel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION");
if (showIncompatibleCheckbox != null)
{
showIncompatibleCheckbox.IsChecked = () => showIncompatible;
showIncompatibleCheckbox.OnClick = () => { showIncompatible ^= true; RefreshServerList(); };
}
var filtersButton = widget.GetOrNull<DropDownButtonWidget>("FILTERS_DROPDOWNBUTTON");
if (filtersButton != null)
{
filtersButton.OnMouseDown = _ =>
{
filtersButton.RemovePanel();
filtersButton.AttachPanel(filtersPanel);
};
}
var refreshButton = widget.Get<ButtonWidget>("REFRESH_BUTTON");
refreshButton.GetText = () => searchStatus == SearchStatus.Fetching ? "Refreshing..." : "Refresh";
refreshButton.OnClick = RefreshServerList;
var mapPreview = widget.GetOrNull<MapPreviewWidget>("SELECTED_MAP_PREVIEW");
if (mapPreview != null)
mapPreview.Preview = () => currentMap;
var mapTitle = widget.GetOrNull<LabelWidget>("SELECTED_MAP");
if (mapTitle != null)
mapTitle.GetText = () => currentMap != null ? currentMap.Title : "No Server Selected";
var ip = widget.GetOrNull<LabelWidget>("SELECTED_IP");
if (ip != null)
{
ip.IsVisible = () => currentServer != null;
ip.GetText = () => currentServer.Address;
}
var status = widget.GetOrNull<LabelWidget>("SELECTED_STATUS");
if (status != null)
{
status.IsVisible = () => currentServer != null;
status.GetText = () => GetStateLabel(currentServer);
status.GetColor = () => GetStateColor(currentServer, status);
}
var modVersion = widget.GetOrNull<LabelWidget>("SELECTED_MOD_VERSION");
if (modVersion != null)
{
modVersion.IsVisible = () => currentServer != null;
modVersion.GetText = () => currentServer.ModLabel;
modVersion.GetColor = () => currentServer.IsCompatible ? modVersion.TextColor : incompatibleVersionColor;
}
var players = widget.GetOrNull<LabelWidget>("SELECTED_PLAYERS");
if (players != null)
{
players.IsVisible = () => currentServer != null;
players.GetText = () => PlayersLabel(currentServer);
}
}
void LoadDirectConnectPanel(Widget widget)
{
var directConnectPanel = Game.LoadWidget(null, "MULTIPLAYER_DIRECTCONNECT_PANEL",
widget.Get("TOP_PANELS_ROOT"), new WidgetArgs());
directConnectPanel.IsVisible = () => panel == PanelType.DirectConnect;
var ipField = directConnectPanel.Get<TextFieldWidget>("IP");
var portField = directConnectPanel.Get<TextFieldWidget>("PORT");
var last = Game.Settings.Player.LastServer.Split(':');
ipField.Text = last.Length > 1 ? last[0] : "localhost";
portField.Text = last.Length == 2 ? last[1] : "1234";
directConnectPanel.Get<ButtonWidget>("JOIN_BUTTON").OnClick = () =>
{
var port = Exts.WithDefault(1234, () => Exts.ParseIntegerInvariant(portField.Text));
Game.Settings.Player.LastServer = "{0}:{1}".F(ipField.Text, port);
Game.Settings.Save();
ConnectionLogic.Connect(ipField.Text, port, "", OpenLobby, DoNothing);
};
}
void LoadCreateServerPanel(Widget widget)
{
var createServerPanel = Game.LoadWidget(null, "MULTIPLAYER_CREATESERVER_PANEL",
widget.Get("TOP_PANELS_ROOT"), new WidgetArgs
{
{ "openLobby", OpenLobby },
{ "onExit", DoNothing }
});
createServerPanel.IsVisible = () => panel == PanelType.CreateServer;
}
string PlayersLabel(GameServer game)
{
return "{0}{1}{2}".F(
"{0} Player{1}".F(game.Players > 0 ? game.Players.ToString() : "No", game.Players != 1 ? "s" : ""),
game.Bots > 0 ? ", {0} Bot{1}".F(game.Bots, game.Bots != 1 ? "s" : "") : "",
game.Spectators > 0 ? ", {0} Spectator{1}".F(game.Spectators, game.Spectators != 1 ? "s" : "") : "");
}
void RefreshServerList()
{
// Query in progress
@@ -196,6 +319,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return 1;
}
void SelectServer(GameServer server)
{
currentServer = server;
currentMap = server != null ? Game.ModData.MapCache[server.Map] : null;
}
void RefreshServerListInner(IEnumerable<GameServer> games)
{
if (games == null)
@@ -205,6 +334,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
.OrderByDescending(g => GroupSortOrder(g.First()))
.ThenByDescending(g => g.Count());
ScrollItemWidget nextServerRow = null;
var rows = new List<Widget>();
foreach (var modGames in mods)
{
@@ -224,49 +354,39 @@ namespace OpenRA.Mods.Common.Widgets.Logic
continue;
var canJoin = game.IsJoinable;
var compatible = game.IsCompatible;
var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => currentServer = game, () => Join(game));
var map = Game.ModData.MapCache[game.Map];
var preview = item.GetOrNull<MapPreviewWidget>("MAP_PREVIEW");
if (preview != null)
preview.Preview = () => map;
var item = ScrollItemWidget.Setup(serverTemplate, () => currentServer == game, () => SelectServer(game), () => Join(game));
var title = item.GetOrNull<LabelWidget>("TITLE");
if (title != null)
{
title.GetText = () => game.Name;
title.GetColor = () => !compatible ? incompatibleGameColor : !canJoin ? cantJoinGameColor : title.TextColor;
title.GetColor = () => canJoin ? title.TextColor : incompatibleGameColor;
}
var maptitle = item.GetOrNull<LabelWidget>("MAP");
if (maptitle != null)
var password = item.GetOrNull<ImageWidget>("PASSWORD_PROTECTED");
if (password != null)
{
maptitle.GetText = () => map.Title;
maptitle.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : maptitle.TextColor;
password.IsVisible = () => game.Protected;
password.GetImageName = () => canJoin ? "protected" : "protected-disabled";
}
var players = item.GetOrNull<LabelWidget>("PLAYERS");
if (players != null)
{
players.GetText = () => "{0} / {1}".F(game.Players, game.MaxPlayers)
+ (game.Spectators > 0 ? " ({0} Spectator{1})".F(game.Spectators, game.Spectators > 1 ? "s" : "") : "");
players.GetColor = () => !compatible ? incompatibleGameColor : !canJoin ? cantJoinGameColor : players.TextColor;
+ (game.Spectators > 0 ? " + {0}".F(game.Spectators) : "");
players.GetColor = () => canJoin ? players.TextColor : incompatibleGameColor;
}
var state = item.GetOrNull<LabelWidget>("STATE");
var state = item.GetOrNull<LabelWidget>("STATUS");
if (state != null)
{
state.GetText = () => GetStateLabel(game);
state.GetColor = () => GetStateColor(game, state, !compatible || !canJoin);
}
var label = game.State >= (int)ServerState.GameStarted ?
"Playing" : "Waiting";
state.GetText = () => label;
var ip = item.GetOrNull<LabelWidget>("IP");
if (ip != null)
{
ip.GetText = () => game.Address;
ip.GetColor = () => !compatible ? incompatibleGameColor : !canJoin ? cantJoinGameColor : ip.TextColor;
var color = GetStateColor(game, state, !canJoin);
state.GetColor = () => color;
}
var location = item.GetOrNull<LabelWidget>("LOCATION");
@@ -274,9 +394,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
var cachedServerLocation = GeoIP.LookupCountry(game.Address.Split(':')[0]);
location.GetText = () => cachedServerLocation;
location.GetColor = () => !compatible ? incompatibleGameColor : !canJoin ? cantJoinGameColor : location.TextColor;
location.GetColor = () => canJoin ? location.TextColor : incompatibleGameColor;
}
if (currentServer != null && game.Address == currentServer.Address)
nextServerRow = item;
rows.Add(item);
}
}
@@ -284,7 +407,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.RunAfterTick(() =>
{
serverList.RemoveChildren();
currentServer = null;
SelectServer(null);
if (games == null)
{
@@ -292,13 +415,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return;
}
if (!games.Any())
if (!rows.Any())
{
searchStatus = SearchStatus.NoGames;
return;
}
currentServer = games.FirstOrDefault();
searchStatus = SearchStatus.Hidden;
// Search for any unknown maps
@@ -307,28 +429,39 @@ namespace OpenRA.Mods.Common.Widgets.Logic
foreach (var row in rows)
serverList.AddChild(row);
if (nextServerRow != null)
nextServerRow.OnClick();
});
}
void OpenLobby()
{
// Close the multiplayer browser
Ui.CloseWindow();
Action onLobbyExit = () =>
{
// Open a fresh copy of the multiplayer browser
Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs
{
{ "onStart", onStart },
{ "onExit", onExit },
{ "directConnectHost", null },
{ "directConnectPort", 0 },
});
Game.Disconnect();
};
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs
{
{ "onExit", Game.Disconnect },
{ "onStart", onStart },
{ "onExit", onLobbyExit },
{ "skirmishMode", false }
});
}
void OpenDirectConnectPanel()
{
Ui.OpenWindow("DIRECTCONNECT_PANEL", new WidgetArgs
{
{ "openLobby", OpenLobby },
{ "onExit", DoNothing }
});
}
void OpenCreateServerPanel()
{
Ui.OpenWindow("CREATESERVER_PANEL", new WidgetArgs
@@ -365,14 +498,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
label += " for {0} minute{1}".F(totalMinutes, totalMinutes > 1 ? "s" : "");
}
return game.Protected ? label + " (Password protected)" : label;
return label;
}
if (game.State == (int)ServerState.WaitingPlayers)
{
var label = "Waiting for players";
return game.Protected ? label + " (Password protected)" : label;
}
return game.Protected ? "Password protected" : "Waiting for players";
if (game.State == (int)ServerState.ShuttingDown)
return "Server shutting down";
@@ -380,14 +510,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return "Unknown server state";
}
Color GetStateColor(GameServer game, LabelWidget label, bool darkened)
Color GetStateColor(GameServer game, LabelWidget label, bool darkened = false)
{
if (!game.Protected && game.State == (int)ServerState.WaitingPlayers)
return darkened ? incompatibleWaitingGameColor : waitingGameColor;
if (game.Protected && game.State == (int)ServerState.WaitingPlayers)
return darkened ? incompatibleProtectedGameColor : protectedGameColor;
if (game.State == (int)ServerState.WaitingPlayers)
return darkened ? incompatibleWaitingGameColor : waitingGameColor;
if (game.State == (int)ServerState.GameStarted)
return darkened ? incompatibleGameStartedColor : gameStartedColor;
@@ -396,13 +526,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
bool Filtered(GameServer game)
{
if ((game.State == (int)ServerState.GameStarted) && !showStarted)
if (game.State == (int)ServerState.GameStarted && !showStarted)
return true;
if ((game.State == (int)ServerState.WaitingPlayers) && !showWaiting && game.Players != 0)
if (game.State == (int)ServerState.WaitingPlayers && !showWaiting && game.Players != 0)
return true;
if ((game.Players == 0) && !showEmpty)
if (game.Players == 0 && !showEmpty)
return true;
if (!game.IsCompatible && !showIncompatible)

View File

@@ -33,7 +33,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var settings = Game.Settings;
preview = Game.ModData.MapCache[WidgetUtils.ChooseInitialMap(Game.Settings.Server.Map)];
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = CreateAndJoin;
var mapButton = panel.GetOrNull<ButtonWidget>("MAP_BUTTON");
@@ -132,7 +131,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return;
}
Ui.CloseWindow();
ConnectionLogic.Connect(IPAddress.Loopback.ToString(), Game.Settings.Server.ListenPort, password, onCreate, onExit);
}
}

View File

@@ -61,8 +61,6 @@ namespace OpenRA.Mods.Common.Widgets
readonly SpriteFont spawnFont;
readonly Color spawnColor, spawnContrastColor;
readonly int2 spawnLabelOffset;
readonly int cellWidth;
readonly TileShape shape;
public Func<MapPreview> Preview = () => null;
public Func<Dictionary<CPos, SpawnOccupant>> SpawnOccupants = () => new Dictionary<CPos, SpawnOccupant>();
@@ -83,9 +81,6 @@ namespace OpenRA.Mods.Common.Widgets
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
shape = Game.ModData.Manifest.Get<MapGrid>().Type;
cellWidth = shape == TileShape.Diamond ? 2 : 1;
}
protected MapPreviewWidget(MapPreviewWidget other)
@@ -107,9 +102,6 @@ namespace OpenRA.Mods.Common.Widgets
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
shape = other.shape;
cellWidth = other.cellWidth;
}
public override Widget Clone() { return new MapPreviewWidget(this); }
@@ -138,10 +130,11 @@ namespace OpenRA.Mods.Common.Widgets
tooltipContainer.Value.RemoveTooltip();
}
public int2 ConvertToPreview(CPos cell)
public int2 ConvertToPreview(CPos cell, TileShape gridType)
{
var preview = Preview();
var point = cell.ToMPos(shape);
var point = cell.ToMPos(gridType);
var cellWidth = gridType == TileShape.Diamond ? 2 : 1;
var dx = (int)(previewScale * cellWidth * (point.U - preview.Bounds.Left));
var dy = (int)(previewScale * (point.V - preview.Bounds.Top));
@@ -180,10 +173,11 @@ namespace OpenRA.Mods.Common.Widgets
var colors = SpawnOccupants().ToDictionary(c => c.Key, c => c.Value.Color.RGB);
var spawnPoints = preview.SpawnPoints;
var gridType = preview.GridType;
foreach (var p in spawnPoints)
{
var owned = colors.ContainsKey(p);
var pos = ConvertToPreview(p);
var pos = ConvertToPreview(p, gridType);
var sprite = owned ? spawnClaimed : spawnUnclaimed;
var offset = new int2(sprite.Bounds.Width, sprite.Bounds.Height) / 2;