mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-06 07:31:26 +07:00
Research Tech Button shows progress; Small bug fix (#4303)
* "Research" button now shows progress in the selected tech * Current tech is automtically selected as free tech when applicable * Implemented requested changes
This commit is contained in:
parent
a0cf30831c
commit
c1e92225c9
@ -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<String>()
|
||||
private var techsInProgress = HashMap<String, Int>()
|
||||
var overflowScience = 0
|
||||
private var techsInProgress = HashMap<String, Int>()
|
||||
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
|
||||
|
@ -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<String, TechButton>()
|
||||
private var isFreeTechPick: Boolean = false
|
||||
private var selectedTech: Technology? = null
|
||||
private var civTech: TechManager = civInfo.tech
|
||||
private var tempTechsToResearch: ArrayList<String>
|
||||
@ -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>): 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()
|
||||
|
@ -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()) ->
|
||||
|
Loading…
Reference in New Issue
Block a user