Checkboxes, Delegates, Create Server.
This commit is contained in:
@@ -25,6 +25,10 @@ namespace OpenRA.Widgets
|
|||||||
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
|
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
|
||||||
return base.HandleInput(mi);
|
return base.HandleInput(mi);
|
||||||
|
|
||||||
|
|
||||||
|
if (base.HandleInput(mi))
|
||||||
|
return true;
|
||||||
|
|
||||||
// Give button focus only while the mouse is down
|
// Give button focus only while the mouse is down
|
||||||
// This is a bit of a hack: it will become cleaner soonish
|
// This is a bit of a hack: it will become cleaner soonish
|
||||||
// It will also steal events from any potential children
|
// It will also steal events from any potential children
|
||||||
@@ -36,7 +40,7 @@ namespace OpenRA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.HandleInput(mi);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
|
|||||||
53
OpenRA.Game/Chrome/CheckboxWidget.cs
Normal file
53
OpenRA.Game/Chrome/CheckboxWidget.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using OpenRA.Graphics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace OpenRA.Widgets
|
||||||
|
{
|
||||||
|
class CheckboxWidget : Widget
|
||||||
|
{
|
||||||
|
public override void Draw()
|
||||||
|
{
|
||||||
|
if (!Visible)
|
||||||
|
{
|
||||||
|
base.Draw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool selected = false;
|
||||||
|
if (InputHandler.Value != null)
|
||||||
|
selected = InputHandler.Value.GetState(this);
|
||||||
|
|
||||||
|
string collection = (selected) ? "dialog3" : "dialog2";
|
||||||
|
|
||||||
|
Game.chrome.renderer.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height);
|
||||||
|
string[] images = { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" };
|
||||||
|
var ss = Graphics.Util.MakeArray(9, n => ChromeProvider.GetImage(Game.chrome.renderer, collection,images[n]));
|
||||||
|
|
||||||
|
for( var x = Bounds.Left + (int)ss[2].size.X; x < Bounds.Right - (int)ss[3].size.X; x += (int)ss[8].size.X )
|
||||||
|
for( var y = Bounds.Top + (int)ss[0].size.Y; y < Bounds.Bottom - (int)ss[1].size.Y; y += (int)ss[8].size.Y )
|
||||||
|
Game.chrome.rgbaRenderer.DrawSprite(ss[8], new float2(x, y), "chrome");
|
||||||
|
|
||||||
|
//draw borders
|
||||||
|
for (var y = Bounds.Top + (int)ss[0].size.Y; y < Bounds.Bottom - (int)ss[1].size.Y; y += (int)ss[2].size.Y)
|
||||||
|
{
|
||||||
|
Game.chrome.rgbaRenderer.DrawSprite(ss[2], new float2(Bounds.Left, y), "chrome");
|
||||||
|
Game.chrome.rgbaRenderer.DrawSprite(ss[3], new float2(Bounds.Right - ss[3].size.X, y), "chrome");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var x = Bounds.Left + (int)ss[2].size.X; x < Bounds.Right - (int)ss[3].size.X; x += (int)ss[0].size.X)
|
||||||
|
{
|
||||||
|
Game.chrome.rgbaRenderer.DrawSprite(ss[0], new float2(x, Bounds.Top), "chrome");
|
||||||
|
Game.chrome.rgbaRenderer.DrawSprite(ss[1], new float2(x, Bounds.Bottom - ss[1].size.Y), "chrome");
|
||||||
|
}
|
||||||
|
|
||||||
|
Game.chrome.rgbaRenderer.DrawSprite(ss[4], new float2(Bounds.Left, Bounds.Top), "chrome");
|
||||||
|
Game.chrome.rgbaRenderer.DrawSprite(ss[5], new float2(Bounds.Right - ss[5].size.X, Bounds.Top), "chrome");
|
||||||
|
Game.chrome.rgbaRenderer.DrawSprite(ss[6], new float2(Bounds.Left, Bounds.Bottom - ss[6].size.Y), "chrome");
|
||||||
|
Game.chrome.rgbaRenderer.DrawSprite(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y), "chrome");
|
||||||
|
Game.chrome.rgbaRenderer.Flush();
|
||||||
|
Game.chrome.renderer.Device.DisableScissor();
|
||||||
|
|
||||||
|
base.Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,27 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Net;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Server;
|
using OpenRA.Server;
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
public interface IWidgetDelegate { bool OnClick(Widget w, MouseInput mi); }
|
public class WidgetDelegate
|
||||||
|
|
||||||
public class MainMenuButtonsDelegate : IWidgetDelegate
|
|
||||||
{
|
{
|
||||||
public bool OnClick(Widget w, MouseInput mi)
|
// For checkboxes
|
||||||
|
public virtual bool GetState(Widget w) { return false; }
|
||||||
|
|
||||||
|
// For any widget
|
||||||
|
public virtual bool OnMouseDown(Widget w, MouseInput mi) { return false; }
|
||||||
|
public virtual bool OnMouseUp(Widget w, MouseInput mi) { return false; }
|
||||||
|
public virtual bool OnMouseMove(Widget w, MouseInput mi) { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MainMenuButtonsDelegate : WidgetDelegate
|
||||||
|
{
|
||||||
|
public override bool OnMouseUp(Widget w, MouseInput mi)
|
||||||
{
|
{
|
||||||
// Main Menu root
|
// Main Menu root
|
||||||
if (w.Id == "MAINMENU_BUTTON_QUIT")
|
if (w.Id == "MAINMENU_BUTTON_QUIT")
|
||||||
@@ -19,7 +29,35 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
Game.Exit();
|
Game.Exit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateServerMenuDelegate : WidgetDelegate
|
||||||
|
{
|
||||||
|
static bool AdvertiseServerOnline = Game.Settings.InternetServer;
|
||||||
|
|
||||||
|
public override bool GetState(Widget w)
|
||||||
|
{
|
||||||
|
if (w.Id == "CREATESERVER_CHECKBOX_ONLINE")
|
||||||
|
return AdvertiseServerOnline;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool OnMouseDown(Widget w, MouseInput mi)
|
||||||
|
{
|
||||||
|
if (w.Id == "CREATESERVER_CHECKBOX_ONLINE")
|
||||||
|
{
|
||||||
|
AdvertiseServerOnline = !AdvertiseServerOnline;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool OnMouseUp(Widget w, MouseInput mi)
|
||||||
|
{
|
||||||
if (w.Id == "MAINMENU_BUTTON_CREATE")
|
if (w.Id == "MAINMENU_BUTTON_CREATE")
|
||||||
{
|
{
|
||||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
|
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
|
||||||
@@ -27,7 +65,6 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Create Server" submenu
|
|
||||||
if (w.Id == "CREATESERVER_BUTTON_CANCEL")
|
if (w.Id == "CREATESERVER_BUTTON_CANCEL")
|
||||||
{
|
{
|
||||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||||
@@ -38,7 +75,14 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
if (w.Id == "CREATESERVER_BUTTON_START")
|
if (w.Id == "CREATESERVER_BUTTON_START")
|
||||||
{
|
{
|
||||||
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
|
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
|
||||||
Game.CreateServer();
|
Log.Write("Creating server");
|
||||||
|
|
||||||
|
Server.Server.ServerMain(AdvertiseServerOnline, Game.Settings.MasterServer,
|
||||||
|
Game.Settings.GameName, Game.Settings.ListenPort,
|
||||||
|
Game.Settings.ExternalPort, Game.Settings.InitialMods);
|
||||||
|
|
||||||
|
Log.Write("Joining server");
|
||||||
|
Game.JoinServer(IPAddress.Loopback.ToString(), Game.Settings.ListenPort);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,12 +90,12 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ServerBrowserDelegate : IWidgetDelegate
|
public class ServerBrowserDelegate : WidgetDelegate
|
||||||
{
|
{
|
||||||
static GameServer[] GameList;
|
static GameServer[] GameList;
|
||||||
static List<Widget> GameButtons = new List<Widget>();
|
static List<Widget> GameButtons = new List<Widget>();
|
||||||
|
|
||||||
public bool OnClick(Widget w, MouseInput mi)
|
public override bool OnMouseUp(Widget w, MouseInput mi)
|
||||||
{
|
{
|
||||||
// Main Menu root
|
// Main Menu root
|
||||||
if (w.Id == "MAINMENU_BUTTON_JOIN")
|
if (w.Id == "MAINMENU_BUTTON_JOIN")
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRA.Widgets
|
|||||||
public readonly string Height = "0";
|
public readonly string Height = "0";
|
||||||
public readonly string Delegate = null;
|
public readonly string Delegate = null;
|
||||||
|
|
||||||
public Lazy<IWidgetDelegate> InputHandler;
|
public Lazy<WidgetDelegate> InputHandler;
|
||||||
|
|
||||||
public bool Visible = true;
|
public bool Visible = true;
|
||||||
public readonly List<Widget> Children = new List<Widget>();
|
public readonly List<Widget> Children = new List<Widget>();
|
||||||
@@ -61,13 +61,13 @@ namespace OpenRA.Widgets
|
|||||||
.Aggregate(Bounds, Rectangle.Union);
|
.Aggregate(Bounds, Rectangle.Union);
|
||||||
}
|
}
|
||||||
|
|
||||||
static IWidgetDelegate BindHandler(string name)
|
static WidgetDelegate BindHandler(string name)
|
||||||
{
|
{
|
||||||
if (name == null) return null;
|
if (name == null) return null;
|
||||||
|
|
||||||
foreach (var mod in Game.ModAssemblies)
|
foreach (var mod in Game.ModAssemblies)
|
||||||
{
|
{
|
||||||
var act = (IWidgetDelegate)mod.First.CreateInstance(mod.Second + "." + name);
|
var act = (WidgetDelegate)mod.First.CreateInstance(mod.Second + "." + name);
|
||||||
if (act != null) return act;
|
if (act != null) return act;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,10 +86,16 @@ namespace OpenRA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Mousedown
|
// Mousedown
|
||||||
// todo: route the other events too!
|
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Down)
|
||||||
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Up)
|
return InputHandler.Value.OnMouseDown(this, mi);
|
||||||
return InputHandler.Value.OnClick(this, mi);
|
|
||||||
|
|
||||||
|
// Mouseup
|
||||||
|
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Up)
|
||||||
|
return InputHandler.Value.OnMouseUp(this, mi);
|
||||||
|
|
||||||
|
// Mousemove
|
||||||
|
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Move)
|
||||||
|
return InputHandler.Value.OnMouseMove(this, mi);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,17 +156,6 @@ namespace OpenRA
|
|||||||
orderManager = new OrderManager(new EchoConnection());
|
orderManager = new OrderManager(new EchoConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lastTime = Environment.TickCount;
|
static int lastTime = Environment.TickCount;
|
||||||
|
|
||||||
public static void ResetTimer()
|
public static void ResetTimer()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -284,6 +284,7 @@
|
|||||||
<Compile Include="Chrome\BackgroundWidget.cs" />
|
<Compile Include="Chrome\BackgroundWidget.cs" />
|
||||||
<Compile Include="Chrome\LabelWidget.cs" />
|
<Compile Include="Chrome\LabelWidget.cs" />
|
||||||
<Compile Include="Chrome\DefaultWidgetDelegates.cs" />
|
<Compile Include="Chrome\DefaultWidgetDelegates.cs" />
|
||||||
|
<Compile Include="Chrome\CheckboxWidget.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ Container:
|
|||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Create Game
|
Text:Create Game
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:CreateServerMenuDelegate
|
||||||
Button@MAINMENU_BUTTON_QUIT:
|
Button@MAINMENU_BUTTON_QUIT:
|
||||||
Id:MAINMENU_BUTTON_QUIT
|
Id:MAINMENU_BUTTON_QUIT
|
||||||
X:45
|
X:45
|
||||||
@@ -55,35 +55,36 @@ Container:
|
|||||||
Height:25
|
Height:25
|
||||||
Text:Create Server
|
Text:Create Server
|
||||||
Align:Center
|
Align:Center
|
||||||
Button@CREATESERVER_CHECKBOX_HIDDEN:
|
Checkbox@CREATESERVER_CHECKBOX_ONLINE:
|
||||||
Id:CREATESERVER_CHECKBOX_HIDDEN
|
Id:CREATESERVER_CHECKBOX_ONLINE
|
||||||
X:100
|
X:100
|
||||||
Y:60
|
Y:60
|
||||||
Width:20
|
Width:20
|
||||||
Height:20
|
Height:20
|
||||||
Label@CREATESERVER_LABEL_HIDDENGAME:
|
Delegate:CreateServerMenuDelegate
|
||||||
Id:CREATESERVER_LABEL_HIDDENGAME
|
Label@CREATESERVER_LABEL_ONLINE:
|
||||||
|
Id:CREATESERVER_LABEL_ONLINE
|
||||||
X:135
|
X:135
|
||||||
Y:60
|
Y:60
|
||||||
Width:300
|
Width:300
|
||||||
Height:25
|
Height:25
|
||||||
Text:Hide from Server Browser
|
Text:Advertise game Online
|
||||||
Button@CREATESERVER_BUTTON_CANCEL:
|
Button@CREATESERVER_BUTTON_START:
|
||||||
Id:CREATESERVER_BUTTON_CANCEL
|
Id:CREATESERVER_BUTTON_START
|
||||||
X:100
|
X:100
|
||||||
Y:100
|
Y:100
|
||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Cancel
|
Text:Create
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:CreateServerMenuDelegate
|
||||||
Button@CREATESERVER_BUTTON_START:
|
Button@CREATESERVER_BUTTON_CANCEL:
|
||||||
Id:CREATESERVER_BUTTON_START
|
Id:CREATESERVER_BUTTON_CANCEL
|
||||||
X:270
|
X:270
|
||||||
Y:100
|
Y:100
|
||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Create
|
Text:Cancel
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:CreateServerMenuDelegate
|
||||||
Background@JOINSERVER_BG:
|
Background@JOINSERVER_BG:
|
||||||
Id:JOINSERVER_BG
|
Id:JOINSERVER_BG
|
||||||
X:WINDOW_RIGHT/2 - 225
|
X:WINDOW_RIGHT/2 - 225
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ Container:
|
|||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Create Game
|
Text:Create Game
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:CreateServerMenuDelegate
|
||||||
Button@MAINMENU_BUTTON_QUIT:
|
Button@MAINMENU_BUTTON_QUIT:
|
||||||
Id:MAINMENU_BUTTON_QUIT
|
Id:MAINMENU_BUTTON_QUIT
|
||||||
X:45
|
X:45
|
||||||
@@ -55,35 +55,36 @@ Container:
|
|||||||
Height:25
|
Height:25
|
||||||
Text:Create Server
|
Text:Create Server
|
||||||
Align:Center
|
Align:Center
|
||||||
Button@CREATESERVER_CHECKBOX_HIDDEN:
|
Checkbox@CREATESERVER_CHECKBOX_ONLINE:
|
||||||
Id:CREATESERVER_CHECKBOX_HIDDEN
|
Id:CREATESERVER_CHECKBOX_ONLINE
|
||||||
X:100
|
X:100
|
||||||
Y:60
|
Y:60
|
||||||
Width:20
|
Width:20
|
||||||
Height:20
|
Height:20
|
||||||
Label@CREATESERVER_LABEL_HIDDENGAME:
|
Delegate:CreateServerMenuDelegate
|
||||||
Id:CREATESERVER_LABEL_HIDDENGAME
|
Label@CREATESERVER_LABEL_ONLINE:
|
||||||
|
Id:CREATESERVER_LABEL_ONLINE
|
||||||
X:135
|
X:135
|
||||||
Y:60
|
Y:60
|
||||||
Width:300
|
Width:300
|
||||||
Height:25
|
Height:25
|
||||||
Text:Hide from Server Browser
|
Text:Advertise game Online
|
||||||
Button@CREATESERVER_BUTTON_CANCEL:
|
Button@CREATESERVER_BUTTON_START:
|
||||||
Id:CREATESERVER_BUTTON_CANCEL
|
Id:CREATESERVER_BUTTON_START
|
||||||
X:100
|
X:100
|
||||||
Y:100
|
Y:100
|
||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Cancel
|
Text:Create
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:CreateServerMenuDelegate
|
||||||
Button@CREATESERVER_BUTTON_START:
|
Button@CREATESERVER_BUTTON_CANCEL:
|
||||||
Id:CREATESERVER_BUTTON_START
|
Id:CREATESERVER_BUTTON_CANCEL
|
||||||
X:270
|
X:270
|
||||||
Y:100
|
Y:100
|
||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Create
|
Text:Cancel
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:CreateServerMenuDelegate
|
||||||
Background@JOINSERVER_BG:
|
Background@JOINSERVER_BG:
|
||||||
Id:JOINSERVER_BG
|
Id:JOINSERVER_BG
|
||||||
X:WINDOW_RIGHT/2 - 225
|
X:WINDOW_RIGHT/2 - 225
|
||||||
|
|||||||
Reference in New Issue
Block a user