mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
Added Diplomacy overview!
This commit is contained in:
parent
44d5017f6f
commit
5d56b930c1
@ -7,7 +7,7 @@ import kotlin.math.max
|
|||||||
|
|
||||||
class HexMath {
|
class HexMath {
|
||||||
|
|
||||||
private fun getVectorForAngle(angle: Float): Vector2 {
|
fun getVectorForAngle(angle: Float): Vector2 {
|
||||||
return Vector2(Math.sin(angle.toDouble()).toFloat(), Math.cos(angle.toDouble()).toFloat())
|
return Vector2(Math.sin(angle.toDouble()).toFloat(), Math.cos(angle.toDouble()).toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package com.unciv.ui
|
package com.unciv.ui
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Group
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.UnCivGame
|
import com.unciv.UnCivGame
|
||||||
|
import com.unciv.logic.HexMath
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
|
import com.unciv.logic.civilization.DiplomaticStatus
|
||||||
import com.unciv.logic.trade.Trade
|
import com.unciv.logic.trade.Trade
|
||||||
import com.unciv.logic.trade.TradeOffersList
|
import com.unciv.logic.trade.TradeOffersList
|
||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
@ -66,6 +71,16 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
|||||||
}
|
}
|
||||||
topTable.add(setUnitsButton )
|
topTable.add(setUnitsButton )
|
||||||
|
|
||||||
|
|
||||||
|
val setDiplomacyButton = TextButton("Diplomacy".tr(),skin)
|
||||||
|
setDiplomacyButton.onClick {
|
||||||
|
centerTable.clear()
|
||||||
|
centerTable.add(createDiplomacyGroup()).height(stage.height*0.8f)
|
||||||
|
centerTable.pack()
|
||||||
|
centerTable.center(stage)
|
||||||
|
}
|
||||||
|
topTable.add(setDiplomacyButton )
|
||||||
|
|
||||||
topTable.pack()
|
topTable.pack()
|
||||||
topTable.width = stage.width
|
topTable.width = stage.width
|
||||||
topTable.y = stage.height-topTable.height
|
topTable.y = stage.height-topTable.height
|
||||||
@ -258,4 +273,49 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){
|
|||||||
table.pack()
|
table.pack()
|
||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createDiplomacyGroup(): Group {
|
||||||
|
val relevantCivs = civInfo.gameInfo.civilizations.filter { !it.isBarbarianCivilization() }
|
||||||
|
val groupSize = 500f
|
||||||
|
val group = Group()
|
||||||
|
group.setSize(groupSize,groupSize)
|
||||||
|
val civGroups = HashMap<CivilizationInfo,Actor>()
|
||||||
|
for(i in 0 until relevantCivs.size){
|
||||||
|
val civ = relevantCivs[i]
|
||||||
|
|
||||||
|
|
||||||
|
val civGroup = Table()
|
||||||
|
civGroup.background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
|
||||||
|
.tint(civ.getNation().getColor())
|
||||||
|
val label = Label(civ.civName, CameraStageBaseScreen.skin)
|
||||||
|
label.setFontColor(civ.getNation().getSecondaryColor())
|
||||||
|
civGroup.add(label).pad(10f)
|
||||||
|
civGroup.pack()
|
||||||
|
|
||||||
|
val vector = HexMath().getVectorForAngle(2 * Math.PI.toFloat() *i / relevantCivs.size)
|
||||||
|
civGroup.center(group)
|
||||||
|
civGroup.moveBy(vector.x*groupSize/3, vector.y*groupSize/3)
|
||||||
|
|
||||||
|
civGroups[civ]=civGroup
|
||||||
|
group.addActor(civGroup)
|
||||||
|
}
|
||||||
|
|
||||||
|
for(civ in relevantCivs)
|
||||||
|
for(diplomacy in civ.diplomacy.values.filter { !it.otherCiv().isBarbarianCivilization() }){
|
||||||
|
val civGroup = civGroups[civ]!!
|
||||||
|
val otherCivGroup = civGroups[diplomacy.otherCiv()]!!
|
||||||
|
|
||||||
|
val statusLine = ImageGetter.getLine(civGroup.x+civGroup.width/2,civGroup.y+civGroup.height/2,
|
||||||
|
otherCivGroup.x+otherCivGroup.width/2,otherCivGroup.y+otherCivGroup.height/2,3f)
|
||||||
|
|
||||||
|
statusLine.color = if(diplomacy.diplomaticStatus==DiplomaticStatus.War) Color.RED
|
||||||
|
else Color.GREEN
|
||||||
|
|
||||||
|
group.addActor(statusLine)
|
||||||
|
statusLine.toBack()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return group
|
||||||
|
}
|
||||||
}
|
}
|
@ -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.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
|
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
|
||||||
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
import com.unciv.models.gamebasics.tile.ResourceType
|
import com.unciv.models.gamebasics.tile.ResourceType
|
||||||
|
|
||||||
@ -163,4 +164,30 @@ object ImageGetter {
|
|||||||
healthBar.pack()
|
healthBar.pack()
|
||||||
return healthBar
|
return healthBar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getLine(startX:Float,startY:Float,endX:Float,endY:Float, width:Float): Image {
|
||||||
|
/** The simplest way to draw a line between 2 points seems to be:
|
||||||
|
* A. Get a pixel dot, set its width to the required length (hypotenuse)
|
||||||
|
* B. Set its rotational center, and set its rotation
|
||||||
|
* C. Center it on the point where you want its center to be
|
||||||
|
*/
|
||||||
|
|
||||||
|
// A
|
||||||
|
val line = getWhiteDot()
|
||||||
|
val deltaX = (startX-endX).toDouble()
|
||||||
|
val deltaY = (startY-endY).toDouble()
|
||||||
|
line.width = Math.sqrt(deltaX*deltaX+deltaY*deltaY).toFloat()
|
||||||
|
line.height = width // the width of the line, is the height of the
|
||||||
|
|
||||||
|
// B
|
||||||
|
line.setOrigin(Align.center)
|
||||||
|
val radiansToDegrees = 180 / Math.PI
|
||||||
|
line.rotation = (Math.atan2(deltaY, deltaX) * radiansToDegrees).toFloat()
|
||||||
|
|
||||||
|
// C
|
||||||
|
line.x = (startX+endX)/2 - line.width/2
|
||||||
|
line.y = (startY+endY)/2 - line.height/2
|
||||||
|
|
||||||
|
return line
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user