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 hotkey filtering functionality (by name and by context) #19979

Merged
merged 2 commits into from
May 3, 2022

Conversation

dragunoff
Copy link
Contributor

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.

image
Filtering by context

image
Filtering by name and a warning for duplicate binding

image
No matching hotkeys

Closes #19898

@pchote
Copy link
Member

pchote commented Apr 23, 2022

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)?

@dragunoff
Copy link
Contributor Author

Rebased and implemented #19979 (comment):
image

pchote
pchote previously approved these changes Apr 30, 2022
@pchote pchote added this to the Next release milestone Apr 30, 2022
Comment on lines 308 to 311
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Member

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.

@dragunoff
Copy link
Contributor Author

Update: rebased and applied the fixups suggested by @abcdefg30

@dragunoff dragunoff force-pushed the feature/hotkey-filtering-ui branch from c74836b to 9c89423 Compare May 3, 2022 18:13
@dragunoff
Copy link
Contributor Author

Update: Slight scope creep - I'm using the opportunity to remove a couple of stray yaml nodes that are no longer needed.

@abcdefg30 abcdefg30 merged commit 1cf4838 into OpenRA:bleed May 3, 2022
@dragunoff dragunoff deleted the feature/hotkey-filtering-ui branch May 3, 2022 20:23
@abcdefg30
Copy link
Member

Changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hotkey contexts for easier validation and improved mental model
3 participants