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

@@ -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);

View File

@@ -827,6 +827,10 @@
<Compile Include="Widgets\Logic\Ingame\Hotkeys\CycleProductionActorsHotkeyLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\Hotkeys\JumpToLastEventHotkeyLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\Hotkeys\JumpToSelectedActorsHotkeyLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\Hotkeys\TogglePixelDoubleHotkeyLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\Hotkeys\TogglePlayerStanceColorHotkeyLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\Hotkeys\PauseHotkeyLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\Hotkeys\CycleStatusBarsHotkeyLogic.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">

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

View File

@@ -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<SelectableInfo>() && (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;
}
}
}

View File

@@ -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:

View File

@@ -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: