Quick and extremely hacky server browser for chrisf
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Server;
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
@@ -18,12 +20,6 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w.Id == "MAINMENU_BUTTON_JOIN")
|
|
||||||
{
|
|
||||||
Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (w.Id == "MAINMENU_BUTTON_CREATE")
|
if (w.Id == "MAINMENU_BUTTON_CREATE")
|
||||||
{
|
{
|
||||||
WidgetLoader.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
|
WidgetLoader.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
|
||||||
@@ -45,6 +41,60 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (w.Id == "JOINSERVER_BUTTON_CANCEL")
|
||||||
|
{
|
||||||
|
WidgetLoader.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
|
||||||
|
WidgetLoader.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ServerBrowserDelegate : IWidgetDelegate
|
||||||
|
{
|
||||||
|
IEnumerable<GameServer> GameList;
|
||||||
|
|
||||||
|
public bool OnClick(Widget w, MouseInput mi)
|
||||||
|
{
|
||||||
|
// Main Menu root
|
||||||
|
if (w.Id == "MAINMENU_BUTTON_JOIN")
|
||||||
|
{
|
||||||
|
WidgetLoader.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
|
||||||
|
Widget bg = WidgetLoader.rootWidget.GetWidget("JOINSERVER_BG");
|
||||||
|
bg.Visible = true;
|
||||||
|
|
||||||
|
int height = 50;
|
||||||
|
int width = 300;
|
||||||
|
int i = 0;
|
||||||
|
GameList = MasterServerQuery.GetGameList(Game.Settings.MasterServer);
|
||||||
|
|
||||||
|
foreach (var game in GameList)
|
||||||
|
{
|
||||||
|
ButtonWidget b = new ButtonWidget();
|
||||||
|
b.Bounds = new Rectangle(bg.Bounds.X + 10, bg.Bounds.Y + height, width, 25);
|
||||||
|
b.GetType().GetField("Id").SetValue( b, "JOIN_GAME_{0}".F(i));
|
||||||
|
b.GetType().GetField("Text").SetValue( b, "{0} ({1})".F(game.Name, game.Address));
|
||||||
|
b.GetType().GetField("Delegate").SetValue( b, "ServerBrowserDelegate");
|
||||||
|
|
||||||
|
b.EventBounds = b.Bounds;
|
||||||
|
bg.AddChild(b);
|
||||||
|
|
||||||
|
height += 35;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (w.Id.Substring(0,10) == "JOIN_GAME_")
|
||||||
|
{
|
||||||
|
int index = int.Parse(w.Id.Substring(10));
|
||||||
|
GameList = MasterServerQuery.GetGameList(Game.Settings.MasterServer);
|
||||||
|
var game = GameList.ElementAt(index);
|
||||||
|
Game.JoinServer(game.Address.Split(':')[0], int.Parse(game.Address.Split(':')[1]));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ Container:
|
|||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Join Game
|
Text:Join Game
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:ServerBrowserDelegate
|
||||||
Button@MAINMENU_BUTTON_CREATE:
|
Button@MAINMENU_BUTTON_CREATE:
|
||||||
Id:MAINMENU_BUTTON_CREATE
|
Id:MAINMENU_BUTTON_CREATE
|
||||||
X:45
|
X:45
|
||||||
@@ -84,3 +84,27 @@ Container:
|
|||||||
Height:25
|
Height:25
|
||||||
Text:Create
|
Text:Create
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:MainMenuButtonsDelegate
|
||||||
|
Background@JOINSERVER_BG:
|
||||||
|
Id:JOINSERVER_BG
|
||||||
|
X:WINDOW_RIGHT/2 - 225
|
||||||
|
Y:200
|
||||||
|
Width:450
|
||||||
|
Height:400
|
||||||
|
Visible:false
|
||||||
|
Children:
|
||||||
|
Label@JOINSERVER_LABEL_TITLE:
|
||||||
|
Id:JOINSERVER_LABEL_TITLE
|
||||||
|
X:0
|
||||||
|
Y:20
|
||||||
|
Width:250
|
||||||
|
Height:25
|
||||||
|
Text:Quick'n'dirty Server Browser
|
||||||
|
Align:Center
|
||||||
|
Button@JOINSERVER_BUTTON_CANCEL:
|
||||||
|
Id:JOINSERVER_BUTTON_CANCEL
|
||||||
|
X:PARENT_RIGHT - 170
|
||||||
|
Y:PARENT_BOTTOM - 35
|
||||||
|
Width:160
|
||||||
|
Height:25
|
||||||
|
Text:Cancel
|
||||||
|
Delegate:MainMenuButtonsDelegate
|
||||||
Reference in New Issue
Block a user