Add platform override support for hotkeys and unhardcode editor hotkeys

This commit is contained in:
Ivaylo Draganov
2022-05-05 22:51:27 +03:00
committed by Paul Chote
parent 1cf4838b08
commit 6a1a6b6397
12 changed files with 45 additions and 14 deletions

View File

@@ -41,6 +41,14 @@ namespace OpenRA
var contextsNode = node.Nodes.FirstOrDefault(n => n.Key == "Contexts"); var contextsNode = node.Nodes.FirstOrDefault(n => n.Key == "Contexts");
if (contextsNode != null) if (contextsNode != null)
Contexts = FieldLoader.GetValue<HashSet<string>>("Contexts", contextsNode.Value.Value); Contexts = FieldLoader.GetValue<HashSet<string>>("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<Hotkey>("value", platformOverride.Value.Value);
}
} }
} }
} }

View File

@@ -39,15 +39,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var copypasteButton = widget.GetOrNull<ButtonWidget>("COPYPASTE_BUTTON"); var copypasteButton = widget.GetOrNull<ButtonWidget>("COPYPASTE_BUTTON");
if (copypasteButton != null) 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(); 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<HotkeyReference>("Key", modified.ToString());
}
copypasteButton.OnClick = () => editorViewport.SetBrush(new EditorCopyPasteBrush(editorViewport, worldRenderer, () => copyFilters)); copypasteButton.OnClick = () => editorViewport.SetBrush(new EditorCopyPasteBrush(editorViewport, worldRenderer, () => copyFilters));
copypasteButton.IsHighlighted = () => editorViewport.CurrentBrush is EditorCopyPasteBrush; copypasteButton.IsHighlighted = () => editorViewport.CurrentBrush is EditorCopyPasteBrush;

View File

@@ -591,7 +591,7 @@ Container@EDITOR_WORLD_ROOT:
Width: 100 Width: 100
Text: Undo Text: Undo
Font: Bold Font: Bold
Key: z ctrl Key: EditorUndo
TooltipTemplate: BUTTON_TOOLTIP TooltipTemplate: BUTTON_TOOLTIP
TooltipText: Undo last step TooltipText: Undo last step
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer: TOOLTIP_CONTAINER
@@ -602,7 +602,7 @@ Container@EDITOR_WORLD_ROOT:
Width: 100 Width: 100
Text: Redo Text: Redo
Font: Bold Font: Bold
Key: y ctrl Key: EditorRedo
TooltipTemplate: BUTTON_TOOLTIP TooltipTemplate: BUTTON_TOOLTIP
TooltipText: Redo last step TooltipText: Redo last step
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer: TOOLTIP_CONTAINER
@@ -612,7 +612,7 @@ Container@EDITOR_WORLD_ROOT:
Width: 96 Width: 96
Height: 25 Height: 25
Text: Copy/Paste Text: Copy/Paste
Key: c ctrl Key: EditorCopy
TooltipTemplate: BUTTON_TOOLTIP TooltipTemplate: BUTTON_TOOLTIP
TooltipText: Copy TooltipText: Copy
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer: TOOLTIP_CONTAINER

View File

@@ -21,6 +21,8 @@ Container@HOTKEYS_PANEL:
Types: Chat Types: Chat
Control Groups: Control Groups:
Types: ControlGroups Types: ControlGroups
Editor Commands:
Types: Editor
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM Height: PARENT_BOTTOM
Children: Children:

View File

@@ -162,6 +162,7 @@ Hotkeys:
common|hotkeys/supportpowers.yaml common|hotkeys/supportpowers.yaml
common|hotkeys/viewport.yaml common|hotkeys/viewport.yaml
common|hotkeys/chat.yaml common|hotkeys/chat.yaml
common|hotkeys/editor.yaml
common|hotkeys/control-groups.yaml common|hotkeys/control-groups.yaml
cnc|hotkeys.yaml cnc|hotkeys.yaml

View File

@@ -573,7 +573,7 @@ Container@EDITOR_WORLD_ROOT:
TooltipText: Copy TooltipText: Copy
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer: TOOLTIP_CONTAINER
Font: Bold Font: Bold
Key: c ctrl Key: EditorCopy
DropDownButton@COPYFILTER_BUTTON: DropDownButton@COPYFILTER_BUTTON:
X: 170 X: 170
Width: 140 Width: 140
@@ -586,7 +586,7 @@ Container@EDITOR_WORLD_ROOT:
Width: 70 Width: 70
Text: Undo Text: Undo
Font: Bold Font: Bold
Key: z ctrl Key: EditorUndo
TooltipTemplate: BUTTON_TOOLTIP TooltipTemplate: BUTTON_TOOLTIP
TooltipText: Undo last step TooltipText: Undo last step
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer: TOOLTIP_CONTAINER
@@ -596,7 +596,7 @@ Container@EDITOR_WORLD_ROOT:
Width: 70 Width: 70
Text: Redo Text: Redo
Font: Bold Font: Bold
Key: y ctrl Key: EditorRedo
TooltipTemplate: BUTTON_TOOLTIP TooltipTemplate: BUTTON_TOOLTIP
TooltipText: Redo last step TooltipText: Redo last step
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer: TOOLTIP_CONTAINER

View File

@@ -21,6 +21,8 @@ Container@HOTKEYS_PANEL:
Types: Chat Types: Chat
Control Groups: Control Groups:
Types: ControlGroups Types: ControlGroups
Editor Commands:
Types: Editor
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM Height: PARENT_BOTTOM
Children: Children:

View File

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

View File

@@ -147,6 +147,7 @@ Hotkeys:
common|hotkeys/supportpowers.yaml common|hotkeys/supportpowers.yaml
common|hotkeys/viewport.yaml common|hotkeys/viewport.yaml
common|hotkeys/chat.yaml common|hotkeys/chat.yaml
common|hotkeys/editor.yaml
common|hotkeys/control-groups.yaml common|hotkeys/control-groups.yaml
d2k|hotkeys.yaml d2k|hotkeys.yaml

View File

@@ -165,6 +165,7 @@ Hotkeys:
common|hotkeys/supportpowers.yaml common|hotkeys/supportpowers.yaml
common|hotkeys/viewport.yaml common|hotkeys/viewport.yaml
common|hotkeys/chat.yaml common|hotkeys/chat.yaml
common|hotkeys/editor.yaml
common|hotkeys/control-groups.yaml common|hotkeys/control-groups.yaml
ra|hotkeys.yaml ra|hotkeys.yaml

View File

@@ -21,6 +21,8 @@ Container@HOTKEYS_PANEL:
Types: Chat Types: Chat
Control Groups: Control Groups:
Types: ControlGroups Types: ControlGroups
Editor Commands:
Types: Editor
Depth Preview Debug: Depth Preview Debug:
Types: DepthDebug Types: DepthDebug
Width: PARENT_RIGHT Width: PARENT_RIGHT

View File

@@ -204,6 +204,7 @@ Hotkeys:
common|hotkeys/supportpowers.yaml common|hotkeys/supportpowers.yaml
common|hotkeys/viewport.yaml common|hotkeys/viewport.yaml
common|hotkeys/chat.yaml common|hotkeys/chat.yaml
common|hotkeys/editor.yaml
common|hotkeys/control-groups.yaml common|hotkeys/control-groups.yaml
ts|hotkeys.yaml ts|hotkeys.yaml