From f7bb5c4a5979c1f0841d193b0b2d5fc88d0e5ecd Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 17 Nov 2019 22:41:08 +0200 Subject: [PATCH] Added lines between prerequisite techs in TechPickerScreen - now you can see the entire tree! --- android/assets/jsons/Techs.json | 4 ++ .../ui/pickerscreens/TechPickerScreen.kt | 43 ++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/android/assets/jsons/Techs.json b/android/assets/jsons/Techs.json index 1d14690a75..1b67c94c25 100644 --- a/android/assets/jsons/Techs.json +++ b/android/assets/jsons/Techs.json @@ -22,21 +22,25 @@ { name:"Pottery", row:2, + prerequisites:["Agriculture"], quote:"'Shall the clay say to him that fashioneth it, what makest thou?' - Bible Isaiah 45:9" }, { name:"Animal Husbandry", row:5, + prerequisites:["Agriculture"], quote:"'Thou shalt not muzzle the ox when he treadeth out the corn.' - Bible Deuteronomy 25:4" }, { name:"Archery", 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" }, { name:"Mining", row:9, + prerequisites:["Agriculture"], quote:"'The meek shall inherit the Earth, but not its mineral rights.' - J. Paul Getty" } diff --git a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt index 3b41149f92..ad08d6c7ba 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt @@ -2,6 +2,8 @@ package com.unciv.ui.pickerscreens import com.badlogic.gdx.Gdx 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.unciv.Constants import com.unciv.UnCivGame @@ -21,6 +23,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, switchfromWorldSc private var selectedTech: Technology? = null private var civTech: TechManager = civInfo.tech private var tempTechsToResearch: ArrayList + private var lines=ArrayList() // All these are to counter performance problems when updating buttons for all techs. private var researchableTechs = GameBasics.Technologies.keys @@ -61,7 +64,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, switchfromWorldSc // Create tech table (row by row) for (i in 0..9) { - topTable.row().pad(5f) + topTable.row().pad(5f).padRight(40f) for (j in techMatrix.indices) { val tech = techMatrix[j][i] @@ -119,7 +122,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, switchfromWorldSc tempTechsToResearch.firstOrNull() == techName && !isFreeTechPick -> currentTechColor researchableTechs.contains(techName) && !civTech.isResearched(techName) -> researchableTechColor tempTechsToResearch.contains(techName) -> queuedTechColor - else -> Color.BLACK + else -> Color.GRAY } var text = techName.tr() @@ -137,6 +140,42 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo, switchfromWorldSc 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) {