mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-30 15:30:43 -04: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. */
|
/** When moving towards a certain tech, the user doesn't have to manually pick every one. */
|
||||||
var techsToResearch = ArrayList<String>()
|
var techsToResearch = ArrayList<String>()
|
||||||
private var techsInProgress = HashMap<String, Int>()
|
|
||||||
var overflowScience = 0
|
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 */
|
/** In civ IV, you can auto-convert a certain percentage of gold in cities to science */
|
||||||
var goldPercentConvertedToScience = 0.6f
|
var goldPercentConvertedToScience = 0.6f
|
||||||
|
@ -17,10 +17,9 @@ import java.util.*
|
|||||||
import kotlin.collections.ArrayList
|
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 techNameToButton = HashMap<String, TechButton>()
|
||||||
private var isFreeTechPick: Boolean = false
|
|
||||||
private var selectedTech: Technology? = null
|
private var selectedTech: Technology? = null
|
||||||
private var civTech: TechManager = civInfo.tech
|
private var civTech: TechManager = civInfo.tech
|
||||||
private var tempTechsToResearch: ArrayList<String>
|
private var tempTechsToResearch: ArrayList<String>
|
||||||
@ -47,11 +46,6 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
|||||||
|
|
||||||
private val turnsToTech = civInfo.gameInfo.ruleSet.technologies.values.associateBy({ it.name }, { civTech.turnsToTech(it.name) })
|
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 {
|
init {
|
||||||
setDefaultCloseAction()
|
setDefaultCloseAction()
|
||||||
onBackButtonClicked { UncivGame.Current.setWorldScreen() }
|
onBackButtonClicked { UncivGame.Current.setWorldScreen() }
|
||||||
@ -65,7 +59,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
|||||||
rightSideButton.setText("Pick a tech".tr())
|
rightSideButton.setText("Pick a tech".tr())
|
||||||
rightSideButton.onClick(UncivSound.Paper) {
|
rightSideButton.onClick(UncivSound.Paper) {
|
||||||
game.settings.addCompletedTutorialTask("Pick technology")
|
game.settings.addCompletedTutorialTask("Pick technology")
|
||||||
if (isFreeTechPick) civTech.getFreeTechnology(selectedTech!!.name)
|
if (freeTechPick) civTech.getFreeTechnology(selectedTech!!.name)
|
||||||
else civTech.techsToResearch = tempTechsToResearch
|
else civTech.techsToResearch = tempTechsToResearch
|
||||||
|
|
||||||
game.setWorldScreen()
|
game.setWorldScreen()
|
||||||
@ -142,7 +136,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
|||||||
techButton.color = when {
|
techButton.color = when {
|
||||||
civTech.isResearched(techName) && techName != Constants.futureTech -> researchedTechColor
|
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
|
// 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
|
researchableTechs.contains(techName) -> researchableTechColor
|
||||||
tempTechsToResearch.contains(techName) -> queuedTechColor
|
tempTechsToResearch.contains(techName) -> queuedTechColor
|
||||||
else -> Color.GRAY
|
else -> Color.GRAY
|
||||||
@ -227,7 +221,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
|||||||
// center on technology
|
// center on technology
|
||||||
if (center) centerOnTechnology(tech)
|
if (center) centerOnTechnology(tech)
|
||||||
|
|
||||||
if (isFreeTechPick) {
|
if (freeTechPick) {
|
||||||
selectTechnologyForFreeTech(tech)
|
selectTechnologyForFreeTech(tech)
|
||||||
setButtonsInfo()
|
setButtonsInfo()
|
||||||
return
|
return
|
||||||
@ -262,10 +256,19 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
|||||||
tempTechsToResearch.clear()
|
tempTechsToResearch.clear()
|
||||||
tempTechsToResearch.addAll(pathToTech.map { it.name })
|
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()
|
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) {
|
private fun centerOnTechnology(tech: Technology) {
|
||||||
Gdx.app.postRunnable {
|
Gdx.app.postRunnable {
|
||||||
techNameToButton[tech.name]?.let {
|
techNameToButton[tech.name]?.let {
|
||||||
@ -275,10 +278,11 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, centerOnTech: Tec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun selectTechnologyForFreeTech(tech: Technology) {
|
private fun selectTechnologyForFreeTech(tech: Technology) {
|
||||||
if (researchableTechs.contains(tech.name)) {
|
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 {
|
} else {
|
||||||
rightSideButton.setText("Pick a free tech".tr())
|
rightSideButton.setText("Pick a free tech".tr())
|
||||||
rightSideButton.disable()
|
rightSideButton.disable()
|
||||||
|
@ -683,7 +683,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
|
|||||||
|
|
||||||
viewingCiv.shouldOpenTechPicker() ->
|
viewingCiv.shouldOpenTechPicker() ->
|
||||||
NextTurnAction("Pick a tech", Color.SKY) {
|
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()) ->
|
viewingCiv.policies.shouldOpenPolicyPicker || (viewingCiv.policies.freePolicies > 0 && viewingCiv.policies.canAdoptPolicy()) ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user