mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 22:06:05 -04:00
Updated battle table UI
This commit is contained in:
parent
4817f49ce9
commit
f40ca8469f
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.*
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.*
|
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||||
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
import com.unciv.CrashScreen
|
import com.unciv.CrashScreen
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
@ -82,6 +83,7 @@ fun Actor.surroundWithCircle(size: Float, resizeActor: Boolean = true, color: Co
|
|||||||
return IconCircleGroup(size, this, resizeActor, color)
|
return IconCircleGroup(size, this, resizeActor, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun Actor.addBorder(size:Float, color: Color, expandCell:Boolean = false): Table {
|
fun Actor.addBorder(size:Float, color: Color, expandCell:Boolean = false): Table {
|
||||||
val table = Table()
|
val table = Table()
|
||||||
table.pad(size)
|
table.pad(size)
|
||||||
@ -93,6 +95,17 @@ fun Actor.addBorder(size:Float, color: Color, expandCell:Boolean = false): Table
|
|||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Group.addBorderAllowOpacity(size:Float, color: Color): Group {
|
||||||
|
val group = this
|
||||||
|
fun getTopBottomBorder() = ImageGetter.getDot(color).apply { width=group.width; height=size }
|
||||||
|
addActor(getTopBottomBorder().apply { setPosition(0f, group.height, Align.topLeft) })
|
||||||
|
addActor(getTopBottomBorder().apply { setPosition(0f, 0f, Align.bottomLeft) })
|
||||||
|
fun getLeftRightBorder() = ImageGetter.getDot(color).apply { width=size; height=group.height }
|
||||||
|
addActor(getLeftRightBorder().apply { setPosition(0f, 0f, Align.bottomLeft) })
|
||||||
|
addActor(getLeftRightBorder().apply { setPosition(group.width, 0f, Align.bottomRight) })
|
||||||
|
return group
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** get background Image for a new separator */
|
/** get background Image for a new separator */
|
||||||
private fun getSeparatorImage(color: Color) = ImageGetter.getDot(
|
private fun getSeparatorImage(color: Color) = ImageGetter.getDot(
|
||||||
|
@ -53,6 +53,8 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
|||||||
if (defender == null) { hide(); return }
|
if (defender == null) { hide(); return }
|
||||||
simulateBattle(attacker, defender)
|
simulateBattle(attacker, defender)
|
||||||
}
|
}
|
||||||
|
pack()
|
||||||
|
addBorderAllowOpacity(1f, Color.WHITE)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryGetAttacker(): ICombatant? {
|
private fun tryGetAttacker(): ICombatant? {
|
||||||
@ -118,32 +120,45 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
|||||||
add(attacker.getAttackingStrength().toString() + Fonts.strength)
|
add(attacker.getAttackingStrength().toString() + Fonts.strength)
|
||||||
add(defender.getDefendingStrength().toString() + Fonts.strength).row()
|
add(defender.getDefendingStrength().toString() + Fonts.strength).row()
|
||||||
|
|
||||||
|
|
||||||
|
val quarterScreen = worldScreen.stage.width/4
|
||||||
|
|
||||||
val attackerModifiers =
|
val attackerModifiers =
|
||||||
BattleDamage.getAttackModifiers(attacker, defender).map {
|
BattleDamage.getAttackModifiers(attacker, defender).map {
|
||||||
val description = if (it.key.startsWith("vs "))
|
val description = if (it.key.startsWith("vs "))
|
||||||
("vs [" + it.key.replace("vs ", "") + "]").tr()
|
("vs [" + it.key.replace("vs ", "") + "]").tr()
|
||||||
else it.key.tr()
|
else it.key.tr()
|
||||||
val percentage = (if (it.value > 0) "+" else "") + it.value + "%"
|
val percentage = (if (it.value > 0) "+" else "") + it.value + "%"
|
||||||
"$description: $percentage"
|
|
||||||
|
val upOrDownLabel = if (it.value > 0f) "⬆".toLabel(Color.GREEN) else "⬇".toLabel(
|
||||||
|
Color.RED)
|
||||||
|
val modifierTable = Table()
|
||||||
|
modifierTable.add(upOrDownLabel)
|
||||||
|
val modifierLabel = "$percentage $description".toLabel(fontSize = 14).apply { wrap=true }
|
||||||
|
modifierTable.add(modifierLabel).width(quarterScreen)
|
||||||
|
modifierTable
|
||||||
}
|
}
|
||||||
val defenderModifiers =
|
val defenderModifiers =
|
||||||
if (defender is MapUnitCombatant)
|
if (defender is MapUnitCombatant)
|
||||||
BattleDamage.getDefenceModifiers(attacker, defender).map {
|
BattleDamage.getDefenceModifiers(attacker, defender).map {
|
||||||
val description = if(it.key.startsWith("vs ")) ("vs ["+it.key.replace("vs ","")+"]").tr() else it.key.tr()
|
val description = if(it.key.startsWith("vs ")) ("vs ["+it.key.replace("vs ","")+"]").tr() else it.key.tr()
|
||||||
val percentage = (if(it.value>0)"+" else "")+ it.value +"%"
|
val percentage = (if(it.value>0)"+" else "")+ it.value +"%"
|
||||||
"$description: $percentage"
|
val upOrDownLabel = if (it.value > 0f) "⬆".toLabel(Color.GREEN) else "⬇".toLabel(
|
||||||
|
Color.RED)
|
||||||
|
val modifierTable = Table()
|
||||||
|
modifierTable.add(upOrDownLabel)
|
||||||
|
val modifierLabel = "$percentage $description".toLabel(fontSize = 14).apply { wrap=true }
|
||||||
|
modifierTable.add(modifierLabel).width(quarterScreen)
|
||||||
|
modifierTable
|
||||||
}
|
}
|
||||||
else listOf()
|
else listOf()
|
||||||
|
|
||||||
val quarterScreen = worldScreen.stage.width/4
|
|
||||||
for (i in 0..max(attackerModifiers.size,defenderModifiers.size)) {
|
for (i in 0..max(attackerModifiers.size,defenderModifiers.size)) {
|
||||||
if (attackerModifiers.size > i)
|
if (attackerModifiers.size > i)
|
||||||
add(attackerModifiers[i].toLabel(fontSize = 14)
|
add(attackerModifiers[i])
|
||||||
.apply { wrap = true }).width(quarterScreen)
|
|
||||||
else add().width(quarterScreen)
|
else add().width(quarterScreen)
|
||||||
if (defenderModifiers.size > i)
|
if (defenderModifiers.size > i)
|
||||||
add(defenderModifiers[i].toLabel(fontSize = 14)
|
add(defenderModifiers[i])
|
||||||
.apply { wrap = true }).width(quarterScreen)
|
|
||||||
else add().width(quarterScreen)
|
else add().width(quarterScreen)
|
||||||
row().pad(2f)
|
row().pad(2f)
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,11 @@ import com.badlogic.gdx.utils.Align
|
|||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.ui.civilopedia.CivilopediaScreen
|
|
||||||
import com.unciv.ui.civilopedia.FormattedLine.IconDisplay
|
import com.unciv.ui.civilopedia.FormattedLine.IconDisplay
|
||||||
import com.unciv.ui.civilopedia.MarkupRenderer
|
import com.unciv.ui.civilopedia.MarkupRenderer
|
||||||
import com.unciv.ui.utils.BaseScreen
|
import com.unciv.ui.utils.BaseScreen
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
|
import com.unciv.ui.utils.addBorderAllowOpacity
|
||||||
import com.unciv.ui.utils.toLabel
|
import com.unciv.ui.utils.toLabel
|
||||||
|
|
||||||
class TileInfoTable(private val viewingCiv :CivilizationInfo) : Table(BaseScreen.skin) {
|
class TileInfoTable(private val viewingCiv :CivilizationInfo) : Table(BaseScreen.skin) {
|
||||||
@ -32,6 +32,7 @@ class TileInfoTable(private val viewingCiv :CivilizationInfo) : Table(BaseScreen
|
|||||||
}
|
}
|
||||||
|
|
||||||
pack()
|
pack()
|
||||||
|
addBorderAllowOpacity(1f, Color.WHITE)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getStatsTable(tile: TileInfo): Table {
|
fun getStatsTable(tile: TileInfo): Table {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user