mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 19:08:48 -04:00
The tiles the unit can move to are now displayed when selecting a unit,
The hex borders have been changed to points Thanks to Mihail Pastuhov for the ideas!
This commit is contained in:
parent
030ddafce6
commit
2c2a4e5da3
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.game"
|
applicationId "com.unciv.game"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 55
|
versionCode 57
|
||||||
versionName "2.1.5"
|
versionName "2.1.7"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -24,6 +24,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getDistanceToTilesWithinTurn(origin: Vector2, unitMovement: Float): HashMap<TileInfo, Float> {
|
fun getDistanceToTilesWithinTurn(origin: Vector2, unitMovement: Float): HashMap<TileInfo, Float> {
|
||||||
|
if(unitMovement==0f) return hashMapOf()
|
||||||
val distanceToTiles = HashMap<TileInfo, Float>()
|
val distanceToTiles = HashMap<TileInfo, Float>()
|
||||||
val unitTile = tileMap[origin]
|
val unitTile = tileMap[origin]
|
||||||
distanceToTiles[unitTile] = 0f
|
distanceToTiles[unitTile] = 0f
|
||||||
|
@ -9,7 +9,7 @@ import com.unciv.ui.cityscreen.addClickListener
|
|||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
|
|
||||||
class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
||||||
private var selectedProduction: String?=null
|
private var selectedProduction: String? = null
|
||||||
|
|
||||||
private fun getProductionButton(production: String, buttonText: String,
|
private fun getProductionButton(production: String, buttonText: String,
|
||||||
description: String?, rightSideButtonText: String): TextButton {
|
description: String?, rightSideButtonText: String): TextButton {
|
||||||
@ -57,7 +57,7 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
|||||||
regularBuildings.addActor(productionTextButton)
|
regularBuildings.addActor(productionTextButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unit in GameBasics.Units.values.filter { it.isBuildable(cityConstructions)}) {
|
for (unit in GameBasics.Units.values.filter { it.isBuildable(cityConstructions) }) {
|
||||||
units.addActor(getProductionButton(unit.name,
|
units.addActor(getProductionButton(unit.name,
|
||||||
unit.name + "\r\n" + cityConstructions.turnsToConstruction(unit.name) + " turns",
|
unit.name + "\r\n" + cityConstructions.turnsToConstruction(unit.name) + " turns",
|
||||||
unit.getDescription(true), "Train " + unit.name))
|
unit.getDescription(true), "Train " + unit.name))
|
||||||
|
@ -34,11 +34,12 @@ open class PickerScreen : CameraStageBaseScreen() {
|
|||||||
bottomTable.add(descriptionLabel).pad(5f).width(stage.width / 2)
|
bottomTable.add(descriptionLabel).pad(5f).width(stage.width / 2)
|
||||||
|
|
||||||
rightSideButton = TextButton("", CameraStageBaseScreen.skin)
|
rightSideButton = TextButton("", CameraStageBaseScreen.skin)
|
||||||
|
rightSideButton.disable()
|
||||||
rightSideGroup.addActor(rightSideButton)
|
rightSideGroup.addActor(rightSideButton)
|
||||||
|
|
||||||
bottomTable.add(rightSideGroup).width(stage.width / 4)
|
bottomTable.add(rightSideGroup).width(stage.width / 4)
|
||||||
bottomTable.height = stage.height * (1 - screenSplit)
|
bottomTable.height = stage.height * (1 - screenSplit)
|
||||||
bottomTable.align(Align.center)
|
bottomTable.align(Align.center)
|
||||||
rightSideButton.disable()
|
|
||||||
|
|
||||||
topTable = Table()
|
topTable = Table()
|
||||||
val scrollPane = ScrollPane(topTable)
|
val scrollPane = ScrollPane(topTable)
|
||||||
|
@ -88,14 +88,16 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||||||
|
|
||||||
if (tileInfo.getOwner() != null) {
|
if (tileInfo.getOwner() != null) {
|
||||||
for (neighbor in tileInfo.neighbors.filter { it.getOwner() != tileInfo.getOwner() }) {
|
for (neighbor in tileInfo.neighbors.filter { it.getOwner() != tileInfo.getOwner() }) {
|
||||||
val image = ImageGetter.getImage(ImageGetter.WhiteDot)
|
|
||||||
|
|
||||||
val relativeHexPosition = tileInfo.position.cpy().sub(neighbor.position)
|
val relativeHexPosition = tileInfo.position.cpy().sub(neighbor.position)
|
||||||
val relativeWorldPosition = HexMath.Hex2WorldCoords(relativeHexPosition)
|
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.setSize(35f, 2f)
|
for(i in -2..2) {
|
||||||
|
val image = ImageGetter.getImage("UnitIcons/Circle.png")
|
||||||
|
image.setSize(5f, 5f)
|
||||||
image.moveBy(width / 2 - image.width / 2, // center
|
image.moveBy(width / 2 - image.width / 2, // center
|
||||||
height / 2 - image.height / 2)
|
height / 2 - image.height / 2)
|
||||||
// in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50
|
// in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50
|
||||||
@ -104,14 +106,22 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||||||
// So we set it to 0.75
|
// So we set it to 0.75
|
||||||
image.moveBy(-relativeWorldPosition.x * 0.75f * 25f, -relativeWorldPosition.y * 0.75f * 25f)
|
image.moveBy(-relativeWorldPosition.x * 0.75f * 25f, -relativeWorldPosition.y * 0.75f * 25f)
|
||||||
|
|
||||||
|
// And now, move it within the hexagon side according to i.
|
||||||
|
// Remember, if from the center of the heagon to the middle of the side is an (a,b) vecctor,
|
||||||
|
// Then within the side, which is of course perpendicular to the (a,b) vector,
|
||||||
|
// we can move with multiples of (b,-a) which is perpendicular to (a,b)
|
||||||
|
image.moveBy(relativeWorldPosition.y*i * 4, -relativeWorldPosition.x*i * 4)
|
||||||
|
|
||||||
image.color = tileInfo.getOwner()!!.getCivilization().getColor()
|
image.color = tileInfo.getOwner()!!.getCivilization().getColor()
|
||||||
image.setOrigin(image.width / 2, image.height / 2) // This is so that the rotation is calculated from the middle of the road and not the edge
|
//image.setOrigin(image.width / 2, image.height / 2) // This is so that the rotation is calculated from the middle of the road and not the edge
|
||||||
image.rotation = (90 + 180 / Math.PI * Math.atan2(relativeWorldPosition.y.toDouble(), relativeWorldPosition.x.toDouble())).toFloat()
|
//image.rotation = (90 + 180 / Math.PI * Math.atan2(relativeWorldPosition.y.toDouble(), relativeWorldPosition.x.toDouble())).toFloat()
|
||||||
addActor(image)
|
addActor(image)
|
||||||
borderImages.add(image)
|
borderImages.add(image)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateRoadImages() {
|
private fun updateRoadImages() {
|
||||||
@ -238,6 +248,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||||||
|
|
||||||
fun showCircle(color:Color){
|
fun showCircle(color:Color){
|
||||||
circleImage.isVisible = true
|
circleImage.isVisible = true
|
||||||
|
val color = Color(color)
|
||||||
color.a = 0.3f
|
color.a = 0.3f
|
||||||
circleImage.color = color
|
circleImage.color = color
|
||||||
}
|
}
|
||||||
|
@ -98,11 +98,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(worldScreen.unitTable.currentlyExecutingAction!=null)
|
if(worldScreen.unitTable.selectedUnit!=null){
|
||||||
for(tile: TileInfo in worldScreen.unitTable.getTilesForCurrentlyExecutingAction())
|
|
||||||
tileGroups[tile]!!.showCircle(Color(0f,120/255f,215/255f,1f))
|
|
||||||
|
|
||||||
else if(worldScreen.unitTable.selectedUnit!=null){
|
|
||||||
val unit = worldScreen.unitTable.selectedUnit!!
|
val unit = worldScreen.unitTable.selectedUnit!!
|
||||||
tileGroups[unit.getTile()]!!.addWhiteCircleAroundUnit()
|
tileGroups[unit.getTile()]!!.addWhiteCircleAroundUnit()
|
||||||
val attackableTiles:List<TileInfo>
|
val attackableTiles:List<TileInfo>
|
||||||
@ -113,9 +109,16 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
|||||||
UnitType.City -> throw Exception("How are you attacking with a city?")
|
UnitType.City -> throw Exception("How are you attacking with a city?")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(tile: TileInfo in unit.getDistanceToTiles().keys)
|
||||||
|
tileGroups[tile]!!.showCircle(Color().fromRGB(0,120,215))
|
||||||
|
|
||||||
for (tile in attackableTiles.filter { it.unit!=null && it.unit!!.owner != unit.owner && civViewableTiles.contains(it)})
|
for (tile in attackableTiles.filter { it.unit!=null && it.unit!!.owner != unit.owner && civViewableTiles.contains(it)})
|
||||||
tileGroups[tile]!!.showCircle(Color().fromRGB(237,41,57))
|
tileGroups[tile]!!.showCircle(Color().fromRGB(237,41,57))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(selectedTile!=null)
|
||||||
|
tileGroups[selectedTile!!]!!.showCircle(Color.WHITE)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCenterPosition(vector: Vector2) {
|
fun setCenterPosition(vector: Vector2) {
|
||||||
|
@ -80,10 +80,4 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
selectedUnit= selectedTile.unit
|
selectedUnit= selectedTile.unit
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTilesForCurrentlyExecutingAction(): Set<TileInfo>
|
|
||||||
{
|
|
||||||
if(currentlyExecutingAction == "moveTo")
|
|
||||||
return selectedUnit!!.getDistanceToTiles().keys
|
|
||||||
return emptySet()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user