diff --git a/core/src/com/unciv/ui/cityscreen/CityScreen.kt b/core/src/com/unciv/ui/cityscreen/CityScreen.kt index 92f4221503..47c68b3fa4 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreen.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreen.kt @@ -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) diff --git a/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt b/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt index f9c85b8e29..759adbccd9 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt @@ -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() diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt index ff7e31edc9..87d82a3dc0 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionInfoTable.kt @@ -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)) } } } diff --git a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt index cb529c2a80..baaf9aa9cb 100644 --- a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt +++ b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt @@ -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)) } } } diff --git a/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt b/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt index c9164dabc4..41cf905bb2 100644 --- a/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt +++ b/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt @@ -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()) } diff --git a/core/src/com/unciv/ui/overviewscreen/WonderOverviewTable.kt b/core/src/com/unciv/ui/overviewscreen/WonderOverviewTable.kt index c313f652e2..e67f03c35c 100644 --- a/core/src/com/unciv/ui/overviewscreen/WonderOverviewTable.kt +++ b/core/src/com/unciv/ui/overviewscreen/WonderOverviewTable.kt @@ -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) diff --git a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt index ce55b36aec..2f4c62ceaf 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt @@ -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) diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index 92a07035ea..d56fe406fc 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -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) diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 9fc6f61bd7..a1934c0e32 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -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 diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt b/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt index 5dd88e799b..d480a49d9b 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreenTopBar.kt @@ -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) diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt index 7156f740f4..d41496d51a 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt @@ -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) diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt index be0dc9b44d..9496687837 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt @@ -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)) } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index e40ee1e0a7..0e5e1ff769 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -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()