Resolved #5692 - exiting Civilopedia always brings you o the previous screen

This commit is contained in:
yairm210 2021-11-19 14:15:48 +02:00
parent ff3cd7511c
commit bdeccb87e8
13 changed files with 30 additions and 17 deletions

View File

@ -51,7 +51,7 @@ class CityScreen(
private var tileTable = CityScreenTileTable(this)
/** Displays selected construction info, alternate with tileTable - sits on BOTTOM RIGHT */
private var selectedConstructionTable = ConstructionInfoTable(this.city)
private var selectedConstructionTable = ConstructionInfoTable(this)
/** Displays city name, allows switching between cities - sits on BOTTOM CENTER */
private var cityPickerTable = CityScreenCityPickerTable(this)

View File

@ -39,7 +39,7 @@ class CityScreenTileTable(private val cityScreen: CityScreen): Table() {
innerTable.add( MarkupRenderer.render(selectedTile.toMarkup(city.civInfo), iconDisplay = IconDisplay.None) {
// Sorry, this will leave the city screen
UncivGame.Current.setScreen(CivilopediaScreen(city.getRuleset(), link = it))
UncivGame.Current.setScreen(CivilopediaScreen(city.getRuleset(), cityScreen, link = it))
} )
innerTable.row()
innerTable.add(getTileStatsTable(stats)).row()

View File

@ -16,8 +16,9 @@ import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.surroundWithCircle
import com.unciv.ui.utils.toLabel
class ConstructionInfoTable(val city: CityInfo): Table() {
class ConstructionInfoTable(val cityScreen: CityScreen): Table() {
private val selectedConstructionTable = Table()
val city = cityScreen.city
init {
selectedConstructionTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
@ -72,7 +73,7 @@ class ConstructionInfoTable(val city: CityInfo): Table() {
if (link.isEmpty()) return
touchable = Touchable.enabled
onClick {
UncivGame.Current.setScreen(CivilopediaScreen(city.getRuleset(), link = link))
UncivGame.Current.setScreen(CivilopediaScreen(city.getRuleset(), cityScreen, link = link))
}
}
}

View File

@ -23,9 +23,10 @@ import com.unciv.ui.utils.AutoScrollPane as ScrollPane
* overriding the [category] parameter, or just `entry` to complement it.
*/
class CivilopediaScreen(
val ruleset: Ruleset
, category: CivilopediaCategories = CivilopediaCategories.Tutorial
, link: String = ""
val ruleset: Ruleset,
val previousScreen: BaseScreen,
category: CivilopediaCategories = CivilopediaCategories.Tutorial,
link: String = ""
) : BaseScreen() {
/** Container collecting data per Civilopedia entry
@ -168,7 +169,7 @@ class CivilopediaScreen(
init {
val imageSize = 50f
onBackButtonClicked { UncivGame.Current.setWorldScreen() }
onBackButtonClicked { game.setScreen(previousScreen) }
val hideReligionItems = !game.gameInfo.isReligionEnabled()
@ -306,7 +307,7 @@ class CivilopediaScreen(
override fun resize(width: Int, height: Int) {
if (stage.viewport.screenWidth != width || stage.viewport.screenHeight != height) {
game.setScreen(CivilopediaScreen(game.worldScreen.gameInfo.ruleSet, currentCategory, currentEntry))
game.setScreen(CivilopediaScreen(game.worldScreen.gameInfo.ruleSet, previousScreen, currentCategory, currentEntry))
}
}
}

View File

@ -143,7 +143,7 @@ class ReligionOverviewTable(
yieldAll(getCivilopediaTextLines(gameInfo.ruleSet, true))
} }.toList()
) {
UncivGame.Current.setScreen(CivilopediaScreen(gameInfo.ruleSet, link = it))
UncivGame.Current.setScreen(CivilopediaScreen(gameInfo.ruleSet, overviewScreen, link = it))
}.apply {
background = ImageGetter.getBackground(ImageGetter.getBlue())
}

View File

@ -222,7 +222,7 @@ class WonderOverviewTable(
val image = wonder.getImage()
image?.onClick {
UncivGame.Current.setScreen(CivilopediaScreen(ruleSet, wonder.category, wonder.name))
UncivGame.Current.setScreen(CivilopediaScreen(ruleSet, overviewScreen, wonder.category, wonder.name))
}
// Terrain image padding is a bit unpredictable, they need ~5f more. Ensure equal line spacing on name, not image:
add(image).pad(0f, 10f, 0f, 10f)

View File

@ -59,7 +59,7 @@ class TechPickerScreen(
descriptionLabel.onClick {
if (selectedTech != null)
game.setScreen(CivilopediaScreen(civInfo.gameInfo.ruleSet, CivilopediaCategories.Technology, selectedTech!!.name))
game.setScreen(CivilopediaScreen(civInfo.gameInfo.ruleSet, this, CivilopediaCategories.Technology, selectedTech!!.name))
}
tempTechsToResearch = ArrayList(civTech.techsToResearch)

View File

@ -159,6 +159,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo): BaseScreen() {
wrapper.onClick {
val pedia = CivilopediaScreen(
UncivGame.Current.gameInfo.ruleSet,
this,
link = "Resource/$name"
)
UncivGame.Current.setScreen(pedia)

View File

@ -236,7 +236,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
}
// Space and N are assigned in createNextTurnButton
keyPressDispatcher[Input.Keys.F1] = { game.setScreen(CivilopediaScreen(gameInfo.ruleSet)) }
keyPressDispatcher[Input.Keys.F1] = { game.setScreen(CivilopediaScreen(gameInfo.ruleSet, this)) }
keyPressDispatcher['E'] = { game.setScreen(EmpireOverviewScreen(selectedCiv)) } // Empire overview last used page
/*
* These try to be faithful to default Civ5 key bindings as found in several places online

View File

@ -197,7 +197,16 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
selectedCivTable.x = getMenuButton().width + 20f
selectedCivLabel.setFontSize(25)
selectedCivLabel.onClick { worldScreen.game.setScreen(CivilopediaScreen( worldScreen.selectedCiv.gameInfo.ruleSet, CivilopediaCategories.Nation, worldScreen.selectedCiv.civName)) }
selectedCivLabel.onClick {
val civilopeidaScreen = CivilopediaScreen(
worldScreen.selectedCiv.gameInfo.ruleSet,
worldScreen,
CivilopediaCategories.Nation,
worldScreen.selectedCiv.civName
)
worldScreen.game.setScreen(civilopeidaScreen)
}
val nation = worldScreen.gameInfo.ruleSet.nations[worldScreen.selectedCiv.civName]!!
val selectedCivIcon = ImageGetter.getNationIndicator(nation, 35f)

View File

@ -24,7 +24,8 @@ class TileInfoTable(private val viewingCiv :CivilizationInfo) : Table(BaseScreen
if (tile != null && (UncivGame.Current.viewEntireMapForDebug || viewingCiv.exploredTiles.contains(tile.position)) ) {
add(getStatsTable(tile))
add( MarkupRenderer.render(tile.toMarkup(viewingCiv), padding = 0f, iconDisplay = IconDisplay.None) {
UncivGame.Current.setScreen(CivilopediaScreen(viewingCiv.gameInfo.ruleSet, link = it))
// We need to pass the current screen here to get this to work and I can't be bothered now
// UncivGame.Current.setScreen(CivilopediaScreen(viewingCiv.gameInfo.ruleSet, link = it))
} ).pad(5f).row()
if (UncivGame.Current.viewEntireMapForDebug)
add(tile.position.run { "(${x.toInt()},${y.toInt()})" }.toLabel()).colspan(2).pad(5f)

View File

@ -16,7 +16,7 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) {
defaults().fillX()
addButton("Main menu") { worldScreen.game.setScreen(MainMenuScreen()) }
addButton("Civilopedia") { worldScreen.game.setScreen(CivilopediaScreen(worldScreen.gameInfo.ruleSet)) }
addButton("Civilopedia") { worldScreen.game.setScreen(CivilopediaScreen(worldScreen.gameInfo.ruleSet, worldScreen)) }
addButton("Save game") { worldScreen.game.setScreen(SaveGameScreen(worldScreen.gameInfo)) }
addButton("Load game") { worldScreen.game.setScreen(LoadGameScreen(worldScreen)) }

View File

@ -130,7 +130,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
}
unitIconNameGroup.clearListeners()
unitIconNameGroup.onClick {
worldScreen.game.setScreen(CivilopediaScreen(worldScreen.gameInfo.ruleSet, CivilopediaCategories.Unit, unit.name))
worldScreen.game.setScreen(CivilopediaScreen(worldScreen.gameInfo.ruleSet, worldScreen, CivilopediaCategories.Unit, unit.name))
}
unitDescriptionTable.clear()