Split unrelated hotkeys from WorldInteractionController.

This commit is contained in:
Paul Chote
2017-09-07 18:20:37 +00:00
committed by reaperrr
parent 0e3bfcfb35
commit 83d522d945
10 changed files with 175 additions and 49 deletions

View File

@@ -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<string, MiniYaml> 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;
}
}
}

View File

@@ -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<string, MiniYaml> 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;
}
}
}

View File

@@ -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<string, MiniYaml> 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;
}
}
}

View File

@@ -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<string, MiniYaml> logicArgs)
: base(widget, "TogglePlayerStanceColorKey", "WORLD_KEYHANDLER", logicArgs) { }
protected override bool OnHotkeyActivated(KeyInput e)
{
Game.Settings.Game.UsePlayerStanceColors ^= true;
return true;
}
}
}

View File

@@ -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" }
};