mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 10:18:26 +07:00
ImprovementPicker: R key 'moves' from Road to Railroad patch (#3871)
This commit is contained in:
@ -52,7 +52,8 @@
|
|||||||
"name": "Oil well",
|
"name": "Oil well",
|
||||||
"terrainsCanBeBuiltOn": ["Coast"],
|
"terrainsCanBeBuiltOn": ["Coast"],
|
||||||
"turnsToBuild": 9,
|
"turnsToBuild": 9,
|
||||||
"techRequired": "Biology"
|
"techRequired": "Biology",
|
||||||
|
"shortcutKey": "W"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Pasture",
|
"name": "Pasture",
|
||||||
@ -106,7 +107,8 @@
|
|||||||
"name": "Railroad",
|
"name": "Railroad",
|
||||||
"turnsToBuild": 4,
|
"turnsToBuild": 4,
|
||||||
"techRequired": "Railroad",
|
"techRequired": "Railroad",
|
||||||
"uniques": ["Can be built outside your borders", "Costs [2] gold per turn when in your territory"]
|
"uniques": ["Can be built outside your borders", "Costs [2] gold per turn when in your territory"],
|
||||||
|
"shortcutKey": "R"
|
||||||
},
|
},
|
||||||
|
|
||||||
// Removals
|
// Removals
|
||||||
@ -156,7 +158,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Cancel improvement order",
|
"name": "Cancel improvement order",
|
||||||
"uniques": ["Can be built outside your borders"]
|
"uniques": ["Can be built outside your borders"],
|
||||||
|
"shortcutKey": "."
|
||||||
},
|
},
|
||||||
|
|
||||||
// Great Person improvements
|
// Great Person improvements
|
||||||
|
@ -18,7 +18,12 @@ import kotlin.math.round
|
|||||||
|
|
||||||
class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) : PickerScreen() {
|
class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) : PickerScreen() {
|
||||||
private var selectedImprovement: TileImprovement? = null
|
private var selectedImprovement: TileImprovement? = null
|
||||||
val currentPlayerCiv = tileInfo.tileMap.gameInfo.getCurrentPlayerCivilization()
|
private val gameInfo = tileInfo.tileMap.gameInfo
|
||||||
|
private val ruleSet = gameInfo.ruleSet
|
||||||
|
private val currentPlayerCiv = gameInfo.getCurrentPlayerCivilization()
|
||||||
|
|
||||||
|
private fun getRequiredTechColumn(improvement: TileImprovement) =
|
||||||
|
ruleSet.technologies[improvement.techRequired]?.column?.columnNumber ?: -1
|
||||||
|
|
||||||
fun accept(improvement: TileImprovement?) {
|
fun accept(improvement: TileImprovement?) {
|
||||||
if (improvement == null) return
|
if (improvement == null) return
|
||||||
@ -47,10 +52,10 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) :
|
|||||||
val regularImprovements = Table()
|
val regularImprovements = Table()
|
||||||
regularImprovements.defaults().pad(5f)
|
regularImprovements.defaults().pad(5f)
|
||||||
|
|
||||||
for (improvement in tileInfo.tileMap.gameInfo.ruleSet.tileImprovements.values) {
|
for (improvement in ruleSet.tileImprovements.values) {
|
||||||
// canBuildImprovement() would allow e.g. great improvements thus we need to exclude them - except cancel
|
// canBuildImprovement() would allow e.g. great improvements thus we need to exclude them - except cancel
|
||||||
if (improvement.turnsToBuild == 0 && improvement.name != Constants.cancelImprovementOrder) continue
|
if (improvement.turnsToBuild == 0 && improvement.name != Constants.cancelImprovementOrder) continue
|
||||||
if (improvement.name == tileInfo.improvement) continue
|
if (improvement.name == tileInfo.improvement) continue // also checked by canImprovementBeBuiltHere, but after more expensive tests
|
||||||
if (!tileInfo.canBuildImprovement(improvement, currentPlayerCiv)) continue
|
if (!tileInfo.canBuildImprovement(improvement, currentPlayerCiv)) continue
|
||||||
|
|
||||||
val improvementButtonTable = Table()
|
val improvementButtonTable = Table()
|
||||||
@ -59,8 +64,24 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) :
|
|||||||
|
|
||||||
improvementButtonTable.add(image).size(30f).pad(10f)
|
improvementButtonTable.add(image).size(30f).pad(10f)
|
||||||
|
|
||||||
|
// allow multiple key mappings to technologically supersede each other
|
||||||
|
var shortcutKey = improvement.shortcutKey
|
||||||
|
if (shortcutKey != null) {
|
||||||
|
val techLevel = getRequiredTechColumn(improvement)
|
||||||
|
val isSuperseded = ruleSet.tileImprovements.values.asSequence()
|
||||||
|
// *other* improvements with same shortcutKey
|
||||||
|
.filter { it.shortcutKey == improvement.shortcutKey && it != improvement }
|
||||||
|
// civ can build it (checks tech researched)
|
||||||
|
.filter { tileInfo.canBuildImprovement(it, currentPlayerCiv) }
|
||||||
|
// is technologically more advanced
|
||||||
|
.filter { getRequiredTechColumn(it) > techLevel }
|
||||||
|
.any()
|
||||||
|
// another supersedes this - ignore key binding
|
||||||
|
if (isSuperseded) shortcutKey = null
|
||||||
|
}
|
||||||
|
|
||||||
var labelText = improvement.name.tr()
|
var labelText = improvement.name.tr()
|
||||||
if (improvement.shortcutKey != null) labelText += " (${improvement.shortcutKey})"
|
if (shortcutKey != null) labelText += " ($shortcutKey)"
|
||||||
val turnsToBuild = if (tileInfo.improvementInProgress == improvement.name) tileInfo.turnsToImprovement
|
val turnsToBuild = if (tileInfo.improvementInProgress == improvement.name) tileInfo.turnsToImprovement
|
||||||
else improvement.getTurnsToBuild(currentPlayerCiv)
|
else improvement.getTurnsToBuild(currentPlayerCiv)
|
||||||
if (turnsToBuild > 0) labelText += " - $turnsToBuild${Fonts.turn}"
|
if (turnsToBuild > 0) labelText += " - $turnsToBuild${Fonts.turn}"
|
||||||
@ -76,7 +97,6 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) :
|
|||||||
improvementButtonTable.onClick {
|
improvementButtonTable.onClick {
|
||||||
selectedImprovement = improvement
|
selectedImprovement = improvement
|
||||||
pick(improvement.name.tr())
|
pick(improvement.name.tr())
|
||||||
val ruleSet = tileInfo.tileMap.gameInfo.ruleSet
|
|
||||||
descriptionLabel.setText(improvement.getDescription(ruleSet))
|
descriptionLabel.setText(improvement.getDescription(ruleSet))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,8 +104,8 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) :
|
|||||||
"Pick now!".toLabel().onClick { accept(improvement) }
|
"Pick now!".toLabel().onClick { accept(improvement) }
|
||||||
else "Current construction".toLabel()
|
else "Current construction".toLabel()
|
||||||
|
|
||||||
if (improvement.shortcutKey != null)
|
if (shortcutKey != null)
|
||||||
keyPressDispatcher[improvement.shortcutKey.toLowerCase()] = { accept(improvement) }
|
keyPressDispatcher[shortcutKey] = { accept(improvement) }
|
||||||
|
|
||||||
|
|
||||||
val statIcons = getStatIconsTable(provideResource, removeImprovement)
|
val statIcons = getStatIconsTable(provideResource, removeImprovement)
|
||||||
|
Reference in New Issue
Block a user