Widget actions and main menu
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Widget> Children = new List<Widget>();
|
||||
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.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<Assembly, string>[] ModAssemblies;
|
||||
public static Pair<Assembly, string>[] WidgetActionAssemblies;
|
||||
public static void LoadModAssemblies(Manifest m)
|
||||
{
|
||||
var asms = new List<Pair<Assembly, string>>();
|
||||
@@ -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 )
|
||||
|
||||
Reference in New Issue
Block a user