Some visual improvements for the Mod Manager Screen (#3841)

This commit is contained in:
SomeTroglodyte
2021-04-27 11:06:05 +02:00
committed by GitHub
parent 8dc748f919
commit 3da02b18b6

View File

@ -1,10 +1,13 @@
package com.unciv.ui.pickerscreens package com.unciv.ui.pickerscreens
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextArea import com.badlogic.gdx.scenes.scene2d.ui.TextArea
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.utils.Align
import com.badlogic.gdx.utils.Json import com.badlogic.gdx.utils.Json
import com.unciv.JsonParser import com.unciv.JsonParser
import com.unciv.MainMenuScreen import com.unciv.MainMenuScreen
@ -16,9 +19,8 @@ import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.mainmenu.Github import com.unciv.ui.worldscreen.mainmenu.Github
import java.text.DateFormat import java.text.DateFormat
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.* import java.util.*
import kotlin.collections.HashMap
import kotlin.concurrent.thread import kotlin.concurrent.thread
class ModManagementScreen: PickerScreen() { class ModManagementScreen: PickerScreen() {
@ -29,11 +31,15 @@ class ModManagementScreen: PickerScreen() {
val amountPerPage = 30 val amountPerPage = 30
var lastSelectedButton: TextButton? = null
val modDescriptions: HashMap<String, String> = hashMapOf()
init { init {
setDefaultCloseAction(MainMenuScreen()) setDefaultCloseAction(MainMenuScreen())
refreshModTable() refreshModTable()
topTable.add("Current mods".toLabel()) topTable.add("Current mods".toLabel()).padRight(35f)
// 35 = 10 default pad + 25 to compensate for permanent visual mod decoration icon
topTable.add("Downloadable mods".toLabel()) topTable.add("Downloadable mods".toLabel())
// topTable.add("Mod actions") // topTable.add("Mod actions")
topTable.row() topTable.row()
@ -65,6 +71,12 @@ class ModManagementScreen: PickerScreen() {
Gdx.app.postRunnable { Gdx.app.postRunnable {
for (repo in repoSearch.items) { for (repo in repoSearch.items) {
repo.name = repo.name.replace('-', ' ') repo.name = repo.name.replace('-', ' ')
modDescriptions[repo.name] = repo.description + "\n" + "[${repo.stargazers_count}]✯".tr() +
if (modDescriptions.contains(repo.name))
"\n" + modDescriptions[repo.name]
else ""
var downloadButtonText = repo.name var downloadButtonText = repo.name
val existingMod = RulesetCache.values.firstOrNull { it.name == repo.name } val existingMod = RulesetCache.values.firstOrNull { it.name == repo.name }
@ -76,7 +88,10 @@ class ModManagementScreen: PickerScreen() {
val downloadButton = downloadButtonText.toTextButton() val downloadButton = downloadButtonText.toTextButton()
downloadButton.onClick { downloadButton.onClick {
descriptionLabel.setText(repo.description + "\n" + "[${repo.stargazers_count}]✯".tr()) lastSelectedButton?.color = Color.WHITE
downloadButton.color = Color.BLUE
lastSelectedButton = downloadButton
descriptionLabel.setText(modDescriptions[repo.name])
removeRightSideClickListeners() removeRightSideClickListeners()
rightSideButton.enable() rightSideButton.enable()
rightSideButton.setText("Download [${repo.name}]".tr()) rightSideButton.setText("Download [${repo.name}]".tr())
@ -172,22 +187,26 @@ class ModManagementScreen: PickerScreen() {
} }
} }
fun refreshModActions(mod: Ruleset) { fun refreshModActions(mod: Ruleset, decorationImage: Actor) {
modActionTable.clear() modActionTable.clear()
val visualMods = game.settings.visualMods val visualMods = game.settings.visualMods
if (!visualMods.contains(mod.name)) if (!visualMods.contains(mod.name)) {
decorationImage.isVisible = false
modActionTable.add("Enable as permanent visual mod".toTextButton().onClick { modActionTable.add("Enable as permanent visual mod".toTextButton().onClick {
visualMods.add(mod.name) visualMods.add(mod.name)
game.settings.save() game.settings.save()
ImageGetter.setNewRuleset(ImageGetter.ruleset) ImageGetter.setNewRuleset(ImageGetter.ruleset)
refreshModActions(mod) refreshModActions(mod, decorationImage)
}) })
else modActionTable.add("Disable as permanent visual mod".toTextButton().onClick { } else {
visualMods.remove(mod.name) decorationImage.isVisible = true
game.settings.save() modActionTable.add("Disable as permanent visual mod".toTextButton().onClick {
ImageGetter.setNewRuleset(ImageGetter.ruleset) visualMods.remove(mod.name)
refreshModActions(mod) game.settings.save()
}) ImageGetter.setNewRuleset(ImageGetter.ruleset)
refreshModActions(mod, decorationImage)
})
}
modActionTable.row() modActionTable.row()
addModInfoToActionTable(mod.modOptions.modUrl, mod.modOptions.lastUpdated) addModInfoToActionTable(mod.modOptions.modUrl, mod.modOptions.lastUpdated)
@ -197,18 +216,30 @@ class ModManagementScreen: PickerScreen() {
modTable.clear() modTable.clear()
val currentMods = RulesetCache.values.filter { it.name != "" } val currentMods = RulesetCache.values.filter { it.name != "" }
for (mod in currentMods) { for (mod in currentMods) {
val button = mod.name.toTextButton().onClick { val summary = mod.getSummary()
refreshModActions(mod) modDescriptions[mod.name] = "Installed".tr() +
(if (summary.isEmpty()) "" else ": $summary")
val decorationImage = ImageGetter.getPromotionIcon("Scouting", 25f)
val button = mod.name.toTextButton()
button.onClick {
lastSelectedButton?.color = Color.WHITE
button.color = Color.BLUE
lastSelectedButton = button
refreshModActions(mod, decorationImage)
rightSideButton.setText("Delete [${mod.name}]".tr()) rightSideButton.setText("Delete [${mod.name}]".tr())
rightSideButton.enable() rightSideButton.enable()
descriptionLabel.setText(mod.getSummary()) descriptionLabel.setText(modDescriptions[mod.name])
removeRightSideClickListeners() removeRightSideClickListeners()
rightSideButton.onClick { rightSideButton.onClick {
YesNoPopup("Are you SURE you want to delete this mod?", YesNoPopup("Are you SURE you want to delete this mod?",
{ deleteMod(mod) }, this).open() { deleteMod(mod) }, this).open()
} }
} }
modTable.add(button).row() val decoratedButton = Table()
decoratedButton.add(button)
decorationImage.isVisible = game.settings.visualMods.contains(mod.name)
decoratedButton.add(decorationImage).align(Align.topLeft)
modTable.add(decoratedButton).row()
} }
} }
@ -219,4 +250,4 @@ class ModManagementScreen: PickerScreen() {
RulesetCache.loadRulesets() RulesetCache.loadRulesets()
refreshModTable() refreshModTable()
} }
} }