Cosmetic: Convenience shortcuts, some linting (#4067)

This commit is contained in:
SomeTroglodyte
2021-06-07 06:26:01 +02:00
committed by GitHub
parent a7afc0718c
commit 7a5b88923d
18 changed files with 81 additions and 63 deletions

View File

@ -514,6 +514,7 @@ Disband unit =
Explore = Explore =
Stop exploration = Stop exploration =
Pillage = Pillage =
Are you sure you want to pillage this [improvement]? =
Do you really want to disband this unit? = Do you really want to disband this unit? =
Disband this unit for [goldAmount] gold? = Disband this unit for [goldAmount] gold? =
Create [improvement] = Create [improvement] =

View File

@ -665,8 +665,8 @@ class CivilizationInfo {
fun getProtectorCivs() : List<CivilizationInfo> { fun getProtectorCivs() : List<CivilizationInfo> {
if(this.isMajorCiv()) return emptyList() if(this.isMajorCiv()) return emptyList()
return diplomacy.values return diplomacy.values
.filter{!it.otherCiv().isDefeated() && it.diplomaticStatus == DiplomaticStatus.Protector} .filter{ !it.otherCiv().isDefeated() && it.diplomaticStatus == DiplomaticStatus.Protector }
.map{it->it.otherCiv()} .map{ it.otherCiv() }
} }
fun addProtectorCiv(otherCiv: CivilizationInfo) { fun addProtectorCiv(otherCiv: CivilizationInfo) {

View File

@ -43,6 +43,12 @@ class Nation : INamed {
var innerColor: List<Int>? = null var innerColor: List<Int>? = null
var startBias = ArrayList<String>() var startBias = ArrayList<String>()
/* Properties present in json but not yet implemented:
var adjective = ArrayList<String>()
var startIntroPart1 = ""
var startIntroPart2 = ""
*/
@Transient @Transient
private lateinit var outerColorObject: Color private lateinit var outerColorObject: Color
fun getOuterColor(): Color = outerColorObject fun getOuterColor(): Color = outerColorObject
@ -71,8 +77,8 @@ class Nation : INamed {
fun setTransients() { fun setTransients() {
outerColorObject = colorFromRGB(outerColor) outerColorObject = colorFromRGB(outerColor)
if (innerColor == null) innerColorObject = Color.BLACK innerColorObject = if (innerColor == null) Color.BLACK
else innerColorObject = colorFromRGB(innerColor!!) else colorFromRGB(innerColor!!)
forestsAndJunglesAreRoads = uniques.contains("All units move through Forest and Jungle Tiles in friendly territory as if they have roads. These tiles can be used to establish City Connections upon researching the Wheel.") forestsAndJunglesAreRoads = uniques.contains("All units move through Forest and Jungle Tiles in friendly territory as if they have roads. These tiles can be used to establish City Connections upon researching the Wheel.")
ignoreHillMovementCost = uniques.contains("Units ignore terrain costs when moving into any tile with Hills") ignoreHillMovementCost = uniques.contains("Units ignore terrain costs when moving into any tile with Hills")

View File

@ -56,7 +56,7 @@ class CityScreenCityPickerTable(private val cityScreen: CityScreen) : Table() {
textArea.alignment = Align.center textArea.alignment = Align.center
editCityNamePopup.add(textArea).colspan(2).row() editCityNamePopup.add(textArea).colspan(2).row()
//editCityNamePopup.name = "CityNamePopup" // debug help //editCityNamePopup.name = "CityNamePopup" // debug help
editCityNamePopup.addButtonInRow("Save", '\r') { editCityNamePopup.addButtonInRow("Save", KeyCharAndCode.RETURN) {
city.name = textArea.text city.name = textArea.text
cityScreen.game.setScreen(CityScreen(city)) cityScreen.game.setScreen(CityScreen(city))
} }

View File

@ -37,7 +37,7 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
add(ScrollPane(checkboxTable)).maxHeight(mapEditorScreen.stage.height * 0.8f).colspan(2).row() add(ScrollPane(checkboxTable)).maxHeight(mapEditorScreen.stage.height * 0.8f).colspan(2).row()
addButtonInRow("Save", '\r') { addButtonInRow("Save", KeyCharAndCode.RETURN) {
val incompatibilities = HashSet<String>() val incompatibilities = HashSet<String>()
for (set in mapEditorScreen.tileMap.values.map { it.getRulesetIncompatibility(ruleset) }) for (set in mapEditorScreen.tileMap.values.map { it.getRulesetIncompatibility(ruleset) })
incompatibilities.addAll(set) incompatibilities.addAll(set)

View File

@ -1,6 +1,5 @@
package com.unciv.ui.mapeditor package com.unciv.ui.mapeditor
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.InputEvent import com.badlogic.gdx.scenes.scene2d.InputEvent
@ -68,7 +67,7 @@ class MapEditorScreen(): CameraStageBaseScreen() {
} }
val optionsMenuButton = "Menu".toTextButton() val optionsMenuButton = "Menu".toTextButton()
optionsMenuButton.onClick(openOptionsMenu) optionsMenuButton.onClick(openOptionsMenu)
keyPressDispatcher[Input.Keys.BACK] = openOptionsMenu keyPressDispatcher[KeyCharAndCode.BACK] = openOptionsMenu
optionsMenuButton.label.setFontSize(24) optionsMenuButton.label.setFontSize(24)
optionsMenuButton.labelCell.pad(20f) optionsMenuButton.labelCell.pad(20f)
optionsMenuButton.pack() optionsMenuButton.pack()

View File

@ -7,7 +7,6 @@ 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.scenes.scene2d.ui.TextField import com.badlogic.gdx.scenes.scene2d.ui.TextField
import com.badlogic.gdx.utils.Json import com.badlogic.gdx.utils.Json
import com.badlogic.gdx.Input
import com.unciv.logic.MapSaver import com.unciv.logic.MapSaver
import com.unciv.logic.map.MapType import com.unciv.logic.map.MapType
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
@ -71,7 +70,7 @@ class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousSc
} }
} }
rightSideButton.onClick(rightSideButtonAction) rightSideButton.onClick(rightSideButtonAction)
keyPressDispatcher['\r'] = rightSideButtonAction keyPressDispatcher[KeyCharAndCode.RETURN] = rightSideButtonAction
topTable.add(ScrollPane(mapsTable)).maxWidth(stage.width / 2) topTable.add(ScrollPane(mapsTable)).maxWidth(stage.width / 2)

View File

@ -15,7 +15,7 @@ import com.unciv.ui.utils.*
import kotlin.math.max import kotlin.math.max
import kotlin.math.roundToInt import kotlin.math.roundToInt
class CityOverviewTable(val viewingPlayer: CivilizationInfo, val overviewScreen: EmpireOverviewScreen): Table() { class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val overviewScreen: EmpireOverviewScreen): Table() {
companion object { companion object {
const val iconSize = 50f //if you set this too low, there is a chance that the tables will be misaligned const val iconSize = 50f //if you set this too low, there is a chance that the tables will be misaligned
@ -52,7 +52,7 @@ class CityOverviewTable(val viewingPlayer: CivilizationInfo, val overviewScreen:
// Prepare top third: cityInfoTableIcons // Prepare top third: cityInfoTableIcons
cityInfoTableIcons.defaults() cityInfoTableIcons.defaults()
.pad(paddingVert, paddingHorz, paddingVert, paddingHorz) .pad(paddingVert, paddingHorz)
.align(Align.center) .align(Align.center)
cityInfoTableIcons.add("Cities".toLabel(fontSize = 24)).colspan(numHeaderCells).align(Align.center).row() cityInfoTableIcons.add("Cities".toLabel(fontSize = 24)).colspan(numHeaderCells).align(Align.center).row()
val citySortIcon: IconCircleGroup = ImageGetter.getUnitIcon("Settler").surroundWithCircle(iconSize) val citySortIcon: IconCircleGroup = ImageGetter.getUnitIcon("Settler").surroundWithCircle(iconSize)
@ -65,7 +65,7 @@ class CityOverviewTable(val viewingPlayer: CivilizationInfo, val overviewScreen:
// Prepare middle third: cityInfoScrollPane (a ScrollPane containing cityInfoTableDetails) // Prepare middle third: cityInfoScrollPane (a ScrollPane containing cityInfoTableDetails)
cityInfoTableDetails.defaults() cityInfoTableDetails.defaults()
.pad(paddingVert, paddingHorz, paddingVert, paddingHorz) .pad(paddingVert, paddingHorz)
.minWidth(iconSize) //we need the min width so we can align the different tables .minWidth(iconSize) //we need the min width so we can align the different tables
.align(Align.left) .align(Align.left)
@ -83,7 +83,7 @@ class CityOverviewTable(val viewingPlayer: CivilizationInfo, val overviewScreen:
// Prepare bottom third: cityInfoTableTotal // Prepare bottom third: cityInfoTableTotal
cityInfoTableTotal.defaults() cityInfoTableTotal.defaults()
.pad(paddingVert, paddingHorz, paddingVert, paddingHorz) .pad(paddingVert, paddingHorz)
.minWidth(iconSize) //we need the min width so we can align the different tables .minWidth(iconSize) //we need the min width so we can align the different tables
cityInfoTableTotal.add("Total".toLabel()) cityInfoTableTotal.add("Total".toLabel())
@ -109,8 +109,9 @@ class CityOverviewTable(val viewingPlayer: CivilizationInfo, val overviewScreen:
} }
private fun getStatOfCity(cityInfo: CityInfo, stat: Stat): Int { private fun getStatOfCity(cityInfo: CityInfo, stat: Stat): Int {
if (stat == Stat.Happiness) return cityInfo.cityStats.happinessList.values.sum().roundToInt() return if (stat == Stat.Happiness)
else return cityInfo.cityStats.currentCityStats.get(stat).roundToInt() cityInfo.cityStats.happinessList.values.sum().roundToInt()
else cityInfo.cityStats.currentCityStats.get(stat).roundToInt()
} }
private fun fillCitiesTable(citiesTable: Table, sortType: String, descending: Boolean) { private fun fillCitiesTable(citiesTable: Table, sortType: String, descending: Boolean) {

View File

@ -18,7 +18,7 @@ import com.unciv.ui.utils.AutoScrollPane as ScrollPane
class SaveGameScreen(val gameInfo: GameInfo) : PickerScreen(disableScroll = true) { class SaveGameScreen(val gameInfo: GameInfo) : PickerScreen(disableScroll = true) {
val gameNameTextField = TextField("", skin) private val gameNameTextField = TextField("", skin)
val currentSaves = Table() val currentSaves = Table()
init { init {
@ -30,7 +30,7 @@ class SaveGameScreen(val gameInfo: GameInfo) : PickerScreen(disableScroll = true
topTable.add(ScrollPane(currentSaves)) topTable.add(ScrollPane(currentSaves))
val newSave = Table() val newSave = Table()
newSave.defaults().pad(5f, 10f, 5f, 10f) newSave.defaults().pad(5f, 10f)
val defaultSaveName = gameInfo.currentPlayer + " - " + gameInfo.turns + " turns" val defaultSaveName = gameInfo.currentPlayer + " - " + gameInfo.turns + " turns"
gameNameTextField.text = defaultSaveName gameNameTextField.text = defaultSaveName
@ -100,7 +100,7 @@ class SaveGameScreen(val gameInfo: GameInfo) : PickerScreen(disableScroll = true
} }
} }
fun updateShownSaves(showAutosaves: Boolean) { private fun updateShownSaves(showAutosaves: Boolean) {
currentSaves.clear() currentSaves.clear()
val saves = GameSaver.getSaves() val saves = GameSaver.getSaves()
.sortedByDescending { it.lastModified() } .sortedByDescending { it.lastModified() }

View File

@ -116,8 +116,8 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
} }
val protectors = otherCiv.getProtectorCivs() val protectors = otherCiv.getProtectorCivs()
if (protectors.size > 0) { if (protectors.isNotEmpty()) {
val protectorString = "{Protected by}: " + protectors.map{it.civName}.joinToString(", ") val protectorString = "{Protected by}: " + protectors.joinToString(", ") { it.civName }
diplomacyTable.add(protectorString.toLabel()).row() diplomacyTable.add(protectorString.toLabel()).row()
} }
@ -164,28 +164,28 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
if (viewingCiv.gold < giftAmount || isNotPlayersTurn()) giftButton.disable() if (viewingCiv.gold < giftAmount || isNotPlayersTurn()) giftButton.disable()
if (otherCivDiplomacyManager.diplomaticStatus == DiplomaticStatus.Protector){ if (otherCivDiplomacyManager.diplomaticStatus == DiplomaticStatus.Protector){
val RevokeProtectionButton = "Revoke Protection".toTextButton() val revokeProtectionButton = "Revoke Protection".toTextButton()
RevokeProtectionButton.onClick{ revokeProtectionButton.onClick {
YesNoPopup("Revoke protection for [${otherCiv.civName}]?".tr(), { YesNoPopup("Revoke protection for [${otherCiv.civName}]?", {
otherCiv.removeProtectorCiv(viewingCiv) otherCiv.removeProtectorCiv(viewingCiv)
updateLeftSideTable() updateLeftSideTable()
updateRightSide(otherCiv) updateRightSide(otherCiv)
}, this).open() }, this).open()
} }
diplomacyTable.add(RevokeProtectionButton).row() diplomacyTable.add(revokeProtectionButton).row()
} else { } else {
val ProtectionButton = "Pledge to protect".toTextButton() val protectionButton = "Pledge to protect".toTextButton()
ProtectionButton.onClick{ protectionButton.onClick {
YesNoPopup("Declare Protection of [${otherCiv.civName}]?".tr(), { YesNoPopup("Declare Protection of [${otherCiv.civName}]?", {
otherCiv.addProtectorCiv(viewingCiv) otherCiv.addProtectorCiv(viewingCiv)
updateLeftSideTable() updateLeftSideTable()
updateRightSide(otherCiv) updateRightSide(otherCiv)
}, this).open() }, this).open()
} }
if(viewingCiv.isAtWarWith(otherCiv)) { if(viewingCiv.isAtWarWith(otherCiv)) {
ProtectionButton.disable() protectionButton.disable()
} }
diplomacyTable.add(ProtectionButton).row() diplomacyTable.add(protectionButton).row()
} }
val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv) val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
@ -193,7 +193,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
if (viewingCiv.isAtWarWith(otherCiv)) { if (viewingCiv.isAtWarWith(otherCiv)) {
val peaceButton = "Negotiate Peace".toTextButton() val peaceButton = "Negotiate Peace".toTextButton()
peaceButton.onClick { peaceButton.onClick {
YesNoPopup("Peace with [${otherCiv.civName}]?".tr(), { YesNoPopup("Peace with [${otherCiv.civName}]?", {
val tradeLogic = TradeLogic(viewingCiv, otherCiv) val tradeLogic = TradeLogic(viewingCiv, otherCiv)
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty)) tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty))
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty)) tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty))
@ -457,7 +457,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
declareWarButton.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty${Fonts.turn})") declareWarButton.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty${Fonts.turn})")
} }
declareWarButton.onClick { declareWarButton.onClick {
YesNoPopup("Declare war on [${otherCiv.civName}]?".tr(), { YesNoPopup("Declare war on [${otherCiv.civName}]?", {
diplomacyManager.declareWar() diplomacyManager.declareWar()
setRightSideFlavorText(otherCiv, otherCiv.nation.attacked, "Very well.") setRightSideFlavorText(otherCiv, otherCiv.nation.attacked, "Very well.")
updateLeftSideTable() updateLeftSideTable()
@ -466,6 +466,8 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
return declareWarButton return declareWarButton
} }
// response currently always gets "Very Well.", but that may expand in the future.
@Suppress("SameParameterValue")
private fun setRightSideFlavorText(otherCiv: CivilizationInfo, flavorText: String, response: String) { private fun setRightSideFlavorText(otherCiv: CivilizationInfo, flavorText: String, response: String) {
val diplomacyTable = Table() val diplomacyTable = Table()
diplomacyTable.defaults().pad(10f) diplomacyTable.defaults().pad(10f)

View File

@ -28,7 +28,7 @@ class TutorialRender(private val screen: CameraStageBaseScreen) {
tutorialPopup.addGoodSizedLabel(texts[0]).row() tutorialPopup.addGoodSizedLabel(texts[0]).row()
tutorialPopup.addCloseButton(additionalKey = KeyCharAndCode(' ')) { tutorialPopup.addCloseButton(additionalKey = KeyCharAndCode.SPACE) {
tutorialPopup.remove() tutorialPopup.remove()
texts.removeIndex(0) texts.removeIndex(0)
showDialog(tutorialName, texts, closeAction) showDialog(tutorialName, texts, closeAction)

View File

@ -1,7 +1,6 @@
package com.unciv.ui.utils package com.unciv.ui.utils
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.Screen import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.GL20
@ -95,8 +94,7 @@ open class CameraStageBaseScreen : Screen {
} }
fun onBackButtonClicked(action: () -> Unit) { fun onBackButtonClicked(action: () -> Unit) {
keyPressDispatcher[Input.Keys.BACK] = action keyPressDispatcher[KeyCharAndCode.BACK] = action
keyPressDispatcher['\u001B'] = action
} }
fun isPortrait() = stage.viewport.screenHeight > stage.viewport.screenWidth fun isPortrait() = stage.viewport.screenHeight > stage.viewport.screenWidth

View File

@ -111,6 +111,11 @@ fun <T : Actor> Table.addCell(actor: T): Table {
return this return this
} }
/** Shortcut for [Cell].[pad][com.badlogic.gdx.scenes.scene2d.ui.Cell.pad] with top=bottom and left=right */
fun <T : Actor> Cell<T>.pad(vertical: Float, horizontal: Float): Cell<T> {
return pad(vertical, horizontal, vertical, horizontal)
}
/** Gets a clone of an [ArrayList] with an additional item /** Gets a clone of an [ArrayList] with an additional item
* *
* Solves concurrent modification problems - everyone who had a reference to the previous arrayList can keep using it because it hasn't changed * Solves concurrent modification problems - everyone who had a reference to the previous arrayList can keep using it because it hasn't changed

View File

@ -146,10 +146,10 @@ object Fonts {
} }
const val turn = '⏳' const val turn = '⏳' // U+23F3 'hourglass'
const val strength = '†' const val strength = '†' // U+2020 'dagger'
const val rangedStrength = '‡' const val rangedStrength = '‡' // U+2021 'double dagger'
const val movement = '➡' const val movement = '➡' // U+27A1 'black rightwards arrow'
const val range = '…' const val range = '…' // U+2026 'horizontal ellipsis'
const val production = '⚙' const val production = '⚙' // U+2699 'gear'
} }

View File

@ -39,11 +39,20 @@ data class KeyCharAndCode(val char: Char, val code: Int) {
// debug helper // debug helper
return when { return when {
char == Char.MIN_VALUE -> Input.Keys.toString(code) char == Char.MIN_VALUE -> Input.Keys.toString(code)
char == '\u001B' -> "ESC" this == ESC -> "ESC"
char < ' ' -> "Ctrl-" + (char.toInt()+64).toChar() char < ' ' -> "Ctrl-" + (char.toInt()+64).toChar()
else -> "\"$char\"" else -> "\"$char\""
} }
} }
// Convenience shortcuts for frequently used constants
companion object {
val BACK = KeyCharAndCode(Input.Keys.BACK)
val ESC = KeyCharAndCode('\u001B')
val RETURN = KeyCharAndCode('\r')
val NEWLINE = KeyCharAndCode('\n')
val SPACE = KeyCharAndCode(' ')
}
} }
@ -86,19 +95,19 @@ class KeyPressDispatcher(val name: String? = null) : HashMap<KeyCharAndCode, (()
operator fun set(key: KeyCharAndCode, action: () -> Unit) { operator fun set(key: KeyCharAndCode, action: () -> Unit) {
super.put(key, action) super.put(key, action)
// On Android the Enter key will fire with Ascii code `Linefeed`, on desktop as `Carriage Return` // On Android the Enter key will fire with Ascii code `Linefeed`, on desktop as `Carriage Return`
if (key == KeyCharAndCode('\r')) if (key == KeyCharAndCode.RETURN)
super.put(KeyCharAndCode('\n'), action) super.put(KeyCharAndCode.NEWLINE, action)
// Likewise always match Back to ESC // Likewise always match Back to ESC
if (key == KeyCharAndCode(Input.Keys.BACK)) if (key == KeyCharAndCode.BACK)
super.put(KeyCharAndCode('\u001B'), action) super.put(KeyCharAndCode.ESC, action)
checkInstall() checkInstall()
} }
override fun remove(key: KeyCharAndCode): (() -> Unit)? { override fun remove(key: KeyCharAndCode): (() -> Unit)? {
val result = super.remove(key) val result = super.remove(key)
if (key == KeyCharAndCode('\r')) if (key == KeyCharAndCode.RETURN)
super.remove(KeyCharAndCode('\n')) super.remove(KeyCharAndCode.NEWLINE)
if (key == KeyCharAndCode(Input.Keys.BACK)) if (key == KeyCharAndCode.BACK)
super.remove(KeyCharAndCode('\u001B')) super.remove(KeyCharAndCode.ESC)
checkInstall() checkInstall()
return result return result
} }

View File

@ -1,6 +1,5 @@
package com.unciv.ui.utils package com.unciv.ui.utils
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.Touchable
@ -137,7 +136,7 @@ open class Popup(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen
action: (()->Unit)? = null action: (()->Unit)? = null
): Cell<TextButton> { ): Cell<TextButton> {
val closeAction = { close(); if(action!=null) action() } val closeAction = { close(); if(action!=null) action() }
keyPressDispatcher[Input.Keys.BACK] = closeAction keyPressDispatcher[KeyCharAndCode.BACK] = closeAction
return addButton(text, additionalKey, closeAction) return addButton(text, additionalKey, closeAction)
} }

View File

@ -1,7 +1,6 @@
package com.unciv.ui.utils package com.unciv.ui.utils
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.unciv.UncivGame import com.unciv.UncivGame
/** Variant of [Popup] pre-populated with one label, plus yes and no buttons /** Variant of [Popup] pre-populated with one label, plus yes and no buttons
@ -23,8 +22,8 @@ open class YesNoPopup (
add(question.toLabel()).colspan(2).row() add(question.toLabel()).colspan(2).row()
addButtonInRow("Yes", 'y', yes) addButtonInRow("Yes", 'y', yes)
addButtonInRow("No", 'n', no) addButtonInRow("No", 'n', no)
keyPressDispatcher['\r'] = yes keyPressDispatcher[KeyCharAndCode.RETURN] = yes
keyPressDispatcher[Input.Keys.BACK] = no keyPressDispatcher[KeyCharAndCode.BACK] = no
} }
} }

View File

@ -7,12 +7,13 @@ import com.badlogic.gdx.utils.Align
import com.unciv.logic.map.MapUnit import com.unciv.logic.map.MapUnit
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.pad
import com.unciv.ui.worldscreen.WorldMapHolder import com.unciv.ui.worldscreen.WorldMapHolder
class IdleUnitButton ( class IdleUnitButton (
internal val unitTable: UnitTable, internal val unitTable: UnitTable,
val tileMapHolder: WorldMapHolder, private val tileMapHolder: WorldMapHolder,
val previous:Boolean val previous:Boolean
) : Table() { ) : Table() {
val image = ImageGetter.getImage("OtherIcons/BackArrow") val image = ImageGetter.getImage("OtherIcons/BackArrow")
@ -26,7 +27,7 @@ class IdleUnitButton (
image.setOrigin(Align.center) image.setOrigin(Align.center)
image.rotateBy(180f) image.rotateBy(180f)
} }
add(image).size(imageSize).pad(10f,20f,10f,20f) add(image).size(imageSize).pad(10f,20f)
enable() enable()
onClick { onClick {
@ -61,4 +62,3 @@ class IdleUnitButton (
touchable=Touchable.disabled touchable=Touchable.disabled
} }
} }