Widget actions and main menu
This commit is contained in:
@@ -428,32 +428,6 @@ namespace OpenRA
|
|||||||
public void DrawMainMenu( World world )
|
public void DrawMainMenu( World world )
|
||||||
{
|
{
|
||||||
rootWidget.Draw(rgbaRenderer,renderer);
|
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 )
|
public void DrawLobby( World world )
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Widgets.Actions;
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@@ -7,16 +9,21 @@ namespace OpenRA.Widgets
|
|||||||
class ButtonWidget : Widget
|
class ButtonWidget : Widget
|
||||||
{
|
{
|
||||||
public readonly string Text = null;
|
public readonly string Text = null;
|
||||||
|
public readonly string Action = null;
|
||||||
|
|
||||||
public override bool HandleInput(MouseInput mi)
|
public override bool HandleInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
// TEMPORARY: Define a default mouse button event - quit the game
|
if (Action != null && mi.Event == MouseInputEvent.Down && ClickRect.Contains(mi.Location.X,mi.Location.Y))
|
||||||
if (mi.Event == MouseInputEvent.Down && ClickRect.Contains(mi.Location.X,mi.Location.Y))
|
|
||||||
{
|
{
|
||||||
Game.Exit();
|
foreach (var mod in WidgetLoader.WidgetActionAssemblies)
|
||||||
return true;
|
{
|
||||||
|
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);
|
return base.HandleInput(mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace OpenRA.Widgets
|
|||||||
public readonly int Y = 0;
|
public readonly int Y = 0;
|
||||||
public readonly int Width = 0;
|
public readonly int Width = 0;
|
||||||
public readonly int Height = 0;
|
public readonly int Height = 0;
|
||||||
|
|
||||||
public readonly List<Widget> Children = new List<Widget>();
|
public readonly List<Widget> Children = new List<Widget>();
|
||||||
public Rectangle Bounds
|
public Rectangle Bounds
|
||||||
{
|
{
|
||||||
|
|||||||
36
OpenRA.Game/Chrome/WidgetActions.cs
Normal file
36
OpenRA.Game/Chrome/WidgetActions.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
using OpenRA.Widgets.Actions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
@@ -12,6 +13,7 @@ namespace OpenRA
|
|||||||
class WidgetLoader
|
class WidgetLoader
|
||||||
{
|
{
|
||||||
static Pair<Assembly, string>[] ModAssemblies;
|
static Pair<Assembly, string>[] ModAssemblies;
|
||||||
|
public static Pair<Assembly, string>[] WidgetActionAssemblies;
|
||||||
public static void LoadModAssemblies(Manifest m)
|
public static void LoadModAssemblies(Manifest m)
|
||||||
{
|
{
|
||||||
var asms = new List<Pair<Assembly, string>>();
|
var asms = new List<Pair<Assembly, string>>();
|
||||||
@@ -23,6 +25,16 @@ namespace OpenRA
|
|||||||
foreach (var a in m.Assemblies)
|
foreach (var a in m.Assemblies)
|
||||||
asms.Add(Pair.New(Assembly.LoadFile(Path.GetFullPath(a)), Path.GetFileNameWithoutExtension(a)));
|
asms.Add(Pair.New(Assembly.LoadFile(Path.GetFullPath(a)), Path.GetFileNameWithoutExtension(a)));
|
||||||
ModAssemblies = asms.ToArray();
|
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 )
|
public static Widget LoadWidget( MiniYaml node )
|
||||||
|
|||||||
@@ -153,10 +153,12 @@ namespace OpenRA
|
|||||||
|
|
||||||
internal static void CreateServer()
|
internal static void CreateServer()
|
||||||
{
|
{
|
||||||
|
Log.Write("Creating server");
|
||||||
// todo: LobbyInfo is the wrong place for this.
|
// todo: LobbyInfo is the wrong place for this.
|
||||||
Server.Server.ServerMain(Settings.InternetServer, Settings.MasterServer, Settings.GameName, Settings.ListenPort,
|
Server.Server.ServerMain(Settings.InternetServer, Settings.MasterServer, Settings.GameName, Settings.ListenPort,
|
||||||
Settings.ExternalPort, LobbyInfo.GlobalSettings.Mods);
|
Settings.ExternalPort, LobbyInfo.GlobalSettings.Mods);
|
||||||
|
|
||||||
|
Log.Write("Joining server");
|
||||||
JoinServer(IPAddress.Loopback.ToString(), Settings.ListenPort);
|
JoinServer(IPAddress.Loopback.ToString(), Settings.ListenPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,6 +281,7 @@
|
|||||||
<Compile Include="Chrome\Widget.cs" />
|
<Compile Include="Chrome\Widget.cs" />
|
||||||
<Compile Include="Chrome\BackgroundWidget.cs" />
|
<Compile Include="Chrome\BackgroundWidget.cs" />
|
||||||
<Compile Include="Chrome\LabelWidget.cs" />
|
<Compile Include="Chrome\LabelWidget.cs" />
|
||||||
|
<Compile Include="Chrome\WidgetActions.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ Background:
|
|||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Join Game
|
Text:Join Game
|
||||||
|
Action:JoinServerButtonAction
|
||||||
Button@MAINMENU_BUTTON_CREATE:
|
Button@MAINMENU_BUTTON_CREATE:
|
||||||
Id:MAINMENU_BUTTON_CREATE
|
Id:MAINMENU_BUTTON_CREATE
|
||||||
X:445
|
X:445
|
||||||
@@ -26,6 +27,7 @@ Background:
|
|||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Create Game
|
Text:Create Game
|
||||||
|
Action:CreateServerButtonAction
|
||||||
Button@MAINMENU_BUTTON_QUIT:
|
Button@MAINMENU_BUTTON_QUIT:
|
||||||
Id:MAINMENU_BUTTON_QUIT
|
Id:MAINMENU_BUTTON_QUIT
|
||||||
X:445
|
X:445
|
||||||
@@ -33,3 +35,4 @@ Background:
|
|||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Quit
|
Text:Quit
|
||||||
|
Action:QuitButtonAction
|
||||||
|
|||||||
Reference in New Issue
Block a user