diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 18d8f61248..b76dee1b18 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -60,6 +60,7 @@ namespace OpenRA public static string EngineVersion { get; private set; } static Task discoverNat; + static bool takeScreenshot = false; public static OrderManager JoinServer(string host, int port, string password, bool recordReplay = true) { @@ -630,7 +631,10 @@ namespace OpenRA InnerLogicTick(worldRenderer.World.OrderManager); } - public static bool TakeScreenshot = false; + public static void TakeScreenshot() + { + takeScreenshot = true; + } static void RenderTick() { @@ -666,9 +670,9 @@ namespace OpenRA using (new PerfSample("render_flip")) Renderer.EndFrame(new DefaultInputHandler(OrderManager.World)); - if (TakeScreenshot) + if (takeScreenshot) { - TakeScreenshot = false; + takeScreenshot = false; TakeScreenshotInner(); } } diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 41a099a9ea..7a72f3d51c 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -143,12 +143,6 @@ namespace OpenRA.Widgets Root.Visible ^= true; return true; } - - if (hk == Game.Settings.Keys.TakeScreenshotKey) - { - Game.TakeScreenshot = true; - return true; - } } if (KeyboardFocusWidget != null) diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 1007ff2e54..a7bfc55d4f 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -822,6 +822,7 @@ + diff --git a/OpenRA.Mods.Common/Widgets/Logic/ScreenshotHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ScreenshotHotkeyLogic.cs new file mode 100644 index 0000000000..596f5a9259 --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/ScreenshotHotkeyLogic.cs @@ -0,0 +1,31 @@ +#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.Mods.Common.Lint; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Common.Widgets.Logic +{ + [ChromeLogicArgsHotkeys("TakeScreenshotKey")] + public class ScreenshotHotkeyLogic : SingleHotkeyBaseLogic + { + [ObjectCreator.UseCtor] + public ScreenshotHotkeyLogic(Widget widget, Dictionary logicArgs) + : base(widget, "TakeScreenshotKey", "GLOBAL_KEYHANDLER", logicArgs) { } + + protected override bool OnHotkeyActivated(KeyInput e) + { + Game.TakeScreenshot(); + return true; + } + } +} diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index c712df1f58..7643fd2fc8 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -192,11 +192,12 @@ Container@EDITOR_ROOT: Logic: LoadMapEditorLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic + TakeScreenshotKey: TakeScreenshot Container@WORLD_ROOT: Container@MENU_ROOT: TooltipContainer@TOOLTIP_CONTAINER: diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 9be148daf0..0936109ddb 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -2,11 +2,12 @@ Container@INGAME_ROOT: Logic: LoadIngamePlayerOrObserverUILogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic + TakeScreenshotKey: TakeScreenshot Container@WORLD_ROOT: Logic: LoadIngamePerfLogic Children: diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index d69f5def47..ebc27d985a 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -4,11 +4,12 @@ Container@MENU_BACKGROUND: Logic: MainMenuLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic + TakeScreenshotKey: TakeScreenshot Container@SHELLMAP_DECORATIONS: Children: Image@NOD: diff --git a/mods/common/chrome/editor.yaml b/mods/common/chrome/editor.yaml index bfe6ef8bb6..aeec45fb92 100644 --- a/mods/common/chrome/editor.yaml +++ b/mods/common/chrome/editor.yaml @@ -183,11 +183,12 @@ Container@EDITOR_ROOT: Logic: LoadMapEditorLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic + TakeScreenshotKey: TakeScreenshot Container@WORLD_ROOT: Container@MENU_ROOT: TooltipContainer@TOOLTIP_CONTAINER: diff --git a/mods/common/chrome/ingame.yaml b/mods/common/chrome/ingame.yaml index e5f4b1c3a8..2df8e40c6b 100644 --- a/mods/common/chrome/ingame.yaml +++ b/mods/common/chrome/ingame.yaml @@ -2,11 +2,12 @@ Container@INGAME_ROOT: Logic: LoadIngamePlayerOrObserverUILogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic + TakeScreenshotKey: TakeScreenshot Container@WORLD_ROOT: Logic: LoadIngamePerfLogic Children: diff --git a/mods/common/chrome/mainmenu.yaml b/mods/common/chrome/mainmenu.yaml index 5fa5a99b85..42e9967d2a 100644 --- a/mods/common/chrome/mainmenu.yaml +++ b/mods/common/chrome/mainmenu.yaml @@ -2,11 +2,12 @@ Container@MAINMENU: Logic: MainMenuLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic + TakeScreenshotKey: TakeScreenshot Background@BORDER: Background: mainmenu-border X: 0 - 15 diff --git a/mods/d2k/chrome/mainmenu.yaml b/mods/d2k/chrome/mainmenu.yaml index 97769d87d2..8829b3b73e 100644 --- a/mods/d2k/chrome/mainmenu.yaml +++ b/mods/d2k/chrome/mainmenu.yaml @@ -2,11 +2,12 @@ Container@MAINMENU: Logic: MainMenuLogic Children: LogicKeyListener@GLOBAL_KEYHANDLER: - Logic: MusicHotkeyLogic + Logic: MusicHotkeyLogic, ScreenshotHotkeyLogic StopMusicKey: StopMusic PauseMusicKey: PauseMusic PrevMusicKey: PrevMusic NextMusicKey: NextMusic + TakeScreenshotKey: TakeScreenshot Label@VERSION_LABEL: X: WINDOW_RIGHT - 10 Y: WINDOW_BOTTOM - 20