More toTextButton() changes

This commit is contained in:
Yair Morgenstern
2020-04-20 17:33:46 +03:00
parent fea202dbd6
commit 1a0d808b65
15 changed files with 41 additions and 55 deletions

View File

@ -82,7 +82,7 @@ class CivilopediaScreen(ruleset: Ruleset) : CameraStageBaseScreen() {
buttonTable.defaults().pad(10f)
for (category in categoryToEntries.keys) {
val button = TextButton(category.tr(), skin)
val button = category.toTextButton()
button.style = TextButton.TextButtonStyle(button.style)
categoryToButtons[category] = button
button.onClick { select(category) }

View File

@ -383,7 +383,7 @@ class EmpireOverviewScreen(private val viewingPlayer:CivilizationInfo, private v
for(unit in viewingPlayer.getCivUnits().sortedWith(compareBy({it.name},{!it.due},
{it.currentMovement<0.1f},{abs(it.currentTile.position.x)+abs(it.currentTile.position.y)}))) {
val baseUnit = unit.baseUnit()
val button = TextButton(unit.name.tr(), skin)
val button = unit.name.toTextButton()
button.onClick {
UncivGame.Current.setWorldScreen()
UncivGame.Current.worldScreen.mapHolder.setCenterPosition(unit.currentTile.position)

View File

@ -271,7 +271,7 @@ class MultiplayerScreen() : PickerScreen() {
if (!currentlyRunningGame.gameParameters.isOnlineMultiplayer || gameIsAlreadySavedAsMultiplayer(currentlyRunningGame.gameId))
return
val currentGameButton = TextButton("Add Currently Running Game".tr(), skin)
val currentGameButton = "Add Currently Running Game".toTextButton()
currentGameButton.onClick {
if (gameIsAlreadySavedAsMultiplayer(currentlyRunningGame.gameId))
return@onClick
@ -321,7 +321,7 @@ class EditMultiplayerGameInfoScreen(game: GameInfo, gameName: String, backScreen
//TODO Change delete to "give up"
//->turn a player into an AI so everyone can still play without the user
//->should only be possible on the users turn because it has to be uploaded afterwards
val deleteButton = TextButton("Delete save".tr(), skin)
val deleteButton = "Delete save".toTextButton()
deleteButton.onClick {
val askPopup = Popup(this)
askPopup.addGoodSizedLabel("Are you sure you want to delete this map?".tr()).row()

View File

@ -31,7 +31,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
private val pad = 10f
init {
showCityInfoTableButton = TextButton("Show stats drilldown".tr(), skin)
showCityInfoTableButton = "Show stats drilldown".toTextButton()
showCityInfoTableButton.onClick {
cityScreen.showConstructionsTable = false
cityScreen.update()

View File

@ -15,7 +15,7 @@ import com.unciv.ui.utils.*
class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
var chosenMap = ""
val deleteMapButton = TextButton("Delete map".tr(),skin)
val deleteMapButton = "Delete map".toTextButton()
init {
rightSideButton.setText("Load map".tr())
@ -40,7 +40,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
val rightSideTable = Table().apply { defaults().pad(10f) }
val downloadMapButton = TextButton("Download map".tr(), skin)
val downloadMapButton = "Download map".toTextButton()
downloadMapButton.onClick {
MapDownloadPopup(this).open()
}
@ -49,7 +49,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
rightSideTable.addSeparator()
val loadFromClipboardButton = TextButton("Load copied data".tr(), skin)
val loadFromClipboardButton = "Load copied data".toTextButton()
val couldNotLoadMapLabel = "Could not load map!".toLabel(Color.RED).apply { isVisible=false }
loadFromClipboardButton.onClick {
try {

View File

@ -11,10 +11,7 @@ import com.unciv.logic.map.MapType
import com.unciv.logic.map.RoadStatus
import com.unciv.models.translations.tr
import com.unciv.ui.saves.Gzip
import com.unciv.ui.utils.Popup
import com.unciv.ui.utils.enable
import com.unciv.ui.utils.isEnabled
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.mainmenu.DropBox
import kotlin.concurrent.thread
@ -26,13 +23,13 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScree
mapNameEditor.maxLength = 240 // A few under max for most filesystems
mapEditorScreen.stage.keyboardFocus = mapNameEditor
val newMapButton = TextButton("New map".tr(),skin)
val newMapButton = "New map".toTextButton()
newMapButton.onClick {
UncivGame.Current.setScreen(NewMapScreen())
}
add(newMapButton).row()
val clearCurrentMapButton = TextButton("Clear current map".tr(),skin)
val clearCurrentMapButton = "Clear current map".toTextButton()
clearCurrentMapButton.onClick {
for(tileGroup in mapEditorScreen.mapHolder.tileGroups.values)
{
@ -51,7 +48,7 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScree
}
add(clearCurrentMapButton).row()
val saveMapButton = TextButton("Save map".tr(), skin)
val saveMapButton = "Save map".toTextButton()
saveMapButton.onClick {
mapEditorScreen.tileMap.mapParameters.name=mapEditorScreen.mapName
mapEditorScreen.tileMap.mapParameters.type=MapType.custom
@ -78,7 +75,7 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScree
true
}
val copyMapAsTextButton = TextButton("Copy to clipboard".tr(), skin)
val copyMapAsTextButton = "Copy to clipboard".toTextButton()
copyMapAsTextButton.onClick {
val json = Json().toJson(mapEditorScreen.tileMap)
val base64Gzip = Gzip.zip(json)
@ -86,13 +83,13 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScree
}
add(copyMapAsTextButton).row()
val loadMapButton = TextButton("Load map".tr(), skin)
val loadMapButton = "Load map".toTextButton()
loadMapButton.onClick {
UncivGame.Current.setScreen(LoadMapScreen(mapEditorScreen.tileMap))
}
add(loadMapButton).row()
val uploadMapButton = TextButton("Upload map".tr(), skin)
val uploadMapButton = "Upload map".toTextButton()
uploadMapButton.onClick {
thread(name="MapUpload") {
try {
@ -116,11 +113,11 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScree
add(uploadMapButton).row()
val exitMapEditorButton = TextButton("Exit map editor".tr(), skin)
val exitMapEditorButton = "Exit map editor".toTextButton()
exitMapEditorButton.onClick { UncivGame.Current.setWorldScreen(); mapEditorScreen.dispose() }
add(exitMapEditorButton ).row()
val closeOptionsButton = TextButton(Constants.close.tr(), skin)
val closeOptionsButton = Constants.close.toTextButton()
closeOptionsButton.onClick { close() }
add(closeOptionsButton).row()
}

View File

@ -9,10 +9,7 @@ import com.unciv.logic.map.MapShape
import com.unciv.logic.map.MapSize
import com.unciv.logic.map.MapType
import com.unciv.models.translations.tr
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onChange
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
import com.unciv.ui.utils.*
/** Table for editing [mapParameters]
*
@ -110,7 +107,7 @@ class MapParametersTable(val mapParameters: MapParameters, val isEmptyMapAllowed
}
private fun addAdvancedSettings() {
val button = TextButton("Show advanced settings".tr(), skin)
val button = "Show advanced settings".toTextButton()
val advancedSettingsTable = Table()
.apply {isVisible = false; defaults().pad(5f)}
@ -133,12 +130,12 @@ class MapParametersTable(val mapParameters: MapParameters, val isEmptyMapAllowed
val sliders = HashMap<Slider, ()->Float>()
fun addSlider(text:String, getValue:()->Float, min:Float, max:Float, onChange: (value:Float)->Unit): Slider {
val slider = Slider(min, max, (max-min)/20,false,skin)
val slider = Slider(min, max, (max - min) / 20, false, skin)
slider.value = getValue()
slider.onChange { onChange(slider.value) }
advancedSettingsTable.add(text.toLabel()).left()
advancedSettingsTable.add(slider).fillX().row()
sliders.put(slider, getValue)
sliders[slider] = getValue
return slider
}
@ -166,7 +163,7 @@ class MapParametersTable(val mapParameters: MapParameters, val isEmptyMapAllowed
addSlider("Water level", {mapParameters.waterThreshold}, -0.1f, 0.1f)
{ mapParameters.waterThreshold = it }
val resetToDefaultButton = TextButton("Reset to default".tr(), skin)
val resetToDefaultButton = "Reset to default".toTextButton()
resetToDefaultButton.onClick {
mapParameters.resetAdvancedSettings()
for(entry in sliders)

View File

@ -9,7 +9,7 @@ import com.unciv.ui.utils.*
open class PickerScreen : CameraStageBaseScreen() {
internal var closeButton: TextButton = TextButton(Constants.close.tr(), skin)
internal var closeButton: TextButton = Constants.close.toTextButton()
protected var descriptionLabel: Label
protected var rightSideGroup = VerticalGroup()
protected var rightSideButton: TextButton

View File

@ -17,9 +17,9 @@ import java.util.*
class LoadGameScreen : PickerScreen() {
lateinit var selectedSave:String
private val copySavedGameToClipboardButton = TextButton("Copy saved game to clipboard".tr(),skin)
private val copySavedGameToClipboardButton = "Copy saved game to clipboard".toTextButton()
private val saveTable = Table()
private val deleteSaveButton = TextButton("Delete save".tr(), skin)
private val deleteSaveButton = "Delete save".toTextButton()
private val showAutosavesCheckbox = CheckBox("Show autosaves".tr(), skin)
init {
@ -61,7 +61,7 @@ class LoadGameScreen : PickerScreen() {
val rightSideTable = Table()
val errorLabel = "".toLabel(Color.RED)
val loadFromClipboardButton = TextButton("Load copied data".tr(), skin)
val loadFromClipboardButton = "Load copied data".toTextButton()
loadFromClipboardButton.onClick {
try {
val clipboardContentsString = Gdx.app.clipboard.contents.trim()

View File

@ -10,10 +10,7 @@ import com.unciv.UncivGame
import com.unciv.logic.GameSaver
import com.unciv.models.translations.tr
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onChange
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
import com.unciv.ui.utils.*
import kotlin.concurrent.thread
@ -35,7 +32,7 @@ class SaveGameScreen : PickerScreen() {
newSave.add("Saved game name".toLabel()).row()
newSave.add(textField).width(300f).pad(10f).row()
val copyJsonButton = TextButton("Copy to clipboard".tr(),skin)
val copyJsonButton = "Copy to clipboard".toTextButton()
copyJsonButton.onClick {
val json = Json().toJson(game.gameInfo)
val base64Gzip = Gzip.zip(json)

View File

@ -327,7 +327,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
}
demandsTable.add(dontSettleCitiesButton).row()
demandsTable.add(TextButton(Constants.close.tr(),skin).onClick { updateRightSide(otherCiv) })
demandsTable.add(Constants.close.toTextButton().onClick { updateRightSide(otherCiv) })
return demandsTable
}
@ -364,7 +364,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
diplomacyManager.declareWar()
setRightSideFlavorText(otherCiv, otherCiv.nation.attacked, "Very well.")
updateLeftSideTable()
}, this).open()
}, this).open()
}
return declareWarButton
}

View File

@ -51,7 +51,7 @@ open class Popup(val screen: CameraStageBaseScreen): Table(CameraStageBaseScreen
}
fun addButton(text: String, action: () -> Unit): Cell<TextButton> {
val button = TextButton(text.tr(), skin).apply { color = ImageGetter.getBlue() }
val button = text.toTextButton().apply { color = ImageGetter.getBlue() }
button.onClick(action)
return add(button).apply { row() }
}

View File

@ -8,7 +8,7 @@ class YesNoPopup(question:String, action:()->Unit,
screen: CameraStageBaseScreen = UncivGame.Current.worldScreen, restoredefault:()->Unit = {}) : Popup(screen){
init{
add(question.toLabel()).colspan(2).row()
add(TextButton("No".tr(), skin).onClick { close(); restoredefault() })
add(TextButton("Yes".tr(), skin).onClick { close(); action() })
add("No".toTextButton().onClick { close(); restoredefault() })
add("Yes".toTextButton().onClick { close(); action() })
}
}

View File

@ -10,10 +10,7 @@ import com.unciv.models.translations.tr
import com.unciv.ui.EmpireOverviewScreen
import com.unciv.ui.newgamescreen.NewGameScreen
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.addSeparator
import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
import com.unciv.ui.utils.*
class VictoryScreen : PickerScreen() {
@ -28,14 +25,11 @@ class VictoryScreen : PickerScreen() {
init {
val tabsTable = Table().apply { defaults().pad(10f) }
val setMyVictoryButton = TextButton("Our status".tr(),skin)
setMyVictoryButton.onClick { setMyVictoryTable() }
val setMyVictoryButton = "Our status".toTextButton().onClick { setMyVictoryTable() }
tabsTable.add(setMyVictoryButton)
val setGlobalVictoryButton = TextButton("Global status".tr(),skin)
setGlobalVictoryButton .onClick { setGlobalVictoryTable() }
val setGlobalVictoryButton = "Global status".toTextButton().onClick { setGlobalVictoryTable() }
tabsTable.add(setGlobalVictoryButton)
val setCivRankingsButton = TextButton("Rankings".tr(),skin)
setCivRankingsButton.onClick { setCivRankingsTable() }
val setCivRankingsButton = "Rankings".toTextButton().onClick { setCivRankingsTable() }
tabsTable.add(setCivRankingsButton)
topTable.add(tabsTable)
topTable.addSeparator()
@ -124,7 +118,8 @@ class VictoryScreen : PickerScreen() {
private fun scienceVictoryColumn():Table {
val t = Table()
t.defaults().pad(5f)
t.add(getMilestone("Built Apollo Program",playerCivInfo.containsBuildingUnique("Enables construction of Spaceship parts"))).row()
t.add(getMilestone("Built Apollo Program",
playerCivInfo.containsBuildingUnique("Enables construction of Spaceship parts"))).row()
val victoryManager= playerCivInfo.victoryManager
@ -159,7 +154,7 @@ class VictoryScreen : PickerScreen() {
}
fun getMilestone(text:String, achieved:Boolean): TextButton {
val textButton = TextButton(text.tr(),skin)
val textButton = text.toTextButton()
if(achieved) textButton.color = Color.GREEN
else textButton.color = Color.GRAY
return textButton

View File

@ -375,7 +375,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
.filterNot { it==viewingCiv || it.isBarbarian() }
.any()) {
displayTutorial(Tutorial.OtherCivEncountered)
val btn = TextButton("Diplomacy".tr(), skin)
val btn = "Diplomacy".toTextButton()
btn.onClick { UncivGame.Current.setScreen(DiplomacyScreen(viewingCiv)) }
btn.label.setFontSize(30)
btn.labelCell.pad(10f)