diff --git a/OpenRA.FileFormats/Map/MapStub.cs b/OpenRA.FileFormats/Map/MapStub.cs
index c8d52b5649..cdfc8eb3ce 100644
--- a/OpenRA.FileFormats/Map/MapStub.cs
+++ b/OpenRA.FileFormats/Map/MapStub.cs
@@ -64,10 +64,10 @@ namespace OpenRA.FileFormats
{
string[] loc = wp.Value.Value.Split(',');
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
- }
-
+ }
+
Preview = Lazy.New(
- () => { return new Bitmap(Package.GetContent("preview.png")); }
+ () => new Bitmap(Package.GetContent("preview.png"))
);
Uid = Package.GetContent("map.uid").ReadAllText();
diff --git a/OpenRA.FileFormats/Support/Log.cs b/OpenRA.FileFormats/Support/Log.cs
index 4952af205d..cbf9ae9f15 100755
--- a/OpenRA.FileFormats/Support/Log.cs
+++ b/OpenRA.FileFormats/Support/Log.cs
@@ -18,11 +18,11 @@
*/
#endregion
-using System.IO;
using System;
using System.Collections.Generic;
-using System.Linq;
+using System.IO;
using System.IO.Compression;
+using System.Linq;
using System.Net;
namespace OpenRA
diff --git a/OpenRA.Game/Server/MasterServerQuery.cs b/OpenRA.Game/Server/MasterServerQuery.cs
index 8bb07af431..0375bdc036 100644
--- a/OpenRA.Game/Server/MasterServerQuery.cs
+++ b/OpenRA.Game/Server/MasterServerQuery.cs
@@ -1,10 +1,29 @@
-using System;
-using System.Collections.Generic;
+#region Copyright & License Information
+/*
+ * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
+ * This file is part of OpenRA.
+ *
+ * OpenRA is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenRA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenRA. If not, see .
+ */
+#endregion
+
+using System;
using System.Linq;
-using System.Text;
using System.Net;
-using OpenRA.FileFormats;
+using System.Text;
using System.Threading;
+using OpenRA.FileFormats;
namespace OpenRA.Server
{
diff --git a/OpenRA.Game/Widgets/BackgroundWidget.cs b/OpenRA.Game/Widgets/BackgroundWidget.cs
index 1dcac979a3..4340004bf3 100644
--- a/OpenRA.Game/Widgets/BackgroundWidget.cs
+++ b/OpenRA.Game/Widgets/BackgroundWidget.cs
@@ -1,4 +1,3 @@
-using System.Drawing;
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
@@ -32,10 +31,10 @@ namespace OpenRA.Widgets
public BackgroundWidget() : base() { }
- public BackgroundWidget(Widget other)
+ protected BackgroundWidget(BackgroundWidget other)
: base(other)
{
- Background = (other as BackgroundWidget).Background;
+ Background = other.Background;
}
public override Widget Clone() { return new BackgroundWidget(this); }
diff --git a/OpenRA.Game/Widgets/BuildPaletteWidget.cs b/OpenRA.Game/Widgets/BuildPaletteWidget.cs
index eb95100091..e5ee33e681 100644
--- a/OpenRA.Game/Widgets/BuildPaletteWidget.cs
+++ b/OpenRA.Game/Widgets/BuildPaletteWidget.cs
@@ -18,15 +18,14 @@
*/
#endregion
-using System.Drawing;
-using System.Collections.Generic;
-using System.Linq;
-using OpenRA;
-using OpenRA.Traits;
-using OpenRA.Graphics;
-using OpenRA.FileFormats;
-using OpenRA.Orders;
using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using OpenRA.FileFormats;
+using OpenRA.Graphics;
+using OpenRA.Orders;
+using OpenRA.Traits;
namespace OpenRA.Widgets
{
@@ -52,14 +51,6 @@ namespace OpenRA.Widgets
List visibleTabs = new List();
public BuildPaletteWidget() : base() { }
-
- public BuildPaletteWidget(Widget other)
- : base(other)
- {
- throw new NotImplementedException("Why are you Cloning BuildPalette?");
- }
-
- public override Widget Clone() { return new BuildPaletteWidget(this); }
public override void Initialize()
{
diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs
index 6199f625e1..5a0a746c10 100644
--- a/OpenRA.Game/Widgets/ButtonWidget.cs
+++ b/OpenRA.Game/Widgets/ButtonWidget.cs
@@ -18,8 +18,8 @@
*/
#endregion
-using System.Drawing;
using System;
+using System.Drawing;
namespace OpenRA.Widgets
{
@@ -30,45 +30,45 @@ namespace OpenRA.Widgets
public bool Depressed = false;
public int VisualHeight = 1;
public Func GetText;
-
+
public ButtonWidget()
: base()
{
GetText = () => { return Text; };
}
-
- public ButtonWidget(Widget widget)
- :base(widget)
+
+ protected ButtonWidget(ButtonWidget widget)
+ : base(widget)
{
- Text = (widget as ButtonWidget).Text;
- Depressed = (widget as ButtonWidget).Depressed;
- VisualHeight = (widget as ButtonWidget).VisualHeight;
- GetText = (widget as ButtonWidget).GetText;
+ Text = widget.Text;
+ Depressed = widget.Depressed;
+ VisualHeight = widget.VisualHeight;
+ GetText = widget.GetText;
}
-
- public override bool LoseFocus (MouseInput mi)
+
+ public override bool LoseFocus(MouseInput mi)
{
Depressed = false;
return base.LoseFocus(mi);
}
-
+
public override bool HandleInput(MouseInput mi)
- {
+ {
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
return false;
-
+
// Only fire the onMouseUp order if we successfully lost focus, and were pressed
if (Focused && mi.Event == MouseInputEvent.Up)
{
var wasPressed = Depressed;
return (LoseFocus(mi) && wasPressed);
}
-
+
if (mi.Event == MouseInputEvent.Down)
Depressed = true;
else if (mi.Event == MouseInputEvent.Move && Focused)
- Depressed = RenderBounds.Contains(mi.Location.X,mi.Location.Y);
-
+ Depressed = RenderBounds.Contains(mi.Location.X, mi.Location.Y);
+
return Depressed;
}
@@ -76,19 +76,16 @@ namespace OpenRA.Widgets
{
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
- WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", RenderBounds );
-
+ WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", RenderBounds);
+
var text = GetText();
font.DrawText(text,
- new int2( RenderOrigin.X + Bounds.Width / 2, RenderOrigin.Y + Bounds.Height / 2)
+ new int2(RenderOrigin.X + Bounds.Width / 2, RenderOrigin.Y + Bounds.Height / 2)
- new int2(font.Measure(text).X / 2,
font.Measure(text).Y / 2) + stateOffset, Color.White);
}
-
- public override Widget Clone()
- {
- return new ButtonWidget(this);
- }
-
+
+ public override Widget Clone() { return new ButtonWidget(this); }
+
}
}
\ No newline at end of file
diff --git a/OpenRA.Game/Widgets/ChatDisplayWidget.cs b/OpenRA.Game/Widgets/ChatDisplayWidget.cs
index cac445a6cb..a26a4c215a 100644
--- a/OpenRA.Game/Widgets/ChatDisplayWidget.cs
+++ b/OpenRA.Game/Widgets/ChatDisplayWidget.cs
@@ -16,69 +16,68 @@
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see .
*/
-#endregion
-
-using OpenRA.FileFormats;
+#endregion
+
using System.Collections.Generic;
using System.Drawing;
-using System.Linq;
-using System.Text;
-using System;
-
-namespace OpenRA.Widgets
-{
- class ChatDisplayWidget : Widget
- {
- const int logLength = 10;
- public string Notification = "";
-
- public List recentLines = new List();
-
- public ChatDisplayWidget()
- : base() {}
-
- public ChatDisplayWidget(Widget widget)
- :base(widget) {}
-
- public override void DrawInner(World world)
- {
- var pos = RenderOrigin;
- var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
- var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
- WidgetUtils.DrawPanel("dialog3", chatLogArea);
-
- var renderer = Game.chrome.renderer;
- var font = renderer.RegularFont;
-
- renderer.Device.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);
- foreach (var line in recentLines.AsEnumerable().Reverse())
- {
- chatpos.Y -= 20;
- var owner = line.Owner + ":";
- var inset = font.Measure(owner).X + 10;
- font.DrawText(owner, chatpos, line.Color);
- font.DrawText(line.Text, chatpos + new int2(inset, 0), Color.White);
- }
-
- renderer.RgbaSpriteRenderer.Flush();
- renderer.Device.DisableScissor();
- }
-
- public void AddLine(Color c, string from, string text)
- {
- recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
-
- if (Notification != null)
- Sound.Play(Notification);
-
- while (recentLines.Count > logLength) recentLines.RemoveAt(0);
- }
-
- public override Widget Clone()
- {
- return new ChatDisplayWidget(this);
- }
- }
- class ChatLine { public Color Color = Color.White; public string Owner, Text; public bool wrapped = false; }
-
+using System.Linq;
+
+namespace OpenRA.Widgets
+{
+ class ChatDisplayWidget : Widget
+ {
+ const int logLength = 10;
+ public string Notification = "";
+
+ public List recentLines = new List();
+
+ public ChatDisplayWidget()
+ : base() { }
+
+ protected ChatDisplayWidget(Widget widget)
+ : base(widget) { }
+
+ public override void DrawInner(World world)
+ {
+ var pos = RenderOrigin;
+ var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
+ var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
+ WidgetUtils.DrawPanel("dialog3", chatLogArea);
+
+ var renderer = Game.chrome.renderer;
+ var font = renderer.RegularFont;
+
+ renderer.Device.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);
+ foreach (var line in recentLines.AsEnumerable().Reverse())
+ {
+ chatpos.Y -= 20;
+ var owner = line.Owner + ":";
+ var inset = font.Measure(owner).X + 10;
+ font.DrawText(owner, chatpos, line.Color);
+ font.DrawText(line.Text, chatpos + new int2(inset, 0), Color.White);
+ }
+
+ renderer.RgbaSpriteRenderer.Flush();
+ renderer.Device.DisableScissor();
+ }
+
+ public void AddLine(Color c, string from, string text)
+ {
+ recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
+
+ if (Notification != null)
+ Sound.Play(Notification);
+
+ while (recentLines.Count > logLength) recentLines.RemoveAt(0);
+ }
+
+ public override Widget Clone() { return new ChatDisplayWidget(this); }
+ }
+
+ class ChatLine
+ {
+ public Color Color = Color.White;
+ public string Owner, Text;
+ public bool wrapped = false;
+ }
}
\ No newline at end of file
diff --git a/OpenRA.Game/Widgets/CheckboxWidget.cs b/OpenRA.Game/Widgets/CheckboxWidget.cs
index d84e83246e..690b355124 100644
--- a/OpenRA.Game/Widgets/CheckboxWidget.cs
+++ b/OpenRA.Game/Widgets/CheckboxWidget.cs
@@ -56,15 +56,16 @@ namespace OpenRA.Widgets
Game.chrome.lineRenderer.Flush();
}
}
+
public override bool HandleInput(MouseInput mi) { return true; }
public CheckboxWidget() : base() { }
- public CheckboxWidget(Widget other)
+ protected CheckboxWidget(CheckboxWidget other)
: base(other)
{
- Text = (other as CheckboxWidget).Text;
- Checked = (other as CheckboxWidget).Checked;
+ Text = other.Text;
+ Checked = other.Checked;
}
public override Widget Clone() { return new CheckboxWidget(this); }
diff --git a/OpenRA.Game/Widgets/ColorBlockWidget.cs b/OpenRA.Game/Widgets/ColorBlockWidget.cs
index 2c40a17e56..7c88da7411 100644
--- a/OpenRA.Game/Widgets/ColorBlockWidget.cs
+++ b/OpenRA.Game/Widgets/ColorBlockWidget.cs
@@ -19,36 +19,37 @@
#endregion
using System;
-using System.Drawing;
-
-namespace OpenRA.Widgets
-{
- class ColorBlockWidget : Widget
- {
- public Func GetColor;
-
- public ColorBlockWidget()
- : base()
- {
- GetColor = () => Color.White;
- }
-
- public ColorBlockWidget(Widget widget)
- :base(widget)
- {
- GetColor = (widget as ColorBlockWidget).GetColor;
- }
-
- public override Widget Clone()
- {
- return new ColorBlockWidget(this);
- }
-
- public override void DrawInner(World world)
- {
- var pos = RenderOrigin;
- var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X, pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
- Game.chrome.lineRenderer.FillRect(paletteRect, GetColor());
- }
- }
+using System.Drawing;
+
+namespace OpenRA.Widgets
+{
+ class ColorBlockWidget : Widget
+ {
+ public Func GetColor;
+
+ public ColorBlockWidget()
+ : base()
+ {
+ GetColor = () => Color.White;
+ }
+
+ protected ColorBlockWidget(ColorBlockWidget widget)
+ : base(widget)
+ {
+ GetColor = widget.GetColor;
+ }
+
+ public override Widget Clone()
+ {
+ return new ColorBlockWidget(this);
+ }
+
+ public override void DrawInner(World world)
+ {
+ var pos = RenderOrigin;
+ var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X,
+ pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
+ Game.chrome.lineRenderer.FillRect(paletteRect, GetColor());
+ }
+ }
}
diff --git a/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs b/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs
index 1f633e9582..7d755b39df 100644
--- a/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs
+++ b/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs
@@ -1,8 +1,27 @@
+#region Copyright & License Information
+/*
+ * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
+ * This file is part of OpenRA.
+ *
+ * OpenRA is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenRA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenRA. If not, see .
+ */
+#endregion
+
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Drawing;
+using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Widgets.Delegates
diff --git a/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs
index c43752f2f1..81f067598b 100644
--- a/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs
+++ b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs
@@ -16,11 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see .
*/
-#endregion
-using System;
-using OpenRA.FileFormats;
-using OpenRA.Support;
-
+#endregion
+
namespace OpenRA.Widgets.Delegates
{
public class IngameChromeDelegate : IWidgetDelegate
diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs
index 6652f9a6ad..9a4a9ccd74 100644
--- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs
+++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs
@@ -18,76 +18,77 @@
*/
#endregion
-using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
-using OpenRA.FileFormats;
-
-namespace OpenRA.Widgets.Delegates
-{
- public class LobbyDelegate : IWidgetDelegate
- {
- Widget Players, LocalPlayerTemplate, RemotePlayerTemplate;
-
- Dictionary CountryNames;
-
- string MapUid;
- MapStub Map;
- public LobbyDelegate()
- {
- Game.LobbyInfoChanged += UpdateCurrentMap;
- UpdateCurrentMap();
-
- var r = Chrome.rootWidget;
- var lobby = r.GetWidget("SERVER_LOBBY");
- Players = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("PLAYERS");
- LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
- RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
-
-
- var map = lobby.GetWidget("LOBBY_MAP_PREVIEW");
- map.Map = () => {return Map;};
- map.OnSpawnClick = sp =>
- {
- if (Game.LocalClient.State == Session.ClientState.Ready) return;
- var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
- if (sp == 0 || !owned)
- Game.IssueOrder(Order.Command("spawn {0}".F(sp)));
- };
-
- map.SpawnColors = () =>
- {
- var spawns = Map.SpawnPoints;
- var playerColors = Game.world.PlayerColors();
- var sc = new Dictionary();
-
- for (int i = 1; i <= spawns.Count(); i++)
- {
- var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
- if (client == null)
- continue;
- sc.Add(spawns.ElementAt(i-1),playerColors[client.PaletteIndex % playerColors.Count()].Color);
- }
- return sc;
- };
-
- CountryNames = Rules.Info["world"].Traits.WithInterface().ToDictionary(a => a.Race, a => a.Name);
- CountryNames.Add("random", "Random");
-
- var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
- mapButton.OnMouseUp = mi => {
- r.GetWidget("MAP_CHOOSER").SpecialOneArg(MapUid);
- r.OpenWindow("MAP_CHOOSER");
- return true;
- };
-
- mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
-
- var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
- disconnectButton.OnMouseUp = mi => {
- Game.Disconnect();
- return true;
+using OpenRA.FileFormats;
+
+namespace OpenRA.Widgets.Delegates
+{
+ public class LobbyDelegate : IWidgetDelegate
+ {
+ Widget Players, LocalPlayerTemplate, RemotePlayerTemplate;
+
+ Dictionary CountryNames;
+
+ string MapUid;
+ MapStub Map;
+ public LobbyDelegate()
+ {
+ Game.LobbyInfoChanged += UpdateCurrentMap;
+ UpdateCurrentMap();
+
+ var r = Chrome.rootWidget;
+ var lobby = r.GetWidget("SERVER_LOBBY");
+ Players = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("PLAYERS");
+ LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
+ RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
+
+
+ var mapPreview = lobby.GetWidget("LOBBY_MAP_PREVIEW");
+ mapPreview.Map = () => Map;
+ mapPreview.OnSpawnClick = sp =>
+ {
+ if (Game.LocalClient.State == Session.ClientState.Ready) return;
+ var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
+ if (sp == 0 || !owned)
+ Game.IssueOrder(Order.Command("spawn {0}".F(sp)));
+ };
+
+ mapPreview.SpawnColors = () =>
+ {
+ var spawns = Map.SpawnPoints;
+ var playerColors = Game.world.PlayerColors();
+ var sc = new Dictionary();
+
+ for (int i = 1; i <= spawns.Count(); i++)
+ {
+ var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
+ if (client == null)
+ continue;
+ sc.Add(spawns.ElementAt(i - 1), playerColors[client.PaletteIndex % playerColors.Count()].Color);
+ }
+ return sc;
+ };
+
+ CountryNames = Rules.Info["world"].Traits.WithInterface().ToDictionary(a => a.Race, a => a.Name);
+ CountryNames.Add("random", "Random");
+
+ var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
+ mapButton.OnMouseUp = mi =>
+ {
+ r.GetWidget("MAP_CHOOSER").SpecialOneArg(MapUid);
+ r.OpenWindow("MAP_CHOOSER");
+ return true;
+ };
+
+ mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
+
+ var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
+ disconnectButton.OnMouseUp = mi =>
+ {
+ Game.Disconnect();
+ return true;
};
var lockTeamsCheckbox = lobby.GetWidget("LOCKTEAMS_CHECKBOX");
@@ -99,186 +100,186 @@ namespace OpenRA.Widgets.Delegates
Game.IssueOrder(Order.Command(
"lockteams {0}".F(!Game.LobbyInfo.GlobalSettings.LockTeams)));
return true;
- };
-
- Game.LobbyInfoChanged += UpdatePlayerList;
- Game.AddChatLine += (c,n,s) => lobby.GetWidget("CHAT_DISPLAY").AddLine(c,n,s);
-
- bool teamChat = false;
- var chatLabel = lobby.GetWidget("LABEL_CHATTYPE");
- var chatTextField = lobby.GetWidget("CHAT_TEXTFIELD");
- chatTextField.OnEnterKey = () =>
- {
- if (chatTextField.Text.Length == 0)
- return true;
-
- var order = (teamChat) ? Order.TeamChat( chatTextField.Text ) : Order.Chat( chatTextField.Text );
- Game.IssueOrder( order );
- chatTextField.Text = "";
- return true;
- };
-
- chatTextField.OnTabKey = () =>
- {
- teamChat ^= true;
- chatLabel.Text = (teamChat) ? "Team:" : "Chat:";
- return true;
- };
-
- }
-
- void UpdateCurrentMap()
- {
- if (MapUid == Game.LobbyInfo.GlobalSettings.Map) return;
- MapUid = Game.LobbyInfo.GlobalSettings.Map;
- Map = Game.AvailableMaps[ MapUid ];
- }
-
- void UpdatePlayerList()
- {
- // This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
- // Todo: handle this nicer
- Players.Children.Clear();
-
- int offset = 0;
- foreach(var client in Game.LobbyInfo.Clients)
- {
- var c = client;
- Widget template;
-
- if(client.Index == Game.LocalClient.Index && c.State != Session.ClientState.Ready)
- {
- template = LocalPlayerTemplate.Clone();
- var name = template.GetWidget("NAME");
- name.Text = c.Name;
- name.OnEnterKey = () =>
- {
- name.Text = name.Text.Trim();
- if (name.Text.Length == 0)
- name.Text = c.Name;
-
- name.LoseFocus();
- if (name.Text == c.Name)
- return true;
-
- Game.IssueOrder(Order.Command( "name "+name.Text ));
- Game.Settings.PlayerName = name.Text;
- Game.Settings.Save();
- return true;
- };
- name.OnLoseFocus = () => name.OnEnterKey();
-
- var color = template.GetWidget("COLOR");
- color.OnMouseUp = CyclePalette;
-
+ };
+
+ Game.LobbyInfoChanged += UpdatePlayerList;
+ Game.AddChatLine += (c, n, s) => lobby.GetWidget("CHAT_DISPLAY").AddLine(c, n, s);
+
+ bool teamChat = false;
+ var chatLabel = lobby.GetWidget("LABEL_CHATTYPE");
+ var chatTextField = lobby.GetWidget("CHAT_TEXTFIELD");
+ chatTextField.OnEnterKey = () =>
+ {
+ if (chatTextField.Text.Length == 0)
+ return true;
+
+ var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text);
+ Game.IssueOrder(order);
+ chatTextField.Text = "";
+ return true;
+ };
+
+ chatTextField.OnTabKey = () =>
+ {
+ teamChat ^= true;
+ chatLabel.Text = (teamChat) ? "Team:" : "Chat:";
+ return true;
+ };
+
+ }
+
+ void UpdateCurrentMap()
+ {
+ if (MapUid == Game.LobbyInfo.GlobalSettings.Map) return;
+ MapUid = Game.LobbyInfo.GlobalSettings.Map;
+ Map = Game.AvailableMaps[MapUid];
+ }
+
+ void UpdatePlayerList()
+ {
+ // This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
+ // Todo: handle this nicer
+ Players.Children.Clear();
+
+ int offset = 0;
+ foreach (var client in Game.LobbyInfo.Clients)
+ {
+ var c = client;
+ Widget template;
+
+ if (client.Index == Game.LocalClient.Index && c.State != Session.ClientState.Ready)
+ {
+ template = LocalPlayerTemplate.Clone();
+ var name = template.GetWidget("NAME");
+ name.Text = c.Name;
+ name.OnEnterKey = () =>
+ {
+ name.Text = name.Text.Trim();
+ if (name.Text.Length == 0)
+ name.Text = c.Name;
+
+ name.LoseFocus();
+ if (name.Text == c.Name)
+ return true;
+
+ Game.IssueOrder(Order.Command("name " + name.Text));
+ Game.Settings.PlayerName = name.Text;
+ Game.Settings.Save();
+ return true;
+ };
+ name.OnLoseFocus = () => name.OnEnterKey();
+
+ var color = template.GetWidget("COLOR");
+ color.OnMouseUp = CyclePalette;
+
var colorBlock = color.GetWidget("COLORBLOCK");
- colorBlock.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
-
- var faction = template.GetWidget("FACTION");
- faction.OnMouseUp = CycleRace;
- var factionname = faction.GetWidget("FACTIONNAME");
- factionname.GetText = () => CountryNames[c.Country];
- var factionflag = faction.GetWidget("FACTIONFLAG");
- factionflag.GetImageName = () => c.Country;
- factionflag.GetImageCollection = () => "flags";
-
- var team = template.GetWidget("TEAM");
- team.OnMouseUp = CycleTeam;
- team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
-
- var status = template.GetWidget("STATUS");
- status.Checked = () => c.State == Session.ClientState.Ready;
- status.OnMouseDown = CycleReady;
- }
- else
- {
- template = RemotePlayerTemplate.Clone();
- template.GetWidget("NAME").GetText = () => c.Name;
+ colorBlock.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
+
+ var faction = template.GetWidget("FACTION");
+ faction.OnMouseUp = CycleRace;
+ var factionname = faction.GetWidget("FACTIONNAME");
+ factionname.GetText = () => CountryNames[c.Country];
+ var factionflag = faction.GetWidget("FACTIONFLAG");
+ factionflag.GetImageName = () => c.Country;
+ factionflag.GetImageCollection = () => "flags";
+
+ var team = template.GetWidget("TEAM");
+ team.OnMouseUp = CycleTeam;
+ team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
+
+ var status = template.GetWidget("STATUS");
+ status.Checked = () => c.State == Session.ClientState.Ready;
+ status.OnMouseDown = CycleReady;
+ }
+ else
+ {
+ template = RemotePlayerTemplate.Clone();
+ template.GetWidget("NAME").GetText = () => c.Name;
var color = template.GetWidget("COLOR");
- color.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
-
- var faction = template.GetWidget("FACTION");
- var factionname = faction.GetWidget("FACTIONNAME");
- factionname.GetText = () => CountryNames[c.Country];
- var factionflag = faction.GetWidget("FACTIONFLAG");
- factionflag.GetImageName = () => c.Country;
- factionflag.GetImageCollection = () => "flags";
-
- var team = template.GetWidget("TEAM");
- team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
-
- var status = template.GetWidget("STATUS");
- status.Checked = () => c.State == Session.ClientState.Ready;
- if (client.Index == Game.LocalClient.Index) status.OnMouseDown = CycleReady;
- }
-
- template.Id = "PLAYER_{0}".F(c.Index);
- template.Parent = Players;
-
- template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
- template.IsVisible = () => true;
- Players.AddChild(template);
-
- offset += template.Bounds.Height;
- }
- }
-
- bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index) && Game.world.PlayerColors()[index % Game.world.PlayerColors().Count].Playable; }
- bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
-
- bool CyclePalette(MouseInput mi)
+ color.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
+
+ var faction = template.GetWidget("FACTION");
+ var factionname = faction.GetWidget("FACTIONNAME");
+ factionname.GetText = () => CountryNames[c.Country];
+ var factionflag = faction.GetWidget("FACTIONFLAG");
+ factionflag.GetImageName = () => c.Country;
+ factionflag.GetImageCollection = () => "flags";
+
+ var team = template.GetWidget("TEAM");
+ team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
+
+ var status = template.GetWidget("STATUS");
+ status.Checked = () => c.State == Session.ClientState.Ready;
+ if (client.Index == Game.LocalClient.Index) status.OnMouseDown = CycleReady;
+ }
+
+ template.Id = "PLAYER_{0}".F(c.Index);
+ template.Parent = Players;
+
+ template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
+ template.IsVisible = () => true;
+ Players.AddChild(template);
+
+ offset += template.Bounds.Height;
+ }
+ }
+
+ bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index) && Game.world.PlayerColors()[index % Game.world.PlayerColors().Count].Playable; }
+ bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
+
+ bool CyclePalette(MouseInput mi)
{
var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.PlayerColors().Count() - 1;
- var newIndex = ((int)Game.LocalClient.PaletteIndex + d) % Game.world.PlayerColors().Count();
-
+ var newIndex = ((int)Game.LocalClient.PaletteIndex + d) % Game.world.PlayerColors().Count();
+
while (!PaletteAvailable(newIndex) && newIndex != (int)Game.LocalClient.PaletteIndex)
- newIndex = (newIndex + d) % Game.world.PlayerColors().Count();
-
- Game.IssueOrder(
- Order.Command("pal " + newIndex));
-
- return true;
- }
-
- bool CycleRace(MouseInput mi)
- {
- var countries = CountryNames.Select(a => a.Key);
-
- if (mi.Button == MouseButton.Right)
- countries = countries.Reverse();
-
- var nextCountry = countries
- .SkipWhile(c => c != Game.LocalClient.Country)
- .Skip(1)
- .FirstOrDefault();
-
- if (nextCountry == null)
- nextCountry = countries.First();
-
- Game.IssueOrder(Order.Command("race " + nextCountry));
-
- return true;
- }
-
- bool CycleReady(MouseInput mi)
- {
- //HACK: Can't set this as part of the fuction as LocalClient/State not initalised yet
- Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("CHANGEMAP_BUTTON").Visible
- = (Game.IsHost && Game.LocalClient.State == Session.ClientState.Ready);
- Game.IssueOrder(Order.Command("ready"));
- return true;
- }
-
- bool CycleTeam(MouseInput mi)
- {
- var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.PlayerCount;
-
- var newIndex = (Game.LocalClient.Team + d) % (Game.world.Map.PlayerCount+1);
-
- Game.IssueOrder(
- Order.Command("team " + newIndex));
- return true;
- }
- }
+ newIndex = (newIndex + d) % Game.world.PlayerColors().Count();
+
+ Game.IssueOrder(
+ Order.Command("pal " + newIndex));
+
+ return true;
+ }
+
+ bool CycleRace(MouseInput mi)
+ {
+ var countries = CountryNames.Select(a => a.Key);
+
+ if (mi.Button == MouseButton.Right)
+ countries = countries.Reverse();
+
+ var nextCountry = countries
+ .SkipWhile(c => c != Game.LocalClient.Country)
+ .Skip(1)
+ .FirstOrDefault();
+
+ if (nextCountry == null)
+ nextCountry = countries.First();
+
+ Game.IssueOrder(Order.Command("race " + nextCountry));
+
+ return true;
+ }
+
+ bool CycleReady(MouseInput mi)
+ {
+ //HACK: Can't set this as part of the fuction as LocalClient/State not initalised yet
+ Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("CHANGEMAP_BUTTON").Visible
+ = (Game.IsHost && Game.LocalClient.State == Session.ClientState.Ready);
+ Game.IssueOrder(Order.Command("ready"));
+ return true;
+ }
+
+ bool CycleTeam(MouseInput mi)
+ {
+ var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.Map.PlayerCount;
+
+ var newIndex = (Game.LocalClient.Team + d) % (Game.world.Map.PlayerCount + 1);
+
+ Game.IssueOrder(
+ Order.Command("team " + newIndex));
+ return true;
+ }
+ }
}
diff --git a/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs b/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs
index 9baf147dd1..88ff227aa7 100644
--- a/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs
+++ b/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs
@@ -17,8 +17,9 @@
* along with OpenRA. If not, see .
*/
#endregion
-using System;
+
using OpenRA.FileFormats;
+
namespace OpenRA.Widgets.Delegates
{
public class MainMenuButtonsDelegate : IWidgetDelegate
@@ -27,10 +28,10 @@ namespace OpenRA.Widgets.Delegates
{
// Main menu is the default window
Widget.WindowList.Push("MAINMENU_BG");
- Chrome.rootWidget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => {Game.Exit(); return true;};
-
+ Chrome.rootWidget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => { Game.Exit(); return true; };
+
var version = Chrome.rootWidget.GetWidget("MAINMENU_BG").GetWidget("VERSION_STRING");
-
+
if (FileSystem.Exists("VERSION"))
{
var s = FileSystem.Open("VERSION");
diff --git a/OpenRA.Game/Widgets/Delegates/MapChooserDelegate.cs b/OpenRA.Game/Widgets/Delegates/MapChooserDelegate.cs
index 9ff1d019ca..63cb299744 100644
--- a/OpenRA.Game/Widgets/Delegates/MapChooserDelegate.cs
+++ b/OpenRA.Game/Widgets/Delegates/MapChooserDelegate.cs
@@ -16,75 +16,75 @@
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see .
*/
-#endregion
-
-using System;
-using System.Collections.Generic;
+#endregion
+
using System.Drawing;
using System.Linq;
-using OpenRA.FileFormats;
-
-namespace OpenRA.Widgets.Delegates
-{
- public class MapChooserDelegate : IWidgetDelegate
- {
- MapStub Map = null;
- public MapChooserDelegate()
- {
- var r = Chrome.rootWidget;
- var bg = r.GetWidget("MAP_CHOOSER");
- bg.SpecialOneArg = (map) => RefreshMapList(map);
- var ml = bg.GetWidget("MAP_LIST");
-
- bg.GetWidget("MAPCHOOSER_MAP_PREVIEW").Map = () => {return Map;};
- bg.GetWidget("CURMAP_TITLE").GetText = () => {return Map.Title;};
- bg.GetWidget("CURMAP_SIZE").GetText = () => {return "{0}x{1}".F(Map.Width, Map.Height);};
- bg.GetWidget("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Map.Tileset].Name;};
- bg.GetWidget("CURMAP_PLAYERS").GetText = () => {return Map.PlayerCount.ToString();};
-
- bg.GetWidget("BUTTON_OK").OnMouseUp = mi => {
- Game.IssueOrder(Order.Command("map " + Map.Uid));
- r.CloseWindow();
- return true;
- };
-
- bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi => {
- r.CloseWindow();
- return true;
- };
-
- var itemTemplate = ml.GetWidget("MAP_TEMPLATE");
- int offset = itemTemplate.Bounds.Y;
- foreach (var kv in Game.AvailableMaps)
- {
- var map = kv.Value;
- if (!map.Selectable)
- continue;
-
- var template = itemTemplate.Clone() as LabelWidget;
- template.Id = "MAP_{0}".F(map.Uid);
- template.GetText = () => " "+map.Title;
- template.GetBackground = () => ((Map == map) ? "dialog2" : null);
- template.OnMouseDown = mi => {Map = map; return true;};
- template.Parent = ml;
-
- template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
- template.IsVisible = () => true;
- ml.AddChild(template);
-
- offset += template.Bounds.Height;
- ml.ContentHeight += template.Bounds.Height;
- }
- }
-
- public void RefreshMapList(object uidobj)
- {
- // Set the default selected map
- var uid = uidobj as string;
- if (uid != null)
- Map = Game.AvailableMaps[ uid ];
- else
- Map = Game.AvailableMaps.FirstOrDefault().Value;
- }
- }
+using OpenRA.FileFormats;
+
+namespace OpenRA.Widgets.Delegates
+{
+ public class MapChooserDelegate : IWidgetDelegate
+ {
+ MapStub Map = null;
+ public MapChooserDelegate()
+ {
+ var r = Chrome.rootWidget;
+ var bg = r.GetWidget("MAP_CHOOSER");
+ bg.SpecialOneArg = (map) => RefreshMapList(map);
+ var ml = bg.GetWidget("MAP_LIST");
+
+ bg.GetWidget("MAPCHOOSER_MAP_PREVIEW").Map = () => Map;
+ bg.GetWidget("CURMAP_TITLE").GetText = () => Map.Title;
+ bg.GetWidget("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Width, Map.Height);
+ bg.GetWidget("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
+ bg.GetWidget("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();
+
+ bg.GetWidget("BUTTON_OK").OnMouseUp = mi =>
+ {
+ Game.IssueOrder(Order.Command("map " + Map.Uid));
+ r.CloseWindow();
+ return true;
+ };
+
+ bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi =>
+ {
+ r.CloseWindow();
+ return true;
+ };
+
+ var itemTemplate = ml.GetWidget("MAP_TEMPLATE");
+ int offset = itemTemplate.Bounds.Y;
+ foreach (var kv in Game.AvailableMaps)
+ {
+ var map = kv.Value;
+ if (!map.Selectable)
+ continue;
+
+ var template = itemTemplate.Clone() as LabelWidget;
+ template.Id = "MAP_{0}".F(map.Uid);
+ template.GetText = () => " " + map.Title;
+ template.GetBackground = () => ((Map == map) ? "dialog2" : null);
+ template.OnMouseDown = mi => { Map = map; return true; };
+ template.Parent = ml;
+
+ template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
+ template.IsVisible = () => true;
+ ml.AddChild(template);
+
+ offset += template.Bounds.Height;
+ ml.ContentHeight += template.Bounds.Height;
+ }
+ }
+
+ public void RefreshMapList(object uidobj)
+ {
+ // Set the default selected map
+ var uid = uidobj as string;
+ if (uid != null)
+ Map = Game.AvailableMaps[uid];
+ else
+ Map = Game.AvailableMaps.FirstOrDefault().Value;
+ }
+ }
}
diff --git a/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs b/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs
index a0e6850309..02e3670c59 100644
--- a/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs
+++ b/OpenRA.Game/Widgets/Delegates/MusicPlayerDelegate.cs
@@ -17,69 +17,80 @@
* along with OpenRA. If not, see .
*/
#endregion
-using System;
+
namespace OpenRA.Widgets.Delegates
-{
- public class MusicPlayerDelegate : IWidgetDelegate
- {
- public MusicPlayerDelegate()
- {
- var bg = Chrome.rootWidget.GetWidget("MUSIC_BG");
- bg.Visible = Game.Settings.MusicPlayer;
-
- bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi => {
- if (Sound.MusicStopped)
- Sound.PlayMusic(GetSong());
- Sound.MusicStopped = false;
- Sound.MusicPaused = false;
- bg.GetWidget("BUTTON_PLAY").Visible = false;
- bg.GetWidget("BUTTON_PAUSE").Visible = true;
- return true;
- };
- bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi => {
- Sound.MusicPaused = true;
- bg.GetWidget("BUTTON_PAUSE").Visible = false;
- bg.GetWidget("BUTTON_PLAY").Visible = true;
- return true;
- };
- bg.GetWidget("BUTTON_STOP").OnMouseUp = mi => {
- Sound.MusicStopped = true;
- bg.GetWidget("BUTTON_PAUSE").Visible = false;
- bg.GetWidget("BUTTON_PLAY").Visible = true;
- return true;
- };
- bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi => {
- Sound.PlayMusic(GetNextSong());
- Sound.MusicStopped = false;
- Sound.MusicPaused = false;
- bg.GetWidget("BUTTON_PLAY").Visible = false;
- bg.GetWidget("BUTTON_PAUSE").Visible = true;
- return true;
- };
- bg.GetWidget("BUTTON_PREV").OnMouseUp = mi => {
- Sound.PlayMusic(GetPrevSong());
- Sound.MusicStopped = false;
- Sound.MusicPaused = false;
- bg.GetWidget("BUTTON_PLAY").Visible = false;
- bg.GetWidget("BUTTON_PAUSE").Visible = true;
- return true;
- };
- }
-
- string GetNextSong()
- {
- if (!Rules.Music.ContainsKey("allmusic")) return null;
- return Rules.Music["allmusic"].Pool.GetNext();
- }
- string GetPrevSong()
- {
- if (!Rules.Music.ContainsKey("allmusic")) return null;
- return Rules.Music["allmusic"].Pool.GetPrev();
- }
- string GetSong()
- {
- if (!Rules.Music.ContainsKey("allmusic")) return null;
- return Rules.Music["allmusic"].Pool.GetCurrent();
- }
+{
+ public class MusicPlayerDelegate : IWidgetDelegate
+ {
+ public MusicPlayerDelegate()
+ {
+ var bg = Chrome.rootWidget.GetWidget("MUSIC_BG");
+ bg.Visible = Game.Settings.MusicPlayer;
+
+ bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
+ {
+ if (Sound.MusicStopped)
+ Sound.PlayMusic(GetSong());
+ Sound.MusicStopped = false;
+ Sound.MusicPaused = false;
+ bg.GetWidget("BUTTON_PLAY").Visible = false;
+ bg.GetWidget("BUTTON_PAUSE").Visible = true;
+ return true;
+ };
+
+ bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi =>
+ {
+ Sound.MusicPaused = true;
+ bg.GetWidget("BUTTON_PAUSE").Visible = false;
+ bg.GetWidget("BUTTON_PLAY").Visible = true;
+ return true;
+ };
+
+ bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
+ {
+ Sound.MusicStopped = true;
+ bg.GetWidget("BUTTON_PAUSE").Visible = false;
+ bg.GetWidget("BUTTON_PLAY").Visible = true;
+ return true;
+ };
+
+ bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi =>
+ {
+ Sound.PlayMusic(GetNextSong());
+ Sound.MusicStopped = false;
+ Sound.MusicPaused = false;
+ bg.GetWidget("BUTTON_PLAY").Visible = false;
+ bg.GetWidget("BUTTON_PAUSE").Visible = true;
+ return true;
+ };
+
+ bg.GetWidget("BUTTON_PREV").OnMouseUp = mi =>
+ {
+ Sound.PlayMusic(GetPrevSong());
+ Sound.MusicStopped = false;
+ Sound.MusicPaused = false;
+ bg.GetWidget("BUTTON_PLAY").Visible = false;
+ bg.GetWidget("BUTTON_PAUSE").Visible = true;
+ return true;
+ };
+ }
+
+ string GetNextSong()
+ {
+ if (!Rules.Music.ContainsKey("allmusic")) return null;
+ return Rules.Music["allmusic"].Pool.GetNext();
+ }
+
+ string GetPrevSong()
+ {
+ if (!Rules.Music.ContainsKey("allmusic")) return null;
+ return Rules.Music["allmusic"].Pool.GetPrev();
+ }
+
+ string GetSong()
+ {
+ if (!Rules.Music.ContainsKey("allmusic")) return null;
+ return Rules.Music["allmusic"].Pool.GetCurrent();
+ }
}
}
diff --git a/OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs b/OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs
index e320112fd0..a0071f9a01 100644
--- a/OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs
+++ b/OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs
@@ -17,31 +17,28 @@
* along with OpenRA. If not, see .
*/
#endregion
-using System;
-using OpenRA.FileFormats;
-using OpenRA.Support;
-
-namespace OpenRA.Widgets.Delegates
-{
- public class PerfDebugDelegate : IWidgetDelegate
- {
- public PerfDebugDelegate()
- {
- var r = Chrome.rootWidget;
- var perfRoot = r.GetWidget("PERF_BG");
- perfRoot.IsVisible = () => {return (perfRoot.Visible && Game.Settings.PerfDebug);};
-
- // Perf text
- var perfText = perfRoot.GetWidget("TEXT");
- perfText.GetText = () => {
- return "Render {0} ({5}={2:F1} ms)\nTick {4} ({3:F1} ms)".F(
- Game.RenderFrame,
- Game.orderManager.FrameNumber,
- PerfHistory.items["render"].LastValue,
- PerfHistory.items["tick_time"].LastValue,
- Game.LocalTick,
- PerfHistory.items["batches"].LastValue);
- };
- }
- }
+
+using OpenRA.Support;
+
+namespace OpenRA.Widgets.Delegates
+{
+ public class PerfDebugDelegate : IWidgetDelegate
+ {
+ public PerfDebugDelegate()
+ {
+ var r = Chrome.rootWidget;
+ var perfRoot = r.GetWidget("PERF_BG");
+ perfRoot.IsVisible = () => perfRoot.Visible && Game.Settings.PerfDebug;
+
+ // Perf text
+ var perfText = perfRoot.GetWidget("TEXT");
+ perfText.GetText = () => "Render {0} ({5}={2:F1} ms)\nTick {4} ({3:F1} ms)".F(
+ Game.RenderFrame,
+ Game.orderManager.FrameNumber,
+ PerfHistory.items["render"].LastValue,
+ PerfHistory.items["tick_time"].LastValue,
+ Game.LocalTick,
+ PerfHistory.items["batches"].LastValue);
+ }
+ }
}
diff --git a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs
index c0c85e1a88..f068260530 100644
--- a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs
+++ b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs
@@ -21,9 +21,8 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
-using OpenRA.Server;
using OpenRA.FileFormats;
-using System;
+using OpenRA.Server;
namespace OpenRA.Widgets.Delegates
{
@@ -36,10 +35,10 @@ namespace OpenRA.Widgets.Delegates
public ServerBrowserDelegate()
{
- var r = Chrome.rootWidget;
+ var r = Chrome.rootWidget;
var bg = r.GetWidget("JOINSERVER_BG");
var dc = r.GetWidget("DIRECTCONNECT_BG");
-
+
MasterServerQuery.OnComplete += games => RefreshServerList(games);
r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi =>
@@ -56,14 +55,14 @@ namespace OpenRA.Widgets.Delegates
return true;
};
-
+
bg.GetWidget("SERVER_INFO").IsVisible = () => currentServer != null;
var preview = bg.GetWidget("MAP_PREVIEW");
preview.Map = () => CurrentMap();
preview.IsVisible = () => CurrentMap() != null;
-
+
bg.GetWidget("SERVER_IP").GetText = () => currentServer.Address;
- bg.GetWidget("SERVER_MODS").GetText = () => string.Join( ",", currentServer.Mods );
+ bg.GetWidget("SERVER_MODS").GetText = () => string.Join(",", currentServer.Mods);
bg.GetWidget("MAP_TITLE").GetText = () => (CurrentMap() != null) ? CurrentMap().Title : "Unknown";
bg.GetWidget("MAP_PLAYERS").GetText = () =>
{
@@ -71,11 +70,11 @@ namespace OpenRA.Widgets.Delegates
return "";
string ret = currentServer.Players.ToString();
if (CurrentMap() != null)
- ret += "/"+CurrentMap().PlayerCount.ToString();
+ ret += "/" + CurrentMap().PlayerCount.ToString();
return ret;
};
-
-
+
+
var sl = bg.GetWidget("SERVER_LIST");
ServerTemplate = sl.GetWidget("SERVER_TEMPLATE");
@@ -101,20 +100,20 @@ namespace OpenRA.Widgets.Delegates
bg.GetWidget("DIRECTCONNECT_BUTTON").OnMouseUp = mi =>
{
r.CloseWindow();
-
+
dc.GetWidget("SERVER_ADDRESS").Text = Game.Settings.LastServer;
r.OpenWindow("DIRECTCONNECT_BG");
return true;
};
-
+
bg.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
{
if (currentServer == null)
return false;
-
+
// Todo: Add an error dialog explaining why we aren't letting them join
// Or even better, reject them server side and display the error in the connection failed dialog.
-
+
// Don't bother joining a server with different mods... its only going to crash
if (currentServer.Mods.SymmetricDifference(Game.LobbyInfo.GlobalSettings.Mods).Any())
{
@@ -122,56 +121,59 @@ namespace OpenRA.Widgets.Delegates
System.Console.WriteLine("FIX THIS BUG YOU NOOB!");
return false;
}
-
+
// Prevent user joining a full server
if (CurrentMap() != null && currentServer.Players >= CurrentMap().PlayerCount)
{
System.Console.WriteLine("Server is full; not connecting");
return false;
}
-
+
r.CloseWindow();
Game.JoinServer(currentServer.Address.Split(':')[0], int.Parse(currentServer.Address.Split(':')[1]));
Game.SetGameId(currentServer.Id);
return true;
};
-
+
// Direct Connect
- dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi => {
-
+ dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
+ {
+
var address = dc.GetWidget("SERVER_ADDRESS").Text;
var cpts = address.Split(':').ToArray();
if (cpts.Length != 2)
return true;
-
+
Game.Settings.LastServer = address;
Game.Settings.Save();
-
+
r.CloseWindow();
Game.JoinServer(cpts[0], int.Parse(cpts[1]));
return true;
};
-
- dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi => {
+
+ dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
+ {
r.CloseWindow();
return r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp(mi);
};
}
-
+
MapStub CurrentMap()
{
- return (currentServer == null || !Game.AvailableMaps.ContainsKey(currentServer.Map)) ? null : Game.AvailableMaps[currentServer.Map];
+ return (currentServer == null || !Game.AvailableMaps.ContainsKey(currentServer.Map))
+ ? null : Game.AvailableMaps[currentServer.Map];
}
-
+
void RefreshServerList(IEnumerable games)
{
- var r = Chrome.rootWidget;
+ var r = Chrome.rootWidget;
var bg = r.GetWidget("JOINSERVER_BG");
var sl = bg.GetWidget("SERVER_LIST");
sl.Children.Clear();
currentServer = null;
-
+
if (games == null)
{
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
@@ -187,26 +189,26 @@ namespace OpenRA.Widgets.Delegates
}
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = false;
-
+
int offset = ServerTemplate.Bounds.Y;
int i = 0;
- foreach (var game in games.Where( g => g.State == 1 )) /* only "waiting for players" */
- {
+ foreach (var game in games.Where(g => g.State == 1)) /* only "waiting for players" */
+ {
var template = ServerTemplate.Clone() as LabelWidget;
template.Id = "JOIN_GAME_{0}".F(i);
template.GetText = () => " {0} ({1})".F( /* /8 = hack */
- game.Name,
+ game.Name,
game.Address);
- template.GetBackground = () => ((currentServer == game) ? "dialog2" : null);
- template.OnMouseDown = mi => {currentServer = game; return true;};
- template.Parent = sl;
-
+ template.GetBackground = () => (currentServer == game) ? "dialog2" : null;
+ template.OnMouseDown = mi => { currentServer = game; return true; };
+ template.Parent = sl;
+
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
template.IsVisible = () => true;
sl.AddChild(template);
-
+
if (i == 0) currentServer = game;
-
+
offset += template.Bounds.Height;
sl.ContentHeight += template.Bounds.Height;
i++;
diff --git a/OpenRA.Game/Widgets/ImageWidget.cs b/OpenRA.Game/Widgets/ImageWidget.cs
index 40daeabe87..3778ba9524 100644
--- a/OpenRA.Game/Widgets/ImageWidget.cs
+++ b/OpenRA.Game/Widgets/ImageWidget.cs
@@ -3,40 +3,39 @@ using System;
using OpenRA.Graphics;
namespace OpenRA.Widgets
-{
- public class ImageWidget : Widget
- {
- public string ImageCollection = "";
- public string ImageName = "";
- public Func GetImageName;
- public Func GetImageCollection;
-
- public ImageWidget ()
- : base()
- {
- GetImageName = () => { return ImageName; };
- GetImageCollection = () => { return ImageCollection; };
- }
-
- public ImageWidget(Widget other)
- : base(other)
- {
- ImageName = (other as ImageWidget).ImageName;
- GetImageName = (other as ImageWidget).GetImageName;
- ImageCollection = (other as ImageWidget).ImageCollection;
- GetImageCollection = (other as ImageWidget).GetImageCollection;
- }
-
- public override Widget Clone()
- {
- return new ImageWidget(this);
- }
-
- public override void DrawInner(World world)
- {
- var name = GetImageName();
- var collection = GetImageCollection();
- WidgetUtils.DrawRGBA(ChromeProvider.GetImage(Game.chrome.renderer, collection, name), RenderOrigin);
- }
+{
+ public class ImageWidget : Widget
+ {
+ public string ImageCollection = "";
+ public string ImageName = "";
+ public Func GetImageName;
+ public Func GetImageCollection;
+
+ public ImageWidget()
+ : base()
+ {
+ GetImageName = () => { return ImageName; };
+ GetImageCollection = () => { return ImageCollection; };
+ }
+
+ protected ImageWidget(ImageWidget other)
+ : base(other)
+ {
+ ImageName = other.ImageName;
+ GetImageName = other.GetImageName;
+ ImageCollection = other.ImageCollection;
+ GetImageCollection = other.GetImageCollection;
+ }
+
+ public override Widget Clone() { return new ImageWidget(this); }
+
+ public override void DrawInner(World world)
+ {
+ var name = GetImageName();
+ var collection = GetImageCollection();
+ WidgetUtils.DrawRGBA(
+ ChromeProvider.GetImage(Game.chrome.renderer, collection, name),
+ RenderOrigin);
+ }
}
}
diff --git a/OpenRA.Game/Widgets/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs
index e8661e303d..8cdc6aab5c 100644
--- a/OpenRA.Game/Widgets/LabelWidget.cs
+++ b/OpenRA.Game/Widgets/LabelWidget.cs
@@ -18,19 +18,14 @@
*/
#endregion
-using System.Drawing;
using System;
+using System.Drawing;
namespace OpenRA.Widgets
{
class LabelWidget : Widget
{
- public enum TextAlign
- {
- Left,
- Center,
- Right
- }
+ public enum TextAlign { Left, Center, Right }
public string Text = null;
public string Background = null;
@@ -46,14 +41,14 @@ namespace OpenRA.Widgets
GetBackground = () => { return Background; };
}
- public LabelWidget(Widget other)
+ protected LabelWidget(LabelWidget other)
: base(other)
{
- Text = (other as LabelWidget).Text;
- Align = (other as LabelWidget).Align;
- Bold = (other as LabelWidget).Bold;
- GetText = (other as LabelWidget).GetText;
- GetBackground = (other as LabelWidget).GetBackground;
+ Text = other.Text;
+ Align = other.Align;
+ Bold = other.Bold;
+ GetText = other.GetText;
+ GetBackground = other.GetBackground;
}
public override void DrawInner(World world)
@@ -79,10 +74,7 @@ namespace OpenRA.Widgets
font.DrawText(text, position, Color.White);
}
-
- public override Widget Clone()
- {
- return new LabelWidget(this);
- }
+
+ public override Widget Clone() { return new LabelWidget(this); }
}
}
\ No newline at end of file
diff --git a/OpenRA.Game/Widgets/ListBoxWidget.cs b/OpenRA.Game/Widgets/ListBoxWidget.cs
index 0a4f8b0304..91866d79ed 100644
--- a/OpenRA.Game/Widgets/ListBoxWidget.cs
+++ b/OpenRA.Game/Widgets/ListBoxWidget.cs
@@ -1,4 +1,3 @@
-using System.Drawing;
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
@@ -18,6 +17,8 @@ using System.Drawing;
* along with OpenRA. If not, see .
*/
#endregion
+
+using System.Drawing;
namespace OpenRA.Widgets
{
@@ -38,50 +39,49 @@ namespace OpenRA.Widgets
Rectangle backgroundRect;
Rectangle scrollbarRect;
- public ListBoxWidget() : base() {}
- public ListBoxWidget(Widget other)
+ public ListBoxWidget() : base() {}
+ protected ListBoxWidget(ListBoxWidget other)
: base(other)
{
- Background = (other as ListBoxWidget).Background;
- upButtonRect = (other as ListBoxWidget).upButtonRect;
- downButtonRect = (other as ListBoxWidget).downButtonRect;
- scrollbarRect = (other as ListBoxWidget).scrollbarRect;
- backgroundRect = (other as ListBoxWidget).backgroundRect;
+ Background = other.Background;
+ upButtonRect = other.upButtonRect;
+ downButtonRect = other.downButtonRect;
+ scrollbarRect = other.scrollbarRect;
+ backgroundRect = other.backgroundRect;
- UpPressed = (other as ListBoxWidget).UpPressed;
- DownPressed = (other as ListBoxWidget).DownPressed;
+ UpPressed = other.UpPressed;
+ DownPressed = other.DownPressed;
}
- public override void DrawInner(World world) {}
- public override void Draw(World world)
- {
- if (!IsVisible())
- return;
-
- backgroundRect = new Rectangle(RenderBounds.X, RenderBounds.Y, RenderBounds.Width - ScrollbarWidth, RenderBounds.Height);
- upButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y, ScrollbarWidth, ScrollbarWidth);
- downButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
- scrollbarRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y + ScrollbarWidth, ScrollbarWidth, RenderBounds.Height - 2*ScrollbarWidth);
-
- string upButtonBg = (UpPressed) ? "dialog3" : "dialog2";
- string downButtonBg = (DownPressed) ? "dialog3" : "dialog2";
- string scrolbarBg = "dialog3";
- string scrollbarButton = "dialog2";
-
- WidgetUtils.DrawPanel(Background, backgroundRect);
- WidgetUtils.DrawPanel(upButtonBg, upButtonRect);
- WidgetUtils.DrawPanel(downButtonBg, downButtonRect);
- WidgetUtils.DrawPanel(scrolbarBg, scrollbarRect);
-
-
- Game.chrome.renderer.Device.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight);
-
- foreach (var child in Children)
- child.Draw(world);
-
- Game.chrome.renderer.RgbaSpriteRenderer.Flush();
- Game.chrome.renderer.Device.DisableScissor();
+ public override void DrawInner(World world) {}
+ public override void Draw(World world)
+ {
+ if (!IsVisible())
+ return;
+
+ backgroundRect = new Rectangle(RenderBounds.X, RenderBounds.Y, RenderBounds.Width - ScrollbarWidth, RenderBounds.Height);
+ upButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y, ScrollbarWidth, ScrollbarWidth);
+ downButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
+ scrollbarRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y + ScrollbarWidth, ScrollbarWidth, RenderBounds.Height - 2 * ScrollbarWidth);
+
+ string upButtonBg = (UpPressed) ? "dialog3" : "dialog2";
+ string downButtonBg = (DownPressed) ? "dialog3" : "dialog2";
+ string scrollbarBg = "dialog3";
+
+ WidgetUtils.DrawPanel(Background, backgroundRect);
+ WidgetUtils.DrawPanel(upButtonBg, upButtonRect);
+ WidgetUtils.DrawPanel(downButtonBg, downButtonRect);
+ WidgetUtils.DrawPanel(scrollbarBg, scrollbarRect);
+
+ Game.chrome.renderer.Device.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight);
+
+ foreach (var child in Children)
+ child.Draw(world);
+
+ Game.chrome.renderer.RgbaSpriteRenderer.Flush();
+ Game.chrome.renderer.Device.DisableScissor();
}
+
public override int2 ChildOrigin { get { return RenderOrigin + new int2(0, (int)ListOffset); } }
public override void Tick (World world)
diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs
index f20531538c..7d75aa9d43 100755
--- a/OpenRA.Game/Widgets/MapPreviewWidget.cs
+++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using OpenRA.Graphics;
using System.Drawing;
+using System.Linq;
using OpenRA.FileFormats;
+using OpenRA.Graphics;
namespace OpenRA.Widgets
{
@@ -14,25 +13,26 @@ namespace OpenRA.Widgets
Sprite mapChooserSprite;
bool mapPreviewDirty = true;
MapStub lastMap;
-
- public Func Map = () => {return null;};
+
+ public Func Map = () => null;
public Action OnSpawnClick = spawn => {};
- public Func> SpawnColors = () => {return new Dictionary(); };
+ public Func> SpawnColors = () => new Dictionary();
public MapPreviewWidget() : base() { }
- public MapPreviewWidget(Widget other)
+ protected MapPreviewWidget(MapPreviewWidget other)
: base(other)
{
- lastMap = (other as MapPreviewWidget).lastMap;
- Map = (other as MapPreviewWidget).Map;
- OnSpawnClick = (other as MapPreviewWidget).OnSpawnClick;
- SpawnColors = (other as MapPreviewWidget).SpawnColors;
+ lastMap = other.lastMap;
+ Map = other.Map;
+ OnSpawnClick = other.OnSpawnClick;
+ SpawnColors = other.SpawnColors;
}
static Sprite UnownedSpawn = null;
static Sprite OwnedSpawn = null;
const int closeEnough = 50;
+
public override bool HandleInput(MouseInput mi)
{
var map = Map();
diff --git a/OpenRA.Game/Widgets/MoneyBinWidget.cs b/OpenRA.Game/Widgets/MoneyBinWidget.cs
index b717f5574c..db818b9732 100644
--- a/OpenRA.Game/Widgets/MoneyBinWidget.cs
+++ b/OpenRA.Game/Widgets/MoneyBinWidget.cs
@@ -36,12 +36,12 @@ namespace OpenRA.Widgets
/* legacy crap!!! */
List>> buttons = new List>>();
void AddButton(Rectangle r, Action b) { buttons.Add(Pair.New(r, b)); }
-
+
public MoneyBinWidget() : base() { }
- public MoneyBinWidget(Widget other) : base(other) { }
+ protected MoneyBinWidget(Widget other) : base(other) { }
public override Widget Clone() { return new MoneyBinWidget(this); }
-
+
public override void DrawInner(World world)
{
var playerResources = world.LocalPlayer.PlayerActor.traits.Get();
@@ -54,7 +54,7 @@ namespace OpenRA.Widgets
new float2(Bounds.Left, 0), "chrome");
// Cash
- var cashDigits = (SplitOreAndCash ? playerResources.DisplayCash
+ var cashDigits = (SplitOreAndCash ? playerResources.DisplayCash
: (playerResources.DisplayCash + playerResources.DisplayOre)).ToString();
var x = Bounds.Right - 65;
@@ -149,6 +149,6 @@ namespace OpenRA.Widgets
}
return false;
- }
+ }
}
}
diff --git a/OpenRA.Game/Widgets/PerfGraphWidget.cs b/OpenRA.Game/Widgets/PerfGraphWidget.cs
index 0f367b8549..b282498321 100644
--- a/OpenRA.Game/Widgets/PerfGraphWidget.cs
+++ b/OpenRA.Game/Widgets/PerfGraphWidget.cs
@@ -17,8 +17,8 @@
* along with OpenRA. If not, see .
*/
#endregion
-using System.Drawing;
-using System.Collections.Generic;
+
+using System.Drawing;
using System.Linq;
using OpenRA.Support;
@@ -26,36 +26,32 @@ namespace OpenRA.Widgets
{
class PerfGraphWidget : Widget
{
- public PerfGraphWidget() : base() { }
-
- public PerfGraphWidget(Widget other) : base(other) { }
-
- public override Widget Clone() { return new PerfGraphWidget(this); }
-
- public override void DrawInner(World world)
- {
- var rect = RenderBounds;
- float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom);
- float2 basis = new float2(-rect.Width/100,-rect.Height/100);
-
- Game.chrome.lineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
- Game.chrome.lineRenderer.DrawLine(origin + new float2(100,0) * basis, origin + new float2(100,100) * basis, Color.White, Color.White);
-
- foreach (var item in PerfHistory.items.Values)
- {
- int n = 0;
- item.Samples().Aggregate((a, b) =>
- {
- Game.chrome.lineRenderer.DrawLine(
- origin + new float2(n, (float)a) * basis,
- origin + new float2(n+1, (float)b) * basis,
- item.c, item.c);
- ++n;
- return b;
- });
- }
-
- Game.chrome.lineRenderer.Flush();
+ public PerfGraphWidget() : base() { }
+
+ public override void DrawInner(World world)
+ {
+ var rect = RenderBounds;
+ float2 origin = Game.viewport.Location + new float2(rect.Right, rect.Bottom);
+ float2 basis = new float2(-rect.Width / 100, -rect.Height / 100);
+
+ Game.chrome.lineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
+ Game.chrome.lineRenderer.DrawLine(origin + new float2(100, 0) * basis, origin + new float2(100, 100) * basis, Color.White, Color.White);
+
+ foreach (var item in PerfHistory.items.Values)
+ {
+ int n = 0;
+ item.Samples().Aggregate((a, b) =>
+ {
+ Game.chrome.lineRenderer.DrawLine(
+ origin + new float2(n, (float)a) * basis,
+ origin + new float2(n + 1, (float)b) * basis,
+ item.c, item.c);
+ ++n;
+ return b;
+ });
+ }
+
+ Game.chrome.lineRenderer.Flush();
}
}
}
\ No newline at end of file
diff --git a/OpenRA.Game/Widgets/PostGameWidget.cs b/OpenRA.Game/Widgets/PostGameWidget.cs
index 7d49025ca5..7be747e29c 100644
--- a/OpenRA.Game/Widgets/PostGameWidget.cs
+++ b/OpenRA.Game/Widgets/PostGameWidget.cs
@@ -28,10 +28,6 @@ namespace OpenRA.Widgets
{
public PostGameWidget() : base() { }
- public PostGameWidget(Widget other) : base(other) { }
-
- public override Widget Clone() { return new PostGameWidget(this); }
-
bool AreMutualAllies(Player a, Player b) { return a.Stances[b] == Stance.Ally && b.Stances[a] == Stance.Ally; }
// todo: all this shit needs to move, probably to Player.
diff --git a/OpenRA.Game/Widgets/PowerBinWidget.cs b/OpenRA.Game/Widgets/PowerBinWidget.cs
index 835bda28d3..6499d5a181 100644
--- a/OpenRA.Game/Widgets/PowerBinWidget.cs
+++ b/OpenRA.Game/Widgets/PowerBinWidget.cs
@@ -21,80 +21,77 @@
using System;
using System.Drawing;
using OpenRA.Graphics;
-using OpenRA.Traits;
-
-namespace OpenRA.Widgets
-{
-
- public class PowerBinWidget : Widget
- {
- // Power bar
- static float2 powerOrigin = new float2(42, 205); // Relative to radarOrigin
- static Size powerSize = new Size(138, 5);
- float? lastPowerProvidedPos;
- float? lastPowerDrainedPos;
- string powerCollection;
-
- public override Widget Clone() { throw new NotImplementedException("Why are you Cloning PowerBin?"); }
-
- public override void DrawInner(World world)
- {
- powerCollection = "power-" + world.LocalPlayer.Country.Race;
-
- var resources = world.LocalPlayer.PlayerActor.traits.Get();
-
- // Nothing to draw
- if (resources.PowerProvided == 0
- && resources.PowerDrained == 0)
- return;
-
- var renderer = Game.chrome.renderer;
- var lineRenderer = Game.chrome.lineRenderer;
- var rgbaRenderer = renderer.RgbaSpriteRenderer;
-
- // Draw bar horizontally
- var barStart = powerOrigin + RadarBinWidget.radarOrigin;
- var barEnd = barStart + new float2(powerSize.Width, 0);
-
- float powerScaleBy = 100;
- var maxPower = Math.Max(resources.PowerProvided, resources.PowerDrained);
- while (maxPower >= powerScaleBy) powerScaleBy *= 2;
-
- // Current power supply
- var powerLevelTemp = barStart.X + (barEnd.X - barStart.X) * (resources.PowerProvided / powerScaleBy);
- lastPowerProvidedPos = float2.Lerp(lastPowerProvidedPos.GetValueOrDefault(powerLevelTemp), powerLevelTemp, .3f);
- float2 powerLevel = new float2(lastPowerProvidedPos.Value, barStart.Y);
-
- var color = Color.LimeGreen;
- if (resources.GetPowerState() == PowerState.Low)
- color = Color.Orange;
- if (resources.GetPowerState() == PowerState.Critical)
- color = Color.Red;
-
- var colorDark = Graphics.Util.Lerp(0.25f, color, Color.Black);
- for (int i = 0; i < powerSize.Height; i++)
- {
- color = (i - 1 < powerSize.Height / 2) ? color : colorDark;
- float2 leftOffset = new float2(0, i);
- float2 rightOffset = new float2(0, i);
- // Indent corners
- if ((i == 0 || i == powerSize.Height - 1) && powerLevel.X - barStart.X > 1)
- {
- leftOffset.X += 1;
- rightOffset.X -= 1;
- }
- lineRenderer.DrawLine(Game.viewport.Location + barStart + leftOffset, Game.viewport.Location + powerLevel + rightOffset, color, color);
- }
- lineRenderer.Flush();
-
- // Power usage indicator
- var indicator = ChromeProvider.GetImage(renderer, powerCollection, "power-indicator");
- var powerDrainedTemp = barStart.X + (barEnd.X - barStart.X) * (resources.PowerDrained / powerScaleBy);
- lastPowerDrainedPos = float2.Lerp(lastPowerDrainedPos.GetValueOrDefault(powerDrainedTemp), powerDrainedTemp, .3f);
- float2 powerDrainLevel = new float2(lastPowerDrainedPos.Value - indicator.size.X / 2, barStart.Y - 1);
-
- rgbaRenderer.DrawSprite(indicator, powerDrainLevel, "chrome");
- rgbaRenderer.Flush();
- }
- }
+using OpenRA.Traits;
+
+namespace OpenRA.Widgets
+{
+ public class PowerBinWidget : Widget
+ {
+ // Power bar
+ static float2 powerOrigin = new float2(42, 205); // Relative to radarOrigin
+ static Size powerSize = new Size(138, 5);
+ float? lastPowerProvidedPos;
+ float? lastPowerDrainedPos;
+ string powerCollection;
+
+ public override void DrawInner(World world)
+ {
+ powerCollection = "power-" + world.LocalPlayer.Country.Race;
+
+ var resources = world.LocalPlayer.PlayerActor.traits.Get();
+
+ // Nothing to draw
+ if (resources.PowerProvided == 0
+ && resources.PowerDrained == 0)
+ return;
+
+ var renderer = Game.chrome.renderer;
+ var lineRenderer = Game.chrome.lineRenderer;
+ var rgbaRenderer = renderer.RgbaSpriteRenderer;
+
+ // Draw bar horizontally
+ var barStart = powerOrigin + RadarBinWidget.radarOrigin;
+ var barEnd = barStart + new float2(powerSize.Width, 0);
+
+ float powerScaleBy = 100;
+ var maxPower = Math.Max(resources.PowerProvided, resources.PowerDrained);
+ while (maxPower >= powerScaleBy) powerScaleBy *= 2;
+
+ // Current power supply
+ var powerLevelTemp = barStart.X + (barEnd.X - barStart.X) * (resources.PowerProvided / powerScaleBy);
+ lastPowerProvidedPos = float2.Lerp(lastPowerProvidedPos.GetValueOrDefault(powerLevelTemp), powerLevelTemp, .3f);
+ float2 powerLevel = new float2(lastPowerProvidedPos.Value, barStart.Y);
+
+ var color = Color.LimeGreen;
+ if (resources.GetPowerState() == PowerState.Low)
+ color = Color.Orange;
+ if (resources.GetPowerState() == PowerState.Critical)
+ color = Color.Red;
+
+ var colorDark = Graphics.Util.Lerp(0.25f, color, Color.Black);
+ for (int i = 0; i < powerSize.Height; i++)
+ {
+ color = (i - 1 < powerSize.Height / 2) ? color : colorDark;
+ float2 leftOffset = new float2(0, i);
+ float2 rightOffset = new float2(0, i);
+ // Indent corners
+ if ((i == 0 || i == powerSize.Height - 1) && powerLevel.X - barStart.X > 1)
+ {
+ leftOffset.X += 1;
+ rightOffset.X -= 1;
+ }
+ lineRenderer.DrawLine(Game.viewport.Location + barStart + leftOffset, Game.viewport.Location + powerLevel + rightOffset, color, color);
+ }
+ lineRenderer.Flush();
+
+ // Power usage indicator
+ var indicator = ChromeProvider.GetImage(renderer, powerCollection, "power-indicator");
+ var powerDrainedTemp = barStart.X + (barEnd.X - barStart.X) * (resources.PowerDrained / powerScaleBy);
+ lastPowerDrainedPos = float2.Lerp(lastPowerDrainedPos.GetValueOrDefault(powerDrainedTemp), powerDrainedTemp, .3f);
+ float2 powerDrainLevel = new float2(lastPowerDrainedPos.Value - indicator.size.X / 2, barStart.Y - 1);
+
+ rgbaRenderer.DrawSprite(indicator, powerDrainLevel, "chrome");
+ rgbaRenderer.Flush();
+ }
+ }
}
diff --git a/OpenRA.Game/Widgets/RadarBinWidget.cs b/OpenRA.Game/Widgets/RadarBinWidget.cs
index fb60bc0bd5..2b27d48e25 100644
--- a/OpenRA.Game/Widgets/RadarBinWidget.cs
+++ b/OpenRA.Game/Widgets/RadarBinWidget.cs
@@ -44,10 +44,10 @@ namespace OpenRA.Widgets
{
if (!hasRadar || radarAnimating) return false; // we're not set up for this.
- var mapRect = new RectangleF(radarOrigin.X + 9, radarOrigin.Y + (192 - radarMinimapHeight) / 2,
+ var mapRect = new RectangleF(radarOrigin.X + 9, radarOrigin.Y + (192 - radarMinimapHeight) / 2,
192, radarMinimapHeight);
- if (!mapRect.Contains(mi.Location.ToPointF()))
+ if (!mapRect.Contains(mi.Location.ToPointF()))
return false;
var loc = Game.world.Minimap.MinimapPixelToCell(mapRect, mi.Location);
@@ -59,10 +59,10 @@ namespace OpenRA.Widgets
{
// fake a mousedown/mouseup here
- var fakemi = new MouseInput
+ var fakemi = new MouseInput
{
- Event = MouseInputEvent.Down,
- Button = MouseButton.Right,
+ Event = MouseInputEvent.Down,
+ Button = MouseButton.Right,
Modifiers = mi.Modifiers,
Location = (loc * Game.CellSize - Game.viewport.Location).ToInt2()
};
@@ -75,8 +75,6 @@ namespace OpenRA.Widgets
return true;
}
-
- public override Widget Clone() { throw new NotImplementedException("Why are you Cloning RadarBin?"); }
public override void DrawInner(World world)
{
@@ -143,7 +141,7 @@ namespace OpenRA.Widgets
radarMinimapHeight = float2.Lerp(0, 192, (radarAnimationFrame - radarSlideAnimationLength) * 1.0f / radarActivateAnimationLength);
// Animation is complete
- if (radarAnimationFrame == (hasRadar ? radarSlideAnimationLength+radarActivateAnimationLength : 0))
+ if (radarAnimationFrame == (hasRadar ? radarSlideAnimationLength + radarActivateAnimationLength : 0))
radarAnimating = false;
}
}
diff --git a/OpenRA.Game/Widgets/SliderWidget.cs b/OpenRA.Game/Widgets/SliderWidget.cs
index 040fdaf4cf..6292ccadb9 100644
--- a/OpenRA.Game/Widgets/SliderWidget.cs
+++ b/OpenRA.Game/Widgets/SliderWidget.cs
@@ -1,158 +1,163 @@
using System;
-using System.Drawing;
-
-namespace OpenRA.Widgets
-{
- public class SliderWidget : Widget
- {
- public event Action OnChange;
- public Func GetOffset;
- public float Offset = 0;
- public int Ticks = 0;
- public int TrackHeight = 5;
-
- int2 lastMouseLocation;
- bool isMoving = false;
-
- public SliderWidget () : base()
- {
- GetOffset = () => Offset;
- OnChange = x => Offset = x;
- }
-
- public SliderWidget(Widget other)
- : base(other)
- {
- OnChange = (other as SliderWidget).OnChange;
- GetOffset = (other as SliderWidget).GetOffset;
- Offset = (other as SliderWidget).Offset;
- Ticks = (other as SliderWidget).Ticks;
- TrackHeight = (other as SliderWidget).TrackHeight;
- lastMouseLocation = (other as SliderWidget).lastMouseLocation;
- isMoving = (other as SliderWidget).isMoving;
- }
-
- public override bool HandleInput(MouseInput mi)
- {
- if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
- return false;
-
- if (!Focused)
- return false;
-
- switch (mi.Event)
- {
- case MouseInputEvent.Up:
- {
- if (Focused)
- {
- isMoving = false;
- base.LoseFocus(mi);
- }
- }
- break;
-
- case MouseInputEvent.Down:
- {
- if (thumbRect.Contains(mi.Location.ToPoint()))
- {
- isMoving = true;
- lastMouseLocation = mi.Location;
- }
- else if (Ticks != 0)
- {
- var pos = GetOffset();
-
- // Offset slightly the direction we want to move so we don't get stuck on a tick
- var delta = 0.001;
- var targetTick = (float)((mi.Location.X > thumbRect.Right) ? Math.Ceiling((pos+delta)*(Ticks-1))
- : Math.Floor((pos-delta)*(Ticks-1)));
- OnChange(targetTick/(Ticks-1));
-
- if (thumbRect.Contains(mi.Location.ToPoint()))
- {
- isMoving = true;
- lastMouseLocation = mi.Location;
- }
- return true;
- }
- else // No ticks; move to the mouse position
- {
- var thumb = thumbRect;
- var center = thumb.X + thumb.Width/2;
- var newOffset = OffsetBy((mi.Location.X - center)*1f/(RenderBounds.Width-thumb.Width));
- if (newOffset != GetOffset())
- {
- OnChange(newOffset);
-
- if (thumbRect.Contains(mi.Location.ToPoint()))
- {
- isMoving = true;
- lastMouseLocation = mi.Location;
- }
- return true;
- }
- }
- }
- break;
-
- case MouseInputEvent.Move:
- {
- if ((mi.Location.X != lastMouseLocation.X) && isMoving)
- {
- var newOffset = OffsetBy((mi.Location.X - lastMouseLocation.X)*1f/(RenderBounds.Width-thumbRect.Width));
- if (newOffset != Offset)
- {
- lastMouseLocation = mi.Location;
- OnChange(newOffset);
- }
- }
- }
- break;
- }
-
- return thumbRect.Contains(mi.Location.X,mi.Location.Y);
- }
-
- float OffsetBy(float amount)
- {
- var centerPos = GetOffset() + amount;
- if (centerPos < 0) centerPos = 0;
- if (centerPos > 1) centerPos = 1;
- return centerPos;
- }
-
- public override Widget Clone() { return new SliderWidget(this); }
-
- Rectangle thumbRect
- { get {
- var width = RenderBounds.Height;
- var height = RenderBounds.Height;
- var origin = (int)((RenderBounds.X + width/2) + GetOffset()*(RenderBounds.Width - width) - width/2f);
- return new Rectangle(origin, RenderBounds.Y, width, height);
- } }
-
- public override void DrawInner(World world) {
- if (!IsVisible())
- return;
-
- var trackWidth = RenderBounds.Width - thumbRect.Width;
- var trackOrigin = RenderBounds.X + thumbRect.Width/2;
- var trackRect = new Rectangle(trackOrigin-1, RenderBounds.Y + (RenderBounds.Height - TrackHeight)/2, trackWidth+2, TrackHeight);
-
- // Tickmarks (hacked until we have real art)
- for (int i = 0; i < Ticks; i++)
- {
- var tickRect = new Rectangle(trackOrigin -1 + (int)(i*trackWidth*1f/(Ticks-1)),
- RenderBounds.Y + RenderBounds.Height/2, 2, RenderBounds.Height/2);
- WidgetUtils.DrawPanel("dialog2", tickRect);
- }
- // Track
- WidgetUtils.DrawPanel("dialog3", trackRect);
-
- // Thumb
- WidgetUtils.DrawPanel("dialog2", thumbRect);
- }
- }
+using System.Drawing;
+
+namespace OpenRA.Widgets
+{
+ public class SliderWidget : Widget
+ {
+ public event Action OnChange;
+ public Func GetOffset;
+ public float Offset = 0;
+ public int Ticks = 0;
+ public int TrackHeight = 5;
+
+ int2 lastMouseLocation;
+ bool isMoving = false;
+
+ public SliderWidget()
+ : base()
+ {
+ GetOffset = () => Offset;
+ OnChange = x => Offset = x;
+ }
+
+ public SliderWidget(SliderWidget other)
+ : base(other)
+ {
+ OnChange = other.OnChange;
+ GetOffset = other.GetOffset;
+ Offset = other.Offset;
+ Ticks = other.Ticks;
+ TrackHeight = other.TrackHeight;
+ lastMouseLocation = other.lastMouseLocation;
+ isMoving = other.isMoving;
+ }
+
+ public override bool HandleInput(MouseInput mi)
+ {
+ if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
+ return false;
+
+ if (!Focused)
+ return false;
+
+ switch (mi.Event)
+ {
+ case MouseInputEvent.Up:
+ {
+ if (Focused)
+ {
+ isMoving = false;
+ base.LoseFocus(mi);
+ }
+ }
+ break;
+
+ case MouseInputEvent.Down:
+ {
+ if (thumbRect.Contains(mi.Location.ToPoint()))
+ {
+ isMoving = true;
+ lastMouseLocation = mi.Location;
+ }
+ else if (Ticks != 0)
+ {
+ var pos = GetOffset();
+
+ // Offset slightly the direction we want to move so we don't get stuck on a tick
+ var delta = 0.001;
+ var targetTick = (float)((mi.Location.X > thumbRect.Right) ? Math.Ceiling((pos + delta) * (Ticks - 1))
+ : Math.Floor((pos - delta) * (Ticks - 1)));
+ OnChange(targetTick / (Ticks - 1));
+
+ if (thumbRect.Contains(mi.Location.ToPoint()))
+ {
+ isMoving = true;
+ lastMouseLocation = mi.Location;
+ }
+ return true;
+ }
+ else // No ticks; move to the mouse position
+ {
+ var thumb = thumbRect;
+ var center = thumb.X + thumb.Width / 2;
+ var newOffset = OffsetBy((mi.Location.X - center) * 1f / (RenderBounds.Width - thumb.Width));
+ if (newOffset != GetOffset())
+ {
+ OnChange(newOffset);
+
+ if (thumbRect.Contains(mi.Location.ToPoint()))
+ {
+ isMoving = true;
+ lastMouseLocation = mi.Location;
+ }
+ return true;
+ }
+ }
+ }
+ break;
+
+ case MouseInputEvent.Move:
+ {
+ if ((mi.Location.X != lastMouseLocation.X) && isMoving)
+ {
+ var newOffset = OffsetBy((mi.Location.X - lastMouseLocation.X) * 1f / (RenderBounds.Width - thumbRect.Width));
+ if (newOffset != Offset)
+ {
+ lastMouseLocation = mi.Location;
+ OnChange(newOffset);
+ }
+ }
+ }
+ break;
+ }
+
+ return thumbRect.Contains(mi.Location.X, mi.Location.Y);
+ }
+
+ float OffsetBy(float amount)
+ {
+ var centerPos = GetOffset() + amount;
+ if (centerPos < 0) centerPos = 0;
+ if (centerPos > 1) centerPos = 1;
+ return centerPos;
+ }
+
+ public override Widget Clone() { return new SliderWidget(this); }
+
+ Rectangle thumbRect
+ {
+ get
+ {
+ var width = RenderBounds.Height;
+ var height = RenderBounds.Height;
+ var origin = (int)((RenderBounds.X + width / 2) + GetOffset() * (RenderBounds.Width - width) - width / 2f);
+ return new Rectangle(origin, RenderBounds.Y, width, height);
+ }
+ }
+
+ public override void DrawInner(World world)
+ {
+ if (!IsVisible())
+ return;
+
+ var trackWidth = RenderBounds.Width - thumbRect.Width;
+ var trackOrigin = RenderBounds.X + thumbRect.Width / 2;
+ var trackRect = new Rectangle(trackOrigin - 1, RenderBounds.Y + (RenderBounds.Height - TrackHeight) / 2, trackWidth + 2, TrackHeight);
+
+ // Tickmarks (hacked until we have real art)
+ for (int i = 0; i < Ticks; i++)
+ {
+ var tickRect = new Rectangle(trackOrigin - 1 + (int)(i * trackWidth * 1f / (Ticks - 1)),
+ RenderBounds.Y + RenderBounds.Height / 2, 2, RenderBounds.Height / 2);
+ WidgetUtils.DrawPanel("dialog2", tickRect);
+ }
+ // Track
+ WidgetUtils.DrawPanel("dialog3", trackRect);
+
+ // Thumb
+ WidgetUtils.DrawPanel("dialog2", thumbRect);
+ }
+ }
}
diff --git a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs
index 9517daf72c..9cf9da1662 100644
--- a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs
+++ b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs
@@ -16,16 +16,16 @@
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see .
*/
-#endregion
-
-using System.Drawing;
-using System.Collections.Generic;
-using System.Linq;
-using OpenRA;
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using OpenRA.FileFormats;
+using OpenRA.Graphics;
using OpenRA.Traits;
-using OpenRA.Graphics;
-using OpenRA.FileFormats;
-using System;
+
namespace OpenRA.Widgets
{
class SpecialPowerBinWidget : Widget
@@ -36,16 +36,6 @@ namespace OpenRA.Widgets
readonly List>> buttons = new List>>();
public SpecialPowerBinWidget() : base() { }
-
- public SpecialPowerBinWidget(Widget other)
- : base(other)
- {
- ready = (other as SpecialPowerBinWidget).ready;
- clock = (other as SpecialPowerBinWidget).clock;
- buttons = (other as SpecialPowerBinWidget).buttons;
- }
-
- public override Widget Clone() { return new SpecialPowerBinWidget(this); }
public override void Initialize()
{
diff --git a/OpenRA.Game/Widgets/TextFieldWidget.cs b/OpenRA.Game/Widgets/TextFieldWidget.cs
index d3c0614536..da1fdd17c4 100644
--- a/OpenRA.Game/Widgets/TextFieldWidget.cs
+++ b/OpenRA.Game/Widgets/TextFieldWidget.cs
@@ -16,140 +16,137 @@
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see .
*/
-#endregion
-
-using System.Drawing;
-using System;
-
-namespace OpenRA.Widgets
-{
- class TextFieldWidget : Widget
- {
- public string Text = "";
- public int MaxLength = 0;
- public bool Bold = false;
- public int VisualHeight = 1;
- public Func OnEnterKey = () => {return false;};
- public Func OnTabKey = () => {return false;};
- public Action OnLoseFocus = () => {};
-
- public TextFieldWidget()
- : base()
- {
- }
-
- public TextFieldWidget(Widget widget)
- :base(widget)
- {
- Text = (widget as TextFieldWidget).Text;
- MaxLength = (widget as TextFieldWidget).MaxLength;
- Bold = (widget as TextFieldWidget).Bold;
- VisualHeight = (widget as TextFieldWidget).VisualHeight;
- }
-
- public override bool LoseFocus(MouseInput mi)
- {
- OnLoseFocus();
- var lose = base.LoseFocus(mi);
- return lose;
- }
-
- public override bool HandleInput(MouseInput mi)
- {
- if (mi.Event == MouseInputEvent.Move)
- return false;
-
- // Lose focus if they click outside the box; return false so the next widget can grab this event
- if (mi.Event == MouseInputEvent.Down && !RenderBounds.Contains(mi.Location.X,mi.Location.Y) && LoseFocus(mi))
- return false;
-
- if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
- return false;
-
- blinkCycle = 10;
- showCursor = true;
- return true;
- }
-
- public override bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
- {
- // Only take input if we are focused
- if (!Focused)
- return false;
-
- if (e.KeyChar == '\r' && OnEnterKey())
- return true;
-
- if (e.KeyChar == '\t' && OnTabKey())
- return true;
-
- TypeChar(e.KeyChar);
- return true;
- }
-
- public void TypeChar(char c)
- {
- if (c == '\b' || c == 0x7f)
- {
- if (Text.Length > 0)
- Text = Text.Remove(Text.Length - 1);
- }
- else if (!char.IsControl(c))
- {
- if (MaxLength > 0 && Text.Length >= MaxLength)
- return;
-
- Text += c;
- }
- }
-
- int blinkCycle = 10;
- bool showCursor = true;
- public override void Tick(World world)
- {
- if (--blinkCycle <= 0)
- {
- blinkCycle = 20;
- showCursor ^= true;
- }
- base.Tick(world);
- }
-
- public override void DrawInner(World world)
- {
- int margin = 5;
- var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
- var cursor = (showCursor && Focused) ? "|" : "";
- var textSize = font.Measure(Text + "|");
- var pos = RenderOrigin;
-
- WidgetUtils.DrawPanel("dialog3",
- new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
-
- // Inset text by the margin and center vertically
- var textPos = pos + new int2( margin, (Bounds.Height - textSize.Y)/2 - VisualHeight);
-
- // Right align when editing and scissor when the text overflows
- if (textSize.X > Bounds.Width - 2*margin)
- {
- if (Focused)
- textPos += new int2(Bounds.Width - 2*margin - textSize.X,0);
-
- Game.chrome.renderer.Device.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2*margin, Bounds.Bottom);
- }
-
- font.DrawText(Text + cursor, textPos, Color.White);
-
- if (textSize.X > Bounds.Width - 2*margin)
- {
- Game.chrome.renderer.RgbaSpriteRenderer.Flush();
- Game.chrome.renderer.Device.DisableScissor();
- }
- }
-
- public override Widget Clone()
- {
- return new TextFieldWidget(this);
- }
- }
+#endregion
+
+using System;
+using System.Drawing;
+
+namespace OpenRA.Widgets
+{
+ class TextFieldWidget : Widget
+ {
+ public string Text = "";
+ public int MaxLength = 0;
+ public bool Bold = false;
+ public int VisualHeight = 1;
+ public Func OnEnterKey = () => false;
+ public Func OnTabKey = () => false;
+ public Action OnLoseFocus = () => { };
+
+ public TextFieldWidget()
+ : base()
+ {
+ }
+
+ protected TextFieldWidget(TextFieldWidget widget)
+ : base(widget)
+ {
+ Text = widget.Text;
+ MaxLength = widget.MaxLength;
+ Bold = widget.Bold;
+ VisualHeight = widget.VisualHeight;
+ }
+
+ public override bool LoseFocus(MouseInput mi)
+ {
+ OnLoseFocus();
+ var lose = base.LoseFocus(mi);
+ return lose;
+ }
+
+ public override bool HandleInput(MouseInput mi)
+ {
+ if (mi.Event == MouseInputEvent.Move)
+ return false;
+
+ // Lose focus if they click outside the box; return false so the next widget can grab this event
+ if (mi.Event == MouseInputEvent.Down && !RenderBounds.Contains(mi.Location.X, mi.Location.Y) && LoseFocus(mi))
+ return false;
+
+ if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
+ return false;
+
+ blinkCycle = 10;
+ showCursor = true;
+ return true;
+ }
+
+ public override bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
+ {
+ // Only take input if we are focused
+ if (!Focused)
+ return false;
+
+ if (e.KeyChar == '\r' && OnEnterKey())
+ return true;
+
+ if (e.KeyChar == '\t' && OnTabKey())
+ return true;
+
+ TypeChar(e.KeyChar);
+ return true;
+ }
+
+ public void TypeChar(char c)
+ {
+ if (c == '\b' || c == 0x7f)
+ {
+ if (Text.Length > 0)
+ Text = Text.Remove(Text.Length - 1);
+ }
+ else if (!char.IsControl(c))
+ {
+ if (MaxLength > 0 && Text.Length >= MaxLength)
+ return;
+
+ Text += c;
+ }
+ }
+
+ int blinkCycle = 10;
+ bool showCursor = true;
+ public override void Tick(World world)
+ {
+ if (--blinkCycle <= 0)
+ {
+ blinkCycle = 20;
+ showCursor ^= true;
+ }
+ base.Tick(world);
+ }
+
+ public override void DrawInner(World world)
+ {
+ int margin = 5;
+ var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
+ var cursor = (showCursor && Focused) ? "|" : "";
+ var textSize = font.Measure(Text + "|");
+ var pos = RenderOrigin;
+
+ WidgetUtils.DrawPanel("dialog3",
+ new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height));
+
+ // Inset text by the margin and center vertically
+ var textPos = pos + new int2(margin, (Bounds.Height - textSize.Y) / 2 - VisualHeight);
+
+ // Right align when editing and scissor when the text overflows
+ if (textSize.X > Bounds.Width - 2 * margin)
+ {
+ if (Focused)
+ textPos += new int2(Bounds.Width - 2 * margin - textSize.X, 0);
+
+ Game.chrome.renderer.Device.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2 * margin, Bounds.Bottom);
+ }
+
+ font.DrawText(Text + cursor, textPos, Color.White);
+
+ if (textSize.X > Bounds.Width - 2 * margin)
+ {
+ Game.chrome.renderer.RgbaSpriteRenderer.Flush();
+ Game.chrome.renderer.Device.DisableScissor();
+ }
+ }
+
+ public override Widget Clone() { return new TextFieldWidget(this); }
+ }
}
\ No newline at end of file
diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs
index 88a8710d06..25e3cf9c6b 100644
--- a/OpenRA.Game/Widgets/Widget.cs
+++ b/OpenRA.Game/Widgets/Widget.cs
@@ -22,8 +22,8 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
+using System.Windows.Forms;
using OpenRA.FileFormats;
-using OpenRA.Widgets.Delegates;
namespace OpenRA.Widgets
{
@@ -49,10 +49,10 @@ namespace OpenRA.Widgets
// Common Funcs that most widgets will want
public Action