diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 08a931a646..5bdd73b962 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -192,25 +192,25 @@ namespace OpenRA public Hotkey SelectAllUnitsKey = new Hotkey(Keycode.Q, Modifiers.None); public Hotkey SelectUnitsByTypeKey = new Hotkey(Keycode.W, Modifiers.None); - public Hotkey MapScrollUp = new Hotkey(Keycode.UP, Modifiers.None); - public Hotkey MapScrollDown = new Hotkey(Keycode.DOWN, Modifiers.None); - public Hotkey MapScrollLeft = new Hotkey(Keycode.LEFT, Modifiers.None); - public Hotkey MapScrollRight = new Hotkey(Keycode.RIGHT, Modifiers.None); + public Hotkey MapScrollUpKey = new Hotkey(Keycode.UP, Modifiers.None); + public Hotkey MapScrollDownKey = new Hotkey(Keycode.DOWN, Modifiers.None); + public Hotkey MapScrollLeftKey = new Hotkey(Keycode.LEFT, Modifiers.None); + public Hotkey MapScrollRightKey = new Hotkey(Keycode.RIGHT, Modifiers.None); - public Hotkey MapPushTop = new Hotkey(Keycode.UP, Modifiers.Alt); - public Hotkey MapPushBottom = new Hotkey(Keycode.DOWN, Modifiers.Alt); - public Hotkey MapPushLeftEdge = new Hotkey(Keycode.LEFT, Modifiers.Alt); - public Hotkey MapPushRightEdge = new Hotkey(Keycode.RIGHT, Modifiers.Alt); + public Hotkey MapJumpToTopEdgeKey = new Hotkey(Keycode.UP, Modifiers.Alt); + public Hotkey MapJumpToBottomEdgeKey = new Hotkey(Keycode.DOWN, Modifiers.Alt); + public Hotkey MapJumpToLeftEdgeKey = new Hotkey(Keycode.LEFT, Modifiers.Alt); + public Hotkey MapJumpToRightEdgeKey = new Hotkey(Keycode.RIGHT, Modifiers.Alt); - public Hotkey ViewPortBookmarkSaveSlot1 = new Hotkey(Keycode.Q, Modifiers.Ctrl); - public Hotkey ViewPortBookmarkSaveSlot2 = new Hotkey(Keycode.W, Modifiers.Ctrl); - public Hotkey ViewPortBookmarkSaveSlot3 = new Hotkey(Keycode.E, Modifiers.Ctrl); - public Hotkey ViewPortBookmarkSaveSlot4 = new Hotkey(Keycode.R, Modifiers.Ctrl); + public Hotkey MapBookmarkSave01Key = new Hotkey(Keycode.Q, Modifiers.Ctrl); + public Hotkey MapBookmarkSave02Key = new Hotkey(Keycode.W, Modifiers.Ctrl); + public Hotkey MapBookmarkSave03Key = new Hotkey(Keycode.E, Modifiers.Ctrl); + public Hotkey MapBookmarkSave04Key = new Hotkey(Keycode.R, Modifiers.Ctrl); - public Hotkey ViewPortBookmarkUseSlot1 = new Hotkey(Keycode.Q, Modifiers.Alt); - public Hotkey ViewPortBookmarkUseSlot2 = new Hotkey(Keycode.W, Modifiers.Alt); - public Hotkey ViewPortBookmarkUseSlot3 = new Hotkey(Keycode.E, Modifiers.Alt); - public Hotkey ViewPortBookmarkUseSlot4 = new Hotkey(Keycode.R, Modifiers.Alt); + public Hotkey MapBookmarkRestore01Key = new Hotkey(Keycode.Q, Modifiers.Alt); + public Hotkey MapBookmarkRestore02Key = new Hotkey(Keycode.W, Modifiers.Alt); + public Hotkey MapBookmarkRestore03Key = new Hotkey(Keycode.E, Modifiers.Alt); + public Hotkey MapBookmarkRestore04Key = new Hotkey(Keycode.R, Modifiers.Alt); public Hotkey PauseKey = new Hotkey(Keycode.PAUSE, Modifiers.None); public Hotkey PlaceBeaconKey = new Hotkey(Keycode.B, Modifiers.None); diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index d9d85adc91..00b19ac166 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -463,24 +463,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var hotkeys = new Dictionary() { - { "MapScrollUp", "Scroll up" }, - { "MapScrollDown", "Scroll down" }, - { "MapScrollLeft", "Scroll left" }, - { "MapScrollRight", "Scroll right" }, + { "MapScrollUpKey", "Scroll up" }, + { "MapScrollDownKey", "Scroll down" }, + { "MapScrollLeftKey", "Scroll left" }, + { "MapScrollRightKey", "Scroll right" }, - { "MapPushTop", "Jump to top edge" }, - { "MapPushBottom", "Jump to bottom edge" }, - { "MapPushLeftEdge", "Jump to left edge" }, - { "MapPushRightEdge", "Jump to right edge" }, + { "MapJumpToTopEdgeKey", "Jump to top edge" }, + { "MapJumpToBottomEdgeKey", "Jump to bottom edge" }, + { "MapJumpToLeftEdgeKey", "Jump to left edge" }, + { "MapJumpToRightEdgeKey", "Jump to right edge" }, - { "ViewPortBookmarkSaveSlot1", "Record bookmark #1" }, - { "ViewPortBookmarkUseSlot1", "Jump to bookmark #1" }, - { "ViewPortBookmarkSaveSlot2", "Record bookmark #2" }, - { "ViewPortBookmarkUseSlot2", "Jump to bookmark #2" }, - { "ViewPortBookmarkSaveSlot3", "Record bookmark #3" }, - { "ViewPortBookmarkUseSlot3", "Jump to bookmark #3" }, - { "ViewPortBookmarkSaveSlot4", "Record bookmark #4" }, - { "ViewPortBookmarkUseSlot4", "Jump to bookmark #4" } + { "MapBookmarkSave01Key", "Record bookmark #1" }, + { "MapBookmarkRestore01Key", "Jump to bookmark #1" }, + { "MapBookmarkSave02Key", "Record bookmark #2" }, + { "MapBookmarkRestore02Key", "Jump to bookmark #2" }, + { "MapBookmarkSave03Key", "Record bookmark #3" }, + { "MapBookmarkRestore03Key", "Jump to bookmark #3" }, + { "MapBookmarkSave04Key", "Record bookmark #4" }, + { "MapBookmarkRestore04Key", "Jump to bookmark #4" } }; var header = ScrollItemWidget.Setup(hotkeyHeader, returnTrue, doNothing); diff --git a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs index 1e9036f992..07ebc8bc72 100644 --- a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.Common.Lint; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; using OpenRA.Widgets; @@ -25,9 +26,23 @@ namespace OpenRA.Mods.Common.Widgets { readonly ResourceLayer resourceLayer; + public readonly NamedHotkey ScrollUpKey = new NamedHotkey(); + public readonly NamedHotkey ScrollDownKey = new NamedHotkey(); + public readonly NamedHotkey ScrollLeftKey = new NamedHotkey(); + public readonly NamedHotkey ScrollRightKey = new NamedHotkey(); + + public readonly NamedHotkey JumpToTopEdgeKey = new NamedHotkey(); + public readonly NamedHotkey JumpToBottomEdgeKey = new NamedHotkey(); + public readonly NamedHotkey JumpToLeftEdgeKey = new NamedHotkey(); + public readonly NamedHotkey JumpToRightEdgeKey = new NamedHotkey(); + + // Note: LinterHotkeyNames assumes that these are disabled by default + public readonly string BookmarkSaveKeyPrefix = null; + public readonly string BookmarkRestoreKeyPrefix = null; + public readonly int BookmarkKeyCount = 0; + public readonly string TooltipTemplate = "WORLD_TOOLTIP"; public readonly string TooltipContainer; - Lazy tooltipContainer; public WorldTooltipType TooltipType { get; private set; } public ITooltip ActorTooltip { get; private set; } @@ -35,10 +50,6 @@ namespace OpenRA.Mods.Common.Widgets public FrozenActor FrozenActorTooltip { get; private set; } public ResourceType ResourceTooltip { get; private set; } - int2? joystickScrollStart, joystickScrollEnd; - int2? standardScrollStart; - bool isStandardScrolling; - static readonly Dictionary ScrollCursors = new Dictionary { { ScrollDirection.Up | ScrollDirection.Left, "scroll-tl" }, @@ -71,32 +82,53 @@ namespace OpenRA.Mods.Common.Widgets { ScrollDirection.Right, new float2(1, 0) }, }; + Lazy tooltipContainer; + int2? joystickScrollStart, joystickScrollEnd; + int2? standardScrollStart; + bool isStandardScrolling; + ScrollDirection keyboardDirections; ScrollDirection edgeDirections; World world; WorldRenderer worldRenderer; - WPos?[] viewPortBookmarkSlots = new WPos?[4]; - void SaveBookmark(int index, WPos position) - { - viewPortBookmarkSlots[index] = position; - } + NamedHotkey[] saveBookmarkHotkeys; + NamedHotkey[] restoreBookmarkHotkeys; + WPos?[] bookmarkPositions; - void SaveCurrentPositionToBookmark(int index) + [CustomLintableHotkeyNames] + public static IEnumerable LinterHotkeyNames(MiniYamlNode widgetNode, Action emitError, Action emitWarning) { - SaveBookmark(index, worldRenderer.Viewport.CenterPosition); - } + var savePrefix = ""; + var savePrefixNode = widgetNode.Value.Nodes.FirstOrDefault(n => n.Key == "BookmarkSaveKeyPrefix"); + if (savePrefixNode != null) + savePrefix = savePrefixNode.Value.Value; - WPos? JumpToBookmark(int index) - { - return viewPortBookmarkSlots[index]; - } + var restorePrefix = ""; + var restorePrefixNode = widgetNode.Value.Nodes.FirstOrDefault(n => n.Key == "BookmarkRestoreKeyPrefix"); + if (restorePrefixNode != null) + restorePrefix = restorePrefixNode.Value.Value; - void JumpToSavedBookmark(int index) - { - var bookmark = JumpToBookmark(index); - if (bookmark != null) - worldRenderer.Viewport.Center((WPos)bookmark); + var count = 0; + var countNode = widgetNode.Value.Nodes.FirstOrDefault(n => n.Key == "BookmarkKeyCount"); + if (countNode != null) + count = FieldLoader.GetValue("BookmarkKeyCount", countNode.Value.Value); + + if (count == 0) + yield break; + + if (string.IsNullOrEmpty(savePrefix)) + emitError("{0} must define BookmarkSaveKeyPrefix if BookmarkKeyCount > 0.".F(widgetNode.Location)); + + if (string.IsNullOrEmpty(restorePrefix)) + emitError("{0} must define BookmarkRestoreKeyPrefix if BookmarkKeyCount > 0.".F(widgetNode.Location)); + + for (var i = 0; i < count; i++) + { + var suffix = (i + 1).ToString("D2"); + yield return savePrefix + suffix; + yield return restorePrefix + suffix; + } } [ObjectCreator.UseCtor] @@ -110,6 +142,19 @@ namespace OpenRA.Mods.Common.Widgets resourceLayer = world.WorldActor.TraitOrDefault(); } + public override void Initialize(WidgetArgs args) + { + base.Initialize(args); + + saveBookmarkHotkeys = Exts.MakeArray(BookmarkKeyCount, + i => new NamedHotkey(BookmarkSaveKeyPrefix + (i + 1).ToString("D2"), Game.Settings.Keys)); + + restoreBookmarkHotkeys = Exts.MakeArray(BookmarkKeyCount, + i => new NamedHotkey(BookmarkRestoreKeyPrefix + (i + 1).ToString("D2"), Game.Settings.Keys)); + + bookmarkPositions = new WPos?[BookmarkKeyCount]; + } + public override void MouseEntered() { if (TooltipContainer == null) @@ -381,97 +426,71 @@ namespace OpenRA.Mods.Common.Widgets public override bool HandleKeyPress(KeyInput e) { var key = Hotkey.FromKeyInput(e); - var ks = Game.Settings.Keys; - Func handleMapScrollKey = (hotkey, scrollDirection) => + Func handleMapScrollKey = (hotkey, scrollDirection) => { var isHotkey = false; - if (key.Key == hotkey.Key) + var keyValue = hotkey.GetValue(); + if (key.Key == keyValue.Key) { - isHotkey = key == hotkey; - keyboardDirections = keyboardDirections.Set(scrollDirection, e.Event == KeyInputEvent.Down && (isHotkey || hotkey.Modifiers == Modifiers.None)); + isHotkey = key == keyValue; + keyboardDirections = keyboardDirections.Set(scrollDirection, e.Event == KeyInputEvent.Down && (isHotkey || keyValue.Modifiers == Modifiers.None)); } return isHotkey; }; - if (handleMapScrollKey(ks.MapScrollUp, ScrollDirection.Up) || handleMapScrollKey(ks.MapScrollDown, ScrollDirection.Down) - || handleMapScrollKey(ks.MapScrollLeft, ScrollDirection.Left) || handleMapScrollKey(ks.MapScrollRight, ScrollDirection.Right)) + if (handleMapScrollKey(ScrollUpKey, ScrollDirection.Up) || handleMapScrollKey(ScrollDownKey, ScrollDirection.Down) + || handleMapScrollKey(ScrollLeftKey, ScrollDirection.Left) || handleMapScrollKey(ScrollRightKey, ScrollDirection.Right)) return true; if (e.Event != KeyInputEvent.Down) return false; - if (key == ks.MapPushTop) + if (key == JumpToTopEdgeKey.GetValue()) { worldRenderer.Viewport.Center(new WPos(worldRenderer.Viewport.CenterPosition.X, 0, 0)); return true; } - if (key == ks.MapPushBottom) + if (key == JumpToBottomEdgeKey.GetValue()) { worldRenderer.Viewport.Center(new WPos(worldRenderer.Viewport.CenterPosition.X, worldRenderer.World.Map.ProjectedBottomRight.Y, 0)); return true; } - if (key == ks.MapPushLeftEdge) + if (key == JumpToLeftEdgeKey.GetValue()) { worldRenderer.Viewport.Center(new WPos(0, worldRenderer.Viewport.CenterPosition.Y, 0)); return true; } - if (key == ks.MapPushRightEdge) + if (key == JumpToRightEdgeKey.GetValue()) { worldRenderer.Viewport.Center(new WPos(worldRenderer.World.Map.ProjectedBottomRight.X, worldRenderer.Viewport.CenterPosition.Y, 0)); return true; } - if (key == ks.ViewPortBookmarkSaveSlot1) + for (var i = 0; i < saveBookmarkHotkeys.Length; i++) { - SaveCurrentPositionToBookmark(0); - return true; + if (key == saveBookmarkHotkeys[i].GetValue()) + { + bookmarkPositions[i] = worldRenderer.Viewport.CenterPosition; + return true; + } } - if (key == ks.ViewPortBookmarkSaveSlot2) + for (var i = 0; i < restoreBookmarkHotkeys.Length; i++) { - SaveCurrentPositionToBookmark(1); - return true; - } - - if (key == ks.ViewPortBookmarkSaveSlot3) - { - SaveCurrentPositionToBookmark(2); - return true; - } - - if (key == ks.ViewPortBookmarkSaveSlot4) - { - SaveCurrentPositionToBookmark(3); - return true; - } - - if (key == ks.ViewPortBookmarkUseSlot1) - { - JumpToSavedBookmark(0); - return true; - } - - if (key == ks.ViewPortBookmarkUseSlot2) - { - JumpToSavedBookmark(1); - return true; - } - - if (key == ks.ViewPortBookmarkUseSlot3) - { - JumpToSavedBookmark(2); - return true; - } - - if (key == ks.ViewPortBookmarkUseSlot4) - { - JumpToSavedBookmark(3); - return true; + if (key == restoreBookmarkHotkeys[i].GetValue()) + { + var bookmark = bookmarkPositions[i]; + if (bookmark.HasValue) + { + worldRenderer.Viewport.Center(bookmark.Value); + return true; + } + } } return false; diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index c7634b3fc6..d21283593b 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -224,6 +224,17 @@ Container@EDITOR_WORLD_ROOT: Width: WINDOW_RIGHT Height: WINDOW_BOTTOM IgnoreMouseOver: True + ScrollUpKey: MapScrollUp + ScrollDownKey: MapScrollDown + ScrollLeftKey: MapScrollLeft + ScrollRightKey: MapScrollRight + JumpToTopEdgeKey: MapJumpToTopEdge + JumpToBottomEdgeKey: MapJumpToBottomEdge + JumpToLeftEdgeKey: MapJumpToLeftEdge + JumpToRightEdgeKey: MapJumpToRightEdge + BookmarkSaveKeyPrefix: MapBookmarkSave + BookmarkRestoreKeyPrefix: MapBookmarkRestore + BookmarkKeyCount: 4 Background@RADAR_BG: X: WINDOW_RIGHT - 255 Y: 5 diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index a57898cadd..c4f0126877 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -33,6 +33,17 @@ Container@INGAME_ROOT: Width: WINDOW_RIGHT Height: WINDOW_BOTTOM TooltipContainer: TOOLTIP_CONTAINER + ScrollUpKey: MapScrollUp + ScrollDownKey: MapScrollDown + ScrollLeftKey: MapScrollLeft + ScrollRightKey: MapScrollRight + JumpToTopEdgeKey: MapJumpToTopEdge + JumpToBottomEdgeKey: MapJumpToBottomEdge + JumpToLeftEdgeKey: MapJumpToLeftEdge + JumpToRightEdgeKey: MapJumpToRightEdge + BookmarkSaveKeyPrefix: MapBookmarkSave + BookmarkRestoreKeyPrefix: MapBookmarkRestore + BookmarkKeyCount: 4 WorldCommand: Width: WINDOW_RIGHT Height: WINDOW_BOTTOM diff --git a/mods/common/chrome/editor.yaml b/mods/common/chrome/editor.yaml index b413baca79..4234ed1396 100644 --- a/mods/common/chrome/editor.yaml +++ b/mods/common/chrome/editor.yaml @@ -215,6 +215,17 @@ Container@EDITOR_WORLD_ROOT: Width: WINDOW_RIGHT Height: WINDOW_BOTTOM IgnoreMouseOver: True + ScrollUpKey: MapScrollUp + ScrollDownKey: MapScrollDown + ScrollLeftKey: MapScrollLeft + ScrollRightKey: MapScrollRight + JumpToTopEdgeKey: MapJumpToTopEdge + JumpToBottomEdgeKey: MapJumpToBottomEdge + JumpToLeftEdgeKey: MapJumpToLeftEdge + JumpToRightEdgeKey: MapJumpToRightEdge + BookmarkSaveKeyPrefix: MapBookmarkSave + BookmarkRestoreKeyPrefix: MapBookmarkRestore + BookmarkKeyCount: 4 Background@RADAR_BG: X: WINDOW_RIGHT - 255 Y: 5 diff --git a/mods/common/chrome/ingame.yaml b/mods/common/chrome/ingame.yaml index 41e3309c37..e74531f5d0 100644 --- a/mods/common/chrome/ingame.yaml +++ b/mods/common/chrome/ingame.yaml @@ -29,6 +29,17 @@ Container@INGAME_ROOT: Width: WINDOW_RIGHT Height: WINDOW_BOTTOM TooltipContainer: TOOLTIP_CONTAINER + ScrollUpKey: MapScrollUp + ScrollDownKey: MapScrollDown + ScrollLeftKey: MapScrollLeft + ScrollRightKey: MapScrollRight + JumpToTopEdgeKey: MapJumpToTopEdge + JumpToBottomEdgeKey: MapJumpToBottomEdge + JumpToLeftEdgeKey: MapJumpToLeftEdge + JumpToRightEdgeKey: MapJumpToRightEdge + BookmarkSaveKeyPrefix: MapBookmarkSave + BookmarkRestoreKeyPrefix: MapBookmarkRestore + BookmarkKeyCount: 4 WorldCommand: Width: WINDOW_RIGHT Height: WINDOW_BOTTOM