fixed line-endings on *.cs
This commit is contained in:
@@ -23,21 +23,21 @@ using OpenRA.Graphics;
|
||||
using System.Drawing;
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
class BackgroundWidget : Widget
|
||||
{
|
||||
public override void Draw()
|
||||
{
|
||||
if (!Visible)
|
||||
{
|
||||
base.Draw();
|
||||
return;
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
class BackgroundWidget : Widget
|
||||
{
|
||||
public override void Draw()
|
||||
{
|
||||
if (!Visible)
|
||||
{
|
||||
base.Draw();
|
||||
return;
|
||||
}
|
||||
|
||||
WidgetUtils.DrawPanel("dialog", Bounds, null);
|
||||
base.Draw();
|
||||
}
|
||||
WidgetUtils.DrawPanel("dialog", Bounds, null);
|
||||
base.Draw();
|
||||
}
|
||||
}
|
||||
|
||||
static class WidgetUtils
|
||||
@@ -79,5 +79,5 @@ namespace OpenRA.Widgets
|
||||
|
||||
r.Device.DisableScissor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,45 +21,45 @@
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
class ButtonWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = 1;
|
||||
public override bool HandleInput(MouseInput mi)
|
||||
{
|
||||
if (Game.chrome.selectedWidget == this)
|
||||
Depressed = (GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) ? true : false;
|
||||
|
||||
// Relinquish focus
|
||||
if (Game.chrome.selectedWidget == this && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
Game.chrome.selectedWidget = null;
|
||||
Depressed = false;
|
||||
}
|
||||
|
||||
// Are we able to handle this event?
|
||||
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
|
||||
return base.HandleInput(mi);
|
||||
|
||||
|
||||
if (base.HandleInput(mi))
|
||||
return true;
|
||||
|
||||
// Give button focus only while the mouse is down
|
||||
// This is a bit of a hack: it will become cleaner soonish
|
||||
// It will also steal events from any potential children
|
||||
// We also want to play a click sound
|
||||
if (mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
Game.chrome.selectedWidget = this;
|
||||
Depressed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
class ButtonWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = 1;
|
||||
public override bool HandleInput(MouseInput mi)
|
||||
{
|
||||
if (Game.chrome.selectedWidget == this)
|
||||
Depressed = (GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) ? true : false;
|
||||
|
||||
// Relinquish focus
|
||||
if (Game.chrome.selectedWidget == this && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
Game.chrome.selectedWidget = null;
|
||||
Depressed = false;
|
||||
}
|
||||
|
||||
// Are we able to handle this event?
|
||||
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
|
||||
return base.HandleInput(mi);
|
||||
|
||||
|
||||
if (base.HandleInput(mi))
|
||||
return true;
|
||||
|
||||
// Give button focus only while the mouse is down
|
||||
// This is a bit of a hack: it will become cleaner soonish
|
||||
// It will also steal events from any potential children
|
||||
// We also want to play a click sound
|
||||
if (mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
Game.chrome.selectedWidget = this;
|
||||
Depressed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
@@ -78,6 +78,6 @@ namespace OpenRA.Widgets
|
||||
Game.chrome.renderer.BoldFont.Measure(Text).Y / 2) + stateOffset, Color.White));
|
||||
|
||||
base.Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,22 +16,22 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
class CheckboxWidget : Widget
|
||||
{
|
||||
public override void Draw()
|
||||
{
|
||||
if (!Visible)
|
||||
{
|
||||
base.Draw();
|
||||
return;
|
||||
}
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
class CheckboxWidget : Widget
|
||||
{
|
||||
public override void Draw()
|
||||
{
|
||||
if (!Visible)
|
||||
{
|
||||
base.Draw();
|
||||
return;
|
||||
}
|
||||
|
||||
var selected = InputHandler.Value != null ? InputHandler.Value.GetState(this) : false;
|
||||
|
||||
@@ -47,9 +47,9 @@ namespace OpenRA.Widgets
|
||||
Bounds.Height - 9),
|
||||
Color.White);
|
||||
Game.chrome.lineRenderer.Flush();
|
||||
}
|
||||
|
||||
base.Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
base.Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,184 +22,184 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using OpenRA.Server;
|
||||
|
||||
namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
public class WidgetDelegate
|
||||
{
|
||||
// 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
|
||||
if (w.Id == "MAINMENU_BUTTON_QUIT")
|
||||
{
|
||||
Game.Exit();
|
||||
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")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
|
||||
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "CREATESERVER_BUTTON_CANCEL")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "CREATESERVER_BUTTON_START")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
|
||||
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 false;
|
||||
}
|
||||
}
|
||||
|
||||
public class ServerBrowserDelegate : WidgetDelegate
|
||||
{
|
||||
static GameServer[] GameList;
|
||||
static List<Widget> GameButtons = new List<Widget>();
|
||||
|
||||
public override bool OnMouseUp(Widget w, MouseInput mi)
|
||||
{
|
||||
// Main Menu root
|
||||
if (w.Id == "MAINMENU_BUTTON_JOIN")
|
||||
using OpenRA.Server;
|
||||
|
||||
namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
public class WidgetDelegate
|
||||
{
|
||||
// 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
|
||||
if (w.Id == "MAINMENU_BUTTON_QUIT")
|
||||
{
|
||||
Game.Exit();
|
||||
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")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
|
||||
Widget bg = Game.chrome.rootWidget.GetWidget("JOINSERVER_BG");
|
||||
bg.Visible = true;
|
||||
|
||||
int height = 50;
|
||||
int width = 300;
|
||||
int i = 0;
|
||||
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "CREATESERVER_BUTTON_CANCEL")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "CREATESERVER_BUTTON_START")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false;
|
||||
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 false;
|
||||
}
|
||||
}
|
||||
|
||||
public class ServerBrowserDelegate : WidgetDelegate
|
||||
{
|
||||
static GameServer[] GameList;
|
||||
static List<Widget> GameButtons = new List<Widget>();
|
||||
|
||||
public override bool OnMouseUp(Widget w, MouseInput mi)
|
||||
{
|
||||
// Main Menu root
|
||||
if (w.Id == "MAINMENU_BUTTON_JOIN")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false;
|
||||
Widget bg = Game.chrome.rootWidget.GetWidget("JOINSERVER_BG");
|
||||
bg.Visible = true;
|
||||
|
||||
int height = 50;
|
||||
int width = 300;
|
||||
int i = 0;
|
||||
GameList = MasterServerQuery.GetGameList(Game.Settings.MasterServer).ToArray();
|
||||
|
||||
bg.Children.RemoveAll(a => GameButtons.Contains(a));
|
||||
GameButtons.Clear();
|
||||
|
||||
foreach (var game in GameList)
|
||||
{
|
||||
ButtonWidget b = new ButtonWidget();
|
||||
b.Bounds = new Rectangle(bg.Bounds.X + 20, 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");
|
||||
|
||||
GameButtons.Clear();
|
||||
|
||||
foreach (var game in GameList)
|
||||
{
|
||||
ButtonWidget b = new ButtonWidget();
|
||||
b.Bounds = new Rectangle(bg.Bounds.X + 20, 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");
|
||||
|
||||
bg.AddChild(b);
|
||||
GameButtons.Add(b);
|
||||
|
||||
height += 35;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "JOINSERVER_BUTTON_DIRECTCONNECT")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
|
||||
Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id.Substring(0,10) == "JOIN_GAME_")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
|
||||
int index = int.Parse(w.Id.Substring(10));
|
||||
var game = GameList[index];
|
||||
Game.JoinServer(game.Address.Split(':')[0], int.Parse(game.Address.Split(':')[1]));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "JOINSERVER_BUTTON_CANCEL")
|
||||
GameButtons.Add(b);
|
||||
|
||||
height += 35;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "JOINSERVER_BUTTON_DIRECTCONNECT")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConnectionDialogsDelegate : WidgetDelegate
|
||||
{
|
||||
public override bool OnMouseUp(Widget w, MouseInput mi)
|
||||
{
|
||||
// Main Menu root
|
||||
if (w.Id == "CONNECTION_BUTTON_ABORT")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||
Game.chrome.rootWidget.GetWidget("CONNECTING_BG").Visible = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "CONNECTION_BUTTON_CANCEL")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||
Game.chrome.rootWidget.GetWidget("CONNECTION_FAILED_BG").Visible = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "CONNECTION_BUTTON_RETRY")
|
||||
{
|
||||
Game.JoinServer(Game.CurrentHost,Game.CurrentPort);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id.Substring(0,10) == "JOIN_GAME_")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
|
||||
int index = int.Parse(w.Id.Substring(10));
|
||||
var game = GameList[index];
|
||||
Game.JoinServer(game.Address.Split(':')[0], int.Parse(game.Address.Split(':')[1]));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "JOINSERVER_BUTTON_CANCEL")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("JOINSERVER_BG").Visible = false;
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConnectionDialogsDelegate : WidgetDelegate
|
||||
{
|
||||
public override bool OnMouseUp(Widget w, MouseInput mi)
|
||||
{
|
||||
// Main Menu root
|
||||
if (w.Id == "CONNECTION_BUTTON_ABORT")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||
Game.chrome.rootWidget.GetWidget("CONNECTING_BG").Visible = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "CONNECTION_BUTTON_CANCEL")
|
||||
{
|
||||
Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true;
|
||||
Game.chrome.rootWidget.GetWidget("CONNECTION_FAILED_BG").Visible = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (w.Id == "CONNECTION_BUTTON_RETRY")
|
||||
{
|
||||
Game.JoinServer(Game.CurrentHost,Game.CurrentPort);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,34 +20,34 @@
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
class LabelWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public string Align = "Left";
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (!Visible)
|
||||
{
|
||||
base.Draw();
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle r = Bounds;
|
||||
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
|
||||
|
||||
int2 bounds = Game.chrome.renderer.BoldFont.Measure(Text);
|
||||
int2 position = new int2(Bounds.X,Bounds.Y);
|
||||
|
||||
if (Align == "Center")
|
||||
position = new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(bounds.X / 2, bounds.Y/2);
|
||||
|
||||
|
||||
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, position, Color.White);
|
||||
Game.chrome.renderer.Device.DisableScissor();
|
||||
base.Draw();
|
||||
}
|
||||
}
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
class LabelWidget : Widget
|
||||
{
|
||||
public string Text = "";
|
||||
public string Align = "Left";
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (!Visible)
|
||||
{
|
||||
base.Draw();
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle r = Bounds;
|
||||
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
|
||||
|
||||
int2 bounds = Game.chrome.renderer.BoldFont.Measure(Text);
|
||||
int2 position = new int2(Bounds.X,Bounds.Y);
|
||||
|
||||
if (Align == "Center")
|
||||
position = new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) - new int2(bounds.X / 2, bounds.Y/2);
|
||||
|
||||
|
||||
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, position, Color.White);
|
||||
Game.chrome.renderer.Device.DisableScissor();
|
||||
base.Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,54 +23,54 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Widgets.Delegates;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class Widget
|
||||
{
|
||||
// Info defined in YAML
|
||||
public readonly string Id = null;
|
||||
public readonly string X = "0";
|
||||
public readonly string Y = "0";
|
||||
public readonly string Width = "0";
|
||||
public readonly string Height = "0";
|
||||
using OpenRA.Widgets.Delegates;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class Widget
|
||||
{
|
||||
// Info defined in YAML
|
||||
public readonly string Id = null;
|
||||
public readonly string X = "0";
|
||||
public readonly string Y = "0";
|
||||
public readonly string Width = "0";
|
||||
public readonly string Height = "0";
|
||||
public readonly string Delegate = null;
|
||||
|
||||
public Lazy<WidgetDelegate> InputHandler;
|
||||
|
||||
public bool Visible = true;
|
||||
public readonly List<Widget> Children = new List<Widget>();
|
||||
|
||||
// Calculated internally
|
||||
public Rectangle Bounds;
|
||||
public Lazy<WidgetDelegate> InputHandler;
|
||||
|
||||
public bool Visible = true;
|
||||
public readonly List<Widget> Children = new List<Widget>();
|
||||
|
||||
// Calculated internally
|
||||
public Rectangle Bounds;
|
||||
public Widget Parent = null;
|
||||
|
||||
public Widget() { InputHandler = Lazy.New(() => BindHandler(Delegate)); }
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
// Parse the YAML equations to find the widget bounds
|
||||
Rectangle parentBounds = (Parent == null) ? new Rectangle(0,0,Game.viewport.Width,Game.viewport.Height) : Parent.Bounds;
|
||||
|
||||
Dictionary<string, int> substitutions = new Dictionary<string, int>();
|
||||
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
|
||||
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
|
||||
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
|
||||
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
|
||||
int width = Evaluator.Evaluate(Width, substitutions);
|
||||
int height = Evaluator.Evaluate(Height, substitutions);
|
||||
|
||||
substitutions.Add("WIDTH", width);
|
||||
substitutions.Add("HEIGHT", height);
|
||||
|
||||
Bounds = new Rectangle(parentBounds.X + Evaluator.Evaluate(X, substitutions),
|
||||
parentBounds.Y + Evaluator.Evaluate(Y, substitutions),
|
||||
width,
|
||||
height);
|
||||
|
||||
foreach (var child in Children)
|
||||
child.Initialize();
|
||||
public Widget() { InputHandler = Lazy.New(() => BindHandler(Delegate)); }
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
// Parse the YAML equations to find the widget bounds
|
||||
Rectangle parentBounds = (Parent == null) ? new Rectangle(0,0,Game.viewport.Width,Game.viewport.Height) : Parent.Bounds;
|
||||
|
||||
Dictionary<string, int> substitutions = new Dictionary<string, int>();
|
||||
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
|
||||
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
|
||||
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
|
||||
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
|
||||
int width = Evaluator.Evaluate(Width, substitutions);
|
||||
int height = Evaluator.Evaluate(Height, substitutions);
|
||||
|
||||
substitutions.Add("WIDTH", width);
|
||||
substitutions.Add("HEIGHT", height);
|
||||
|
||||
Bounds = new Rectangle(parentBounds.X + Evaluator.Evaluate(X, substitutions),
|
||||
parentBounds.Y + Evaluator.Evaluate(Y, substitutions),
|
||||
width,
|
||||
height);
|
||||
|
||||
foreach (var child in Children)
|
||||
child.Initialize();
|
||||
}
|
||||
|
||||
public Rectangle GetEventBounds()
|
||||
@@ -92,59 +92,59 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Cannot locate widget delegate: {0}".F(name));
|
||||
}
|
||||
|
||||
public virtual bool HandleInput(MouseInput mi)
|
||||
{
|
||||
// Are we able to handle this event?
|
||||
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
|
||||
return false;
|
||||
|
||||
// Can any of our children handle this?
|
||||
foreach (var child in Children)
|
||||
if (child.HandleInput(mi))
|
||||
return true;
|
||||
|
||||
// Mousedown
|
||||
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Down)
|
||||
return InputHandler.Value.OnMouseDown(this, mi);
|
||||
|
||||
// Mouseup
|
||||
}
|
||||
|
||||
public virtual bool HandleInput(MouseInput mi)
|
||||
{
|
||||
// Are we able to handle this event?
|
||||
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
|
||||
return false;
|
||||
|
||||
// Can any of our children handle this?
|
||||
foreach (var child in Children)
|
||||
if (child.HandleInput(mi))
|
||||
return true;
|
||||
|
||||
// Mousedown
|
||||
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Down)
|
||||
return InputHandler.Value.OnMouseDown(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;
|
||||
}
|
||||
|
||||
public virtual void Draw()
|
||||
{
|
||||
if (Visible)
|
||||
foreach (var child in Children)
|
||||
child.Draw();
|
||||
}
|
||||
|
||||
public void AddChild(Widget child)
|
||||
{
|
||||
child.Parent = this;
|
||||
Children.Add( child );
|
||||
}
|
||||
|
||||
public Widget GetWidget(string id)
|
||||
{
|
||||
if (this.Id == id)
|
||||
return this;
|
||||
|
||||
foreach (var child in Children)
|
||||
if (child.GetWidget(id) != null)
|
||||
return child;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return InputHandler.Value.OnMouseUp(this, mi);
|
||||
|
||||
// Mousemove
|
||||
if (InputHandler.Value != null && mi.Event == MouseInputEvent.Move)
|
||||
return InputHandler.Value.OnMouseMove(this, mi);
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void Draw()
|
||||
{
|
||||
if (Visible)
|
||||
foreach (var child in Children)
|
||||
child.Draw();
|
||||
}
|
||||
|
||||
public void AddChild(Widget child)
|
||||
{
|
||||
child.Parent = this;
|
||||
Children.Add( child );
|
||||
}
|
||||
|
||||
public Widget GetWidget(string id)
|
||||
{
|
||||
if (this.Id == id)
|
||||
return this;
|
||||
|
||||
foreach (var child in Children)
|
||||
if (child.GetWidget(id) != null)
|
||||
return child;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ContainerWidget : Widget { }
|
||||
class ContainerWidget : Widget { }
|
||||
}
|
||||
Reference in New Issue
Block a user