Added lines between prerequisite techs in TechPickerScreen - now you can see the entire tree!

This commit is contained in:
Yair Morgenstern 2019-11-17 22:41:08 +02:00
parent 2d94cc2179
commit f7bb5c4a59
2 changed files with 45 additions and 2 deletions

View File

@ -22,21 +22,25 @@
{ {
name:"Pottery", name:"Pottery",
row:2, row:2,
prerequisites:["Agriculture"],
quote:"'Shall the clay say to him that fashioneth it, what makest thou?' - Bible Isaiah 45:9" quote:"'Shall the clay say to him that fashioneth it, what makest thou?' - Bible Isaiah 45:9"
}, },
{ {
name:"Animal Husbandry", name:"Animal Husbandry",
row:5, row:5,
prerequisites:["Agriculture"],
quote:"'Thou shalt not muzzle the ox when he treadeth out the corn.' - Bible Deuteronomy 25:4" quote:"'Thou shalt not muzzle the ox when he treadeth out the corn.' - Bible Deuteronomy 25:4"
}, },
{ {
name:"Archery", name:"Archery",
row:7, row:7,
prerequisites:["Agriculture"],
quote:"'The haft of the arrow has been feathered with one of the eagle's own plumes, we often give our enemies the means of our own destruction' - Aesop" quote:"'The haft of the arrow has been feathered with one of the eagle's own plumes, we often give our enemies the means of our own destruction' - Aesop"
}, },
{ {
name:"Mining", name:"Mining",
row:9, row:9,
prerequisites:["Agriculture"],
quote:"'The meek shall inherit the Earth, but not its mineral rights.' - J. Paul Getty" quote:"'The meek shall inherit the Earth, but not its mineral rights.' - J. Paul Getty"
} }

View File

@ -2,6 +2,8 @@ package com.unciv.ui.pickerscreens
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.unciv.Constants import com.unciv.Constants
import com.unciv.UnCivGame import com.unciv.UnCivGame
@ -21,6 +23,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, switchfromWorldSc
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>
private var lines=ArrayList<Image>()
// All these are to counter performance problems when updating buttons for all techs. // All these are to counter performance problems when updating buttons for all techs.
private var researchableTechs = GameBasics.Technologies.keys private var researchableTechs = GameBasics.Technologies.keys
@ -61,7 +64,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, switchfromWorldSc
// Create tech table (row by row) // Create tech table (row by row)
for (i in 0..9) { for (i in 0..9) {
topTable.row().pad(5f) topTable.row().pad(5f).padRight(40f)
for (j in techMatrix.indices) { for (j in techMatrix.indices) {
val tech = techMatrix[j][i] val tech = techMatrix[j][i]
@ -119,7 +122,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, switchfromWorldSc
tempTechsToResearch.firstOrNull() == techName && !isFreeTechPick -> currentTechColor tempTechsToResearch.firstOrNull() == techName && !isFreeTechPick -> currentTechColor
researchableTechs.contains(techName) && !civTech.isResearched(techName) -> researchableTechColor researchableTechs.contains(techName) && !civTech.isResearched(techName) -> researchableTechColor
tempTechsToResearch.contains(techName) -> queuedTechColor tempTechsToResearch.contains(techName) -> queuedTechColor
else -> Color.BLACK else -> Color.GRAY
} }
var text = techName.tr() var text = techName.tr()
@ -137,6 +140,42 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, switchfromWorldSc
techButton.text.setText(text) techButton.text.setText(text)
} }
addConnectingLines()
}
private fun addConnectingLines() {
topTable.pack() // Needed for the lines to work!
for (line in lines) line.remove()
lines.clear()
for (tech in GameBasics.Technologies.values) {
val techButton = techNameToButton[tech.name]!!
for (prerequisite in tech.prerequisites) {
val prerequisiteButton = techNameToButton[prerequisite]!!
val techButtonCoords = Vector2(0f, techButton.height / 2)
techButton.localToStageCoordinates(techButtonCoords)
topTable.stageToLocalCoordinates(techButtonCoords)
val prerequisiteCoords = Vector2(prerequisiteButton.width, prerequisiteButton.height / 2)
prerequisiteButton.localToStageCoordinates(prerequisiteCoords)
topTable.stageToLocalCoordinates(prerequisiteCoords)
val line = ImageGetter.getLine(techButtonCoords.x, techButtonCoords.y,
prerequisiteCoords.x, prerequisiteCoords.y, 2f)
val lineColor = when {
civTech.isResearched(tech.name) && tech.name != Constants.futureTech -> researchedTechColor
civTech.isResearched(prerequisite) -> researchableTechColor
else -> Color.GRAY
}
line.color = lineColor
topTable.addActor(line)
lines.add(line)
}
}
} }
private fun selectTechnology(tech: Technology?, center: Boolean = false, switchfromWorldScreen: Boolean = true) { private fun selectTechnology(tech: Technology?, center: Boolean = false, switchfromWorldScreen: Boolean = true) {