Back button now acts like the "close" button, returning you to the upper-level screen (usually the world screen)

This commit is contained in:
Yair Morgenstern 2018-08-14 19:09:58 +03:00
parent 27b4c2c2ab
commit f9632b4151
11 changed files with 43 additions and 35 deletions

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Json
import com.unciv.logic.GameInfo import com.unciv.logic.GameInfo
import com.unciv.logic.GameSaver import com.unciv.logic.GameSaver
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
class UnCivGame : Game() { class UnCivGame : Game() {
@ -24,6 +25,7 @@ class UnCivGame : Game() {
override fun create() { override fun create() {
Current = this Current = this
Gdx.input.isCatchBackKey=true
GameBasics.run { } // just to initialize GameBasics.run { } // just to initialize
settings = GameSaver().getGeneralSettings() settings = GameSaver().getGeneralSettings()
if (GameSaver().getSave("Autosave").exists()) { if (GameSaver().getSave("Autosave").exists()) {
@ -64,6 +66,12 @@ class UnCivGame : Game() {
Gdx.input.inputProcessor = worldScreen.stage Gdx.input.inputProcessor = worldScreen.stage
} }
override fun resume() {
ImageGetter.refreshAltas()
worldScreen = WorldScreen()
setWorldScreen()
}
companion object { companion object {
lateinit var Current: UnCivGame lateinit var Current: UnCivGame

View File

@ -16,6 +16,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val civInfo = UnCivGame.Current.gameInfo.getPlayerCivilization() val civInfo = UnCivGame.Current.gameInfo.getPlayerCivilization()
init { init {
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
val topTable = Table().apply { defaults().pad(10f) } val topTable = Table().apply { defaults().pad(10f) }
val centerTable=Table().apply { defaults().pad(20f) } val centerTable=Table().apply { defaults().pad(20f) }

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.ui.*
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.UnCivGame
import com.unciv.logic.HexMath import com.unciv.logic.HexMath
import com.unciv.logic.city.CityInfo import com.unciv.logic.city.CityInfo
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
@ -25,6 +26,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
private var tileGroups = ArrayList<CityTileGroup>() private var tileGroups = ArrayList<CityTileGroup>()
init { init {
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
addTiles() addTiles()
stage.addActor(tileTable) stage.addActor(tileTable)

View File

@ -33,6 +33,10 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
game.screen = CityScreen(this@ConstructionPickerScreen.city) game.screen = CityScreen(this@ConstructionPickerScreen.city)
dispose() dispose()
} }
onBackButtonClicked {
game.screen = CityScreen(this@ConstructionPickerScreen.city)
dispose()
}
rightSideButton.setText("Pick construction".tr()) rightSideButton.setText("Pick construction".tr())
rightSideButton.addClickListener { rightSideButton.addClickListener {

View File

@ -16,7 +16,6 @@ open class PickerScreen : CameraStageBaseScreen() {
internal var splitPane: SplitPane internal var splitPane: SplitPane
init { init {
closeButton.addClickListener { closeButton.addClickListener {
game.setWorldScreen() game.setWorldScreen()
dispose() dispose()

View File

@ -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.Button
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UnCivGame
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.Policy import com.unciv.models.gamebasics.Policy
@ -15,16 +16,6 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
private var pickedPolicy: Policy? = null private var pickedPolicy: Policy? = null
init { 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 val policies = civInfo.policies
displayTutorials("PolicyPickerScreen") displayTutorials("PolicyPickerScreen")
@ -34,6 +25,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
rightSideButton.setText("Adopt free policy") rightSideButton.setText("Adopt free policy")
closeButton.disable() closeButton.disable()
} }
else onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
rightSideButton.addClickListener { rightSideButton.addClickListener {
civInfo.policies.adopt(pickedPolicy!!) civInfo.policies.adopt(pickedPolicy!!)

View File

@ -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.Button
import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
import com.unciv.UnCivGame
import com.unciv.logic.map.MapUnit import com.unciv.logic.map.MapUnit
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.unit.Promotion import com.unciv.models.gamebasics.unit.Promotion
@ -14,6 +15,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() {
init { init {
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
rightSideButton.setText("Pick promotion") rightSideButton.setText("Pick promotion")
rightSideButton.addClickListener { rightSideButton.addClickListener {
mapUnit.promotions.addPromotion(selectedPromotion!!.name) mapUnit.promotions.addPromotion(selectedPromotion!!.name)

View File

@ -3,6 +3,7 @@ package com.unciv.ui.pickerscreens
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UnCivGame
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.TechManager import com.unciv.logic.civilization.TechManager
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
@ -32,6 +33,8 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
} }
init { init {
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
techsToResearch = ArrayList(civTech.techsToResearch) techsToResearch = ArrayList(civTech.techsToResearch)
val columns = 17 val columns = 17

View File

@ -1,6 +1,7 @@
package com.unciv.ui.utils package com.unciv.ui.utils
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.Screen import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20 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.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.*
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.ui.* import com.badlogic.gdx.scenes.scene2d.ui.*
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
@ -114,6 +112,8 @@ open class CameraStageBaseScreen : Screen {
stage.addActor(tutorialTable) stage.addActor(tutorialTable)
} }
companion object { companion object {
var skin = Skin(Gdx.files.internal("skin/flat-earth-ui.json")) var skin = Skin(Gdx.files.internal("skin/flat-earth-ui.json"))
.apply { .apply {
@ -126,6 +126,18 @@ open class CameraStageBaseScreen : Screen {
internal var batch: Batch = SpriteBatch() 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
}
})
}
} }

View File

@ -3,7 +3,6 @@ package com.unciv.ui.utils
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.TextureAtlas import com.badlogic.gdx.graphics.g2d.TextureAtlas
import com.badlogic.gdx.graphics.g2d.TextureRegion 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.ui.Image
import com.badlogic.gdx.scenes.scene2d.utils.Drawable import com.badlogic.gdx.scenes.scene2d.utils.Drawable
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
@ -16,7 +15,7 @@ object ImageGetter {
// always have to switch between like 170 different textures. // 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, // 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. // and the atlas is what tells us what was packed where.
val atlas = TextureAtlas("game.atlas") var atlas = TextureAtlas("game.atlas")
init{ init{
} }
@ -43,27 +42,12 @@ object ImageGetter {
return getTextureRegion(WhiteDot) 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 { fun getStatIcon(statName: String): Image {
return ImageGetter.getImage("StatIcons/20x" + statName + "5.png") return ImageGetter.getImage("StatIcons/20x" + statName + "5.png")
.apply { setSize(20f,20f)} .apply { setSize(20f,20f)}
// return IconGroup(name)
} }
fun getUnitIcon(unitName:String):Image{ fun getUnitIcon(unitName:String):Image{
return getImage("UnitIcons/$unitName.png") return getImage("UnitIcons/$unitName.png")
} }
@ -81,4 +65,8 @@ object ImageGetter {
fun getBackground(color:Color): Drawable { fun getBackground(color:Color): Drawable {
return getDrawable(WhiteDot).tint(color) return getDrawable(WhiteDot).tint(color)
} }
fun refreshAltas() {
atlas = TextureAtlas("game.atlas")
}
} }

View File

@ -235,8 +235,5 @@ class WorldScreen : CameraStageBaseScreen() {
super.render(delta) super.render(delta)
} }
// override fun resume() {
// resize(Gdx.graphics.width,Gdx.graphics.height)
// }
} }