The ImageGetter changes rulesets correctly when entering\exiting scenario editor

This commit is contained in:
Yair Morgenstern 2020-08-11 22:44:41 +03:00
parent 0c84b95614
commit 7382d4f8e8
5 changed files with 19 additions and 8 deletions

View file

@ -50,6 +50,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
val newMap = MapGenerator(RulesetCache.getBaseRuleset())
.generateMap(MapParameters().apply { size = MapSize.Small; type = MapType.default })
Gdx.app.postRunnable { // for GL context
ImageGetter.setNewRuleset(RulesetCache.getBaseRuleset())
val mapHolder = EditorMapHolder(MapEditorScreen(), newMap)
backgroundTable.addAction(Actions.sequence(
Actions.fadeOut(0f),

View file

@ -232,7 +232,7 @@ class DiplomacyManager() {
* This includes friendly and allied city-states and the open border treaties.
*/
fun isConsideredFriendlyTerritory(): Boolean {
if(civInfo.isCityState() && relationshipLevel() >= RelationshipLevel.Friend)
if (civInfo.isCityState() && relationshipLevel() >= RelationshipLevel.Friend)
return true
return hasOpenBorders
}

View file

@ -40,9 +40,11 @@ class GameParametersScreen(var mapEditorScreen: MapEditorScreen): IPreviousScree
mapEditorScreen.ruleset.add(ruleset)
mapEditorScreen.tileEditorOptions.update()
// Remove resources that are not applicable to this scenario
for(tile in mapEditorScreen.tileMap.values){
if(tile.resource!=null && !ruleset.tileResources.containsKey(tile.resource!!))
tile.resource=null
for(tile in mapEditorScreen.tileMap.values) {
if (tile.resource != null && !ruleset.tileResources.containsKey(tile.resource!!))
tile.resource = null
if (tile.improvement != null && !ruleset.tileImprovements.containsKey(tile.improvement!!))
tile.improvement = null
}
mapEditorScreen.mapHolder.updateTileGroups()

View file

@ -12,6 +12,7 @@ import com.unciv.logic.MapSaver
import com.unciv.logic.map.Scenario
import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.translations.tr
import com.unciv.ui.newgamescreen.GameSetupInfo
@ -23,7 +24,7 @@ class MapEditorScreen(): CameraStageBaseScreen() {
var tileMap = TileMap()
var scenarioName = "" // when loading map: mapName is taken as default for scenarioName
var scenario: Scenario? = null // main indicator whether scenario information is present
var ruleset = RulesetCache.getBaseRuleset()
var ruleset = Ruleset().apply { add(RulesetCache.getBaseRuleset()) } // Since we change this in scenarios, we can't take the base ruleset directly
var gameSetupInfo = GameSetupInfo()
lateinit var mapHolder: EditorMapHolder
@ -64,12 +65,11 @@ class MapEditorScreen(): CameraStageBaseScreen() {
gameSetupInfo.gameParameters = scenario.gameParameters
ruleset = RulesetCache.getComplexRuleset(scenario.gameParameters)
ImageGetter.ruleset = ruleset
ImageGetter.setTextureRegionDrawables()
initialize()
}
fun initialize() {
ImageGetter.setNewRuleset(ruleset)
tileMap.setTransients(ruleset,false)
mapHolder = EditorMapHolder(this, tileMap)

View file

@ -37,6 +37,12 @@ object ImageGetter {
setTextureRegionDrawables()
}
fun setNewRuleset(ruleset: Ruleset) {
if (this.ruleset == ruleset) return
this.ruleset = ruleset
setTextureRegionDrawables()
}
fun setTextureRegionDrawables(){
textureRegionDrawables.clear()
@ -134,7 +140,9 @@ object ImageGetter {
val iconGroup = getImage("ImprovementIcons/$improvementName").surroundWithCircle(size)
val improvement = ruleset.tileImprovements[improvementName]!!
val improvement = ruleset.tileImprovements[improvementName]
if(improvement==null)
throw Exception("No improvement $improvementName found in ruleset!")
when {
improvement.food>0 -> iconGroup.circle.color= foodCircleColor
improvement.production>0 -> iconGroup.circle.color= productionCircleColor