Resolved #908 - added Science overview to overview screen

This commit is contained in:
Yair Morgenstern 2019-06-27 12:01:08 +03:00
parent 06d1bd6881
commit 8f0c3f1c02
4 changed files with 39 additions and 22 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.app" applicationId "com.unciv.app"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 28 targetSdkVersion 28
versionCode 263 versionCode 264
versionName "2.17.10-patch2" versionName "2.17.11"
} }
// Had to add this crap for Travis to build, it wanted to sign the app // Had to add this crap for Travis to build, it wanted to sign the app

View File

@ -20,6 +20,7 @@ import com.unciv.models.gamebasics.tech.TechEra
import com.unciv.models.gamebasics.tile.ResourceSupplyList import com.unciv.models.gamebasics.tile.ResourceSupplyList
import com.unciv.models.gamebasics.tile.ResourceType import com.unciv.models.gamebasics.tile.ResourceType
import com.unciv.models.stats.Stat import com.unciv.models.stats.Stat
import com.unciv.models.stats.StatMap
import com.unciv.models.stats.Stats import com.unciv.models.stats.Stats
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@ -138,10 +139,9 @@ class CivilizationInfo {
} }
fun getStatMapForNextTurn(): HashMap<String, Stats> { fun getStatMapForNextTurn(): HashMap<String, Stats> {
val statMap = HashMap<String,Stats>() val statMap = StatMap()
for (city in cities){ for (city in cities){
if(!statMap.containsKey("Cities")) statMap["Cities"]=Stats() statMap.add("Cities",city.cityStats.currentCityStats)
statMap["Cities"] = statMap["Cities"]!! + city.cityStats.currentCityStats
} }
//City states culture bonus //City states culture bonus
@ -150,17 +150,12 @@ class CivilizationInfo {
&& otherCiv.getDiplomacyManager(civName).relationshipLevel() >= RelationshipLevel.Friend) { && otherCiv.getDiplomacyManager(civName).relationshipLevel() >= RelationshipLevel.Friend) {
val cultureBonus = Stats() val cultureBonus = Stats()
cultureBonus.add(Stat.Culture, 3f * (getEra().ordinal+1)) cultureBonus.add(Stat.Culture, 3f * (getEra().ordinal+1))
if (statMap.containsKey("City States")) statMap.add("City States",cultureBonus)
statMap["City States"] = statMap["City States"]!! + cultureBonus
else
statMap["City States"] = cultureBonus
} }
} }
for (entry in getHappinessBreakdown()) { for (entry in getHappinessBreakdown()) {
if (!statMap.containsKey(entry.key)) statMap.add(entry.key,Stats().apply { happiness=entry.value })
statMap[entry.key] = Stats()
statMap[entry.key]!!.happiness += entry.value
} }
statMap["Transportation upkeep"] = Stats().apply { gold=- getTransportationUpkeep().toFloat()} statMap["Transportation upkeep"] = Stats().apply { gold=- getTransportationUpkeep().toFloat()}
@ -168,10 +163,7 @@ class CivilizationInfo {
if (policies.isAdopted("Mandate Of Heaven")) { if (policies.isAdopted("Mandate Of Heaven")) {
val happiness = statMap.values.map { it.happiness }.sum() val happiness = statMap.values.map { it.happiness }.sum()
if(happiness>0) { if(happiness>0) statMap.add("Policies",Stats().apply { culture=happiness/2 })
if (!statMap.containsKey("Policies")) statMap["Policies"] = Stats()
statMap["Policies"]!!.culture += happiness / 2
}
} }
// negative gold hurts science // negative gold hurts science

View File

@ -87,3 +87,10 @@ open class Stats() {
science=hashMap[Stat.Science]!! science=hashMap[Stat.Science]!!
} }
} }
class StatMap:LinkedHashMap<String,Stats>(){
fun add(source:String,stats:Stats){
if(!containsKey(source)) put(source,stats)
else put(source, get(source)!!+stats)
}
}

View File

@ -44,12 +44,12 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
val setStatsInfoButton = TextButton("Stats".tr(),skin) val setStatsInfoButton = TextButton("Stats".tr(),skin)
setStatsInfoButton.onClick { setStatsInfoButton.onClick {
centerTable.clear() centerTable.clear()
centerTable.add(ScrollPane(HorizontalGroup().apply { centerTable.add(ScrollPane(Table().apply {
space(40f) defaults().pad(40f)
top() add(getHappinessTable()).top()
addActor(getHappinessTable()) add(getGoldTable()).top()
addActor(getGoldTable()) add(getScienceTable()).top()
addActor(getGreatPeopleTable()) add(getGreatPeopleTable()).top()
})) }))
centerTable.pack() centerTable.pack()
} }
@ -169,6 +169,24 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
} }
private fun getScienceTable(): Table {
val scienceTable = Table(skin)
scienceTable.defaults().pad(5f)
scienceTable.add("Science".toLabel().setFontSize(24)).colspan(2).row()
scienceTable.addSeparator()
val scienceStats = currentPlayerCivInfo.getStatMapForNextTurn()
.filter { it.value.science!=0f }
for (entry in scienceStats) {
scienceTable.add(entry.key.tr())
scienceTable.add(entry.value.science.roundToInt().toString()).row()
}
scienceTable.add("Total".tr())
scienceTable.add(scienceStats.values.map { it.science }.sum().roundToInt().toString())
scienceTable.pack()
return scienceTable
}
private fun getGreatPeopleTable(): Table { private fun getGreatPeopleTable(): Table {
val greatPeopleTable = Table(skin) val greatPeopleTable = Table(skin)