* Refactoring: extracted "getImprovementStats" method * Display the icons for added/removed resources
This commit is contained in:
parent
b6e2b72b5c
commit
0143f6702d
2 changed files with 81 additions and 29 deletions
|
@ -199,25 +199,8 @@ open class TileInfo {
|
|||
}
|
||||
|
||||
val improvement = getTileImprovement()
|
||||
if (improvement != null) {
|
||||
if (hasViewableResource(observingCiv) && getTileResource().improvement == improvement.name)
|
||||
stats.add(getTileResource().improvementStats!!) // resource-specific improvement
|
||||
else
|
||||
stats.add(improvement) // basic improvement
|
||||
|
||||
if (improvement.improvingTech != null && observingCiv.tech.isResearched(improvement.improvingTech!!)) stats.add(improvement.improvingTechStats!!) // eg Chemistry for mines
|
||||
if (improvement.name == "Trading post" && city != null && city.civInfo.policies.isAdopted("Free Thought"))
|
||||
stats.science += 1f
|
||||
if (improvement.name == "Trading post" && city != null && city.civInfo.policies.isAdopted("Commerce Complete"))
|
||||
stats.gold += 1f
|
||||
if (containsGreatImprovement() && observingCiv.policies.isAdopted("Freedom Complete"))
|
||||
stats.add(improvement) // again, for the double effect
|
||||
if (containsGreatImprovement() && city != null && city.civInfo.nation.unique == "+2 Science for all specialists and Great Person tile improvements")
|
||||
stats.science += 2
|
||||
|
||||
if(improvement.uniques.contains("+1 additional Culture for each adjacent Moai"))
|
||||
stats.culture += neighbors.count{it.improvement=="Moai"}
|
||||
}
|
||||
if (improvement != null)
|
||||
stats.add(getImprovementStats(improvement, observingCiv, city))
|
||||
|
||||
if(city!=null && isWater && city.containsBuildingUnique("+1 gold from worked water tiles in city"))
|
||||
stats.gold += 1
|
||||
|
@ -235,6 +218,29 @@ open class TileInfo {
|
|||
return stats
|
||||
}
|
||||
|
||||
fun getImprovementStats(improvement: TileImprovement, observingCiv: CivilizationInfo, city: CityInfo?): Stats {
|
||||
val stats =
|
||||
if (hasViewableResource(observingCiv) && getTileResource().improvement == improvement.name)
|
||||
getTileResource().improvementStats!!.clone() // resource-specific improvement
|
||||
else
|
||||
improvement.clone() // basic improvement
|
||||
|
||||
if (improvement.improvingTech != null && observingCiv.tech.isResearched(improvement.improvingTech!!)) stats.add(improvement.improvingTechStats!!) // eg Chemistry for mines
|
||||
if (improvement.name == "Trading post" && city != null && city.civInfo.policies.isAdopted("Free Thought"))
|
||||
stats.science += 1f
|
||||
if (improvement.name == "Trading post" && city != null && city.civInfo.policies.isAdopted("Commerce Complete"))
|
||||
stats.gold += 1f
|
||||
if (containsGreatImprovement() && observingCiv.policies.isAdopted("Freedom Complete"))
|
||||
stats.add(improvement) // again, for the double effect
|
||||
if (containsGreatImprovement() && city != null && city.civInfo.nation.unique == "+2 Science for all specialists and Great Person tile improvements")
|
||||
stats.science += 2
|
||||
|
||||
if (improvement.uniques.contains("+1 additional Culture for each adjacent Moai"))
|
||||
stats.culture += neighbors.count { it.improvement == "Moai" }
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
/** Returns true if the [improvement] can be built on this [TileInfo] */
|
||||
fun canBuildImprovement(improvement: TileImprovement, civInfo: CivilizationInfo): Boolean {
|
||||
val topTerrain = getLastTerrain()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.unciv.ui.pickerscreens
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
|
@ -8,10 +10,8 @@ import com.unciv.logic.map.RoadStatus
|
|||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.ruleset.tile.TileImprovement
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.addSeparatorVertical
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.toLabel
|
||||
import com.unciv.ui.utils.*
|
||||
import kotlin.math.round
|
||||
|
||||
class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerScreen() {
|
||||
private var selectedImprovement: TileImprovement? = null
|
||||
|
@ -41,7 +41,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc
|
|||
for (improvement in tileInfo.tileMap.gameInfo.ruleSet.tileImprovements.values) {
|
||||
if (!tileInfo.canBuildImprovement(improvement, currentPlayerCiv)) continue
|
||||
if(improvement.name == tileInfo.improvement) continue
|
||||
if(improvement.name==tileInfo.improvementInProgress) continue
|
||||
if(improvement.name == tileInfo.improvementInProgress) continue
|
||||
|
||||
val group = Table()
|
||||
|
||||
|
@ -50,11 +50,11 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc
|
|||
group.add(image).size(30f).pad(10f)
|
||||
|
||||
var labelText = improvement.name.tr() + " - " + improvement.getTurnsToBuild(currentPlayerCiv) + " {turns}"
|
||||
if(tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == improvement.name)
|
||||
labelText += "\n"+"Provides [${tileInfo.resource}]".tr()
|
||||
if(tileInfo.improvement!=null && improvement.name!=RoadStatus.Road.name
|
||||
val provideResource = tileInfo.hasViewableResource(currentPlayerCiv) && tileInfo.getTileResource().improvement == improvement.name
|
||||
if (provideResource) labelText += "\n"+"Provides [${tileInfo.resource}]".tr()
|
||||
val removeImprovement = (improvement.name!=RoadStatus.Road.name
|
||||
&& improvement.name!=RoadStatus.Railroad.name && !improvement.name.startsWith("Remove"))
|
||||
labelText += "\n" + "Replaces [${tileInfo.improvement}]".tr()
|
||||
if (tileInfo.improvement!=null && removeImprovement) labelText += "\n" + "Replaces [${tileInfo.improvement}]".tr()
|
||||
|
||||
group.add(labelText.toLabel()).pad(10f)
|
||||
|
||||
|
@ -71,12 +71,58 @@ class ImprovementPickerScreen(tileInfo: TileInfo, onAccept: ()->Unit) : PickerSc
|
|||
accept(improvement)
|
||||
}
|
||||
|
||||
val improvementRow = Table()
|
||||
|
||||
// get benefits of the new improvement
|
||||
val stats = tileInfo.getImprovementStats(improvement, currentPlayerCiv, tileInfo.getCity())
|
||||
// subtract the benefits of the replaced improvement, if any
|
||||
val existingImprovement = tileInfo.getTileImprovement()
|
||||
if (existingImprovement!=null && removeImprovement)
|
||||
{
|
||||
val existingStats = tileInfo.getImprovementStats(existingImprovement, currentPlayerCiv, tileInfo.getCity())
|
||||
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)
|
||||
improvementRow.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)
|
||||
improvementRow.add(crossedResource).padTop(30f).padRight(33f)
|
||||
}
|
||||
|
||||
improvementRow.add(statsTable).padLeft(13f)
|
||||
|
||||
val improvementButton = Button(skin)
|
||||
improvementButton.add(group).padRight(10f).fillY()
|
||||
improvementButton.addSeparatorVertical()
|
||||
improvementButton.add(pickNow).padLeft(10f).fill()
|
||||
regularImprovements.addActor(improvementButton)
|
||||
improvementRow.add(improvementButton)
|
||||
|
||||
regularImprovements.addActor(improvementRow)
|
||||
}
|
||||
topTable.add(regularImprovements)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue