mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04:00
Added Civ strategic resources to top of screen
This commit is contained in:
parent
c3a51460b7
commit
a230676325
@ -6,6 +6,7 @@ import com.unciv.logic.map.RoadStatus
|
|||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.logic.map.TileMap
|
import com.unciv.logic.map.TileMap
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
|
import com.unciv.models.gamebasics.ResourceType
|
||||||
import com.unciv.models.gamebasics.TileResource
|
import com.unciv.models.gamebasics.TileResource
|
||||||
import com.unciv.models.linq.Counter
|
import com.unciv.models.linq.Counter
|
||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
@ -42,8 +43,11 @@ class CityInfo {
|
|||||||
|
|
||||||
for (tileInfo in getTiles().filter { it.resource != null }) {
|
for (tileInfo in getTiles().filter { it.resource != null }) {
|
||||||
val resource = tileInfo.tileResource
|
val resource = tileInfo.tileResource
|
||||||
if (resource.improvement == tileInfo.improvement || tileInfo.isCityCenter())
|
if (resource.improvement == tileInfo.improvement || tileInfo.isCityCenter()){
|
||||||
cityResources.add(resource, 1)
|
if(resource.resourceType == ResourceType.Strategic) cityResources.add(resource, 2)
|
||||||
|
else cityResources.add(resource, 1)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (building in cityConstructions.getBuiltBuildings().filter { it.requiredResource != null }) {
|
for (building in cityConstructions.getBuiltBuildings().filter { it.requiredResource != null }) {
|
||||||
|
@ -1,55 +1,85 @@
|
|||||||
package com.unciv.ui.worldscreen
|
package com.unciv.ui.worldscreen
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
|
import com.unciv.models.gamebasics.ResourceType
|
||||||
import com.unciv.ui.cityscreen.addClickListener
|
import com.unciv.ui.cityscreen.addClickListener
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
|
|
||||||
class CivStatsTable : Table {
|
class CivStatsTable(val screen: WorldScreen) : Table() {
|
||||||
|
|
||||||
private val turnsLabel = Label("Turns: 0/400", CameraStageBaseScreen.skin)
|
private val turnsLabel = Label("Turns: 0/400", CameraStageBaseScreen.skin)
|
||||||
private val goldLabel = Label("Gold:",CameraStageBaseScreen.skin)
|
private val goldLabel = Label("Gold:",CameraStageBaseScreen.skin)
|
||||||
private val scienceLabel = Label("Science:",CameraStageBaseScreen.skin)
|
private val scienceLabel = Label("Science:",CameraStageBaseScreen.skin)
|
||||||
private val happinessLabel = Label("Happiness:",CameraStageBaseScreen.skin)
|
private val happinessLabel = Label("Happiness:",CameraStageBaseScreen.skin)
|
||||||
private val cultureLabel = Label("Culture:",CameraStageBaseScreen.skin)
|
private val cultureLabel = Label("Culture:",CameraStageBaseScreen.skin)
|
||||||
|
private val resourceLabels = HashMap<String, Label>()
|
||||||
|
private val resourceImages = HashMap<String, Image>()
|
||||||
|
|
||||||
|
init{
|
||||||
internal constructor(screen: WorldScreen){
|
|
||||||
val civBackground = ImageGetter.getDrawable("skin/civTableBackground.png")
|
val civBackground = ImageGetter.getDrawable("skin/civTableBackground.png")
|
||||||
background = civBackground.tint(Color(0x004085bf))
|
background = civBackground.tint(Color(0x004085e0))
|
||||||
addCivilopediaButton(screen)
|
|
||||||
add(turnsLabel)
|
val resourceTable = Table()
|
||||||
add(goldLabel)
|
resourceTable.defaults().pad(10f)
|
||||||
scienceLabel.setAlignment(Align.center)
|
val revealedStrategicResources = GameBasics.TileResources.values
|
||||||
add(scienceLabel)
|
.filter { it.resourceType== ResourceType.Strategic} // && civInfo.tech.isResearched(it.revealedBy!!) }
|
||||||
happinessLabel.setAlignment(Align.center)
|
for(resource in revealedStrategicResources){
|
||||||
add(happinessLabel)
|
val fileName = "ResourceIcons/${resource.name}_(Civ5).png"
|
||||||
cultureLabel.setAlignment(Align.center)
|
val resourceImage = ImageGetter.getImage(fileName)
|
||||||
add(cultureLabel)
|
resourceImages.put(resource.name,resourceImage)
|
||||||
|
resourceTable.add(resourceImage).size(20f)
|
||||||
|
val resourceLabel = Label("0",CameraStageBaseScreen.skin)
|
||||||
|
resourceLabels.put(resource.name, resourceLabel)
|
||||||
|
resourceTable.add(resourceLabel)
|
||||||
|
}
|
||||||
|
add(resourceTable).row()
|
||||||
|
|
||||||
|
|
||||||
|
val statsTable = Table()
|
||||||
|
statsTable.defaults().padRight(20f).padBottom(10f)
|
||||||
|
statsTable.add(getMenuButton())
|
||||||
|
statsTable.add(turnsLabel)
|
||||||
|
statsTable.add(goldLabel)
|
||||||
|
statsTable.add(scienceLabel.apply { setAlignment(Align.center) })
|
||||||
|
statsTable.add(happinessLabel.apply { setAlignment(Align.center) })
|
||||||
|
statsTable.add(cultureLabel.apply { setAlignment(Align.center) })
|
||||||
|
add(statsTable)
|
||||||
|
|
||||||
pack()
|
pack()
|
||||||
width = screen.stage.width - 20
|
width = screen.stage.width - 20
|
||||||
|
statsTable.width = width
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun addCivilopediaButton(screen: WorldScreen){
|
internal fun getMenuButton(): TextButton {
|
||||||
row().pad(15f)
|
val menuButton = TextButton("Menu", CameraStageBaseScreen.skin)
|
||||||
val civilopediaButton = TextButton("Menu", CameraStageBaseScreen.skin)
|
menuButton.addClickListener {
|
||||||
civilopediaButton.addClickListener {
|
|
||||||
screen.optionsTable.isVisible = !screen.optionsTable.isVisible
|
screen.optionsTable.isVisible = !screen.optionsTable.isVisible
|
||||||
}
|
}
|
||||||
civilopediaButton.label.setFontScale(screen.buttonScale)
|
return menuButton
|
||||||
add(civilopediaButton)
|
|
||||||
.size(civilopediaButton.width * screen.buttonScale, civilopediaButton.height * screen.buttonScale)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal fun update(screen: WorldScreen) {
|
internal fun update() {
|
||||||
val civInfo = screen.civInfo
|
val civInfo = screen.civInfo
|
||||||
|
|
||||||
|
val revealedStrategicResources = GameBasics.TileResources.values
|
||||||
|
.filter { it.resourceType== ResourceType.Strategic} // && }
|
||||||
|
val civResources = civInfo.getCivResources()
|
||||||
|
for(resource in revealedStrategicResources){
|
||||||
|
val isRevealed = civInfo.tech.isResearched(resource.revealedBy!!)
|
||||||
|
resourceLabels[resource.name]!!.isVisible = isRevealed
|
||||||
|
resourceImages[resource.name]!!.isVisible = isRevealed
|
||||||
|
if(!civResources.containsKey(resource)) resourceLabels[resource.name]!!.setText("0")
|
||||||
|
else resourceLabels[resource.name]!!.setText(civResources[resource]!!.toString())
|
||||||
|
}
|
||||||
|
|
||||||
turnsLabel.setText("Turns: " + civInfo.gameInfo.turns + "/400")
|
turnsLabel.setText("Turns: " + civInfo.gameInfo.turns + "/400")
|
||||||
|
|
||||||
val nextTurnStats = civInfo.getStatsForNextTurn()
|
val nextTurnStats = civInfo.getStatsForNextTurn()
|
||||||
|
@ -75,7 +75,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
|
|
||||||
unitTable.update() // has to come before tilemapholder update because the tilemapholder actions depend on the selected unit!
|
unitTable.update() // has to come before tilemapholder update because the tilemapholder actions depend on the selected unit!
|
||||||
tileMapHolder.updateTiles()
|
tileMapHolder.updateTiles()
|
||||||
civTable.update(this)
|
civTable.update()
|
||||||
notificationsScroll.update()
|
notificationsScroll.update()
|
||||||
notificationsScroll.width = stage.width/3
|
notificationsScroll.width = stage.width/3
|
||||||
notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f,
|
notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user