Unhardcode spectator combined/world view hotkeys.

This commit is contained in:
Paul Chote
2017-07-23 22:06:33 +01:00
committed by reaperrr
parent 0525408664
commit 1bd1a185f5
7 changed files with 28 additions and 7 deletions

View File

@@ -232,8 +232,8 @@ namespace OpenRA
public Hotkey StanceAttackAnythingKey = new Hotkey(Keycode.A, Modifiers.Alt); public Hotkey StanceAttackAnythingKey = new Hotkey(Keycode.A, Modifiers.Alt);
public Hotkey GuardKey = new Hotkey(Keycode.D, Modifiers.None); public Hotkey GuardKey = new Hotkey(Keycode.D, Modifiers.None);
public Hotkey ObserverCombinedView = new Hotkey(Keycode.MINUS, Modifiers.None); public Hotkey ObserverCombinedViewKey = new Hotkey(Keycode.MINUS, Modifiers.None);
public Hotkey ObserverWorldView = new Hotkey(Keycode.EQUALS, Modifiers.None); public Hotkey ObserverWorldViewKey = new Hotkey(Keycode.EQUALS, Modifiers.None);
public Hotkey CycleStatusBarsKey = new Hotkey(Keycode.COMMA, Modifiers.None); public Hotkey CycleStatusBarsKey = new Hotkey(Keycode.COMMA, Modifiers.None);
public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None); public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None);

View File

@@ -13,17 +13,22 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Mods.Common.Lint;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic namespace OpenRA.Mods.Common.Widgets.Logic
{ {
[ChromeLogicArgsHotkeys("CombinedViewKey", "WorldViewKey")]
public class ObserverShroudSelectorLogic : ChromeLogic public class ObserverShroudSelectorLogic : ChromeLogic
{ {
readonly CameraOption combined, disableShroud; readonly CameraOption combined, disableShroud;
readonly IOrderedEnumerable<IGrouping<int, CameraOption>> teams; readonly IOrderedEnumerable<IGrouping<int, CameraOption>> teams;
readonly bool limitViews; readonly bool limitViews;
readonly NamedHotkey combinedViewKey = new NamedHotkey();
readonly NamedHotkey worldViewKey = new NamedHotkey();
CameraOption selected; CameraOption selected;
class CameraOption class CameraOption
@@ -57,8 +62,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ObserverShroudSelectorLogic(Widget widget, World world) public ObserverShroudSelectorLogic(Widget widget, World world, Dictionary<string, MiniYaml> logicArgs)
{ {
MiniYaml yaml;
var ks = Game.Settings.Keys;
if (logicArgs.TryGetValue("CombinedViewKey", out yaml))
combinedViewKey = new NamedHotkey(yaml.Value, ks);
if (logicArgs.TryGetValue("WorldViewKey", out yaml))
worldViewKey = new NamedHotkey(yaml.Value, ks);
limitViews = world.Map.Visibility.HasFlag(MapVisibility.MissionSelector); limitViews = world.Map.Visibility.HasFlag(MapVisibility.MissionSelector);
var groups = new Dictionary<string, IEnumerable<CameraOption>>(); var groups = new Dictionary<string, IEnumerable<CameraOption>>();
@@ -136,7 +149,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (e.Event == KeyInputEvent.Down && !e.IsRepeat) if (e.Event == KeyInputEvent.Down && !e.IsRepeat)
{ {
var h = Hotkey.FromKeyInput(e); var h = Hotkey.FromKeyInput(e);
if (h == Game.Settings.Keys.ObserverCombinedView && !limitViews) if (h == combinedViewKey.GetValue() && !limitViews)
{ {
selected = combined; selected = combined;
selected.OnClick(); selected.OnClick();
@@ -144,7 +157,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return true; return true;
} }
if (h == Game.Settings.Keys.ObserverWorldView && !limitViews) if (h == worldViewKey.GetValue() && !limitViews)
{ {
selected = disableShroud; selected = disableShroud;
selected.OnClick(); selected.OnClick();

View File

@@ -495,8 +495,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
var hotkeys = new Dictionary<string, string>() var hotkeys = new Dictionary<string, string>()
{ {
{ "ObserverCombinedView", "All Players" }, { "ObserverCombinedViewKey", "All Players" },
{ "ObserverWorldView", "Disable Shroud" }, { "ObserverWorldViewKey", "Disable Shroud" },
{ "PauseKey", "Pause/Play" }, { "PauseKey", "Pause/Play" },
{ "ReplaySpeedSlowKey", "Slow speed" }, { "ReplaySpeedSlowKey", "Slow speed" },
{ "ReplaySpeedRegularKey", "Regular speed" }, { "ReplaySpeedRegularKey", "Regular speed" },

View File

@@ -224,6 +224,8 @@ Container@OBSERVER_WIDGETS:
Font: TinyBold Font: TinyBold
DropDownButton@SHROUD_SELECTOR: DropDownButton@SHROUD_SELECTOR:
Logic: ObserverShroudSelectorLogic Logic: ObserverShroudSelectorLogic
CombinedViewKey: ObserverCombinedView
WorldViewKey: ObserverWorldView
X: WINDOW_RIGHT - WIDTH - 5 X: WINDOW_RIGHT - WIDTH - 5
Y: 260 Y: 260
Width: 256 Width: 256

View File

@@ -60,6 +60,8 @@ Container@OBSERVER_WIDGETS:
Children: Children:
DropDownButton@SHROUD_SELECTOR: DropDownButton@SHROUD_SELECTOR:
Logic: ObserverShroudSelectorLogic Logic: ObserverShroudSelectorLogic
CombinedViewKey: ObserverCombinedView
WorldViewKey: ObserverWorldView
X: 15 X: 15
Y: 15 Y: 15
Width: 220 Width: 220

View File

@@ -78,6 +78,8 @@ Container@OBSERVER_WIDGETS:
Height: 220 Height: 220
DropDownButton@SHROUD_SELECTOR: DropDownButton@SHROUD_SELECTOR:
Logic: ObserverShroudSelectorLogic Logic: ObserverShroudSelectorLogic
CombinedViewKey: ObserverCombinedView
WorldViewKey: ObserverWorldView
X: 6 X: 6
Y: 262 Y: 262
Width: 226 Width: 226

View File

@@ -60,6 +60,8 @@ Container@OBSERVER_WIDGETS:
Children: Children:
DropDownButton@SHROUD_SELECTOR: DropDownButton@SHROUD_SELECTOR:
Logic: ObserverShroudSelectorLogic Logic: ObserverShroudSelectorLogic
CombinedViewKey: ObserverCombinedView
WorldViewKey: ObserverWorldView
X: 15 X: 15
Y: 15 Y: 15
Width: 220 Width: 220