remove plenty of redundant junk
This commit is contained in:
@@ -21,9 +21,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Server;
|
||||
using OpenRA.FileFormats;
|
||||
using System;
|
||||
using OpenRA.Server;
|
||||
|
||||
namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
@@ -36,10 +35,10 @@ namespace OpenRA.Widgets.Delegates
|
||||
|
||||
public ServerBrowserDelegate()
|
||||
{
|
||||
var r = Chrome.rootWidget;
|
||||
var r = Chrome.rootWidget;
|
||||
var bg = r.GetWidget("JOINSERVER_BG");
|
||||
var dc = r.GetWidget("DIRECTCONNECT_BG");
|
||||
|
||||
|
||||
MasterServerQuery.OnComplete += games => RefreshServerList(games);
|
||||
|
||||
r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi =>
|
||||
@@ -56,14 +55,14 @@ namespace OpenRA.Widgets.Delegates
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
bg.GetWidget("SERVER_INFO").IsVisible = () => currentServer != null;
|
||||
var preview = bg.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
||||
preview.Map = () => CurrentMap();
|
||||
preview.IsVisible = () => CurrentMap() != null;
|
||||
|
||||
|
||||
bg.GetWidget<LabelWidget>("SERVER_IP").GetText = () => currentServer.Address;
|
||||
bg.GetWidget<LabelWidget>("SERVER_MODS").GetText = () => string.Join( ",", currentServer.Mods );
|
||||
bg.GetWidget<LabelWidget>("SERVER_MODS").GetText = () => string.Join(",", currentServer.Mods);
|
||||
bg.GetWidget<LabelWidget>("MAP_TITLE").GetText = () => (CurrentMap() != null) ? CurrentMap().Title : "Unknown";
|
||||
bg.GetWidget<LabelWidget>("MAP_PLAYERS").GetText = () =>
|
||||
{
|
||||
@@ -71,11 +70,11 @@ namespace OpenRA.Widgets.Delegates
|
||||
return "";
|
||||
string ret = currentServer.Players.ToString();
|
||||
if (CurrentMap() != null)
|
||||
ret += "/"+CurrentMap().PlayerCount.ToString();
|
||||
ret += "/" + CurrentMap().PlayerCount.ToString();
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
var sl = bg.GetWidget<ListBoxWidget>("SERVER_LIST");
|
||||
ServerTemplate = sl.GetWidget<LabelWidget>("SERVER_TEMPLATE");
|
||||
|
||||
@@ -101,20 +100,20 @@ namespace OpenRA.Widgets.Delegates
|
||||
bg.GetWidget("DIRECTCONNECT_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
r.CloseWindow();
|
||||
|
||||
|
||||
dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text = Game.Settings.LastServer;
|
||||
r.OpenWindow("DIRECTCONNECT_BG");
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
bg.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
if (currentServer == null)
|
||||
return false;
|
||||
|
||||
|
||||
// Todo: Add an error dialog explaining why we aren't letting them join
|
||||
// Or even better, reject them server side and display the error in the connection failed dialog.
|
||||
|
||||
|
||||
// Don't bother joining a server with different mods... its only going to crash
|
||||
if (currentServer.Mods.SymmetricDifference(Game.LobbyInfo.GlobalSettings.Mods).Any())
|
||||
{
|
||||
@@ -122,56 +121,59 @@ namespace OpenRA.Widgets.Delegates
|
||||
System.Console.WriteLine("FIX THIS BUG YOU NOOB!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Prevent user joining a full server
|
||||
if (CurrentMap() != null && currentServer.Players >= CurrentMap().PlayerCount)
|
||||
{
|
||||
System.Console.WriteLine("Server is full; not connecting");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
r.CloseWindow();
|
||||
Game.JoinServer(currentServer.Address.Split(':')[0], int.Parse(currentServer.Address.Split(':')[1]));
|
||||
Game.SetGameId(currentServer.Id);
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
// Direct Connect
|
||||
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi => {
|
||||
|
||||
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
|
||||
var address = dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text;
|
||||
var cpts = address.Split(':').ToArray();
|
||||
if (cpts.Length != 2)
|
||||
return true;
|
||||
|
||||
|
||||
Game.Settings.LastServer = address;
|
||||
Game.Settings.Save();
|
||||
|
||||
|
||||
r.CloseWindow();
|
||||
Game.JoinServer(cpts[0], int.Parse(cpts[1]));
|
||||
return true;
|
||||
};
|
||||
|
||||
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi => {
|
||||
|
||||
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
r.CloseWindow();
|
||||
return r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp(mi);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
MapStub CurrentMap()
|
||||
{
|
||||
return (currentServer == null || !Game.AvailableMaps.ContainsKey(currentServer.Map)) ? null : Game.AvailableMaps[currentServer.Map];
|
||||
return (currentServer == null || !Game.AvailableMaps.ContainsKey(currentServer.Map))
|
||||
? null : Game.AvailableMaps[currentServer.Map];
|
||||
}
|
||||
|
||||
|
||||
void RefreshServerList(IEnumerable<GameServer> games)
|
||||
{
|
||||
var r = Chrome.rootWidget;
|
||||
var r = Chrome.rootWidget;
|
||||
var bg = r.GetWidget("JOINSERVER_BG");
|
||||
var sl = bg.GetWidget<ListBoxWidget>("SERVER_LIST");
|
||||
|
||||
sl.Children.Clear();
|
||||
currentServer = null;
|
||||
|
||||
|
||||
if (games == null)
|
||||
{
|
||||
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
@@ -187,26 +189,26 @@ namespace OpenRA.Widgets.Delegates
|
||||
}
|
||||
|
||||
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = false;
|
||||
|
||||
|
||||
int offset = ServerTemplate.Bounds.Y;
|
||||
int i = 0;
|
||||
foreach (var game in games.Where( g => g.State == 1 )) /* only "waiting for players" */
|
||||
{
|
||||
foreach (var game in games.Where(g => g.State == 1)) /* only "waiting for players" */
|
||||
{
|
||||
var template = ServerTemplate.Clone() as LabelWidget;
|
||||
template.Id = "JOIN_GAME_{0}".F(i);
|
||||
template.GetText = () => " {0} ({1})".F( /* /8 = hack */
|
||||
game.Name,
|
||||
game.Name,
|
||||
game.Address);
|
||||
template.GetBackground = () => ((currentServer == game) ? "dialog2" : null);
|
||||
template.OnMouseDown = mi => {currentServer = game; return true;};
|
||||
template.Parent = sl;
|
||||
|
||||
template.GetBackground = () => (currentServer == game) ? "dialog2" : null;
|
||||
template.OnMouseDown = mi => { currentServer = game; return true; };
|
||||
template.Parent = sl;
|
||||
|
||||
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
||||
template.IsVisible = () => true;
|
||||
sl.AddChild(template);
|
||||
|
||||
|
||||
if (i == 0) currentServer = game;
|
||||
|
||||
|
||||
offset += template.Bounds.Height;
|
||||
sl.ContentHeight += template.Bounds.Height;
|
||||
i++;
|
||||
|
||||
Reference in New Issue
Block a user