From 397d9ccec35a6f2c76983e15c1911878eabb1b41 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 18 Oct 2019 09:16:08 +0300 Subject: [PATCH] Added river rendering, river effects not implemented yet --- core/src/com/unciv/logic/map/TileInfo.kt | 4 +++ .../ui/mapeditor/TileEditorOptionsTable.kt | 4 +++ core/src/com/unciv/ui/tilegroups/TileGroup.kt | 31 +++++++++++++++++-- .../com/unciv/ui/tilegroups/TileSetStrings.kt | 3 ++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 3091a34298..2cb6a8a6d2 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -35,6 +35,10 @@ open class TileInfo { var roadStatus = RoadStatus.None var turnsToImprovement: Int = 0 + var hasBottomRightRiver = false + var hasBottomRiver = false + var hasBottomLeftRiver = false + fun clone(): TileInfo { val toReturn = TileInfo() if(militaryUnit!=null) toReturn.militaryUnit=militaryUnit!!.clone() diff --git a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt index 7351706945..2a8c1dc5d4 100644 --- a/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt +++ b/core/src/com/unciv/ui/mapeditor/TileEditorOptionsTable.kt @@ -31,6 +31,10 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera var clearImprovement=false var selectedImprovement:TileImprovement?=null + var toggleBottomRightRiver=false + var toggleBottomRiver=false + var toggleBottomLeftRiver=false + val editorPickTable = Table() private var currentHex: Actor = Group() diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index e28ac160b4..e3b915fa88 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -182,6 +182,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) val showMilitaryUnit = viewingCiv == null || showMilitaryUnit(viewingCiv) updateTileImage(true) + updateRivers(tileInfo.hasBottomRightRiver, tileInfo.hasBottomRiver, tileInfo.hasBottomLeftRiver) updateTerrainBaseImage() updateTerrainFeatureImage() @@ -398,7 +399,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) pixelMilitaryUnitImage = null pixelMilitaryUnitImageLocation = newImageLocation - if (newImageLocation != "") { + if (newImageLocation != "" && ImageGetter.imageExists(newImageLocation)) { val pixelUnitImage = ImageGetter.getImage(newImageLocation) terrainFeatureLayerGroup.addActor(pixelUnitImage) setHexagonImageSize(pixelUnitImage)// Treat this as A TILE, which gets overlayed on the base tile. @@ -425,7 +426,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) pixelCivilianUnitImage = null pixelCivilianUnitImageLocation = newImageLocation - if (newImageLocation != "") { + if (newImageLocation != "" && ImageGetter.imageExists(newImageLocation)) { val pixelUnitImage = ImageGetter.getImage(newImageLocation) terrainFeatureLayerGroup.addActor(pixelUnitImage) setHexagonImageSize(pixelUnitImage)// Treat this as A TILE, which gets overlayed on the base tile. @@ -435,6 +436,30 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) } + var bottomRightRiverImage :Image?=null + var bottomRiverImage :Image?=null + var bottomLeftRiverImage :Image?=null + + fun updateRivers(displayBottomRight:Boolean,displayBottom:Boolean,displayBottomLeft:Boolean){ + bottomRightRiverImage = updateRiver(bottomRightRiverImage,displayBottomRight,tileSetStrings.bottomRightRiver) + bottomRiverImage = updateRiver(bottomRiverImage, displayBottom, tileSetStrings.bottomRiver) + bottomLeftRiverImage = updateRiver(bottomLeftRiverImage,displayBottomLeft,tileSetStrings.bottomLeftRiver) + } + + fun updateRiver(currentImage:Image?, shouldDisplay:Boolean,imageName:String): Image? { + if(!shouldDisplay){ + currentImage?.remove() + return null + } + else{ + if(currentImage!=null) return currentImage + if(!ImageGetter.imageExists(imageName)) return null // Old "Default" tileset gets no rivers. + val newImage = ImageGetter.getImage(imageName) + baseLayerGroup.addActor(newImage) + setHexagonImageSize(newImage) + return newImage + } + } fun showCircle(color: Color, alpha: Float = 0.3f) { circleImage.isVisible = true @@ -444,4 +469,4 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) fun hideCircle() { circleImage.isVisible = false } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt b/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt index 8b91b1556a..10f3de8065 100644 --- a/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt +++ b/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt @@ -14,6 +14,9 @@ class TileSetStrings { val tilesLocation = tileSetLocation+"Tiles/" val cityTile = tilesLocation+"City" + val bottomRightRiver = tilesLocation+"River-BottomRight" + val bottomRiver = tilesLocation+"River-Bottom" + val bottomLeftRiver = tilesLocation+"River-BottomLeft" val unitsLocation = tileSetLocation+"Units/" val landUnit = unitsLocation+"LandUnit"