From 220c465a18705e6b1b29627522b7f524efc4121d Mon Sep 17 00:00:00 2001 From: nacro711072 Date: Mon, 5 Dec 2022 00:04:16 +0800 Subject: [PATCH] fix civilopedia category bug. (#8084) * fix civilopedia category bug. * fix negative index. --- .../unciv/ui/civilopedia/CivilopediaScreen.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt index c81ab91b89..fd2db4d00b 100644 --- a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt +++ b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt @@ -291,11 +291,26 @@ class CivilopediaScreen( else selectEntry(link, noScrollAnimation = true) - for (categoryKey in CivilopediaCategories.values()) { + for (categoryKey in categoryToEntries.keys) { globalShortcuts.add(categoryKey.key) { navigateCategories(categoryKey.key) } } - globalShortcuts.add(Input.Keys.LEFT) { selectCategory(currentCategory.getByOffset(-1)) } - globalShortcuts.add(Input.Keys.RIGHT) { selectCategory(currentCategory.getByOffset(1)) } + globalShortcuts.add(Input.Keys.LEFT) { + val categoryKey = categoryToEntries.keys + val currentIndex = categoryKey.indexOf(currentCategory) + val targetCategory = categoryKey.elementAt( + (currentIndex + categoryKey.size - 1) % categoryKey.size + ) + selectCategory(targetCategory) + } + globalShortcuts.add(Input.Keys.RIGHT) { + val categoryKey = categoryToEntries.keys + val currentIndex = categoryKey.indexOf(currentCategory) + val targetCategory = categoryKey.elementAt( + (currentIndex + categoryKey.size + 1) % categoryKey.size + ) + selectCategory(targetCategory) + + } globalShortcuts.add(Input.Keys.UP) { navigateEntries(-1) } globalShortcuts.add(Input.Keys.DOWN) { navigateEntries(1) } globalShortcuts.add(Input.Keys.PAGE_UP) { navigateEntries(-10) }