From e81df16317953b4c4ba0f8701993816091199829 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 27 Jun 2018 22:43:15 +0300 Subject: [PATCH] Added Yes/No popup (we'll need it when we have diplomacy and you tell a unit to enter enemy territory) Added opttion to disband unit (as a test for the popup) --- android/assets/OtherIcons/DisbandUnit.png | Bin 0 -> 3817 bytes android/assets/jsons/Translations.json | 7 ++++ .../logic/civilization/CivilizationInfo.kt | 36 +++++++++------- .../worldscreen/optionstable/OptionsTable.kt | 26 ------------ .../ui/worldscreen/optionstable/PopupTable.kt | 39 ++++++++++++++++++ .../WorldScreenDisplayOptionsTable.kt | 2 +- .../optionstable/WorldScreenOptionsTable.kt | 2 +- .../unciv/ui/worldscreen/unit/UnitActions.kt | 8 ++++ .../ui/worldscreen/unit/UnitActionsTable.kt | 1 + 9 files changed, 78 insertions(+), 43 deletions(-) create mode 100644 android/assets/OtherIcons/DisbandUnit.png delete mode 100644 core/src/com/unciv/ui/worldscreen/optionstable/OptionsTable.kt create mode 100644 core/src/com/unciv/ui/worldscreen/optionstable/PopupTable.kt diff --git a/android/assets/OtherIcons/DisbandUnit.png b/android/assets/OtherIcons/DisbandUnit.png new file mode 100644 index 0000000000000000000000000000000000000000..ef89fd0f1f717797df54f3ada83e12d5de4435ae GIT binary patch literal 3817 zcmY*cXHb({*9|2kAp}APr36fz3~f|V)~ z)CfF6DAEPdfL9Fxq!=`yVCWxyzux!E?7i1Hvu4kp{o|}zG-skMLUf-f2n0gd+Ywy% zYVV(bitOcDkGk@`A{>pkcZ2So1ZW_2?+%Nw^Na?8;L?9W0Q66(0th6YX-}|piz{6! zyOLXcTCvBR0fp+v5=Q(i@Hh1QR#Nt93tcR_5d8bqA!6~u(d>yEN4)MGA)d;rE*zJ+ zZ*{+*xLf-X&qi_z{OXR@!warHG9KSE`#UZtnJ}j5J8Q95hL^Ut+bT-tBm^p=$-}>6 zhc?Tj%OPn} z?G$%L4aUNIQ3}RHAS@0?NEy`jXLmA@DaVp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WywI;#~BjLO0h|Z$$Va$le2fFC<8(iZbwgHdsw`h!Lz^d@yfT#Mt zS*^#!blw(OHPq{$>n?(A3XVrZB8*}Jw-wl;9f@*b;P2f-kteEu*{8n-oY>xgIjyNh z(g~%1e`25zYNy$ta^>~s^sa(^Y1`McJ4G(cgP!zwPYSRI>;lM9=0MwWh!+q0#JnMHAVy=|_il!h~iM zi+m_F^t$k0d2dXP`a)+g5VMdHxVB!l2K#8JJ45!?$%UVRy2== z%(dCQZ@yiFbdj`TUmU&Ue7Jb|s$H9xf;+@I#ju+tk2! z=^{jd7`2+BP3Rafpc19KoTTUatjwdT3$Judxe7ZQ087ja)GD$+7Gr$sS*!Jio?)z1 zyOnG6583&8HP(Q4T@FU(DodL=2<2{C%@E1h2#)JvHG!71GAnrK|rne zHp~U_GZHP%i;hgftPeWrt_<#D6S(jqX`hO(pHizG$0VVW|17as(HeW4f47a;KB3_R zD)O12sz`b466-@^ZZ%7wRqo_Y`h4(y14w2AN2x;oevy#osn6PH)E@g`Qt|2s zzb>WGg^>@bK|7w!CO+(86(09X(6+JChQoC)IlHgFyiK(VeBTFkPrTZUo%mqy(k~cU zvi{ilzWRDnX0v!A&EhZ8o1mw4^}7dlt@Y+*StIXO#71FT-INONnRcCBb;u3oN|f8? zx95rqXPCQMSgup+#uvAa_FjQG(rb`TA|I06v zU`I(Si@T#bTS+ek_d1n|)l~lKOxg#(drteoyX4*T{k&at1YUN>TKodDNTwwqvUu_( zH;CQBiqdebX|Tce#g%VYK(^{Kc8@W(aG() 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") } }