Quick and extremely hacky server browser for chrisf
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Server;
|
||||
|
||||
namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
public interface IWidgetDelegate { bool OnClick(Widget w, MouseInput mi); }
|
||||
|
||||
public class MainMenuButtonsDelegate : IWidgetDelegate
|
||||
{
|
||||
{
|
||||
public bool OnClick(Widget w, MouseInput mi)
|
||||
{
|
||||
// Main Menu root
|
||||
@@ -18,12 +20,6 @@ namespace OpenRA.Widgets.Delegates
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "MAINMENU_BUTTON_JOIN")
|
||||
{
|
||||
Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "MAINMENU_BUTTON_CREATE")
|
||||
{
|
||||
WidgetLoader.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
|
||||
@@ -45,6 +41,60 @@ namespace OpenRA.Widgets.Delegates
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user