diff --git a/OpenRA.Game/Graphics/ChromeProvider.cs b/OpenRA.Game/Graphics/ChromeProvider.cs index 79630d8e1c..da23ff8dcc 100644 --- a/OpenRA.Game/Graphics/ChromeProvider.cs +++ b/OpenRA.Game/Graphics/ChromeProvider.cs @@ -27,6 +27,8 @@ namespace OpenRA.Graphics static Dictionary cachedSheets; static Dictionary> cachedSprites; + static string[] storedChromeFiles; + public static void Initialize(params string[] chromeFiles) { collections = new Dictionary(); @@ -34,7 +36,13 @@ namespace OpenRA.Graphics cachedSprites = new Dictionary>(); if (chromeFiles.Length == 0) - return; + { + chromeFiles = storedChromeFiles; + if (chromeFiles == null || chromeFiles.Length == 0) + return; + } + else + storedChromeFiles = chromeFiles; var chrome = chromeFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 6e1e58beaa..727e2889c9 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -250,6 +250,7 @@ + diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index ca1a8b4fd0..e1ada88405 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -176,6 +176,8 @@ namespace OpenRA public Hotkey ObserverWorldView = new Hotkey(Keycode.EQUALS, Modifiers.None); public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None); + + public Hotkey DevReloadChromeKey = new Hotkey(Keycode.C, Modifiers.Ctrl | Modifiers.Shift); } public class IrcSettings diff --git a/OpenRA.Game/Widgets/RootWidget.cs b/OpenRA.Game/Widgets/RootWidget.cs new file mode 100644 index 0000000000..3029bc0e28 --- /dev/null +++ b/OpenRA.Game/Widgets/RootWidget.cs @@ -0,0 +1,39 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using OpenRA.Graphics; + +namespace OpenRA.Widgets +{ + public class RootWidget : ContainerWidget + { + public RootWidget() + { + IgnoreMouseOver = true; + } + + public override bool HandleKeyPress(KeyInput e) + { + if (e.Event == KeyInputEvent.Down) + { + var hk = Hotkey.FromKeyInput(e); + + if (hk == Game.Settings.Keys.DevReloadChromeKey) + { + ChromeProvider.Initialize(); + return true; + } + } + + return base.HandleKeyPress(e); + } + } +} diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 35a9b558b6..9d263ac3ba 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -19,7 +19,7 @@ namespace OpenRA.Widgets { public static class Ui { - public static Widget Root = new ContainerWidget(); + public static Widget Root = new RootWidget(); public static int LastTickTime = Environment.TickCount; diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs index dabe5e96dc..44f3d4624d 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs @@ -244,46 +244,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic Action InitInputPanel(Widget panel) { - // TODO: Extract these to a yaml file - var specialHotkeys = new Dictionary() - { - { "CycleBaseKey", "Jump to base" }, - { "ToLastEventKey", "Jump to last radar event" }, - { "ToSelectionKey", "Jump to selection" }, - { "SelectAllUnitsKey", "Select all units on screen" }, - { "SelectUnitsByTypeKey", "Select units by type" }, - - { "PlaceBeaconKey", "Place beacon" }, - - { "PauseKey", "Pause / Unpause" }, - { "SellKey", "Sell mode" }, - { "PowerDownKey", "Power-down mode" }, - { "RepairKey", "Repair mode" }, - - { "NextProductionTabKey", "Next production tab" }, - { "PreviousProductionTabKey", "Previous production tab" }, - { "CycleProductionBuildingsKey", "Cycle production facilities" }, - - { "ToggleStatusBarsKey", "Toggle status bars" }, - { "TogglePixelDoubleKey", "Toggle pixel doubling" }, - }; - - var unitHotkeys = new Dictionary() - { - { "AttackMoveKey", "Attack Move" }, - { "StopKey", "Stop" }, - { "ScatterKey", "Scatter" }, - { "StanceCycleKey", "Cycle Stance" }, - { "DeployKey", "Deploy" }, - { "GuardKey", "Guard" } - }; - - var observerHotkeys = new Dictionary() - { - { "ObserverCombinedView", "All Players" }, - { "ObserverWorldView", "Disable Shroud" } - }; - var gs = Game.Settings.Game; var ks = Game.Settings.Keys; @@ -304,26 +264,89 @@ namespace OpenRA.Mods.RA.Widgets.Logic var unitTemplate = hotkeyList.Get("UNIT_TEMPLATE"); hotkeyList.RemoveChildren(); - var globalHeader = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {}); - globalHeader.Get("LABEL").GetText = () => "Global Commands"; - hotkeyList.AddChild(globalHeader); + // Game + { + var hotkeys = new Dictionary() + { + { "CycleBaseKey", "Jump to base" }, + { "ToLastEventKey", "Jump to last radar event" }, + { "ToSelectionKey", "Jump to selection" }, + { "SelectAllUnitsKey", "Select all units on screen" }, + { "SelectUnitsByTypeKey", "Select units by type" }, - foreach (var kv in specialHotkeys) - BindHotkeyPref(kv, ks, globalTemplate, hotkeyList); + { "PlaceBeaconKey", "Place beacon" }, - var observerHeader = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {}); - observerHeader.Get("LABEL").GetText = () => "Observer Commands"; - hotkeyList.AddChild(observerHeader); + { "PauseKey", "Pause / Unpause" }, + { "SellKey", "Sell mode" }, + { "PowerDownKey", "Power-down mode" }, + { "RepairKey", "Repair mode" }, - foreach (var kv in observerHotkeys) - BindHotkeyPref(kv, ks, globalTemplate, hotkeyList); + { "NextProductionTabKey", "Next production tab" }, + { "PreviousProductionTabKey", "Previous production tab" }, + { "CycleProductionBuildingsKey", "Cycle production facilities" }, - var unitHeader = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {}); - unitHeader.Get("LABEL").GetText = () => "Unit Commands"; - hotkeyList.AddChild(unitHeader); + { "ToggleStatusBarsKey", "Toggle status bars" }, + { "TogglePixelDoubleKey", "Toggle pixel doubling" }, + }; - foreach (var kv in unitHotkeys) - BindHotkeyPref(kv, ks, unitTemplate, hotkeyList); + var header = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {}); + header.Get("LABEL").GetText = () => "Game Commands"; + hotkeyList.AddChild(header); + + foreach (var kv in hotkeys) + BindHotkeyPref(kv, ks, globalTemplate, hotkeyList); + } + + // Observer + { + var hotkeys = new Dictionary() + { + { "ObserverCombinedView", "All Players" }, + { "ObserverWorldView", "Disable Shroud" } + }; + + var header = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {}); + header.Get("LABEL").GetText = () => "Observer Commands"; + hotkeyList.AddChild(header); + + foreach (var kv in hotkeys) + BindHotkeyPref(kv, ks, globalTemplate, hotkeyList); + } + + // Unit + { + var hotkeys = new Dictionary() + { + { "AttackMoveKey", "Attack Move" }, + { "StopKey", "Stop" }, + { "ScatterKey", "Scatter" }, + { "StanceCycleKey", "Cycle Stance" }, + { "DeployKey", "Deploy" }, + { "GuardKey", "Guard" } + }; + + var header = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {}); + header.Get("LABEL").GetText = () => "Unit Commands"; + hotkeyList.AddChild(header); + + foreach (var kv in hotkeys) + BindHotkeyPref(kv, ks, unitTemplate, hotkeyList); + } + + // Developer + { + var hotkeys = new Dictionary() + { + { "DevReloadChromeKey", "Reload Chrome" } + }; + + var header = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {}); + header.Get("LABEL").GetText = () => "Developer commands"; + hotkeyList.AddChild(header); + + foreach (var kv in hotkeys) + BindHotkeyPref(kv, ks, globalTemplate, hotkeyList); + } return () => {