diff --git a/core/src/com/unciv/ui/screens/mainmenuscreen/MainMenuScreen.kt b/core/src/com/unciv/ui/screens/mainmenuscreen/MainMenuScreen.kt index b0b7128fe9..4c4ac66d86 100644 --- a/core/src/com/unciv/ui/screens/mainmenuscreen/MainMenuScreen.kt +++ b/core/src/com/unciv/ui/screens/mainmenuscreen/MainMenuScreen.kt @@ -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() { diff --git a/docs/Modders/Creating-a-UI-skin.md b/docs/Modders/Creating-a-UI-skin.md index 301969a323..40e2f04b3f 100644 --- a/docs/Modders/Creating-a-UI-skin.md +++ b/docs/Modders/Creating-a-UI-skin.md @@ -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. \ No newline at end of file +The alpha this UI element should have. Overwrites the alpha value of tint if specified. diff --git a/docs/Modders/Creating-a-custom-tileset.md b/docs/Modders/Creating-a-custom-tileset.md index 04bb6d0924..5540049872 100644 --- a/docs/Modders/Creating-a-custom-tileset.md +++ b/docs/Modders/Creating-a-custom-tileset.md @@ -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: