mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 02:42:16 -04:00
parent
0b507422f0
commit
461028deed
@ -12,6 +12,7 @@ import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
import com.unciv.logic.files.UncivFiles
|
||||
import com.unciv.logic.UncivShowableException
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.logic.multiplayer.OnlineMultiplayer
|
||||
import com.unciv.models.metadata.GameSettings
|
||||
@ -36,7 +37,9 @@ import com.unciv.ui.screens.mainmenuscreen.MainMenuScreen
|
||||
import com.unciv.ui.screens.basescreen.BaseScreen
|
||||
import com.unciv.ui.components.extensions.center
|
||||
import com.unciv.ui.screens.worldscreen.PlayerReadyScreen
|
||||
import com.unciv.ui.screens.worldscreen.WorldMapHolder
|
||||
import com.unciv.ui.screens.worldscreen.WorldScreen
|
||||
import com.unciv.ui.screens.worldscreen.unit.UnitTable
|
||||
import com.unciv.utils.Log
|
||||
import com.unciv.utils.concurrency.Concurrency
|
||||
import com.unciv.utils.concurrency.launchOnGLThread
|
||||
@ -48,6 +51,66 @@ import java.io.PrintWriter
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayDeque
|
||||
|
||||
object GUI {
|
||||
|
||||
fun isDebugMapVisible(): Boolean {
|
||||
return UncivGame.Current.viewEntireMapForDebug
|
||||
}
|
||||
|
||||
fun setUpdateWorldOnNextRender() {
|
||||
UncivGame.Current.worldScreen?.shouldUpdate = true
|
||||
}
|
||||
|
||||
fun pushScreen(screen: BaseScreen) {
|
||||
UncivGame.Current.pushScreen(screen)
|
||||
}
|
||||
|
||||
fun resetToWorldScreen() {
|
||||
UncivGame.Current.resetToWorldScreen()
|
||||
}
|
||||
|
||||
fun getSettings(): GameSettings {
|
||||
return UncivGame.Current.settings
|
||||
}
|
||||
|
||||
fun isWorldLoaded(): Boolean {
|
||||
return UncivGame.Current.worldScreen != null
|
||||
}
|
||||
|
||||
fun isMyTurn(): Boolean {
|
||||
return UncivGame.Current.worldScreen!!.isPlayersTurn
|
||||
}
|
||||
|
||||
fun isAllowedChangeState(): Boolean {
|
||||
return UncivGame.Current.worldScreen!!.canChangeState
|
||||
}
|
||||
|
||||
fun getWorldScreen(): WorldScreen {
|
||||
return UncivGame.Current.worldScreen!!
|
||||
}
|
||||
|
||||
fun getWorldScreenIfActive(): WorldScreen? {
|
||||
return UncivGame.Current.getWorldScreenIfActive()
|
||||
}
|
||||
|
||||
fun getMap(): WorldMapHolder {
|
||||
return UncivGame.Current.worldScreen!!.mapHolder
|
||||
}
|
||||
|
||||
fun getUnitTable(): UnitTable {
|
||||
return UncivGame.Current.worldScreen!!.bottomUnitTable
|
||||
}
|
||||
|
||||
fun getViewingPlayer(): Civilization {
|
||||
return UncivGame.Current.worldScreen!!.viewingCiv
|
||||
}
|
||||
|
||||
fun getSelectedPlayer(): Civilization {
|
||||
return UncivGame.Current.worldScreen!!.selectedCiv
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class UncivGame(parameters: UncivGameParameters) : Game() {
|
||||
constructor() : this(UncivGameParameters())
|
||||
|
||||
@ -61,7 +124,6 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
|
||||
|
||||
var deepLinkedMultiplayerGame: String? = null
|
||||
var gameInfo: GameInfo? = null
|
||||
private set
|
||||
lateinit var settings: GameSettings
|
||||
lateinit var musicController: MusicController
|
||||
lateinit var onlineMultiplayer: OnlineMultiplayer
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.logic.automation.ai
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
@ -32,7 +33,7 @@ class TacticalAI : IsPartOfGameInfoSerialization {
|
||||
Log.debug("MYTAG Zone $zoneId City: ${zone?.city} Area: ${zone?.area} Area size: ${
|
||||
tile.tileMap.continentSizes[tile.getContinent()]} Zone size: ${zone?.tileCount}")
|
||||
|
||||
val mapHolder = UncivGame.Current.worldScreen!!.mapHolder
|
||||
val mapHolder = GUI.getMap()
|
||||
|
||||
for (otherTile in mapHolder.tileMap.values.asSequence()) {
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.logic.city
|
||||
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
import com.unciv.logic.automation.Automation
|
||||
@ -673,8 +674,7 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
||||
city.cityStats.update()
|
||||
city.civ.cache.updateCivResources()
|
||||
// If bought the worldscreen will not have been marked to update, and the new improvement won't show until later...
|
||||
if (UncivGame.isCurrentInitialized() && UncivGame.Current.worldScreen != null)
|
||||
UncivGame.Current.worldScreen!!.shouldUpdate = true
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
}
|
||||
|
||||
/** Support for [UniqueType.CreatesOneImprovement]:
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.logic.city.managers
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.battle.Battle
|
||||
import com.unciv.logic.city.City
|
||||
@ -158,10 +159,7 @@ class CityInfoConquestFunctions(val city: City){
|
||||
city.isPuppet = false
|
||||
city.cityConstructions.inProgressConstructions.clear() // undo all progress of the previous civ on units etc.
|
||||
city.cityStats.update()
|
||||
val worldScreen = UncivGame.Current.worldScreen
|
||||
if (!UncivGame.Current.consoleMode && worldScreen != null) {
|
||||
worldScreen.shouldUpdate = true
|
||||
}
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
}
|
||||
|
||||
private fun diplomaticRepercussionsForConqueringCity(oldCiv: Civilization, conqueringCiv: Civilization) {
|
||||
|
@ -2,6 +2,7 @@ package com.unciv.logic.civilization.managers
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
@ -835,16 +836,14 @@ class AssignedQuest(val questName: String = "",
|
||||
}
|
||||
|
||||
fun onClickAction() {
|
||||
val game = UncivGame.Current
|
||||
|
||||
when (questName) {
|
||||
QuestName.ClearBarbarianCamp.value -> {
|
||||
game.resetToWorldScreen()
|
||||
game.worldScreen!!.mapHolder.setCenterPosition(Vector2(data1.toFloat(), data2.toFloat()), selectUnit = false)
|
||||
GUI.resetToWorldScreen()
|
||||
GUI.getMap().setCenterPosition(Vector2(data1.toFloat(), data2.toFloat()), selectUnit = false)
|
||||
}
|
||||
QuestName.Route.value -> {
|
||||
game.resetToWorldScreen()
|
||||
game.worldScreen!!.mapHolder.setCenterPosition(gameInfo.getCivilization(assigner).getCapital()!!.location, selectUnit = false)
|
||||
GUI.resetToWorldScreen()
|
||||
GUI.getMap().setCenterPosition(gameInfo.getCivilization(assigner).getCapital()!!.location, selectUnit = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.models.ruleset.tech
|
||||
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.models.ruleset.Building
|
||||
@ -50,7 +51,7 @@ class Technology: RulesetObject() {
|
||||
}
|
||||
}
|
||||
|
||||
val viewingCiv = UncivGame.Current.worldScreen!!.viewingCiv
|
||||
val viewingCiv = GUI.getViewingPlayer()
|
||||
val enabledUnits = getEnabledUnits(ruleset, viewingCiv)
|
||||
if (enabledUnits.any()) {
|
||||
lineList += "{Units enabled}: "
|
||||
@ -224,7 +225,7 @@ class Technology: RulesetObject() {
|
||||
}
|
||||
}
|
||||
|
||||
val viewingCiv = UncivGame.Current.worldScreen?.viewingCiv
|
||||
val viewingCiv = GUI.getViewingPlayer()
|
||||
val enabledUnits = getEnabledUnits(ruleset, viewingCiv)
|
||||
if (enabledUnits.any()) {
|
||||
lineList += FormattedLine()
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.ui.components.extensions.addToCenter
|
||||
@ -206,14 +207,14 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
||||
|
||||
// Unit base icon is faded out only if out of moves
|
||||
// Foreign unit icons are never faded!
|
||||
val shouldBeFaded = (unit.owner == UncivGame.Current.worldScreen?.viewingCiv?.civName
|
||||
&& unit.currentMovement == 0f && UncivGame.Current.settings.unitIconOpacity == 1f)
|
||||
val shouldBeFaded = (unit.owner == GUI.getSelectedPlayer().civName
|
||||
&& unit.currentMovement == 0f && GUI.getSettings().unitIconOpacity == 1f)
|
||||
val alpha = if (shouldBeFaded) opacity * 0.5f else opacity
|
||||
flagIcon.color.a = alpha
|
||||
flagBg.color.a = alpha
|
||||
flagSelection.color.a = opacity
|
||||
|
||||
if (UncivGame.Current.settings.continuousRendering) {
|
||||
if (GUI.getSettings().continuousRendering) {
|
||||
flagSelection.color.a = opacity
|
||||
flagSelection.addAction(
|
||||
Actions.repeat(
|
||||
|
@ -9,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.battle.CityCombatant
|
||||
import com.unciv.logic.city.City
|
||||
@ -112,7 +113,7 @@ private class DefenceTable(city: City) : BorderedTable(
|
||||
|
||||
init {
|
||||
|
||||
val viewingCiv = UncivGame.Current.worldScreen!!.viewingCiv
|
||||
val viewingCiv = GUI.getViewingPlayer()
|
||||
|
||||
borderSize = 4f
|
||||
bgColor = Color.BLACK
|
||||
@ -160,18 +161,18 @@ class AirUnitTable(city: City, numberOfUnits: Int, size: Float=14f) : BorderedTa
|
||||
|
||||
}
|
||||
|
||||
private class StatusTable(worldScreen: WorldScreen, city: City, iconSize: Float = 18f) : Table() {
|
||||
private class StatusTable(city: City, iconSize: Float = 18f) : Table() {
|
||||
|
||||
init {
|
||||
|
||||
val padBetween = 2f
|
||||
val viewingCiv = UncivGame.Current.worldScreen!!.viewingCiv
|
||||
val viewingCiv = GUI.getViewingPlayer()
|
||||
|
||||
if (city.civ == viewingCiv) {
|
||||
if (city.isBlockaded()) {
|
||||
val connectionImage = ImageGetter.getImage("OtherIcons/Blockade")
|
||||
add(connectionImage).size(iconSize)
|
||||
worldScreen.displayTutorial(TutorialTrigger.CityBlockade)
|
||||
GUI.getWorldScreen().displayTutorial(TutorialTrigger.CityBlockade)
|
||||
} else if (!city.isCapital() && city.isConnectedToCapital()) {
|
||||
val connectionImage = ImageGetter.getStatIcon("CityConnection")
|
||||
add(connectionImage).size(iconSize)
|
||||
@ -210,7 +211,7 @@ private class CityTable(city: City, forPopup: Boolean = false) : BorderedTable(
|
||||
isTransform = false
|
||||
touchable = Touchable.enabled
|
||||
|
||||
val viewingCiv = UncivGame.Current.worldScreen!!.viewingCiv
|
||||
val viewingCiv = GUI.getViewingPlayer()
|
||||
|
||||
bgBorderColor = when {
|
||||
city.civ == viewingCiv -> colorFromRGB(233, 233, 172)
|
||||
@ -392,9 +393,6 @@ private class CityTable(city: City, forPopup: Boolean = false) : BorderedTable(
|
||||
|
||||
class CityButton(val city: City, private val tileGroup: TileGroup): Table(BaseScreen.skin){
|
||||
|
||||
val worldScreen = UncivGame.Current.worldScreen!!
|
||||
val uncivGame = worldScreen.game
|
||||
|
||||
init {
|
||||
touchable = Touchable.disabled
|
||||
}
|
||||
@ -431,13 +429,13 @@ class CityButton(val city: City, private val tileGroup: TileGroup): Table(BaseSc
|
||||
add(cityTable).row()
|
||||
|
||||
// If city state - add influence bar
|
||||
if (city.civ.isCityState() && city.civ.knows(worldScreen.viewingCiv)) {
|
||||
val diplomacyManager = city.civ.getDiplomacyManager(worldScreen.viewingCiv)
|
||||
if (city.civ.isCityState() && city.civ.knows(GUI.getViewingPlayer())) {
|
||||
val diplomacyManager = city.civ.getDiplomacyManager(GUI.getViewingPlayer())
|
||||
add(InfluenceTable(diplomacyManager.getInfluence(), diplomacyManager.relationshipLevel())).padTop(1f).row()
|
||||
}
|
||||
|
||||
// Add statuses: connection, resistance, puppet, raze, WLTKD
|
||||
add(StatusTable(worldScreen, city)).padTop(3f)
|
||||
add(StatusTable(city)).padTop(3f)
|
||||
|
||||
pack()
|
||||
|
||||
@ -481,13 +479,13 @@ class CityButton(val city: City, private val tileGroup: TileGroup): Table(BaseSc
|
||||
(tile.civilianUnit != null) && direction.epsilonEquals(0f, 1f) ->
|
||||
insertHiddenUnitMarker(HiddenUnitMarkerPosition.Left)
|
||||
// detect military under the city
|
||||
(tile.militaryUnit != null && !tile.hasEnemyInvisibleUnit(worldScreen.viewingCiv)) && direction.epsilonEquals(1f, 1f) ->
|
||||
(tile.militaryUnit != null && !tile.hasEnemyInvisibleUnit(GUI.getViewingPlayer())) && direction.epsilonEquals(1f, 1f) ->
|
||||
insertHiddenUnitMarker(HiddenUnitMarkerPosition.Center)
|
||||
// detect civilian right-below the city
|
||||
(tile.civilianUnit != null) && direction.epsilonEquals(1f, 0f) ->
|
||||
insertHiddenUnitMarker(HiddenUnitMarkerPosition.Right)
|
||||
}
|
||||
} else if (tile.militaryUnit != null && !tile.hasEnemyInvisibleUnit(worldScreen.viewingCiv)) {
|
||||
} else if (tile.militaryUnit != null && !tile.hasEnemyInvisibleUnit(GUI.getViewingPlayer())) {
|
||||
when {
|
||||
// detect military left from the city
|
||||
direction.epsilonEquals(0f, 1f) ->
|
||||
@ -518,11 +516,11 @@ class CityButton(val city: City, private val tileGroup: TileGroup): Table(BaseSc
|
||||
listOfHiddenUnitMarkers.add(indicator)
|
||||
}
|
||||
|
||||
private fun belongsToViewingCiv() = city.civ == worldScreen.viewingCiv
|
||||
private fun belongsToViewingCiv() = city.civ == GUI.getViewingPlayer()
|
||||
|
||||
private fun setButtonActions() {
|
||||
|
||||
val unitTable = worldScreen.bottomUnitTable
|
||||
val unitTable = GUI.getUnitTable()
|
||||
|
||||
// So you can click anywhere on the button to go to the city
|
||||
touchable = Touchable.childrenOnly
|
||||
@ -531,12 +529,12 @@ class CityButton(val city: City, private val tileGroup: TileGroup): Table(BaseSc
|
||||
// clicking swings the button a little down to allow selection of units there.
|
||||
// this also allows to target selected units to move to the city tile from elsewhere.
|
||||
if (isButtonMoved) {
|
||||
val viewingCiv = worldScreen.viewingCiv
|
||||
val viewingCiv = GUI.getViewingPlayer()
|
||||
// second tap on the button will go to the city screen
|
||||
// if this city belongs to you and you are not iterating though the air units
|
||||
if (uncivGame.viewEntireMapForDebug || viewingCiv.isSpectator()
|
||||
if (GUI.isDebugMapVisible() || viewingCiv.isSpectator()
|
||||
|| (belongsToViewingCiv() && !tileGroup.tile.airUnits.contains(unitTable.selectedUnit))) {
|
||||
uncivGame.pushScreen(CityScreen(city))
|
||||
GUI.pushScreen(CityScreen(city))
|
||||
} else if (viewingCiv.knows(city.civ)) {
|
||||
foreignCityInfoPopup()
|
||||
}
|
||||
@ -584,13 +582,13 @@ class CityButton(val city: City, private val tileGroup: TileGroup): Table(BaseSc
|
||||
private fun foreignCityInfoPopup() {
|
||||
fun openDiplomacy() {
|
||||
// If city doesn't belong to you, go directly to its owner's diplomacy screen.
|
||||
worldScreen.game.pushScreen(DiplomacyScreen(worldScreen.viewingCiv, city.civ))
|
||||
GUI.pushScreen(DiplomacyScreen(GUI.getViewingPlayer(), city.civ))
|
||||
}
|
||||
|
||||
// If there's nothing to display cuz no Religion - skip popup
|
||||
if (!city.civ.gameInfo.isReligionEnabled()) return openDiplomacy()
|
||||
|
||||
val popup = Popup(worldScreen).apply {
|
||||
val popup = Popup(GUI.getWorldScreen()).apply {
|
||||
name = "ForeignCityInfoPopup"
|
||||
add(CityTable(city, true)).fillX().padBottom(5f).colspan(3).row()
|
||||
add(CityReligionInfoTable(city.religion, true)).colspan(3).row()
|
||||
|
@ -11,7 +11,7 @@ import com.unciv.ui.components.extensions.darken
|
||||
import com.unciv.ui.screens.worldscreen.WorldScreen
|
||||
|
||||
|
||||
class WorldTileGroup(internal val worldScreen: WorldScreen, tile: Tile, tileSetStrings: TileSetStrings)
|
||||
class WorldTileGroup(tile: Tile, tileSetStrings: TileSetStrings)
|
||||
: TileGroup(tile,tileSetStrings) {
|
||||
|
||||
init {
|
||||
@ -50,5 +50,5 @@ class WorldTileGroup(internal val worldScreen: WorldScreen, tile: Tile, tileSetS
|
||||
}
|
||||
}
|
||||
|
||||
override fun clone(): WorldTileGroup = WorldTileGroup(worldScreen, tile , tileSetStrings)
|
||||
override fun clone(): WorldTileGroup = WorldTileGroup(tile , tileSetStrings)
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Cell
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.models.metadata.GameSettings
|
||||
import com.unciv.models.metadata.ScreenSize
|
||||
@ -169,7 +170,8 @@ private fun addMaxZoomSlider(table: Table, settings: GameSettings) {
|
||||
) {
|
||||
settings.maxWorldZoomOut = it
|
||||
settings.save()
|
||||
UncivGame.Current.worldScreen?.mapHolder?.reloadMaxZoom()
|
||||
if (GUI.isWorldLoaded())
|
||||
GUI.getMap().reloadMaxZoom()
|
||||
}
|
||||
table.add(maxZoomSlider).pad(5f).row()
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.ui.popups.options
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.files.UncivFiles
|
||||
import com.unciv.logic.files.MapSaver
|
||||
@ -19,8 +20,7 @@ fun debugTab() = Table(BaseScreen.skin).apply {
|
||||
defaults().pad(5f)
|
||||
val game = UncivGame.Current
|
||||
|
||||
val worldScreen = game.worldScreen
|
||||
if (worldScreen != null) {
|
||||
if (GUI.isWorldLoaded()) {
|
||||
val simulateButton = "Simulate until turn:".toTextButton()
|
||||
val simulateTextField = UncivTextField.create("Turn", game.simulateUntilTurnForDebug.toString())
|
||||
val invalidInputLabel = "This is not a valid integer!".toLabel().also { it.isVisible = false }
|
||||
@ -32,7 +32,7 @@ fun debugTab() = Table(BaseScreen.skin).apply {
|
||||
}
|
||||
game.simulateUntilTurnForDebug = simulateUntilTurns
|
||||
invalidInputLabel.isVisible = false
|
||||
worldScreen.nextTurn()
|
||||
GUI.getWorldScreen().nextTurn()
|
||||
}
|
||||
add(simulateButton)
|
||||
add(simulateTextField).row()
|
||||
@ -89,7 +89,7 @@ fun debugTab() = Table(BaseScreen.skin).apply {
|
||||
}
|
||||
}
|
||||
curGameInfo.getCurrentPlayerCivilization().cache.updateSightAndResources()
|
||||
if (worldScreen != null) worldScreen.shouldUpdate = true
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
}
|
||||
add(unlockTechsButton).colspan(2).row()
|
||||
|
||||
@ -107,7 +107,7 @@ fun debugTab() = Table(BaseScreen.skin).apply {
|
||||
tile.changeImprovement(resource.getImprovements().first())
|
||||
}
|
||||
curGameInfo.getCurrentPlayerCivilization().cache.updateSightAndResources()
|
||||
if (worldScreen != null) worldScreen.shouldUpdate = true
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
}
|
||||
add(giveResourcesButton).colspan(2).row()
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.models.metadata.GameSettings
|
||||
import com.unciv.models.metadata.ScreenSize
|
||||
@ -39,8 +40,9 @@ fun displayTab(
|
||||
if (Gdx.app.type == Application.ApplicationType.Desktop) {
|
||||
addFullscreenSelectBox(this, settings, optionsPopup.selectBoxMinWidth)
|
||||
optionsPopup.addCheckbox(this, "Map mouse auto-scroll", settings.mapAutoScroll, true) {
|
||||
UncivGame.Current.worldScreen?.mapHolder?.isAutoScrollEnabled = it
|
||||
settings.mapAutoScroll = it
|
||||
if (GUI.isWorldLoaded())
|
||||
GUI.getMap().isAutoScrollEnabled = settings.mapAutoScroll
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,9 +114,9 @@ private fun addMinimapSizeSlider(table: Table, settings: GameSettings, selectBox
|
||||
settings.minimapSize = size
|
||||
}
|
||||
settings.save()
|
||||
val worldScreen = UncivGame.Current.getWorldScreenIfActive()
|
||||
val worldScreen = GUI.getWorldScreenIfActive()
|
||||
if (worldScreen != null)
|
||||
worldScreen.shouldUpdate = true
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
}
|
||||
table.add(minimapSlider).minWidth(selectBoxMinWidth).pad(10f).row()
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.ui.popups.options
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.models.metadata.GameSettings
|
||||
@ -21,7 +22,7 @@ fun gameplayTab(
|
||||
optionsPopup.addCheckbox(this, "Move units with a single tap", settings.singleTapMove) { settings.singleTapMove = it }
|
||||
optionsPopup.addCheckbox(this, "Auto-assign city production", settings.autoAssignCityProduction, true) { shouldAutoAssignCityProduction ->
|
||||
settings.autoAssignCityProduction = shouldAutoAssignCityProduction
|
||||
val worldScreen = UncivGame.Current.getWorldScreenIfActive()
|
||||
val worldScreen = GUI.getWorldScreenIfActive()
|
||||
if (shouldAutoAssignCityProduction && worldScreen != null &&
|
||||
worldScreen.viewingCiv.isCurrentPlayer() && worldScreen.viewingCiv.playerType == PlayerType.Human
|
||||
) {
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.GUI
|
||||
import com.unciv.ui.screens.mainmenuscreen.MainMenuScreen
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.event.EventBus
|
||||
@ -161,7 +162,7 @@ class OptionsPopup(
|
||||
val checkbox = text.toCheckBox(initialState) {
|
||||
action(it)
|
||||
settings.save()
|
||||
val worldScreen = UncivGame.Current.getWorldScreenIfActive()
|
||||
val worldScreen = GUI.getWorldScreenIfActive()
|
||||
if (updateWorld && worldScreen != null) worldScreen.shouldUpdate = true
|
||||
}
|
||||
if (newRow) table.add(checkbox).colspan(2).left().row()
|
||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.automation.Automation
|
||||
import com.unciv.logic.city.City
|
||||
@ -53,7 +54,7 @@ class CityScreen(
|
||||
}
|
||||
|
||||
/** Toggles or adds/removes all state changing buttons */
|
||||
val canChangeState = UncivGame.Current.worldScreen!!.canChangeState
|
||||
val canChangeState = GUI.isAllowedChangeState()
|
||||
|
||||
// Clockwise from the top-left
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
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.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.city.IConstruction
|
||||
import com.unciv.logic.city.PerpetualConstruction
|
||||
@ -118,7 +119,7 @@ class ConstructionInfoTable(val cityScreen: CityScreen): Table() {
|
||||
}
|
||||
if (cityScreen.city.hasSoldBuildingThisTurn && !cityScreen.city.civ.gameInfo.gameParameters.godMode
|
||||
|| cityScreen.city.isPuppet
|
||||
|| !UncivGame.Current.worldScreen!!.isPlayersTurn || !cityScreen.canChangeState)
|
||||
|| !GUI.isMyTurn() || !GUI.isAllowedChangeState())
|
||||
sellBuildingButton.disable()
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.ui.images.ImageGetter
|
||||
import com.unciv.ui.screens.basescreen.BaseScreen
|
||||
@ -82,7 +83,7 @@ class SpecialistAllocationTable(val cityScreen: CityScreen) : Table(BaseScreen.s
|
||||
cityInfo.cityStats.update()
|
||||
cityScreen.update()
|
||||
}
|
||||
if (cityInfo.population.getFreePopulation() == 0 || !UncivGame.Current.worldScreen!!.isPlayersTurn)
|
||||
if (cityInfo.population.getFreePopulation() == 0 || !GUI.isMyTurn())
|
||||
assignButton.clear()
|
||||
return assignButton
|
||||
}
|
||||
@ -99,7 +100,7 @@ class SpecialistAllocationTable(val cityScreen: CityScreen) : Table(BaseScreen.s
|
||||
}
|
||||
|
||||
if (assignedSpecialists <= 0 || cityInfo.isPuppet) unassignButton.isVisible = false
|
||||
if (!UncivGame.Current.worldScreen!!.isPlayersTurn) unassignButton.clear()
|
||||
if (!GUI.isMyTurn()) unassignButton.clear()
|
||||
return unassignButton
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.AlertType
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
@ -72,7 +73,7 @@ class DiplomacyScreen(
|
||||
private val rightSideTable = Table()
|
||||
private val closeButton = Constants.close.toTextButton()
|
||||
|
||||
private fun isNotPlayersTurn() = !UncivGame.Current.worldScreen!!.canChangeState
|
||||
private fun isNotPlayersTurn() = !GUI.isMyTurn() || !GUI.isAllowedChangeState()
|
||||
|
||||
init {
|
||||
val splitPane = SplitPane(leftSideScroll, rightSideTable, false, skin)
|
||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.GameStarter
|
||||
@ -219,11 +220,10 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
|
||||
|
||||
|
||||
private fun resumeGame() {
|
||||
val curWorldScreen = game.worldScreen
|
||||
if (curWorldScreen != null) {
|
||||
game.resetToWorldScreen()
|
||||
if (GUI.isWorldLoaded()) {
|
||||
GUI.resetToWorldScreen()
|
||||
GUI.getWorldScreen().popups.filterIsInstance(WorldScreenMenuPopup::class.java).forEach(Popup::close)
|
||||
ImageGetter.ruleset = game.gameInfo!!.ruleset
|
||||
curWorldScreen.popups.filterIsInstance(WorldScreenMenuPopup::class.java).forEach(Popup::close)
|
||||
} else {
|
||||
QuickSave.autoLoadGame(this)
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ enum class EmpireOverviewCategories(
|
||||
fun (viewingPlayer: Civilization) = (viewingPlayer.naturalWonders.isEmpty() && viewingPlayer.cities.isEmpty()).toState()),
|
||||
Notifications("OtherIcons/Notifications", 'N', Align.top,
|
||||
fun (viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?)
|
||||
= NotificationsOverviewTable(worldScreen = UncivGame.Current.worldScreen!!, viewingPlayer, overviewScreen, persistedData),
|
||||
= NotificationsOverviewTable(viewingPlayer, overviewScreen, persistedData),
|
||||
fun (_: Civilization) = EmpireOverviewTabState.Normal)
|
||||
|
||||
; //must be here
|
||||
|
@ -3,6 +3,7 @@ package com.unciv.ui.screens.overviewscreen
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.civilization.Notification
|
||||
@ -16,7 +17,6 @@ import com.unciv.ui.components.extensions.toLabel
|
||||
import com.unciv.ui.screens.worldscreen.WorldScreen
|
||||
|
||||
class NotificationsOverviewTable(
|
||||
val worldScreen: WorldScreen,
|
||||
viewingPlayer: Civilization,
|
||||
overviewScreen: EmpireOverviewScreen,
|
||||
persistedData: EmpireOverviewTabPersistableData? = null
|
||||
@ -36,12 +36,14 @@ class NotificationsOverviewTable(
|
||||
persistableData.scrollY = pager.getPageScrollY(index)
|
||||
}
|
||||
|
||||
val notificationLog = viewingPlayer.notificationsLog
|
||||
|
||||
private val worldScreen = GUI.getWorldScreen()
|
||||
|
||||
private val notificationLog = viewingPlayer.notificationsLog
|
||||
private val notificationTable = Table(BaseScreen.skin)
|
||||
|
||||
val scaleFactor = 0.3f
|
||||
val inverseScaleFactor = 1f / scaleFactor
|
||||
private val scaleFactor = 0.3f
|
||||
private val inverseScaleFactor = 1f / scaleFactor
|
||||
private val maxWidthOfStage = 0.333f
|
||||
private val maxEntryWidth = worldScreen.stage.width * maxWidthOfStage * inverseScaleFactor
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.unciv.ui.screens.overviewscreen
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.models.ruleset.ModOptionsConstants
|
||||
@ -138,7 +139,7 @@ class StatsOverviewTab(
|
||||
for (city in viewingPlayer.cities) { city.cityStats.update() }
|
||||
update()
|
||||
}
|
||||
slider.isDisabled = !UncivGame.Current.worldScreen!!.canChangeState
|
||||
slider.isDisabled = !GUI.isAllowedChangeState()
|
||||
|
||||
sliderTable.add(slider).padTop(15f)
|
||||
add(sliderTable).colspan(2)
|
||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
@ -80,9 +81,8 @@ class UnitOverviewTab(
|
||||
}
|
||||
|
||||
private fun showWorldScreenAt(position: Vector2, unit: MapUnit?) {
|
||||
val game = overviewScreen.game
|
||||
game.resetToWorldScreen()
|
||||
game.worldScreen!!.mapHolder.setCenterPosition(position, forceSelectUnit = unit)
|
||||
GUI.resetToWorldScreen()
|
||||
GUI.getMap().setCenterPosition(position, forceSelectUnit = unit)
|
||||
}
|
||||
private fun showWorldScreenAt(unit: MapUnit) = showWorldScreenAt(unit.currentTile.position, unit)
|
||||
private fun showWorldScreenAt(tile: Tile) = showWorldScreenAt(tile.position, null)
|
||||
@ -216,7 +216,7 @@ class UnitOverviewTab(
|
||||
if (unit.promotions.canBePromoted())
|
||||
promotionsTable.add(
|
||||
ImageGetter.getImage("OtherIcons/Star").apply {
|
||||
color = if (game.worldScreen!!.canChangeState && unit.currentMovement > 0f && unit.attacksThisTurn == 0)
|
||||
color = if (GUI.isAllowedChangeState() && unit.currentMovement > 0f && unit.attacksThisTurn == 0)
|
||||
Color.GOLDENROD
|
||||
else Color.GOLDENROD.darken(0.25f)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.SplitPane
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.ui.images.IconTextButton
|
||||
import com.unciv.ui.components.AutoScrollPane
|
||||
@ -73,7 +74,7 @@ class PickerPane(
|
||||
|
||||
/** Sets the text of the [rightSideButton] and enables it if it's the player's turn */
|
||||
fun pick(rightButtonText: String) {
|
||||
if (UncivGame.Current.worldScreen!!.isPlayersTurn) rightSideButton.enable()
|
||||
if (GUI.isMyTurn()) rightSideButton.enable()
|
||||
rightSideButton.setText(rightButtonText)
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Cell
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.models.TutorialTrigger
|
||||
@ -51,16 +52,13 @@ private object PolicyColors {
|
||||
}
|
||||
|
||||
fun Policy.isAdopted() : Boolean {
|
||||
val worldScreen = UncivGame.Current.worldScreen ?: return false
|
||||
val viewingCiv = worldScreen.selectedCiv
|
||||
return viewingCiv.policies.isAdopted(this.name)
|
||||
return GUI.getSelectedPlayer().policies.isAdopted(this.name)
|
||||
}
|
||||
|
||||
fun Policy.isPickable() : Boolean {
|
||||
val worldScreen = UncivGame.Current.worldScreen ?: return false
|
||||
val viewingCiv = worldScreen.viewingCiv
|
||||
val selectedCiv = worldScreen.selectedCiv
|
||||
if (!worldScreen.isPlayersTurn
|
||||
val viewingCiv = GUI.getViewingPlayer()
|
||||
val selectedCiv = GUI.getSelectedPlayer()
|
||||
if (!GUI.isMyTurn()
|
||||
|| viewingCiv.isDefeated()
|
||||
|| selectedCiv.policies.isAdopted(this.name)
|
||||
|| this.policyBranchType == PolicyBranchType.BranchComplete
|
||||
@ -109,13 +107,10 @@ class PolicyButton(val policy: Policy, size: Float = 30f) : BorderedTable(
|
||||
return this
|
||||
}
|
||||
|
||||
fun updateState() {
|
||||
|
||||
val worldScreen = UncivGame.Current.worldScreen ?: return
|
||||
val viewingCiv = worldScreen.selectedCiv
|
||||
private fun updateState() {
|
||||
|
||||
val isPickable = policy.isPickable()
|
||||
val isAdopted = viewingCiv.policies.isAdopted(policy.name)
|
||||
val isAdopted = GUI.getSelectedPlayer().policies.isAdopted(policy.name)
|
||||
|
||||
when {
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Cell
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.GUI
|
||||
import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.models.TutorialTrigger
|
||||
import com.unciv.models.UncivSound
|
||||
@ -161,7 +162,7 @@ class PromotionPickerScreen(val unit: MapUnit) : PickerScreen(), RecreateOnResiz
|
||||
}
|
||||
|
||||
val canBePromoted = unit.promotions.canBePromoted()
|
||||
val canChangeState = game.worldScreen!!.canChangeState
|
||||
val canChangeState = GUI.isAllowedChangeState()
|
||||
val canPromoteNow = canBePromoted && canChangeState
|
||||
&& unit.currentMovement > 0 && unit.attacksThisTurn == 0
|
||||
rightSideButton.isEnabled = canPromoteNow
|
||||
@ -202,7 +203,7 @@ class PromotionPickerScreen(val unit: MapUnit) : PickerScreen(), RecreateOnResiz
|
||||
val availablePromotions = unit.promotions.getAvailablePromotions()
|
||||
|
||||
val canBePromoted = unit.promotions.canBePromoted()
|
||||
val canChangeState = game.worldScreen!!.canChangeState
|
||||
val canChangeState = GUI.isAllowedChangeState()
|
||||
|
||||
// Create nodes
|
||||
// Pass 1 - create nodes for all promotions
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.civilization.managers.TechManager
|
||||
@ -398,7 +399,7 @@ class TechPickerScreen(
|
||||
return
|
||||
}
|
||||
|
||||
if (!UncivGame.Current.worldScreen!!.canChangeState) {
|
||||
if (!GUI.isAllowedChangeState()) {
|
||||
rightSideButton.disable()
|
||||
return
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ class WorldMapHolder(
|
||||
|
||||
internal fun addTiles() {
|
||||
val tileSetStrings = TileSetStrings()
|
||||
val tileGroupsNew = tileMap.values.map { WorldTileGroup(worldScreen, it, tileSetStrings) }
|
||||
val tileGroupsNew = tileMap.values.map { WorldTileGroup(it, tileSetStrings) }
|
||||
tileGroupMap = TileGroupMap(this, tileGroupsNew, continuousScrollingX)
|
||||
|
||||
for (tileGroup in tileGroupsNew) {
|
||||
|
@ -3,6 +3,7 @@ package com.unciv.ui.screens.worldscreen.minimap
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.ui.images.IconCircleGroup
|
||||
import com.unciv.ui.components.extensions.onClick
|
||||
@ -42,7 +43,7 @@ class MapOverlayToggleButton(
|
||||
/** Toggle overlay. Called on click. */
|
||||
fun toggle() {
|
||||
setter(!getter())
|
||||
UncivGame.Current.worldScreen!!.shouldUpdate = true
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
// Setting worldScreen.shouldUpdate implicitly causes this.update() to be called by the WorldScreen on the next update.
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.ui.screens.worldscreen.unit.actions
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.automation.unit.UnitAutomation
|
||||
import com.unciv.logic.automation.unit.WorkerAutomation
|
||||
@ -30,14 +31,13 @@ import com.unciv.ui.screens.worldscreen.unit.UnitTable
|
||||
|
||||
object UnitActions {
|
||||
|
||||
fun getUnitActions(unit: MapUnit, worldScreen: WorldScreen): List<UnitAction> {
|
||||
return if (unit.showAdditionalActions) getAdditionalActions(unit, worldScreen)
|
||||
else getNormalActions(unit, worldScreen)
|
||||
fun getUnitActions(unit: MapUnit): List<UnitAction> {
|
||||
return if (unit.showAdditionalActions) getAdditionalActions(unit)
|
||||
else getNormalActions(unit)
|
||||
}
|
||||
|
||||
private fun getNormalActions(unit: MapUnit, worldScreen: WorldScreen): List<UnitAction> {
|
||||
private fun getNormalActions(unit: MapUnit): List<UnitAction> {
|
||||
val tile = unit.getTile()
|
||||
val unitTable = worldScreen.bottomUnitTable
|
||||
val actionList = ArrayList<UnitAction>()
|
||||
|
||||
if (unit.isMoving())
|
||||
@ -53,12 +53,12 @@ object UnitActions {
|
||||
addPromoteAction(unit, actionList)
|
||||
UnitActionsUpgrade.addUnitUpgradeAction(unit, actionList)
|
||||
addTransformAction(unit, actionList)
|
||||
UnitActionsPillage.addPillageAction(unit, actionList, worldScreen)
|
||||
UnitActionsPillage.addPillageAction(unit, actionList)
|
||||
addParadropAction(unit, actionList)
|
||||
addAirSweepAction(unit, actionList)
|
||||
addSetupAction(unit, actionList)
|
||||
addFoundCityAction(unit, actionList, tile)
|
||||
addBuildingImprovementsAction(unit, actionList, tile, worldScreen)
|
||||
addBuildingImprovementsAction(unit, actionList, tile)
|
||||
addRepairAction(unit, actionList)
|
||||
addCreateWaterImprovements(unit, actionList)
|
||||
UnitActionsGreatPerson.addGreatPersonActions(unit, actionList, tile)
|
||||
@ -71,32 +71,32 @@ object UnitActions {
|
||||
addTriggerUniqueActions(unit, actionList)
|
||||
addAddInCapitalAction(unit, actionList, tile)
|
||||
|
||||
addWaitAction(unit, actionList, worldScreen)
|
||||
addWaitAction(unit, actionList)
|
||||
|
||||
addToggleActionsAction(unit, actionList, unitTable)
|
||||
addToggleActionsAction(unit, actionList)
|
||||
|
||||
return actionList
|
||||
}
|
||||
|
||||
private fun getAdditionalActions(unit: MapUnit, worldScreen: WorldScreen): List<UnitAction> {
|
||||
private fun getAdditionalActions(unit: MapUnit): List<UnitAction> {
|
||||
val tile = unit.getTile()
|
||||
val unitTable = worldScreen.bottomUnitTable
|
||||
val actionList = ArrayList<UnitAction>()
|
||||
|
||||
addSleepActions(actionList, unit, true)
|
||||
addFortifyActions(actionList, unit, true)
|
||||
|
||||
addSwapAction(unit, actionList, worldScreen)
|
||||
addDisbandAction(actionList, unit, worldScreen)
|
||||
addSwapAction(unit, actionList)
|
||||
addDisbandAction(actionList, unit)
|
||||
addGiftAction(unit, actionList, tile)
|
||||
|
||||
|
||||
addToggleActionsAction(unit, actionList, unitTable)
|
||||
addToggleActionsAction(unit, actionList)
|
||||
|
||||
return actionList
|
||||
}
|
||||
|
||||
private fun addSwapAction(unit: MapUnit, actionList: ArrayList<UnitAction>, worldScreen: WorldScreen) {
|
||||
private fun addSwapAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||
val worldScreen = GUI.getWorldScreen()
|
||||
// Air units cannot swap
|
||||
if (unit.baseUnit.movesLikeAirUnits()) return
|
||||
// Disable unit swapping if multiple units are selected. It would make little sense.
|
||||
@ -118,16 +118,18 @@ object UnitActions {
|
||||
)
|
||||
}
|
||||
|
||||
private fun addDisbandAction(actionList: ArrayList<UnitAction>, unit: MapUnit, worldScreen: WorldScreen) {
|
||||
private fun addDisbandAction(actionList: ArrayList<UnitAction>, unit: MapUnit) {
|
||||
val worldScreen = GUI.getWorldScreen()
|
||||
actionList += UnitAction(type = UnitActionType.DisbandUnit, action = {
|
||||
if (!worldScreen.hasOpenPopups()) {
|
||||
val disbandText = if (unit.currentTile.getOwner() == unit.civ)
|
||||
"Disband this unit for [${unit.baseUnit.getDisbandGold(unit.civ)}] gold?".tr()
|
||||
else "Do you really want to disband this unit?".tr()
|
||||
ConfirmPopup(UncivGame.Current.worldScreen!!, disbandText, "Disband unit") {
|
||||
ConfirmPopup(worldScreen, disbandText, "Disband unit") {
|
||||
unit.disband()
|
||||
worldScreen.shouldUpdate = true
|
||||
if (UncivGame.Current.settings.autoUnitCycle) worldScreen.switchToNextUnit()
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
if (GUI.getSettings().autoUnitCycle)
|
||||
worldScreen.switchToNextUnit()
|
||||
}.open()
|
||||
}
|
||||
}.takeIf { unit.currentMovement > 0 })
|
||||
@ -189,7 +191,7 @@ object UnitActions {
|
||||
tile.changeImprovement("City center")
|
||||
tile.removeRoad()
|
||||
unit.destroy()
|
||||
UncivGame.Current.worldScreen!!.shouldUpdate = true
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
}
|
||||
|
||||
if (unit.civ.playerType == PlayerType.AI)
|
||||
@ -206,7 +208,7 @@ object UnitActions {
|
||||
else {
|
||||
// ask if we would be breaking a promise
|
||||
val text = "Do you want to break your promise to [$leaders]?"
|
||||
ConfirmPopup(UncivGame.Current.worldScreen!!, text, "Break promise", action = foundAction).open(force = true)
|
||||
ConfirmPopup(GUI.getWorldScreen(), text, "Break promise", action = foundAction).open(force = true)
|
||||
}
|
||||
}
|
||||
)
|
||||
@ -360,9 +362,7 @@ object UnitActions {
|
||||
private fun addBuildingImprovementsAction(
|
||||
unit: MapUnit,
|
||||
actionList: ArrayList<UnitAction>,
|
||||
tile: Tile,
|
||||
worldScreen: WorldScreen
|
||||
) {
|
||||
tile: Tile) {
|
||||
if (!unit.cache.hasUniqueToBuildImprovements) return
|
||||
if (unit.isEmbarked()) return
|
||||
|
||||
@ -376,7 +376,10 @@ object UnitActions {
|
||||
actionList += UnitAction(UnitActionType.ConstructImprovement,
|
||||
isCurrentAction = unit.currentTile.hasImprovementInProgress(),
|
||||
action = {
|
||||
worldScreen.game.pushScreen(ImprovementPickerScreen(tile, unit) { if (UncivGame.Current.settings.autoUnitCycle) worldScreen.switchToNextUnit() })
|
||||
GUI.pushScreen(ImprovementPickerScreen(tile, unit) {
|
||||
if (GUI.getSettings().autoUnitCycle)
|
||||
GUI.getWorldScreen().switchToNextUnit()
|
||||
})
|
||||
}.takeIf { couldConstruct }
|
||||
)
|
||||
}
|
||||
@ -628,7 +631,7 @@ object UnitActions {
|
||||
unit.destroy() // City states don't get GPs
|
||||
else
|
||||
unit.gift(recipient)
|
||||
UncivGame.Current.worldScreen!!.shouldUpdate = true
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
}
|
||||
|
||||
return UnitAction(UnitActionType.GiftUnit, action = giftAction)
|
||||
@ -645,23 +648,23 @@ object UnitActions {
|
||||
}
|
||||
}
|
||||
|
||||
private fun addWaitAction(unit: MapUnit, actionList: ArrayList<UnitAction>, worldScreen: WorldScreen) {
|
||||
private fun addWaitAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||
actionList += UnitAction(
|
||||
type = UnitActionType.Wait,
|
||||
action = {
|
||||
unit.due = false
|
||||
worldScreen.switchToNextUnit()
|
||||
GUI.getWorldScreen().switchToNextUnit()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun addToggleActionsAction(unit: MapUnit, actionList: ArrayList<UnitAction>, unitTable: UnitTable) {
|
||||
private fun addToggleActionsAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||
actionList += UnitAction(
|
||||
type = if (unit.showAdditionalActions) UnitActionType.HideAdditionalActions
|
||||
else UnitActionType.ShowAdditionalActions,
|
||||
action = {
|
||||
unit.showAdditionalActions = !unit.showAdditionalActions
|
||||
unitTable.update()
|
||||
GUI.getWorldScreen().bottomUnitTable.update()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.ui.screens.worldscreen.unit.actions
|
||||
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.NotificationCategory
|
||||
import com.unciv.logic.civilization.NotificationIcon
|
||||
@ -17,7 +18,7 @@ import kotlin.random.Random
|
||||
|
||||
object UnitActionsPillage {
|
||||
|
||||
fun addPillageAction(unit: MapUnit, actionList: ArrayList<UnitAction>, worldScreen: WorldScreen) {
|
||||
fun addPillageAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||
val pillageAction = getPillageAction(unit)
|
||||
?: return
|
||||
if (pillageAction.action == null)
|
||||
@ -27,16 +28,16 @@ object UnitActionsPillage {
|
||||
action = null)
|
||||
else actionList += UnitAction(type = UnitActionType.Pillage,
|
||||
title = "${UnitActionType.Pillage} [${unit.currentTile.getImprovementToPillageName()!!}]") {
|
||||
if (!worldScreen.hasOpenPopups()) {
|
||||
if (!GUI.getWorldScreen().hasOpenPopups()) {
|
||||
val pillageText = "Are you sure you want to pillage this [${unit.currentTile.getImprovementToPillageName()!!}]?"
|
||||
ConfirmPopup(
|
||||
UncivGame.Current.worldScreen!!,
|
||||
GUI.getWorldScreen(),
|
||||
pillageText,
|
||||
"Pillage",
|
||||
true
|
||||
) {
|
||||
(pillageAction.action)()
|
||||
worldScreen.shouldUpdate = true
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
}.open()
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.unciv.ui.screens.worldscreen.unit.actions
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.models.UnitAction
|
||||
@ -21,7 +22,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() {
|
||||
clear()
|
||||
if (unit == null) return
|
||||
if (!worldScreen.canChangeState) return // No actions when it's not your turn or spectator!
|
||||
for (button in UnitActions.getUnitActions(unit, worldScreen)
|
||||
for (button in UnitActions.getUnitActions(unit)
|
||||
.map { getUnitActionButton(unit, it) })
|
||||
add(button).left().padBottom(2f).row()
|
||||
pack()
|
||||
@ -46,7 +47,7 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() {
|
||||
} else {
|
||||
actionButton.onActivation(unitAction.uncivSound) {
|
||||
unitAction.action.invoke()
|
||||
UncivGame.Current.worldScreen!!.shouldUpdate = true
|
||||
GUI.setUpdateWorldOnNextRender()
|
||||
// We keep the unit action/selection overlay from the previous unit open even when already selecting another unit
|
||||
// so you need less clicks/touches to do things, but once we do an action with the new unit, we want to close this
|
||||
// overlay, since the user definitely wants to interact with the new unit.
|
||||
|
Loading…
x
Reference in New Issue
Block a user