Can now move around the world screen with the arrow keys as well as WASD

This commit is contained in:
Yair Morgenstern
2020-10-15 21:09:05 +03:00
parent 0aa53f07e7
commit 55d0f7f1dd
3 changed files with 12 additions and 6 deletions

View File

@ -1,5 +1,7 @@
## 3.11.4 ## 3.11.4
Added city images by The Bucketeer for all eras up to Modern
Influence bar not displayed for city-states that don't know the viewing civ Influence bar not displayed for city-states that don't know the viewing civ
Resolved #3254 - Solved bug in calculating turns to production for settlers Resolved #3254 - Solved bug in calculating turns to production for settlers

View File

@ -7,6 +7,7 @@ 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.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.Constants import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.RoadStatus
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.models.ruleset.tile.TileImprovement import com.unciv.models.ruleset.tile.TileImprovement
@ -34,6 +35,7 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) :
init { init {
setDefaultCloseAction() setDefaultCloseAction()
onBackButtonClicked { UncivGame.Current.setWorldScreen() }
rightSideButton.setText("Pick improvement".tr()) rightSideButton.setText("Pick improvement".tr())
rightSideButton.onClick { rightSideButton.onClick {

View File

@ -71,7 +71,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
private var backButtonListener : InputListener private var backButtonListener : InputListener
// An initialized val always turned out to illegally be null... // An initialized val always turned out to illegally be null...
lateinit var keyPressDispatcher: HashMap<Char,(() -> Unit)> lateinit var keyPressDispatcher: HashMap<Char, (() -> Unit)>
init { init {
@ -185,7 +185,9 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
private val pressedKeys = mutableSetOf<Int>() private val pressedKeys = mutableSetOf<Int>()
private var infiniteAction : RepeatAction? = null private var infiniteAction : RepeatAction? = null
private val amountToMove = 30 / mapHolder.scaleX private val amountToMove = 30 / mapHolder.scaleX
private val ALLOWED_KEYS = setOf(Input.Keys.W,Input.Keys.S,Input.Keys.A,Input.Keys.D) private val ALLOWED_KEYS = setOf(Input.Keys.W,Input.Keys.S,Input.Keys.A,Input.Keys.D,
Input.Keys.UP, Input.Keys.DOWN, Input.Keys.LEFT, Input.Keys.RIGHT )
override fun keyDown(event: InputEvent?, keycode: Int): Boolean { override fun keyDown(event: InputEvent?, keycode: Int): Boolean {
if (keycode !in ALLOWED_KEYS) return false if (keycode !in ALLOWED_KEYS) return false
@ -202,10 +204,10 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
fun whileKeyPressedLoop() { fun whileKeyPressedLoop() {
for (keycode in pressedKeys) { for (keycode in pressedKeys) {
when (keycode) { when (keycode) {
Input.Keys.W -> mapHolder.scrollY -= amountToMove Input.Keys.W, Input.Keys.UP -> mapHolder.scrollY -= amountToMove
Input.Keys.S -> mapHolder.scrollY += amountToMove Input.Keys.S, Input.Keys.DOWN -> mapHolder.scrollY += amountToMove
Input.Keys.A -> mapHolder.scrollX -= amountToMove Input.Keys.A, Input.Keys.LEFT -> mapHolder.scrollX -= amountToMove
Input.Keys.D -> mapHolder.scrollX += amountToMove Input.Keys.D, Input.Keys.RIGHT -> mapHolder.scrollX += amountToMove
} }
} }
mapHolder.updateVisualScroll() mapHolder.updateVisualScroll()