mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 03:18:18 +07:00
Resolved #3265 - added keyboard shortcuts to tile improvements
This commit is contained in:
parent
8c5e0d1889
commit
a6642cb536
@ -9,6 +9,7 @@
|
||||
"uniques": ["Can also be built on tiles adjacent to fresh water",
|
||||
"[+1 Food] on [fresh water] tiles once [Civil Service] is discovered",
|
||||
"[+1 Food] on [non-fresh water] tiles once [Fertilizer] is discovered"],
|
||||
"shortcutKey": "F"
|
||||
},
|
||||
{
|
||||
"name": "Lumber mill",
|
||||
@ -16,7 +17,8 @@
|
||||
"production": 1,
|
||||
"turnsToBuild": 7,
|
||||
"techRequired": "Construction",
|
||||
"uniques": ["[+1 Production] once [Scientific Theory] is discovered"]
|
||||
"uniques": ["[+1 Production] once [Scientific Theory] is discovered"],
|
||||
"shortcutKey": "L"
|
||||
},
|
||||
{
|
||||
"name": "Mine",
|
||||
@ -24,7 +26,8 @@
|
||||
"production": 1,
|
||||
"turnsToBuild": 7,
|
||||
"techRequired": "Mining",
|
||||
"uniques": ["[+1 Production] once [Chemistry] is discovered"]
|
||||
"uniques": ["[+1 Production] once [Chemistry] is discovered"],
|
||||
"shortcutKey": "M"
|
||||
},
|
||||
{
|
||||
"name": "Trading post",
|
||||
@ -32,7 +35,8 @@
|
||||
"gold": 1,
|
||||
"turnsToBuild": 7,
|
||||
"techRequired": "Guilds",
|
||||
"uniques": ["[+1 Gold] once [Economics] is discovered"]
|
||||
"uniques": ["[+1 Gold] once [Economics] is discovered"],
|
||||
"shortcutKey": "T"
|
||||
},
|
||||
|
||||
// Resource-specific
|
||||
@ -41,7 +45,8 @@
|
||||
"resourceTerrainAllow": ["Forest"],
|
||||
"turnsToBuild": 7,
|
||||
"techRequired": "Trapping",
|
||||
"uniques": ["[+1 Gold] once [Economics] is discovered"]
|
||||
"uniques": ["[+1 Gold] once [Economics] is discovered"],
|
||||
"shortcutKey": "C"
|
||||
},
|
||||
{
|
||||
"name": "Oil well",
|
||||
@ -52,20 +57,23 @@
|
||||
"name": "Pasture",
|
||||
"turnsToBuild": 8,
|
||||
"techRequired": "Animal Husbandry",
|
||||
"uniques": ["[+1 Food] once [Fertilizer] is discovered"]
|
||||
"uniques": ["[+1 Food] once [Fertilizer] is discovered"],
|
||||
"shortcutKey": "P"
|
||||
},
|
||||
{
|
||||
"name": "Plantation",
|
||||
"turnsToBuild": 6,
|
||||
"gold": 1,
|
||||
"techRequired": "Calendar",
|
||||
"uniques": ["[+1 Food] once [Fertilizer] is discovered"]
|
||||
"uniques": ["[+1 Food] once [Fertilizer] is discovered"],
|
||||
"shortcutKey": "P"
|
||||
},
|
||||
{
|
||||
"name": "Quarry",
|
||||
"turnsToBuild": 8,
|
||||
"techRequired": "Masonry",
|
||||
"uniques": ["[+1 Production] once [Chemistry] is discovered"]
|
||||
"uniques": ["[+1 Production] once [Chemistry] is discovered"],
|
||||
"shortcutKey": "Q"
|
||||
},
|
||||
{
|
||||
"name": "Fishing Boats",
|
||||
@ -81,7 +89,8 @@
|
||||
"terrainsCanBeBuiltOn": ["Plains","Grassland","Desert","Hill","Tundra","Snow","Forest","Jungle"],
|
||||
"turnsToBuild": 6,
|
||||
"techRequired": "Engineering",
|
||||
"uniques": ["Gives a defensive bonus of [50]%", "Can be built outside your borders"]
|
||||
"uniques": ["Gives a defensive bonus of [50]%", "Can be built outside your borders"],
|
||||
"shortcutKey": "O"
|
||||
},
|
||||
|
||||
// Transportation
|
||||
@ -89,7 +98,8 @@
|
||||
"name": "Road",
|
||||
"turnsToBuild": 4,
|
||||
"techRequired": "The Wheel",
|
||||
"uniques": ["Can be built outside your borders"]
|
||||
"uniques": ["Can be built outside your borders"],
|
||||
"shortcutKey": "R"
|
||||
},
|
||||
{
|
||||
"name": "Railroad",
|
||||
@ -104,28 +114,32 @@
|
||||
"turnsToBuild": 4,
|
||||
"terrainsCanBeBuiltOn": ["Forest"],
|
||||
"techRequired": "Mining",
|
||||
"uniques": ["Can be built outside your borders"]
|
||||
"uniques": ["Can be built outside your borders"],
|
||||
"shortcutKey": "X"
|
||||
},
|
||||
{
|
||||
"name": "Remove Jungle",
|
||||
"turnsToBuild": 7,
|
||||
"terrainsCanBeBuiltOn": ["Jungle"],
|
||||
"techRequired": "Bronze Working",
|
||||
"uniques": ["Can be built outside your borders"]
|
||||
"uniques": ["Can be built outside your borders"],
|
||||
"shortcutKey": "X"
|
||||
},
|
||||
{
|
||||
"name": "Remove Fallout",
|
||||
"turnsToBuild": 8,
|
||||
"terrainsCanBeBuiltOn": ["Fallout"],
|
||||
"techRequired": "Atomic Theory",
|
||||
"uniques": ["Can be built outside your borders"]
|
||||
"uniques": ["Can be built outside your borders"],
|
||||
"shortcutKey": "X"
|
||||
},
|
||||
{
|
||||
"name": "Remove Marsh",
|
||||
"turnsToBuild": 6,
|
||||
"terrainsCanBeBuiltOn": ["Marsh"],
|
||||
"techRequired": "Masonry",
|
||||
"uniques": ["Can be built outside your borders"]
|
||||
"uniques": ["Can be built outside your borders"],
|
||||
"shortcutKey": "X"
|
||||
},
|
||||
|
||||
// These are unique and have unique in-game checks related to them
|
||||
@ -178,7 +192,8 @@
|
||||
"culture": 1,
|
||||
"turnsToBuild": 4,
|
||||
"uniques": ["[+1 Culture] for each adjacent [Moai]", "Can only be built on Coastal tiles", "[+1 Gold] once [Flight] is discovered"],
|
||||
"techRequired": "Construction"
|
||||
"techRequired": "Construction",
|
||||
"shortcutKey": "M"
|
||||
},
|
||||
{
|
||||
"name": "Terrace farm",
|
||||
@ -189,7 +204,8 @@
|
||||
"uniques": ["[+1 Food] for each adjacent [Mountain]", "Cannot be built on bonus resource",
|
||||
"[+1 Food] on [fresh water] tiles once [Civil Service] is discovered",
|
||||
"[+1 Food] on [non-fresh water] tiles once [Fertilizer] is discovered"],
|
||||
"techRequired": "Construction"
|
||||
"techRequired": "Construction",
|
||||
"shortcutKey": "F"
|
||||
},
|
||||
|
||||
{ "name": "Ancient ruins" },
|
||||
|
@ -26,6 +26,7 @@ class TileImprovement : NamedStats() {
|
||||
var uniqueTo:String? = null
|
||||
var uniques = ArrayList<String>()
|
||||
val uniqueObjects:List<Unique> by lazy { uniques.map { Unique(it) } }
|
||||
val shortcutKey: Char? = null
|
||||
|
||||
val turnsToBuild: Int = 0 // This is the base cost.
|
||||
|
||||
|
@ -11,6 +11,7 @@ import com.unciv.UncivGame
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.ruleset.tile.TileImprovement
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.utils.*
|
||||
import kotlin.math.round
|
||||
@ -56,6 +57,7 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) :
|
||||
improvementButtonTable.add(image).size(30f).pad(10f)
|
||||
|
||||
var labelText = improvement.name.tr()
|
||||
if (improvement.shortcutKey != null) labelText += " (${improvement.shortcutKey})"
|
||||
val turnsToBuild = improvement.getTurnsToBuild(currentPlayerCiv)
|
||||
if (turnsToBuild > 0) labelText += " - $turnsToBuild${Fonts.turn}"
|
||||
val provideResource = tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == improvement.name
|
||||
@ -76,7 +78,11 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) :
|
||||
|
||||
val pickNow = "Pick now!".toLabel().onClick { accept(improvement) }
|
||||
|
||||
val statIcons = Table()
|
||||
if (improvement.shortcutKey != null)
|
||||
keyPressDispatcher[improvement.shortcutKey] = { accept(improvement) }
|
||||
|
||||
|
||||
val statIcons = getStatIconsTable(provideResource, removeImprovement)
|
||||
|
||||
// get benefits of the new improvement
|
||||
val stats = tileInfo.getImprovementStats(improvement, currentPlayerCiv, tileInfo.getCity())
|
||||
@ -87,43 +93,15 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) :
|
||||
stats.add(existingStats.times(-1.0f))
|
||||
}
|
||||
|
||||
// icons of benefits (food, gold, etc) by improvement
|
||||
val statsTable = Table()
|
||||
statsTable.defaults()
|
||||
for (stat in stats.toHashMap()) {
|
||||
val statValue = round(stat.value).toInt()
|
||||
if (statValue == 0) continue
|
||||
|
||||
statsTable.add(ImageGetter.getStatIcon(stat.key.name)).size(20f).padRight(3f)
|
||||
|
||||
val valueLabel = statValue.toString().toLabel()
|
||||
valueLabel.color = if (statValue < 0) Color.RED else Color.WHITE
|
||||
|
||||
statsTable.add(valueLabel).padRight(13f)
|
||||
}
|
||||
|
||||
// icon for adding the resource by improvement
|
||||
if (provideResource)
|
||||
statIcons.add(ImageGetter.getResourceImage(tileInfo.resource.toString(), 30f)).pad(3f)
|
||||
|
||||
// icon for removing the resource by replacing improvement
|
||||
if (removeImprovement && tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == tileInfo.improvement) {
|
||||
val crossedResource = Group()
|
||||
val cross = ImageGetter.getImage("OtherIcons/Close")
|
||||
cross.setSize(30f, 30f)
|
||||
cross.color = Color.RED
|
||||
val resourceIcon = ImageGetter.getResourceImage(tileInfo.resource.toString(), 30f)
|
||||
crossedResource.addActor(resourceIcon)
|
||||
crossedResource.addActor(cross)
|
||||
statIcons.add(crossedResource).padTop(30f).padRight(33f)
|
||||
}
|
||||
|
||||
val statsTable = getStatsTable(stats)
|
||||
statIcons.add(statsTable).padLeft(13f)
|
||||
|
||||
|
||||
regularImprovements.add(statIcons).align(Align.right)
|
||||
|
||||
val improvementButton = Button(skin)
|
||||
improvementButton.add(improvementButtonTable).pad(5f).fillY()
|
||||
if (improvement.name == tileInfo.improvementInProgress) improvementButton.color= Color.GREEN
|
||||
if (improvement.name == tileInfo.improvementInProgress) improvementButton.color = Color.GREEN
|
||||
regularImprovements.add(improvementButton)
|
||||
regularImprovements.add(pickNow).padLeft(10f)
|
||||
regularImprovements.row()
|
||||
@ -131,5 +109,43 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, val onAccept: ()->Unit) :
|
||||
|
||||
topTable.add(regularImprovements)
|
||||
}
|
||||
|
||||
private fun getStatIconsTable(provideResource: Boolean, removeImprovement: Boolean): Table {
|
||||
val statIcons = Table()
|
||||
|
||||
// icon for adding the resource by improvement
|
||||
if (provideResource)
|
||||
statIcons.add(ImageGetter.getResourceImage(tileInfo.resource.toString(), 30f)).pad(3f)
|
||||
|
||||
// icon for removing the resource by replacing improvement
|
||||
if (removeImprovement && tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == tileInfo.improvement) {
|
||||
val crossedResource = Group()
|
||||
val cross = ImageGetter.getImage("OtherIcons/Close")
|
||||
cross.setSize(30f, 30f)
|
||||
cross.color = Color.RED
|
||||
val resourceIcon = ImageGetter.getResourceImage(tileInfo.resource.toString(), 30f)
|
||||
crossedResource.addActor(resourceIcon)
|
||||
crossedResource.addActor(cross)
|
||||
statIcons.add(crossedResource).padTop(30f).padRight(33f)
|
||||
}
|
||||
return statIcons
|
||||
}
|
||||
|
||||
// icons of benefits (food, gold, etc) by improvement
|
||||
private fun getStatsTable(stats: Stats): Table {
|
||||
val statsTable = Table()
|
||||
for (stat in stats.toHashMap()) {
|
||||
val statValue = round(stat.value).toInt()
|
||||
if (statValue == 0) continue
|
||||
|
||||
statsTable.add(ImageGetter.getStatIcon(stat.key.name)).size(20f).padRight(3f)
|
||||
|
||||
val valueLabel = statValue.toString().toLabel()
|
||||
valueLabel.color = if (statValue < 0) Color.RED else Color.WHITE
|
||||
|
||||
statsTable.add(valueLabel).padRight(13f)
|
||||
}
|
||||
return statsTable
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user