/
WorldScreen.kt
532 lines (457 loc) · 25 KB
/
WorldScreen.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
package com.unciv.ui.worldscreen
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.InputListener
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.actions.Actions
import com.badlogic.gdx.scenes.scene2d.ui.Button
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.UncivGame
import com.unciv.logic.GameSaver
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
import com.unciv.models.Tutorial
import com.unciv.models.UncivSound
import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.ruleset.unit.UnitType
import com.unciv.models.translations.tr
import com.unciv.ui.VictoryScreen
import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.pickerscreens.GreatPersonPickerScreen
import com.unciv.ui.pickerscreens.PolicyPickerScreen
import com.unciv.ui.pickerscreens.TechButton
import com.unciv.ui.pickerscreens.TechPickerScreen
import com.unciv.ui.trade.DiplomacyScreen
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.bottombar.BattleTable
import com.unciv.ui.worldscreen.bottombar.TileInfoTable
import com.unciv.ui.worldscreen.optionstable.OnlineMultiplayer
import com.unciv.ui.worldscreen.optionstable.PopupTable
import com.unciv.ui.worldscreen.unit.UnitActionsTable
import com.unciv.ui.worldscreen.unit.UnitTable
import kotlin.concurrent.thread
class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
val gameInfo = game.gameInfo
var isPlayersTurn = viewingCiv == gameInfo.currentPlayerCiv // todo this should be updated when passing turns
var waitingForAutosave = false
val mapHolder = WorldMapHolder(this, gameInfo.tileMap)
val minimapWrapper = MinimapHolder(mapHolder)
private val topBar = WorldScreenTopBar(this)
val bottomUnitTable = UnitTable(this)
val bottomTileInfoTable = TileInfoTable(this)
val battleTable = BattleTable(this)
val unitActionsTable = UnitActionsTable(this)
private val techPolicyAndVictoryHolder = Table()
private val techButtonHolder = Table()
private val diplomacyButtonWrapper = Table()
private val nextTurnButton = createNextTurnButton()
private val tutorialTaskTable=Table().apply { background=ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f)) }
private val notificationsScroll: NotificationsScroll
var shouldUpdate=false
private var backButtonListener : InputListener
init {
topBar.setPosition(0f, stage.height - topBar.height)
topBar.width = stage.width
notificationsScroll = NotificationsScroll(this)
// notifications are right-aligned, they take up only as much space as necessary.
notificationsScroll.width = stage.width/2
minimapWrapper.x = stage.width - minimapWrapper.width
mapHolder.addTiles()
techButtonHolder.touchable=Touchable.enabled
techButtonHolder.onClick(UncivSound.Paper) {
game.setScreen(TechPickerScreen(viewingCiv))
}
techPolicyAndVictoryHolder.add(techButtonHolder)
// Don't show policies until they become relevant
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.setScreen(PolicyPickerScreen(this)) }
techPolicyAndVictoryHolder.add(policyScreenButton).pad(10f)
}
stage.addActor(mapHolder)
stage.addActor(minimapWrapper)
stage.addActor(topBar)
stage.addActor(nextTurnButton)
stage.addActor(techPolicyAndVictoryHolder)
stage.addActor(notificationsScroll)
stage.addActor(tutorialTaskTable)
diplomacyButtonWrapper.defaults().pad(5f)
stage.addActor(diplomacyButtonWrapper)
stage.addActor(bottomUnitTable)
stage.addActor(bottomTileInfoTable)
battleTable.width = stage.width/3
battleTable.x = stage.width/3
stage.addActor(battleTable)
stage.addActor(unitActionsTable)
createNextTurnButton() // needs civ table to be positioned
val tileToCenterOn: Vector2 =
when {
viewingCiv.cities.isNotEmpty() -> viewingCiv.getCapital().location
viewingCiv.getCivUnits().isNotEmpty() -> viewingCiv.getCivUnits().first().getTile().position
else -> Vector2.Zero
}
mapHolder.setCenterPosition(tileToCenterOn,true)
if(gameInfo.gameParameters.isOnlineMultiplayer && !gameInfo.isUpToDate)
isPlayersTurn = false // until we're up to date, don't let the player do anything
if(gameInfo.gameParameters.isOnlineMultiplayer && !isPlayersTurn) {
stage.addAction(Actions.forever(Actions.sequence(Actions.run {
loadLatestMultiplayerState()
}, Actions.delay(10f)))) // delay is in seconds
}
tutorialController.allTutorialsShowedCallback = {
shouldUpdate = true
}
backButtonListener = onBackButtonClicked { exitGamePrompt() }
// don't run update() directly, because the UncivGame.worldScreen should be set so that the city buttons and tile groups
// know what the viewing civ is.
shouldUpdate = true
}
private fun loadLatestMultiplayerState(){
val loadingGamePopup = PopupTable(this)
loadingGamePopup.add("Loading latest game state...")
loadingGamePopup.open()
thread(name="MultiplayerLoad") {
try {
val latestGame = OnlineMultiplayer().tryDownloadGame(gameInfo.gameId)
if(gameInfo.isUpToDate && gameInfo.currentPlayer==latestGame.currentPlayer) { // we were trying to download this to see when it's our turn...nothing changed
loadingGamePopup.close()
return@thread
}
latestGame.isUpToDate=true
// Since we're making a screen this needs to run from the man thread which has a GL context
Gdx.app.postRunnable { game.loadGame(latestGame) }
} catch (ex: Exception) {
loadingGamePopup.close()
val couldntDownloadLatestGame = PopupTable(this)
couldntDownloadLatestGame.addGoodSizedLabel("Couldn't download the latest game state!").row()
couldntDownloadLatestGame.addCloseButton()
couldntDownloadLatestGame.addAction(Actions.delay(5f, Actions.run { couldntDownloadLatestGame.close() }))
couldntDownloadLatestGame.open()
}
}
}
// This is private so that we will set the shouldUpdate to true instead.
// That way, not only do we save a lot of unnecessary updates, we also ensure that all updates are called from the main GL thread
// and we don't get any silly concurrency problems!
private fun update() {
displayTutorialsOnUpdate()
bottomUnitTable.update()
bottomTileInfoTable.updateTileTable(mapHolder.selectedTile!!)
bottomTileInfoTable.x = stage.width - bottomTileInfoTable.width
bottomTileInfoTable.y = if (UncivGame.Current.settings.showMinimap) minimapWrapper.height else 0f
battleTable.update()
tutorialTaskTable.clear()
val tutorialTask = getCurrentTutorialTask()
if (tutorialTask == "" || !game.settings.showTutorials) {
tutorialTaskTable.isVisible = false
} else {
tutorialTaskTable.isVisible = true
tutorialTaskTable.add(tutorialTask.toLabel()
.apply { setAlignment(Align.center) }).pad(10f)
tutorialTaskTable.pack()
tutorialTaskTable.centerX(stage)
tutorialTaskTable.y = topBar.y - tutorialTaskTable.height
}
minimapWrapper.update(viewingCiv)
unitActionsTable.update(bottomUnitTable.selectedUnit)
unitActionsTable.y = bottomUnitTable.height
// if we use the clone, then when we update viewable tiles
// it doesn't update the explored tiles of the civ... need to think about that harder
// it causes a bug when we move a unit to an unexplored tile (for instance a cavalry unit which can move far)
mapHolder.updateTiles(viewingCiv)
topBar.update(viewingCiv)
updateTechButton()
techPolicyAndVictoryHolder.pack()
techPolicyAndVictoryHolder.setPosition(10f, topBar.y - techPolicyAndVictoryHolder.height - 5f)
updateDiplomacyButton(viewingCiv)
if (!hasVisibleDialogs() && isPlayersTurn) {
when {
!gameInfo.oneMoreTurnMode && gameInfo.civilizations.any { it.victoryManager.hasWon() } -> game.setScreen(VictoryScreen())
viewingCiv.policies.freePolicies > 0 && viewingCiv.policies.canAdoptPolicy() -> game.setScreen(PolicyPickerScreen(this))
viewingCiv.greatPeople.freeGreatPeople > 0 -> game.setScreen(GreatPersonPickerScreen(viewingCiv))
viewingCiv.popupAlerts.any() -> AlertPopup(this, viewingCiv.popupAlerts.first())
viewingCiv.tradeRequests.isNotEmpty() -> TradePopup(this)
}
}
updateNextTurnButton(hasVisibleDialogs()) // This must be before the notifications update, since its position is based on it
notificationsScroll.update(viewingCiv.notifications)
notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f,
nextTurnButton.y - notificationsScroll.height - 5f)
}
private fun getCurrentTutorialTask(): String {
val completedTasks = game.settings.tutorialTasksCompleted
if(!completedTasks.contains("Move unit"))
return "Move a unit!\nClick on a unit > Click on a destination > Click the arrow popup"
if(!completedTasks.contains("Found city"))
return "Found a city!\nSelect the Settler (flag unit) > Click on 'Found city' (bottom-left corner)"
if(!completedTasks.contains("Enter city screen"))
return "Enter the city screen!\nClick the city button twice"
if(!completedTasks.contains("Pick technology"))
return "Pick a technology to research!\nClick on the tech button (greenish, top left) > " +
"\n select technology > click 'Research' (bottom right)"
if(!completedTasks.contains("Pick construction"))
return "Pick a construction!\nEnter city screen > Click on a unit or building (bottom left side) >" +
" \n click 'add to queue'"
if(!completedTasks.contains("Pass a turn"))
return "Pass a turn!\nCycle through units with 'Next unit' > Click 'Next turn'"
if(!completedTasks.contains("Reassign worked tiles"))
return "Reassign worked tiles!\nEnter city screen > click the assigned (green) tile to unassign > " +
"\n click an unassigned tile to assign population"
if(!completedTasks.contains("Meet another civilization"))
return "Meet another civilization!\nExplore the map until you encounter another civilization!"
if(!completedTasks.contains("Open the options table"))
return "Open the options table!\nClick the menu button (top left) > click 'Options'"
if(!completedTasks.contains("Construct an improvement"))
return "Construct an improvement!\nConstruct a Worker unit > Move to a Plains or Grassland tile > " +
"\n Click 'Create improvement' (above the unit table, bottom left)" +
"\n > Choose the farm > \n Leave the worker there until it's finished"
if(!completedTasks.contains("Create a trade route")
&& viewingCiv.citiesConnectedToCapital.any { it.civInfo==viewingCiv })
game.settings.addCompletedTutorialTask("Create a trade route")
if(viewingCiv.cities.size>1 && !completedTasks.contains("Create a trade route"))
return "Create a trade route!\nConstruct roads between your capital and another city" +
"\nOr, automate your worker and let him get to that eventually"
if(viewingCiv.isAtWar() && !completedTasks.contains("Conquer a city"))
return "Conquer a city!\nBring an enemy city down to low health > " +
"\nEnter the city with a melee unit"
if(viewingCiv.getCivUnits().any { it.type.isAirUnit() } && !completedTasks.contains("Move an air unit"))
return "Move an air unit!\nSelect an air unit > select another city withing range > " +
"\nMove the unit to the other city"
if(!completedTasks.contains("See your stats breakdown"))
return "See your stats breakdown!\nEnter the Overview screen (top right corner) >" +
"\nClick on 'Stats'"
return ""
}
private fun displayTutorialsOnUpdate() {
UncivGame.Current.crashController.showDialogIfNeeded()
displayTutorial(Tutorial.Introduction)
if (!UncivGame.Current.settings.tutorialsShown.contains("_EnemyCityNeedsConqueringWithMeleeUnit")) {
for (enemyCity in viewingCiv.diplomacy.values.filter { it.diplomaticStatus == DiplomaticStatus.War }
.map { it.otherCiv() }.flatMap { it.cities }) {
if (enemyCity.health == 1 && enemyCity.getCenterTile().getTilesInDistance(2)
.any { it.getUnits().any { unit -> unit.civInfo == viewingCiv} })
displayTutorial(Tutorial.EnemyCityNeedsConqueringWithMeleeUnit)
}
}
if(viewingCiv.cities.any { it.hasJustBeenConquered })
displayTutorial(Tutorial.AfterConquering)
if (gameInfo.getCurrentPlayerCivilization().getCivUnits().any { it.health < 100 })
displayTutorial(Tutorial.InjuredUnits)
if (gameInfo.getCurrentPlayerCivilization().getCivUnits().any { it.name == Constants.worker })
displayTutorial(Tutorial.Workers)
}
private fun updateDiplomacyButton(civInfo: CivilizationInfo) {
diplomacyButtonWrapper.clear()
if(civInfo.getKnownCivs()
.filterNot { it.isDefeated() || it==viewingCiv || it.isBarbarian() }
.any()) {
displayTutorial(Tutorial.OtherCivEncountered)
val btn = TextButton("Diplomacy".tr(), skin)
btn.onClick { UncivGame.Current.setScreen(DiplomacyScreen(viewingCiv)) }
btn.label.setFontSize(30)
btn.labelCell.pad(10f)
diplomacyButtonWrapper.add(btn)
}
diplomacyButtonWrapper.pack()
diplomacyButtonWrapper.y = techPolicyAndVictoryHolder.y - 20 - diplomacyButtonWrapper.height
}
private fun updateTechButton() {
techButtonHolder.isVisible = viewingCiv.cities.isNotEmpty()
techButtonHolder.clearChildren()
val researchableTechs = viewingCiv.gameInfo.ruleSet.technologies.values.filter { !viewingCiv.tech.isResearched(it.name) && viewingCiv.tech.canBeResearched(it.name) }
if (viewingCiv.tech.currentTechnology() == null && researchableTechs.isEmpty())
viewingCiv.tech.techsToResearch.add(Constants.futureTech)
if (viewingCiv.tech.currentTechnology() == null) {
val buttonPic = Table()
buttonPic.background = ImageGetter.getRoundedEdgeTableBackground(colorFromRGB(7, 46, 43))
buttonPic.defaults().pad(20f)
buttonPic.add("{Pick a tech}!".toLabel(Color.WHITE,30))
techButtonHolder.add(buttonPic)
}
else {
val currentTech = viewingCiv.tech.currentTechnologyName()!!
val innerButton = TechButton(currentTech,viewingCiv.tech)
innerButton.color = colorFromRGB(7, 46, 43)
techButtonHolder.add(innerButton)
val turnsToTech = viewingCiv.tech.turnsToTech(currentTech)
innerButton.text.setText(currentTech.tr() + "\r\n" + turnsToTech
+ (if(turnsToTech>1) " {turns}".tr() else " {turn}".tr()))
}
techButtonHolder.pack() //setSize(techButtonHolder.prefWidth, techButtonHolder.prefHeight)
}
private fun createNextTurnButton(): TextButton {
val nextTurnButton = TextButton("", skin) // text is set in update()
nextTurnButton.label.setFontSize(30)
nextTurnButton.labelCell.pad(10f)
nextTurnButton.onClick {
// cycle through units not yet done
if (viewingCiv.shouldGoToDueUnit()) {
val nextDueUnit = viewingCiv.getNextDueUnit()
if(nextDueUnit!=null) {
mapHolder.setCenterPosition(nextDueUnit.currentTile.position, false, false)
bottomUnitTable.selectedUnit = nextDueUnit
shouldUpdate=true
}
return@onClick
}
val cityWithNoProductionSet = viewingCiv.cities
.firstOrNull{it.cityConstructions.currentConstruction==""}
if(cityWithNoProductionSet!=null){
game.setScreen(CityScreen(cityWithNoProductionSet))
return@onClick
}
if (viewingCiv.shouldOpenTechPicker()) {
game.setScreen(TechPickerScreen(viewingCiv.tech.freeTechs != 0, viewingCiv))
return@onClick
} else if (viewingCiv.policies.shouldOpenPolicyPicker) {
game.setScreen(PolicyPickerScreen(this))
viewingCiv.policies.shouldOpenPolicyPicker = false
return@onClick
}
game.settings.addCompletedTutorialTask("Pass a turn")
nextTurn() // If none of the above
}
return nextTurnButton
}
private fun nextTurn() {
isPlayersTurn = false
shouldUpdate = true
thread(name="NextTurn") { // on a separate thread so the user can explore their world while we're passing the turn
val gameInfoClone = gameInfo.clone()
gameInfoClone.setTransients()
try {
gameInfoClone.nextTurn()
if(gameInfo.gameParameters.isOnlineMultiplayer) {
try {
OnlineMultiplayer().tryUploadGame(gameInfoClone)
} catch (ex: Exception) {
val cantUploadNewGamePopup = PopupTable(this)
cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!").row()
cantUploadNewGamePopup.addCloseButton()
cantUploadNewGamePopup.open()
isPlayersTurn = true // Since we couldn't push the new game clone, then it's like we never clicked the "next turn" button
shouldUpdate = true
return@thread
}
}
} catch (ex: Exception) {
UncivGame.Current.crashController.crashOccurred()
throw ex
}
game.gameInfo = gameInfoClone
val shouldAutoSave = gameInfoClone.turns % game.settings.turnsBetweenAutosaves == 0
// create a new worldscreen to show the new stuff we've changed, and switch out the current screen.
// do this on main thread - it's the only one that has a GL context to create images from
Gdx.app.postRunnable {
fun createNewWorldScreen(){
val newWorldScreen = WorldScreen(gameInfoClone.getPlayerToViewAs())
newWorldScreen.mapHolder.scrollX = mapHolder.scrollX
newWorldScreen.mapHolder.scrollY = mapHolder.scrollY
newWorldScreen.mapHolder.scaleX = mapHolder.scaleX
newWorldScreen.mapHolder.scaleY = mapHolder.scaleY
newWorldScreen.mapHolder.updateVisualScroll()
game.worldScreen = newWorldScreen
game.setWorldScreen()
}
if (gameInfoClone.currentPlayerCiv.civName != viewingCiv.civName
&& !gameInfoClone.gameParameters.isOnlineMultiplayer)
UncivGame.Current.setScreen(PlayerReadyScreen(gameInfoClone.getCurrentPlayerCivilization()))
else {
createNewWorldScreen()
}
if(shouldAutoSave) {
val newWorldScreen = game.worldScreen
newWorldScreen.waitingForAutosave = true
newWorldScreen.shouldUpdate = true
GameSaver().autoSave(gameInfoClone) {
// only enable the user to next turn once we've saved the current one
newWorldScreen.waitingForAutosave = false
newWorldScreen.shouldUpdate = true
}
}
}
}
}
private fun updateNextTurnButton(isSomethingOpen: Boolean) {
val text = when {
!isPlayersTurn -> "Waiting for other players..."
viewingCiv.shouldGoToDueUnit() -> "Next unit"
viewingCiv.cities.any { it.cityConstructions.currentConstruction == "" } -> "Pick construction"
viewingCiv.shouldOpenTechPicker() -> "Pick a tech"
viewingCiv.policies.shouldOpenPolicyPicker -> "Pick a policy"
else -> "Next turn"
}
nextTurnButton.setText(text.tr())
nextTurnButton.color = if (text == "Next turn") Color.WHITE else Color.GRAY
nextTurnButton.pack()
if (isSomethingOpen || !isPlayersTurn || waitingForAutosave) nextTurnButton.disable()
else nextTurnButton.enable()
nextTurnButton.setPosition(stage.width - nextTurnButton.width - 10f, topBar.y - nextTurnButton.height - 10f)
}
override fun resize(width: Int, height: Int) {
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) {
super.resize(width, height)
game.worldScreen = WorldScreen(viewingCiv) // start over.
game.setWorldScreen()
}
}
override fun render(delta: Float) {
// This is so that updates happen in the MAIN THREAD, where there is a GL Context,
// otherwise images will not load properly!
if (shouldUpdate) {
shouldUpdate = false
update()
showTutorialsOnNextTurn()
}
super.render(delta)
}
private fun showTutorialsOnNextTurn(){
val shownTutorials = UncivGame.Current.settings.tutorialsShown
displayTutorial(Tutorial.SlowStart)
if("_BarbarianEncountered" !in shownTutorials
&& viewingCiv.viewableTiles.any { it.getUnits().any { unit -> unit.civInfo.isBarbarian() } })
displayTutorial(Tutorial.BarbarianEncountered)
if(viewingCiv.cities.size > 2) displayTutorial(Tutorial.RoadsAndRailroads)
if(viewingCiv.getHappiness() < 5) displayTutorial(Tutorial.Happiness)
if(viewingCiv.getHappiness() < 0) displayTutorial(Tutorial.Unhappiness)
if(viewingCiv.goldenAges.isGoldenAge()) displayTutorial(Tutorial.GoldenAge)
if(gameInfo.turns >= 50 && UncivGame.Current.settings.checkForDueUnits) displayTutorial(Tutorial.IdleUnits)
if(gameInfo.turns >= 100) displayTutorial(Tutorial.ContactMe)
val resources = viewingCiv.getCivResources()
if(resources.any { it.resource.resourceType==ResourceType.Luxury }) displayTutorial(Tutorial.LuxuryResource)
if(resources.any { it.resource.resourceType==ResourceType.Strategic}) displayTutorial(Tutorial.StrategicResource)
if("Enemy_City" !in shownTutorials
&& viewingCiv.getKnownCivs().filter { viewingCiv.isAtWarWith(it) }
.flatMap { it.cities }.any { viewingCiv.exploredTiles.contains(it.location) })
displayTutorial(Tutorial.EnemyCity)
if(viewingCiv.containsBuildingUnique("Enables construction of Spaceship parts"))
displayTutorial(Tutorial.ApolloProgram)
if(viewingCiv.getCivUnits().any { it.type == UnitType.Siege })
displayTutorial(Tutorial.SiegeUnits)
if(viewingCiv.tech.getTechUniques().contains("Enables embarkation for land units"))
displayTutorial(Tutorial.Embarking)
}
private fun exitGamePrompt() {
// don't show a dialog, if it can't exit the game
if (game.exitEvent == null)
return
// remove current listener for the "BACK" button to avoid showing the dialog twice
stage.removeListener( backButtonListener )
var promptWindow = PopupTable(this)
promptWindow.addGoodSizedLabel("Do you want to exit the game?".tr())
promptWindow.row()
promptWindow.addButton("Yes"){game.exitEvent?.invoke()}
promptWindow.addButton("No") {
// restore the listener back
stage.addListener(backButtonListener)
promptWindow.close()
}
// show the dialog
promptWindow.open()
}
}