Keyboard: Left/Right arrows work in city screen (#2445)
This commit is contained in:
parent
bc6e2c97ef
commit
fce4b41aaa
2 changed files with 35 additions and 16 deletions
|
@ -1,7 +1,10 @@
|
|||
package com.unciv.ui.cityscreen
|
||||
|
||||
import com.badlogic.gdx.Input
|
||||
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.utils.Align
|
||||
|
@ -20,6 +23,7 @@ import java.util.*
|
|||
class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
||||
var selectedTile: TileInfo? = null
|
||||
var selectedConstruction: IConstruction? = null
|
||||
var keyListener: InputListener? = null
|
||||
|
||||
/** Toggle between Constructions and cityInfo (buildings, specialists etc. */
|
||||
var showConstructionsTable = true
|
||||
|
@ -64,6 +68,9 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
|||
stage.addActor(cityPickerTable)
|
||||
stage.addActor(cityInfoTable)
|
||||
update()
|
||||
|
||||
keyListener = getKeyboardListener()
|
||||
stage.addListener(keyListener)
|
||||
}
|
||||
|
||||
internal fun update() {
|
||||
|
@ -190,4 +197,29 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
|||
scrollPane.scrollPercentY=0.5f
|
||||
scrollPane.updateVisualScroll()
|
||||
}
|
||||
|
||||
fun exit() {
|
||||
stage.removeListener(keyListener)
|
||||
game.setWorldScreen()
|
||||
game.worldScreen.mapHolder.setCenterPosition(city.location)
|
||||
game.worldScreen.bottomUnitTable.selectedUnit=null
|
||||
}
|
||||
fun page(delta: Int) {
|
||||
val civInfo = city.civInfo
|
||||
val numCities = civInfo.cities.size
|
||||
if (numCities == 0) return
|
||||
val indexOfCity = civInfo.cities.indexOf(city)
|
||||
val indexOfNextCity = (indexOfCity + delta + numCities) % numCities
|
||||
stage.removeListener(keyListener)
|
||||
game.setScreen(CityScreen(civInfo.cities[indexOfNextCity]))
|
||||
}
|
||||
|
||||
private fun getKeyboardListener(): InputListener = object : InputListener() {
|
||||
override fun keyTyped(event: InputEvent?, character: Char): Boolean {
|
||||
if (character != 0.toChar() || event == null) return super.keyTyped(event, character)
|
||||
if (event.keyCode == Input.Keys.LEFT) page(-1)
|
||||
if (event.keyCode == Input.Keys.RIGHT) page(1)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,11 +21,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
|
|||
|
||||
if (civInfo.cities.size > 1) {
|
||||
val prevCityButton = TextButton("<", CameraStageBaseScreen.skin)
|
||||
prevCityButton.onClick {
|
||||
val indexOfCity = civInfo.cities.indexOf(city)
|
||||
val indexOfNextCity = if (indexOfCity == 0) civInfo.cities.size - 1 else indexOfCity - 1
|
||||
cityScreen.game.setScreen(CityScreen(civInfo.cities[indexOfNextCity]))
|
||||
}
|
||||
prevCityButton.onClick { cityScreen.page(-1) }
|
||||
add(prevCityButton).pad(20f)
|
||||
} else add()
|
||||
|
||||
|
@ -72,11 +68,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
|
|||
|
||||
if (civInfo.cities.size > 1) {
|
||||
val nextCityButton = TextButton(">", CameraStageBaseScreen.skin)
|
||||
nextCityButton.onClick {
|
||||
val indexOfCity = civInfo.cities.indexOf(city)
|
||||
val indexOfNextCity = if (indexOfCity == civInfo.cities.size - 1) 0 else indexOfCity + 1
|
||||
cityScreen.game.setScreen(CityScreen(civInfo.cities[indexOfNextCity]))
|
||||
}
|
||||
nextCityButton.onClick { cityScreen.page(1) }
|
||||
add(nextCityButton).pad(20f)
|
||||
} else add()
|
||||
row()
|
||||
|
@ -84,12 +76,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
|
|||
val exitCityButton = TextButton("Exit city".tr(), CameraStageBaseScreen.skin)
|
||||
exitCityButton.labelCell.pad(10f)
|
||||
|
||||
exitCityButton.onClick {
|
||||
val game = cityScreen.game
|
||||
game.setWorldScreen()
|
||||
game.worldScreen.mapHolder.setCenterPosition(city.location)
|
||||
game.worldScreen.bottomUnitTable.selectedUnit=null
|
||||
}
|
||||
exitCityButton.onClick { cityScreen.exit() }
|
||||
|
||||
add(exitCityButton).pad(10f).colspan(columns)
|
||||
|
||||
|
|
Loading…
Reference in a new issue