mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 08:21:36 +07:00
added the ability to scroll the cities in cities overview screen (#187)
* added the ability to scroll the cities in cities overview screen * fixed the includes * shortned the code a bit
This commit is contained in:
@ -1,8 +1,7 @@
|
|||||||
package com.unciv.ui
|
package com.unciv.ui
|
||||||
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
|
||||||
import com.unciv.UnCivGame
|
import com.unciv.UnCivGame
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
@ -11,14 +10,15 @@ import kotlin.math.roundToInt
|
|||||||
class EmpireOverviewScreen : CameraStageBaseScreen(){
|
class EmpireOverviewScreen : CameraStageBaseScreen(){
|
||||||
init {
|
init {
|
||||||
val civInfo = UnCivGame.Current.gameInfo.getPlayerCivilization()
|
val civInfo = UnCivGame.Current.gameInfo.getPlayerCivilization()
|
||||||
|
|
||||||
val closeButton = TextButton("Close".tr(), skin)
|
val closeButton = TextButton("Close".tr(), skin)
|
||||||
|
|
||||||
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
|
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
|
||||||
closeButton.y = stage.height - closeButton.height - 5
|
closeButton.y = stage.height - closeButton.height - 5
|
||||||
stage.addActor(closeButton)
|
stage.addActor(closeButton)
|
||||||
|
|
||||||
val table=Table()
|
val table=Table()
|
||||||
table.defaults().pad(20f)
|
table.defaults().pad(20f)
|
||||||
|
|
||||||
table.add(getCityInfoTable(civInfo))
|
table.add(getCityInfoTable(civInfo))
|
||||||
table.add(getHappinessTable(civInfo))
|
table.add(getHappinessTable(civInfo))
|
||||||
table.add(getGoldTable(civInfo))
|
table.add(getGoldTable(civInfo))
|
||||||
@ -26,8 +26,6 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
|||||||
stage.addActor(table)
|
stage.addActor(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun getHappinessTable(civInfo: CivilizationInfo): Table {
|
private fun getHappinessTable(civInfo: CivilizationInfo): Table {
|
||||||
val happinessTable = Table(skin)
|
val happinessTable = Table(skin)
|
||||||
happinessTable.defaults().pad(5f)
|
happinessTable.defaults().pad(5f)
|
||||||
@ -60,39 +58,70 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getCityInfoTable(civInfo: CivilizationInfo): Table {
|
private fun getCityInfoTable(civInfo: CivilizationInfo): Table {
|
||||||
val cityInfotable = Table()
|
val iconSize = 20f//if you set this too low, there is a chance that the tables will be misaligned
|
||||||
cityInfotable.skin = skin
|
val padding = 5f
|
||||||
cityInfotable.defaults().pad(5f)
|
|
||||||
cityInfotable.add(Label("Cities", skin).setFont(24)).colspan(8).row()
|
val cityInfoTableIcons = Table(skin)
|
||||||
cityInfotable.add()
|
cityInfoTableIcons.defaults().pad(padding).align(Align.center)
|
||||||
cityInfotable.add(ImageGetter.getStatIcon("Population")).size(20f)
|
|
||||||
cityInfotable.add(ImageGetter.getStatIcon("Food")).size(20f)
|
cityInfoTableIcons.add(Label("Cities", skin).setFont(24)).colspan(8).align(Align.center).row()
|
||||||
cityInfotable.add(ImageGetter.getStatIcon("Gold")).size(20f)
|
cityInfoTableIcons.add()
|
||||||
cityInfotable.add(ImageGetter.getStatIcon("Science")).size(20f)
|
cityInfoTableIcons.add(ImageGetter.getStatIcon("Population")).size(iconSize)
|
||||||
cityInfotable.add(ImageGetter.getStatIcon("Production")).size(20f)
|
cityInfoTableIcons.add(ImageGetter.getStatIcon("Food")).size(iconSize)
|
||||||
cityInfotable.add(ImageGetter.getStatIcon("Culture")).size(20f)
|
cityInfoTableIcons.add(ImageGetter.getStatIcon("Gold")).size(iconSize)
|
||||||
cityInfotable.add(ImageGetter.getStatIcon("Happiness")).size(20f).row()
|
cityInfoTableIcons.add(ImageGetter.getStatIcon("Science")).size(iconSize)
|
||||||
|
cityInfoTableIcons.add(ImageGetter.getStatIcon("Production")).size(iconSize)
|
||||||
|
cityInfoTableIcons.add(ImageGetter.getStatIcon("Culture")).size(iconSize)
|
||||||
|
cityInfoTableIcons.add(ImageGetter.getStatIcon("Happiness")).size(iconSize)
|
||||||
|
cityInfoTableIcons.pack()
|
||||||
|
|
||||||
|
val cityInfoTableDetails = Table(skin)
|
||||||
|
cityInfoTableDetails.defaults().pad(padding).minWidth(iconSize).align(Align.left)//we need the min width so we can align the different tables
|
||||||
|
|
||||||
for (city in civInfo.cities) {
|
for (city in civInfo.cities) {
|
||||||
cityInfotable.add(city.name)
|
cityInfoTableDetails.add(city.name)
|
||||||
cityInfotable.add(city.population.population.toString())
|
cityInfoTableDetails.add(city.cityConstructions.getCityProductionTextForCityButton()).actor!!.setAlignment(Align.left)
|
||||||
cityInfotable.add(city.cityStats.currentCityStats.food.roundToInt().toString())
|
cityInfoTableDetails.add(city.population.population.toString()).actor!!.setAlignment(Align.center)
|
||||||
cityInfotable.add(city.cityStats.currentCityStats.gold.roundToInt().toString())
|
cityInfoTableDetails.add(city.cityStats.currentCityStats.food.roundToInt().toString()).actor!!.setAlignment(Align.center)
|
||||||
cityInfotable.add(city.cityStats.currentCityStats.science.roundToInt().toString())
|
cityInfoTableDetails.add(city.cityStats.currentCityStats.gold.roundToInt().toString()).actor!!.setAlignment(Align.center)
|
||||||
cityInfotable.add(city.cityStats.currentCityStats.production.roundToInt().toString())
|
cityInfoTableDetails.add(city.cityStats.currentCityStats.science.roundToInt().toString()).actor!!.setAlignment(Align.center)
|
||||||
cityInfotable.add(city.cityStats.currentCityStats.culture.roundToInt().toString())
|
cityInfoTableDetails.add(city.cityStats.currentCityStats.production.roundToInt().toString()).actor!!.setAlignment(Align.center)
|
||||||
cityInfotable.add(city.cityStats.currentCityStats.happiness.roundToInt().toString()).row()
|
cityInfoTableDetails.add(city.cityStats.currentCityStats.culture.roundToInt().toString()).actor!!.setAlignment(Align.center)
|
||||||
|
cityInfoTableDetails.add(city.cityStats.currentCityStats.happiness.roundToInt().toString()).actor!!.setAlignment(Align.center)
|
||||||
|
cityInfoTableDetails.row()
|
||||||
}
|
}
|
||||||
cityInfotable.add("Total")
|
cityInfoTableDetails.pack()
|
||||||
cityInfotable.add(civInfo.cities.sumBy { it.population.population }.toString())
|
|
||||||
cityInfotable.add("")
|
|
||||||
cityInfotable.add(civInfo.cities.sumBy { it.cityStats.currentCityStats.gold.toInt() }.toString())
|
|
||||||
cityInfotable.add(civInfo.cities.sumBy { it.cityStats.currentCityStats.science.toInt() }.toString())
|
|
||||||
cityInfotable.add("")
|
|
||||||
cityInfotable.add(civInfo.cities.sumBy { it.cityStats.currentCityStats.culture.toInt() }.toString())
|
|
||||||
cityInfotable.add(civInfo.cities.sumBy { it.cityStats.currentCityStats.happiness.toInt() }.toString())
|
|
||||||
|
|
||||||
cityInfotable.pack()
|
val cityInfoScrollPane = ScrollPane(cityInfoTableDetails)
|
||||||
return cityInfotable
|
cityInfoScrollPane.pack()
|
||||||
|
cityInfoScrollPane.setOverscroll(false, false)//I think it feels better with no overscroll
|
||||||
|
|
||||||
|
val cityInfoTableTotal = Table(skin)
|
||||||
|
cityInfoTableTotal.defaults().pad(padding).minWidth(iconSize)//we need the min width so we can align the different tables
|
||||||
|
|
||||||
|
cityInfoTableTotal.add("Total")
|
||||||
|
cityInfoTableTotal.add(civInfo.cities.sumBy { it.population.population }.toString()).actor!!.setAlignment(Align.center)
|
||||||
|
cityInfoTableTotal.add()//an intended empty space
|
||||||
|
cityInfoTableTotal.add(civInfo.cities.sumBy { it.cityStats.currentCityStats.gold.toInt() }.toString()).actor!!.setAlignment(Align.center)
|
||||||
|
cityInfoTableTotal.add(civInfo.cities.sumBy { it.cityStats.currentCityStats.science.toInt() }.toString()).actor!!.setAlignment(Align.center)
|
||||||
|
cityInfoTableTotal.add()//an intended empty space
|
||||||
|
cityInfoTableTotal.add(civInfo.cities.sumBy { it.cityStats.currentCityStats.culture.toInt() }.toString()).actor!!.setAlignment(Align.center)
|
||||||
|
cityInfoTableTotal.add(civInfo.cities.sumBy { it.cityStats.currentCityStats.happiness.toInt() }.toString()).actor!!.setAlignment(Align.center)
|
||||||
|
|
||||||
|
cityInfoTableTotal.pack()
|
||||||
|
|
||||||
|
val table = Table(skin)
|
||||||
|
//since the names of the cities are on the left, and the length of the names varies
|
||||||
|
//we align every row to the right, coz we set the size of the other(number) cells to the image size
|
||||||
|
//and thus, we can guarantee that the tables will be aligned
|
||||||
|
table.defaults().pad(padding).align(Align.right)
|
||||||
|
|
||||||
|
table.add(cityInfoTableIcons).row()
|
||||||
|
val height = if(cityInfoTableDetails.rows > 0) cityInfoTableDetails.getRowHeight(0)*4f else 100f //if there are no cities, set the height of the scroll pane to 100
|
||||||
|
table.add(cityInfoScrollPane).width(cityInfoTableDetails.width).height(height).row()
|
||||||
|
table.add(cityInfoTableTotal)
|
||||||
|
table.pack()
|
||||||
|
|
||||||
|
return table
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user