From b4614fc1f546f6b82f99914a92e61143def17c2c Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 24 Jul 2018 18:22:39 +0300 Subject: [PATCH] Railroad now looks like a railroad and visible on tundra --- android/assets/OtherIcons/Railroad.png | Bin 0 -> 1506 bytes android/build.gradle | 4 +- core/src/com/unciv/logic/map/TileMap.kt | 1 - core/src/com/unciv/ui/tilegroups/TileGroup.kt | 68 +++++++++++------- 4 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 android/assets/OtherIcons/Railroad.png diff --git a/android/assets/OtherIcons/Railroad.png b/android/assets/OtherIcons/Railroad.png new file mode 100644 index 0000000000000000000000000000000000000000..f3e980d295c84e0dc8d64f9a9258e1390cc51d48 GIT binary patch literal 1506 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yu@pObhHwBu4M$1`kk47*5n0T@ zz%2~Ij105pNH8$4ws^WYhE&XXd&jU(##Myv!F{vo2PN4ZCJQMEs54~NvidPiJITwz z*(uz>q3HG`C8dMoAUz0?(mfF_8-#c_Sfz_(erCw>aQ&?YI~UF^lcd}(z#Mz z`*y##-1~dszW<8ronJ3Z-gm5+wQg4D5D~$K<{aJSXY}%n(&T$_MlY3h zuTAr*@>Z)|ay08CQ1|7F*>n43%QM?W+uzAvF61+H>t^g`Wk;!vOvFbBR(k6Q5>(Bf$Q7qeAZLjKN zyGu!1LAqbQ*y?w@Z}*nNUC!V8URtzEEk4>b2_7H9GfQTcs6E>k9r3$*f}+t&&n*$w z`jhvZdbs9W)QKgZ!`39uzW(hk&pd^I0Bop0Ec?CZI&~G5$>((LACFvfd%DjrkM6Bs zA6^o+Fb4TQ%v&v1ZEj!O>ykG+ysg(*l)RtOSG>Y7N=HLeKtn@7BVx&Rvx%P5J=2rk z?QY$=pIuUE@;sOBt;&=2CZFRZY`MQ$t-spbHlM2MlS}%yL_{0C)CGmWYE__qKlk;e zR%LgV%7)48D)%{Vc|}53YzidKbS_2D2F0ea;rF|TZryL@nds@i=;$qwL!Pr-+i*7f zcNv>M*nL1Jq9Kd!t?HBasZaKER@=Kb<&t~U8laWHROQiqbrMkj^2IbtR<|a5-k#B>+Q)U?@undJb@ZX%f_)RPVJ{k`*ySWBJ-=~9=3Mje_Hs;{`A6{zpGCyDdxW_ z{N#ezN9SK!`E^Y#_PtA8Uo8)>Pj6 x!u;%?$EU|dmuLM@JbC{k^Fv5E$ { - var sightDistance = sightDistance val viewableTiles = getTilesInDistance(position, 1).toMutableList() for (i in 1..sightDistance) { // in each layer, getTilesAtDistance(position, i).filterTo(viewableTiles) // take only tiles which have a visible neighbor, which is lower than the tile diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index 2a491e8f3b..33f2601616 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -22,7 +22,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { protected var resourceImage: Image? = null protected var improvementImage: Image? =null var populationImage: Image? = null - private val roadImages = HashMap() + private val roadImages = HashMap() private val borderImages = HashMap>() // map of neiboring tile to border images protected var civilianUnitImage: Group? = null protected var militaryUnitImage: Group? = null @@ -30,6 +30,11 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { private val fogImage = ImageGetter.getImage("TerrainIcons/Fog.png") var yieldGroup = YieldGroup() + class RoadImage{ + var roadStatus:RoadStatus = RoadStatus.None + var image:Image? = null + } + init { val groupSize = 54f this.setSize(groupSize,groupSize) @@ -164,34 +169,45 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { } private fun updateRoadImages() { - if (tileInfo.roadStatus !== RoadStatus.None) { - for (neighbor in tileInfo.neighbors) { - if (neighbor.roadStatus === RoadStatus.None) continue - if (!roadImages.containsKey(neighbor)) { - val image = ImageGetter.getImage(ImageGetter.WhiteDot) - roadImages[neighbor] = image + for (neighbor in tileInfo.neighbors) { + if (!roadImages.containsKey(neighbor)) roadImages[neighbor] = RoadImage() + val roadImage = roadImages[neighbor]!! - val relativeHexPosition = tileInfo.position.cpy().sub(neighbor.position) - val relativeWorldPosition = HexMath().Hex2WorldCoords(relativeHexPosition) - - // This is some crazy voodoo magic so I'll explain. - image.moveBy(25f, 25f) // Move road to center of tile - // in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50 - // Here, we want to have the roads start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25. - image.moveBy(-relativeWorldPosition.x * 0.8f * 25f, -relativeWorldPosition.y * 0.8f * 25f) - image.setSize(10f, 2f) - - image.setOrigin(0f, 1f) // This is so that the rotation is calculated from the middle of the road and not the edge - image.rotation = (180 / Math.PI * Math.atan2(relativeWorldPosition.y.toDouble(), relativeWorldPosition.x.toDouble())).toFloat() - addActor(image) - } - - if (tileInfo.roadStatus === RoadStatus.Railroad && neighbor.roadStatus === RoadStatus.Railroad) - roadImages[neighbor]!!.color = Color.GRAY // railroad - else - roadImages[neighbor]!!.color = Color.BROWN // road + val roadStatus = when{ + tileInfo.roadStatus==RoadStatus.None || neighbor.roadStatus === RoadStatus.None -> RoadStatus.None + tileInfo.roadStatus==RoadStatus.Road || neighbor.roadStatus === RoadStatus.Road -> RoadStatus.Road + else -> RoadStatus.Railroad } + if (roadImage.roadStatus == roadStatus ) continue // the image is correct + + roadImage.roadStatus = roadStatus + + if(roadImage.image!=null) { + roadImage.image!!.remove() + roadImage.image = null + } + if(roadStatus==RoadStatus.None) continue // no road image + + val image = if(roadStatus==RoadStatus.Road) ImageGetter.getImage(ImageGetter.WhiteDot).apply { color= Color.BROWN } + else ImageGetter.getImage("OtherIcons/Railroad.png") + roadImage.image=image + + val relativeHexPosition = tileInfo.position.cpy().sub(neighbor.position) + val relativeWorldPosition = HexMath().Hex2WorldCoords(relativeHexPosition) + + // This is some crazy voodoo magic so I'll explain. + image.moveBy(25f, 25f) // Move road to center of tile + // in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50 + // Here, we want to have the roads start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25. + image.moveBy(-relativeWorldPosition.x * 0.8f * 25f, -relativeWorldPosition.y * 0.8f * 25f) + + image.setSize(10f, 2f) + image.setOrigin(0f, 1f) // This is so that the rotation is calculated from the middle of the road and not the edge + + image.rotation = (180 / Math.PI * Math.atan2(relativeWorldPosition.y.toDouble(), relativeWorldPosition.x.toDouble())).toFloat() + addActor(image) } + } private fun updateTileColor(isViewable: Boolean) {