mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-03 22:22:51 +07:00
Generify hasGoldToBuy -> hasStatToBuy + fix condition (#8602)
Co-authored-by: tunerzinc@gmail.com <vfylfhby>
This commit is contained in:
parent
29ef6f1b86
commit
f6d89678b5
@ -697,11 +697,11 @@ class Civilization : IsPartOfGameInfoSerialization {
|
||||
}
|
||||
}
|
||||
|
||||
fun hasGoldToBuy(price: Int): Boolean {
|
||||
fun hasStatToBuy(stat: Stat, price: Int): Boolean {
|
||||
return when {
|
||||
gameInfo.gameParameters.godMode -> true
|
||||
price == 0 -> true
|
||||
else -> gold >= price
|
||||
else -> getStatReserve(stat) >= price
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class CityScreenTileTable(private val cityScreen: CityScreen): Table() {
|
||||
askToBuyTile(selectedTile)
|
||||
}
|
||||
buyTileButton.keyShortcuts.add('T')
|
||||
buyTileButton.isEnabled = cityScreen.canChangeState && city.civ.hasGoldToBuy(goldCostOfTile)
|
||||
buyTileButton.isEnabled = cityScreen.canChangeState && city.civ.hasStatToBuy(Stat.Gold, goldCostOfTile)
|
||||
buyTileButton.addTooltip('T') // The key binding is done in CityScreen constructor
|
||||
innerTable.add(buyTileButton).padTop(5f).row()
|
||||
}
|
||||
@ -113,9 +113,9 @@ class CityScreenTileTable(private val cityScreen: CityScreen): Table() {
|
||||
*/
|
||||
private fun askToBuyTile(selectedTile: Tile) {
|
||||
// These checks are redundant for the onClick action, but not for the keyboard binding
|
||||
if (!city.expansion.canBuyTile(selectedTile)) return
|
||||
if (!cityScreen.canChangeState || !city.expansion.canBuyTile(selectedTile)) return
|
||||
val goldCostOfTile = city.expansion.getGoldCostOfTile(selectedTile)
|
||||
if (!city.civ.hasGoldToBuy(goldCostOfTile)) return
|
||||
if (!city.civ.hasStatToBuy(Stat.Gold, goldCostOfTile)) return
|
||||
|
||||
cityScreen.closeAllPopups()
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.unciv.UncivGame
|
||||
import com.unciv.logic.city.City
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.ui.images.ImageGetter
|
||||
import com.unciv.ui.utils.extensions.addToCenter
|
||||
import com.unciv.ui.utils.extensions.darken
|
||||
@ -52,7 +53,7 @@ class CityTileGroup(private val city: City, tile: Tile, tileSetStrings: TileSetS
|
||||
label.y -= 15f
|
||||
|
||||
// Can be purchased now?
|
||||
if (!city.civ.hasGoldToBuy(price)) {
|
||||
if (!city.civ.hasStatToBuy(Stat.Gold, price)) {
|
||||
image.color = Color.WHITE.darken(0.5f)
|
||||
label.setFontColor(Color.RED)
|
||||
} else {
|
||||
@ -64,7 +65,6 @@ class CityTileGroup(private val city: City, tile: Tile, tileSetStrings: TileSetS
|
||||
// Out of city range
|
||||
tile !in city.tilesInRange -> {
|
||||
layerTerrain.dim(0.5f)
|
||||
layerMisc.setYieldVisible(UncivGame.Current.settings.showTileYields)
|
||||
layerMisc.dimYields(true)
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ class CityTileGroup(private val city: City, tile: Tile, tileSetStrings: TileSetS
|
||||
}
|
||||
|
||||
// Does not provide yields
|
||||
tile.stats.getTileStats(viewingCiv).isEmpty() -> {
|
||||
tile.stats.getTileStats(city.civ).isEmpty() -> {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user