diff --git a/android/assets/OtherIcons/DisbandUnit.png b/android/assets/OtherIcons/DisbandUnit.png new file mode 100644 index 0000000000..ef89fd0f1f Binary files /dev/null and b/android/assets/OtherIcons/DisbandUnit.png differ diff --git a/android/assets/jsons/Translations.json b/android/assets/jsons/Translations.json index 42432666a9..7c56ab78ef 100644 --- a/android/assets/jsons/Translations.json +++ b/android/assets/jsons/Translations.json @@ -142,6 +142,13 @@ Romanian:"Sanatate" German:"Gesundheit" } + + "Disband unit":{} + + "Do you really want to disband this unit?":{} + "Yes":{} + "No":{} + // Stats "Gold":{ diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 9ab13c8972..0dce22b2a1 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -33,6 +33,7 @@ class CivilizationInfo { var goldenAges = GoldenAgeManager() var greatPeople = GreatPersonManager() var scienceVictory = ScienceVictoryManager() + @Transient var diplomacy = HashMap() var cities = ArrayList() var exploredTiles = HashSet() @@ -65,12 +66,10 @@ class CivilizationInfo { statMap.put("Transportation upkeep",Stats().apply { gold=- getTransportationUpkeep().toFloat()}) statMap.put("Unit upkeep",Stats().apply { gold=- getUnitUpkeep().toFloat()}) - if (policies.isAdopted("Mandate Of Heaven")) - - if (!statMap.containsKey("Policies")) { - statMap["Policies"] = Stats() - statMap["Policies"]!!.culture += statMap.values.map { it.happiness }.sum() / 2 - } + if (policies.isAdopted("Mandate Of Heaven")) { + if (!statMap.containsKey("Policies")) statMap["Policies"] = Stats() + statMap["Policies"]!!.culture += statMap.values.map { it.happiness }.sum() / 2 + } // if we have - or 0, then the techs will never be complete and the tech button // will show a negative number of turns and int.max, respectively @@ -244,12 +243,19 @@ class CivilizationInfo { } } -//enum class DiplomaticStatus{ -// Peace, -// War -//} -// -//class DiplomacyManager { -// lateinit var otherCivName:String -// var status:DiplomaticStatus = DiplomaticStatus.Peace -//} \ No newline at end of file +enum class DiplomaticStatus{ + Peace, + War +} + +class DiplomacyManager { + @Transient lateinit var civInfo:CivilizationInfo + lateinit var otherCivName:String + var status:DiplomaticStatus = DiplomaticStatus.Peace + + fun otherCiv() = civInfo.gameInfo.civilizations.first{it.civName==otherCivName} + fun declareWar(){ + status = DiplomaticStatus.War + otherCiv().diplomacy[civInfo.civName]!!.status = DiplomaticStatus.War + } +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/OptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/OptionsTable.kt deleted file mode 100644 index bf6c34e0b6..0000000000 --- a/core/src/com/unciv/ui/worldscreen/optionstable/OptionsTable.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.unciv.ui.worldscreen.optionstable - -import com.badlogic.gdx.graphics.Color -import com.badlogic.gdx.scenes.scene2d.ui.Table -import com.badlogic.gdx.scenes.scene2d.ui.TextButton -import com.unciv.ui.utils.CameraStageBaseScreen -import com.unciv.ui.utils.ImageGetter -import com.unciv.ui.utils.addClickListener -import com.unciv.ui.utils.tr - -open class OptionsTable: Table(){ - init { - val tileTableBackground = ImageGetter.getDrawable("skin/whiteDot.png") - .tint(Color(0x004085bf)) - background = tileTableBackground - - this.pad(20f) - this.defaults().pad(5f) - } - - fun addButton(text:String, action:()->Unit){ - val button = TextButton(text.tr(), CameraStageBaseScreen.skin).apply { color= ImageGetter.getBlue() } - button.addClickListener(action) - add(button).row() - } -} \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/PopupTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/PopupTable.kt new file mode 100644 index 0000000000..fb470c7c90 --- /dev/null +++ b/core/src/com/unciv/ui/worldscreen/optionstable/PopupTable.kt @@ -0,0 +1,39 @@ +package com.unciv.ui.worldscreen.optionstable + +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.scenes.scene2d.ui.Label +import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.unciv.UnCivGame +import com.unciv.ui.utils.* + +open class PopupTable: Table(){ + init { + val tileTableBackground = ImageGetter.getDrawable("skin/whiteDot.png") + .tint(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) + background = tileTableBackground + + this.pad(20f) + this.defaults().pad(5f) + } + + fun addButton(text:String, action:()->Unit){ + val button = TextButton(text.tr(), CameraStageBaseScreen.skin).apply { color= ImageGetter.getBlue() } + button.addClickListener(action) + add(button).row() + } +} + +class YesNoPopupTable(question:String, action:()->Unit, + screen: CameraStageBaseScreen = UnCivGame.Current.worldScreen) : PopupTable(){ + init{ + val skin = CameraStageBaseScreen.skin + add(Label(question,skin)).colspan(2).row() + + add(TextButton("No",skin).apply { addClickListener { this@YesNoPopupTable.remove() } }) + add(TextButton("Yes",skin).apply { addClickListener { this@YesNoPopupTable.remove(); action() } }) + pack() + center(screen.stage) + screen.stage.addActor(this) + } +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenDisplayOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenDisplayOptionsTable.kt index 06b01ba8fe..b2ba54d94a 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenDisplayOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenDisplayOptionsTable.kt @@ -10,7 +10,7 @@ import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.center import com.unciv.ui.worldscreen.WorldScreen -class WorldScreenDisplayOptionsTable() : OptionsTable(){ +class WorldScreenDisplayOptionsTable() : PopupTable(){ init { update() } diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt index 63db586379..c8781ce24c 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt @@ -6,7 +6,7 @@ import com.unciv.ui.pickerscreens.PolicyPickerScreen import com.unciv.ui.utils.center import com.unciv.ui.utils.tr -class WorldScreenOptionsTable internal constructor() : OptionsTable() { +class WorldScreenOptionsTable internal constructor() : PopupTable() { init { addButton("Civilopedia".tr()){ diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 7fef4836bf..1a97e2c6b3 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -10,6 +10,7 @@ import com.unciv.ui.pickerscreens.ImprovementPickerScreen import com.unciv.ui.pickerscreens.PromotionPickerScreen import com.unciv.ui.pickerscreens.TechPickerScreen import com.unciv.ui.worldscreen.WorldScreen +import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable import java.util.* import kotlin.math.max @@ -36,6 +37,7 @@ class UnitActions { unitTable.currentlyExecutingAction = "moveTo" }, unit.currentMovement != 0f ) } + else { actionList += UnitAction("Stop movement", { @@ -162,6 +164,12 @@ class UnitActions { unit.currentMovement != 0f) } + actionList += UnitAction("Disband unit", + { + YesNoPopupTable("Do you really want to disband this unit?", + {unit.removeFromTile(); worldScreen.update()} ) + },unit.currentMovement != 0f) + return actionList } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt index 686a5ed0e2..e0b5e021b4 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt @@ -35,6 +35,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){ "Conduct Trade Mission" -> return ImageGetter.getUnitIcon("Great Merchant") "Construct Customs House" -> return ImageGetter.getImprovementIcon("Customs house") "Set up" -> return ImageGetter.getUnitIcon("Catapult") + "Disband unit" -> return ImageGetter.getImage("OtherIcons/DisbandUnit.png") else -> return ImageGetter.getImage("OtherIcons/Star.png") } }