diff --git a/core/src/com/unciv/logic/civilization/TechManager.kt b/core/src/com/unciv/logic/civilization/TechManager.kt index 5802642288..95abc39b73 100644 --- a/core/src/com/unciv/logic/civilization/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/TechManager.kt @@ -50,8 +50,9 @@ class TechManager { /** When moving towards a certain tech, the user doesn't have to manually pick every one. */ var techsToResearch = ArrayList() - private var techsInProgress = HashMap() var overflowScience = 0 + private var techsInProgress = HashMap() + fun scienceSpentOnTech(tech: String): Int = if (tech in techsInProgress) techsInProgress[tech]!! else 0 /** In civ IV, you can auto-convert a certain percentage of gold in cities to science */ var goldPercentConvertedToScience = 0.6f diff --git a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt index ecfab27d4e..5b795e54d8 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt @@ -17,10 +17,9 @@ import java.util.* import kotlin.collections.ArrayList -class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Technology? = null) : PickerScreen() { +class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Technology? = null, private val freeTechPick: Boolean = false) : PickerScreen() { private var techNameToButton = HashMap() - private var isFreeTechPick: Boolean = false private var selectedTech: Technology? = null private var civTech: TechManager = civInfo.tech private var tempTechsToResearch: ArrayList @@ -46,12 +45,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec private val turnsToTech = civInfo.gameInfo.ruleSet.technologies.values.associateBy({ it.name }, { civTech.turnsToTech(it.name) }) - - constructor(freeTechPick: Boolean, civInfo: CivilizationInfo) : this(civInfo) { - isFreeTechPick = freeTechPick - } - - + init { setDefaultCloseAction() onBackButtonClicked { UncivGame.Current.setWorldScreen() } @@ -65,7 +59,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec rightSideButton.setText("Pick a tech".tr()) rightSideButton.onClick(UncivSound.Paper) { game.settings.addCompletedTutorialTask("Pick technology") - if (isFreeTechPick) civTech.getFreeTechnology(selectedTech!!.name) + if (freeTechPick) civTech.getFreeTechnology(selectedTech!!.name) else civTech.techsToResearch = tempTechsToResearch game.setWorldScreen() @@ -142,7 +136,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec techButton.color = when { civTech.isResearched(techName) && techName != Constants.futureTech -> researchedTechColor // if we're here to pick a free tech, show the current tech like the rest of the researchables so it'll be obvious what we can pick - tempTechsToResearch.firstOrNull() == techName && !isFreeTechPick -> currentTechColor + tempTechsToResearch.firstOrNull() == techName && !freeTechPick -> currentTechColor researchableTechs.contains(techName) -> researchableTechColor tempTechsToResearch.contains(techName) -> queuedTechColor else -> Color.GRAY @@ -227,7 +221,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec // center on technology if (center) centerOnTechnology(tech) - if (isFreeTechPick) { + if (freeTechPick) { selectTechnologyForFreeTech(tech) setButtonsInfo() return @@ -262,9 +256,18 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec tempTechsToResearch.clear() tempTechsToResearch.addAll(pathToTech.map { it.name }) - pick("Research [${tempTechsToResearch[0]}]".tr()) + val label = "Research [${tempTechsToResearch[0]}]".tr() + val techProgression = getTechProgressLabel(tempTechsToResearch) + + pick("${label}\n${techProgression}") setButtonsInfo() } + + private fun getTechProgressLabel(techs: List): String { + val progress = techs.sumBy { tech -> civTech.scienceSpentOnTech(tech) } + val techCost = techs.sumBy { tech -> civInfo.gameInfo.ruleSet.technologies[tech]!!.cost } + return "(${progress}/${techCost})" + } private fun centerOnTechnology(tech: Technology) { Gdx.app.postRunnable { @@ -275,10 +278,11 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec } } - private fun selectTechnologyForFreeTech(tech: Technology) { if (researchableTechs.contains(tech.name)) { - pick("Pick [${selectedTech!!.name}] as free tech".tr()) + val label = "Pick [${tech.name}] as free tech".tr() + val techProgression = getTechProgressLabel(listOf(tech.name)) + pick("${label}\n${techProgression}") } else { rightSideButton.setText("Pick a free tech".tr()) rightSideButton.disable() diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index db688f2341..07707041e4 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -683,7 +683,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam viewingCiv.shouldOpenTechPicker() -> NextTurnAction("Pick a tech", Color.SKY) { - game.setScreen(TechPickerScreen(viewingCiv.tech.freeTechs != 0, viewingCiv)) + game.setScreen(TechPickerScreen(viewingCiv, null, viewingCiv.tech.freeTechs != 0)) } viewingCiv.policies.shouldOpenPolicyPicker || (viewingCiv.policies.freePolicies > 0 && viewingCiv.policies.canAdoptPolicy()) ->