fix civilopedia category bug. (#8084)

* fix civilopedia category bug.

* fix negative index.
This commit is contained in:
nacro711072 2022-12-05 00:04:16 +08:00 committed by GitHub
parent cfedaeb0e3
commit 220c465a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) }