mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 03:23:17 -04:00
Keyboard: Left/Right arrows work in city screen (#2445)
This commit is contained in:
parent
bc6e2c97ef
commit
fce4b41aaa
@ -1,7 +1,10 @@
|
|||||||
package com.unciv.ui.cityscreen
|
package com.unciv.ui.cityscreen
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Input
|
||||||
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
@ -20,6 +23,7 @@ import java.util.*
|
|||||||
class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
||||||
var selectedTile: TileInfo? = null
|
var selectedTile: TileInfo? = null
|
||||||
var selectedConstruction: IConstruction? = null
|
var selectedConstruction: IConstruction? = null
|
||||||
|
var keyListener: InputListener? = null
|
||||||
|
|
||||||
/** Toggle between Constructions and cityInfo (buildings, specialists etc. */
|
/** Toggle between Constructions and cityInfo (buildings, specialists etc. */
|
||||||
var showConstructionsTable = true
|
var showConstructionsTable = true
|
||||||
@ -64,6 +68,9 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
|||||||
stage.addActor(cityPickerTable)
|
stage.addActor(cityPickerTable)
|
||||||
stage.addActor(cityInfoTable)
|
stage.addActor(cityInfoTable)
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
keyListener = getKeyboardListener()
|
||||||
|
stage.addListener(keyListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun update() {
|
internal fun update() {
|
||||||
@ -190,4 +197,29 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
|||||||
scrollPane.scrollPercentY=0.5f
|
scrollPane.scrollPercentY=0.5f
|
||||||
scrollPane.updateVisualScroll()
|
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) {
|
if (civInfo.cities.size > 1) {
|
||||||
val prevCityButton = TextButton("<", CameraStageBaseScreen.skin)
|
val prevCityButton = TextButton("<", CameraStageBaseScreen.skin)
|
||||||
prevCityButton.onClick {
|
prevCityButton.onClick { cityScreen.page(-1) }
|
||||||
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]))
|
|
||||||
}
|
|
||||||
add(prevCityButton).pad(20f)
|
add(prevCityButton).pad(20f)
|
||||||
} else add()
|
} else add()
|
||||||
|
|
||||||
@ -72,11 +68,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
|
|||||||
|
|
||||||
if (civInfo.cities.size > 1) {
|
if (civInfo.cities.size > 1) {
|
||||||
val nextCityButton = TextButton(">", CameraStageBaseScreen.skin)
|
val nextCityButton = TextButton(">", CameraStageBaseScreen.skin)
|
||||||
nextCityButton.onClick {
|
nextCityButton.onClick { cityScreen.page(1) }
|
||||||
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]))
|
|
||||||
}
|
|
||||||
add(nextCityButton).pad(20f)
|
add(nextCityButton).pad(20f)
|
||||||
} else add()
|
} else add()
|
||||||
row()
|
row()
|
||||||
@ -84,12 +76,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
|
|||||||
val exitCityButton = TextButton("Exit city".tr(), CameraStageBaseScreen.skin)
|
val exitCityButton = TextButton("Exit city".tr(), CameraStageBaseScreen.skin)
|
||||||
exitCityButton.labelCell.pad(10f)
|
exitCityButton.labelCell.pad(10f)
|
||||||
|
|
||||||
exitCityButton.onClick {
|
exitCityButton.onClick { cityScreen.exit() }
|
||||||
val game = cityScreen.game
|
|
||||||
game.setWorldScreen()
|
|
||||||
game.worldScreen.mapHolder.setCenterPosition(city.location)
|
|
||||||
game.worldScreen.bottomUnitTable.selectedUnit=null
|
|
||||||
}
|
|
||||||
|
|
||||||
add(exitCityButton).pad(10f).colspan(columns)
|
add(exitCityButton).pad(10f).colspan(columns)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user