yairm210 / Unciv

Open-source Android/Desktop remake of Civ V
Mozilla Public License 2.0
8.39k stars 1.56k forks source link

Configurable key bindings - Requests and Discussion #8862

Open SomeTroglodyte opened 1 year ago

SomeTroglodyte commented 1 year ago

Context

Unciv may get configurable keyboard key bindings in the near future (PR #8802). Since there are many functions that may be candidates for such a binding, implementing them all is a work in progress and might take a long time. Please bundle any and all requests / comments / criticism on that feature here in this issue.

Goal

Maintain and prioritize a list of desired functions to get a configurable key binding. Possibly discover usages we might otherwise miss.

Status

Framework stuff

List of Contexts / Bindings

Gualdimar commented 1 year ago

I just tried the button assignment tab in the settings. It looks a bit complicated😵 In terms of user-friendly experience (all these drop-downs, along with hovering). The drop-down lists contain characters from gamepads and shift+key characters (although you can't assign them via hover)

Didn't you think of something more common and simple? For example, just a non-editible text field, which indicates the current binding. When a user clicks on the field, it is highlighted in a different color, and then: either the user clicks ESC and the binding does not change or the user presses some button and it is binded to the corresponding action.

Gualdimar commented 1 year ago

And here is a list of standard assignments.

World screen: WASD/Arrows - Scroll map on the world screen PageUp - Hide more unit actions PageDown - Show more unit actions Del - Disabnd unit Tab - Move here/Swap unit Z - Wait LShift - Select multiple units(I didn't know it was possible😲) Space or N - Next unit or turn E - Empire overview (last viewed page) + - Zoom in - - Zoom out Home - center on capital or open its city screen if already centered F1 - Open Civilopedia F2 - Empire overview Trades F3 - Empire overview Units F4 - Empire overview Diplomacy F5 - Social policies F6 - Technologies F7 - Empire overview Cities F8 - Victory Progress F9 - Empire overview Stats F10 - Empire overview Resources F11 - Quicksave F12 - Quickload Ctrl-R - Toggle tile resource display Ctrl-Y - Toggle tile yield display Ctrl-O - Game options Ctrl-S - Save game Ctrl-L - Load game Ctrl-U - Toggle UI

City screen: Left,Right - On the city screen change selected city B - Buy selected construction T - Buy selected tile

Map editor: Up/Down - Move selection in the map editor(did not find out what it means) Ctrl+I - View tab Ctrl+N - Generate tab Ctrl+G - Generate partial tab Ctrl+E - Edit tab:  1-5 - Brush size  Ctrl+F - Brush floodfill  T - Terrain  F - Features  W - Wonders  R - Resources  I - Improvements  V - Rivers  S - Starting locations Ctrl+L - Load tab Ctrl+S - Save tab Ctrl+D - Mods tab Ctrl+O - Options tab:  Ctrl+C - Copy map  Ctrl+V - Paste map

Options: LShift, RShift - Something with the sliders, I don't know what; UncivSlider.kt line 202 F12 - Generate translations in the Options, Advanced tab

File list(e.g. save file list): Up/Down - Change selected entry PageUp/PageDown - Scroll the entry list Home/End - Go to the start/end of the entry list

Save/Load screen: Ctrl+C - Copy save Ctrl+V - Paste save Ctrl+A - Show autosaves

Civilopedia controls: Left/Right - Change tabs Up/Down - Change selected entry PageUp/PageDown - Scroll the entry list Home/End - Go to the start/end of the entry list

Popups: Space or Enter - Confirm popup

Conquered city popup: A - Annex D - Destroy L - Liberate P - Puppet R - Raze

SomeTroglodyte commented 1 year ago

just tried

Thank you!

characters from gamepads

Yup, that's a problem I didn't want to hardcode and am waiting for Eureka. That's the almost complete list from Input.java - how can one guess what some people may actually have on their gaming keyboards and what's completely esoteric? I don't have an F24, but you can buy them... Another json listing allowed codes? Nah. waiting for better idea.

non-editible text field

Hmmm... History and geriatric unflexibility? First I had a plain TextFíeld and parsed the string. Then I did the SelectBox, then I tried building that KeyCapturingButton as Add-on - I thought that would be increasing complexity, but that hover-capture thing was surprisingly simple. Since all that is relatively encapsulated, no biggie to change.

drop-down lists contain shift+key characters

You still misunderstand. That's keycodes, no correlation to shift or alt. Physical keys as they would look on an Imperial (sorry, en-US) layout. Virtual keys. Those characters don't really represent ASCII at that point but the picture on the yankee keyboard - and there all of them are unshifted. They're abstract labels just to recognize a piece of hardware. That's why I tried to translate those. Or think of it like this - take sandpaper and remove all print on your keyboard. It still works, every key will deliver a unique Integer. Paint arbitrary names on them and associate those with the Integers - the system works, keys can be recognized reliably - no text semantics needed. Interpretation into the "character" as in linguistings realm comes much later, and there starts the cultural differences not before. And Gdx doesn't do "culturally interpreted" as per OS keyboard settings at all with just one Exception I know of - TextField... Exception Ctrl-*, the Ctrl up/down is tracked manually in my code, Gdx doesn't help there - much. There's isKeyPressed but if you have the listener anyway it's faster to track oneself..... Yup, and lastly an ASCII Ctrl-character generated from the virtual key name which is why they're still swapped on qwertz or azerty.

list of

Nice. I had forgotten a couple of them, but in turn I remember one or two you missed (City buy construction B buy tile T,...). I'll collate, but not today.

Gualdimar commented 1 year ago

Another json listing allowed codes? Nah. waiting for better idea.

That's why I suggest to abandon the drop-down lists in favor of a text field (which will display only keys that the user can actually press), or a button, or something else that can display text and be highlighted when you click on it.

Since all that is relatively encapsulated, no biggie to change.

I'm not speaking from the point of view of a coder or the complexity of the code. I'm sharing my impressions of using the interface, based on my experience and habits gained in other games.

Physical keys as they would look on an Imperial (sorry, en-US) layout. Virtual keys.

There are keyboards with separate buttons for @,# and : ? Hm...🤔

one or two you missed

My list based on the results of the Input.Keys.* search, I haven't seen the ones you mentioned.

I don't have an F24, but you can buy them...

I googled, and there are only dinosaurs there...🦖

And on the latest version, an exception when opening Options:

``` java.lang.ExceptionInInitializerError at com.unciv.ui.popups.options.KeyBindingsTab$KeyboardBindingWidget.(KeyBindingsTab.kt:74) at com.unciv.ui.popups.options.KeyBindingsTab.(KeyBindingsTab.kt:42) at com.unciv.ui.popups.options.OptionsPopup.showOrHideKeyBindings$core(OptionsPopup.kt:193) at com.unciv.ui.popups.options.OptionsPopup.(OptionsPopup.kt:125) at com.unciv.ui.screens.basescreen.BaseScreen.openOptionsPopup(BaseScreen.kt:166) at com.unciv.ui.screens.basescreen.BaseScreen.openOptionsPopup$default(BaseScreen.kt:165) at com.unciv.ui.screens.mainmenuscreen.MainMenuScreen$optionsTable$1.invoke(MainMenuScreen.kt:187) at com.unciv.ui.screens.mainmenuscreen.MainMenuScreen$optionsTable$1.invoke(MainMenuScreen.kt:186) at com.unciv.ui.components.extensions.Scene2dExtensionsKt$onActivation$1.invoke(Scene2dExtensions.kt:190) at com.unciv.ui.components.extensions.Scene2dExtensionsKt$onActivation$1.invoke(Scene2dExtensions.kt:188) at com.unciv.ui.components.extensions.ActorAttachments.activate(Scene2dExtensions.kt:136) at com.unciv.ui.components.extensions.Scene2dExtensionsKt.activate(Scene2dExtensions.kt:179) at com.unciv.ui.components.extensions.ActorAttachments$addActivationAction$2.clicked(Scene2dExtensions.kt:147) at com.badlogic.gdx.scenes.scene2d.utils.ClickListener.touchUp(ClickListener.java:88) at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:71) at com.badlogic.gdx.scenes.scene2d.Stage.touchUp(Stage.java:355) at com.unciv.ui.screens.basescreen.UncivStage.access$touchUp$s80204510(UncivStage.kt:18) at com.unciv.ui.screens.basescreen.UncivStage$touchUp$1.invoke(UncivStage.kt:90) at com.unciv.ui.screens.basescreen.UncivStage$touchUp$1.invoke(UncivStage.kt:90) at com.unciv.ui.crashhandling.CrashHandlingExtensionsKt$wrapCrashHandling$1.invoke(CrashHandlingExtensions.kt:17) at com.unciv.ui.screens.basescreen.UncivStage.touchUp(UncivStage.kt:90) at com.badlogic.gdx.InputEventQueue.drain(InputEventQueue.java:70) at com.badlogic.gdx.backends.lwjgl3.DefaultLwjgl3Input.update(DefaultLwjgl3Input.java:189) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:378) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:192) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.(Lwjgl3Application.java:166) at com.unciv.app.desktop.DesktopLauncher.main(DesktopLauncher.kt:76) Caused by: java.lang.NullPointerException: toString(keyCode) must not be null at com.unciv.ui.components.extensions.GdxKeyCodeFixes.toString(Scene2dExtensions.kt:578) at com.unciv.ui.components.KeysSelectBox.(KeysSelectBox.kt:49) ... 27 more ```
SomeTroglodyte commented 1 year ago

abandon the drop-down

Seen that way pretty obviousy a Good Thing (tm)

exception when opening Options

I know that one, but I never PR'ed that version or did I? At least the fix isn't pushed anywhere yet. Was an interesting and after all obvious lesson.

Input.Keys.* search

Then someday I'll do "Find Usages" on KeyCharAndCode.constructor(char: Char) and KeyCharAndCode.ctrl(Char), that should find most of the rest. Or trace all of the KeyShortcutDispatcher.add calls

SomeTroglodyte commented 1 year ago

Ctrl-R - Toggle tile resource display Ctrl-Y - Toggle tile yield display

Did you find them in code? I missed them and searched in vain - if they're on the actor itself, then the current next PR is in error.

Gualdimar commented 1 year ago

Did you find them in code? I missed them and searched in vain - if they're on the actor itself, then the current next PR is in error.

Nah, this was taken from civiloledia. I checked in version 4.4.9 these combinations do not work, so I was tricked...

SomeTroglodyte commented 1 year ago

Strange history - I introduce those two keys in 3875, two hours later Yair removes them, and back then it seems I understood why...

Gualdimar commented 1 year ago

Yair removes them

he deleted everything related to the buttons on the minimap in dbc3bcb5a1c956ce0e5dccc2c255562dad411d35, moreover, you thanked him😀 image

SomeTroglodyte commented 1 year ago

..moreover.. yup that's what I said, but I can't be too obvious now can I? I think the thanks was due to me being mortified I had forgotten to run unit tests locally before pushing.

SomeTroglodyte commented 1 year ago

I need to test something... Hello @SomeTroglodyte

saud2410 commented 7 months ago

Can you include Esc key and game shutdown popup keybind? On 4.10.11 win64, Esc cannot be assigned for other keybind. And there is no "Game shutdown" entry on settings - key. I want to use Esc for main menu key on world screen.

SomeTroglodyte commented 7 months ago

Esc cannot be assigned for other keybind.

Yes, intentional. The tutorial should even say so. Correlated with the key being made 1:1 equivalent with Android's "back" button. There's just so many hardcoded places (20 uses), and having that one constant really makes things easier.

And the game shutdown popup is treated as a generic popup, so its yes/no are bindable together with all other such popups. Could be made a separate entry, yes - but without the first one not much sense, right?

saud2410 commented 7 months ago

Wow i've never noticed Android back button shows shutdown popup!.. But if it's hardcoded, i should make a new issue. Why should we see shutdown popup in world screen directly? I've never seen this behavior except Unciv. It's so strange.

SomeTroglodyte commented 7 months ago

I've grown used to it...

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 15 days.

SeventhM commented 4 months ago

Since you're probably getting a notification anyways, might as well ping. @SomeTroglodyte if this is done or something you can close this. Give the more generic nature of this as key bindings discussion, I'll give it a label