Added unit icons to battle table

This commit is contained in:
Yair Morgenstern 2018-11-24 21:15:22 +02:00
parent 254d415968
commit 5577022bd7
10 changed files with 69 additions and 52 deletions

View File

@ -18,9 +18,9 @@ com.badlogic.gdx.graphics.Color: {
a: 1
}
color: {
r: 0.3372549
g: 0.7
b: 0.44705883
r: 0.2
g: 0.3
b: 0.5
a: 1
}
gray: {

View File

@ -147,6 +147,7 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
greatPeopleTable.defaults().pad(5f)
greatPeopleTable.add(Label("Great person points".tr(), skin).setFontSize(24)).colspan(3).row()
greatPeopleTable.addSeparator()
greatPeopleTable.add()
greatPeopleTable.add("Current points")
greatPeopleTable.add("Points per turn").row()
@ -239,6 +240,8 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
table.add("Movement".tr())
table.add("Closest city".tr())
table.row()
table.addSeparator()
for(unit in civInfo.getCivUnits()){
val baseUnit = unit.baseUnit()
table.add(unit.name.tr())

View File

@ -321,7 +321,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
}
if (unit != null && isViewable) { // Tile is visible
newImage = getUnitImage(unit, 25f)
newImage = ImageGetter.getUnitImage(unit, 25f)
addActor(newImage)
newImage.center(this)
newImage.y += yFromCenter
@ -331,37 +331,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
return newImage
}
fun getBackgroundImageForUnit(unit: MapUnit):Image{
return when {
unit.isEmbarked() -> ImageGetter.getImage("OtherIcons/Banner")
unit.isFortified() -> ImageGetter.getImage("OtherIcons/Shield.png")
else -> ImageGetter.getImage("OtherIcons/Circle.png")
}
}
fun getUnitImage(unit: MapUnit, size: Float): Group {
val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.getNation().getSecondaryColor())
.apply { setSize(size*0.75f, size*0.75f) }
val background = getBackgroundImageForUnit(unit)
background.apply {
this.color = unit.civInfo.getNation().getColor()
setSize(size, size)
}
val group = Group().apply {
setSize(size, size)
addActor(background)
}
unitBaseImage.center(group)
group.addActor(unitBaseImage)
if (unit.health < 100) { // add health bar
group.addActor(ImageGetter.getHealthBar(unit.health.toFloat(),100f,size))
}
return group
}
fun showCircle(color: Color) {

View File

@ -5,6 +5,7 @@ import com.unciv.logic.city.CityInfo
import com.unciv.logic.map.MapUnit
import com.unciv.logic.map.TileInfo
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.center
@ -12,7 +13,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
var cityButton: CityButton? = null
fun addWhiteHaloAroundUnit(unit: MapUnit) {
val whiteHalo = getBackgroundImageForUnit(unit)
val whiteHalo = ImageGetter.getBackgroundImageForUnit(unit)
whiteHalo.setSize(30f,30f)
val unitImage = if(unit.type.isCivilian()) civilianUnitImage
else militaryUnitImage

View File

@ -197,8 +197,10 @@ fun Image.surroundWithCircle(size:Float): IconCircleGroup {
return IconCircleGroup(size,this)
}
fun Table.addSeparator(): Image {
fun Table.addSeparator(): Cell<Image> {
row()
val image = ImageGetter.getWhiteDot()
add(image).colspan(columns).fill().row()
return image
val cell = add(image).colspan(columns).fill()
row()
return cell
}

View File

@ -10,6 +10,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
import com.unciv.logic.map.MapUnit
import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.tile.ResourceType
@ -157,4 +158,38 @@ object ImageGetter {
return healthBar
}
fun getUnitImage(unit: MapUnit, size: Float): Group {
val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.getNation().getSecondaryColor())
.apply { setSize(size*0.75f, size*0.75f) }
val background = getBackgroundImageForUnit(unit)
background.apply {
this.color = unit.civInfo.getNation().getColor()
setSize(size, size)
}
val group = Group().apply {
setSize(size, size)
addActor(background)
}
unitBaseImage.center(group)
group.addActor(unitBaseImage)
if (unit.health < 100) { // add health bar
group.addActor(ImageGetter.getHealthBar(unit.health.toFloat(),100f,size))
}
return group
}
fun getBackgroundImageForUnit(unit: MapUnit):Image{
return when {
unit.isEmbarked() -> ImageGetter.getImage("OtherIcons/Banner")
unit.isFortified() -> ImageGetter.getImage("OtherIcons/Shield.png")
else -> ImageGetter.getImage("OtherIcons/Circle.png")
}
}
}

View File

@ -15,7 +15,6 @@ import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.map.MapUnit
import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap
import com.unciv.ui.tilegroups.TileGroup
import com.unciv.ui.tilegroups.WorldTileGroup
import com.unciv.ui.utils.*
@ -114,7 +113,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
moveHereButton.addActor(numberCircle)
moveHereButton.addActor(Label(turnsToGetThere.toString(), CameraStageBaseScreen.skin).apply { center(numberCircle); setFontColor(Color.WHITE) })
val unitIcon = TileGroup(TileInfo()).getUnitImage(selectedUnit, size / 2)
val unitIcon = ImageGetter.getUnitImage(selectedUnit, size / 2)
unitIcon.y = size - unitIcon.height
moveHereButton.addActor(unitIcon)

View File

@ -47,7 +47,7 @@ class WorldScreen : CameraStageBaseScreen() {
topBar.y - nextTurnButton.height - 10f)
notificationsScroll = NotificationsScroll(this)
notificationsScroll.width = stage.width/3
val externalMinimapWrapper = Table()
val internalMinimapWrapper = Table()
internalMinimapWrapper.add(minimap).size(stage.width/5,stage.height/5)

View File

@ -53,20 +53,28 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
fun simulateBattle(attacker: MapUnitCombatant, defender: ICombatant){
clear()
row().pad(5f)
defaults().pad(5f)
val attackerNameWrapper = Table()
val attackerLabel = Label(attacker.getName(), skin)
.setFontColor(attacker.getCivilization().getNation().getColor())
add(attackerLabel)
// .setFontColor(attacker.getCivilization().getNation().getColor())
attackerNameWrapper.add(ImageGetter.getUnitImage(attacker.unit,25f)).padRight(5f)
attackerNameWrapper.add(attackerLabel)
add(attackerNameWrapper)
val defenderNameWrapper = Table()
val defenderLabel = Label(defender.getName(), skin)
.setFontColor(defender.getCivilization().getNation().getColor())
add(defenderLabel)
// .setFontColor(defender.getCivilization().getNation().getColor())
if(defender is MapUnitCombatant)
defenderNameWrapper.add(ImageGetter.getUnitImage(defender.unit,25f)).padRight(5f)
row().pad(5f)
defenderNameWrapper.add(defenderLabel)
add(defenderNameWrapper).row()
addSeparator().pad(0f)
add("{Strength}: ".tr()+attacker.getAttackingStrength(defender))
add("{Strength}: ".tr()+defender.getDefendingStrength(attacker))
row().pad(5f)
add("{Strength}: ".tr()+defender.getDefendingStrength(attacker)).row()
val attackerModifiers = BattleDamage().getAttackModifiers(attacker,defender) .map { it.key+": "+(if(it.value>0)"+" else "")+(it.value*100).toInt()+"%" }
val defenderModifiers = if (defender is MapUnitCombatant)

View File

@ -5,7 +5,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.logic.map.MapUnit
import com.unciv.logic.map.TileInfo
import com.unciv.ui.tilegroups.TileGroup
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.WorldScreen
@ -33,7 +32,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
add(unitNameLabel).pad(5f)
add(nextIdleUnitButton)
}).colspan(2).row()
separator= addSeparator()
separator= addSeparator().actor!!
add(promotionsTable).colspan(2).row()
add(unitDescriptionTable)
}
@ -110,7 +109,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
unitDescriptionTable.clearListeners()
if(selectedUnit!=null) {
unitIconHolder.add(TileGroup(TileInfo()).getUnitImage(selectedUnit!!,30f)).pad(5f)
unitIconHolder.add(ImageGetter.getUnitImage(selectedUnit!!,30f)).pad(5f)
for(promotion in selectedUnit!!.promotions.promotions)
promotionsTable.add(ImageGetter.getPromotionIcon(promotion)).size(20f)