From d43e190d245143c1b3b6a0591ffa7ce1969b58b6 Mon Sep 17 00:00:00 2001 From: Gualdimar Date: Wed, 1 Feb 2023 20:08:49 +0200 Subject: [PATCH] CityRenamePopup (#8534) it is now possible to rename a city by clicking on its name in the UnitTable on the world screen(bottom left) --- .../cityscreen/CityScreenCityPickerTable.kt | 16 +++++-------- .../unciv/ui/pickerscreens/CityRenamePopup.kt | 24 +++++++++++++++++++ .../unciv/ui/worldscreen/unit/UnitTable.kt | 16 ++++++++++++- 3 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 core/src/com/unciv/ui/pickerscreens/CityRenamePopup.kt diff --git a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt index 77bf0ad190..47a074f561 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt @@ -5,11 +5,10 @@ import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align import com.unciv.ui.images.ImageGetter -import com.unciv.ui.popup.AskTextPopup +import com.unciv.ui.pickerscreens.CityRenamePopup import com.unciv.ui.utils.BaseScreen import com.unciv.ui.utils.extensions.onClick import com.unciv.ui.utils.extensions.toLabel -import com.unciv.models.translations.tr /** Widget for the City Screen - * the panel at bottom center showing the city name and offering arrows to cycle through the cities. */ @@ -55,16 +54,13 @@ class CityScreenCityPickerTable(private val cityScreen: CityScreen) : Table() { val currentCityLabel = city.name.toLabel(fontSize = 30, fontColor = civInfo.nation.getInnerColor()) if (cityScreen.canChangeState) currentCityLabel.onClick { - AskTextPopup( - cityScreen, - label = "Please enter a new name for your city", - defaultText = city.name.tr(), - validate = { it != "" }, - actionOnOk = { text -> - city.name = text + CityRenamePopup( + screen = cityScreen, + city = city, + actionOnClose = { cityScreen.game.replaceCurrentScreen(CityScreen(city)) } - ).open() + ) } cityNameTable.add(currentCityLabel) diff --git a/core/src/com/unciv/ui/pickerscreens/CityRenamePopup.kt b/core/src/com/unciv/ui/pickerscreens/CityRenamePopup.kt new file mode 100644 index 0000000000..94266b1fa7 --- /dev/null +++ b/core/src/com/unciv/ui/pickerscreens/CityRenamePopup.kt @@ -0,0 +1,24 @@ +package com.unciv.ui.pickerscreens + +import com.unciv.logic.city.City +import com.unciv.models.translations.tr +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.popup.AskTextPopup +import com.unciv.ui.utils.BaseScreen + +class CityRenamePopup(val screen: BaseScreen, val city: City, val actionOnClose: ()->Unit) { + init { + AskTextPopup( + screen, + label = "Please enter a new name for your city", + defaultText = city.name.tr(), + validate = { it != "" }, + actionOnOk = { text -> + city.name = text + actionOnClose() + } + ).open() + } + +} + diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index bb41d99949..8d564ba542 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -17,6 +17,7 @@ import com.unciv.models.translations.tr import com.unciv.ui.civilopedia.CivilopediaCategories import com.unciv.ui.civilopedia.CivilopediaScreen import com.unciv.ui.images.ImageGetter +import com.unciv.ui.pickerscreens.CityRenamePopup import com.unciv.ui.pickerscreens.PromotionPickerScreen import com.unciv.ui.pickerscreens.UnitRenamePopup import com.unciv.ui.utils.BaseScreen @@ -125,7 +126,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table() { if (selectedUnit!!.civInfo != worldScreen.viewingCiv && !worldScreen.viewingCiv.isSpectator()) { // The unit that was selected, was captured. It exists but is no longer ours. selectUnit() selectedUnitHasChanged = true - } else if (selectedUnit!! !in selectedUnit!!.getTile().getUnits()) { // The unit that was there no longer exists} + } else if (selectedUnit!! !in selectedUnit!!.getTile().getUnits()) { // The unit that was there no longer exists selectUnit() selectedUnitHasChanged = true } @@ -228,7 +229,20 @@ class UnitTable(val worldScreen: WorldScreen) : Table() { var nameLabelText = city.name.tr() if(city.health