diff --git a/core/src/com/unciv/ui/CivilopediaScreen.kt b/core/src/com/unciv/ui/CivilopediaScreen.kt index e4612243..e9abfe97 100644 --- a/core/src/com/unciv/ui/CivilopediaScreen.kt +++ b/core/src/com/unciv/ui/CivilopediaScreen.kt @@ -93,7 +93,7 @@ class CivilopediaScreen(ruleset: Ruleset) : CameraStageBaseScreen() { buttonTable.width = stage.width val buttonTableScroll = ScrollPane(buttonTable) - val goToGameButton = TextButton(Constants.close.tr(), skin) + val goToGameButton = Constants.close.toTextButton() goToGameButton.onClick { game.setWorldScreen() dispose() diff --git a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt index cf862f0e..b58af07b 100644 --- a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt @@ -18,7 +18,7 @@ import java.text.DecimalFormat class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseScreen.skin) { private val pad = 10f - private val showConstructionsTableButton = TextButton("Show construction queue".tr(), skin) + private val showConstructionsTableButton = "Show construction queue".toTextButton() private val scrollPane: ScrollPane private val innerTable = Table(skin) @@ -86,7 +86,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS .width(cityScreen.stage.width/4 - 2*pad ).row() // when you set wrap, then you need to manually set the size of the label if(!building.isWonder && !building.isNationalWonder) { val sellAmount = cityScreen.city.getGoldForSellingBuilding(building.name) - val sellBuildingButton = TextButton("Sell for [$sellAmount] gold".tr(),skin) + val sellBuildingButton = "Sell for [$sellAmount] gold".toTextButton() wonderDetailsTable.add(sellBuildingButton).pad(5f).row() sellBuildingButton.onClick { diff --git a/core/src/com/unciv/ui/cityscreen/CityScreen.kt b/core/src/com/unciv/ui/cityscreen/CityScreen.kt index 9e372fbf..73bd5e1f 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreen.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreen.kt @@ -116,7 +116,7 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() { razeCityButtonHolder.clear() if(city.isPuppet) { - val annexCityButton = TextButton("Annex city".tr(), skin) + val annexCityButton = "Annex city".toTextButton() annexCityButton.labelCell.pad(10f) annexCityButton.onClick { city.annexCity() @@ -124,13 +124,13 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() { } razeCityButtonHolder.add(annexCityButton).colspan(cityPickerTable.columns) } else if(!city.isBeingRazed) { - val razeCityButton = TextButton("Raze city".tr(), skin) + val razeCityButton = "Raze city".toTextButton() razeCityButton.labelCell.pad(10f) razeCityButton.onClick { city.isBeingRazed=true; update() } if(!UncivGame.Current.worldScreen.isPlayersTurn) razeCityButton.disable() razeCityButtonHolder.add(razeCityButton).colspan(cityPickerTable.columns) } else { - val stopRazingCityButton = TextButton("Stop razing city".tr(), skin) + val stopRazingCityButton = "Stop razing city".toTextButton() stopRazingCityButton.labelCell.pad(10f) stopRazingCityButton.onClick { city.isBeingRazed=false; update() } if(!UncivGame.Current.worldScreen.isPlayersTurn) stopRazingCityButton.disable() diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt b/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt index eede9a74..4284454e 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorScreen.kt @@ -11,10 +11,7 @@ import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileMap import com.unciv.models.ruleset.RulesetCache import com.unciv.models.translations.tr -import com.unciv.ui.utils.CameraStageBaseScreen -import com.unciv.ui.utils.onClick -import com.unciv.ui.utils.popups -import com.unciv.ui.utils.setFontSize +import com.unciv.ui.utils.* class MapEditorScreen(): CameraStageBaseScreen() { val ruleset = RulesetCache.getBaseRuleset() @@ -25,7 +22,7 @@ class MapEditorScreen(): CameraStageBaseScreen() { val tileEditorOptions = TileEditorOptionsTable(this) - private val showHideEditorOptionsButton = TextButton(">", skin) + private val showHideEditorOptionsButton = ">".toTextButton() constructor(mapNameToLoad: String?): this() { @@ -76,7 +73,7 @@ class MapEditorScreen(): CameraStageBaseScreen() { stage.addActor(showHideEditorOptionsButton) - val optionsMenuButton = TextButton("Menu".tr(), skin) + val optionsMenuButton = "Menu".toTextButton() optionsMenuButton.onClick { if(popups.any { it is MapEditorMenuPopup }) return@onClick // already open diff --git a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt index 44b0f17f..df683a68 100644 --- a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt +++ b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt @@ -51,11 +51,11 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera setTerrainsAndResources() val tabPickerTable = Table().apply { defaults().pad(10f) } - val terrainsAndResourcesTabButton = TextButton("Terrains & Resources".tr(),skin) + val terrainsAndResourcesTabButton = "Terrains & Resources".toTextButton() .onClick { setTerrainsAndResources() } tabPickerTable.add(terrainsAndResourcesTabButton) - val civLocationsButton = TextButton("Improvements".tr(), skin) + val civLocationsButton = "Improvements".toTextButton() .onClick { setImprovements() } tabPickerTable.add(civLocationsButton) tabPickerTable.pack() diff --git a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt index b552c819..f7af87aa 100644 --- a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt @@ -27,7 +27,7 @@ open class PickerScreen : CameraStageBaseScreen() { val labelScroll = ScrollPane(descriptionLabel) bottomTable.add(labelScroll).pad(5f).fill().expand() - rightSideButton = TextButton("", skin) + rightSideButton = "".toTextButton() rightSideButton.disable() rightSideGroup.addActor(rightSideButton) diff --git a/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt index 9bb3b2f1..ceb8137b 100644 --- a/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt @@ -109,7 +109,7 @@ class PolicyPickerScreen(val worldScreen: WorldScreen, civInfo: CivilizationInfo val policyImage = ImageGetter.getImage("PolicyIcons/" + policy.name) policyButton.add(policyImage).size(30f) } else { - policyButton = TextButton(policy.name.tr(), skin) + policyButton = policy.name.toTextButton() } if (viewingCiv.policies.isAdopted(policy.name)) { // existing diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index f2dc54eb..21a3c25f 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -40,7 +40,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { stage.addActor(splitPane) - val closeButton = TextButton(Constants.close.tr(), skin) + val closeButton = Constants.close.toTextButton() closeButton.onClick { UncivGame.Current.setWorldScreen() } closeButton.label.setFontSize(24) closeButton.labelCell.pad(10f) @@ -137,7 +137,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { val giftAmount = 250 val influenceAmount = giftAmount / 10 - val giftButton = TextButton("Gift [$giftAmount] gold (+[$influenceAmount] influence)".tr(), skin) + val giftButton = "Gift [$giftAmount] gold (+[$influenceAmount] influence)".toTextButton() giftButton.onClick { viewingCiv.giveGoldGift(otherCiv, giftAmount) updateRightSide(otherCiv) @@ -148,7 +148,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv) if (viewingCiv.isAtWarWith(otherCiv)) { - val peaceButton = TextButton("Negotiate Peace".tr(), skin) + val peaceButton = "Negotiate Peace".toTextButton() peaceButton.onClick { YesNoPopup("Peace with [${otherCiv.civName}]?".tr(), { val tradeLogic = TradeLogic(viewingCiv, otherCiv) @@ -184,7 +184,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { diplomacyTable.addSeparator() if(!viewingCiv.isAtWarWith(otherCiv)) { - val tradeButton = TextButton("Trade".tr(), skin) + val tradeButton = "Trade".toTextButton() tradeButton.onClick { setTrade(otherCiv).apply { tradeLogic.ourAvailableOffers.apply { remove(firstOrNull { it.type==TradeType.Treaty }) } @@ -196,7 +196,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { if(isNotPlayersTurn()) tradeButton.disable() } else{ - val negotiatePeaceButton = TextButton("Negotiate Peace".tr(),skin) + val negotiatePeaceButton = "Negotiate Peace".toTextButton() negotiatePeaceButton.onClick { val tradeTable = setTrade(otherCiv) val peaceTreaty = TradeOffer(Constants.peaceTreaty,TradeType.Treaty) @@ -218,7 +218,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { if(otherCivDiplomacyManager.relationshipLevel() > RelationshipLevel.Neutral && !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship) && !diplomacyManager.hasFlag(DiplomacyFlags.Denunceation)){ - val declareFriendshipButton = TextButton("Declare Friendship ([30] turns)".tr(),skin) + val declareFriendshipButton = "Declare Friendship ([30] turns)".toTextButton() declareFriendshipButton.onClick { diplomacyManager.signDeclarationOfFriendship() setRightSideFlavorText(otherCiv,"May our nations forever remain united!","Indeed!") @@ -228,7 +228,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { } if(viewingCiv.canSignResearchAgreementsWith(otherCiv)){ - val researchAgreementButton = TextButton("Research Agreement".tr(),skin) + val researchAgreementButton = "Research Agreement".toTextButton() val requiredGold = viewingCiv.getResearchAgreementCost(otherCiv) researchAgreementButton.onClick { @@ -250,7 +250,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { if(!diplomacyManager.hasFlag(DiplomacyFlags.Denunceation) && !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)){ - val denounceButton = TextButton("Denounce ([30] turns)".tr(),skin) + val denounceButton = "Denounce ([30] turns)".toTextButton() denounceButton.onClick { diplomacyManager.denounce() setRightSideFlavorText(otherCiv,"We will remember this.","Very well.") @@ -264,7 +264,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { if(isNotPlayersTurn()) declareWarButton.disable() } - val demandsButton = TextButton("Demands".tr(),skin) + val demandsButton = "Demands".toTextButton() demandsButton.onClick { rightSideTable.clear() rightSideTable.add(getDemandsTable(viewingCiv,otherCiv)) @@ -317,7 +317,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { val demandsTable = Table() demandsTable.defaults().pad(10f) - val dontSettleCitiesButton = TextButton("Please don't settle new cities near us.".tr(),skin) + val dontSettleCitiesButton = "Please don't settle new cities near us.".toTextButton() if(otherCiv.popupAlerts.any { it.type==AlertType.DemandToStopSettlingCitiesNear && it.value==viewingCiv.civName }) dontSettleCitiesButton.disable() dontSettleCitiesButton.onClick { @@ -351,7 +351,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { } private fun getDeclareWarButton(diplomacyManager: DiplomacyManager, otherCiv: CivilizationInfo): TextButton { - val declareWarButton = TextButton("Declare war".tr(), skin) + val declareWarButton = "Declare war".toTextButton() declareWarButton.color = Color.RED val turnsToPeaceTreaty = diplomacyManager.turnsToPeaceTreaty() if (turnsToPeaceTreaty > 0) { @@ -375,7 +375,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { diplomacyTable.addSeparator() diplomacyTable.add(flavorText.toLabel()).row() - val responseButton = TextButton(response.tr(),skin) + val responseButton = response.toTextButton() responseButton.onClick { updateRightSide(otherCiv) } diplomacyTable.add(responseButton) diff --git a/core/src/com/unciv/ui/trade/OffersListScroll.kt b/core/src/com/unciv/ui/trade/OffersListScroll.kt index fdd004ee..2ed93832 100644 --- a/core/src/com/unciv/ui/trade/OffersListScroll.kt +++ b/core/src/com/unciv/ui/trade/OffersListScroll.kt @@ -14,6 +14,7 @@ import com.unciv.ui.cityscreen.ExpanderTab import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.disable import com.unciv.ui.utils.onClick +import com.unciv.ui.utils.toTextButton import kotlin.math.min class OffersListScroll(val onOfferClicked: (TradeOffer) -> Unit) : ScrollPane(null) { @@ -52,7 +53,7 @@ class OffersListScroll(val onOfferClicked: (TradeOffer) -> Unit) : ScrollPane(nu } for (offer in offersOfType) { - val tradeButton = TextButton(offer.getOfferText(), CameraStageBaseScreen.skin) + val tradeButton = offer.getOfferText().toTextButton() val amountPerClick = if (offer.type == Gold) 50 else 1 diff --git a/core/src/com/unciv/ui/trade/TradeTable.kt b/core/src/com/unciv/ui/trade/TradeTable.kt index 2c7677d0..6be2d4c1 100644 --- a/core/src/com/unciv/ui/trade/TradeTable.kt +++ b/core/src/com/unciv/ui/trade/TradeTable.kt @@ -7,17 +7,14 @@ import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeRequest import com.unciv.models.translations.tr -import com.unciv.ui.utils.CameraStageBaseScreen -import com.unciv.ui.utils.disable -import com.unciv.ui.utils.enable -import com.unciv.ui.utils.onClick +import com.unciv.ui.utils.* class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage): Table(CameraStageBaseScreen.skin){ val currentPlayerCiv = otherCivilization.gameInfo.getCurrentPlayerCivilization() var tradeLogic = TradeLogic(currentPlayerCiv,otherCivilization) var offerColumnsTable = OfferColumnsTable(tradeLogic, stage) { onChange() } var offerColumnsTableWrapper = Table() // This is so that after a trade has been traded, we can switch out the offersToDisplay to start anew - this is the easiest way - val offerButton = TextButton("Offer trade".tr(), CameraStageBaseScreen.skin) + val offerButton = "Offer trade".toTextButton() fun isTradeOffered() = otherCivilization.tradeRequests.any{it.requestingCiv==currentPlayerCiv.civName} diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index eb476351..30f5bee8 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -226,6 +226,8 @@ fun HashSet.withoutItem(item:T): HashSet { return newHashSet } +fun String.toTextButton() = TextButton(this.tr(), CameraStageBaseScreen.skin) + /** also translates */ fun String.toLabel() = Label(this.tr(),CameraStageBaseScreen.skin) diff --git a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt index 94efd151..5021d5c3 100644 --- a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt @@ -11,7 +11,7 @@ import com.unciv.ui.utils.* class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popup(worldScreen){ fun getCloseButton(text: String, action: (() -> Unit)?=null): TextButton { - val button = TextButton(text.tr(), skin) + val button = text.toTextButton() button.onClick { if(action!=null) action() worldScreen.shouldUpdate=true @@ -66,7 +66,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu if (city.foundingCiv != "" && city.civInfo.civName != city.foundingCiv // can't liberate if the city actually belongs to those guys && conqueringCiv.civName != city.foundingCiv) { // or belongs originally to us - add(TextButton("Liberate".tr(), skin).onClick { + add("Liberate".toTextButton().onClick { city.liberateCity(conqueringCiv) worldScreen.shouldUpdate=true close() @@ -77,7 +77,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu if (!conqueringCiv.isOneCityChallenger()){ - add(TextButton("Annex".tr(), skin).onClick { + add("Annex".toTextButton().onClick { city.puppetCity(conqueringCiv) city.annexCity() worldScreen.shouldUpdate=true @@ -87,7 +87,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu addGoodSizedLabel("Their citizens generate 2x the unhappiness, unless you build a courthouse.").row() addSeparator() - add(TextButton("Puppet".tr(), skin).onClick { + add("Puppet".toTextButton().onClick { city.puppetCity(conqueringCiv) worldScreen.shouldUpdate=true close() @@ -99,7 +99,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu addSeparator() - add(TextButton("Raze".tr(), skin).onClick { + add("Raze".toTextButton().onClick { city.puppetCity(conqueringCiv) city.annexCity() city.isBeingRazed = true @@ -110,7 +110,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu addGoodSizedLabel("The population will gradually dwindle until the city is destroyed.").row() } else { - add(TextButton("Destroy".tr(), skin).onClick { + add("Destroy".toTextButton().onClick { city.puppetCity(conqueringCiv) city.destroyCity() worldScreen.shouldUpdate=true diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index ed586880..f2689ab7 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -182,7 +182,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() { is CityCombatant -> "Bombard" else -> "Attack" } - val attackButton = TextButton(attackText.tr(), skin).apply { color= Color.RED } + val attackButton = attackText.toTextButton().apply { color= Color.RED } var attackableTile : AttackableTile? = null @@ -275,7 +275,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() { addSeparator().pad(0f) row().pad(5f) - val attackButton = TextButton("NUKE".tr(), skin).apply { color= Color.RED } + val attackButton = "NUKE".toTextButton().apply { color= Color.RED } val canReach = attacker.unit.currentTile.getTilesInDistance(attacker.unit.getRange()).contains(targetTile)