Merged all tables at the bottom of the screen to a single bar

This commit is contained in:
Yair Morgenstern 2018-05-17 18:09:00 +03:00
parent 4267d5b1be
commit 7155bfb927
9 changed files with 70 additions and 62 deletions

View File

@ -26,8 +26,7 @@ open class CameraStageBaseScreen : Screen {
private var isTutorialShowing = false private var isTutorialShowing = false
init { init {
stage = Stage(ExtendViewport(1000f, 600f stage = Stage(ExtendViewport(1500f, 900f), batch)// FitViewport(1000,600)
), batch)// FitViewport(1000,600)
Gdx.input.inputProcessor = stage Gdx.input.inputProcessor = stage
} }

View File

@ -1,6 +1,5 @@
package com.unciv.ui.worldscreen package com.unciv.ui.worldscreen
import com.badlogic.gdx.graphics.Color
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
@ -21,22 +20,24 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
private val battle = Battle(worldScreen.civInfo.gameInfo) private val battle = Battle(worldScreen.civInfo.gameInfo)
init{ init{
skin = CameraStageBaseScreen.skin skin = CameraStageBaseScreen.skin
background = ImageGetter.getDrawable(ImageGetter.WhiteDot)
.tint(ImageGetter.getBlue())
pad(10f) pad(10f)
} }
fun hide(){ fun hide(){
clear() clear()
background=null
} }
fun update() { fun update() {
if (worldScreen.unitTable.selectedUnit == null val unitTable = worldScreen.bottomBar.unitTable
|| worldScreen.unitTable.selectedUnit!!.getBaseUnit().unitType == UnitType.Civilian){ if (unitTable.selectedUnit == null
|| unitTable.selectedUnit!!.getBaseUnit().unitType == UnitType.Civilian){
hide() hide()
return return
} // no attacker } // no attacker
val attacker = MapUnitCombatant(worldScreen.unitTable.selectedUnit!!) val attacker = MapUnitCombatant(unitTable.selectedUnit!!)
if (worldScreen.tileMapHolder.selectedTile == null) return if (worldScreen.tileMapHolder.selectedTile == null) return
val selectedTile = worldScreen.tileMapHolder.selectedTile!! val selectedTile = worldScreen.tileMapHolder.selectedTile!!
@ -118,7 +119,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
row().pad(5f) row().pad(5f)
val attackButton = TextButton("Attack", skin) val attackButton = TextButton("Attack", skin)
val attackerDistanceToTiles = attacker.unit.getDistanceToTiles() attacker.unit.getDistanceToTiles()
val attackerCanReachDefender = UnitAutomation().getAttackableEnemies(attacker.unit) val attackerCanReachDefender = UnitAutomation().getAttackableEnemies(attacker.unit)
.contains(defender.getTile()) .contains(defender.getTile())
@ -137,12 +138,6 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
pack() pack()
val tileTableBackground = ImageGetter.getDrawable("skin/tileTableBackground.png")
.tint(Color(0x004085ff))
tileTableBackground.minHeight = 0f
tileTableBackground.minWidth = 0f
background = tileTableBackground
setPosition(worldScreen.stage.width/2-width/2, 5f) setPosition(worldScreen.stage.width/2-width/2, 5f)
} }

View File

@ -1,26 +1,17 @@
package com.unciv.ui.worldscreen package com.unciv.ui.worldscreen
import com.badlogic.gdx.graphics.Color
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.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
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 TileInfoTable(private val worldScreen: WorldScreen, internal val civInfo: CivilizationInfo) : Table() { class TileInfoTable(private val worldScreen: WorldScreen) : Table() {
init {
val tileTableBackground = ImageGetter.getDrawable("skin/tileTableBackground.png")
.tint(Color(0x004085bf))
tileTableBackground.minHeight = 0f
tileTableBackground.minWidth = 0f
background = tileTableBackground
}
internal fun updateTileTable(tile: TileInfo) { internal fun updateTileTable(tile: TileInfo) {
clearChildren() clearChildren()
val civInfo = worldScreen.civInfo
val stats = tile.getTileStats(civInfo) val stats = tile.getTileStats(civInfo)
pad(20f) pad(20f)
columnDefaults(0).padRight(10f) columnDefaults(0).padRight(10f)

View File

@ -34,7 +34,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
worldScreen.displayTutorials("TileClicked") worldScreen.displayTutorials("TileClicked")
selectedTile = tileInfo selectedTile = tileInfo
worldScreen.unitTable.tileSelected(tileInfo) worldScreen.bottomBar.unitTable.tileSelected(tileInfo)
worldScreen.update() worldScreen.update()
} }
@ -98,8 +98,8 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
} }
} }
if(worldScreen.unitTable.selectedUnit!=null){ if(worldScreen.bottomBar.unitTable.selectedUnit!=null){
val unit = worldScreen.unitTable.selectedUnit!! val unit = worldScreen.bottomBar.unitTable.selectedUnit!!
tileGroups[unit.getTile()]!!.addWhiteCircleAroundUnit() tileGroups[unit.getTile()]!!.addWhiteCircleAroundUnit()
val attackableTiles:List<TileInfo> val attackableTiles:List<TileInfo>
when(unit.getBaseUnit().unitType){ when(unit.getBaseUnit().unitType){
@ -124,7 +124,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
fun setCenterPosition(vector: Vector2) { fun setCenterPosition(vector: Vector2) {
val tileGroup = tileGroups.values.first { it.tileInfo.position == vector } val tileGroup = tileGroups.values.first { it.tileInfo.position == vector }
selectedTile = tileGroup.tileInfo selectedTile = tileGroup.tileInfo
worldScreen.unitTable.tileSelected(selectedTile!!) worldScreen.bottomBar.unitTable.tileSelected(selectedTile!!)
layout() // Fit the scroll pane to the contents - otherwise, setScroll won't work! layout() // Fit the scroll pane to the contents - otherwise, setScroll won't work!
// We want to center on the middle of TG (TG.getX()+TG.getWidth()/2) // We want to center on the middle of TG (TG.getX()+TG.getWidth()/2)
// and so the scroll position (== filter the screen starts) needs to be half a screen away // and so the scroll position (== filter the screen starts) needs to be half a screen away

View File

@ -9,38 +9,31 @@ import com.unciv.ui.pickerscreens.PolicyPickerScreen
import com.unciv.ui.pickerscreens.TechPickerScreen import com.unciv.ui.pickerscreens.TechPickerScreen
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.GameSaver import com.unciv.ui.utils.GameSaver
import com.unciv.ui.worldscreen.unit.UnitTable
class WorldScreen : CameraStageBaseScreen() { class WorldScreen : CameraStageBaseScreen() {
internal val civInfo: CivilizationInfo val gameInfo = game.gameInfo
internal val civInfo: CivilizationInfo = gameInfo.getPlayerCivilization()
val tileMapHolder: TileMapHolder val tileMapHolder: TileMapHolder
internal var buttonScale = game.settings.buttonScale internal var buttonScale = game.settings.buttonScale
private val tileInfoTable: TileInfoTable private val topBar = WorldScreenTopBar(this)
private val civTable = CivStatsTable(this) val bottomBar = WorldScreenBottomBar(this)
private val techButton = TextButton("", CameraStageBaseScreen.skin) private val techButton = TextButton("", CameraStageBaseScreen.skin)
private val nextTurnButton = createNextTurnButton() private val nextTurnButton = createNextTurnButton()
internal val optionsTable: WorldScreenOptionsTable internal val optionsTable: WorldScreenOptionsTable
private val notificationsScroll: NotificationsScroll private val notificationsScroll: NotificationsScroll
internal val unitTable = UnitTable(this)
private val battleTable:BattleTable
init { init {
val gameInfo = game.gameInfo
this.civInfo = gameInfo.getPlayerCivilization()
battleTable = BattleTable(this)
unitTable.setPosition(5f, 5f)
tileMapHolder = TileMapHolder(this, gameInfo.tileMap, civInfo) tileMapHolder = TileMapHolder(this, gameInfo.tileMap, civInfo)
tileInfoTable = TileInfoTable(this, civInfo)
civTable.setPosition(0f, stage.height - civTable.height) topBar.setPosition(0f, stage.height - topBar.height)
civTable.width = stage.width topBar.width = stage.width
nextTurnButton.setPosition(stage.width - nextTurnButton.width - 10f, nextTurnButton.setPosition(stage.width - nextTurnButton.width - 10f,
civTable.y - nextTurnButton.height - 10f) topBar.y - nextTurnButton.height - 10f)
notificationsScroll = NotificationsScroll(gameInfo.notifications, this) notificationsScroll = NotificationsScroll(gameInfo.notifications, this)
notificationsScroll.width = stage.width/3 notificationsScroll.width = stage.width/3
optionsTable = WorldScreenOptionsTable(this, civInfo) optionsTable = WorldScreenOptionsTable(this, civInfo)
@ -50,13 +43,13 @@ class WorldScreen : CameraStageBaseScreen() {
tileMapHolder.addTiles() tileMapHolder.addTiles()
stage.addActor(tileMapHolder) stage.addActor(tileMapHolder)
stage.addActor(tileInfoTable) stage.addActor(topBar)
stage.addActor(civTable)
stage.addActor(nextTurnButton) stage.addActor(nextTurnButton)
stage.addActor(techButton) stage.addActor(techButton)
stage.addActor(notificationsScroll) stage.addActor(notificationsScroll)
stage.addActor(unitTable)
stage.addActor(battleTable) bottomBar.width = stage.width
stage.addActor(bottomBar)
update() update()
@ -73,19 +66,14 @@ class WorldScreen : CameraStageBaseScreen() {
} }
updateTechButton() updateTechButton()
if (tileMapHolder.selectedTile != null) bottomBar.update(tileMapHolder.selectedTile) // has to come before tilemapholder update because the tilemapholder actions depend on the selected unit!
tileInfoTable.updateTileTable(tileMapHolder.selectedTile!!)
unitTable.update() // has to come before tilemapholder update because the tilemapholder actions depend on the selected unit!
tileMapHolder.updateTiles() tileMapHolder.updateTiles()
civTable.update() topBar.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,
nextTurnButton.y - notificationsScroll.height - 5f) nextTurnButton.y - notificationsScroll.height - 5f)
battleTable.update()
} }
private fun updateTechButton() { private fun updateTechButton() {
@ -102,7 +90,7 @@ class WorldScreen : CameraStageBaseScreen() {
+ civInfo.tech.turnsToTech(civInfo.tech.currentTechnology()!!) + " turns") + civInfo.tech.turnsToTech(civInfo.tech.currentTechnology()!!) + " turns")
techButton.setSize(techButton.prefWidth, techButton.prefHeight) techButton.setSize(techButton.prefWidth, techButton.prefHeight)
techButton.setPosition(10f, civTable.y - techButton.height - 5f) techButton.setPosition(10f, topBar.y - techButton.height - 5f)
} }
private fun createNextTurnButton(): TextButton { private fun createNextTurnButton(): TextButton {
@ -122,7 +110,7 @@ class WorldScreen : CameraStageBaseScreen() {
} }
game.gameInfo.nextTurn() game.gameInfo.nextTurn()
unitTable.currentlyExecutingAction = null bottomBar.unitTable.currentlyExecutingAction = null
GameSaver.saveGame(game.gameInfo, "Autosave") GameSaver.saveGame(game.gameInfo, "Autosave")
update() update()
displayTutorials("NextTurn") displayTutorials("NextTurn")
@ -140,3 +128,4 @@ class WorldScreen : CameraStageBaseScreen() {
} }
} }
} }

View File

@ -0,0 +1,35 @@
package com.unciv.ui.worldscreen
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.logic.map.TileInfo
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.worldscreen.unit.UnitTable
class WorldScreenBottomBar(val worldScreen: WorldScreen) : Table(){
val unitTable = UnitTable(worldScreen)
val battleTable = BattleTable(worldScreen)
val tileInfoTable = TileInfoTable(worldScreen)
init {
add(unitTable).width(worldScreen.stage.width/3)
add(battleTable).width(worldScreen.stage.width/3).fill()
add(tileInfoTable).width(worldScreen.stage.width/3)
val tileTableBackground = ImageGetter.getDrawable(ImageGetter.WhiteDot)
.tint(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
tileTableBackground.minHeight = 0f
tileTableBackground.minWidth = 0f
background = tileTableBackground
pack()
}
fun update(selectedTile: TileInfo?){
unitTable.update()
battleTable.update()
if(selectedTile!=null) tileInfoTable.updateTileTable(selectedTile)
pack()
}
}

View File

@ -16,7 +16,7 @@ import com.unciv.ui.utils.colorFromRGB
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.ceil import kotlin.math.ceil
class CivStatsTable(val screen: WorldScreen) : Table() { class WorldScreenTopBar(val screen: WorldScreen) : Table() {
val labelStyle = Label.LabelStyle(Label("", CameraStageBaseScreen.skin).style) val labelStyle = Label.LabelStyle(Label("", CameraStageBaseScreen.skin).style)
.apply { fontColor = Color.valueOf("f5f5f5ff") } .apply { fontColor = Color.valueOf("f5f5f5ff") }

View File

@ -32,7 +32,7 @@ class UnitActions {
fun getUnitActions(unit:MapUnit,worldScreen: WorldScreen): List<UnitAction> { fun getUnitActions(unit:MapUnit,worldScreen: WorldScreen): List<UnitAction> {
val tile = unit.getTile() val tile = unit.getTile()
val unitTable = worldScreen.unitTable val unitTable = worldScreen.bottomBar.unitTable
val actionList = ArrayList<UnitAction>() val actionList = ArrayList<UnitAction>()
if (unitTable.currentlyExecutingAction != "moveTo" if (unitTable.currentlyExecutingAction != "moveTo"

View File

@ -19,8 +19,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
private val unitActionsTable = Table() private val unitActionsTable = Table()
init { init {
val tileTableBackground = ImageGetter.getDrawable("skin/tileTableBackground.png")
.tint(Color(0x004085bf))
pad(20f) pad(20f)
//background = tileTableBackground //background = tileTableBackground
add(unitLabel).pad(10f) add(unitLabel).pad(10f)