mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-21 21:30:20 +07:00
City states button influence bar (#3248)
* City States influence fix * Influence when at war = -60f * Enemies if influence < 0f, neutrality is only from 0f to 30f * Changed RelationshipLevel accordingly * City States buttons influence bar * Influence bar in DiplomacyScreen
This commit is contained in:
@ -90,7 +90,7 @@ class DiplomacyManager() {
|
||||
* Won't go below [MINIMUM_INFLUENCE] */
|
||||
var influence = 0f
|
||||
set(value) { field = max(value, MINIMUM_INFLUENCE) }
|
||||
|
||||
get() = if(civInfo.isAtWarWith(otherCiv())) MINIMUM_INFLUENCE else field
|
||||
/** For city-states. Resting point is the value of Influence at which it ceases changing by itself */
|
||||
var restingPoint = 0f
|
||||
|
||||
@ -137,10 +137,9 @@ class DiplomacyManager() {
|
||||
return otherCiv().getDiplomacyManager(civInfo).relationshipLevel()
|
||||
|
||||
if(civInfo.isCityState()) {
|
||||
if(influence <= -60) return RelationshipLevel.Unforgivable
|
||||
if(influence <= -30 || civInfo.isAtWarWith(otherCiv())) return RelationshipLevel.Enemy
|
||||
|
||||
if(influence >= 60) return RelationshipLevel.Ally
|
||||
if(influence <= -30 || civInfo.isAtWarWith(otherCiv())) return RelationshipLevel.Unforgivable
|
||||
if(influence < 0) return RelationshipLevel.Enemy
|
||||
if(influence >= 60 && civInfo.getAllyCiv() == otherCivName) return RelationshipLevel.Ally
|
||||
if(influence >= 30) return RelationshipLevel.Friend
|
||||
return RelationshipLevel.Neutral
|
||||
}
|
||||
|
@ -12,9 +12,12 @@ import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.logic.city.CityConstructions
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.city.PerpetualConstruction
|
||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||
import com.unciv.ui.cityscreen.CityScreen
|
||||
import com.unciv.ui.trade.DiplomacyScreen
|
||||
import com.unciv.ui.utils.*
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Table(CameraStageBaseScreen.skin){
|
||||
val worldScreen = tileGroup.worldScreen
|
||||
@ -45,6 +48,12 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
||||
iconTable = getIconTable()
|
||||
add(iconTable).row()
|
||||
|
||||
if (city.civInfo.isCityState()) {
|
||||
val diplomacyManager = city.civInfo.getDiplomacyManager(worldScreen.viewingCiv)
|
||||
val influenceBar = getInfluenceBar(diplomacyManager.influence, diplomacyManager.relationshipLevel())
|
||||
add(influenceBar).row()
|
||||
}
|
||||
|
||||
pack()
|
||||
setOrigin(Align.center)
|
||||
centerX(tileGroup)
|
||||
@ -357,4 +366,63 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
||||
return group
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getInfluenceBar(influence: Float, relationshipLevel: RelationshipLevel, width: Float = 100f, height: Float = 5f): Table {
|
||||
val normalizedInfluence = max(-60f, min(influence, 60f)) / 30f
|
||||
|
||||
val color = when (relationshipLevel) {
|
||||
RelationshipLevel.Unforgivable -> Color.RED
|
||||
RelationshipLevel.Enemy -> Color.ORANGE
|
||||
RelationshipLevel.Neutral, RelationshipLevel.Friend -> Color.LIME
|
||||
RelationshipLevel.Ally -> Color.SKY
|
||||
else -> Color.DARK_GRAY
|
||||
}
|
||||
|
||||
val percentages = arrayListOf(0f, 0f, 0f, 0f)
|
||||
when {
|
||||
normalizedInfluence < -1f -> {
|
||||
percentages[0] = -normalizedInfluence - 1f
|
||||
percentages[1] = 1f
|
||||
}
|
||||
normalizedInfluence < 0f -> percentages[1] = -normalizedInfluence
|
||||
normalizedInfluence < 1f -> percentages[2] = normalizedInfluence
|
||||
else -> {
|
||||
percentages[2] = 1f
|
||||
percentages[3] = (normalizedInfluence - 1f)
|
||||
}
|
||||
}
|
||||
|
||||
fun getBarPiece(percentage: Float, color: Color, negative: Boolean): Table{
|
||||
val barPieceSize = width / 4f
|
||||
val barPiece = Table()
|
||||
val full = ImageGetter.getWhiteDot()
|
||||
val empty = ImageGetter.getWhiteDot()
|
||||
|
||||
full.color = color
|
||||
empty.color = Color.DARK_GRAY
|
||||
|
||||
if (negative) {
|
||||
barPiece.add(empty).size((1f - percentage) * barPieceSize, height)
|
||||
barPiece.add(full).size(percentage * barPieceSize, height)
|
||||
} else {
|
||||
barPiece.add(full).size(percentage * barPieceSize, height)
|
||||
barPiece.add(empty).size((1f - percentage) * barPieceSize, height)
|
||||
}
|
||||
|
||||
return barPiece
|
||||
}
|
||||
|
||||
val influenceBar = Table().apply {
|
||||
defaults().pad(1f)
|
||||
setSize(width, height)
|
||||
background = ImageGetter.getBackground(Color.BLACK)
|
||||
}
|
||||
|
||||
for (i in 0..3)
|
||||
influenceBar.add(getBarPiece(percentages[i], color, i < 2))
|
||||
|
||||
return influenceBar
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,7 @@ import com.unciv.logic.trade.TradeType
|
||||
import com.unciv.models.ruleset.ModOptionsConstants
|
||||
import com.unciv.models.ruleset.Quest
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.tilegroups.CityButton
|
||||
import com.unciv.ui.utils.*
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.roundToInt
|
||||
@ -391,7 +392,14 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
|
||||
else -> Color.RED
|
||||
}
|
||||
|
||||
relationshipTable.add(relationshipText.toLabel(relationshipColor))
|
||||
relationshipTable.add(relationshipText.toLabel(relationshipColor)).row()
|
||||
if (otherCivDiplomacyManager.civInfo.isCityState())
|
||||
relationshipTable.add(
|
||||
CityButton.getInfluenceBar(
|
||||
otherCivDiplomacyManager.influence,
|
||||
otherCivDiplomacyManager.relationshipLevel(),
|
||||
200f, 10f)
|
||||
).colspan(2).pad(5f)
|
||||
return relationshipTable
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,12 @@ import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||
import com.unciv.models.ruleset.Nation
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.stats.Stat
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
object ImageGetter {
|
||||
private const val whiteDotLocation = "OtherIcons/whiteDot"
|
||||
|
Reference in New Issue
Block a user