From 3feb2316208ceab5e1711279eef6b0aaa7176da6 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 9 Feb 2019 21:25:30 +0200 Subject: [PATCH] Added "deselect" button to unit & city display --- core/src/com/unciv/logic/battle/Battle.kt | 1 + core/src/com/unciv/ui/NewGameScreen.kt | 1 + .../ui/{ => mapeditor}/MapEditorScreen.kt | 55 +++---------------- .../unciv/ui/mapeditor/MapScreenLoadTable.kt | 33 +++++++++++ .../ui/mapeditor/MapScreenOptionsTable.kt | 35 ++++++++++++ .../ui/worldscreen/bottombar/BattleTable.kt | 1 - .../bottombar/WorldScreenBottomBar.kt | 3 +- .../optionstable/WorldScreenOptionsTable.kt | 2 +- .../unciv/ui/worldscreen/unit/UnitTable.kt | 9 +++ 9 files changed, 88 insertions(+), 52 deletions(-) rename core/src/com/unciv/ui/{ => mapeditor}/MapEditorScreen.kt (76%) create mode 100644 core/src/com/unciv/ui/mapeditor/MapScreenLoadTable.kt create mode 100644 core/src/com/unciv/ui/mapeditor/MapScreenOptionsTable.kt diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 76704c8773..4ef7ba7c8c 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -12,6 +12,7 @@ import java.util.* */ class Battle(val gameInfo:GameInfo) { fun attack(attacker: ICombatant, defender: ICombatant) { + println(attacker.getCivInfo().civName+" "+attacker.getName()+" attacked "+defender.getCivInfo().civName+" "+defender.getName()) val attackedTile = defender.getTile() var damageToDefender = BattleDamage().calculateDamageToDefender(attacker,defender) diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index 79d55b81c0..f7b84d0d30 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -27,6 +27,7 @@ class NewGameScreen: PickerScreen(){ val nationTables = ArrayList() val civPickerTable = Table().apply { defaults().pad(15f) } + init { setDefaultCloseAction() val mainTable = Table() diff --git a/core/src/com/unciv/ui/MapEditorScreen.kt b/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt similarity index 76% rename from core/src/com/unciv/ui/MapEditorScreen.kt rename to core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt index d6f202cbba..9d11779776 100644 --- a/core/src/com/unciv/ui/MapEditorScreen.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt @@ -1,12 +1,12 @@ -package com.unciv.ui +package com.unciv.ui.mapeditor import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Group -import com.badlogic.gdx.scenes.scene2d.ui.* -import com.badlogic.gdx.utils.Array +import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane +import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.unciv.GameParameters -import com.unciv.UnCivGame import com.unciv.logic.GameSaver import com.unciv.logic.map.TileMap 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.TileResource import com.unciv.models.gamebasics.tr +import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.tilegroups.TileGroup import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.center import com.unciv.ui.utils.onClick import com.unciv.ui.worldscreen.TileGroupMap -import com.unciv.ui.worldscreen.optionstable.PopupTable class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){ var clearTerrainFeature=false @@ -77,7 +77,7 @@ class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){ val saveMapButton = TextButton("Options".tr(),skin) saveMapButton.onClick { - mapScreenOptionsTable(this) + MapScreenOptionsTable(this) } stage.addActor(saveMapButton) } @@ -187,49 +187,8 @@ class MapEditorScreen(var mapToLoad:String?=null): CameraStageBaseScreen(){ } } -class mapScreenOptionsTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScreen){ +class NewMapScreen:PickerScreen(){ 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(CameraStageBaseScreen.skin) - val mapNames = Array() - 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() } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/mapeditor/MapScreenLoadTable.kt b/core/src/com/unciv/ui/mapeditor/MapScreenLoadTable.kt new file mode 100644 index 0000000000..c819467df4 --- /dev/null +++ b/core/src/com/unciv/ui/mapeditor/MapScreenLoadTable.kt @@ -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(CameraStageBaseScreen.skin) + val mapNames = Array() + 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() + } +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/mapeditor/MapScreenOptionsTable.kt b/core/src/com/unciv/ui/mapeditor/MapScreenOptionsTable.kt new file mode 100644 index 0000000000..6d0aa822f5 --- /dev/null +++ b/core/src/com/unciv/ui/mapeditor/MapScreenOptionsTable.kt @@ -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() + } +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 649d5b595a..169cd50593 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -56,7 +56,6 @@ class BattleTable(val worldScreen: WorldScreen): Table() { fun simulateBattle(attacker: ICombatant, defender: ICombatant){ clear() defaults().pad(5f) - println("debuglog simulateBattle") val attackerNameWrapper = Table() val attackerLabel = Label(attacker.getName(), skin) diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt b/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt index 6fe602cb59..fdc0e78b00 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/WorldScreenBottomBar.kt @@ -3,7 +3,6 @@ package com.unciv.ui.worldscreen.bottombar import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Table -import com.unciv.logic.city.CityInfo import com.unciv.logic.map.TileInfo import com.unciv.ui.utils.ImageGetter import com.unciv.ui.worldscreen.WorldScreen @@ -16,7 +15,7 @@ class WorldScreenBottomBar(val worldScreen: WorldScreen) : Table(){ init { 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(tileInfoTable).width(worldScreen.stage.width/3).fill() diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt index 5499829a9c..72f5b66558 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt @@ -3,7 +3,7 @@ package com.unciv.ui.worldscreen.optionstable import com.unciv.UnCivGame import com.unciv.models.gamebasics.tr 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.VictoryScreen import com.unciv.ui.pickerscreens.PolicyPickerScreen diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index c757356ea0..93b0dd94a1 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -1,5 +1,7 @@ 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.Label import com.badlogic.gdx.scenes.scene2d.ui.Table @@ -22,6 +24,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ var selectedCity : CityInfo? = null var currentlyExecutingAction : String? = null var lastSelectedCityButton : Boolean = false + val deselectUnitButton = 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? @@ -40,6 +43,12 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ separator= addSeparator().actor!! add(promotionsTable).colspan(2).row() 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() {