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:
Yair Morgenstern 2018-05-15 23:39:04 +03:00
parent 030ddafce6
commit 2c2a4e5da3
7 changed files with 52 additions and 42 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 26
versionCode 55
versionName "2.1.5"
versionCode 57
versionName "2.1.7"
}
buildTypes {
release {

View File

@ -24,6 +24,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
}
fun getDistanceToTilesWithinTurn(origin: Vector2, unitMovement: Float): HashMap<TileInfo, Float> {
if(unitMovement==0f) return hashMapOf()
val distanceToTiles = HashMap<TileInfo, Float>()
val unitTile = tileMap[origin]
distanceToTiles[unitTile] = 0f

View File

@ -9,16 +9,16 @@ import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.utils.CameraStageBaseScreen
class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
private var selectedProduction: String?=null
private var selectedProduction: String? = null
private fun getProductionButton(production: String, buttonText: String,
description: String?, rightSideButtonText: String): TextButton {
val productionTextButton = TextButton(buttonText, CameraStageBaseScreen.skin)
productionTextButton.addClickListener {
selectedProduction = production
pick(rightSideButtonText)
descriptionLabel.setText(description)
}
selectedProduction = production
pick(rightSideButtonText)
descriptionLabel.setText(description)
}
return productionTextButton
}
@ -27,17 +27,17 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
closeButton.clearListeners() // Don't go back to the world screen, unlike the other picker screens!
closeButton.addClickListener {
game.screen = CityScreen(this@ConstructionPickerScreen.city)
dispose()
}
game.screen = CityScreen(this@ConstructionPickerScreen.city)
dispose()
}
rightSideButton.setText("Pick building")
rightSideButton.addClickListener {
city.cityConstructions.currentConstruction = selectedProduction!!
city.cityStats.update() // Because maybe we set/removed the science or gold production options.
game.screen = CityScreen(this@ConstructionPickerScreen.city)
dispose()
}
city.cityConstructions.currentConstruction = selectedProduction!!
city.cityStats.update() // Because maybe we set/removed the science or gold production options.
game.screen = CityScreen(this@ConstructionPickerScreen.city)
dispose()
}
val cityConstructions = city.cityConstructions
val regularBuildings = VerticalGroup().space(10f)
@ -57,7 +57,7 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
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,
unit.name + "\r\n" + cityConstructions.turnsToConstruction(unit.name) + " turns",
unit.getDescription(true), "Train " + unit.name))

View File

@ -34,11 +34,12 @@ open class PickerScreen : CameraStageBaseScreen() {
bottomTable.add(descriptionLabel).pad(5f).width(stage.width / 2)
rightSideButton = TextButton("", CameraStageBaseScreen.skin)
rightSideButton.disable()
rightSideGroup.addActor(rightSideButton)
bottomTable.add(rightSideGroup).width(stage.width / 4)
bottomTable.height = stage.height * (1 - screenSplit)
bottomTable.align(Align.center)
rightSideButton.disable()
topTable = Table()
val scrollPane = ScrollPane(topTable)

View File

@ -88,27 +88,37 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
if (tileInfo.getOwner() != null) {
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 relativeWorldPosition = HexMath.Hex2WorldCoords(relativeHexPosition)
// This is some crazy voodoo magic so I'll explain.
image.setSize(35f, 2f)
image.moveBy(width / 2 - image.width / 2, // center
height / 2 - image.height / 2)
// in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50
// Here, we want to have the borders start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25.
// BUT, we don't actually want it all the way out there, because we want to display the borders of 2 different civs!
// So we set it to 0.75
image.moveBy(-relativeWorldPosition.x * 0.75f * 25f, -relativeWorldPosition.y * 0.75f * 25f)
for(i in -2..2) {
val image = ImageGetter.getImage("UnitIcons/Circle.png")
image.setSize(5f, 5f)
image.moveBy(width / 2 - image.width / 2, // center
height / 2 - image.height / 2)
// in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50
// Here, we want to have the borders start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25.
// BUT, we don't actually want it all the way out there, because we want to display the borders of 2 different civs!
// So we set it to 0.75
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.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()
addActor(image)
borderImages.add(image)
}
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.rotation = (90 + 180 / Math.PI * Math.atan2(relativeWorldPosition.y.toDouble(), relativeWorldPosition.x.toDouble())).toFloat()
addActor(image)
borderImages.add(image)
}
}
@ -238,6 +248,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
fun showCircle(color:Color){
circleImage.isVisible = true
val color = Color(color)
color.a = 0.3f
circleImage.color = color
}

View File

@ -98,11 +98,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
}
}
if(worldScreen.unitTable.currentlyExecutingAction!=null)
for(tile: TileInfo in worldScreen.unitTable.getTilesForCurrentlyExecutingAction())
tileGroups[tile]!!.showCircle(Color(0f,120/255f,215/255f,1f))
else if(worldScreen.unitTable.selectedUnit!=null){
if(worldScreen.unitTable.selectedUnit!=null){
val unit = worldScreen.unitTable.selectedUnit!!
tileGroups[unit.getTile()]!!.addWhiteCircleAroundUnit()
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?")
}
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)})
tileGroups[tile]!!.showCircle(Color().fromRGB(237,41,57))
}
if(selectedTile!=null)
tileGroups[selectedTile!!]!!.showCircle(Color.WHITE)
}
fun setCenterPosition(vector: Vector2) {

View File

@ -80,10 +80,4 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
selectedUnit= selectedTile.unit
}
fun getTilesForCurrentlyExecutingAction(): Set<TileInfo>
{
if(currentlyExecutingAction == "moveTo")
return selectedUnit!!.getDistanceToTiles().keys
return emptySet()
}
}