-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 hotkey filtering functionality (by name and by context) #19979
Conversation
How about: diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs
index 4a078409bc..8385cd2cc2 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs
@@ -216,7 +216,7 @@ void InitHotkeyRemapDialog(Widget panel)
var duplicateNotice = panel.Get<LabelWidget>("DUPLICATE_NOTICE");
duplicateNotice.TextColor = ChromeMetrics.Get<Color>("NoticeErrorColor");
duplicateNotice.IsVisible = () => !isHotkeyValid;
- var duplicateNoticeText = new CachedTransform<HotkeyDefinition, string>(hd => hd != null ? duplicateNotice.Text.F(hd.Description) : duplicateNotice.Text);
+ var duplicateNoticeText = new CachedTransform<HotkeyDefinition, string>(hd => hd != null ? duplicateNotice.Text.F(hd.Description, hd.Contexts.First(c => selectedHotkeyDefinition.Contexts.Contains(c))) : duplicateNotice.Text);
duplicateNotice.GetText = () => duplicateNoticeText.Update(duplicateHotkeyDefinition);
var originalNotice = panel.Get<LabelWidget>("ORIGINAL_NOTICE");
diff --git a/mods/cnc/chrome/settings-hotkeys.yaml b/mods/cnc/chrome/settings-hotkeys.yaml
index 310956c438..f5eee56fdf 100644
--- a/mods/cnc/chrome/settings-hotkeys.yaml
+++ b/mods/cnc/chrome/settings-hotkeys.yaml
@@ -128,7 +128,7 @@ Container@HOTKEYS_PANEL:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Font: Tiny
- Text: This is already used for "{0}" in an overlapping context
+ Text: This is already used for "{0}" in the {1} context
Button@OVERRIDE_HOTKEY_BUTTON:
X: PARENT_RIGHT - 3 * WIDTH - 30
Y: 20 (plus the other yaml files)? |
0c44fbe
to
964f6c2
Compare
Rebased and implemented #19979 (comment): |
var isFilteredByName = false; | ||
var isFilteredByContext = false; | ||
|
||
if (string.IsNullOrWhiteSpace(filter) || hd.Description.Contains(filter, StringComparison.OrdinalIgnoreCase)) | ||
isFilteredByName = true; | ||
|
||
if (currentContext == "Any" || hd.Contexts.Contains(currentContext)) | ||
isFilteredByContext = true; | ||
|
||
return isFilteredByName && isFilteredByContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var isFilteredByName = false; | |
var isFilteredByContext = false; | |
if (string.IsNullOrWhiteSpace(filter) || hd.Description.Contains(filter, StringComparison.OrdinalIgnoreCase)) | |
isFilteredByName = true; | |
if (currentContext == "Any" || hd.Contexts.Contains(currentContext)) | |
isFilteredByContext = true; | |
return isFilteredByName && isFilteredByContext; | |
var isFilteredByName = string.IsNullOrWhiteSpace(filter) || hd.Description.Contains(filter, StringComparison.OrdinalIgnoreCase); | |
var isFilteredByContext = currentContext == "Any" || hd.Contexts.Contains(currentContext); | |
return isFilteredByName && isFilteredByContext; |
var duplicateNoticeText = new CachedTransform<HotkeyDefinition, string>(hd => | ||
hd != null ? | ||
duplicateNotice.Text.F(hd.Description, hd.Contexts.First(c => selectedHotkeyDefinition.Contexts.Contains(c))) : | ||
duplicateNotice.Text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplicate notice has {0}
and {1}
in it, so does it even make sense to display that here without .F
? Also, if hd
is null
in this context, then duplicateHotkeyDefinition
is also null
, correct? In that case this text is not displayed anyway, so I'd suggest putting an empty string.
964f6c2
to
c74836b
Compare
Update: rebased and applied the fixups suggested by @abcdefg30 |
c74836b
to
9c89423
Compare
Update: Slight scope creep - I'm using the opportunity to remove a couple of stray yaml nodes that are no longer needed. |
This implements the UI part of #19898 (back-end part was done in #19900). Hotkey can be filtered by name and by context. Context overlap is used for validation so this new UI should make it clearer to the user how hotkeys are validated. The error message for duplicate bindings is expanded to clarify that.
Filtering by context
Filtering by name and a warning for duplicate binding
No matching hotkeys
Closes #19898