From 0a05f9337cd15a57b2e1633449cd0812a41b7dbc Mon Sep 17 00:00:00 2001 From: Ivaylo Draganov Date: Thu, 22 Jul 2021 18:49:19 +0300 Subject: [PATCH] Add support for readonly hotkeys and expose chat input hotkeys --- OpenRA.Game/HotkeyDefinition.cs | 5 ++++ OpenRA.Game/HotkeyManager.cs | 5 +++- .../Logic/Settings/HotkeysSettingsLogic.cs | 30 +++++++++++++------ mods/cnc/chrome/ingame-chat.yaml | 2 +- mods/cnc/chrome/ingame-infochat.yaml | 2 +- mods/cnc/chrome/lobby.yaml | 2 +- mods/cnc/chrome/settings-hotkeys.yaml | 5 ++++ mods/common/chrome/ingame-chat.yaml | 2 +- mods/common/chrome/ingame-infochat.yaml | 2 +- mods/common/chrome/lobby.yaml | 2 +- mods/common/chrome/settings-hotkeys.yaml | 5 ++++ mods/common/hotkeys/chat.yaml | 12 ++++++++ mods/ts/chrome/settings-hotkeys.yaml | 5 ++++ 13 files changed, 63 insertions(+), 16 deletions(-) diff --git a/OpenRA.Game/HotkeyDefinition.cs b/OpenRA.Game/HotkeyDefinition.cs index 567153a90c47..cc46f9ee405e 100644 --- a/OpenRA.Game/HotkeyDefinition.cs +++ b/OpenRA.Game/HotkeyDefinition.cs @@ -21,6 +21,7 @@ public sealed class HotkeyDefinition public readonly string Description = ""; public readonly HashSet Types = new HashSet(); public readonly HashSet Contexts = new HashSet(); + public readonly bool Readonly = false; public bool HasDuplicates { get; internal set; } public HotkeyDefinition(string name, MiniYaml node) @@ -49,6 +50,10 @@ public HotkeyDefinition(string name, MiniYaml node) if (platformOverride != null) Default = FieldLoader.GetValue("value", platformOverride.Value.Value); } + + var readonlyNode = node.Nodes.FirstOrDefault(n => n.Key == "Readonly"); + if (readonlyNode != null) + Readonly = FieldLoader.GetValue("Readonly", readonlyNode.Value.Value); } } } diff --git a/OpenRA.Game/HotkeyManager.cs b/OpenRA.Game/HotkeyManager.cs index 1c3907346bf0..9ad34e3f2305 100644 --- a/OpenRA.Game/HotkeyManager.cs +++ b/OpenRA.Game/HotkeyManager.cs @@ -35,7 +35,7 @@ public HotkeyManager(IReadOnlyFileSystem fileSystem, Dictionary foreach (var kv in settings) { - if (definitions.ContainsKey(kv.Key)) + if (definitions.ContainsKey(kv.Key) && !definitions[kv.Key].Readonly) keys[kv.Key] = kv.Value; } @@ -61,6 +61,9 @@ public void Set(string name, Hotkey value) if (!definitions.TryGetValue(name, out var definition)) return; + if (definition.Readonly) + return; + keys[name] = value; if (value != definition.Default) settings[name] = value; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs index 5be4a49ff893..e62e93753e77 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs @@ -86,7 +86,11 @@ void BindHotkeyPref(HotkeyDefinition hd, Widget template) selectedHotkeyButton = remapButton; hotkeyEntryWidget.Key = modData.Hotkeys[hd.Name].GetValue(); ValidateHotkey(); - hotkeyEntryWidget.TakeKeyboardFocus(); + + if (hd.Readonly) + hotkeyEntryWidget.YieldKeyboardFocus(); + else + hotkeyEntryWidget.TakeKeyboardFocus(); }; hotkeyList.AddChild(key); @@ -215,7 +219,7 @@ void InitHotkeyRemapDialog(Widget panel) var duplicateNotice = panel.Get("DUPLICATE_NOTICE"); duplicateNotice.TextColor = ChromeMetrics.Get("NoticeErrorColor"); - duplicateNotice.IsVisible = () => !isHotkeyValid; + duplicateNotice.IsVisible = () => !isHotkeyValid && !selectedHotkeyDefinition.Readonly; var duplicateNoticeText = new CachedTransform(hd => hd != null ? duplicateNotice.Text.F(hd.Description, hd.Contexts.First(c => selectedHotkeyDefinition.Contexts.Contains(c))) : @@ -224,21 +228,25 @@ void InitHotkeyRemapDialog(Widget panel) var originalNotice = panel.Get("ORIGINAL_NOTICE"); originalNotice.TextColor = ChromeMetrics.Get("NoticeInfoColor"); - originalNotice.IsVisible = () => isHotkeyValid && !isHotkeyDefault; + originalNotice.IsVisible = () => isHotkeyValid && !isHotkeyDefault && !selectedHotkeyDefinition.Readonly; var originalNoticeText = new CachedTransform(hd => originalNotice.Text.F(hd?.Default.DisplayString())); originalNotice.GetText = () => originalNoticeText.Update(selectedHotkeyDefinition); + var readonlyNotice = panel.Get("READONLY_NOTICE"); + readonlyNotice.TextColor = ChromeMetrics.Get("NoticeInfoColor"); + readonlyNotice.IsVisible = () => selectedHotkeyDefinition.Readonly && isHotkeyValid; + var resetButton = panel.Get("RESET_HOTKEY_BUTTON"); - resetButton.IsDisabled = () => isHotkeyDefault; + resetButton.IsDisabled = () => isHotkeyDefault || selectedHotkeyDefinition.Readonly; resetButton.OnClick = ResetHotkey; var clearButton = panel.Get("CLEAR_HOTKEY_BUTTON"); - clearButton.IsDisabled = () => !hotkeyEntryWidget.Key.IsValid(); + clearButton.IsDisabled = () => !hotkeyEntryWidget.Key.IsValid() || selectedHotkeyDefinition.Readonly; clearButton.OnClick = ClearHotkey; var overrideButton = panel.Get("OVERRIDE_HOTKEY_BUTTON"); - overrideButton.IsDisabled = () => isHotkeyValid; - overrideButton.IsVisible = () => !isHotkeyValid; + overrideButton.IsDisabled = () => isHotkeyValid || selectedHotkeyDefinition.Readonly; + overrideButton.IsVisible = () => !isHotkeyValid && !selectedHotkeyDefinition.Readonly && !duplicateHotkeyDefinition.Readonly; overrideButton.OnClick = OverrideHotkey; hotkeyEntryWidget = panel.Get("HOTKEY_ENTRY"); @@ -248,6 +256,7 @@ void InitHotkeyRemapDialog(Widget panel) { hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue(); }; + hotkeyEntryWidget.IsDisabled = () => selectedHotkeyDefinition.Readonly; validHotkeyEntryWidth = hotkeyEntryWidget.Bounds.Width; invalidHotkeyEntryWidth = validHotkeyEntryWidth - (clearButton.Bounds.X - overrideButton.Bounds.X); @@ -259,7 +268,7 @@ void ValidateHotkey() return; duplicateHotkeyDefinition = modData.Hotkeys.GetFirstDuplicate(selectedHotkeyDefinition, hotkeyEntryWidget.Key); - isHotkeyValid = duplicateHotkeyDefinition == null; + isHotkeyValid = duplicateHotkeyDefinition == null || selectedHotkeyDefinition.Readonly; isHotkeyDefault = hotkeyEntryWidget.Key == selectedHotkeyDefinition.Default || (!hotkeyEntryWidget.Key.IsValid() && !selectedHotkeyDefinition.Default.IsValid()); if (isHotkeyValid) @@ -269,13 +278,16 @@ void ValidateHotkey() } else { - hotkeyEntryWidget.Bounds.Width = invalidHotkeyEntryWidth; + hotkeyEntryWidget.Bounds.Width = duplicateHotkeyDefinition.Readonly ? validHotkeyEntryWidth : invalidHotkeyEntryWidth; hotkeyEntryWidget.TakeKeyboardFocus(); } } void SaveHotkey() { + if (selectedHotkeyDefinition.Readonly) + return; + WidgetUtils.TruncateButtonToTooltip(selectedHotkeyButton, hotkeyEntryWidget.Key.DisplayString()); modData.Hotkeys.Set(selectedHotkeyDefinition.Name, hotkeyEntryWidget.Key); Game.Settings.Save(); diff --git a/mods/cnc/chrome/ingame-chat.yaml b/mods/cnc/chrome/ingame-chat.yaml index 6153af88c5f6..bc0b3293bd88 100644 --- a/mods/cnc/chrome/ingame-chat.yaml +++ b/mods/cnc/chrome/ingame-chat.yaml @@ -32,7 +32,7 @@ Container@CHAT_PANEL: Height: 25 Text: Team Font: Bold - Key: Tab SHIFT + Key: ToggleChatMode TooltipText: Toggle chat mode TooltipTemplate: BUTTON_TOOLTIP_FACTIONSUFFIX TooltipContainer: TOOLTIP_CONTAINER diff --git a/mods/cnc/chrome/ingame-infochat.yaml b/mods/cnc/chrome/ingame-infochat.yaml index a32467e74084..64be9d5f4c3e 100644 --- a/mods/cnc/chrome/ingame-infochat.yaml +++ b/mods/cnc/chrome/ingame-infochat.yaml @@ -19,7 +19,7 @@ Container@CHAT_CONTAINER: Height: 25 Text: Team Font: Bold - Key: Tab SHIFT + Key: ToggleChatMode TooltipText: Toggle chat mode TooltipContainer: TOOLTIP_CONTAINER TextField@CHAT_TEXTFIELD: diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 573a13e66d6e..3f0d13e77b05 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -110,7 +110,7 @@ Container@SERVER_LOBBY: Height: 25 Text: Team Font: Bold - Key: Tab SHIFT + Key: ToggleChatMode TooltipText: Toggle chat mode TooltipContainer: TOOLTIP_CONTAINER TextField@CHAT_TEXTFIELD: diff --git a/mods/cnc/chrome/settings-hotkeys.yaml b/mods/cnc/chrome/settings-hotkeys.yaml index 3fc2c783ed5b..1b1f153eb4a4 100644 --- a/mods/cnc/chrome/settings-hotkeys.yaml +++ b/mods/cnc/chrome/settings-hotkeys.yaml @@ -131,6 +131,11 @@ Container@HOTKEYS_PANEL: Height: PARENT_BOTTOM Font: Tiny Text: This is already used for "{0}" in the {1} context + Label@READONLY_NOTICE: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM + Font: Tiny + Text: This hotkey cannot be modified Button@OVERRIDE_HOTKEY_BUTTON: X: PARENT_RIGHT - 3 * WIDTH - 30 Y: 20 diff --git a/mods/common/chrome/ingame-chat.yaml b/mods/common/chrome/ingame-chat.yaml index dceb441d02d3..0d2a819c4eef 100644 --- a/mods/common/chrome/ingame-chat.yaml +++ b/mods/common/chrome/ingame-chat.yaml @@ -31,7 +31,7 @@ Container@CHAT_PANEL: Height: 25 Text: Team Font: Bold - Key: Tab SHIFT + Key: ToggleChatMode TooltipText: Toggle chat mode TooltipContainer: TOOLTIP_CONTAINER TextField@CHAT_TEXTFIELD: diff --git a/mods/common/chrome/ingame-infochat.yaml b/mods/common/chrome/ingame-infochat.yaml index 6b7313bd9c85..6d681bfa9c3f 100644 --- a/mods/common/chrome/ingame-infochat.yaml +++ b/mods/common/chrome/ingame-infochat.yaml @@ -19,7 +19,7 @@ Container@CHAT_CONTAINER: Height: 25 Text: Team Font: Bold - Key: Tab SHIFT + Key: ToggleChatMode TooltipText: Toggle chat mode TooltipContainer: TOOLTIP_CONTAINER TextField@CHAT_TEXTFIELD: diff --git a/mods/common/chrome/lobby.yaml b/mods/common/chrome/lobby.yaml index 0535cb1d58bf..cb5f89b50739 100644 --- a/mods/common/chrome/lobby.yaml +++ b/mods/common/chrome/lobby.yaml @@ -114,7 +114,7 @@ Background@SERVER_LOBBY: Height: 25 Text: Team Font: Bold - Key: Tab SHIFT + Key: ToggleChatMode TooltipText: Toggle chat mode TooltipContainer: TOOLTIP_CONTAINER TextField@CHAT_TEXTFIELD: diff --git a/mods/common/chrome/settings-hotkeys.yaml b/mods/common/chrome/settings-hotkeys.yaml index 8cc27338c477..9fac07e92fc7 100644 --- a/mods/common/chrome/settings-hotkeys.yaml +++ b/mods/common/chrome/settings-hotkeys.yaml @@ -131,6 +131,11 @@ Container@HOTKEYS_PANEL: Height: PARENT_BOTTOM Font: Tiny Text: This is already used for "{0}" in the {1} context + Label@READONLY_NOTICE: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM + Font: Tiny + Text: This hotkey cannot be modified Button@OVERRIDE_HOTKEY_BUTTON: X: PARENT_RIGHT - 3 * WIDTH - 30 Y: 20 diff --git a/mods/common/hotkeys/chat.yaml b/mods/common/hotkeys/chat.yaml index 9eac1b60acc0..c02d3c34a293 100644 --- a/mods/common/hotkeys/chat.yaml +++ b/mods/common/hotkeys/chat.yaml @@ -7,3 +7,15 @@ OpenGeneralChat: Return Shift Description: Open General Chat Types: Chat Contexts: Player, Spectator + +ToggleChatMode: Tab Shift + Description: Toggle Chat Mode + Types: Chat + Contexts: Chat Input, Menu + Readonly: True + +Autocomplete: Tab + Description: Autocomplete + Types: Chat + Contexts: Chat Input + Readonly: True diff --git a/mods/ts/chrome/settings-hotkeys.yaml b/mods/ts/chrome/settings-hotkeys.yaml index 48911c1b13de..49a94d5f38d6 100644 --- a/mods/ts/chrome/settings-hotkeys.yaml +++ b/mods/ts/chrome/settings-hotkeys.yaml @@ -133,6 +133,11 @@ Container@HOTKEYS_PANEL: Height: PARENT_BOTTOM Font: Tiny Text: This is already used for "{0}" in the {1} context + Label@READONLY_NOTICE: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM + Font: Tiny + Text: This hotkey cannot be modified Button@OVERRIDE_HOTKEY_BUTTON: X: PARENT_RIGHT - 3 * WIDTH - 30 Y: 20