Opened 13 years ago

Closed 12 years ago

Last modified 8 years ago

#953 closed defect (fixed)

[PATCH] local.cfg adds keys instead of replacing them

Reported by: vts Owned by: philip
Priority: Nice to Have Milestone: Alpha 10
Component: Core engine Keywords: patch, simple
Cc: Patch:

Description

When defining custom keys in local.cfg, the keys appear to work in addition to the existing ones from default.cfg, rather than instead of them.

For instance. Specifying

hotkey.camera.left = Q, LeftArrow

in local.cfg causes the Q key to activate both camera.left and the existing camera.rotate.cw from default.cfg:

hotkey.camera.rotate.cw = "Ctrl+LeftArrow", "Ctrl+A", Q

The same is true for e.g. trying to change hotkey.console.toggle; the keys specified in local.cfg will work in addition to the ones from default.cfg, not instead of.

Also, using local.cfg to try and set the Escape key to certain commands does not work. hotkey.menu.toggle = Escape does not toggle the menu ingame when Escape is pressed, but the F10 key from default.cfg still does.

Attachments (2)

Ticket#953.patch (3.2 KB ) - added by Bogdan Lazic 13 years ago.
Ticket#953_v2.patch (2.5 KB ) - added by Bogdan Lazic 12 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 by Bogdan Lazic, 13 years ago

I will try to solve it.

by Bogdan Lazic, 13 years ago

Attachment: Ticket#953.patch added

comment:2 by Bogdan Lazic, 13 years ago

Keywords: review added

Idea is to use set to detect all hotkey shortcut which is already used. Order in which config file is applied in Config.cpp is changed. So if shortcut already exist then do not add it again. Exception is Shift and Ctrl, because they can be used multiple time.

comment:3 by historic_bruno, 13 years ago

Milestone: BacklogAlpha 8
Summary: local.cfg adds keys instead of replacing them[PATCH] local.cfg adds keys instead of replacing them

in reply to:  2 comment:4 by historic_bruno, 13 years ago

Keywords: review removed

Replying to Bogi:

Idea is to use set to detect all hotkey shortcut which is already used. Order in which config file is applied in Config.cpp is changed. So if shortcut already exist then do not add it again. Exception is Shift and Ctrl, because they can be used multiple time.

First, thanks for the patch and sorry it took a while to review :)

You should probably use the definitions in KeyName.cpp instead of hard-coding e.g. "Ctrl".

The patch's logic still allows for multiple identical hotkeys because if a hotkey has a modifier in it, it's instantly excluded from testing the used set, meaning Ctrl+Foo could still be used multiple times.

There's another bigger complication: any modifier key can be used multiple times, not just Ctrl and Shift, but Alt and also multiple combinations, in fact you can use combinations of almost any keys (I almost think you need multiple used sets to handle all these weird cases). In other words, the engine doesn't require that Ctrl and Shift come first in the argument. Consider the valid hotkeys "Shift+Alt+Ctrl+C" or "F9+Alt".

I'm not sure what the best solution is. We need something like the parsing logic of Hotkey.cpp so that we can break the hotkey strings into distinct keys, and then they have to be compared against all previously defined combinations of keys, but ignoring argument order, and that has to be done respecting the "priority" of config files. Feel free to discuss :)

comment:5 by historic_bruno, 13 years ago

Milestone: Alpha 8Backlog

comment:6 by Philip Taylor, 12 years ago

I think a better solution would be to change CConfigDB::GetValuesWithPrefix. Currently it returns every config key-value pair whose key matches the prefix, regardless of config namespace. Instead, if a key occurs in two or more namespaces, it should only return the key-value pairs for that key from the highest-priority one of those namespaces.

by Bogdan Lazic, 12 years ago

Attachment: Ticket#953_v2.patch added

comment:7 by Bogdan Lazic, 12 years ago

It is another patch, it should be a better solution then previous one.

comment:8 by Bogdan Lazic, 12 years ago

Keywords: review added
Summary: [PATCH] local.cfg adds keys instead of replacing them[PATCH]

comment:9 by Bogdan Lazic, 12 years ago

Summary: [PATCH][PATCH] local.cfg adds keys instead of replacing them

comment:10 by historic_bruno, 12 years ago

Milestone: BacklogAlpha 9

comment:11 by historic_bruno, 12 years ago

Milestone: Alpha 9Alpha 10

comment:12 by Kieran P, 12 years ago

Priority: Should HaveNice to Have

comment:13 by Kieran P, 12 years ago

Keywords: patch added

comment:14 by Kieran P, 12 years ago

Keywords: simple, patch, review → patch, review, simple

comment:15 by Philip Taylor, 12 years ago

Hmm, RemoveOverlapingHotkeys() seems to break things: It's intentional that the same key sequence might be used for multiple hotkeys, e.g. ctrl+rightarrow is both "text.move.right" (when a GUI text input is focused) and "camera.rotate.ccw" (when not handled by the GUI), but that function removes one of those bindings. So I think the original bug report about the Q key is not a bug - it's perfectly legitimate to bind one key to multiple actions, in either a single config file or multiple. If we had a hotkey-editing UI then it probably ought to warn you if you add a binding that conflicts with another binding, but that's a problem for the UI and not for the config system.

The change in GetValuesWithPrefix seems to work, but I'll simplify it by returning a std::map to guarantee uniqueness of keys, instead of returning a std::vector and having to manually check for duplicates.

comment:16 by philip, 12 years ago

Owner: set to philip
Resolution: fixed
Status: newclosed

In 11535:

Fix #953 (local.cfg adds keys instead of replacing them)

comment:17 by sanderd17, 8 years ago

Keywords: review removed
Note: See TracTickets for help on using tickets.