Improve keyboard shortcut (#2663)
* Use keyDown instead of keyTyped to handle arrow keys * Rename getIconAnKeyForUnitAction to getIconAndKeyForUnitAction Remove unnecessary dependencies in UnitActionsTable.kt * Use backButtonAndESCHandler to deselect unit and city
This commit is contained in:
parent
29d17ead9b
commit
ef0c0b9407
3 changed files with 27 additions and 11 deletions
|
@ -221,11 +221,14 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
|||
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)
|
||||
private fun getKeyboardListener(): InputListener = object: InputListener() {
|
||||
override fun keyDown(event: InputEvent?, keyCode: Int): Boolean {
|
||||
if (event == null) return super.keyDown(event, keyCode)
|
||||
when(event.keyCode) {
|
||||
Input.Keys.LEFT -> page(-1)
|
||||
Input.Keys.RIGHT -> page(1)
|
||||
else -> return super.keyDown(event, keyCode)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -634,6 +634,22 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||
return
|
||||
}
|
||||
|
||||
// Deselect Unit
|
||||
if (bottomUnitTable.selectedUnit != null) {
|
||||
bottomUnitTable.selectedUnit = null
|
||||
bottomUnitTable.isVisible = false
|
||||
shouldUpdate = true
|
||||
return
|
||||
}
|
||||
|
||||
// Deselect city
|
||||
if (bottomUnitTable.selectedCity != null) {
|
||||
bottomUnitTable.selectedCity = null
|
||||
bottomUnitTable.isVisible = false
|
||||
shouldUpdate = true
|
||||
return
|
||||
}
|
||||
|
||||
// don't show a dialog, if it can't exit the game
|
||||
if (game.exitEvent == null) {
|
||||
return
|
||||
|
|
|
@ -2,12 +2,9 @@ package com.unciv.ui.worldscreen.unit
|
|||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.map.MapUnit
|
||||
|
@ -24,7 +21,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() {
|
|||
touchable = Touchable.enabled
|
||||
}
|
||||
|
||||
private fun getIconAnKeyForUnitAction(unitAction: String): UnitIconAndKey {
|
||||
private fun getIconAndKeyForUnitAction(unitAction: String): UnitIconAndKey {
|
||||
when {
|
||||
unitAction.startsWith("Upgrade to") -> {
|
||||
// Regexplaination: start with a [, take as many non-] chars as you can, until you reach a ].
|
||||
|
@ -74,7 +71,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() {
|
|||
|
||||
|
||||
private fun getUnitActionButton(unitAction: UnitAction): Button {
|
||||
val iconAndKey = getIconAnKeyForUnitAction(unitAction.title)
|
||||
val iconAndKey = getIconAndKeyForUnitAction(unitAction.title)
|
||||
val actionButton = Button(CameraStageBaseScreen.skin)
|
||||
actionButton.add(iconAndKey.Icon).size(20f).pad(5f)
|
||||
val fontColor = if (unitAction.isCurrentAction) Color.YELLOW else Color.WHITE
|
||||
|
|
Loading…
Reference in a new issue