Added icon of selected unit to unit table and movement

This commit is contained in:
Yair Morgenstern
2018-09-25 09:09:28 +03:00
parent 6af4e20d3e
commit e9bb834bac
3 changed files with 16 additions and 3 deletions

View File

@ -333,7 +333,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
} }
private fun getUnitImage(unit: MapUnit, size: Float): Group { fun getUnitImage(unit: MapUnit, size: Float): Group {
val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.getNation().getSecondaryColor()) val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.getNation().getSecondaryColor())
.apply { setSize(20f, 20f) } .apply { setSize(20f, 20f) }

View File

@ -15,6 +15,7 @@ import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
import com.unciv.models.gamebasics.unit.UnitType import com.unciv.models.gamebasics.unit.UnitType
import com.unciv.ui.tilegroups.TileGroup
import com.unciv.ui.tilegroups.WorldTileGroup import com.unciv.ui.tilegroups.WorldTileGroup
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
@ -44,14 +45,19 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
val selectedUnit = worldScreen.bottomBar.unitTable.selectedUnit val selectedUnit = worldScreen.bottomBar.unitTable.selectedUnit
if(selectedUnit!=null && selectedUnit.getTile()!=tileInfo if(selectedUnit!=null && selectedUnit.getTile()!=tileInfo
&& selectedUnit.canMoveTo(tileInfo) && selectedUnit.movementAlgs().canReach(tileInfo)) { && selectedUnit.canMoveTo(tileInfo) && selectedUnit.movementAlgs().canReach(tileInfo)) {
val size = 40f val size = 60f
val moveHereGroup = Group().apply { width = size;height = size; } val moveHereGroup = Group().apply { width = size;height = size; }
moveHereGroup.addActor(ImageGetter.getImage("OtherIcons/Circle").apply { width = size; height = size }) moveHereGroup.addActor(ImageGetter.getImage("OtherIcons/Circle").apply { width = size; height = size })
moveHereGroup.addActor(ImageGetter.getStatIcon("Movement").apply { width = size / 2; height = size / 2; center(moveHereGroup) }) moveHereGroup.addActor(ImageGetter.getStatIcon("Movement").apply { width = size / 2; height = size / 2; center(moveHereGroup) })
val turnsToGetThere = selectedUnit.movementAlgs().getShortestPath(tileInfo).size val turnsToGetThere = selectedUnit.movementAlgs().getShortestPath(tileInfo).size
val numberCircle = ImageGetter.getImage("OtherIcons/Circle").apply { width = size/2; height = size/2;color= Color.BLUE } val numberCircle = ImageGetter.getImage("OtherIcons/Circle").apply { width = size/2; height = size/2;color= Color.BLUE }
moveHereGroup.addActor(numberCircle) moveHereGroup.addActor(numberCircle)
moveHereGroup.addActor(Label(turnsToGetThere.toString(),CameraStageBaseScreen.skin).apply { center(numberCircle) }) moveHereGroup.addActor(Label(turnsToGetThere.toString(),CameraStageBaseScreen.skin).apply { center(numberCircle); setFontColor(Color.WHITE) })
val unitIcon = TileGroup(TileInfo()).getUnitImage(selectedUnit,size/3)
unitIcon.y = size-unitIcon.height
moveHereGroup.addActor(unitIcon)
if(selectedUnit.currentMovement>0) if(selectedUnit.currentMovement>0)
moveHereGroup.onClick { moveHereGroup.onClick {

View File

@ -5,12 +5,14 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.logic.map.MapUnit import com.unciv.logic.map.MapUnit
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.models.gamebasics.unit.UnitType import com.unciv.models.gamebasics.unit.UnitType
import com.unciv.ui.tilegroups.TileGroup
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
class UnitTable(val worldScreen: WorldScreen) : Table(){ class UnitTable(val worldScreen: WorldScreen) : Table(){
private val prevIdleUnitButton = IdleUnitButton(this,worldScreen.tileMapHolder,true) private val prevIdleUnitButton = IdleUnitButton(this,worldScreen.tileMapHolder,true)
private val nextIdleUnitButton = IdleUnitButton(this,worldScreen.tileMapHolder,false) private val nextIdleUnitButton = IdleUnitButton(this,worldScreen.tileMapHolder,false)
private val unitIconHolder=Table()
private val unitNameLabel = Label("",CameraStageBaseScreen.skin) private val unitNameLabel = Label("",CameraStageBaseScreen.skin)
private val promotionsTable = Table() private val promotionsTable = Table()
private val unitDescriptionLabel = Label("",CameraStageBaseScreen.skin) private val unitDescriptionLabel = Label("",CameraStageBaseScreen.skin)
@ -26,6 +28,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
add(Table().apply { add(Table().apply {
add(prevIdleUnitButton) add(prevIdleUnitButton)
add(unitIconHolder)
add(unitNameLabel).pad(5f) add(unitNameLabel).pad(5f)
add(nextIdleUnitButton) add(nextIdleUnitButton)
}).colspan(2).row() }).colspan(2).row()
@ -82,14 +85,18 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
else { else {
unitNameLabel.setText("") unitNameLabel.setText("")
unitDescriptionLabel.setText("") unitDescriptionLabel.setText("")
unitIconHolder.clear()
} }
if(!selectedUnitHasChanged) return if(!selectedUnitHasChanged) return
unitIconHolder.clear()
promotionsTable.clear() promotionsTable.clear()
unitDescriptionLabel.clearListeners() unitDescriptionLabel.clearListeners()
if(selectedUnit!=null) { if(selectedUnit!=null) {
unitIconHolder.add(TileGroup(TileInfo()).getUnitImage(selectedUnit!!,20f)).pad(5f)
for(promotion in selectedUnit!!.promotions.promotions) for(promotion in selectedUnit!!.promotions.promotions)
promotionsTable.add(ImageGetter.getPromotionIcon(promotion)).size(20f) promotionsTable.add(ImageGetter.getPromotionIcon(promotion)).size(20f)