From 6a1a6b639759e8163a6cb2c6c9534fa49525f6ce Mon Sep 17 00:00:00 2001 From: Ivaylo Draganov Date: Thu, 5 May 2022 22:51:27 +0300 Subject: [PATCH] Add platform override support for hotkeys and unhardcode editor hotkeys --- OpenRA.Game/HotkeyDefinition.cs | 8 +++++++ .../Widgets/Logic/Editor/MapEditorLogic.cs | 8 ------- mods/cnc/chrome/editor.yaml | 6 +++--- mods/cnc/chrome/settings-hotkeys.yaml | 2 ++ mods/cnc/mod.yaml | 1 + mods/common/chrome/editor.yaml | 6 +++--- mods/common/chrome/settings-hotkeys.yaml | 2 ++ mods/common/hotkeys/editor.yaml | 21 +++++++++++++++++++ mods/d2k/mod.yaml | 1 + mods/ra/mod.yaml | 1 + mods/ts/chrome/settings-hotkeys.yaml | 2 ++ mods/ts/mod.yaml | 1 + 12 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 mods/common/hotkeys/editor.yaml diff --git a/OpenRA.Game/HotkeyDefinition.cs b/OpenRA.Game/HotkeyDefinition.cs index f2c0fc2a84..567153a90c 100644 --- a/OpenRA.Game/HotkeyDefinition.cs +++ b/OpenRA.Game/HotkeyDefinition.cs @@ -41,6 +41,14 @@ namespace OpenRA var contextsNode = node.Nodes.FirstOrDefault(n => n.Key == "Contexts"); if (contextsNode != null) Contexts = FieldLoader.GetValue>("Contexts", contextsNode.Value.Value); + + var platformNode = node.Nodes.FirstOrDefault(n => n.Key == "Platform"); + if (platformNode != null) + { + var platformOverride = platformNode.Value.Nodes.FirstOrDefault(n => n.Key == Platform.CurrentPlatform.ToString()); + if (platformOverride != null) + Default = FieldLoader.GetValue("value", platformOverride.Value.Value); + } } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs index 14357cf82e..f666b92e34 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs @@ -39,15 +39,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var copypasteButton = widget.GetOrNull("COPYPASTE_BUTTON"); if (copypasteButton != null) { - // HACK: Replace Ctrl with Cmd on macOS - // TODO: Add platform-specific override support to HotkeyManager - // and then port the editor hotkeys to this system. var copyPasteKey = copypasteButton.Key.GetValue(); - if (Platform.CurrentPlatform == PlatformType.OSX && copyPasteKey.Modifiers.HasModifier(Modifiers.Ctrl)) - { - var modified = new Hotkey(copyPasteKey.Key, copyPasteKey.Modifiers & ~Modifiers.Ctrl | Modifiers.Meta); - copypasteButton.Key = FieldLoader.GetValue("Key", modified.ToString()); - } copypasteButton.OnClick = () => editorViewport.SetBrush(new EditorCopyPasteBrush(editorViewport, worldRenderer, () => copyFilters)); copypasteButton.IsHighlighted = () => editorViewport.CurrentBrush is EditorCopyPasteBrush; diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index 6eb9e54298..63b54d3e67 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -591,7 +591,7 @@ Container@EDITOR_WORLD_ROOT: Width: 100 Text: Undo Font: Bold - Key: z ctrl + Key: EditorUndo TooltipTemplate: BUTTON_TOOLTIP TooltipText: Undo last step TooltipContainer: TOOLTIP_CONTAINER @@ -602,7 +602,7 @@ Container@EDITOR_WORLD_ROOT: Width: 100 Text: Redo Font: Bold - Key: y ctrl + Key: EditorRedo TooltipTemplate: BUTTON_TOOLTIP TooltipText: Redo last step TooltipContainer: TOOLTIP_CONTAINER @@ -612,7 +612,7 @@ Container@EDITOR_WORLD_ROOT: Width: 96 Height: 25 Text: Copy/Paste - Key: c ctrl + Key: EditorCopy TooltipTemplate: BUTTON_TOOLTIP TooltipText: Copy TooltipContainer: TOOLTIP_CONTAINER diff --git a/mods/cnc/chrome/settings-hotkeys.yaml b/mods/cnc/chrome/settings-hotkeys.yaml index 8cf1ec1906..3fc2c783ed 100644 --- a/mods/cnc/chrome/settings-hotkeys.yaml +++ b/mods/cnc/chrome/settings-hotkeys.yaml @@ -21,6 +21,8 @@ Container@HOTKEYS_PANEL: Types: Chat Control Groups: Types: ControlGroups + Editor Commands: + Types: Editor Width: PARENT_RIGHT Height: PARENT_BOTTOM Children: diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 526daa77ba..09770b6235 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -162,6 +162,7 @@ Hotkeys: common|hotkeys/supportpowers.yaml common|hotkeys/viewport.yaml common|hotkeys/chat.yaml + common|hotkeys/editor.yaml common|hotkeys/control-groups.yaml cnc|hotkeys.yaml diff --git a/mods/common/chrome/editor.yaml b/mods/common/chrome/editor.yaml index b43e6525f9..0141f8103e 100644 --- a/mods/common/chrome/editor.yaml +++ b/mods/common/chrome/editor.yaml @@ -573,7 +573,7 @@ Container@EDITOR_WORLD_ROOT: TooltipText: Copy TooltipContainer: TOOLTIP_CONTAINER Font: Bold - Key: c ctrl + Key: EditorCopy DropDownButton@COPYFILTER_BUTTON: X: 170 Width: 140 @@ -586,7 +586,7 @@ Container@EDITOR_WORLD_ROOT: Width: 70 Text: Undo Font: Bold - Key: z ctrl + Key: EditorUndo TooltipTemplate: BUTTON_TOOLTIP TooltipText: Undo last step TooltipContainer: TOOLTIP_CONTAINER @@ -596,7 +596,7 @@ Container@EDITOR_WORLD_ROOT: Width: 70 Text: Redo Font: Bold - Key: y ctrl + Key: EditorRedo TooltipTemplate: BUTTON_TOOLTIP TooltipText: Redo last step TooltipContainer: TOOLTIP_CONTAINER diff --git a/mods/common/chrome/settings-hotkeys.yaml b/mods/common/chrome/settings-hotkeys.yaml index 1e4bdcbc22..8cc27338c4 100644 --- a/mods/common/chrome/settings-hotkeys.yaml +++ b/mods/common/chrome/settings-hotkeys.yaml @@ -21,6 +21,8 @@ Container@HOTKEYS_PANEL: Types: Chat Control Groups: Types: ControlGroups + Editor Commands: + Types: Editor Width: PARENT_RIGHT Height: PARENT_BOTTOM Children: diff --git a/mods/common/hotkeys/editor.yaml b/mods/common/hotkeys/editor.yaml new file mode 100644 index 0000000000..85a6da96b9 --- /dev/null +++ b/mods/common/hotkeys/editor.yaml @@ -0,0 +1,21 @@ +EditorUndo: Z Ctrl + Description: Undo + Types: Editor + Contexts: Editor + Platform: + OSX: Z Meta + +EditorRedo: Y Ctrl + Description: Redo + Types: Editor + Contexts: Editor + Platform: + OSX: Z Meta, Shift + Linux: Z Ctrl, Shift + +EditorCopy: C Ctrl + Description: Copy + Types: Editor + Contexts: Editor + Platform: + OSX: C Meta diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 691d9157f0..dcaa353c51 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -147,6 +147,7 @@ Hotkeys: common|hotkeys/supportpowers.yaml common|hotkeys/viewport.yaml common|hotkeys/chat.yaml + common|hotkeys/editor.yaml common|hotkeys/control-groups.yaml d2k|hotkeys.yaml diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 4fafd5edbb..2ad42c0826 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -165,6 +165,7 @@ Hotkeys: common|hotkeys/supportpowers.yaml common|hotkeys/viewport.yaml common|hotkeys/chat.yaml + common|hotkeys/editor.yaml common|hotkeys/control-groups.yaml ra|hotkeys.yaml diff --git a/mods/ts/chrome/settings-hotkeys.yaml b/mods/ts/chrome/settings-hotkeys.yaml index e57d06e3a6..48911c1b13 100644 --- a/mods/ts/chrome/settings-hotkeys.yaml +++ b/mods/ts/chrome/settings-hotkeys.yaml @@ -21,6 +21,8 @@ Container@HOTKEYS_PANEL: Types: Chat Control Groups: Types: ControlGroups + Editor Commands: + Types: Editor Depth Preview Debug: Types: DepthDebug Width: PARENT_RIGHT diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 49cfe0c6aa..7eb95cb9e1 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -204,6 +204,7 @@ Hotkeys: common|hotkeys/supportpowers.yaml common|hotkeys/viewport.yaml common|hotkeys/chat.yaml + common|hotkeys/editor.yaml common|hotkeys/control-groups.yaml ts|hotkeys.yaml