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.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.*
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.List
|
import com.badlogic.gdx.scenes.scene2d.ui.List
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
|
||||||
import com.badlogic.gdx.utils.Array
|
import com.badlogic.gdx.utils.Array
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
import com.unciv.models.gamebasics.ICivilopedia
|
import com.unciv.models.gamebasics.ICivilopedia
|
||||||
|
@ -29,12 +27,10 @@ class CivilopediaScreen : CameraStageBaseScreen() {
|
||||||
label.setWrap(true)
|
label.setWrap(true)
|
||||||
|
|
||||||
val goToGameButton = TextButton("Return \r\nto game", CameraStageBaseScreen.skin)
|
val goToGameButton = TextButton("Return \r\nto game", CameraStageBaseScreen.skin)
|
||||||
goToGameButton.addListener(object : ClickListener() {
|
goToGameButton.addClickListener {
|
||||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
|
||||||
game.setWorldScreen()
|
game.setWorldScreen()
|
||||||
dispose()
|
dispose()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
buttonTable.add(goToGameButton)
|
buttonTable.add(goToGameButton)
|
||||||
|
|
||||||
val map = LinkedHashMap<String, Collection<ICivilopedia>>()
|
val map = LinkedHashMap<String, Collection<ICivilopedia>>()
|
||||||
|
|
|
@ -1,27 +1,24 @@
|
||||||
package com.unciv.ui.pickerscreens
|
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.TextButton
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
|
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.logic.city.CityInfo
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
import com.unciv.ui.cityscreen.CityScreen
|
import com.unciv.ui.cityscreen.CityScreen
|
||||||
|
import com.unciv.ui.cityscreen.addClickListener
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
|
|
||||||
class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
||||||
var selectedProduction: String?=null
|
private var selectedProduction: String?=null
|
||||||
|
|
||||||
private fun getProductionButton(production: String, buttonText: String,
|
private fun getProductionButton(production: String, buttonText: String,
|
||||||
description: String?, rightSideButtonText: String): TextButton {
|
description: String?, rightSideButtonText: String): TextButton {
|
||||||
val productionTextButton = TextButton(buttonText, CameraStageBaseScreen.skin)
|
val productionTextButton = TextButton(buttonText, CameraStageBaseScreen.skin)
|
||||||
productionTextButton.addListener(object : ClickListener() {
|
productionTextButton.addClickListener {
|
||||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
|
||||||
selectedProduction = production
|
selectedProduction = production
|
||||||
pick(rightSideButtonText)
|
pick(rightSideButtonText)
|
||||||
descriptionLabel.setText(description)
|
descriptionLabel.setText(description)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
return productionTextButton
|
return productionTextButton
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,22 +26,18 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
||||||
val civInfo = game.gameInfo.getPlayerCivilization()
|
val civInfo = game.gameInfo.getPlayerCivilization()
|
||||||
|
|
||||||
closeButton.clearListeners() // Don't go back to the world screen, unlike the other picker screens!
|
closeButton.clearListeners() // Don't go back to the world screen, unlike the other picker screens!
|
||||||
closeButton.addListener(object : ClickListener() {
|
closeButton.addClickListener {
|
||||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
|
||||||
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
||||||
dispose()
|
dispose()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
rightSideButton.setText("Pick building")
|
rightSideButton.setText("Pick building")
|
||||||
rightSideButton.addListener(object : ClickListener() {
|
rightSideButton.addClickListener {
|
||||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
|
||||||
city.cityConstructions.currentConstruction = selectedProduction!!
|
city.cityConstructions.currentConstruction = selectedProduction!!
|
||||||
city.cityStats.update() // Because maybe we set/removed the science or gold production options.
|
city.cityStats.update() // Because maybe we set/removed the science or gold production options.
|
||||||
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
||||||
dispose()
|
dispose()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
val cityConstructions = city.cityConstructions
|
val cityConstructions = city.cityConstructions
|
||||||
val regularBuildings = VerticalGroup().space(10f)
|
val regularBuildings = VerticalGroup().space(10f)
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
package com.unciv.ui.pickerscreens
|
package com.unciv.ui.pickerscreens
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||||
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.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
|
import com.unciv.ui.cityscreen.addClickListener
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
|
|
||||||
open class PickerScreen : CameraStageBaseScreen() {
|
open class PickerScreen : CameraStageBaseScreen() {
|
||||||
|
@ -25,12 +20,10 @@ open class PickerScreen : CameraStageBaseScreen() {
|
||||||
val buttonTable = Table()
|
val buttonTable = Table()
|
||||||
|
|
||||||
closeButton = TextButton("Close", CameraStageBaseScreen.skin)
|
closeButton = TextButton("Close", CameraStageBaseScreen.skin)
|
||||||
closeButton.addListener(object : ClickListener() {
|
closeButton.addClickListener {
|
||||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
|
||||||
game.setWorldScreen()
|
game.setWorldScreen()
|
||||||
dispose()
|
dispose()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
buttonTable.add(closeButton).width(stage.width / 4)
|
buttonTable.add(closeButton).width(stage.width / 4)
|
||||||
|
|
||||||
descriptionLabel = Label("", CameraStageBaseScreen.skin)
|
descriptionLabel = Label("", CameraStageBaseScreen.skin)
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package com.unciv.ui.tilegroups
|
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.Container
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
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.logic.map.TileInfo
|
||||||
import com.unciv.ui.cityscreen.CityScreen
|
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.CameraStageBaseScreen
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
|
@ -53,11 +50,8 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
||||||
cityButton!!.actor.label.setFontScale(buttonScale)
|
cityButton!!.actor.label.setFontScale(buttonScale)
|
||||||
|
|
||||||
val game = worldScreen.game
|
val game = worldScreen.game
|
||||||
cityButton!!.actor.addListener(object : ClickListener() {
|
cityButton!!.actor.addClickListener { game.screen = CityScreen(city!!)
|
||||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
|
||||||
game.screen = CityScreen(city!!)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
addActor(cityButton!!)
|
addActor(cityButton!!)
|
||||||
zIndex = parent.children.size // so this tile is rendered over neighboring tiles
|
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,
|
cityButton!!.setPosition((width - cityButton!!.width) / 2,
|
||||||
height * 0.9f)
|
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.GL20
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch
|
import com.badlogic.gdx.graphics.g2d.Batch
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
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.Stage
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
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.Align
|
||||||
import com.badlogic.gdx.utils.viewport.ExtendViewport
|
import com.badlogic.gdx.utils.viewport.ExtendViewport
|
||||||
import com.unciv.models.linq.Linq
|
import com.unciv.models.linq.Linq
|
||||||
import com.unciv.ui.UnCivGame
|
import com.unciv.ui.UnCivGame
|
||||||
|
import com.unciv.ui.cityscreen.addClickListener
|
||||||
|
|
||||||
open class CameraStageBaseScreen : Screen {
|
open class CameraStageBaseScreen : Screen {
|
||||||
|
|
||||||
|
@ -75,15 +74,13 @@ open class CameraStageBaseScreen : Screen {
|
||||||
tutorialTexts.removeAt(0)
|
tutorialTexts.removeAt(0)
|
||||||
tutorialTable.add(label).pad(10f).row()
|
tutorialTable.add(label).pad(10f).row()
|
||||||
val button = TextButton("Close", skin)
|
val button = TextButton("Close", skin)
|
||||||
button.addListener(object : ClickListener() {
|
button.addClickListener {
|
||||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
|
||||||
tutorialTable.remove()
|
tutorialTable.remove()
|
||||||
if (!tutorialTexts.isEmpty())
|
if (!tutorialTexts.isEmpty())
|
||||||
displayTutorial()
|
displayTutorial()
|
||||||
else
|
else
|
||||||
isTutorialShowing = false
|
isTutorialShowing = false
|
||||||
}
|
}
|
||||||
})
|
|
||||||
tutorialTable.add(button).pad(10f)
|
tutorialTable.add(button).pad(10f)
|
||||||
tutorialTable.pack()
|
tutorialTable.pack()
|
||||||
tutorialTable.setPosition(stage.width / 2 - tutorialTable.width / 2,
|
tutorialTable.setPosition(stage.width / 2 - tutorialTable.width / 2,
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package com.unciv.ui.worldscreen
|
package com.unciv.ui.worldscreen
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
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.Align
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
|
@ -57,28 +55,29 @@ class TileInfoTable(private val worldScreen: WorldScreen, internal val civInfo:
|
||||||
moveUnitButton.color = Color.GRAY
|
moveUnitButton.color = Color.GRAY
|
||||||
moveUnitButton.touchable = Touchable.disabled
|
moveUnitButton.touchable = Touchable.disabled
|
||||||
}
|
}
|
||||||
moveUnitButton.addListener(object : ClickListener() {
|
moveUnitButton.addClickListener {
|
||||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
if (worldScreen.tileMapHolder.unitTile != null) {
|
||||||
if (worldScreen.tileMapHolder.unitTile != null) {
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
worldScreen.update()
|
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)
|
add(moveUnitButton).colspan(2)
|
||||||
.size(moveUnitButton.width * worldScreen.buttonScale, moveUnitButton.height * worldScreen.buttonScale)
|
.size(moveUnitButton.width * worldScreen.buttonScale, moveUnitButton.height * worldScreen.buttonScale)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue