From 10caf8e93e466d631352f9e66f62a54cb36aa41a Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Sun, 12 Mar 2023 21:45:06 +0100 Subject: [PATCH] Key bindings Step 2 (#8872) * Configurable key bindings - Enable via Hidden debug-option * Configurable key bindings - better Help * Configurable key bindings - better Widget step 1 --- android/assets/jsons/Tutorials.json | 24 ++- .../com/unciv/ui/components/TabbedPager.kt | 9 +- .../com/unciv/ui/components/UncivTextField.kt | 4 +- .../com/unciv/ui/popups/options/DebugTab.kt | 12 +- .../unciv/ui/popups/options/KeyBindingsTab.kt | 141 +++++++++++++++++- .../unciv/ui/popups/options/OptionsPopup.kt | 42 ++++-- 6 files changed, 210 insertions(+), 22 deletions(-) diff --git a/android/assets/jsons/Tutorials.json b/android/assets/jsons/Tutorials.json index 824f015d58..e6a9beecde 100644 --- a/android/assets/jsons/Tutorials.json +++ b/android/assets/jsons/Tutorials.json @@ -390,5 +390,27 @@ "steps": [ "One of your cities is under a naval blockade! When all adjacent water tiles of a coastal city are blocked - city loses harbor connection to all other cities, including capital. Make sure to de-blockade cities by deploying friendly military naval units to fight off invaders." ] - } + }, + { + "name": "Keyboard Bindings", + "civilopediaText": [ + {"text":"Limitations","header":3}, + {"text":"This is a work in progress.","color":"#b22222","starred":true}, + {"text":"For technical reasons, only direct keys or Ctrl-Letter combinations can be used.","starred":true}, + {"text":"The Escape key is intentionally excluded from being reassigned.","starred":true}, + {"text":"Currently, there are no checks to prevent conflicting assignments.","starred":true}, + {}, + {"text":"Using the Keys page","header":3}, + {"text":"Each binding has a label, a text field, and a key button looking like this:"}, + {"extraImage":"OtherIcons/Keyboard","imageSize":36}, + {"text":"While hovering the mouse over the key button, you can press a desired key directly to assign it."}, + {"text":"Alternatively, you can enter the key's name in the text field."}, + {"text":"To reset a binding to its default, simply clear the text field."}, + {}, + {"text":"Bindings mapped to their default keys are displayed in gray, those reassigned by you in white."}, + {}, + {"text":"For discussion about missing entries, see the linked github issue.","link":"https://github.com/yairm210/Unciv/issues/8862"} + ], + // "uniques": ["Will not be displayed in Civilopedia"] // would prevent use for help link + } ] diff --git a/core/src/com/unciv/ui/components/TabbedPager.kt b/core/src/com/unciv/ui/components/TabbedPager.kt index 95dfd04ec2..9a107a990b 100644 --- a/core/src/com/unciv/ui/components/TabbedPager.kt +++ b/core/src/com/unciv/ui/components/TabbedPager.kt @@ -621,7 +621,14 @@ open class TabbedPager( if (insertBefore >= 0 && insertBefore < pages.size) { newIndex = insertBefore pages.add(insertBefore, page) - header.addActorAt(insertBefore, page.button) + // Table.addActorAt breaks the Table, it's a Group method that updates children but not cells + // So we add an empty cell and move cell actors around + header.add() + for (i in header.cells.size - 1 downTo insertBefore + 1) { + val actor = header.removeActorAt(i - 1, true) as Button + header.cells[i].setActor