mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-24 10:01:39 +07:00
Do not preselect custom map option and defer map file loading (#11485)
This commit is contained in:
parent
c75861af25
commit
a1474fb13c
@ -76,7 +76,10 @@ class MapFileSelectTable(
|
||||
|
||||
private val collator = UncivGame.Current.settings.getCollatorFromLocale()
|
||||
|
||||
private var isActivated = false // Ensure we get activated only once
|
||||
|
||||
init {
|
||||
// Take care that this class can be instantiated cheaply and does not do heavy lifting right away - it may not be displayed at all.
|
||||
add(Table().apply {
|
||||
defaults().pad(5f, 10f) // Must stay same as in MapParametersTable
|
||||
val mapCategoryLabel = "{Map Mod}:".toLabel()
|
||||
@ -103,11 +106,8 @@ class MapFileSelectTable(
|
||||
.maxWidth(columnWidth - 20f)
|
||||
.colspan(2).center().row()
|
||||
|
||||
mapCategorySelectBox.onChange { onCategorySelectBoxChange() }
|
||||
mapFileSelectBox.onChange { onFileSelectBoxChange() }
|
||||
useNationsFromMapButton.onActivation { onUseNationsFromMap() }
|
||||
|
||||
addMapWrappersAsync()
|
||||
}
|
||||
|
||||
private fun getMapFilesSequence() = sequence<FileHandle> {
|
||||
@ -186,12 +186,19 @@ class MapFileSelectTable(
|
||||
|
||||
private fun FileHandle.isRecentlyModified() = lastModified() > System.currentTimeMillis() - 900000 // 900s = quarter hour
|
||||
fun isNotEmpty() = firstMap != null
|
||||
fun recentlySavedMapExists() = firstMap != null && firstMap!!.isRecentlyModified()
|
||||
|
||||
fun activateCustomMaps() {
|
||||
if (loadingIcon.isShowing()) return // Default map selection will be handled when background loading finishes
|
||||
if (isActivated) {
|
||||
if (loadingIcon.isShowing()) return // Default map selection will be handled when background loading finishes
|
||||
onCategorySelectBoxChange() // Coming back to this after fully loading make sure selections are OK
|
||||
}
|
||||
// Code to only run once per NewGameScreen lifetime, after user switches from
|
||||
// generated map to custom map, no matter how many times they repeat that
|
||||
isActivated = true
|
||||
preselectedName = mapParameters.name
|
||||
onFileSelectBoxChange()
|
||||
mapCategorySelectBox.onChange { onCategorySelectBoxChange() }
|
||||
mapFileSelectBox.onChange { onFileSelectBoxChange() }
|
||||
addMapWrappersAsync()
|
||||
}
|
||||
|
||||
private fun onCategorySelectBoxChange() {
|
||||
|
@ -24,13 +24,7 @@ class MapOptionsTable(private val newGameScreen: NewGameScreen, isReset: Boolean
|
||||
val mapTypes = arrayListOf(MapGeneratedMainType.generated, MapGeneratedMainType.randomGenerated)
|
||||
if (savedMapOptionsTable.isNotEmpty()) mapTypes.add(MapGeneratedMainType.custom)
|
||||
|
||||
// Pre-select custom if any map saved within last 15 minutes
|
||||
val chooseCustom = !isReset && (
|
||||
savedMapOptionsTable.recentlySavedMapExists() ||
|
||||
savedMapOptionsTable.isNotEmpty() && mapParameters.type == MapGeneratedMainType.custom && mapParameters.name.isNotEmpty()
|
||||
)
|
||||
val mapTypeDefault = if (chooseCustom) MapGeneratedMainType.custom else MapGeneratedMainType.generated
|
||||
mapTypeSelectBox = TranslatedSelectBox(mapTypes, mapTypeDefault, BaseScreen.skin)
|
||||
mapTypeSelectBox = TranslatedSelectBox(mapTypes, MapGeneratedMainType.generated, BaseScreen.skin)
|
||||
|
||||
fun updateOnMapTypeChange() {
|
||||
mapTypeSpecificTable.clear()
|
||||
@ -46,7 +40,6 @@ class MapOptionsTable(private val newGameScreen: NewGameScreen, isReset: Boolean
|
||||
mapParameters.type = generatedMapOptionsTable.mapTypeSelectBox.selected.value
|
||||
mapTypeSpecificTable.add(generatedMapOptionsTable)
|
||||
newGameScreen.unlockTables()
|
||||
|
||||
}
|
||||
MapGeneratedMainType.randomGenerated -> {
|
||||
mapParameters.name = ""
|
||||
@ -58,7 +51,7 @@ class MapOptionsTable(private val newGameScreen: NewGameScreen, isReset: Boolean
|
||||
newGameScreen.updateTables()
|
||||
}
|
||||
|
||||
// activate once, so when we had a file map before we'll have the right things set for another one
|
||||
// activate once, so the MapGeneratedMainType.generated controls show
|
||||
updateOnMapTypeChange()
|
||||
|
||||
mapTypeSelectBox.onChange { updateOnMapTypeChange() }
|
||||
|
Loading…
Reference in New Issue
Block a user