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.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

View File

@ -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) }

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.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<CityTileGroup>()
init {
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
addTiles()
stage.addActor(tileTable)

View File

@ -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 {

View File

@ -16,7 +16,6 @@ open class PickerScreen : CameraStageBaseScreen() {
internal var splitPane: SplitPane
init {
closeButton.addClickListener {
game.setWorldScreen()
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.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!!)

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.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)

View File

@ -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

View File

@ -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
}
})
}
}

View File

@ -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")
}
}

View File

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