diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 4893d162f0..a57f9523c6 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -428,32 +428,6 @@ namespace OpenRA public void DrawMainMenu( World world ) { rootWidget.Draw(rgbaRenderer,renderer); - buttons.Clear(); - - var w = 250; - var h = 200; - var r = new Rectangle( 0, 0, w, h ); - DrawDialogBackground(r, "dialog"); - DrawCentered("OpenRA Main Menu", new int2(r.Left + w / 2, r.Top + 20), Color.White); - - - AddUiButton(new int2(r.Left + w/2, r.Top + 70), "Join Game", - _ => - { - Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort); - }); - - AddUiButton(new int2(r.Left + w/2, r.Top + 105), "Create Game", - _ => - { - Game.CreateServer(); - }); - - AddUiButton(new int2(r.Left + w/2, r.Top + 140), "Quit", - _ => - { - Game.Exit(); - }); } public void DrawLobby( World world ) diff --git a/OpenRA.Game/Chrome/ButtonWidget.cs b/OpenRA.Game/Chrome/ButtonWidget.cs index 93815077bd..2db5b904d0 100644 --- a/OpenRA.Game/Chrome/ButtonWidget.cs +++ b/OpenRA.Game/Chrome/ButtonWidget.cs @@ -1,4 +1,6 @@ using OpenRA.Graphics; +using OpenRA.Widgets.Actions; +using System; using System.Drawing; using System.Collections.Generic; @@ -7,16 +9,21 @@ namespace OpenRA.Widgets class ButtonWidget : Widget { public readonly string Text = null; - + public readonly string Action = null; + public override bool HandleInput(MouseInput mi) { - // TEMPORARY: Define a default mouse button event - quit the game - if (mi.Event == MouseInputEvent.Down && ClickRect.Contains(mi.Location.X,mi.Location.Y)) + if (Action != null && mi.Event == MouseInputEvent.Down && ClickRect.Contains(mi.Location.X,mi.Location.Y)) { - Game.Exit(); - return true; + foreach (var mod in WidgetLoader.WidgetActionAssemblies) + { + var act = (IWidgetAction)mod.First.CreateInstance(mod.Second + "."+Action); + if (act == null) return false; + Log.Write("Calling: "+mod.Second + "."+Action); + return act.OnClick(mi); + } + throw new InvalidOperationException("Cannot locate WidgetAction: {0}".F(Action)); } - return base.HandleInput(mi); } diff --git a/OpenRA.Game/Chrome/Widget.cs b/OpenRA.Game/Chrome/Widget.cs index 84d4bc39a3..ca9dcf3e9f 100644 --- a/OpenRA.Game/Chrome/Widget.cs +++ b/OpenRA.Game/Chrome/Widget.cs @@ -12,6 +12,7 @@ namespace OpenRA.Widgets public readonly int Y = 0; public readonly int Width = 0; public readonly int Height = 0; + public readonly List Children = new List(); public Rectangle Bounds { diff --git a/OpenRA.Game/Chrome/WidgetActions.cs b/OpenRA.Game/Chrome/WidgetActions.cs new file mode 100644 index 0000000000..d7ef195fe4 --- /dev/null +++ b/OpenRA.Game/Chrome/WidgetActions.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Drawing; +using OpenRA.FileFormats; +using OpenRA.Graphics; + +namespace OpenRA.Widgets.Actions +{ + public interface IWidgetAction { bool OnClick(MouseInput mi); } + + public class QuitButtonAction : IWidgetAction + { + public bool OnClick(MouseInput mi) + { + Game.Exit(); + return true; + } + } + + public class JoinServerButtonAction : IWidgetAction + { + public bool OnClick(MouseInput mi) + { + Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort); + return true; + } + } + + public class CreateServerButtonAction : IWidgetAction + { + public bool OnClick(MouseInput mi) + { + Game.CreateServer(); + return true; + } + } +} \ No newline at end of file diff --git a/OpenRA.Game/Chrome/WidgetLoader.cs b/OpenRA.Game/Chrome/WidgetLoader.cs index 79133c7c21..e01d4c0a57 100644 --- a/OpenRA.Game/Chrome/WidgetLoader.cs +++ b/OpenRA.Game/Chrome/WidgetLoader.cs @@ -1,6 +1,7 @@ using OpenRA.FileFormats; using OpenRA.Graphics; using OpenRA.Widgets; +using OpenRA.Widgets.Actions; using System; using System.Collections.Generic; using System.Drawing; @@ -12,6 +13,7 @@ namespace OpenRA class WidgetLoader { static Pair[] ModAssemblies; + public static Pair[] WidgetActionAssemblies; public static void LoadModAssemblies(Manifest m) { var asms = new List>(); @@ -23,6 +25,16 @@ namespace OpenRA foreach (var a in m.Assemblies) asms.Add(Pair.New(Assembly.LoadFile(Path.GetFullPath(a)), Path.GetFileNameWithoutExtension(a))); ModAssemblies = asms.ToArray(); + + asms.Clear(); + + // all the core stuff is in this assembly + asms.Add(Pair.New(typeof(IWidgetAction).Assembly, typeof(IWidgetAction).Namespace)); + + // add the mods + foreach (var a in m.Assemblies) + asms.Add(Pair.New(Assembly.LoadFile(Path.GetFullPath(a)), Path.GetFileNameWithoutExtension(a))); + WidgetActionAssemblies = asms.ToArray(); } public static Widget LoadWidget( MiniYaml node ) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index a0a114a5f7..d93de1848d 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -153,10 +153,12 @@ namespace OpenRA internal static void CreateServer() { + Log.Write("Creating server"); // todo: LobbyInfo is the wrong place for this. Server.Server.ServerMain(Settings.InternetServer, Settings.MasterServer, Settings.GameName, Settings.ListenPort, Settings.ExternalPort, LobbyInfo.GlobalSettings.Mods); - + + Log.Write("Joining server"); JoinServer(IPAddress.Loopback.ToString(), Settings.ListenPort); } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 184c5595b0..30a4cc14db 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -281,6 +281,7 @@ + diff --git a/mods/cnc/menus.yaml b/mods/cnc/menus.yaml index 54c8ea9ccd..14d3ee44f3 100644 --- a/mods/cnc/menus.yaml +++ b/mods/cnc/menus.yaml @@ -19,6 +19,7 @@ Background: Width:160 Height:25 Text:Join Game + Action:JoinServerButtonAction Button@MAINMENU_BUTTON_CREATE: Id:MAINMENU_BUTTON_CREATE X:445 @@ -26,6 +27,7 @@ Background: Width:160 Height:25 Text:Create Game + Action:CreateServerButtonAction Button@MAINMENU_BUTTON_QUIT: Id:MAINMENU_BUTTON_QUIT X:445 @@ -33,3 +35,4 @@ Background: Width:160 Height:25 Text:Quit + Action:QuitButtonAction