diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 1a38c1f8a7..eda7168aa7 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -237,7 +237,7 @@ namespace OpenRA public Hotkey CycleStatusBarsKey = new Hotkey(Keycode.COMMA, Modifiers.None); public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None); - public Hotkey TogglePlayerStanceColorsKey = new Hotkey(Keycode.COMMA, Modifiers.Ctrl); + public Hotkey TogglePlayerStanceColorKey = new Hotkey(Keycode.COMMA, Modifiers.Ctrl); public Hotkey TakeScreenshotKey = new Hotkey(Keycode.P, Modifiers.Ctrl); public Hotkey ToggleMuteKey = new Hotkey(Keycode.M, Modifiers.None); diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 9cbe974a7e..cbbbecefc0 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -827,6 +827,10 @@ + + + + diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs new file mode 100644 index 0000000000..398aad8c81 --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs @@ -0,0 +1,35 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Lint; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Common.Widgets.Logic.Ingame +{ + [ChromeLogicArgsHotkeys("CycleStatusBarsKey")] + public class CycleStatusBarsHotkeyLogic : SingleHotkeyBaseLogic + { + StatusBarsType[] options = { StatusBarsType.Standard, StatusBarsType.DamageShow, StatusBarsType.AlwaysShow }; + + [ObjectCreator.UseCtor] + public CycleStatusBarsHotkeyLogic(Widget widget, Dictionary logicArgs) + : base(widget, "CycleStatusBarsKey", "WORLD_KEYHANDLER", logicArgs) { } + + protected override bool OnHotkeyActivated(KeyInput e) + { + Game.Settings.Game.StatusBars = options[(options.IndexOf(Game.Settings.Game.StatusBars) + 1) % options.Length]; + + return true; + } + } +} diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/PauseHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/PauseHotkeyLogic.cs new file mode 100644 index 0000000000..cf4a9905d4 --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/PauseHotkeyLogic.cs @@ -0,0 +1,42 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Lint; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Common.Widgets.Logic.Ingame +{ + [ChromeLogicArgsHotkeys("PauseKey")] + public class PauseHotkeyLogic : SingleHotkeyBaseLogic + { + readonly World world; + + [ObjectCreator.UseCtor] + public PauseHotkeyLogic(Widget widget, World world, Dictionary logicArgs) + : base(widget, "PauseKey", "WORLD_KEYHANDLER", logicArgs) + { + this.world = world; + } + + protected override bool OnHotkeyActivated(KeyInput e) + { + // Disable pausing for spectators and defeated players unless they are the game host + if (!Game.IsHost && (world.LocalPlayer == null || world.LocalPlayer.WinState == WinState.Lost)) + return false; + + world.SetPauseState(!world.Paused); + + return true; + } + } +} diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePixelDoubleHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePixelDoubleHotkeyLogic.cs new file mode 100644 index 0000000000..9b07c782aa --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePixelDoubleHotkeyLogic.cs @@ -0,0 +1,48 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Lint; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Common.Widgets.Logic.Ingame +{ + [ChromeLogicArgsHotkeys("TogglePixelDoubleKey")] + public class TogglePixelDoubleHotkeyLogic : SingleHotkeyBaseLogic + { + readonly Viewport viewport; + + [ObjectCreator.UseCtor] + public TogglePixelDoubleHotkeyLogic(Widget widget, WorldRenderer worldRenderer, Dictionary logicArgs) + : base(widget, "TogglePixelDoubleKey", "WORLD_KEYHANDLER", logicArgs) + { + viewport = worldRenderer.Viewport; + } + + protected override bool OnHotkeyActivated(KeyInput e) + { + // Zoom is currently always set directly, so we don't need to worry about floating point imprecision + if (viewport.Zoom == 1f) + viewport.Zoom = 2f; + else + { + // Reset zoom to regular view if it was anything else before + // (like a zoom level only reachable by using the scroll wheel). + viewport.Zoom = 1f; + } + + Game.Settings.Graphics.PixelDouble = viewport.Zoom == 2f; + + return true; + } + } +} diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePlayerStanceColorHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePlayerStanceColorHotkeyLogic.cs new file mode 100644 index 0000000000..4be78e83cf --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePlayerStanceColorHotkeyLogic.cs @@ -0,0 +1,33 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Lint; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Common.Widgets.Logic.Ingame +{ + [ChromeLogicArgsHotkeys("TogglePlayerStanceColorKey")] + public class TogglePlayerStanceColorHotkeyLogic : SingleHotkeyBaseLogic + { + [ObjectCreator.UseCtor] + public TogglePlayerStanceColorHotkeyLogic(Widget widget, Dictionary logicArgs) + : base(widget, "TogglePlayerStanceColorKey", "WORLD_KEYHANDLER", logicArgs) { } + + protected override bool OnHotkeyActivated(KeyInput e) + { + Game.Settings.Game.UsePlayerStanceColors ^= true; + + return true; + } + } +} diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 845540f386..9e2a7f4acd 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -448,7 +448,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { "CycleStatusBarsKey", "Cycle status bars display" }, { "TogglePixelDoubleKey", "Toggle pixel doubling" }, { "ToggleMuteKey", "Toggle audio mute" }, - { "TogglePlayerStanceColorsKey", "Toggle player stance colors" }, + { "TogglePlayerStanceColorKey", "Toggle player stance colors" }, { "TakeScreenshotKey", "Take screenshot" } }; diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index 4c74f24425..81f7ec099f 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -242,10 +242,7 @@ namespace OpenRA.Mods.Common.Widgets { var key = Hotkey.FromKeyInput(e); - if (key == Game.Settings.Keys.PauseKey - && (Game.IsHost || (World.LocalPlayer != null && World.LocalPlayer.WinState != WinState.Lost))) // Disable pausing for spectators and defeated players - World.SetPauseState(!World.Paused); - else if (key == Game.Settings.Keys.SelectAllUnitsKey && !World.IsGameOver) + if (key == Game.Settings.Keys.SelectAllUnitsKey && !World.IsGameOver) { // Select actors on the screen which belong to the current player var ownUnitsOnScreen = SelectActorsOnScreen(World, worldRenderer, null, player).SubsetWithHighestSelectionPriority().ToList(); @@ -288,12 +285,6 @@ namespace OpenRA.Mods.Common.Widgets World.Selection.Combine(World, newSelection, true, false); } - else if (key == Game.Settings.Keys.CycleStatusBarsKey) - return CycleStatusBars(); - else if (key == Game.Settings.Keys.TogglePixelDoubleKey) - return TogglePixelDouble(); - else if (key == Game.Settings.Keys.TogglePlayerStanceColorsKey) - return TogglePlayerStanceColors(); } return false; @@ -333,40 +324,5 @@ namespace OpenRA.Mods.Common.Widgets .Where(x => x.Info.HasTraitInfo() && (x.Owner.IsAlliedWith(world.RenderPlayer) || !world.FogObscures(x))) .SubsetWithHighestSelectionPriority(); } - - bool CycleStatusBars() - { - if (Game.Settings.Game.StatusBars == StatusBarsType.Standard) - Game.Settings.Game.StatusBars = StatusBarsType.DamageShow; - else if (Game.Settings.Game.StatusBars == StatusBarsType.DamageShow) - Game.Settings.Game.StatusBars = StatusBarsType.AlwaysShow; - else if (Game.Settings.Game.StatusBars == StatusBarsType.AlwaysShow) - Game.Settings.Game.StatusBars = StatusBarsType.Standard; - - return true; - } - - bool TogglePixelDouble() - { - if (worldRenderer.Viewport.Zoom == 1f) - worldRenderer.Viewport.Zoom = 2f; - else - { - // Reset zoom to regular view if it was anything else before - // (like a zoom level only reachable by using the scroll wheel). - worldRenderer.Viewport.Zoom = 1f; - } - - Game.Settings.Graphics.PixelDouble = worldRenderer.Viewport.Zoom == 2f; - - return true; - } - - bool TogglePlayerStanceColors() - { - Game.Settings.Game.UsePlayerStanceColors ^= true; - - return true; - } } } diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index de545149c4..a33e6950df 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -10,11 +10,15 @@ Container@INGAME_ROOT: TakeScreenshotKey: TakeScreenshot MuteAudioKey: ToggleMute LogicKeyListener@WORLD_KEYHANDLER: - Logic: CycleBasesHotkeyLogic, CycleProductionActorsHotkeyLogic, JumpToLastEventHotkeyLogic, JumpToSelectedActorsHotkeyLogic + Logic: CycleBasesHotkeyLogic, CycleProductionActorsHotkeyLogic, JumpToLastEventHotkeyLogic, JumpToSelectedActorsHotkeyLogic, TogglePixelDoubleHotkeyLogic, TogglePlayerStanceColorHotkeyLogic, CycleStatusBarsHotkeyLogic, PauseHotkeyLogic CycleBasesKey: CycleBase CycleProductionActorsKey: CycleProductionBuildings JumpToLastEventKey: ToLastEvent JumpToSelectedActorsKey: ToSelection + TogglePixelDoubleKey: TogglePixelDouble + TogglePlayerStanceColorKey: TogglePlayerStanceColor + CycleStatusBarsKey: CycleStatusBars + PauseKey: Pause Container@WORLD_ROOT: Logic: LoadIngamePerfLogic Children: diff --git a/mods/common/chrome/ingame.yaml b/mods/common/chrome/ingame.yaml index 7777821928..f4a7a1a73c 100644 --- a/mods/common/chrome/ingame.yaml +++ b/mods/common/chrome/ingame.yaml @@ -10,11 +10,15 @@ Container@INGAME_ROOT: TakeScreenshotKey: TakeScreenshot MuteAudioKey: ToggleMute LogicKeyListener@WORLD_KEYHANDLER: - Logic: CycleBasesHotkeyLogic, CycleProductionActorsHotkeyLogic, JumpToLastEventHotkeyLogic, JumpToSelectedActorsHotkeyLogic + Logic: CycleBasesHotkeyLogic, CycleProductionActorsHotkeyLogic, JumpToLastEventHotkeyLogic, JumpToSelectedActorsHotkeyLogic, TogglePixelDoubleHotkeyLogic, TogglePlayerStanceColorHotkeyLogic, CycleStatusBarsHotkeyLogic, PauseHotkeyLogic CycleBasesKey: CycleBase CycleProductionActorsKey: CycleProductionBuildings JumpToLastEventKey: ToLastEvent JumpToSelectedActorsKey: ToSelection + TogglePixelDoubleKey: TogglePixelDouble + TogglePlayerStanceColorKey: TogglePlayerStanceColor + CycleStatusBarsKey: CycleStatusBars + PauseKey: Pause Container@WORLD_ROOT: Logic: LoadIngamePerfLogic Children: