Added "deselect" button to unit & city display

This commit is contained in:
Yair Morgenstern 2019-02-09 21:25:30 +02:00
parent d2a48fae38
commit 3feb231620
9 changed files with 88 additions and 52 deletions

View File

@ -12,6 +12,7 @@ import java.util.*
*/ */
class Battle(val gameInfo:GameInfo) { class Battle(val gameInfo:GameInfo) {
fun attack(attacker: ICombatant, defender: ICombatant) { fun attack(attacker: ICombatant, defender: ICombatant) {
println(attacker.getCivInfo().civName+" "+attacker.getName()+" attacked "+defender.getCivInfo().civName+" "+defender.getName())
val attackedTile = defender.getTile() val attackedTile = defender.getTile()
var damageToDefender = BattleDamage().calculateDamageToDefender(attacker,defender) var damageToDefender = BattleDamage().calculateDamageToDefender(attacker,defender)

View File

@ -27,6 +27,7 @@ class NewGameScreen: PickerScreen(){
val nationTables = ArrayList<NationTable>() val nationTables = ArrayList<NationTable>()
val civPickerTable = Table().apply { defaults().pad(15f) } val civPickerTable = Table().apply { defaults().pad(15f) }
init { init {
setDefaultCloseAction() setDefaultCloseAction()
val mainTable = Table() val mainTable = Table()

View File

@ -1,12 +1,12 @@
package com.unciv.ui package com.unciv.ui.mapeditor
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.utils.Array import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.GameParameters import com.unciv.GameParameters
import com.unciv.UnCivGame
import com.unciv.logic.GameSaver import com.unciv.logic.GameSaver
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
@ -14,13 +14,13 @@ import com.unciv.models.gamebasics.tile.Terrain
import com.unciv.models.gamebasics.tile.TerrainType import com.unciv.models.gamebasics.tile.TerrainType
import com.unciv.models.gamebasics.tile.TileResource import com.unciv.models.gamebasics.tile.TileResource
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.tilegroups.TileGroup import com.unciv.ui.tilegroups.TileGroup
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.center import com.unciv.ui.utils.center
import com.unciv.ui.utils.onClick import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.TileGroupMap import com.unciv.ui.worldscreen.TileGroupMap
import com.unciv.ui.worldscreen.optionstable.PopupTable
class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){ class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){
var clearTerrainFeature=false var clearTerrainFeature=false
@ -77,7 +77,7 @@ class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){
val saveMapButton = TextButton("Options".tr(),skin) val saveMapButton = TextButton("Options".tr(),skin)
saveMapButton.onClick { saveMapButton.onClick {
mapScreenOptionsTable(this) MapScreenOptionsTable(this)
} }
stage.addActor(saveMapButton) stage.addActor(saveMapButton)
} }
@ -187,49 +187,8 @@ class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){
} }
} }
class mapScreenOptionsTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScreen){ class NewMapScreen:PickerScreen(){
init{ init{
val mapNameEditor = TextField(mapEditorScreen.mapName, CameraStageBaseScreen.skin)
mapNameEditor.addListener{ mapEditorScreen.mapName=mapNameEditor.text; true }
add(mapNameEditor).row()
val saveMapButton = TextButton("Save".tr(), CameraStageBaseScreen.skin)
saveMapButton.onClick {
GameSaver().saveMap(mapEditorScreen.mapName,mapEditorScreen.tileMap)
UnCivGame.Current.setWorldScreen()
}
add(saveMapButton).row()
val loadMapButton = TextButton("Load".tr(),CameraStageBaseScreen.skin)
loadMapButton.onClick { MapScreenLoadTable(mapEditorScreen); remove() }
add(loadMapButton).row()
val closeOptionsButtton = TextButton("Close".tr(), CameraStageBaseScreen.skin)
closeOptionsButtton.onClick { remove() }
add(closeOptionsButtton).row()
open()
}
}
class MapScreenLoadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScreen){
init{
val mapFileSelectBox = SelectBox<String>(CameraStageBaseScreen.skin)
val mapNames = Array<String>()
for (mapName in GameSaver().getMaps()) mapNames.add(mapName)
mapFileSelectBox.items = mapNames
add(mapFileSelectBox).row()
val loadMapButton = TextButton("Load".tr(),CameraStageBaseScreen.skin)
loadMapButton.onClick {
UnCivGame.Current.screen = MapEditorScreen(mapFileSelectBox.selected)
}
add(loadMapButton).row()
val closeOptionsButtton = TextButton("Close".tr(), CameraStageBaseScreen.skin)
closeOptionsButtton.onClick { remove() }
add(closeOptionsButtton).row()
open()
} }
} }

View File

@ -0,0 +1,33 @@
package com.unciv.ui.mapeditor
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.utils.Array
import com.unciv.UnCivGame
import com.unciv.logic.GameSaver
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.optionstable.PopupTable
class MapScreenLoadTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEditorScreen){
init{
val mapFileSelectBox = SelectBox<String>(CameraStageBaseScreen.skin)
val mapNames = Array<String>()
for (mapName in GameSaver().getMaps()) mapNames.add(mapName)
mapFileSelectBox.items = mapNames
add(mapFileSelectBox).row()
val loadMapButton = TextButton("Load".tr(), CameraStageBaseScreen.skin)
loadMapButton.onClick {
UnCivGame.Current.screen = MapEditorScreen(mapFileSelectBox.selected)
}
add(loadMapButton).row()
val closeOptionsButtton = TextButton("Close".tr(), CameraStageBaseScreen.skin)
closeOptionsButtton.onClick { remove() }
add(closeOptionsButtton).row()
open()
}
}

View File

@ -0,0 +1,35 @@
package com.unciv.ui.mapeditor
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.scenes.scene2d.ui.TextField
import com.unciv.UnCivGame
import com.unciv.logic.GameSaver
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.optionstable.PopupTable
class MapScreenOptionsTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEditorScreen){
init{
val mapNameEditor = TextField(mapEditorScreen.mapName, CameraStageBaseScreen.skin)
mapNameEditor.addListener{ mapEditorScreen.mapName=mapNameEditor.text; true }
add(mapNameEditor).row()
val saveMapButton = TextButton("Save".tr(), CameraStageBaseScreen.skin)
saveMapButton.onClick {
GameSaver().saveMap(mapEditorScreen.mapName,mapEditorScreen.tileMap)
UnCivGame.Current.setWorldScreen()
}
add(saveMapButton).row()
val loadMapButton = TextButton("Load".tr(), CameraStageBaseScreen.skin)
loadMapButton.onClick { MapScreenLoadTable(mapEditorScreen); remove() }
add(loadMapButton).row()
val closeOptionsButtton = TextButton("Close".tr(), CameraStageBaseScreen.skin)
closeOptionsButtton.onClick { remove() }
add(closeOptionsButtton).row()
open()
}
}

View File

@ -56,7 +56,6 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
fun simulateBattle(attacker: ICombatant, defender: ICombatant){ fun simulateBattle(attacker: ICombatant, defender: ICombatant){
clear() clear()
defaults().pad(5f) defaults().pad(5f)
println("debuglog simulateBattle")
val attackerNameWrapper = Table() val attackerNameWrapper = Table()
val attackerLabel = Label(attacker.getName(), skin) val attackerLabel = Label(attacker.getName(), skin)

View File

@ -3,7 +3,6 @@ package com.unciv.ui.worldscreen.bottombar
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.logic.city.CityInfo
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
@ -16,7 +15,7 @@ class WorldScreenBottomBar(val worldScreen: WorldScreen) : Table(){
init { init {
touchable= Touchable.enabled touchable= Touchable.enabled
add(unitTable).width(worldScreen.stage.width/3) add(unitTable).width(worldScreen.stage.width/3).fill()
add(battleTable).width(worldScreen.stage.width/3).fill() // so that background fills entire middle third add(battleTable).width(worldScreen.stage.width/3).fill() // so that background fills entire middle third
add(tileInfoTable).width(worldScreen.stage.width/3).fill() add(tileInfoTable).width(worldScreen.stage.width/3).fill()

View File

@ -3,7 +3,7 @@ package com.unciv.ui.worldscreen.optionstable
import com.unciv.UnCivGame import com.unciv.UnCivGame
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.ui.CivilopediaScreen import com.unciv.ui.CivilopediaScreen
import com.unciv.ui.MapEditorScreen import com.unciv.ui.mapeditor.MapEditorScreen
import com.unciv.ui.NewGameScreen import com.unciv.ui.NewGameScreen
import com.unciv.ui.VictoryScreen import com.unciv.ui.VictoryScreen
import com.unciv.ui.pickerscreens.PolicyPickerScreen import com.unciv.ui.pickerscreens.PolicyPickerScreen

View File

@ -1,5 +1,7 @@
package com.unciv.ui.worldscreen.unit package com.unciv.ui.worldscreen.unit
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Image 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
@ -22,6 +24,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
var selectedCity : CityInfo? = null var selectedCity : CityInfo? = null
var currentlyExecutingAction : String? = null var currentlyExecutingAction : String? = null
var lastSelectedCityButton : Boolean = false var lastSelectedCityButton : Boolean = false
val deselectUnitButton = Table()
// This is so that not on every update(), we will update the unit table. // This is so that not on every update(), we will update the unit table.
// Most of the time it's the same unit with the same stats so why waste precious time? // Most of the time it's the same unit with the same stats so why waste precious time?
@ -40,6 +43,12 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
separator= addSeparator().actor!! separator= addSeparator().actor!!
add(promotionsTable).colspan(2).row() add(promotionsTable).colspan(2).row()
add(unitDescriptionTable) add(unitDescriptionTable)
deselectUnitButton.add(Label("X",CameraStageBaseScreen.skin).setFontColor(Color.WHITE)).pad(20f)
deselectUnitButton.pack()
deselectUnitButton.touchable = Touchable.enabled
deselectUnitButton.onClick { selectedUnit=null; selectedCity=null; worldScreen.shouldUpdate=true }
addActor(deselectUnitButton)
} }
fun update() { fun update() {