From 411b73a75ece6cde53690d07cfcfa2be59511ead Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 23 Mar 2010 07:39:52 +1300 Subject: [PATCH] settings menu w/ working debug options --- OpenRA.Game/Chrome/DefaultWidgetDelegates.cs | 59 +++++++++++++++ OpenRA.Game/Game.cs | 2 - OpenRA.Game/GameRules/UserSettings.cs | 9 ++- OpenRA.Game/Graphics/WorldRenderer.cs | 9 +-- OpenRA.Game/UiOverlay.cs | 4 +- mods/ra/menus.yaml | 78 +++++++++++++++++++- 6 files changed, 144 insertions(+), 17 deletions(-) diff --git a/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs b/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs index c997ebfa4e..d2fa2bab32 100644 --- a/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs +++ b/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs @@ -50,6 +50,65 @@ namespace OpenRA.Widgets.Delegates 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; + + 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; + } + + return false; + } + + public override bool OnMouseUp(Widget w, MouseInput mi) + { + if (w.Id == "MAINMENU_BUTTON_SETTINGS") + { + Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = false; + Game.chrome.rootWidget.GetWidget("SETTINGS_BG").Visible = true; + return true; + } + + if (w.Id == "SETTINGS_BUTTON_OK") + { + Game.chrome.rootWidget.GetWidget("MAINMENU_BG").Visible = true; + Game.chrome.rootWidget.GetWidget("SETTINGS_BG").Visible = false; + return true; + } + + return false; + } + } public class CreateServerMenuDelegate : WidgetDelegate { diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index bd88e479cd..197a006231 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -432,8 +432,6 @@ namespace OpenRA // Load the default mod to access required files Game.LoadModPackages(new Manifest(Game.LobbyInfo.GlobalSettings.Mods)); - UiOverlay.ShowUnitDebug = Game.Settings.UnitDebug; - WorldRenderer.ShowUnitPaths = Game.Settings.PathDebug; Renderer.SheetSize = Game.Settings.SheetSize; bool windowed = !Game.Settings.Fullscreen; diff --git a/OpenRA.Game/GameRules/UserSettings.cs b/OpenRA.Game/GameRules/UserSettings.cs index b99cbd142c..f2016ca8ef 100644 --- a/OpenRA.Game/GameRules/UserSettings.cs +++ b/OpenRA.Game/GameRules/UserSettings.cs @@ -23,10 +23,11 @@ namespace OpenRA.GameRules public class UserSettings { // Debug settings - public readonly bool UnitDebug = false; - public readonly bool PathDebug = false; - public readonly bool PerfGraph = true; - public readonly bool PerfText = true; + public bool UnitDebug = false; + public bool PathDebug = false; + public bool PerfGraph = true; + public bool PerfText = true; + public bool IndexDebug = false; // Window settings public readonly int Width = 0; diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 8db2bcd08b..4fd34e540d 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -36,9 +36,6 @@ namespace OpenRA.Graphics internal readonly Renderer renderer; internal readonly HardwarePalette palette; - public static bool ShowUnitPaths = false; - public static bool ShowBinDebug = false; - internal WorldRenderer(World world, Renderer renderer) { this.world = world; @@ -154,8 +151,8 @@ namespace OpenRA.Graphics renderer.Device.DisableScissor(); - if (ShowBinDebug) - DrawBins( bounds ); + if (Game.Settings.IndexDebug) + DrawBins(bounds); lineRenderer.Flush(); } @@ -240,7 +237,7 @@ namespace OpenRA.Graphics } } - if (ShowUnitPaths) + if (Game.Settings.PathDebug) { var mobile = selectedUnit.traits.GetOrDefault(); if (mobile != null) diff --git a/OpenRA.Game/UiOverlay.cs b/OpenRA.Game/UiOverlay.cs index a7d4bf864d..9a6d68003e 100644 --- a/OpenRA.Game/UiOverlay.cs +++ b/OpenRA.Game/UiOverlay.cs @@ -32,8 +32,6 @@ namespace OpenRA SpriteRenderer spriteRenderer; Sprite buildOk, buildBlocked, unitDebug; - public static bool ShowUnitDebug = false; - public UiOverlay(SpriteRenderer spriteRenderer) { this.spriteRenderer = spriteRenderer; @@ -56,7 +54,7 @@ namespace OpenRA public void Draw( World world ) { - if (ShowUnitDebug) + if (Game.Settings.UnitDebug) for (var j = 0; j < world.Map.MapSize; j++) for (var i = 0; i < world.Map.MapSize; i++) if (world.WorldActor.traits.Get().GetUnitsAt(new int2(i, j)).Any()) diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml index e8b57ffa7d..f7ea3428f0 100644 --- a/mods/ra/menus.yaml +++ b/mods/ra/menus.yaml @@ -5,7 +5,7 @@ Container: X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 Width:250 - Height:200 + Height:250 Children: Label@MAINMENU_LABEL_TITLE: Id:MAINMENU_LABEL_TITLE @@ -31,10 +31,18 @@ Container: Height:25 Text:Create Game Delegate:CreateServerMenuDelegate + Button@MAINMENU_BUTTON_SETTINGS: + Id:MAINMENU_BUTTON_SETTINGS + X:45 + Y:150 + Width:160 + Height:25 + Text:Settings + Delegate:SettingsMenuDelegate Button@MAINMENU_BUTTON_QUIT: Id:MAINMENU_BUTTON_QUIT X:45 - Y:150 + Y:190 Width:160 Height:25 Text:Quit @@ -85,6 +93,72 @@ Container: Height:25 Text:Cancel Delegate:CreateServerMenuDelegate + Background@SETTINGS_BG: + Id:SETTINGS_BG + X:(WINDOW_RIGHT - WIDTH)/2 + Y:(WINDOW_BOTTOM- HEIGHT)/2 + Width: 450 + Height: 300 + Visible: false + Children: + Label@SETTINGS_LABEL_TITLE: + Id:SETTINGS_LABEL_TITLE + X:0 + Y:20 + Width:450 + Height:25 + Text:Settings + Align:Center + Checkbox@SETTINGS_CHECKBOX_UNITDEBUG: + Id:SETTINGS_CHECKBOX_UNITDEBUG + X:100 + Y:60 + Width:20 + Height:20 + Delegate:SettingsMenuDelegate + Label@SETTINGS_LABEL_UNITDEBUG: + Id:SETTINGS_LABEL_UNITDEBUG + X:135 + Y:60 + Width:300 + Height:25 + Text:Show Occupied Cells + Checkbox@SETTINGS_CHECKBOX_PATHDEBUG: + Id:SETTINGS_CHECKBOX_PATHDEBUG + X:100 + Y:90 + Width:20 + Height:20 + Delegate:SettingsMenuDelegate + Label@SETTINGS_LABEL_PATHDEBUG: + Id:SETTINGS_LABEL_PATHDEBUG + X:135 + Y:90 + Width:300 + Height:25 + Text:Show Unit Paths + Checkbox@SETTINGS_CHECKBOX_INDEXDEBUG: + Id:SETTINGS_CHECKBOX_INDEXDEBUG + X:100 + Y:120 + Width:20 + Height:20 + Delegate:SettingsMenuDelegate + Label@SETTINGS_LABEL_INDEXDEBUG: + Id:SETTINGS_LABEL_INDEXDEBUG + X:135 + Y:120 + Width:300 + Height:25 + Text:Show Spatial Index Debug + Button@SETTINGS_BUTTON_OK: + Id:SETTINGS_BUTTON_OK + X:PARENT_RIGHT - 180 + Y:PARENT_BOTTOM - 45 + Width:160 + Height:25 + Text:OK + Delegate:SettingsMenuDelegate Background@JOINSERVER_BG: Id:JOINSERVER_BG X:(WINDOW_RIGHT - WIDTH)/2