Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add platform override support for hotkeys and unhardcode editor hotkeys #20028

Merged
merged 1 commit into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions OpenRA.Game/HotkeyDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public HotkeyDefinition(string name, MiniYaml node)
var contextsNode = node.Nodes.FirstOrDefault(n => n.Key == "Contexts");
if (contextsNode != null)
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);
}
}
}
}
8 changes: 0 additions & 8 deletions OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@ public MapEditorLogic(Widget widget, World world, WorldRenderer worldRenderer)
var copypasteButton = widget.GetOrNull<ButtonWidget>("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<HotkeyReference>("Key", modified.ToString());
}

copypasteButton.OnClick = () => editorViewport.SetBrush(new EditorCopyPasteBrush(editorViewport, worldRenderer, () => copyFilters));
copypasteButton.IsHighlighted = () => editorViewport.CurrentBrush is EditorCopyPasteBrush;
Expand Down
6 changes: 3 additions & 3 deletions mods/cnc/chrome/editor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mods/cnc/chrome/settings-hotkeys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Container@HOTKEYS_PANEL:
Types: Chat
Control Groups:
Types: ControlGroups
Editor Commands:
Types: Editor
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Children:
Expand Down
1 change: 1 addition & 0 deletions mods/cnc/mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions mods/common/chrome/editor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mods/common/chrome/settings-hotkeys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Container@HOTKEYS_PANEL:
Types: Chat
Control Groups:
Types: ControlGroups
Editor Commands:
Types: Editor
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Children:
Expand Down
21 changes: 21 additions & 0 deletions mods/common/hotkeys/editor.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions mods/d2k/mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions mods/ra/mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions mods/ts/chrome/settings-hotkeys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mods/ts/mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down