mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Options checks mods gradually and has expander tabs (#6099)
* Change options mod checking to check each mod individually, part 1 - change cell to table * Mod checker now posts each mod separately by posting a new runnable each time one has completed * Each mod now has its own expandertab so you don't need to scroll endlessly if you have a lot of mods * Only enable 'check against vanilla' mod checkbox after all mods have been checked
This commit is contained in:
parent
37c0092284
commit
89958e27ff
@ -4,7 +4,6 @@ import com.badlogic.gdx.Application
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.Input
|
import com.badlogic.gdx.Input
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.*
|
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
@ -27,7 +26,6 @@ import com.unciv.ui.utils.LanguageTable.Companion.addLanguageTables
|
|||||||
import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
|
import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
|
||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.thread
|
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
import com.badlogic.gdx.utils.Array as GdxArray
|
import com.badlogic.gdx.utils.Array as GdxArray
|
||||||
|
|
||||||
@ -42,7 +40,7 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
|||||||
private val resolutionArray = com.badlogic.gdx.utils.Array(arrayOf("750x500", "900x600", "1050x700", "1200x800", "1500x1000"))
|
private val resolutionArray = com.badlogic.gdx.utils.Array(arrayOf("750x500", "900x600", "1050x700", "1200x800", "1500x1000"))
|
||||||
private var modCheckFirstRun = true // marker for automatic first run on selecting the page
|
private var modCheckFirstRun = true // marker for automatic first run on selecting the page
|
||||||
private var modCheckCheckBox: CheckBox? = null
|
private var modCheckCheckBox: CheckBox? = null
|
||||||
private var modCheckResultCell: Cell<Actor>? = null
|
private var modCheckResultTable = Table()
|
||||||
private val selectBoxMinWidth: Float
|
private val selectBoxMinWidth: Float
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@ -265,20 +263,20 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
|||||||
runModChecker(it)
|
runModChecker(it)
|
||||||
}
|
}
|
||||||
add(modCheckCheckBox).row()
|
add(modCheckCheckBox).row()
|
||||||
modCheckResultCell = add("Checking mods for errors...".toLabel())
|
|
||||||
|
modCheckResultTable.add("Checking mods for errors...".toLabel()).row()
|
||||||
|
add(modCheckResultTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runModChecker(complex: Boolean = false) {
|
private fun runModChecker(complex: Boolean = false) {
|
||||||
modCheckFirstRun = false
|
modCheckFirstRun = false
|
||||||
if (modCheckCheckBox == null) return
|
if (modCheckCheckBox == null) return
|
||||||
modCheckCheckBox!!.disable()
|
modCheckCheckBox!!.disable()
|
||||||
if (modCheckResultCell == null) return
|
|
||||||
crashHandlingThread(name="ModChecker") {
|
crashHandlingThread(name="ModChecker") {
|
||||||
val lines = ArrayList<FormattedLine>()
|
|
||||||
var noProblem = true
|
|
||||||
for (mod in RulesetCache.values.sortedBy { it.name }) {
|
for (mod in RulesetCache.values.sortedBy { it.name }) {
|
||||||
// Appending {} is a dirty trick to deactivate the automatic translation which would drop [] from unique messages
|
var noProblem = true
|
||||||
lines += FormattedLine("$mod", starred = true, header = 3)
|
val lines = ArrayList<FormattedLine>()
|
||||||
|
|
||||||
val modLinks =
|
val modLinks =
|
||||||
if (complex) RulesetCache.checkCombinedModLinks(linkedSetOf(mod.name))
|
if (complex) RulesetCache.checkCombinedModLinks(linkedSetOf(mod.name))
|
||||||
@ -294,26 +292,38 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
|
|||||||
}
|
}
|
||||||
if (modLinks.isNotOK()) noProblem = false
|
if (modLinks.isNotOK()) noProblem = false
|
||||||
lines += FormattedLine()
|
lines += FormattedLine()
|
||||||
}
|
if (noProblem) lines += FormattedLine("No problems found.".tr())
|
||||||
if (noProblem) lines += FormattedLine("No problems found.".tr())
|
|
||||||
|
|
||||||
postCrashHandlingRunnable {
|
postCrashHandlingRunnable {
|
||||||
// When the options popup is already closed before this postRunnable is run,
|
// When the options popup is already closed before this postRunnable is run,
|
||||||
// Don't add the labels, as otherwise the game will crash
|
// Don't add the labels, as otherwise the game will crash
|
||||||
if (stage == null) return@postCrashHandlingRunnable
|
if (stage == null) return@postCrashHandlingRunnable
|
||||||
// Don't just render text, since that will make all the conditionals in the mod replacement messages move to the end, which makes it unreadable
|
// Don't just render text, since that will make all the conditionals in the mod replacement messages move to the end, which makes it unreadable
|
||||||
// Don't use .toLabel() either, since that activates translations as well, which is what we're trying to avoid,
|
// Don't use .toLabel() either, since that activates translations as well, which is what we're trying to avoid,
|
||||||
// Instead, some manual work needs to be put in.
|
// Instead, some manual work needs to be put in.
|
||||||
val resultTable = Table().apply { defaults().align(Align.left) }
|
|
||||||
for (line in lines) {
|
val expanderTab = ExpanderTab(mod.name, startsOutOpened = false){
|
||||||
val label = if (line.starred) Label(line.text+"\n", BaseScreen.skin)
|
it.defaults().align(Align.left)
|
||||||
.apply { setFontScale(22 / Fonts.ORIGINAL_FONT_SIZE) }
|
for (line in lines) {
|
||||||
else Label(line.text+"\n", BaseScreen.skin)
|
val label = if (line.starred) Label(line.text + "\n", BaseScreen.skin)
|
||||||
.apply { if (line.color != "") color = Color.valueOf(line.color) }
|
.apply { setFontScale(22 / Fonts.ORIGINAL_FONT_SIZE) }
|
||||||
label.wrap = true
|
else Label(line.text + "\n", BaseScreen.skin)
|
||||||
resultTable.add(label).width(stage.width/2).row()
|
.apply { if (line.color != "") color = Color.valueOf(line.color) }
|
||||||
|
label.wrap = true
|
||||||
|
it.add(label).width(stage.width / 2).row()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val loadingLabel = modCheckResultTable.children.last()
|
||||||
|
modCheckResultTable.removeActor(loadingLabel)
|
||||||
|
modCheckResultTable.add(expanderTab).row()
|
||||||
|
modCheckResultTable.add(loadingLabel).row()
|
||||||
}
|
}
|
||||||
modCheckResultCell?.setActor(resultTable)
|
}
|
||||||
|
|
||||||
|
// done with all mods!
|
||||||
|
postCrashHandlingRunnable {
|
||||||
|
modCheckResultTable.removeActor(modCheckResultTable.children.last())
|
||||||
modCheckCheckBox!!.enable()
|
modCheckCheckBox!!.enable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user