diff --git a/build.gradle b/build.gradle index f32a1186..224a1227 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { - ext.kotlinVersion = '1.2.31' + ext.kotlinVersion = '1.2.41' dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 8b699e39..0c9ee857 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -69,7 +69,7 @@ class Battle(val gameInfo:GameInfo) { private fun getHealthDependantDamageRatio(combatant: ICombatant): Float { if (combatant.getUnitType() == UnitType.City) return 1f - return 1 / 2f + combatant.getHealth() / 200f // Each point of health reduces damage dealt by 0.5% + return 1/2f + combatant.getHealth()/200f // Each point of health reduces damage dealt by 0.5% } diff --git a/core/src/com/unciv/logic/battle/CityCombatant.kt b/core/src/com/unciv/logic/battle/CityCombatant.kt index 59e74c98..5e3fca08 100644 --- a/core/src/com/unciv/logic/battle/CityCombatant.kt +++ b/core/src/com/unciv/logic/battle/CityCombatant.kt @@ -39,7 +39,7 @@ class CityCombatant(val city: CityInfo) : ICombatant { // 10% bonus foreach pop val strengthWithPop = (baseStrength + strengthFromTechs) * (1 + 0.1*city.population.population) - return strengthWithPop.toInt() * 100 // *100 because a city is always at 100% strength + return strengthWithPop.toInt() } override fun toString(): String {return city.name} // for debug diff --git a/core/src/com/unciv/logic/battle/MapUnitCombatant.kt b/core/src/com/unciv/logic/battle/MapUnitCombatant.kt index 7015f4da..1b014018 100644 --- a/core/src/com/unciv/logic/battle/MapUnitCombatant.kt +++ b/core/src/com/unciv/logic/battle/MapUnitCombatant.kt @@ -18,15 +18,12 @@ class MapUnitCombatant(val unit: MapUnit) : ICombatant { } override fun getAttackingStrength(defender: ICombatant): Int { - val attackerStrength: Int - if (isRanged()) attackerStrength = unit.getBaseUnit().rangedStrength - else attackerStrength = unit.getBaseUnit().strength - return attackerStrength*unit.health + if (isRanged()) return unit.getBaseUnit().rangedStrength + else return unit.getBaseUnit().strength } override fun getDefendingStrength(attacker: ICombatant): Int { - // too: if ranged units get ranged attacked, they use their ranged str to defend! - return unit.getBaseUnit().strength*unit.health + return unit.getBaseUnit().strength } override fun getUnitType(): UnitType { diff --git a/core/src/com/unciv/models/gamebasics/Civilization.kt b/core/src/com/unciv/models/gamebasics/Civilization.kt index 4a953a99..6cd3f69e 100644 --- a/core/src/com/unciv/models/gamebasics/Civilization.kt +++ b/core/src/com/unciv/models/gamebasics/Civilization.kt @@ -2,13 +2,13 @@ package com.unciv.models.gamebasics import com.badlogic.gdx.graphics.Color import com.unciv.models.stats.INamed -import com.unciv.ui.utils.fromRGB +import com.unciv.ui.utils.colorFromRGB class Civilization : INamed { override lateinit var name: String lateinit var RGB: List fun getColor(): Color { - return Color().fromRGB(RGB[0],RGB[1],RGB[2]) + return colorFromRGB(RGB[0], RGB[1], RGB[2]) } lateinit var cities: List } diff --git a/core/src/com/unciv/ui/cityscreen/CityScreen.kt b/core/src/com/unciv/ui/cityscreen/CityScreen.kt index 65c0e662..1bf5b186 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreen.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreen.kt @@ -11,6 +11,7 @@ import com.unciv.logic.map.TileInfo import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.HexMath import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.centerX import java.util.* class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() { @@ -137,7 +138,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() { cityPickerTable.add(nextCityButton) } cityPickerTable.pack() - cityPickerTable.setPosition(stage.width / 2 - cityPickerTable.width / 2, 0f) + cityPickerTable.centerX(stage) stage.addActor(cityPickerTable) } diff --git a/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt b/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt index 3e821674..4af17c43 100644 --- a/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt +++ b/core/src/com/unciv/ui/cityscreen/CityTileGroup.kt @@ -6,6 +6,8 @@ import com.unciv.logic.city.CityInfo import com.unciv.logic.map.TileInfo import com.unciv.ui.tilegroups.TileGroup import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.center +import com.unciv.ui.utils.centerX class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo) : TileGroup(tileInfo) { @@ -25,8 +27,8 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo) : TileGroup( updateUnitImage(true) if(unitImage!=null) { - unitImage!!.setPosition(width / 2 - unitImage!!.width / 2 + 20, - height / 2 - unitImage!!.height / 2 + 20) // top + unitImage!!.center(this) + unitImage!!.y += 20 // top } updatePopulationImage() @@ -40,7 +42,8 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo) : TileGroup( yieldGroup.setOrigin(Align.center) yieldGroup.setScale(0.7f) yieldGroup.toFront() - yieldGroup.setPosition(width / 2 - yieldGroup.width / 2, height * 0.25f - yieldGroup.height / 2) + yieldGroup.centerX(this) + yieldGroup.y= height * 0.25f - yieldGroup.height / 2 } private fun updatePopulationImage() { @@ -57,4 +60,4 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo) : TileGroup( } -} +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index f202bc6c..759b67d4 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -8,7 +8,8 @@ import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.TileInfo import com.unciv.ui.utils.HexMath import com.unciv.ui.utils.ImageGetter -import com.unciv.ui.utils.fromRGB +import com.unciv.ui.utils.center +import com.unciv.ui.utils.colorFromRGB open class TileGroup(var tileInfo: TileInfo) : Group() { @@ -34,8 +35,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { private fun addCircleImage() { circleImage.width = 50f circleImage.height = 50f - circleImage.setPosition(width / 2 - circleImage.width / 2, - height / 2 - circleImage.height / 2) + circleImage.center(this) addActor(circleImage) circleImage.isVisible = false } @@ -44,8 +44,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { val imageScale = groupSize * 1.5f / hexagon.width hexagon.setScale(imageScale) hexagon.setOrigin(Align.center) - hexagon.setPosition((width - hexagon.width) / 2, - (height - hexagon.height) / 2) + hexagon.center(this) hexagon.zIndex = 0 addActor(hexagon) } @@ -54,8 +53,8 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { populationImage = ImageGetter.getImage("StatIcons/populationGreen.png") populationImage!!.run { setSize(20f, 20f) - setPosition(this@TileGroup.width/2 - width/2, - this@TileGroup.height/2 - height/2 - 20) + center(this@TileGroup) + y -= 20 } // top left addActor(populationImage) } @@ -98,8 +97,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { for(i in -2..2) { val image = ImageGetter.getImage("UnitIcons/Circle.png") image.setSize(5f, 5f) - image.moveBy(width / 2 - image.width / 2, // center - height / 2 - image.height / 2) + image.center(this) // in addTiles, we set the position of groups by relative world position *0.8*groupSize, filter groupSize = 50 // Here, we want to have the borders start HALFWAY THERE and extend towards the tiles, so we give them a position of 0.8*25. // BUT, we don't actually want it all the way out there, because we want to display the borders of 2 different civs! @@ -113,8 +111,6 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { image.moveBy(relativeWorldPosition.y*i * 4, -relativeWorldPosition.x*i * 4) image.color = tileInfo.getOwner()!!.getCivilization().getColor() - //image.setOrigin(image.width / 2, image.height / 2) // This is so that the rotation is calculated from the middle of the road and not the edge - //image.rotation = (90 + 180 / Math.PI * Math.atan2(relativeWorldPosition.y.toDouble(), relativeWorldPosition.x.toDouble())).toFloat() addActor(image) borderImages.add(image) } @@ -157,7 +153,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { private fun updateTileColor(isViewable: Boolean) { val RGB = tileInfo.getBaseTerrain().RGB!! - hexagon.color = Color().fromRGB(RGB[0], RGB[1],RGB[2]) + hexagon.color = colorFromRGB(RGB[0], RGB[1], RGB[2]) if (!isViewable) hexagon.color = hexagon.color.lerp(Color.BLACK, 0.6f) } @@ -168,8 +164,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { terrainFeatureImage!!.run { setSize(30f, 30f) setColor(1f, 1f, 1f, 0.5f) - setPosition(this@TileGroup.width / 2 - width / 2, - this@TileGroup.height / 2 - height / 2) + center(this@TileGroup) } } @@ -185,9 +180,8 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { addActor(improvementImage) improvementImage!!.run { setSize(20f, 20f) - - setPosition(this@TileGroup.width / 2 - width / 2 + 20f, - this@TileGroup.height / 2 - height / 2) // right + center(this@TileGroup) + this.x+=20 // right } improvementType = tileInfo.improvement } @@ -198,8 +192,8 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { val fileName = "ResourceIcons/" + tileInfo.resource + "_(Civ5).png" resourceImage = ImageGetter.getImage(fileName) resourceImage!!.setSize(20f, 20f) - resourceImage!!.setPosition(width / 2 - resourceImage!!.width / 2 - 20f, - height / 2 - resourceImage!!.height / 2) // left + resourceImage!!.center(this) + resourceImage!!.x -= 20 // left addActor(resourceImage!!) } } @@ -239,8 +233,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() { setSize(background.width,background.height) addActor(background) } - unitBaseImage.setPosition(group.width/2-unitBaseImage.width/2, - group.height/2-unitBaseImage.height/2) + unitBaseImage.center(group) group.addActor(unitBaseImage) return group } diff --git a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt index 2367a92f..a3516156 100644 --- a/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/WorldTileGroup.kt @@ -10,6 +10,7 @@ import com.unciv.ui.cityscreen.CityScreen import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.center class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { @@ -18,8 +19,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { fun addWhiteCircleAroundUnit(){ val whiteCircle = ImageGetter.getImage("UnitIcons/Circle.png") whiteCircle.setSize(25f,25f) - whiteCircle.setPosition(unitImage!!.width/2 - whiteCircle.width/2, - unitImage!!.height/2 - whiteCircle.height/2) + whiteCircle.center(unitImage!!) unitImage!!.addActor(whiteCircle) whiteCircle.toBack() } @@ -38,8 +38,8 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { updateCityButton(city) updateUnitImage(isViewable) if(unitImage!=null) { - unitImage!!.setPosition(width / 2 - unitImage!!.width / 2, - height / 2 - unitImage!!.height / 2 + 20) // top + unitImage!!.center(this) + unitImage!!.y += 20 // top } } @@ -72,8 +72,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) { toFront() } - cityButton!!.setPosition(width / 2 - cityButton!!.width / 2, - height / 2 - cityButton!!.height / 2) + cityButton!!.center(this) } } diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 4b6a5143..242063e6 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.* @@ -81,8 +82,7 @@ open class CameraStageBaseScreen : Screen { } tutorialTable.add(button).pad(10f) tutorialTable.pack() - tutorialTable.setPosition(stage.width / 2 - tutorialTable.width / 2, - stage.height / 2 - tutorialTable.height / 2) + tutorialTable.center(stage) stage.addActor(tutorialTable) } @@ -105,6 +105,14 @@ fun Button.enable() { fun List.getRandom(): E = if (size == 0) throw Exception() else get((Math.random() * size).toInt()) -fun Color.fromRGB(r:Int,g:Int,b:Int): Color { +fun colorFromRGB(r: Int, g: Int, b: Int): Color { return Color(r/255f, g/255f, b/255f, 1f) -} \ No newline at end of file +} + +fun Actor.centerX(parent:Actor){ x = parent.width/2 - width/2 } +fun Actor.centerY(parent:Actor){ y = parent.height/2- height/2} +fun Actor.center(parent:Actor){ centerX(parent); centerY(parent)} + +fun Actor.centerX(parent:Stage){ x = parent.width/2 - width/2 } +fun Actor.centerY(parent:Stage){ y = parent.height/2- height/2} +fun Actor.center(parent:Stage){ centerX(parent); centerY(parent)} diff --git a/core/src/com/unciv/ui/worldscreen/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/BattleTable.kt index 437d0b7d..cb0fb4e4 100644 --- a/core/src/com/unciv/ui/worldscreen/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/BattleTable.kt @@ -13,6 +13,7 @@ import com.unciv.logic.map.UnitType import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.centerX import com.unciv.ui.utils.disable import kotlin.math.max @@ -70,8 +71,8 @@ class BattleTable(val worldScreen: WorldScreen): Table() { row().pad(5f) - add("Strength: "+attacker.getAttackingStrength(defender)/100f) - add("Strength: "+defender.getDefendingStrength(attacker)/100f) + add("Strength: "+attacker.getAttackingStrength(defender)) + add("Strength: "+defender.getDefendingStrength(attacker)) row().pad(5f) val attackerModifiers = battle.getAttackModifiers(attacker,defender) .map { it.key+": "+(if(it.value>0)"+" else "")+(it.value*100).toInt()+"%" } @@ -82,8 +83,8 @@ class BattleTable(val worldScreen: WorldScreen): Table() { if (defenderModifiers.size > i) add(defenderModifiers[i]) else add() row().pad(5f) } - add((battle.getAttackingStrength(attacker,defender)/100f).toString()) - add((battle.getDefendingStrength(attacker,defender)/100f).toString()) + add(battle.getAttackingStrength(attacker,defender).toString()) + add(battle.getDefendingStrength(attacker,defender).toString()) row().pad(5f) var damageToDefender = battle.calculateDamageToDefender(attacker,defender) diff --git a/core/src/com/unciv/ui/worldscreen/CivStatsTable.kt b/core/src/com/unciv/ui/worldscreen/CivStatsTable.kt index 26a4a0cd..4806ef15 100644 --- a/core/src/com/unciv/ui/worldscreen/CivStatsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/CivStatsTable.kt @@ -9,7 +9,8 @@ import com.unciv.models.gamebasics.ResourceType import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter -import com.unciv.ui.utils.fromRGB +import com.unciv.ui.utils.centerY +import com.unciv.ui.utils.colorFromRGB import kotlin.math.ceil class CivStatsTable(val screen: WorldScreen) : Table() { @@ -18,10 +19,10 @@ class CivStatsTable(val screen: WorldScreen) : Table() { .apply { fontColor = Color.valueOf("f5f5f5ff") } private val turnsLabel = Label("Turns: 0/400", labelStyle) - private val goldLabel = Label("Gold:",labelStyle).apply { color = Color().fromRGB(225,217,71) } - private val scienceLabel = Label("Science:",labelStyle).apply { color = Color().fromRGB(78,140,151) } + private val goldLabel = Label("Gold:",labelStyle).apply { color = colorFromRGB(225, 217, 71) } + private val scienceLabel = Label("Science:",labelStyle).apply { color = colorFromRGB(78, 140, 151) } private val happinessLabel = Label("Happiness:",labelStyle) - private val cultureLabel = Label("Culture:",labelStyle).apply { color = Color().fromRGB(210,94,210) } + private val cultureLabel = Label("Culture:",labelStyle).apply { color = colorFromRGB(210, 94, 210) } private val resourceLabels = HashMap() private val resourceImages = HashMap() private val happinessImage = ImageGetter.getStatIcon("Happiness") @@ -84,7 +85,7 @@ class CivStatsTable(val screen: WorldScreen) : Table() { menuButton.addClickListener { screen.optionsTable.isVisible = !screen.optionsTable.isVisible } - menuButton.y = this.height/2-menuButton.height/2 + menuButton.centerY(this) menuButton.x = menuButton.y return menuButton } @@ -126,7 +127,7 @@ class CivStatsTable(val screen: WorldScreen) : Table() { happinessImage.drawable = ImageGetter.getStatIcon("Malcontent").drawable } else{ - happinessLabel.color = Color().fromRGB(92,194,77) + happinessLabel.color = colorFromRGB(92, 194, 77) happinessImage.drawable = ImageGetter.getStatIcon("Happiness").drawable } diff --git a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt index 80326d2f..ebddb708 100644 --- a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt @@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.InputEvent import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener +import com.badlogic.gdx.utils.Align import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileMap @@ -13,7 +14,7 @@ import com.unciv.logic.map.UnitType import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.tilegroups.WorldTileGroup import com.unciv.ui.utils.HexMath -import com.unciv.ui.utils.fromRGB +import com.unciv.ui.utils.colorFromRGB class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: TileMap, internal val civInfo: CivilizationInfo) : ScrollPane(null) { internal var selectedTile: TileInfo? = null @@ -63,7 +64,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: widget = allTiles setFillParent(true) - setOrigin(worldScreen.stage.width / 2, worldScreen.stage.height / 2) + setOrigin(Align.center) setSize(worldScreen.stage.width, worldScreen.stage.height) addListener(object : ActorGestureListener() { var lastScale = 1f @@ -110,10 +111,10 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: } for(tile: TileInfo in unit.getDistanceToTiles().keys) - tileGroups[tile]!!.showCircle(Color().fromRGB(0,120,215)) + tileGroups[tile]!!.showCircle(colorFromRGB(0, 120, 215)) for (tile in attackableTiles.filter { it.unit!=null && it.unit!!.owner != unit.owner && civViewableTiles.contains(it)}) - tileGroups[tile]!!.showCircle(Color().fromRGB(237,41,57)) + tileGroups[tile]!!.showCircle(colorFromRGB(237, 41, 57)) } if(selectedTile!=null) diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/WorldScreenOptionsTable.kt index e66edd7a..82240983 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreenOptionsTable.kt @@ -12,6 +12,7 @@ import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.pickerscreens.PolicyPickerScreen import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter +import com.unciv.ui.utils.center class WorldScreenOptionsTable internal constructor(worldScreen: WorldScreen, private val civInfo: CivilizationInfo) : Table() { @@ -67,7 +68,6 @@ class WorldScreenOptionsTable internal constructor(worldScreen: WorldScreen, pri add(closeButton) pack() // Needed to show the background. - setPosition(worldScreen.stage.width / 2 - width / 2, - worldScreen.stage.height / 2 - height / 2) + center(worldScreen.stage) } }