diff --git a/core/src/com/unciv/UnCivGame.kt b/core/src/com/unciv/UnCivGame.kt index 3f1507c1ec..7beb1b439a 100644 --- a/core/src/com/unciv/UnCivGame.kt +++ b/core/src/com/unciv/UnCivGame.kt @@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Json import com.unciv.logic.GameInfo import com.unciv.logic.GameSaver import com.unciv.models.gamebasics.GameBasics +import com.unciv.ui.utils.ImageGetter import com.unciv.ui.worldscreen.WorldScreen class UnCivGame : Game() { @@ -24,6 +25,7 @@ class UnCivGame : Game() { override fun create() { Current = this + Gdx.input.isCatchBackKey=true GameBasics.run { } // just to initialize settings = GameSaver().getGeneralSettings() if (GameSaver().getSave("Autosave").exists()) { @@ -64,6 +66,12 @@ class UnCivGame : Game() { Gdx.input.inputProcessor = worldScreen.stage } + override fun resume() { + ImageGetter.refreshAltas() + worldScreen = WorldScreen() + setWorldScreen() + } + companion object { lateinit var Current: UnCivGame diff --git a/core/src/com/unciv/ui/EmpireOverviewScreen.kt b/core/src/com/unciv/ui/EmpireOverviewScreen.kt index 6963621b69..ede1be2cc6 100644 --- a/core/src/com/unciv/ui/EmpireOverviewScreen.kt +++ b/core/src/com/unciv/ui/EmpireOverviewScreen.kt @@ -16,6 +16,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){ val civInfo = UnCivGame.Current.gameInfo.getPlayerCivilization() init { + onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() } val topTable = Table().apply { defaults().pad(10f) } val centerTable=Table().apply { defaults().pad(20f) } diff --git a/core/src/com/unciv/ui/cityscreen/CityScreen.kt b/core/src/com/unciv/ui/cityscreen/CityScreen.kt index f1791187df..e1e4230be3 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreen.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreen.kt @@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener import com.badlogic.gdx.utils.Align +import com.unciv.UnCivGame import com.unciv.logic.HexMath import com.unciv.logic.city.CityInfo import com.unciv.logic.map.TileInfo @@ -25,6 +26,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() { private var tileGroups = ArrayList() init { + onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() } addTiles() stage.addActor(tileTable) diff --git a/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt index b4f6d89345..b885afce2b 100644 --- a/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt @@ -33,6 +33,10 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() { game.screen = CityScreen(this@ConstructionPickerScreen.city) dispose() } + onBackButtonClicked { + game.screen = CityScreen(this@ConstructionPickerScreen.city) + dispose() + } rightSideButton.setText("Pick construction".tr()) rightSideButton.addClickListener { diff --git a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt index d8f742de3d..d6db3e3e83 100644 --- a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt @@ -16,7 +16,6 @@ open class PickerScreen : CameraStageBaseScreen() { internal var splitPane: SplitPane init { - closeButton.addClickListener { game.setWorldScreen() dispose() diff --git a/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt index b8e47249dc..4e476a0a19 100644 --- a/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.unciv.UnCivGame import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.Policy @@ -15,16 +16,6 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen( private var pickedPolicy: Policy? = null init { - - - // Proof-of-concept for font generation -// val generator = FreeTypeFontGenerator(Gdx.files.internal("skin/Esteban-Regular.ttf")) -// val parameter = FreeTypeFontParameter() -// parameter.size = 25 -// val font12 = generator.generateFont(parameter) // font size 12 pixels -// generator.dispose() // don't forget to dispose to avoid memory leaks! -// rightSideButton.style.font = font12 - val policies = civInfo.policies displayTutorials("PolicyPickerScreen") @@ -34,6 +25,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen( rightSideButton.setText("Adopt free policy") closeButton.disable() } + else onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() } rightSideButton.addClickListener { civInfo.policies.adopt(pickedPolicy!!) diff --git a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt index fd0775fa78..cd900b6822 100644 --- a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup +import com.unciv.UnCivGame import com.unciv.logic.map.MapUnit import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.unit.Promotion @@ -14,6 +15,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() { init { + onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() } rightSideButton.setText("Pick promotion") rightSideButton.addClickListener { mapUnit.promotions.addPromotion(selectedPromotion!!.name) diff --git a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt index c23c678d19..0a4ae045b0 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt @@ -3,6 +3,7 @@ package com.unciv.ui.pickerscreens import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.unciv.UnCivGame import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.TechManager import com.unciv.models.gamebasics.GameBasics @@ -32,6 +33,8 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen() } init { + onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() } + techsToResearch = ArrayList(civTech.techsToResearch) val columns = 17 diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index ad32f2d581..6cb561e69d 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -1,6 +1,7 @@ package com.unciv.ui.utils import com.badlogic.gdx.Gdx +import com.badlogic.gdx.Input import com.badlogic.gdx.Screen import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.GL20 @@ -9,10 +10,7 @@ import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.BitmapFont import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator -import com.badlogic.gdx.scenes.scene2d.Actor -import com.badlogic.gdx.scenes.scene2d.InputEvent -import com.badlogic.gdx.scenes.scene2d.Stage -import com.badlogic.gdx.scenes.scene2d.Touchable +import com.badlogic.gdx.scenes.scene2d.* import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.utils.ClickListener import com.badlogic.gdx.utils.Align @@ -114,6 +112,8 @@ open class CameraStageBaseScreen : Screen { stage.addActor(tutorialTable) } + + companion object { var skin = Skin(Gdx.files.internal("skin/flat-earth-ui.json")) .apply { @@ -126,6 +126,18 @@ open class CameraStageBaseScreen : Screen { internal var batch: Batch = SpriteBatch() } + fun onBackButtonClicked(action:()->Unit){ + stage.addListener(object : InputListener(){ + override fun keyDown(event: InputEvent?, keycode: Int): Boolean { + if(keycode == Input.Keys.BACK){ + action() + return true + } + return false + } + }) + } + } diff --git a/core/src/com/unciv/ui/utils/ImageGetter.kt b/core/src/com/unciv/ui/utils/ImageGetter.kt index cf913bf0b9..8e81694186 100644 --- a/core/src/com/unciv/ui/utils/ImageGetter.kt +++ b/core/src/com/unciv/ui/utils/ImageGetter.kt @@ -3,7 +3,6 @@ package com.unciv.ui.utils import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.TextureAtlas import com.badlogic.gdx.graphics.g2d.TextureRegion -import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.utils.Drawable import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable @@ -16,7 +15,7 @@ object ImageGetter { // always have to switch between like 170 different textures. // So, we now use TexturePacker in the DesktopLauncher class to pack all the different images into single images, // and the atlas is what tells us what was packed where. - val atlas = TextureAtlas("game.atlas") + var atlas = TextureAtlas("game.atlas") init{ } @@ -43,27 +42,12 @@ object ImageGetter { return getTextureRegion(WhiteDot) } } - class IconGroup(statName:String): Group() { - init{ - val circleSize = 20f - val statSize = 17f - setSize(circleSize ,circleSize) -// addActor(ImageGetter.getImage("OtherIcons/Circle") -// .apply { setSize(circleSize,circleSize )} ) - val iconImage = ImageGetter.getImage("StatIcons/20x" + statName + "5.png") - .apply { setSize(statSize,statSize); center(this@IconGroup)} - if(statName=="Population") iconImage.color= Color.GREEN.cpy().lerp(Color.BLACK,0.5f) - addActor(iconImage) - } - } fun getStatIcon(statName: String): Image { return ImageGetter.getImage("StatIcons/20x" + statName + "5.png") .apply { setSize(20f,20f)} -// return IconGroup(name) } - fun getUnitIcon(unitName:String):Image{ return getImage("UnitIcons/$unitName.png") } @@ -81,4 +65,8 @@ object ImageGetter { fun getBackground(color:Color): Drawable { return getDrawable(WhiteDot).tint(color) } + + fun refreshAltas() { + atlas = TextureAtlas("game.atlas") + } } diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index a8a119046c..7bcd8606ad 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -235,8 +235,5 @@ class WorldScreen : CameraStageBaseScreen() { super.render(delta) } -// override fun resume() { -// resize(Gdx.graphics.width,Gdx.graphics.height) -// } }