Changed click listeners to lambdas
This commit is contained in:
parent
bded16720d
commit
abe3d76df7
7 changed files with 35 additions and 63 deletions
|
@ -2,10 +2,8 @@ package com.unciv.ui
|
|||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.List
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.ICivilopedia
|
||||
|
@ -29,12 +27,10 @@ class CivilopediaScreen : CameraStageBaseScreen() {
|
|||
label.setWrap(true)
|
||||
|
||||
val goToGameButton = TextButton("Return \r\nto game", CameraStageBaseScreen.skin)
|
||||
goToGameButton.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
goToGameButton.addClickListener {
|
||||
game.setWorldScreen()
|
||||
dispose()
|
||||
}
|
||||
})
|
||||
buttonTable.add(goToGameButton)
|
||||
|
||||
val map = LinkedHashMap<String, Collection<ICivilopedia>>()
|
||||
|
|
|
@ -1,27 +1,24 @@
|
|||
package com.unciv.ui.pickerscreens
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.cityscreen.CityScreen
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
|
||||
class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
||||
var selectedProduction: String?=null
|
||||
private var selectedProduction: String?=null
|
||||
|
||||
private fun getProductionButton(production: String, buttonText: String,
|
||||
description: String?, rightSideButtonText: String): TextButton {
|
||||
val productionTextButton = TextButton(buttonText, CameraStageBaseScreen.skin)
|
||||
productionTextButton.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
productionTextButton.addClickListener {
|
||||
selectedProduction = production
|
||||
pick(rightSideButtonText)
|
||||
descriptionLabel.setText(description)
|
||||
}
|
||||
})
|
||||
return productionTextButton
|
||||
}
|
||||
|
||||
|
@ -29,22 +26,18 @@ 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.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
closeButton.addClickListener {
|
||||
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
||||
dispose()
|
||||
}
|
||||
})
|
||||
|
||||
rightSideButton.setText("Pick building")
|
||||
rightSideButton.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
rightSideButton.addClickListener {
|
||||
city.cityConstructions.currentConstruction = selectedProduction!!
|
||||
city.cityStats.update() // Because maybe we set/removed the science or gold production options.
|
||||
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
||||
dispose()
|
||||
}
|
||||
})
|
||||
|
||||
val cityConstructions = city.cityConstructions
|
||||
val regularBuildings = VerticalGroup().space(10f)
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
package com.unciv.ui.pickerscreens
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SplitPane
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
|
||||
open class PickerScreen : CameraStageBaseScreen() {
|
||||
|
@ -25,12 +20,10 @@ open class PickerScreen : CameraStageBaseScreen() {
|
|||
val buttonTable = Table()
|
||||
|
||||
closeButton = TextButton("Close", CameraStageBaseScreen.skin)
|
||||
closeButton.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
closeButton.addClickListener {
|
||||
game.setWorldScreen()
|
||||
dispose()
|
||||
}
|
||||
})
|
||||
buttonTable.add(closeButton).width(stage.width / 4)
|
||||
|
||||
descriptionLabel = Label("", CameraStageBaseScreen.skin)
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package com.unciv.ui.tilegroups
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Container
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.ui.cityscreen.CityScreen
|
||||
import com.unciv.ui.UnCivGame
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
|
@ -53,11 +50,8 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||
cityButton!!.actor.label.setFontScale(buttonScale)
|
||||
|
||||
val game = worldScreen.game
|
||||
cityButton!!.actor.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
game.screen = CityScreen(city!!)
|
||||
cityButton!!.actor.addClickListener { game.screen = CityScreen(city!!)
|
||||
}
|
||||
})
|
||||
|
||||
addActor(cityButton!!)
|
||||
zIndex = parent.children.size // so this tile is rendered over neighboring tiles
|
||||
|
@ -70,7 +64,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||
|
||||
cityButton!!.setPosition((width - cityButton!!.width) / 2,
|
||||
height * 0.9f)
|
||||
cityButton!!.zIndex = cityButton!!.parent.children.size // so city button is rendere over oeverything else in this tile
|
||||
cityButton!!.zIndex = cityButton!!.parent.children.size // so city button is rendered over everything else in this tile
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,17 +6,16 @@ import com.badlogic.gdx.graphics.Color
|
|||
import com.badlogic.gdx.graphics.GL20
|
||||
import com.badlogic.gdx.graphics.g2d.Batch
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.badlogic.gdx.utils.viewport.ExtendViewport
|
||||
import com.unciv.models.linq.Linq
|
||||
import com.unciv.ui.UnCivGame
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
|
||||
open class CameraStageBaseScreen : Screen {
|
||||
|
||||
|
@ -75,15 +74,13 @@ open class CameraStageBaseScreen : Screen {
|
|||
tutorialTexts.removeAt(0)
|
||||
tutorialTable.add(label).pad(10f).row()
|
||||
val button = TextButton("Close", skin)
|
||||
button.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
button.addClickListener {
|
||||
tutorialTable.remove()
|
||||
if (!tutorialTexts.isEmpty())
|
||||
displayTutorial()
|
||||
else
|
||||
isTutorialShowing = false
|
||||
}
|
||||
})
|
||||
tutorialTable.add(button).pad(10f)
|
||||
tutorialTable.pack()
|
||||
tutorialTable.setPosition(stage.width / 2 - tutorialTable.width / 2,
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package com.unciv.ui.worldscreen
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
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.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.TileInfo
|
||||
|
@ -57,28 +55,29 @@ class TileInfoTable(private val worldScreen: WorldScreen, internal val civInfo:
|
|||
moveUnitButton.color = Color.GRAY
|
||||
moveUnitButton.touchable = Touchable.disabled
|
||||
}
|
||||
moveUnitButton.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
if (worldScreen.tileMapHolder.unitTile != null) {
|
||||
worldScreen.tileMapHolder.unitTile = null
|
||||
worldScreen.update()
|
||||
return
|
||||
}
|
||||
worldScreen.tileMapHolder.unitTile = selectedTile
|
||||
|
||||
// Set all tiles transparent except those in unit range
|
||||
for (TG in worldScreen.tileGroups.linqValues()) TG.setColor(0f, 0f, 0f, 0.3f)
|
||||
for (tile in civInfo.gameInfo.tileMap.getDistanceToTilesWithinTurn(
|
||||
worldScreen.tileMapHolder.unitTile!!.position,
|
||||
worldScreen.tileMapHolder.unitTile!!.unit!!.currentMovement,
|
||||
civInfo.tech.isResearched("Machinery")
|
||||
).keys) {
|
||||
worldScreen.tileGroups[tile.position.toString()]!!.color = Color.WHITE
|
||||
}
|
||||
|
||||
moveUnitButton.addClickListener {
|
||||
if (worldScreen.tileMapHolder.unitTile != null) {
|
||||
worldScreen.tileMapHolder.unitTile = null
|
||||
worldScreen.update()
|
||||
return@addClickListener
|
||||
}
|
||||
})
|
||||
worldScreen.tileMapHolder.unitTile = selectedTile
|
||||
|
||||
// Set all tiles transparent except those in unit range
|
||||
for (TG in worldScreen.tileGroups.linqValues()) TG.setColor(0f, 0f, 0f, 0.3f)
|
||||
|
||||
val distanceToTiles = civInfo.gameInfo.tileMap.getDistanceToTilesWithinTurn(
|
||||
worldScreen.tileMapHolder.unitTile!!.position,
|
||||
worldScreen.tileMapHolder.unitTile!!.unit!!.currentMovement,
|
||||
civInfo.tech.isResearched("Machinery"))
|
||||
|
||||
for (tile in distanceToTiles.keys) {
|
||||
worldScreen.tileGroups[tile.position.toString()]!!.color = Color.WHITE
|
||||
}
|
||||
|
||||
worldScreen.update()
|
||||
}
|
||||
|
||||
add(moveUnitButton).colspan(2)
|
||||
.size(moveUnitButton.width * worldScreen.buttonScale, moveUnitButton.height * worldScreen.buttonScale)
|
||||
|
||||
|
|
Loading…
Reference in a new issue