mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
General code cleanup - performance improvements on order in ||, StringBuilders replaced with line lists, added missing translations
This commit is contained in:
parent
d087a3f69a
commit
c359616824
@ -1168,6 +1168,8 @@
|
||||
Spanish:"Terreno inundable"
|
||||
}
|
||||
|
||||
"Impassible":{}
|
||||
|
||||
// Bonus Resources
|
||||
"Cattle":{
|
||||
Italian:"Bestiame"
|
||||
@ -3922,6 +3924,10 @@
|
||||
French:"Cuirassé"
|
||||
}
|
||||
|
||||
// Modern units
|
||||
"Landship":{}
|
||||
"Great War Infantry":{}
|
||||
|
||||
// Great units
|
||||
"Great Artist":{
|
||||
Italian:"Grande Artista"
|
||||
|
@ -246,11 +246,11 @@ class CityStats {
|
||||
if(roadType==RoadStatus.Road) return cityInfo.isConnectedToCapital // this transient is not applicable to connection via railroad.
|
||||
|
||||
val capitalTile = cityInfo.civInfo.getCapital().getCenterTile()
|
||||
val BFS = BFS(capitalTile){it.roadStatus == roadType}
|
||||
val bfs = BFS(capitalTile){it.roadStatus == roadType}
|
||||
|
||||
val cityTile = cityInfo.getCenterTile()
|
||||
BFS.stepUntilDestination(cityTile)
|
||||
return BFS.tilesReached.containsKey(cityTile)
|
||||
bfs.stepUntilDestination(cityTile)
|
||||
return bfs.tilesReached.containsKey(cityTile)
|
||||
}
|
||||
//endregion
|
||||
|
||||
|
@ -224,39 +224,41 @@ open class TileInfo {
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
val SB = StringBuilder()
|
||||
val isViewableToPlayer = UnCivGame.Current.gameInfo.getPlayerCivilization().viewableTiles.contains(this)
|
||||
|| UnCivGame.Current.viewEntireMapForDebug
|
||||
val lineList = ArrayList<String>() // more readable than StringBuilder, with same performance for our use-case
|
||||
val isViewableToPlayer = UnCivGame.Current.viewEntireMapForDebug
|
||||
|| UnCivGame.Current.gameInfo.getPlayerCivilization().viewableTiles.contains(this)
|
||||
|
||||
if (isCityCenter()) {
|
||||
val city = getCity()!!
|
||||
var cityString = city.name
|
||||
if(isViewableToPlayer) cityString += " ("+city.health+")"
|
||||
SB.appendln(cityString)
|
||||
if(city.civInfo.isPlayerCivilization() || UnCivGame.Current.viewEntireMapForDebug)
|
||||
SB.appendln(city.cityConstructions.getProductionForTileInfo())
|
||||
lineList += cityString
|
||||
if(UnCivGame.Current.viewEntireMapForDebug || city.civInfo.isPlayerCivilization())
|
||||
lineList += city.cityConstructions.getProductionForTileInfo()
|
||||
}
|
||||
SB.appendln(this.baseTerrain.tr())
|
||||
if (terrainFeature != null) SB.appendln(terrainFeature!!.tr())
|
||||
if (hasViewableResource(tileMap.gameInfo.getPlayerCivilization())) SB.appendln(resource!!.tr())
|
||||
if (roadStatus !== RoadStatus.None && !isCityCenter()) SB.appendln(roadStatus.toString().tr())
|
||||
if (improvement != null) SB.appendln(improvement!!.tr())
|
||||
if (improvementInProgress != null && isViewableToPlayer) SB.appendln("{$improvementInProgress} in ${this.turnsToImprovement} {turns}".tr())
|
||||
if (civilianUnit != null && isViewableToPlayer) SB.appendln(civilianUnit!!.name.tr()+" - "+civilianUnit!!.civInfo.civName.tr())
|
||||
lineList += baseTerrain.tr()
|
||||
if (terrainFeature != null) lineList += terrainFeature!!.tr()
|
||||
if (hasViewableResource(tileMap.gameInfo.getPlayerCivilization())) lineList += resource!!.tr()
|
||||
if (roadStatus !== RoadStatus.None && !isCityCenter()) lineList += roadStatus.toString().tr()
|
||||
if (improvement != null) lineList += improvement!!.tr()
|
||||
if (improvementInProgress != null && isViewableToPlayer)
|
||||
lineList += "{$improvementInProgress} in $turnsToImprovement {turns}".tr() // todo change to [] translation notation
|
||||
if (civilianUnit != null && isViewableToPlayer)
|
||||
lineList += civilianUnit!!.name.tr()+" - "+civilianUnit!!.civInfo.civName.tr()
|
||||
if(militaryUnit!=null && isViewableToPlayer){
|
||||
var milUnitString = militaryUnit!!.name.tr()
|
||||
if(militaryUnit!!.health<100) milUnitString += "(" + militaryUnit!!.health + ")"
|
||||
milUnitString += " - "+militaryUnit!!.civInfo.civName.tr()
|
||||
SB.appendln(milUnitString)
|
||||
lineList += milUnitString
|
||||
}
|
||||
if(getDefensiveBonus()!=0f){
|
||||
var defencePercentString = (getDefensiveBonus()*100).toInt().toString()+"%"
|
||||
if(!defencePercentString.startsWith("-")) defencePercentString = "+$defencePercentString"
|
||||
SB.appendln("[$defencePercentString] to unit defence".tr())
|
||||
lineList += "[$defencePercentString] to unit defence".tr()
|
||||
}
|
||||
if(getBaseTerrain().impassable) SB.appendln("Impassible")
|
||||
if(getBaseTerrain().impassable) lineList += "Impassible".tr()
|
||||
|
||||
return SB.toString().trim()
|
||||
return lineList.joinToString("\n")
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
@ -8,42 +8,60 @@ import java.util.*
|
||||
|
||||
class Technology : ICivilopedia {
|
||||
override val description: String
|
||||
get(){
|
||||
val SB=StringBuilder()
|
||||
for(unique in uniques) SB.appendln(unique.tr())
|
||||
get() {
|
||||
val lineList = ArrayList<String>() // more readable than StringBuilder, with same performance for our use-case
|
||||
for (unique in uniques) lineList += unique.tr()
|
||||
|
||||
val improvedImprovements = GameBasics.TileImprovements.values.filter { it.improvingTech==name }.groupBy { it.improvingTechStats.toString() }
|
||||
val improvedImprovements = GameBasics.TileImprovements.values
|
||||
.filter { it.improvingTech == name }.groupBy { it.improvingTechStats.toString() }
|
||||
for (improvement in improvedImprovements) {
|
||||
val impimpString = improvement.value.joinToString { it.name.tr() } +" {provide" + (if(improvement.value.size==1) "s" else "") +"} "+improvement.key
|
||||
SB.appendln(impimpString.tr())
|
||||
val impimpString = improvement.value.joinToString { it.name.tr() } +
|
||||
" {provide" + (if (improvement.value.size == 1) "s" else "") + "} " + improvement.key
|
||||
lineList += impimpString.tr()
|
||||
}
|
||||
|
||||
var enabledUnits = GameBasics.Units.values.filter { it.requiredTech==name && (it.uniqueTo==null || it.uniqueTo==UnCivGame.Current.gameInfo.getPlayerCivilization().civName) }
|
||||
val playerCiv = UnCivGame.Current.gameInfo.getPlayerCivilization().civName
|
||||
var enabledUnits = GameBasics.Units.values.filter {
|
||||
it.requiredTech == name &&
|
||||
(it.uniqueTo == null || it.uniqueTo == playerCiv)
|
||||
}
|
||||
val replacedUnits = enabledUnits.map { it.replaces }.filterNotNull()
|
||||
enabledUnits = enabledUnits.filter { it.name !in replacedUnits}
|
||||
if(enabledUnits.isNotEmpty()){
|
||||
SB.appendln("{Units enabled}: ")
|
||||
for(unit in enabledUnits)
|
||||
SB.appendln(" * "+unit.name.tr() + " ("+unit.getShortDescription()+")")
|
||||
enabledUnits = enabledUnits.filter { it.name !in replacedUnits }
|
||||
if (enabledUnits.isNotEmpty()) {
|
||||
lineList += "{Units enabled}: "
|
||||
for (unit in enabledUnits)
|
||||
lineList += " * " + unit.name.tr() + " (" + unit.getShortDescription() + ")"
|
||||
}
|
||||
|
||||
var enabledBuildings = GameBasics.Buildings.values.filter { it.requiredTech==name && (it.uniqueTo==null || it.uniqueTo==UnCivGame.Current.gameInfo.getPlayerCivilization().civName) }
|
||||
var enabledBuildings = GameBasics.Buildings.values.filter {
|
||||
it.requiredTech == name &&
|
||||
(it.uniqueTo == null || it.uniqueTo == playerCiv)
|
||||
}
|
||||
val replacedBuildings = enabledBuildings.map { it.replaces }.filterNotNull()
|
||||
enabledBuildings = enabledBuildings.filter { it.name !in replacedBuildings }
|
||||
val regularBuildings = enabledBuildings.filter { !it.isWonder }
|
||||
if(regularBuildings.isNotEmpty())
|
||||
SB.appendln("{Buildings enabled}: "+regularBuildings.map { "\n * "+it.name.tr() + " ("+it.getShortDescription()+")" }.joinToString())
|
||||
if (regularBuildings.isNotEmpty()) {
|
||||
lineList += "{Buildings enabled}: "
|
||||
for (building in regularBuildings)
|
||||
lineList += "* " + building.name.tr() + " (" + building.getShortDescription() + ")"
|
||||
}
|
||||
val wonders = enabledBuildings.filter { it.isWonder }
|
||||
if(wonders.isNotEmpty()) SB.appendln("{Wonders enabled}: "+wonders.map { "\n * "+it.name.tr()+ " ("+it.getShortDescription()+")" }.joinToString())
|
||||
if (wonders.isNotEmpty()) {
|
||||
lineList += "{Wonders enabled}: "
|
||||
for (wonder in wonders)
|
||||
lineList += " * " + wonder.name.tr() + " (" + wonder.getShortDescription() + ")"
|
||||
}
|
||||
|
||||
val revealedResource = GameBasics.TileResources.values.filter { it.revealedBy==name }.map { it.name }.firstOrNull() // can only be one
|
||||
if(revealedResource!=null) SB.appendln("Reveals [$revealedResource] on the map".tr())
|
||||
val revealedResource = GameBasics.TileResources.values.filter { it.revealedBy == name }.map { it.name }.firstOrNull() // can only be one
|
||||
if (revealedResource != null) lineList += "Reveals [$revealedResource] on the map".tr()
|
||||
|
||||
val tileImprovements = GameBasics.TileImprovements.values.filter { it.techRequired==name }
|
||||
if(tileImprovements.isNotEmpty()) SB.appendln("{Tile improvements enabled}: "+tileImprovements.map { it.name.tr() }.joinToString())
|
||||
val tileImprovements = GameBasics.TileImprovements.values.filter { it.techRequired == name }
|
||||
if (tileImprovements.isNotEmpty())
|
||||
lineList += "{Tile improvements enabled}: " + tileImprovements.map { it.name.tr() }.joinToString()
|
||||
|
||||
return SB.toString().trim().tr()
|
||||
return lineList.map { it.tr() }.joinToString("\n")
|
||||
}
|
||||
|
||||
lateinit var name: String
|
||||
|
||||
var cost: Int = 0
|
||||
|
@ -6,8 +6,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.enable
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.tr
|
||||
|
||||
class VictoryScreen : PickerScreen() {
|
||||
@ -90,10 +90,10 @@ class VictoryScreen : PickerScreen() {
|
||||
}
|
||||
|
||||
fun getMilestone(text:String, achieved:Boolean): TextButton {
|
||||
val TB = TextButton(text,skin)
|
||||
if(achieved) TB.setColor(Color.GREEN)
|
||||
else TB.setColor(Color.GRAY)
|
||||
return TB
|
||||
val textButton = TextButton(text,skin)
|
||||
if(achieved) textButton.color = Color.GREEN
|
||||
else textButton.color = Color.GRAY
|
||||
return textButton
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,13 +60,13 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
topTable.add() // empty cell
|
||||
|
||||
else {
|
||||
val TB = TechButton(tech.name,civTech)
|
||||
val techButton = TechButton(tech.name,civTech)
|
||||
|
||||
techNameToButton[tech.name] = TB
|
||||
TB.onClick {
|
||||
techNameToButton[tech.name] = techButton
|
||||
techButton.onClick {
|
||||
selectTechnology(tech)
|
||||
}
|
||||
topTable.add(TB)
|
||||
topTable.add(techButton)
|
||||
if(eras[j].text.toString()=="") eras[j].setText((tech.era().toString()+" era").tr())
|
||||
}
|
||||
}
|
||||
@ -93,19 +93,19 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
|
||||
private fun setButtonsInfo() {
|
||||
for (techName in techNameToButton.keys) {
|
||||
val TB = techNameToButton[techName]!!
|
||||
val techButton = techNameToButton[techName]!!
|
||||
when {
|
||||
civTech.isResearched(techName) && techName!="Future Tech" -> TB.color = researchedTechColor
|
||||
techsToResearch.isNotEmpty() && techsToResearch.first() == techName -> TB.color = currentTechColor
|
||||
techsToResearch.contains(techName) -> TB.color = queuedTechColor
|
||||
researchableTechs.contains(techName) -> TB.color = researchableTechColor
|
||||
else -> TB.color = Color.BLACK
|
||||
civTech.isResearched(techName) && techName!="Future Tech" -> techButton.color = researchedTechColor
|
||||
techsToResearch.isNotEmpty() && techsToResearch.first() == techName -> techButton.color = currentTechColor
|
||||
techsToResearch.contains(techName) -> techButton.color = queuedTechColor
|
||||
researchableTechs.contains(techName) -> techButton.color = researchableTechColor
|
||||
else -> techButton.color = Color.BLACK
|
||||
}
|
||||
|
||||
var text = techName.tr()
|
||||
|
||||
if (techName == selectedTech?.name) {
|
||||
TB.color = TB.color.cpy().lerp(Color.LIGHT_GRAY, 0.5f)
|
||||
techButton.color = techButton.color.cpy().lerp(Color.LIGHT_GRAY, 0.5f)
|
||||
}
|
||||
|
||||
if (techsToResearch.contains(techName) && techsToResearch.size > 1) {
|
||||
@ -115,7 +115,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
if (!civTech.isResearched(techName) || techName=="Future Tech")
|
||||
text += "\r\n" + turnsToTech[techName] + " {turns}".tr()
|
||||
|
||||
TB.text.setText(text)
|
||||
techButton.text.setText(text)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,8 +122,8 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
||||
|
||||
open fun update(isViewable: Boolean, showResourcesAndImprovements:Boolean) {
|
||||
hideCircle()
|
||||
if (!tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)
|
||||
&& !UnCivGame.Current.viewEntireMapForDebug) {
|
||||
if (!UnCivGame.Current.viewEntireMapForDebug
|
||||
&& !tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)) {
|
||||
hexagon.color = Color.BLACK
|
||||
return
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
||||
&& city!!.civInfo.isPlayerCivilization())
|
||||
addPopulationIcon()
|
||||
|
||||
if (tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)
|
||||
|| UnCivGame.Current.viewEntireMapForDebug)
|
||||
if (UnCivGame.Current.viewEntireMapForDebug
|
||||
|| tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position))
|
||||
updateCityButton(city, isViewable || UnCivGame.Current.viewEntireMapForDebug) // needs to be before the update so the units will be above the city button
|
||||
|
||||
super.update(isViewable || UnCivGame.Current.viewEntireMapForDebug,
|
||||
|
@ -71,8 +71,8 @@ object ImageGetter {
|
||||
}
|
||||
|
||||
val foodCircleColor = colorFromRGB(129, 199, 132)// .GREEN.cpy().lerp(Color.WHITE,0.5f)
|
||||
val productionCircleColor = Color.BROWN.cpy().lerp(Color.WHITE,0.5f)
|
||||
val goldCircleColor = Color.GOLD.cpy().lerp(Color.WHITE,0.5f)
|
||||
val productionCircleColor = Color.BROWN.cpy().lerp(Color.WHITE,0.5f)!!
|
||||
val goldCircleColor = Color.GOLD.cpy().lerp(Color.WHITE,0.5f)!!
|
||||
fun getImprovementIcon(improvementName:String, size:Float=20f):Actor{
|
||||
val iconGroup = getImage("ImprovementIcons/$improvementName").surroundWithCircle(size)
|
||||
|
||||
|
@ -76,9 +76,12 @@ class Minimap(val tileMapHolder: TileMapHolder) : ScrollPane(null){
|
||||
val exploredTiles = cloneCivilization.exploredTiles
|
||||
for(tileInfo in tileMapHolder.tileMap.values) {
|
||||
val hex = tileImages[tileInfo]!!
|
||||
if (!(exploredTiles.contains(tileInfo.position) || UnCivGame.Current.viewEntireMapForDebug)) hex.color = Color.BLACK
|
||||
else if (tileInfo.isCityCenter() && !tileInfo.isWater()) hex.color = tileInfo.getOwner()!!.getNation().getSecondaryColor()
|
||||
else if (tileInfo.getCity() != null && !tileInfo.isWater()) hex.color = tileInfo.getOwner()!!.getNation().getColor()
|
||||
if (!(UnCivGame.Current.viewEntireMapForDebug || exploredTiles.contains(tileInfo.position)))
|
||||
hex.color = Color.BLACK
|
||||
else if (tileInfo.isCityCenter() && !tileInfo.isWater())
|
||||
hex.color = tileInfo.getOwner()!!.getNation().getSecondaryColor()
|
||||
else if (tileInfo.getCity() != null && !tileInfo.isWater())
|
||||
hex.color = tileInfo.getOwner()!!.getNation().getColor()
|
||||
else hex.color = tileInfo.getBaseTerrain().getColor().lerp(Color.GRAY, 0.5f)
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
for (tileGroup in tileGroups.values){
|
||||
tileGroup.update(playerViewableTilePositions.contains(tileGroup.tileInfo.position))
|
||||
val unitsInTile = tileGroup.tileInfo.getUnits()
|
||||
if((playerViewableTilePositions.contains(tileGroup.tileInfo.position) || UnCivGame.Current.viewEntireMapForDebug)
|
||||
if((UnCivGame.Current.viewEntireMapForDebug || playerViewableTilePositions.contains(tileGroup.tileInfo.position))
|
||||
&& unitsInTile.isNotEmpty() && !unitsInTile.first().civInfo.isPlayerCivilization())
|
||||
tileGroup.showCircle(Color.RED) // Display ALL viewable enemies with a red circle so that users don't need to go "hunting" for enemy units
|
||||
}
|
||||
@ -192,7 +192,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
for (tile in attackableTiles.filter {
|
||||
it.getUnits().isNotEmpty()
|
||||
&& it.getUnits().first().owner != unit.owner
|
||||
&& (playerViewableTilePositions.contains(it.position) || UnCivGame.Current.viewEntireMapForDebug)}) {
|
||||
&& (UnCivGame.Current.viewEntireMapForDebug || playerViewableTilePositions.contains(it.position))}) {
|
||||
if(unit.type.isCivilian()) tileGroups[tile]!!.hideCircle()
|
||||
else {
|
||||
tileGroups[tile]!!.showCircle(colorFromRGB(237, 41, 57))
|
||||
|
@ -43,8 +43,10 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
||||
|
||||
val defender: ICombatant? = Battle(worldScreen.gameInfo).getMapCombatantOfTile(selectedTile)
|
||||
|
||||
if(defender==null || defender.getCivilization()==worldScreen.civInfo
|
||||
|| !(attacker.getCivilization().exploredTiles.contains(selectedTile.position) || UnCivGame.Current.viewEntireMapForDebug)) {
|
||||
if(defender==null ||
|
||||
defender.getCivilization()==worldScreen.civInfo
|
||||
|| !(UnCivGame.Current.viewEntireMapForDebug
|
||||
|| attacker.getCivilization().exploredTiles.contains(selectedTile.position))) {
|
||||
hide()
|
||||
return
|
||||
}
|
||||
@ -57,7 +59,6 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
||||
|
||||
val attackerNameWrapper = Table()
|
||||
val attackerLabel = Label(attacker.getName(), skin)
|
||||
// .setFontColor(attacker.getCivilization().getNation().getColor())
|
||||
attackerNameWrapper.add(ImageGetter.getUnitImage(attacker.unit,25f)).padRight(5f)
|
||||
attackerNameWrapper.add(attackerLabel)
|
||||
add(attackerNameWrapper)
|
||||
|
@ -19,7 +19,7 @@ class TileInfoTable(private val worldScreen: WorldScreen) : Table() {
|
||||
val civInfo = worldScreen.civInfo
|
||||
columnDefaults(0).padRight(10f)
|
||||
|
||||
if (civInfo.exploredTiles.contains(tile.position) || UnCivGame.Current.viewEntireMapForDebug) {
|
||||
if (UnCivGame.Current.viewEntireMapForDebug || civInfo.exploredTiles.contains(tile.position)) {
|
||||
add(getStatsTable(tile)).pad(10f)
|
||||
add(Label(tile.toString(), skin)).colspan(2)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user