mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 00:09:23 +07:00
Added "Buy tile" option to cities
This commit is contained in:
@ -21,8 +21,8 @@ android {
|
||||
applicationId "com.unciv.game"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 26
|
||||
versionCode 138
|
||||
versionName "2.8.6"
|
||||
versionCode 139
|
||||
versionName "2.8.7"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@ -70,7 +70,7 @@ class Automation {
|
||||
}
|
||||
}
|
||||
|
||||
fun getMinDistanceBetweenCities(civ1:CivilizationInfo,civ2:CivilizationInfo): Float {
|
||||
fun getMinDistanceBetweenCities(civ1:CivilizationInfo,civ2:CivilizationInfo): Int {
|
||||
return civ1.cities.map { city -> civ2.cities.map { it.getCenterTile().arialDistanceTo(city.getCenterTile()) }.min()!! }.min()!!
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,22 @@ class CityExpansionManager {
|
||||
return Math.round(cultureToNextTile).toInt()
|
||||
}
|
||||
|
||||
fun buyTile(tileInfo: TileInfo){
|
||||
val goldCost = getGoldCostOfTile(tileInfo)
|
||||
class NotEnoughGoldToBuyTileException : Exception()
|
||||
if(cityInfo.civInfo.gold<goldCost) throw NotEnoughGoldToBuyTileException()
|
||||
cityInfo.civInfo.gold -= goldCost
|
||||
takeOwnership(tileInfo)
|
||||
}
|
||||
|
||||
fun getGoldCostOfTile(tileInfo: TileInfo): Int {
|
||||
val baseCost = 50
|
||||
val numTilesClaimed= cityInfo.tiles.size - 7
|
||||
val distanceFromCenter = tileInfo.arialDistanceTo(cityInfo.getCenterTile())
|
||||
val cost = baseCost * (distanceFromCenter-1) + numTilesClaimed*5
|
||||
return cost
|
||||
}
|
||||
|
||||
|
||||
fun chooseNewTileToOwn(): TileInfo? {
|
||||
for (i in 2..5) {
|
||||
|
@ -208,10 +208,14 @@ class MapUnit {
|
||||
fun moveToTile(otherTile: TileInfo) {
|
||||
if(otherTile==getTile()) return // already here!
|
||||
val distanceToTiles = getDistanceToTiles()
|
||||
|
||||
class YouCantGetThereFromHereException : Exception()
|
||||
if (!distanceToTiles.containsKey(otherTile))
|
||||
throw Exception("You can't get there from here!")
|
||||
throw YouCantGetThereFromHereException()
|
||||
|
||||
class CantEnterThisTileException : Exception()
|
||||
if(!canMoveTo(otherTile))
|
||||
throw Exception("Can't enter this tile!")
|
||||
throw CantEnterThisTileException()
|
||||
if(otherTile.isCityCenter() && otherTile.getOwner()!=civInfo) throw Exception("This is an enemy city, you can't go here!")
|
||||
|
||||
currentMovement -= distanceToTiles[otherTile]!!
|
||||
|
@ -244,5 +244,5 @@ open class TileInfo {
|
||||
return city!=null && city.workedTiles.contains(position)
|
||||
}
|
||||
|
||||
fun arialDistanceTo(otherTile:TileInfo) = abs(position.x-otherTile.position.x) + abs(position.y-otherTile.position.y)
|
||||
fun arialDistanceTo(otherTile:TileInfo): Int = (abs(position.x-otherTile.position.x) + abs(position.y-otherTile.position.y)).toInt()
|
||||
}
|
@ -34,7 +34,8 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
|
||||
offers.add(TradeOffer(city.name, TradeType.City, 0, 1))
|
||||
|
||||
val civsWeKnowAndTheyDont = civInfo.diplomacy.values.map { it.otherCiv() }
|
||||
.filter { !otherCivilization.diplomacy.containsKey(it.civName) && it != otherCivilization }
|
||||
.filter { !otherCivilization.diplomacy.containsKey(it.civName)
|
||||
&& it != otherCivilization && !it.isBarbarianCivilization() }
|
||||
for(thirdCiv in civsWeKnowAndTheyDont){
|
||||
offers.add(TradeOffer("Introduction to " + thirdCiv.civName, TradeType.Introduction, 0,1))
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import com.unciv.UnCivGame
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.ICivilopedia
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import java.util.*
|
||||
|
||||
class CivilopediaScreen : CameraStageBaseScreen() {
|
||||
@ -27,7 +27,7 @@ class CivilopediaScreen : CameraStageBaseScreen() {
|
||||
label.setWrap(true)
|
||||
|
||||
val goToGameButton = TextButton("Return \r\nto game", CameraStageBaseScreen.skin)
|
||||
goToGameButton.addClickListener {
|
||||
goToGameButton.onClick {
|
||||
game.setWorldScreen()
|
||||
dispose()
|
||||
}
|
||||
@ -48,7 +48,7 @@ class CivilopediaScreen : CameraStageBaseScreen() {
|
||||
val nameListClickListener = {
|
||||
if(nameList.selected!=null) label.setText(nameList.selected.description)
|
||||
}
|
||||
nameList.addClickListener (nameListClickListener)
|
||||
nameList.onClick (nameListClickListener)
|
||||
|
||||
nameList.style = List.ListStyle(nameList.style)
|
||||
nameList.style.fontColorSelected = Color.BLACK
|
||||
@ -70,7 +70,7 @@ class CivilopediaScreen : CameraStageBaseScreen() {
|
||||
for (btn in buttons) btn.isChecked = false
|
||||
button.isChecked = true
|
||||
}
|
||||
button.addClickListener(buttonClicked)
|
||||
button.onClick(buttonClicked)
|
||||
if (first) {// Fake-click the first button so that the user sees results immediately
|
||||
first = false
|
||||
buttonClicked()
|
||||
|
@ -21,7 +21,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
||||
val centerTable=Table().apply { defaults().pad(20f) }
|
||||
|
||||
val closeButton = TextButton("Close".tr(), skin)
|
||||
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
|
||||
closeButton.onClick { UnCivGame.Current.setWorldScreen() }
|
||||
closeButton.y = stage.height - closeButton.height - 5
|
||||
topTable.add(closeButton)
|
||||
|
||||
@ -33,11 +33,11 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
||||
centerTable.center(stage)
|
||||
}
|
||||
setCities()
|
||||
setCityInfoButton.addClickListener(setCities)
|
||||
setCityInfoButton.onClick(setCities)
|
||||
topTable.add(setCityInfoButton)
|
||||
|
||||
val setStatsInfoButton = TextButton("Stats".tr(),skin)
|
||||
setStatsInfoButton.addClickListener {
|
||||
setStatsInfoButton.onClick {
|
||||
centerTable.clear()
|
||||
centerTable.add(getHappinessTable())
|
||||
centerTable.add(getGoldTable())
|
||||
@ -47,7 +47,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
||||
topTable.add(setStatsInfoButton)
|
||||
|
||||
val setCurrentTradesButton = TextButton("Trades".tr(),skin)
|
||||
setCurrentTradesButton.addClickListener {
|
||||
setCurrentTradesButton.onClick {
|
||||
centerTable.clear()
|
||||
centerTable.add(ScrollPane(getTradesTable())).height(stage.height*0.8f) // so it doesn't cover the naviagation buttons
|
||||
centerTable.pack()
|
||||
@ -56,7 +56,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
||||
topTable.add(setCurrentTradesButton)
|
||||
|
||||
val setUnitsButton = TextButton("Units".tr(),skin)
|
||||
setUnitsButton .addClickListener {
|
||||
setUnitsButton .onClick {
|
||||
centerTable.clear()
|
||||
centerTable.add(getUnitTable())
|
||||
centerTable.pack()
|
||||
|
@ -9,7 +9,7 @@ import com.unciv.UnCivGame
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.enable
|
||||
import com.unciv.ui.utils.tr
|
||||
|
||||
@ -61,7 +61,7 @@ class LanguagePickerScreen: PickerScreen(){
|
||||
.sortedByDescending { it.percentComplete } )
|
||||
|
||||
languageTables.forEach {
|
||||
it.addClickListener {
|
||||
it.onClick {
|
||||
chosenLanguage = it.language
|
||||
rightSideButton.enable()
|
||||
update()
|
||||
@ -70,7 +70,7 @@ class LanguagePickerScreen: PickerScreen(){
|
||||
}
|
||||
|
||||
rightSideButton.setText("Pick language".tr())
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
UnCivGame.Current.settings.language = chosenLanguage
|
||||
UnCivGame.Current.settings.save()
|
||||
UnCivGame.Current.startNewGame()
|
||||
|
@ -21,7 +21,7 @@ class LoadScreen : PickerScreen() {
|
||||
val saveTable = Table()
|
||||
|
||||
val deleteSaveButton = TextButton("Delete save".tr(), CameraStageBaseScreen.skin)
|
||||
deleteSaveButton .addClickListener {
|
||||
deleteSaveButton .onClick {
|
||||
GameSaver().deleteSave(selectedSave)
|
||||
UnCivGame.Current.screen = LoadScreen()
|
||||
}
|
||||
@ -33,7 +33,7 @@ class LoadScreen : PickerScreen() {
|
||||
rightSideButton.setText("Load game".tr())
|
||||
saves.forEach {
|
||||
val textButton = TextButton(it,skin)
|
||||
textButton.addClickListener {
|
||||
textButton.onClick {
|
||||
selectedSave=it
|
||||
|
||||
var textToSet = it
|
||||
@ -58,7 +58,7 @@ class LoadScreen : PickerScreen() {
|
||||
val rightSideTable = Table()
|
||||
val loadFromClipboardButton = TextButton("Load copied data".tr(),skin)
|
||||
val errorLabel = Label("",skin).setFontColor(Color.RED)
|
||||
loadFromClipboardButton.addClickListener {
|
||||
loadFromClipboardButton.onClick {
|
||||
try{
|
||||
val clipboardContentsString = Gdx.app.clipboard.contents
|
||||
val decoded = Gzip.decompress(Gzip.decoder(clipboardContentsString))
|
||||
@ -75,7 +75,7 @@ class LoadScreen : PickerScreen() {
|
||||
rightSideTable.add(deleteSaveButton)
|
||||
topTable.add(rightSideTable)
|
||||
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
UnCivGame.Current.loadGame(selectedSave)
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ class NewGameScreen: PickerScreen(){
|
||||
background=ImageGetter.getBackground(nation.getColor().apply { a=0.5f })
|
||||
add(Label(nation.name, skin).apply { setFontColor(nation.getSecondaryColor())}).row()
|
||||
add(Label(getUniqueLabel(nation), skin).apply { setWrap(true);setFontColor(nation.getSecondaryColor())}).width(width)
|
||||
addClickListener { newGameParameters.nation=nation.name; onClick() }
|
||||
onClick { newGameParameters.nation=nation.name; onClick() }
|
||||
touchable=Touchable.enabled
|
||||
update()
|
||||
}
|
||||
@ -142,7 +142,7 @@ class NewGameScreen: PickerScreen(){
|
||||
|
||||
rightSideButton.enable()
|
||||
rightSideButton.setText("Start game!".tr())
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked!
|
||||
rightSideButton.disable()
|
||||
rightSideButton.setText("Working...".tr())
|
||||
|
@ -10,7 +10,7 @@ import com.badlogic.gdx.utils.Json
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.enable
|
||||
import com.unciv.ui.utils.getRandom
|
||||
import com.unciv.ui.utils.tr
|
||||
@ -33,7 +33,7 @@ class SaveScreen : PickerScreen() {
|
||||
val saves = GameSaver().getSaves()
|
||||
saves.forEach {
|
||||
val textButton = TextButton(it, skin)
|
||||
textButton.addClickListener {
|
||||
textButton.onClick {
|
||||
textField.text = it
|
||||
}
|
||||
currentSaves.add(textButton).pad(5f).row()
|
||||
@ -55,7 +55,7 @@ class SaveScreen : PickerScreen() {
|
||||
newSave.add(textField).width(300f).pad(10f).row()
|
||||
|
||||
val copyJsonButton = TextButton("Copy game info".tr(),skin)
|
||||
copyJsonButton.addClickListener {
|
||||
copyJsonButton.onClick {
|
||||
val json = Json().toJson(game.gameInfo)
|
||||
val base64Gzip = Gzip.encoder(Gzip.compress(json))
|
||||
Gdx.app.clipboard.contents = base64Gzip
|
||||
@ -66,7 +66,7 @@ class SaveScreen : PickerScreen() {
|
||||
topTable.pack()
|
||||
|
||||
rightSideButton.setText("Save game".tr())
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
GameSaver().saveGame(UnCivGame.Current.gameInfo, textField.text)
|
||||
UnCivGame.Current.setWorldScreen()
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.enable
|
||||
import com.unciv.ui.utils.tr
|
||||
|
||||
@ -52,7 +52,7 @@ class VictoryScreen : PickerScreen() {
|
||||
rightSideButton.isVisible=true
|
||||
closeButton.isVisible=false
|
||||
rightSideButton.enable()
|
||||
rightSideButton.addClickListener { UnCivGame.Current.startNewGame() }
|
||||
rightSideButton.onClick { UnCivGame.Current.startNewGame() }
|
||||
}
|
||||
|
||||
fun scienceVictoryColumn():Table{
|
||||
|
@ -9,7 +9,7 @@ import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter.getImage
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.setFont
|
||||
|
||||
|
||||
@ -79,11 +79,11 @@ class BuildingsTable(private val cityScreen: CityScreen) : Table() {
|
||||
val specialist = getImage(imageName)
|
||||
specialist.setSize(50f, 50f)
|
||||
if (!isFilled) specialist.color = Color.GRAY
|
||||
specialist.addClickListener( {
|
||||
specialist.onClick( {
|
||||
val cityInfo = cityScreen.city
|
||||
when {
|
||||
isFilled -> cityInfo.population.buildingsSpecialists[building]!!.add(stat,-1f) //unassign
|
||||
cityInfo.population.getFreePopulation() == 0 -> return@addClickListener
|
||||
cityInfo.population.getFreePopulation() == 0 -> return@onClick
|
||||
else -> {
|
||||
if (!cityInfo.population.buildingsSpecialists.containsKey(building))
|
||||
cityInfo.population.buildingsSpecialists[building] = Stats()
|
||||
|
@ -102,11 +102,12 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
||||
|
||||
private fun updateTileGroups() {
|
||||
val nextTile = city.expansion.chooseNewTileToOwn()
|
||||
for (HG in tileGroups) {
|
||||
HG.update()
|
||||
if(HG.tileInfo == nextTile){
|
||||
HG.showCircle(Color.PURPLE)
|
||||
HG.setColor(0f,0f,0f,0.7f)
|
||||
for (tileGroup in tileGroups) {
|
||||
|
||||
tileGroup.update()
|
||||
if(tileGroup.tileInfo == nextTile){
|
||||
tileGroup.showCircle(Color.PURPLE)
|
||||
tileGroup.setColor(0f,0f,0f,0.7f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +120,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
||||
val civInfo = city.civInfo
|
||||
if (civInfo.cities.size > 1) {
|
||||
val prevCityButton = TextButton("<", CameraStageBaseScreen.skin)
|
||||
prevCityButton.addClickListener {
|
||||
prevCityButton.onClick {
|
||||
val indexOfCity = civInfo.cities.indexOf(city)
|
||||
val indexOfNextCity = if (indexOfCity == 0) civInfo.cities.size - 1 else indexOfCity - 1
|
||||
game.screen = CityScreen(civInfo.cities[indexOfNextCity])
|
||||
@ -145,7 +146,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
||||
|
||||
if (civInfo.cities.size > 1) {
|
||||
val nextCityButton = TextButton(">", CameraStageBaseScreen.skin)
|
||||
nextCityButton.addClickListener {
|
||||
nextCityButton.onClick {
|
||||
val indexOfCity = civInfo.cities.indexOf(city)
|
||||
val indexOfNextCity = if (indexOfCity == civInfo.cities.size - 1) 0 else indexOfCity + 1
|
||||
game.screen = CityScreen(civInfo.cities[indexOfNextCity])
|
||||
@ -157,12 +158,12 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
||||
|
||||
if(!city.isBeingRazed) {
|
||||
val razeCityButton = TextButton("Raze city".tr(), skin)
|
||||
razeCityButton.addClickListener { city.isBeingRazed=true; update() }
|
||||
razeCityButton.onClick { city.isBeingRazed=true; update() }
|
||||
cityPickerTable.add(razeCityButton).colspan(cityPickerTable.columns)
|
||||
}
|
||||
else{
|
||||
val stopRazingCityButton = TextButton("Stop razing city".tr(), skin)
|
||||
stopRazingCityButton.addClickListener { city.isBeingRazed=false; update() }
|
||||
stopRazingCityButton.onClick { city.isBeingRazed=false; update() }
|
||||
cityPickerTable.add(stopRazingCityButton).colspan(cityPickerTable.columns)
|
||||
}
|
||||
|
||||
@ -173,7 +174,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
||||
|
||||
private fun updateGoToWorldButton() {
|
||||
goToWorldButton.clearListeners()
|
||||
goToWorldButton.addClickListener {
|
||||
goToWorldButton.onClick {
|
||||
game.setWorldScreen()
|
||||
game.worldScreen.tileMapHolder.setCenterPosition(city.location)
|
||||
dispose()
|
||||
@ -191,36 +192,38 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
||||
|
||||
for (tileInfo in cityInfo.getCenterTile().getTilesInDistance(5)) {
|
||||
if (!city.civInfo.exploredTiles.contains(tileInfo.position)) continue // Don't even bother to display it.
|
||||
val group = CityTileGroup(cityInfo, tileInfo)
|
||||
group.addClickListener {
|
||||
val tileGroup = CityTileGroup(cityInfo, tileInfo)
|
||||
val tilesInRange = city.getTilesInRange()
|
||||
|
||||
// this needs to happen on pdate, because we can buy tiles, which changes the definition of the bought tiles...
|
||||
if (tileInfo.getCity()!=city) { // outside of city
|
||||
tileGroup.setColor(0f, 0f, 0f, 0.3f)
|
||||
tileGroup.yieldGroup.isVisible = false
|
||||
} else if(tileInfo !in tilesInRange){ // within city but not close enough to be workable
|
||||
tileGroup.yieldGroup.isVisible = false
|
||||
}
|
||||
else if (!tileInfo.isCityCenter() && tileGroup.populationImage==null) { // workable
|
||||
tileGroup.addPopulationIcon()
|
||||
tileGroup.populationImage!!.onClick {
|
||||
if (!tileInfo.isWorked() && city.population.getFreePopulation() > 0)
|
||||
city.workedTiles.add(tileInfo.position)
|
||||
else if (tileInfo.isWorked()) city.workedTiles.remove(tileInfo.position)
|
||||
city.cityStats.update()
|
||||
update()
|
||||
}
|
||||
}
|
||||
tileGroup.onClick {
|
||||
selectedTile = tileInfo
|
||||
update()
|
||||
}
|
||||
|
||||
val tilesInRange = city.getTilesInRange()
|
||||
if (tileInfo.getCity()!=city) { // outside of city
|
||||
group.setColor(0f, 0f, 0f, 0.3f)
|
||||
group.yieldGroup.isVisible = false
|
||||
} else if(tileInfo !in tilesInRange){ // within city but not close enough to be workable
|
||||
group.yieldGroup.isVisible = false
|
||||
}
|
||||
else if (!tileInfo.isCityCenter()) { // workable
|
||||
group.addPopulationIcon()
|
||||
group.populationImage!!.addClickListener {
|
||||
if (!tileInfo.isWorked() && cityInfo.population.getFreePopulation() > 0)
|
||||
cityInfo.workedTiles.add(tileInfo.position)
|
||||
else if (tileInfo.isWorked()) cityInfo.workedTiles.remove(tileInfo.position)
|
||||
cityInfo.cityStats.update()
|
||||
update()
|
||||
}
|
||||
}
|
||||
|
||||
val positionalVector = HexMath().Hex2WorldCoords(tileInfo.position.cpy().sub(cityInfo.location))
|
||||
val groupSize = 50
|
||||
group.setPosition(stage.width / 2 + positionalVector.x * 0.8f * groupSize.toFloat(),
|
||||
tileGroup.setPosition(stage.width / 2 + positionalVector.x * 0.8f * groupSize.toFloat(),
|
||||
stage.height / 2 + positionalVector.y * 0.8f * groupSize.toFloat())
|
||||
tileGroups.add(group)
|
||||
allTiles.addActor(group)
|
||||
tileGroups.add(tileGroup)
|
||||
allTiles.addActor(tileGroup)
|
||||
}
|
||||
|
||||
val scrollPane = ScrollPane(allTiles)
|
||||
@ -251,19 +254,30 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
||||
|
||||
private fun updateTileTable() {
|
||||
if (selectedTile == null) return
|
||||
val tile = selectedTile!!
|
||||
tileTable.clearChildren()
|
||||
|
||||
val stats = selectedTile!!.getTileStats(city, city.civInfo)
|
||||
val stats = tile.getTileStats(city, city.civInfo)
|
||||
tileTable.pad(20f)
|
||||
tileTable.columnDefaults(0).padRight(10f)
|
||||
|
||||
tileTable.add(Label(selectedTile!!.toString(), CameraStageBaseScreen.skin)).colspan(2)
|
||||
tileTable.add(Label(tile.toString(), CameraStageBaseScreen.skin)).colspan(2)
|
||||
tileTable.row()
|
||||
|
||||
val statsTable = Table()
|
||||
for (entry in stats.toHashMap().filterNot { it.value==0f }) {
|
||||
tileTable.add(ImageGetter.getStatIcon(entry.key.toString())).size(20f).align(Align.right)
|
||||
tileTable.add(Label(Math.round(entry.value).toString() + "", CameraStageBaseScreen.skin)).align(Align.left)
|
||||
tileTable.row()
|
||||
statsTable.add(ImageGetter.getStatIcon(entry.key.toString())).size(20f).align(Align.right)
|
||||
statsTable.add(Label(Math.round(entry.value).toString() + "", CameraStageBaseScreen.skin)).align(Align.left)
|
||||
statsTable.row()
|
||||
}
|
||||
tileTable.add(statsTable).row()
|
||||
|
||||
if(tile.getOwner()==null && tile.neighbors.any{it.getCity()==city}){
|
||||
val goldCostOfTile = city.expansion.getGoldCostOfTile(tile)
|
||||
val buyTileButton = TextButton("Buy for [$goldCostOfTile] gold".tr(),skin)
|
||||
buyTileButton.onClick { city.expansion.buyTile(tile); game.screen = CityScreen(city); dispose() }
|
||||
if(goldCostOfTile>city.civInfo.gold) buyTileButton.disable()
|
||||
tileTable.add(buyTileButton)
|
||||
}
|
||||
|
||||
tileTable.pack()
|
||||
|
@ -51,7 +51,7 @@ class CityStatsTable(val cityScreen: CityScreen) : Table(){
|
||||
buildingPickButton.add(ImageGetter.getConstructionImage(city.cityConstructions.currentConstruction))
|
||||
.size(40f).padRight(5f)
|
||||
buildingPickButton.add(Label(buildingText , CameraStageBaseScreen.skin).setFontColor(Color.WHITE))
|
||||
buildingPickButton.addClickListener {
|
||||
buildingPickButton.onClick {
|
||||
UnCivGame.Current.screen = ConstructionPickerScreen(city)
|
||||
cityScreen.dispose()
|
||||
}
|
||||
@ -68,7 +68,7 @@ class CityStatsTable(val cityScreen: CityScreen) : Table(){
|
||||
row()
|
||||
val buildingGoldCost = construction.getGoldCost(city.civInfo.policies.getAdoptedPolicies())
|
||||
val buildingBuyButton = TextButton("Buy for [$buildingGoldCost] gold".tr(), CameraStageBaseScreen.skin)
|
||||
buildingBuyButton.addClickListener {
|
||||
buildingBuyButton.onClick {
|
||||
city.cityConstructions.purchaseBuilding(city.cityConstructions.currentConstruction)
|
||||
update()
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import com.unciv.logic.city.SpecialConstruction
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.cityscreen.CityScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.setFontColor
|
||||
import com.unciv.ui.utils.tr
|
||||
|
||||
@ -21,7 +21,7 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
||||
val productionTextButton = Button(skin)
|
||||
productionTextButton.add(ImageGetter.getConstructionImage(production)).size(40f).padRight(5f)
|
||||
productionTextButton.add(Label(buttonText,skin).setFontColor(Color.WHITE))
|
||||
productionTextButton.addClickListener {
|
||||
productionTextButton.onClick {
|
||||
selectedProduction = production
|
||||
pick(rightSideButtonText)
|
||||
descriptionLabel.setText(description)
|
||||
@ -34,7 +34,7 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
||||
val civInfo = game.gameInfo.getPlayerCivilization()
|
||||
|
||||
closeButton.clearListeners() // Don't go back to the world screen, unlike the other picker screens!
|
||||
closeButton.addClickListener {
|
||||
closeButton.onClick {
|
||||
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
||||
dispose()
|
||||
}
|
||||
@ -44,7 +44,7 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
||||
}
|
||||
|
||||
rightSideButton.setText("Pick construction".tr())
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
city.cityConstructions.currentConstruction = selectedProduction!!
|
||||
city.cityStats.update() // Because maybe we set/removed the science or gold production options.
|
||||
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
||||
|
@ -7,7 +7,7 @@ import com.unciv.UnCivGame
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.unit.BaseUnit
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.setFontColor
|
||||
|
||||
class GreatPersonPickerScreen : PickerScreen() {
|
||||
@ -22,7 +22,7 @@ class GreatPersonPickerScreen : PickerScreen() {
|
||||
button.add(ImageGetter.getUnitIcon(unit.name)).size(30f).pad(10f)
|
||||
button.add(Label(unit.name, skin).setFontColor(Color.WHITE)).pad(10f)
|
||||
button.pack()
|
||||
button.addClickListener {
|
||||
button.onClick {
|
||||
theChosenOne = unit
|
||||
pick("Get " +unit.name)
|
||||
descriptionLabel.setText(unit.baseDescription)
|
||||
@ -30,7 +30,7 @@ class GreatPersonPickerScreen : PickerScreen() {
|
||||
topTable.add(button).pad(10f)
|
||||
}
|
||||
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
val civInfo = UnCivGame.Current.gameInfo.getPlayerCivilization()
|
||||
civInfo.placeUnitNearTile(civInfo.cities[0].location, theChosenOne!!.name)
|
||||
civInfo.greatPeople.freeGreatPeople--
|
||||
|
@ -8,7 +8,7 @@ import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.tile.TileImprovement
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.setFontColor
|
||||
import com.unciv.ui.utils.tr
|
||||
|
||||
@ -19,7 +19,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo) : PickerScreen() {
|
||||
val civInfo = game.gameInfo.getPlayerCivilization()
|
||||
|
||||
rightSideButton.setText("Pick improvement")
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
tileInfo.startWorkingOnImprovement(selectedImprovement!!, civInfo)
|
||||
game.setWorldScreen()
|
||||
dispose()
|
||||
@ -39,7 +39,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo) : PickerScreen() {
|
||||
improvementButton.add(Label(improvement.name + " - " + improvement.getTurnsToBuild(civInfo) + " {turns}".tr(),skin)
|
||||
.setFontColor(Color.WHITE)).pad(10f)
|
||||
|
||||
improvementButton.addClickListener {
|
||||
improvementButton.onClick {
|
||||
selectedImprovement = improvement
|
||||
pick(improvement.name)
|
||||
descriptionLabel.setText(improvement.description)
|
||||
|
@ -16,7 +16,7 @@ open class PickerScreen : CameraStageBaseScreen() {
|
||||
internal var splitPane: SplitPane
|
||||
|
||||
init {
|
||||
closeButton.addClickListener {
|
||||
closeButton.onClick {
|
||||
game.setWorldScreen()
|
||||
dispose()
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
|
||||
}
|
||||
else onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
|
||||
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
civInfo.policies.adopt(pickedPolicy!!)
|
||||
|
||||
// If we've moved to another screen in the meantime (great person pick, victory screen) ignore this
|
||||
@ -106,7 +106,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
|
||||
{
|
||||
policyButton.color = Color.GRAY
|
||||
}
|
||||
policyButton.addClickListener { pickPolicy(policy) }
|
||||
policyButton.onClick { pickPolicy(policy) }
|
||||
policyButton.pack()
|
||||
return policyButton
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() {
|
||||
init {
|
||||
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
|
||||
rightSideButton.setText("Pick promotion")
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
mapUnit.promotions.addPromotion(selectedPromotion!!.name)
|
||||
if(mapUnit.promotions.canBePromoted()) game.screen = PromotionPickerScreen(mapUnit)
|
||||
else game.setWorldScreen()
|
||||
@ -40,7 +40,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() {
|
||||
.setFontColor(Color.WHITE)).pad(10f)
|
||||
if(unitHasPromotion) promotionButton.color = Color.GREEN
|
||||
|
||||
promotionButton.addClickListener {
|
||||
promotionButton.onClick {
|
||||
selectedPromotion = promotion
|
||||
rightSideButton.setText(promotion.name)
|
||||
if(isPromotionAvailable && !unitHasPromotion) rightSideButton.enable()
|
||||
|
@ -9,7 +9,7 @@ import com.unciv.logic.civilization.TechManager
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.tech.Technology
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.disable
|
||||
import com.unciv.ui.utils.tr
|
||||
import java.util.*
|
||||
@ -59,7 +59,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
else {
|
||||
val TB = TextButton("", CameraStageBaseScreen.skin)
|
||||
techNameToButton[tech.name] = TB
|
||||
TB.addClickListener {
|
||||
TB.onClick {
|
||||
selectTechnology(tech)
|
||||
}
|
||||
topTable.add(TB)
|
||||
@ -71,7 +71,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
||||
setButtonsInfo()
|
||||
|
||||
rightSideButton.setText("Pick a tech".tr())
|
||||
rightSideButton.addClickListener {
|
||||
rightSideButton.onClick {
|
||||
if (isFreeTechPick) {
|
||||
civTech.techsResearched.add(selectedTech!!.name)
|
||||
civTech.freeTechs -= 1
|
||||
|
@ -88,7 +88,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
||||
val label = Label(cityButtonText, CameraStageBaseScreen.skin)
|
||||
label.setFontColor(city.civInfo.getNation().getSecondaryColor())
|
||||
if (city.civInfo.isPlayerCivilization())
|
||||
label.addClickListener {
|
||||
label.onClick {
|
||||
UnCivGame.Current.screen = CityScreen(city)
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ class DiplomacyScreen():CameraStageBaseScreen(){
|
||||
|
||||
|
||||
val closeButton = TextButton("Close".tr(), skin)
|
||||
closeButton.addClickListener { UnCivGame.Current.setWorldScreen() }
|
||||
closeButton.onClick { UnCivGame.Current.setWorldScreen() }
|
||||
closeButton.y = stage.height - closeButton.height - 10
|
||||
closeButton.x = 10f
|
||||
stage.addActor(closeButton) // This must come after the split pane so it will be above, that the button will be clickable
|
||||
@ -44,7 +44,7 @@ class DiplomacyScreen():CameraStageBaseScreen(){
|
||||
.apply { setFont(22); setFontColor(civ.getNation().getSecondaryColor()) }).row()
|
||||
|
||||
val tradeButton = TextButton("Trade".tr(), skin)
|
||||
tradeButton.addClickListener {
|
||||
tradeButton.onClick {
|
||||
rightSideTable.clear()
|
||||
rightSideTable.add(TradeTable(civ, stage){updateLeftSideTable()})
|
||||
}
|
||||
@ -58,7 +58,7 @@ class DiplomacyScreen():CameraStageBaseScreen(){
|
||||
declareWarButton.disable()
|
||||
declareWarButton.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty)")
|
||||
}
|
||||
declareWarButton.addClickListener {
|
||||
declareWarButton.onClick {
|
||||
civDiplomacy.declareWar()
|
||||
updateLeftSideTable()
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.logic.trade.TradeOffersList
|
||||
import com.unciv.logic.trade.TradeType
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.disable
|
||||
import com.unciv.ui.utils.tr
|
||||
import kotlin.math.min
|
||||
@ -31,7 +31,7 @@ class OffersList(val offers: TradeOffersList, val correspondingOffers: TradeOffe
|
||||
if(offer.type== TradeType.Gold) 50
|
||||
else 1
|
||||
if(offer.amount>0)
|
||||
tb.addClickListener {
|
||||
tb.onClick {
|
||||
val amountTransferred = min(amountPerClick, offer.amount)
|
||||
offers += offer.copy(amount = -amountTransferred)
|
||||
correspondingOffers += offer.copy(amount = amountTransferred)
|
||||
|
@ -8,7 +8,7 @@ import com.unciv.UnCivGame
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.trade.TradeLogic
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.tr
|
||||
|
||||
class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage, onTradeComplete: () -> Unit): Table(CameraStageBaseScreen.skin){
|
||||
@ -27,7 +27,7 @@ class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage, onTradeC
|
||||
|
||||
lowerTable.add(tradeText).colspan(2).row()
|
||||
|
||||
offerButton.addClickListener {
|
||||
offerButton.onClick {
|
||||
if(offerButton.text.toString() == "Offer trade".tr()) {
|
||||
if(tradeLogic.currentTrade.theirOffers.size==0 && tradeLogic.currentTrade.ourOffers.size==0){
|
||||
tradeText.setText("There's nothing on the table.".tr())
|
||||
|
@ -99,7 +99,7 @@ open class CameraStageBaseScreen : Screen {
|
||||
tutorialTexts.removeAt(0)
|
||||
tutorialTable.add(label).pad(10f).row()
|
||||
val button = TextButton("Close".tr(), skin)
|
||||
button.addClickListener {
|
||||
button.onClick {
|
||||
tutorialTable.remove()
|
||||
if (!tutorialTexts.isEmpty())
|
||||
displayTutorial()
|
||||
@ -238,7 +238,7 @@ fun Label.setFont(size:Int): Label {
|
||||
return this // for chaining
|
||||
}
|
||||
|
||||
fun Actor.addClickListener(function: () -> Unit) {
|
||||
fun Actor.onClick(function: () -> Unit) {
|
||||
this.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
function()
|
||||
|
@ -11,7 +11,7 @@ import com.unciv.logic.HexMath
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
|
||||
class Minimap(val tileMapHolder: TileMapHolder) : ScrollPane(null){
|
||||
val allTiles = Group()
|
||||
@ -37,7 +37,7 @@ class Minimap(val tileMapHolder: TileMapHolder) : ScrollPane(null){
|
||||
hex.setSize(groupSize,groupSize)
|
||||
hex.setPosition(positionalVector.x * 0.5f * groupSize,
|
||||
positionalVector.y * 0.5f * groupSize)
|
||||
hex.addClickListener {
|
||||
hex.onClick {
|
||||
tileMapHolder.setCenterPosition(tileInfo.position)
|
||||
setScrollToTileMapHolder()
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class NotificationsScroll(internal val worldScreen: WorldScreen) : ScrollPane(nu
|
||||
minitable.add(label).pad(3f).padRight(10f)
|
||||
|
||||
if (notification.location != null) {
|
||||
minitable.addClickListener {
|
||||
minitable.onClick {
|
||||
worldScreen.tileMapHolder.setCenterPosition(notification.location!!)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.gamebasics.unit.UnitType
|
||||
import com.unciv.ui.tilegroups.WorldTileGroup
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.utils.center
|
||||
import com.unciv.ui.utils.colorFromRGB
|
||||
|
||||
@ -37,7 +37,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
for (tileInfo in tileMap.values) {
|
||||
val group = WorldTileGroup(tileInfo)
|
||||
|
||||
group.addClickListener {
|
||||
group.onClick {
|
||||
worldScreen.displayTutorials("TileClicked")
|
||||
if(overlayActor!=null) overlayActor!!.remove()
|
||||
selectedTile = tileInfo
|
||||
@ -50,7 +50,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
// moveHereGroup.addActor(ImageGetter.getImage("OtherIcons/Circle").apply { width = size; height = size })
|
||||
// moveHereGroup.addActor(ImageGetter.getStatIcon("Movement").apply { width = size / 2; height = size / 2; center(moveHereGroup) })
|
||||
// if(selectedUnit.currentMovement>0)
|
||||
// moveHereGroup.addClickListener { selectedUnit.movementAlgs().headTowards(tileInfo);worldScreen.update() }
|
||||
// moveHereGroup.onClick { selectedUnit.movementAlgs().headTowards(tileInfo);worldScreen.update() }
|
||||
// else moveHereGroup.color.a=0.5f
|
||||
// addAboveGroup(group, moveHereGroup).apply { width = size; height = size }
|
||||
// }
|
||||
|
@ -49,7 +49,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
|
||||
tileMapHolder.addTiles()
|
||||
|
||||
techButton.addClickListener {
|
||||
techButton.onClick {
|
||||
game.screen = TechPickerScreen(civInfo)
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
.any()) {
|
||||
displayTutorials("OtherCivEncountered")
|
||||
val btn = TextButton("Diplomacy".tr(), skin)
|
||||
btn.addClickListener { UnCivGame.Current.screen = DiplomacyScreen() }
|
||||
btn.onClick { UnCivGame.Current.screen = DiplomacyScreen() }
|
||||
diplomacyButtonWrapper.add(btn)
|
||||
}
|
||||
diplomacyButtonWrapper.pack()
|
||||
@ -166,18 +166,18 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
|
||||
private fun createNextTurnButton(): TextButton {
|
||||
val nextTurnButton = TextButton("Next turn".tr(), CameraStageBaseScreen.skin)
|
||||
nextTurnButton.addClickListener {
|
||||
nextTurnButton.onClick {
|
||||
if (civInfo.tech.freeTechs != 0) {
|
||||
game.screen = TechPickerScreen(true, civInfo)
|
||||
return@addClickListener
|
||||
return@onClick
|
||||
} else if (civInfo.policies.shouldOpenPolicyPicker) {
|
||||
game.screen = PolicyPickerScreen(civInfo)
|
||||
civInfo.policies.shouldOpenPolicyPicker = false
|
||||
return@addClickListener
|
||||
return@onClick
|
||||
}
|
||||
else if (civInfo.tech.currentTechnology() == null && civInfo.cities.isNotEmpty()) {
|
||||
game.screen = TechPickerScreen(civInfo)
|
||||
return@addClickListener
|
||||
return@onClick
|
||||
}
|
||||
|
||||
bottomBar.unitTable.currentlyExecutingAction = null
|
||||
|
@ -47,7 +47,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
|
||||
addActor(getMenuButton()) // needs to be after pack
|
||||
|
||||
val button = TextButton("Overview".tr(),CameraStageBaseScreen.skin)
|
||||
button.addClickListener { UnCivGame.Current.screen = EmpireOverviewScreen() }
|
||||
button.onClick { UnCivGame.Current.screen = EmpireOverviewScreen() }
|
||||
button.center(this)
|
||||
button.x = screen.stage.width-button.width-10
|
||||
addActor(button)
|
||||
@ -93,7 +93,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
|
||||
val menuButton = ImageGetter.getImage("OtherIcons/MenuIcon.png")
|
||||
.apply { setSize(50f, 50f) }
|
||||
menuButton.color = Color.WHITE
|
||||
menuButton.addClickListener {
|
||||
menuButton.onClick {
|
||||
if(screen.stage.actors.none { it is WorldScreenOptionsTable })
|
||||
screen.stage.addActor(WorldScreenOptionsTable())
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
||||
|
||||
if(attackableEnemy==null || !attacker.unit.canAttack()) attackButton.disable()
|
||||
else {
|
||||
attackButton.addClickListener {
|
||||
attackButton.onClick {
|
||||
attacker.unit.moveToTile(attackableEnemy.tileToAttackFrom)
|
||||
battle.attack(attacker, defender)
|
||||
worldScreen.update()
|
||||
|
@ -18,7 +18,7 @@ open class PopupTable: Table(){
|
||||
|
||||
fun addButton(text:String, action:()->Unit){
|
||||
val button = TextButton(text.tr(), CameraStageBaseScreen.skin).apply { color= ImageGetter.getBlue() }
|
||||
button.addClickListener(action)
|
||||
button.onClick(action)
|
||||
add(button).row()
|
||||
}
|
||||
}
|
||||
@ -31,8 +31,8 @@ class YesNoPopupTable(question:String, action:()->Unit,
|
||||
val skin = CameraStageBaseScreen.skin
|
||||
add(Label(question, skin)).colspan(2).row()
|
||||
|
||||
add(TextButton("No".tr(), skin).apply { addClickListener { close() } })
|
||||
add(TextButton("Yes".tr(), skin).apply { addClickListener { close(); action() } })
|
||||
add(TextButton("No".tr(), skin).apply { onClick { close() } })
|
||||
add(TextButton("Yes".tr(), skin).apply { onClick { close(); action() } })
|
||||
pack()
|
||||
center(screen.stage)
|
||||
screen.stage.addActor(this)
|
||||
|
@ -3,7 +3,7 @@ package com.unciv.ui.worldscreen.unit
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.addClickListener
|
||||
import com.unciv.ui.utils.onClick
|
||||
import com.unciv.ui.worldscreen.TileMapHolder
|
||||
|
||||
class IdleUnitButton internal constructor(internal val unitTable: UnitTable,
|
||||
@ -13,7 +13,7 @@ class IdleUnitButton internal constructor(internal val unitTable: UnitTable,
|
||||
fun getTilesWithIdleUnits() = tileMapHolder.tileMap.values
|
||||
.filter { it.hasIdleUnit() && it.getUnits().first().owner == unitTable.worldScreen.civInfo.civName }
|
||||
init {
|
||||
addClickListener {
|
||||
onClick {
|
||||
val tilesWithIdleUnits = getTilesWithIdleUnits()
|
||||
|
||||
val tileToSelect: TileInfo
|
||||
|
@ -59,7 +59,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){
|
||||
actionButton.add(Label(unitAction.name.tr(),CameraStageBaseScreen.skin)
|
||||
.setFontColor(Color.WHITE)).pad(5f)
|
||||
actionButton.pack()
|
||||
actionButton.addClickListener({ unitAction.action(); UnCivGame.Current.worldScreen.update() })
|
||||
actionButton.onClick({ unitAction.action(); UnCivGame.Current.worldScreen.update() })
|
||||
if (!unitAction.canAct) actionButton.disable()
|
||||
return actionButton
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
||||
for(promotion in selectedUnit!!.promotions.promotions)
|
||||
promotionsTable.add(ImageGetter.getPromotionIcon(promotion)).size(20f)
|
||||
|
||||
unitDescriptionLabel.addClickListener { worldScreen.tileMapHolder.setCenterPosition(selectedUnit!!.getTile().position) }
|
||||
unitDescriptionLabel.onClick { worldScreen.tileMapHolder.setCenterPosition(selectedUnit!!.getTile().position) }
|
||||
}
|
||||
|
||||
pack()
|
||||
|
Reference in New Issue
Block a user