We now assign the input processor when assigning the current screen, hopefully this should solve the "no input" bug in Chrome OS mentioned in #1140

This commit is contained in:
Yair Morgenstern 2019-10-10 15:35:26 +03:00
parent 8d58702d80
commit 01dd6dfc7d
18 changed files with 57 additions and 49 deletions

View file

@ -11,6 +11,7 @@ import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.metadata.GameParameters
import com.unciv.models.metadata.GameSettings
import com.unciv.ui.LanguagePickerScreen
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.worldscreen.WorldScreen
import java.util.*
@ -18,7 +19,6 @@ import java.util.*
class UnCivGame(val version: String) : Game() {
var gameInfo: GameInfo = GameInfo()
lateinit var settings : GameSettings
/**
* This exists so that when debugging we can see the entire map.
* Remember to turn this to false before commit and upload!
@ -48,7 +48,12 @@ class UnCivGame(val version: String) : Game() {
startNewGame()
}
}
else screen= LanguagePickerScreen()
else setScreen(LanguagePickerScreen())
}
fun setScreen(screen: CameraStageBaseScreen) {
Gdx.input.inputProcessor = screen.stage
super.setScreen(screen)
}
fun loadGame(gameInfo:GameInfo){
@ -70,7 +75,6 @@ class UnCivGame(val version: String) : Game() {
fun setWorldScreen() {
if(screen != null && screen != worldScreen) screen.dispose()
setScreen(worldScreen)
Gdx.input.inputProcessor = worldScreen.stage
worldScreen.shouldUpdate=true // This can set the screen to the policy picker or tech picker screen, so the input processor must come before
}

View file

@ -42,7 +42,7 @@ data class LocationAction(var locations: ArrayList<Vector2> = ArrayList()) : Not
class TechAction(val techName: String = "") : NotificationAction {
override fun execute(worldScreen: WorldScreen) {
val tech = GameBasics.Technologies[techName]
worldScreen.game.screen = TechPickerScreen(worldScreen.viewingCiv, true, tech)
worldScreen.game.setScreen(TechPickerScreen(worldScreen.viewingCiv, true, tech))
}
}
@ -51,7 +51,7 @@ data class CityAction(val city: Vector2 = Vector2.Zero): NotificationAction {
override fun execute(worldScreen: WorldScreen) {
worldScreen.tileMapHolder.tileMap[city].getCity()?.let {
worldScreen.game.screen = CityScreen(it)
worldScreen.game.setScreen(CityScreen(it))
}
}

View file

@ -13,8 +13,10 @@ import com.unciv.ui.newgamescreen.NewGameScreen
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.pickerscreens.PolicyPickerScreen
import com.unciv.ui.pickerscreens.TechPickerScreen
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.WorldScreen
import com.unciv.ui.utils.addSeparator
import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
class VictoryScreen : PickerScreen() {
@ -86,7 +88,7 @@ class VictoryScreen : PickerScreen() {
rightSideButton.isVisible = true
rightSideButton.enable()
rightSideButton.onClick {
UnCivGame.Current.screen= NewGameScreen()
UnCivGame.Current.setScreen(NewGameScreen())
}
closeButton.setText("One more turn...!".tr())
@ -204,7 +206,7 @@ class VictoryScreen : PickerScreen() {
policyVictoryColumn.add(civToBranchesHaveCompleted).row()
civToBranchesHaveCompleted.touchable= Touchable.enabled
civToBranchesHaveCompleted.onClick {
game.screen = PolicyPickerScreen(UnCivGame.Current.worldScreen,entry.civ, false)
game.setScreen(PolicyPickerScreen(UnCivGame.Current.worldScreen,entry.civ, false))
dispose()
}
}
@ -228,7 +230,7 @@ class VictoryScreen : PickerScreen() {
scientificVictoryColumn.add(civToPartsBeRemaining).row()
civToPartsBeRemaining.touchable= Touchable.enabled
civToPartsBeRemaining.onClick {
game.screen = TechPickerScreen(entry.civ, false)
game.setScreen(TechPickerScreen(entry.civ, false))
dispose()
}
}

View file

@ -22,7 +22,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
prevCityButton.onClick {
val indexOfCity = civInfo.cities.indexOf(city)
val indexOfNextCity = if (indexOfCity == 0) civInfo.cities.size - 1 else indexOfCity - 1
cityScreen.game.screen = CityScreen(civInfo.cities[indexOfNextCity])
cityScreen.game.setScreen(CityScreen(civInfo.cities[indexOfNextCity]))
}
add(prevCityButton).pad(20f)
} else add()
@ -59,7 +59,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
editCityNamePopup.addCloseButton()
editCityNamePopup.addButton("Save".tr()){
city.name = textArea.text
cityScreen.game.screen = CityScreen(city)
cityScreen.game.setScreen(CityScreen(city))
}
editCityNamePopup.open()
}
@ -74,7 +74,7 @@ class CityScreenCityPickerTable(val cityScreen: CityScreen) : Table(){
nextCityButton.onClick {
val indexOfCity = civInfo.cities.indexOf(city)
val indexOfNextCity = if (indexOfCity == civInfo.cities.size - 1) 0 else indexOfCity + 1
cityScreen.game.screen = CityScreen(civInfo.cities[indexOfNextCity])
cityScreen.game.setScreen(CityScreen(civInfo.cities[indexOfNextCity]))
}
add(nextCityButton).pad(20f)
} else add()

View file

@ -51,16 +51,19 @@ class CityScreenTileTable(val city: CityInfo): Table(){
val buyTileButton = TextButton("Buy for [$goldCostOfTile] gold".tr(), CameraStageBaseScreen.skin)
buyTileButton.onClick("coin") {
city.expansion.buyTile(selectedTile)
UnCivGame.Current.screen = CityScreen(city)
UnCivGame.Current.setScreen(CityScreen(city))
}
if(goldCostOfTile>city.civInfo.gold || city.isPuppet || !UnCivGame.Current.worldScreen.isPlayersTurn)
buyTileButton.disable()
innerTable.add(buyTileButton)
}
if(city.canAcquireTile(selectedTile)){
if(city.canAcquireTile(selectedTile)) {
val acquireTileButton = TextButton("Acquire".tr(), CameraStageBaseScreen.skin)
acquireTileButton.onClick { city.expansion.takeOwnership(selectedTile); UnCivGame.Current.screen = CityScreen(city) }
acquireTileButton.onClick {
city.expansion.takeOwnership(selectedTile)
UnCivGame.Current.setScreen(CityScreen(city))
}
innerTable.add(acquireTileButton)
}
innerTable.pack()

View file

@ -59,7 +59,7 @@ class MapEditorOptionsTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEdi
val loadMapButton = TextButton("Load".tr(), skin)
loadMapButton.onClick {
UnCivGame.Current.screen = LoadMapScreen(mapEditorScreen.tileMap)
UnCivGame.Current.setScreen(LoadMapScreen(mapEditorScreen.tileMap))
}
add(loadMapButton).row()
@ -123,7 +123,7 @@ class MapDownloadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScr
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
val mapObject = MapSaver().mapFromJson(decodedMapJson)
MapSaver().saveMap(downloadableMap.name, mapObject)
UnCivGame.Current.screen = MapEditorScreen(mapObject)
UnCivGame.Current.setScreen(MapEditorScreen(mapObject))
}
scrollableMapTable.add(downloadMapButton).row()
}

View file

@ -38,7 +38,7 @@ class PolicyPickerScreen(val worldScreen: WorldScreen, civInfo: CivilizationInfo
game.setWorldScreen()
dispose()
}
else game.screen = PolicyPickerScreen(worldScreen) // update policies
else game.setScreen(PolicyPickerScreen(worldScreen)) // update policies
}
if(!UnCivGame.Current.worldScreen.isPlayersTurn)
rightSideButton.disable()

View file

@ -20,7 +20,7 @@ class PromotionPickerScreen(val mapUnit: MapUnit) : PickerScreen() {
fun acceptPromotion(promotion: Promotion?) {
mapUnit.promotions.addPromotion(promotion!!.name)
if(mapUnit.promotions.canBePromoted()) game.screen = PromotionPickerScreen(mapUnit)
if(mapUnit.promotions.canBePromoted()) game.setScreen(PromotionPickerScreen(mapUnit))
else game.setWorldScreen()
dispose()
game.worldScreen.shouldUpdate=true

View file

@ -72,7 +72,7 @@ class LoadGameScreen : PickerScreen() {
deleteSaveButton.onClick {
GameSaver().deleteSave(selectedSave)
UnCivGame.Current.screen = LoadGameScreen()
UnCivGame.Current.setScreen(LoadGameScreen())
}
deleteSaveButton.disable()
rightSideTable.add(deleteSaveButton).row()

View file

@ -21,7 +21,7 @@ class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
init {
rightSideButton.setText("Load map".tr())
rightSideButton.onClick {
UnCivGame.Current.screen = MapEditorScreen(chosenMap)
UnCivGame.Current.setScreen(MapEditorScreen(chosenMap))
dispose()
}
@ -46,7 +46,7 @@ class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
try {
val decoded = Gzip.unzip(clipboardContentsString)
val loadedMap = MapSaver().mapFromJson(decoded)
UnCivGame.Current.screen = MapEditorScreen(loadedMap)
UnCivGame.Current.setScreen(MapEditorScreen(loadedMap))
}
catch (ex:Exception){
couldNotLoadMapLabel.isVisible=true
@ -58,7 +58,7 @@ class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
deleteMapButton.onClick {
YesNoPopupTable("Are you sure you want to delete this map?", {
MapSaver().deleteMap(chosenMap)
UnCivGame.Current.screen = LoadMapScreen(previousMap)
UnCivGame.Current.setScreen(LoadMapScreen(previousMap))
}, this)
}
deleteMapButton.disable()
@ -66,6 +66,6 @@ class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
rightSideTable.add(deleteMapButton).row()
topTable.add(rightSideTable)
closeButton.onClick { UnCivGame.Current.screen = MapEditorScreen(previousMap) }
closeButton.onClick { UnCivGame.Current.setScreen(MapEditorScreen(previousMap)) }
}
}

View file

@ -72,7 +72,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
// second tap on the button will go to the city screen
onClick {
if (isButtonMoved) {
UnCivGame.Current.screen = CityScreen(city)
UnCivGame.Current.setScreen(CityScreen(city))
} else {
moveButtonDown()
if (unitTable.selectedUnit == null || unitTable.selectedUnit!!.currentMovement == 0f)

View file

@ -24,7 +24,6 @@ open class CameraStageBaseScreen : Screen {
init {
val resolutions: List<Float> = game.settings.resolution.split("x").map { it.toInt().toFloat() }
stage = Stage(ExtendViewport(resolutions[0], resolutions[1]), batch)// FitViewport(1000,600)
Gdx.input.inputProcessor = stage
}

View file

@ -84,7 +84,7 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
val tradeTable = diplomacyScreen.setTrade(requestingCiv)
tradeTable.tradeLogic.currentTrade.set(trade)
tradeTable.offerColumnsTable.update()
worldScreen.game.screen=diplomacyScreen
worldScreen.game.setScreen(diplomacyScreen)
worldScreen.shouldUpdate=true
}
open()

View file

@ -68,7 +68,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
techButtonHolder.touchable=Touchable.enabled
techButtonHolder.onClick("paper") {
game.screen = TechPickerScreen(viewingCiv)
game.setScreen(TechPickerScreen(viewingCiv))
}
techPolicyandVictoryHolder.add(techButtonHolder)
@ -76,7 +76,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
if(viewingCiv.policies.adoptedPolicies.isNotEmpty() || viewingCiv.policies.canAdoptPolicy()) {
val policyScreenButton = Button(skin)
policyScreenButton.add(ImageGetter.getImage("PolicyIcons/Constitution")).size(30f).pad(15f)
policyScreenButton.onClick { game.screen = PolicyPickerScreen(this) }
policyScreenButton.onClick { game.setScreen(PolicyPickerScreen(this)) }
techPolicyandVictoryHolder.add(policyScreenButton).pad(10f)
}
@ -189,9 +189,9 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|| alertPopupIsOpen
if(!isSomethingOpen && isPlayersTurn) {
when {
!gameInfo.oneMoreTurnMode && gameInfo.civilizations.any { it.victoryManager.hasWon() } -> game.screen = VictoryScreen()
viewingCiv.policies.freePolicies > 0 -> game.screen = PolicyPickerScreen(this)
viewingCiv.greatPeople.freeGreatPeople > 0 -> game.screen = GreatPersonPickerScreen()
!gameInfo.oneMoreTurnMode && gameInfo.civilizations.any { it.victoryManager.hasWon() } -> game.setScreen(VictoryScreen())
viewingCiv.policies.freePolicies > 0 -> game.setScreen(PolicyPickerScreen(this))
viewingCiv.greatPeople.freeGreatPeople > 0 -> game.setScreen(GreatPersonPickerScreen())
viewingCiv.popupAlerts.any() -> AlertPopup(this, viewingCiv.popupAlerts.first())
viewingCiv.tradeRequests.isNotEmpty() -> TradePopup(this)
}
@ -240,7 +240,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
.any()) {
displayTutorials("_OtherCivEncountered")
val btn = TextButton("Diplomacy".tr(), skin)
btn.onClick { UnCivGame.Current.screen = DiplomacyScreen(viewingCiv) }
btn.onClick { UnCivGame.Current.setScreen(DiplomacyScreen(viewingCiv)) }
btn.label.setFontSize(30)
btn.labelCell.pad(10f)
diplomacyButtonWrapper.add(btn)
@ -299,15 +299,15 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
val cityWithNoProductionSet = viewingCiv.cities
.firstOrNull{it.cityConstructions.currentConstruction==""}
if(cityWithNoProductionSet!=null){
game.screen = CityScreen(cityWithNoProductionSet)
game.setScreen(CityScreen(cityWithNoProductionSet))
return@onClick
}
if (viewingCiv.shouldOpenTechPicker()) {
game.screen = TechPickerScreen(viewingCiv.tech.freeTechs != 0, viewingCiv)
game.setScreen(TechPickerScreen(viewingCiv.tech.freeTechs != 0, viewingCiv))
return@onClick
} else if (viewingCiv.policies.shouldOpenPolicyPicker) {
game.screen = PolicyPickerScreen(this)
game.setScreen(PolicyPickerScreen(this))
viewingCiv.policies.shouldOpenPolicyPicker = false
return@onClick
}
@ -369,7 +369,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
if (gameInfoClone.currentPlayerCiv.civName != viewingCiv.civName
&& !gameInfoClone.gameParameters.isOnlineMultiplayer)
UnCivGame.Current.screen = PlayerReadyScreen(gameInfoClone.getCurrentPlayerCivilization())
UnCivGame.Current.setScreen(PlayerReadyScreen(gameInfoClone.getCurrentPlayerCivilization()))
else {
createNewWorldScreen()
}

View file

@ -48,7 +48,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
val overviewButton = TextButton("Overview".tr(),CameraStageBaseScreen.skin)
overviewButton.labelCell.pad(10f)
overviewButton.pack()
overviewButton.onClick { UnCivGame.Current.screen = EmpireOverviewScreen() }
overviewButton.onClick { UnCivGame.Current.setScreen(EmpireOverviewScreen()) }
overviewButton.center(this)
overviewButton.x = screen.stage.width-overviewButton.width-10
addActor(overviewButton)

View file

@ -35,37 +35,37 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree
tile.turnsToImprovement=0
tile.roadStatus=RoadStatus.None
}
UnCivGame.Current.screen = MapEditorScreen(tileMapClone)
UnCivGame.Current.setScreen(MapEditorScreen(tileMapClone))
remove()
}.size(width,height)
addSeparator()
addSquareButton("Civilopedia".tr()){
UnCivGame.Current.screen = CivilopediaScreen()
UnCivGame.Current.setScreen(CivilopediaScreen())
remove()
}.size(width,height)
addSeparator()
addSquareButton("Load game".tr()){
UnCivGame.Current.screen = LoadGameScreen()
UnCivGame.Current.setScreen(LoadGameScreen())
remove()
}.size(width,height)
addSeparator()
addSquareButton("Save game".tr()) {
UnCivGame.Current.screen = SaveGameScreen()
UnCivGame.Current.setScreen(SaveGameScreen())
remove()
}.size(width,height)
addSeparator()
addSquareButton("Start new game".tr()){ UnCivGame.Current.screen = NewGameScreen() }.size(width,height)
addSquareButton("Start new game".tr()){ UnCivGame.Current.setScreen(NewGameScreen()) }.size(width,height)
addSeparator()
addSquareButton("Multiplayer".tr()) { openMultiplayerPopup() }.size(width,height)
addSeparator()
addSquareButton("Victory status".tr()) { UnCivGame.Current.screen = VictoryScreen() }.size(width,height)
addSquareButton("Victory status".tr()) { UnCivGame.Current.setScreen(VictoryScreen()) }.size(width,height)
addSeparator()
addSquareButton("Options".tr()){

View file

@ -72,7 +72,7 @@ class UnitActions {
if(!unit.type.isCivilian() && unit.promotions.canBePromoted()) {
// promotion does not consume movement points, so we can do it always
actionList += UnitAction("Promote", true) {
UnCivGame.Current.screen = PromotionPickerScreen(unit)
UnCivGame.Current.setScreen(PromotionPickerScreen(unit))
}.sound("promote")
}
@ -146,7 +146,7 @@ class UnitActions {
&& !tile.isCityCenter()
&& GameBasics.TileImprovements.values.any { tile.canBuildImprovement(it, unit.civInfo) },
currentAction = unit.currentTile.hasImprovementInProgress()
) { worldScreen.game.screen = ImprovementPickerScreen(tile) { unitTable.selectedUnit = null } }
) { worldScreen.game.setScreen(ImprovementPickerScreen(tile) { unitTable.selectedUnit = null }) }
if(Constants.unitActionAutomation == unit.action){
actionList += UnitAction("Stop automation", true) {unit.action = null}
@ -202,7 +202,7 @@ class UnitActions {
) {
unit.civInfo.tech.freeTechs += 1
unit.destroy()
worldScreen.game.screen = TechPickerScreen(true, unit.civInfo)
worldScreen.game.setScreen(TechPickerScreen(true, unit.civInfo))
}.sound("chimes")
}

View file

@ -55,7 +55,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
if (selectedUnit != null) {
pedia.select("Units", selectedUnit?.name)
}
UnCivGame.Current.screen = pedia
UnCivGame.Current.setScreen(pedia)
}
addActor(helpUnitButton)