From d0b43599d90e2f535d316d2e4b8d3a9b9deca2b0 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sun, 29 Jun 2025 11:00:47 -0400 Subject: [PATCH] Fix mod names with dashes in them (#13523) * Fix mod names with three dashes * Fix display of mods with three dashes in the name * Remove unneeded Ruleset call --- .../ui/screens/modmanager/ModManagementScreen.kt | 12 +++++++----- .../src/com/unciv/ui/screens/modmanager/ModUIData.kt | 5 +++-- .../ui/screens/newgamescreen/ModCheckboxTable.kt | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/src/com/unciv/ui/screens/modmanager/ModManagementScreen.kt b/core/src/com/unciv/ui/screens/modmanager/ModManagementScreen.kt index 77d0e77f20..18c1a15b29 100644 --- a/core/src/com/unciv/ui/screens/modmanager/ModManagementScreen.kt +++ b/core/src/com/unciv/ui/screens/modmanager/ModManagementScreen.kt @@ -74,6 +74,8 @@ class ModManagementScreen private constructor( const val maxAllowedPreviewImageSize = 200f /** Github queries use this limit */ const val amountPerPage = 100 + + fun cleanModName(modName: String): String = modName.replace(" ", " - ") } // Since we're `RecreateOnResize`, preserve the portrait/landscape mode for our lifetime @@ -466,8 +468,8 @@ class ModManagementScreen private constructor( rightSideButton.isVisible = true rightSideButton.enable() - val label = if (installedModInfo[repo.name]?.hasUpdate == true) "Update [${repo.name}]" - else "Download [${repo.name}]" + val label = if (installedModInfo[repo.name]?.hasUpdate == true) "Update [${cleanModName(repo.name)}]" + else "Download [${cleanModName(repo.name)}]" rightSideButton.setText(label.tr()) rightSideButton.clearActivationActions(ActivationTypes.Tap) rightSideButton.onClick { @@ -556,7 +558,7 @@ class ModManagementScreen private constructor( } onlineModInfo[name]?.run { hasUpdate = false - modButtons[this]?.setText(name) + modButtons[this]?.setText(cleanModName(name)) } if (optionsManager.sortInstalled == SortType.Status) refreshInstalledModTable() @@ -636,7 +638,7 @@ class ModManagementScreen private constructor( syncInstalledSelected(mod.name, button) refreshInstalledModActions(mod.ruleset!!) - val deleteText = "Delete [${mod.name}]" + val deleteText = "Delete [${cleanModName(mod.name)}]" rightSideButton.setText(deleteText.tr()) // Don't let the player think he can delete Vanilla and G&K rulesets rightSideButton.isEnabled = mod.ruleset.folderLocation!=null @@ -652,7 +654,7 @@ class ModManagementScreen private constructor( ) { deleteMod(mod.ruleset) modActionTable.clear() - rightSideButton.setText("[${mod.name}] was deleted.".tr()) + rightSideButton.setText("[${cleanModName(mod.name)}] was deleted.".tr()) }.open() } } diff --git a/core/src/com/unciv/ui/screens/modmanager/ModUIData.kt b/core/src/com/unciv/ui/screens/modmanager/ModUIData.kt index 7e320be777..ce44e3fa14 100644 --- a/core/src/com/unciv/ui/screens/modmanager/ModUIData.kt +++ b/core/src/com/unciv/ui/screens/modmanager/ModUIData.kt @@ -5,6 +5,7 @@ import com.unciv.models.metadata.ModCategories import com.unciv.models.ruleset.Ruleset import com.unciv.models.translations.tr import com.unciv.ui.components.fonts.Fonts +import com.unciv.ui.screens.modmanager.ModManagementScreen /** Helper class holds combined mod info for ModManagementScreen, used for both installed and online lists. * @@ -44,8 +45,8 @@ class ModUIData private constructor( fun author() = ruleset?.modOptions?.author ?: repo?.owner?.login ?: "" fun topics() = ruleset?.modOptions?.topics ?: repo?.topics ?: emptyList() fun buttonText() = when { - ruleset != null -> ruleset.name - repo != null -> repo.name + (if (hasUpdate) " - {Updated}" else "") + ruleset != null -> ModManagementScreen.cleanModName(ruleset.name) + repo != null -> ModManagementScreen.cleanModName(repo.name) + (if (hasUpdate) " - {Updated}" else "") else -> "" } diff --git a/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt b/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt index 92a545cae1..4faa03d71d 100644 --- a/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt +++ b/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt @@ -12,6 +12,7 @@ import com.unciv.ui.components.extensions.toCheckBox import com.unciv.ui.components.input.onChange import com.unciv.ui.components.widgets.ExpanderTab import com.unciv.ui.components.widgets.UncivTextField +import com.unciv.ui.screens.modmanager.ModManagementScreen import com.unciv.ui.popups.ToastPopup import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.utils.Concurrency @@ -57,6 +58,7 @@ class ModCheckboxTable( for (mod in modRulesets.sortedBy { it.name }) { val checkBox = mod.name.toCheckBox(mod.name in mods) + checkBox.setText(ModManagementScreen.cleanModName(mod.name)) checkBox.onChange { // Checks are run in parallel thread to avoid ANRs Concurrency.run { checkBoxChanged(checkBox, mod) }