mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 08:21:36 +07:00
Actually load and display the road texture found in FantasyHex (#4699)
* Actually load and display the road texture found in FantasyHex * Actually load and display the road texture found in FantasyHex - patch1
This commit is contained in:
Before Width: | Height: | Size: 140 B After Width: | Height: | Size: 140 B |
Before Width: | Height: | Size: 338 B After Width: | Height: | Size: 338 B |
@ -2111,7 +2111,7 @@ ImprovementIcons/Railroad
|
|||||||
orig: 100, 100
|
orig: 100, 100
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
index: -1
|
index: -1
|
||||||
TileSets/Default/road
|
TileSets/Default/Road
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 1421, 1847
|
xy: 1421, 1847
|
||||||
size: 61, 11
|
size: 61, 11
|
||||||
@ -4085,7 +4085,7 @@ TileSets/FantasyHex/Units/Worker
|
|||||||
orig: 32, 28
|
orig: 32, 28
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
index: -1
|
index: -1
|
||||||
TileSets/FantasyHex/road
|
TileSets/FantasyHex/Road
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 1121, 1847
|
xy: 1121, 1847
|
||||||
size: 61, 11
|
size: 61, 11
|
||||||
|
@ -146,7 +146,7 @@ object HexMath {
|
|||||||
val current = origin.cpy().sub(distance.toFloat(), distance.toFloat()) // start at 6 o clock
|
val current = origin.cpy().sub(distance.toFloat(), distance.toFloat()) // start at 6 o clock
|
||||||
for (i in 0 until distance) { // From 6 to 8
|
for (i in 0 until distance) { // From 6 to 8
|
||||||
vectors += current.cpy()
|
vectors += current.cpy()
|
||||||
vectors += origin.cpy().scl(2f).sub(current) // Get vector on other side of cloick
|
vectors += origin.cpy().scl(2f).sub(current) // Get vector on other side of clock
|
||||||
current.add(1f, 0f)
|
current.add(1f, 0f)
|
||||||
}
|
}
|
||||||
for (i in 0 until distance) { // 8 to 10
|
for (i in 0 until distance) { // 8 to 10
|
||||||
@ -180,4 +180,17 @@ object HexMath {
|
|||||||
else
|
else
|
||||||
return (abs(relative_x) + abs(relative_y)).toInt()
|
return (abs(relative_x) + abs(relative_y)).toInt()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Statically allocate the Vectors (in World coordinates)
|
||||||
|
// of the 6 clock directions for border and road drawing in TileGroup
|
||||||
|
private val clockToWorldVectors: Map<Int,Vector2> = mapOf(
|
||||||
|
2 to hex2WorldCoords(Vector2(0f, -1f)),
|
||||||
|
4 to hex2WorldCoords(Vector2(1f, 0f)),
|
||||||
|
6 to hex2WorldCoords(Vector2(1f, 1f)),
|
||||||
|
8 to hex2WorldCoords(Vector2(0f, 1f)),
|
||||||
|
10 to hex2WorldCoords(Vector2(-1f, 0f)),
|
||||||
|
12 to hex2WorldCoords(Vector2(-1f, -1f)) )
|
||||||
|
|
||||||
|
fun getClockDirectionToWorldVector(clockDirection: Int): Vector2 =
|
||||||
|
clockToWorldVectors[clockDirection] ?: Vector2.Zero
|
||||||
|
}
|
||||||
|
@ -159,7 +159,7 @@ class TileMap {
|
|||||||
|
|
||||||
/** Tries to place the [unitName] into the [TileInfo] closest to the given [position]
|
/** Tries to place the [unitName] into the [TileInfo] closest to the given [position]
|
||||||
* @param position where to try to place the unit (or close - max 10 tiles distance)
|
* @param position where to try to place the unit (or close - max 10 tiles distance)
|
||||||
* @param unitName name of the [BaseUnit] to create and place
|
* @param unitName name of the [BaseUnit][com.unciv.models.ruleset.unit.BaseUnit] to create and place
|
||||||
* @param civInfo civilization to assign unit to
|
* @param civInfo civilization to assign unit to
|
||||||
* @return created [MapUnit] or null if no suitable location was found
|
* @return created [MapUnit] or null if no suitable location was found
|
||||||
* */
|
* */
|
||||||
@ -335,9 +335,9 @@ class TileMap {
|
|||||||
* Returns -1 if not neighbors
|
* Returns -1 if not neighbors
|
||||||
*/
|
*/
|
||||||
fun getNeighborTileClockPosition(tile: TileInfo, otherTile: TileInfo): Int {
|
fun getNeighborTileClockPosition(tile: TileInfo, otherTile: TileInfo): Int {
|
||||||
var radius = mapParameters.mapSize.radius
|
val radius = if (mapParameters.shape == MapShape.rectangular)
|
||||||
if (mapParameters.shape == MapShape.rectangular)
|
mapParameters.mapSize.width / 2
|
||||||
radius = mapParameters.mapSize.width / 2
|
else mapParameters.mapSize.radius
|
||||||
|
|
||||||
val xDifference = tile.position.x - otherTile.position.x
|
val xDifference = tile.position.x - otherTile.position.x
|
||||||
val yDifference = tile.position.y - otherTile.position.y
|
val yDifference = tile.position.y - otherTile.position.y
|
||||||
@ -357,6 +357,14 @@ class TileMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Convert relative direction of otherTile seen from tile's position into a vector
|
||||||
|
* in world coordinates of length sqrt(3), so that it can be used to go from tile center to
|
||||||
|
* the edge of the hex in that direction (meaning the center of the border between the hexes)
|
||||||
|
*/
|
||||||
|
fun getNeighborTilePositionAsWorldCoords(tile: TileInfo, otherTile: TileInfo): Vector2 =
|
||||||
|
HexMath.getClockDirectionToWorldVector(getNeighborTileClockPosition(tile, otherTile))
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the closest position to (0, 0) outside the map which can be wrapped
|
* Returns the closest position to (0, 0) outside the map which can be wrapped
|
||||||
* to the position of the given vector
|
* to the position of the given vector
|
||||||
|
@ -2,14 +2,12 @@ package com.unciv.ui.tilegroups
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch
|
import com.badlogic.gdx.graphics.g2d.Batch
|
||||||
import com.badlogic.gdx.math.Vector2
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||||
import com.badlogic.gdx.scenes.scene2d.Group
|
import com.badlogic.gdx.scenes.scene2d.Group
|
||||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.HexMath
|
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.map.RoadStatus
|
import com.unciv.logic.map.RoadStatus
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
@ -444,16 +442,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings,
|
|||||||
}
|
}
|
||||||
if (neighborOwner != tileOwner && !borderImages.containsKey(neighbor)) { // there should be a border here but there isn't
|
if (neighborOwner != tileOwner && !borderImages.containsKey(neighbor)) { // there should be a border here but there isn't
|
||||||
|
|
||||||
val relativeHexPosition = when (tileInfo.tileMap.getNeighborTileClockPosition(tileInfo, neighbor)){
|
val relativeWorldPosition = tileInfo.tileMap.getNeighborTilePositionAsWorldCoords(tileInfo, neighbor)
|
||||||
2 -> Vector2(0f,-1f)
|
|
||||||
4 -> Vector2(1f,0f)
|
|
||||||
6 -> Vector2(1f,1f)
|
|
||||||
8 -> Vector2(0f,1f)
|
|
||||||
10 -> Vector2(-1f,0f)
|
|
||||||
12 -> Vector2(-1f,-1f)
|
|
||||||
else -> Vector2.Zero
|
|
||||||
}
|
|
||||||
val relativeWorldPosition = HexMath.hex2WorldCoords(relativeHexPosition)
|
|
||||||
|
|
||||||
// This is some crazy voodoo magic so I'll explain.
|
// This is some crazy voodoo magic so I'll explain.
|
||||||
val images = mutableListOf<Image>()
|
val images = mutableListOf<Image>()
|
||||||
@ -487,8 +476,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings,
|
|||||||
private fun updateRoadImages() {
|
private fun updateRoadImages() {
|
||||||
if (forMapEditorIcon) return
|
if (forMapEditorIcon) return
|
||||||
for (neighbor in tileInfo.neighbors) {
|
for (neighbor in tileInfo.neighbors) {
|
||||||
if (!roadImages.containsKey(neighbor)) roadImages[neighbor] = RoadImage()
|
val roadImage = roadImages[neighbor] ?: RoadImage().also { roadImages[neighbor] = it }
|
||||||
val roadImage = roadImages[neighbor]!!
|
|
||||||
|
|
||||||
val roadStatus = when {
|
val roadStatus = when {
|
||||||
tileInfo.roadStatus == RoadStatus.None || neighbor.roadStatus === RoadStatus.None -> RoadStatus.None
|
tileInfo.roadStatus == RoadStatus.None || neighbor.roadStatus === RoadStatus.None -> RoadStatus.None
|
||||||
@ -505,20 +493,10 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings,
|
|||||||
}
|
}
|
||||||
if (roadStatus == RoadStatus.None) continue // no road image
|
if (roadStatus == RoadStatus.None) continue // no road image
|
||||||
|
|
||||||
val image = if (roadStatus == RoadStatus.Road) ImageGetter.getDot(Color.BROWN)
|
val image = ImageGetter.getImage(tileSetStrings.roadsMap[roadStatus]!!)
|
||||||
else ImageGetter.getImage(tileSetStrings.railroad)
|
|
||||||
roadImage.image = image
|
roadImage.image = image
|
||||||
|
|
||||||
val relativeHexPosition = when (tileInfo.tileMap.getNeighborTileClockPosition(neighbor, tileInfo)){
|
val relativeWorldPosition = tileInfo.tileMap.getNeighborTilePositionAsWorldCoords(tileInfo, neighbor)
|
||||||
2 -> Vector2(0f,1f)
|
|
||||||
4 -> Vector2(-1f,0f)
|
|
||||||
6 -> Vector2(-1f,-1f)
|
|
||||||
8 -> Vector2(0f,-1f)
|
|
||||||
10 -> Vector2(1f,0f)
|
|
||||||
12 -> Vector2(1f,1f)
|
|
||||||
else -> Vector2.Zero
|
|
||||||
}
|
|
||||||
val relativeWorldPosition = HexMath.hex2WorldCoords(relativeHexPosition)
|
|
||||||
|
|
||||||
// This is some crazy voodoo magic so I'll explain.
|
// This is some crazy voodoo magic so I'll explain.
|
||||||
image.moveBy(25f, 25f) // Move road to center of tile
|
image.moveBy(25f, 25f) // Move road to center of tile
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.unciv.ui.tilegroups
|
package com.unciv.ui.tilegroups
|
||||||
|
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.logic.map.RoadStatus
|
||||||
import com.unciv.models.tilesets.TileSetCache
|
import com.unciv.models.tilesets.TileSetCache
|
||||||
import com.unciv.models.tilesets.TileSetConfig
|
import com.unciv.models.tilesets.TileSetConfig
|
||||||
|
|
||||||
@ -13,7 +14,10 @@ class TileSetStrings {
|
|||||||
val hexagon = tileSetLocation + "Hexagon"
|
val hexagon = tileSetLocation + "Hexagon"
|
||||||
val crosshatchHexagon = tileSetLocation + "CrosshatchHexagon"
|
val crosshatchHexagon = tileSetLocation + "CrosshatchHexagon"
|
||||||
val cityOverlay = tileSetLocation + "CityOverlay"
|
val cityOverlay = tileSetLocation + "CityOverlay"
|
||||||
val railroad = tileSetLocation + "Railroad"
|
val roadsMap = RoadStatus.values()
|
||||||
|
.filterNot { it == RoadStatus.None }
|
||||||
|
.map { it to tileSetLocation + it.name }
|
||||||
|
.toMap()
|
||||||
val naturalWonderOverlay = tileSetLocation + "NaturalWonderOverlay"
|
val naturalWonderOverlay = tileSetLocation + "NaturalWonderOverlay"
|
||||||
|
|
||||||
val tilesLocation = tileSetLocation + "Tiles/"
|
val tilesLocation = tileSetLocation + "Tiles/"
|
||||||
|
Reference in New Issue
Block a user