From abe3d76df72d5535254c15103323cf9132487ae2 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 3 Mar 2018 21:54:02 +0200 Subject: [PATCH] Changed click listeners to lambdas --- travis.yml => .travis.yml | 0 core/src/com/unciv/ui/CivilopediaScreen.kt | 6 +-- .../pickerscreens/ConstructionPickerScreen.kt | 17 +++----- .../unciv/ui/pickerscreens/PickerScreen.kt | 13 ++---- .../com/unciv/ui/tilegroups/WorldTileGroup.kt | 12 ++---- .../unciv/ui/utils/CameraStageBaseScreen.kt | 7 +-- .../com/unciv/ui/worldscreen/TileInfoTable.kt | 43 +++++++++---------- 7 files changed, 35 insertions(+), 63 deletions(-) rename travis.yml => .travis.yml (100%) diff --git a/travis.yml b/.travis.yml similarity index 100% rename from travis.yml rename to .travis.yml diff --git a/core/src/com/unciv/ui/CivilopediaScreen.kt b/core/src/com/unciv/ui/CivilopediaScreen.kt index 34e87f44..e52ddbd3 100644 --- a/core/src/com/unciv/ui/CivilopediaScreen.kt +++ b/core/src/com/unciv/ui/CivilopediaScreen.kt @@ -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>() diff --git a/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt index 72cbdaa9..bd4ae62a 100644 --- a/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt @@ -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) diff --git a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt index f07e7361..fa41a9d6 100644 --- a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt @@ -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) diff --git a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt index 7082acfc..794bc2e1 100644 --- a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt @@ -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 } } diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 74a946cb..84a1fb9d 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -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, diff --git a/core/src/com/unciv/ui/worldscreen/TileInfoTable.kt b/core/src/com/unciv/ui/worldscreen/TileInfoTable.kt index 08b1b81f..d1763d02 100644 --- a/core/src/com/unciv/ui/worldscreen/TileInfoTable.kt +++ b/core/src/com/unciv/ui/worldscreen/TileInfoTable.kt @@ -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)