From 41fe6f01fcbfb7920e4a69e1eb8bb9a58faa4d75 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 24 Mar 2010 08:30:59 +1300 Subject: [PATCH] fixed up the chrome/widgets tree --- OpenRA.Game/Chrome/DefaultWidgetDelegates.cs | 263 ------------------ OpenRA.Game/OpenRA.Game.csproj | 20 +- OpenRA.Game/Widgets/BackgroundWidget.cs | 37 +++ .../{Chrome => Widgets}/ButtonWidget.cs | 1 - .../{Chrome => Widgets}/CheckboxWidget.cs | 1 - .../Delegates/ConnectionDialogsDelegate.cs | 48 ++++ .../Delegates/CreateServerMenuDelegate.cs | 79 ++++++ .../Delegates/MainMenuButtonsDelegate.cs | 36 +++ .../Delegates/ServerBrowserDelegate.cs | 90 ++++++ .../Widgets/Delegates/SettingsMenuDelegate.cs | 72 +++++ .../Widgets/Delegates/WidgetDelegate.cs | 33 +++ .../{Chrome => Widgets}/LabelWidget.cs | 0 OpenRA.Game/{Chrome => Widgets}/Widget.cs | 0 .../{Chrome => Widgets}/WidgetLoader.cs | 0 .../WidgetUtils.cs} | 24 +- 15 files changed, 413 insertions(+), 291 deletions(-) delete mode 100644 OpenRA.Game/Chrome/DefaultWidgetDelegates.cs create mode 100644 OpenRA.Game/Widgets/BackgroundWidget.cs rename OpenRA.Game/{Chrome => Widgets}/ButtonWidget.cs (96%) rename OpenRA.Game/{Chrome => Widgets}/CheckboxWidget.cs (95%) create mode 100644 OpenRA.Game/Widgets/Delegates/ConnectionDialogsDelegate.cs create mode 100644 OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs create mode 100644 OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs create mode 100644 OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs create mode 100644 OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs create mode 100644 OpenRA.Game/Widgets/Delegates/WidgetDelegate.cs rename OpenRA.Game/{Chrome => Widgets}/LabelWidget.cs (100%) rename OpenRA.Game/{Chrome => Widgets}/Widget.cs (100%) rename OpenRA.Game/{Chrome => Widgets}/WidgetLoader.cs (100%) rename OpenRA.Game/{Chrome/BackgroundWidget.cs => Widgets/WidgetUtils.cs} (89%) diff --git a/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs b/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs deleted file mode 100644 index b07b8513e6..0000000000 --- a/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs +++ /dev/null @@ -1,263 +0,0 @@ -#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.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 SettingsMenuDelegate : WidgetDelegate - { - public override bool GetState(Widget w) - { - if (w.Id == "SETTINGS_CHECKBOX_UNITDEBUG") return Game.Settings.UnitDebug; - if (w.Id == "SETTINGS_CHECKBOX_PATHDEBUG") return Game.Settings.PathDebug; - if (w.Id == "SETTINGS_CHECKBOX_INDEXDEBUG") return Game.Settings.IndexDebug; - if (w.Id == "SETTINGS_CHECKBOX_PERFGRAPH") return Game.Settings.PerfGraph; - if (w.Id == "SETTINGS_CHECKBOX_PERFTEXT") return Game.Settings.PerfText; - return false; - } - - public override bool OnMouseDown(Widget w, MouseInput mi) - { - if (w.Id == "SETTINGS_CHECKBOX_UNITDEBUG") - { - Game.Settings.UnitDebug = !Game.Settings.UnitDebug; - return true; - } - - if (w.Id == "SETTINGS_CHECKBOX_PATHDEBUG") - { - Game.Settings.PathDebug = !Game.Settings.PathDebug; - return true; - } - - if (w.Id == "SETTINGS_CHECKBOX_INDEXDEBUG") - { - Game.Settings.IndexDebug = !Game.Settings.IndexDebug; - return true; - } - - if (w.Id == "SETTINGS_CHECKBOX_PERFGRAPH") - { - Game.Settings.PerfGraph = !Game.Settings.PerfGraph; - return true; - } - - if (w.Id == "SETTINGS_CHECKBOX_PERFTEXT") - { - Game.Settings.PerfText = !Game.Settings.PerfText; - return true; - } - - return false; - } - - public override bool OnMouseUp(Widget w, MouseInput mi) - { - if (w.Id == "MAINMENU_BUTTON_SETTINGS") - { - Game.chrome.rootWidget.ShowMenu("SETTINGS_BG"); - return true; - } - - if (w.Id == "SETTINGS_BUTTON_OK") - { - Game.chrome.rootWidget.ShowMenu("MAINMENU_BG"); - 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.ShowMenu("CREATESERVER_BG"); - return true; - } - - if (w.Id == "CREATESERVER_BUTTON_CANCEL") - { - Game.chrome.rootWidget.ShowMenu("MAINMENU_BG"); - return true; - } - - if (w.Id == "CREATESERVER_BUTTON_START") - { - Game.chrome.rootWidget.ShowMenu(null); - 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 GameButtons = new List(); - - public override bool OnMouseUp(Widget w, MouseInput mi) - { - // Main Menu root - if (w.Id == "MAINMENU_BUTTON_JOIN") - { - var bg = Game.chrome.rootWidget.ShowMenu("JOINSERVER_BG"); - - 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"); - - 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") - { - Game.chrome.rootWidget.ShowMenu("MAINMENU_BG"); - 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.ShowMenu("MAINMENU_BG"); - return true; - } - - if (w.Id == "CONNECTION_BUTTON_CANCEL") - { - Game.chrome.rootWidget.ShowMenu("MAINMENU_BG"); - return true; - } - - if (w.Id == "CONNECTION_BUTTON_RETRY") - { - Game.JoinServer(Game.CurrentHost,Game.CurrentPort); - return true; - } - return false; - } - } - -} \ No newline at end of file diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 3b353527a3..8d12013379 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -75,6 +75,12 @@ + + + + + + @@ -283,13 +289,13 @@ - - - - - - - + + + + + + + diff --git a/OpenRA.Game/Widgets/BackgroundWidget.cs b/OpenRA.Game/Widgets/BackgroundWidget.cs new file mode 100644 index 0000000000..b45b94e29d --- /dev/null +++ b/OpenRA.Game/Widgets/BackgroundWidget.cs @@ -0,0 +1,37 @@ +#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 + +namespace OpenRA.Widgets +{ + class BackgroundWidget : Widget + { + public override void Draw() + { + if (!Visible) + { + base.Draw(); + return; + } + + WidgetUtils.DrawPanel("dialog", Bounds, null); + base.Draw(); + } + } +} \ No newline at end of file diff --git a/OpenRA.Game/Chrome/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs similarity index 96% rename from OpenRA.Game/Chrome/ButtonWidget.cs rename to OpenRA.Game/Widgets/ButtonWidget.cs index 19af6a6103..0b663638a7 100644 --- a/OpenRA.Game/Chrome/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -19,7 +19,6 @@ #endregion using System.Drawing; -using OpenRA.Graphics; namespace OpenRA.Widgets { diff --git a/OpenRA.Game/Chrome/CheckboxWidget.cs b/OpenRA.Game/Widgets/CheckboxWidget.cs similarity index 95% rename from OpenRA.Game/Chrome/CheckboxWidget.cs rename to OpenRA.Game/Widgets/CheckboxWidget.cs index dfeee70bc9..6ceccf8fc4 100644 --- a/OpenRA.Game/Chrome/CheckboxWidget.cs +++ b/OpenRA.Game/Widgets/CheckboxWidget.cs @@ -18,7 +18,6 @@ */ #endregion -using OpenRA.Graphics; using System.Drawing; namespace OpenRA.Widgets diff --git a/OpenRA.Game/Widgets/Delegates/ConnectionDialogsDelegate.cs b/OpenRA.Game/Widgets/Delegates/ConnectionDialogsDelegate.cs new file mode 100644 index 0000000000..9622c9602d --- /dev/null +++ b/OpenRA.Game/Widgets/Delegates/ConnectionDialogsDelegate.cs @@ -0,0 +1,48 @@ +#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 + +namespace OpenRA.Widgets.Delegates +{ + public class ConnectionDialogsDelegate : WidgetDelegate + { + public override bool OnMouseUp(Widget w, MouseInput mi) + { + // Main Menu root + if (w.Id == "CONNECTION_BUTTON_ABORT") + { + Game.chrome.rootWidget.ShowMenu("MAINMENU_BG"); + return true; + } + + if (w.Id == "CONNECTION_BUTTON_CANCEL") + { + Game.chrome.rootWidget.ShowMenu("MAINMENU_BG"); + return true; + } + + if (w.Id == "CONNECTION_BUTTON_RETRY") + { + Game.JoinServer(Game.CurrentHost, Game.CurrentPort); + return true; + } + return false; + } + } +} diff --git a/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs b/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs new file mode 100644 index 0000000000..8aaa86068b --- /dev/null +++ b/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs @@ -0,0 +1,79 @@ +#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.Net; + +namespace OpenRA.Widgets.Delegates +{ + 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.ShowMenu("CREATESERVER_BG"); + return true; + } + + if (w.Id == "CREATESERVER_BUTTON_CANCEL") + { + Game.chrome.rootWidget.ShowMenu("MAINMENU_BG"); + return true; + } + + if (w.Id == "CREATESERVER_BUTTON_START") + { + Game.chrome.rootWidget.ShowMenu(null); + 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; + } + } +} diff --git a/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs b/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs new file mode 100644 index 0000000000..f026adea4c --- /dev/null +++ b/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs @@ -0,0 +1,36 @@ +#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 + +namespace OpenRA.Widgets.Delegates +{ + 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; + } + } +} diff --git a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs new file mode 100644 index 0000000000..e0ad07c844 --- /dev/null +++ b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs @@ -0,0 +1,90 @@ +#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.Collections.Generic; +using System.Drawing; +using System.Linq; +using OpenRA.Server; + +namespace OpenRA.Widgets.Delegates +{ + public class ServerBrowserDelegate : WidgetDelegate + { + static GameServer[] GameList; + static List GameButtons = new List(); + + public override bool OnMouseUp(Widget w, MouseInput mi) + { + // Main Menu root + if (w.Id == "MAINMENU_BUTTON_JOIN") + { + var bg = Game.chrome.rootWidget.ShowMenu("JOINSERVER_BG"); + + 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"); + + 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") + { + Game.chrome.rootWidget.ShowMenu("MAINMENU_BG"); + return true; + } + + return false; + } + } +} diff --git a/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs b/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs new file mode 100644 index 0000000000..f8e419d1a6 --- /dev/null +++ b/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRA.Widgets.Delegates +{ + public class SettingsMenuDelegate : WidgetDelegate + { + public override bool GetState(Widget w) + { + if (w.Id == "SETTINGS_CHECKBOX_UNITDEBUG") return Game.Settings.UnitDebug; + if (w.Id == "SETTINGS_CHECKBOX_PATHDEBUG") return Game.Settings.PathDebug; + if (w.Id == "SETTINGS_CHECKBOX_INDEXDEBUG") return Game.Settings.IndexDebug; + if (w.Id == "SETTINGS_CHECKBOX_PERFGRAPH") return Game.Settings.PerfGraph; + if (w.Id == "SETTINGS_CHECKBOX_PERFTEXT") return Game.Settings.PerfText; + return false; + } + + public override bool OnMouseDown(Widget w, MouseInput mi) + { + if (w.Id == "SETTINGS_CHECKBOX_UNITDEBUG") + { + Game.Settings.UnitDebug = !Game.Settings.UnitDebug; + return true; + } + + if (w.Id == "SETTINGS_CHECKBOX_PATHDEBUG") + { + Game.Settings.PathDebug = !Game.Settings.PathDebug; + return true; + } + + if (w.Id == "SETTINGS_CHECKBOX_INDEXDEBUG") + { + Game.Settings.IndexDebug = !Game.Settings.IndexDebug; + return true; + } + + if (w.Id == "SETTINGS_CHECKBOX_PERFGRAPH") + { + Game.Settings.PerfGraph = !Game.Settings.PerfGraph; + return true; + } + + if (w.Id == "SETTINGS_CHECKBOX_PERFTEXT") + { + Game.Settings.PerfText = !Game.Settings.PerfText; + return true; + } + + return false; + } + + public override bool OnMouseUp(Widget w, MouseInput mi) + { + if (w.Id == "MAINMENU_BUTTON_SETTINGS") + { + Game.chrome.rootWidget.ShowMenu("SETTINGS_BG"); + return true; + } + + if (w.Id == "SETTINGS_BUTTON_OK") + { + Game.chrome.rootWidget.ShowMenu("MAINMENU_BG"); + return true; + } + + return false; + } + } +} diff --git a/OpenRA.Game/Widgets/Delegates/WidgetDelegate.cs b/OpenRA.Game/Widgets/Delegates/WidgetDelegate.cs new file mode 100644 index 0000000000..797944efae --- /dev/null +++ b/OpenRA.Game/Widgets/Delegates/WidgetDelegate.cs @@ -0,0 +1,33 @@ +#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 + +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; } + } +} \ No newline at end of file diff --git a/OpenRA.Game/Chrome/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs similarity index 100% rename from OpenRA.Game/Chrome/LabelWidget.cs rename to OpenRA.Game/Widgets/LabelWidget.cs diff --git a/OpenRA.Game/Chrome/Widget.cs b/OpenRA.Game/Widgets/Widget.cs similarity index 100% rename from OpenRA.Game/Chrome/Widget.cs rename to OpenRA.Game/Widgets/Widget.cs diff --git a/OpenRA.Game/Chrome/WidgetLoader.cs b/OpenRA.Game/Widgets/WidgetLoader.cs similarity index 100% rename from OpenRA.Game/Chrome/WidgetLoader.cs rename to OpenRA.Game/Widgets/WidgetLoader.cs diff --git a/OpenRA.Game/Chrome/BackgroundWidget.cs b/OpenRA.Game/Widgets/WidgetUtils.cs similarity index 89% rename from OpenRA.Game/Chrome/BackgroundWidget.cs rename to OpenRA.Game/Widgets/WidgetUtils.cs index 4ea5297424..ea7efe80cb 100644 --- a/OpenRA.Game/Chrome/BackgroundWidget.cs +++ b/OpenRA.Game/Widgets/WidgetUtils.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#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. @@ -18,28 +18,14 @@ */ #endregion + +using System; +using System.Drawing; using System.Linq; using OpenRA.Graphics; -using System.Drawing; -using System; namespace OpenRA.Widgets { - class BackgroundWidget : Widget - { - public override void Draw() - { - if (!Visible) - { - base.Draw(); - return; - } - - WidgetUtils.DrawPanel("dialog", Bounds, null); - base.Draw(); - } - } - static class WidgetUtils { public static void DrawPanel(string collection, Rectangle Bounds, Action a) @@ -80,4 +66,4 @@ namespace OpenRA.Widgets r.Device.DisableScissor(); } } -} \ No newline at end of file +}