Main menu background map changes infrequently (#9133)

This commit is contained in:
SomeTroglodyte 2023-04-07 15:22:46 +02:00 committed by GitHub
parent 36667d9d18
commit ca06d7e54a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 20 deletions

View File

@ -1,9 +1,9 @@
package com.unciv.ui.screens.mainmenuscreen
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.actions.Actions
import com.badlogic.gdx.scenes.scene2d.ui.Stack
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align
import com.unciv.GUI
@ -48,23 +48,28 @@ import com.unciv.ui.screens.newgamescreen.NewGameScreen
import com.unciv.ui.screens.pickerscreens.ModManagementScreen
import com.unciv.ui.screens.savescreens.LoadGameScreen
import com.unciv.ui.screens.savescreens.QuickSave
import com.unciv.ui.screens.worldscreen.BackgroundActor
import com.unciv.ui.screens.worldscreen.WorldScreen
import com.unciv.ui.screens.worldscreen.mainmenu.WorldScreenMenuPopup
import com.unciv.utils.concurrency.Concurrency
import com.unciv.utils.concurrency.launchOnGLThread
import kotlinx.coroutines.Job
import kotlinx.coroutines.isActive
import kotlin.math.min
class MainMenuScreen: BaseScreen(), RecreateOnResize {
private val backgroundTable = Table().apply {
background = skinStrings.getUiBackground("MainMenuScreen/Background", tintColor = Color.WHITE)
}
private val backgroundStack = Stack()
private val singleColumn = isCrampedPortrait()
private var easterEggRuleset: Ruleset? = null // Cache it so the next 'egg' can be found in Civilopedia
private var backgroundMapGenerationJob: Job? = null
private var backgroundMapExists = false
companion object {
const val mapFadeTime = 1.3f
const val mapFirstFadeTime = 0.3f
const val mapReplaceDelay = 15f
}
/** Create one **Main Menu Button** including onClick/key binding
* @param text The text to display on the button
@ -105,8 +110,10 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
}
init {
stage.addActor(backgroundTable)
backgroundTable.center(stage)
val background = skinStrings.getUiBackground("MainMenuScreen/Background", tintColor = clearColor)
backgroundStack.add(BackgroundActor(background, Align.center))
stage.addActor(backgroundStack)
backgroundStack.setFillParent(true)
// If we were in a mod, some of the resource images for the background map we're creating
// will not exist unless we reset the ruleset and images
@ -225,20 +232,27 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
newMap
) {}
mapHolder.setScale(scale)
mapHolder.color = mapHolder.color.cpy()
mapHolder.color.a = 0f
backgroundStack.add(mapHolder)
backgroundTable.addAction(Actions.sequence(
Actions.fadeOut(0f),
Actions.run {
backgroundTable.clearChildren()
backgroundTable.addActor(mapHolder)
mapHolder.center(backgroundTable)
},
Actions.fadeIn(0.3f)
))
if (backgroundMapExists) {
mapHolder.addAction(Actions.sequence(
Actions.fadeIn(mapFadeTime),
Actions.run { backgroundStack.removeActorAt(1, false) }
))
} else {
backgroundMapExists = true
mapHolder.addAction(Actions.fadeIn(mapFirstFadeTime))
}
}
}.apply {
invokeOnCompletion {
backgroundMapGenerationJob = null
backgroundStack.addAction(Actions.sequence(
Actions.delay(mapReplaceDelay),
Actions.run { startBackgroundMapGeneration() }
))
}
}
}
@ -249,7 +263,7 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
backgroundMapGenerationJob = null
if (currentJob.isCancelled) return
currentJob.cancel()
backgroundTable.clearActions()
backgroundStack.clearActions()
}
private fun resumeGame() {

View File

@ -117,7 +117,7 @@ These shapes are used all over Unciv and can be replaced to make a lot of UI ele
The skinConfig is similar to the [tilesetConfig](Creating-a-custom-tileset.md#tileset-config) and can be used to define different colors and shapes for unciv to use.
To create a config for your skin you just need to create a new .json file under `Jsons/Skins/`. Just create a .txt file and rename it to MyCoolSkinExample.json. You only have to add things if you want to change them. Else the default values will be used.
To create a config for your skin you just need to create a new .json file under `jsons/Skins/`. Just create a .txt file and rename it to MyCoolSkinExample.json. You only have to add things if you want to change them. Else the default values will be used.
This is an example of such a config file that will be explain below:
@ -179,4 +179,4 @@ The color this UI element should have.
A float value. Default value: null
The alpha this UI element should have. Overwrites the alpha value of tint if specified.
The alpha this UI element should have. Overwrites the alpha value of tint if specified.

View File

@ -25,7 +25,7 @@ BaseTerrain, TerrainFeatures, Resource, Improvement.
This is where tileset configs shine. You can use these to alter the way Unicv renders tiles.
To create a config for your tileset you just need to create a new .json file under Jsons/Tilesets/. Just create a .txt file and rename it to MyCoolTilesetExample.json. You only have to add things if you want to change them. Else the default values will be used.
To create a config for your tileset you just need to create a new .json file under jsons/Tilesets/. Just create a .txt file and rename it to MyCoolTilesetExample.json. You only have to add things if you want to change them. Else the default values will be used.
This is an example of such a config file that will be explain below: