From d7214b7a46012acb8ca8146981994b1a12a3d9eb Mon Sep 17 00:00:00 2001 From: lishaoxia1985 <49801619+lishaoxia1985@users.noreply.github.com> Date: Tue, 16 Mar 2021 03:00:09 +0800 Subject: [PATCH] Method getImprovementIcon can Setsize for all icon (#3685) * Method getImprovementIcon can Setsize for all icon * categoryButton doesn't change background-color if it's disabled --- .../Simplified_Chinese.properties | 9 ++-- .../Traditional_Chinese.properties | 9 ++-- .../ui/overviewscreen/EmpireOverviewScreen.kt | 24 ++++------- .../com/unciv/ui/pickerscreens/TechButton.kt | 4 +- core/src/com/unciv/ui/utils/ImageGetter.kt | 42 +++++++++---------- 5 files changed, 35 insertions(+), 53 deletions(-) diff --git a/android/assets/jsons/translations/Simplified_Chinese.properties b/android/assets/jsons/translations/Simplified_Chinese.properties index 21ce6a0711..a4272a2b75 100644 --- a/android/assets/jsons/translations/Simplified_Chinese.properties +++ b/android/assets/jsons/translations/Simplified_Chinese.properties @@ -71,7 +71,7 @@ Not this time. = 这次不行,我只和有诚意的人交易。 Excellent! = 真是荣幸之至!互相尊重、平等互利是建立友好关系的第一步。 How about something else... = 谈判桌上的尔虞我诈才是我的兴趣所在。 A pleasure to meet you. = 很高兴见到你。 -Our relationship = 我们的关系: +Our relationship = 我们的关系 We have encountered the City-State of [name]! = 我们遇到了城邦[name]! Declare Friendship ([numberOfTurns] turns) = 宣布相互友善([numberOfTurns]回合) May our nations forever remain united! = 我们两个文明将永远肝胆相照、休戚与共地站在一起! @@ -91,7 +91,7 @@ Competitor = 瑜亮之争 Neutral = 泛泛之交 Favorable = 惺惺相惜 Friend = 秦晋之好 -Ally = 同盟: +Ally = 同盟 [questName] (+[influenceAmount] influence) = [questName](+[influenceAmount]影响力) [remainingTurns] turns remaining = 剩余[remainingTurns]回合 @@ -139,7 +139,7 @@ Cultured = 文化型 Maritime = 航海型 Mercantile = 商业型 Militaristic = 军事型 -Type = 城邦类型: +Type = 城邦类型 Friendly = 友善 Hostile = 敌视 Irrational = 无理 @@ -792,8 +792,7 @@ Requires = 需要 Menu = 游戏菜单 Brush Size = 笔刷大小 Map saved = 地图已保存 - # Requires translation! -Change map to fit selected ruleset? = +Change map to fit selected ruleset? = 要更改地图以适配已选规则集吗? # Civilopedia difficulty levels Player settings = 玩家设置 diff --git a/android/assets/jsons/translations/Traditional_Chinese.properties b/android/assets/jsons/translations/Traditional_Chinese.properties index 1775c39766..f7a3001d4b 100644 --- a/android/assets/jsons/translations/Traditional_Chinese.properties +++ b/android/assets/jsons/translations/Traditional_Chinese.properties @@ -71,7 +71,7 @@ Not this time. = 這次不行,我只和有誠意的人交易。 Excellent! = 真是榮幸之至!互相尊重、平等互利是建立友好關係的第一步。 How about something else... = 談判桌上的爾虞我詐才是我的興趣所在。 A pleasure to meet you. = 很高興見到你。 -Our relationship = 我們的關係: +Our relationship = 我們的關係 We have encountered the City-State of [name]! = 我們遇到了城邦[name]! Declare Friendship ([numberOfTurns] turns) = 宣佈相互友善([numberOfTurns]回合) May our nations forever remain united! = 我們兩個文明將永遠肝膽相照、休戚與共地站在一起! @@ -91,7 +91,7 @@ Competitor = 瑜亮之爭 Neutral = 泛泛之交 Favorable = 惺惺相惜 Friend = 秦晉之好 -Ally = 同盟: +Ally = 同盟 [questName] (+[influenceAmount] influence) = [questName](+[influenceAmount]影響力) [remainingTurns] turns remaining = 還剩[remainingTurns]回合 @@ -139,7 +139,7 @@ Cultured = 文化型 Maritime = 航海型 Mercantile = 商業型 Militaristic = 軍事型 -Type = 城邦類型: +Type = 城邦類型 Friendly = 友善 Hostile = 敵視 Irrational = 無理 @@ -792,8 +792,7 @@ Requires = 需要 Menu = 遊戲選單 Brush Size = 筆刷大小 Map saved = 地圖已保存 - # Requires translation! -Change map to fit selected ruleset? = +Change map to fit selected ruleset? = 要更改地圖以適配已選規則集嗎? # Civilopedia difficulty levels Player settings = 玩家設定 diff --git a/core/src/com/unciv/ui/overviewscreen/EmpireOverviewScreen.kt b/core/src/com/unciv/ui/overviewscreen/EmpireOverviewScreen.kt index 0efbb8ae54..e9ecee045e 100644 --- a/core/src/com/unciv/ui/overviewscreen/EmpireOverviewScreen.kt +++ b/core/src/com/unciv/ui/overviewscreen/EmpireOverviewScreen.kt @@ -30,19 +30,18 @@ class EmpireOverviewScreen(private var viewingPlayer:CivilizationInfo, defaultPa private val topTable = Table().apply { defaults().pad(10f) } private val centerTable = Table().apply { defaults().pad(5f) } - val setCategoryActions = HashMap Unit>() - val categoryButtons = HashMap() + private val setCategoryActions = HashMap Unit>() + private val categoryButtons = HashMap() - fun addCategory(name:String, table:Table, disabled:Boolean=false) { + private fun addCategory(name:String, table:Table, disabled:Boolean=false) { val button = name.toTextButton() val setCategoryAction = { centerTable.clear() centerTable.add(ScrollPane(table).apply { setOverscroll(false, false) }) .height(stage.height * 0.8f) centerTable.pack() - for ((key, categoryButton) in categoryButtons) - if (key == name) categoryButton.color = Color.BLUE - else categoryButton.color = Color.WHITE + for ((key, categoryButton) in categoryButtons.filterNot { it.value.touchable == Touchable.disabled }) + categoryButton.color = if (key == name) Color.BLUE else Color.WHITE } setCategoryActions[name] = setCategoryAction categoryButtons[name] = button @@ -167,19 +166,10 @@ class EmpireOverviewScreen(private var viewingPlayer:CivilizationInfo, defaultPa } } - -// -// private fun setStats() { -// -// centerTable.clear() -// centerTable.add(ScrollPane()) -// centerTable.pack() -// } - private fun getTradesTable(): Table { val tradesTable = Table().apply { defaults().pad(10f) } val diplomacies = viewingPlayer.diplomacy.values.filter { it.trades.isNotEmpty() } - .sortedWith(Comparator { d0, d1 -> + .sortedWith { d0, d1 -> val d0offers = d0.trades.first().ourOffers val d1offers = d1.trades.first().ourOffers val d0max = if (d0offers.isEmpty()) 0 else d0offers.maxBy { it.duration }!!.duration @@ -189,7 +179,7 @@ class EmpireOverviewScreen(private var viewingPlayer:CivilizationInfo, defaultPa d0max == d1max -> 0 else -> -1 } - }) + } for(diplomacy in diplomacies) { for (trade in diplomacy.trades) tradesTable.add(createTradeTable(trade, diplomacy.otherCiv())).row() diff --git a/core/src/com/unciv/ui/pickerscreens/TechButton.kt b/core/src/com/unciv/ui/pickerscreens/TechButton.kt index ed7c7608b2..25441a9c3a 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechButton.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechButton.kt @@ -68,9 +68,7 @@ class TechButton(techName:String, private val techManager: TechManager, isWorldS || it.uniqueObjects.any { it.placeholderText == "[] once [] is discovered" && it.params[1] == techName } } .filter { it.uniqueTo == null || it.uniqueTo == civName }) - if (improvement.name.startsWith("Remove")) - techEnabledIcons.add(ImageGetter.getImage("OtherIcons/Stop")).size(techIconSize) - else techEnabledIcons.add(ImageGetter.getImprovementIcon(improvement.name, techIconSize)) + techEnabledIcons.add(ImageGetter.getImprovementIcon(improvement.name, techIconSize)) for (resource in ruleset.tileResources.values.filter { it.revealedBy == techName }) diff --git a/core/src/com/unciv/ui/utils/ImageGetter.kt b/core/src/com/unciv/ui/utils/ImageGetter.kt index f1ebf78fef..433f47ac0a 100644 --- a/core/src/com/unciv/ui/utils/ImageGetter.kt +++ b/core/src/com/unciv/ui/utils/ImageGetter.kt @@ -15,13 +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.Stats -import kotlin.math.max -import kotlin.math.min +import kotlin.math.atan2 +import kotlin.math.sqrt object ImageGetter { private const val whiteDotLocation = "OtherIcons/whiteDot" @@ -36,7 +35,7 @@ object ImageGetter { // We then shove all the drawables into a hashmap, because the atlas specifically tells us // that the search on it is inefficient - val textureRegionDrawables = HashMap() + private val textureRegionDrawables = HashMap() init { reload() @@ -152,8 +151,8 @@ object ImageGetter { } fun getDrawable(fileName: String): TextureRegionDrawable { - if (textureRegionDrawables.containsKey(fileName)) return textureRegionDrawables[fileName]!! - else return textureRegionDrawables[whiteDotLocation]!! + return if (textureRegionDrawables.containsKey(fileName)) textureRegionDrawables[fileName]!! + else textureRegionDrawables[whiteDotLocation]!! } fun getRoundedEdgeTableBackground(tintColor: Color? = null): NinePatchDrawable { @@ -179,27 +178,25 @@ object ImageGetter { fun getNationIndicator(nation: Nation, size: Float): IconCircleGroup { val civIconName = if (nation.isCityState()) "CityState" else nation.name - if (nationIconExists(civIconName)) { + return if (nationIconExists(civIconName)) { val cityStateIcon = getNationIcon(civIconName) cityStateIcon.color = nation.getInnerColor() - return cityStateIcon.surroundWithCircle(size * 0.9f).apply { circle.color = nation.getOuterColor() } + cityStateIcon.surroundWithCircle(size * 0.9f).apply { circle.color = nation.getOuterColor() } .surroundWithCircle(size, false).apply { circle.color = nation.getInnerColor() } - } else { - return getCircle().apply { color = nation.getOuterColor() } - .surroundWithCircle(size).apply { circle.color = nation.getInnerColor() } - } + else getCircle().apply { color = nation.getOuterColor() } + .surroundWithCircle(size).apply { circle.color = nation.getInnerColor() } } - fun nationIconExists(nation: String) = imageExists("NationIcons/$nation") + private fun nationIconExists(nation: String) = imageExists("NationIcons/$nation") fun getNationIcon(nation: String) = getImage("NationIcons/$nation") val foodCircleColor = colorFromRGB(129, 199, 132) - val productionCircleColor = Color.BROWN.cpy().lerp(Color.WHITE, 0.5f)!! - val goldCircleColor = Color.GOLD.cpy().lerp(Color.WHITE, 0.5f)!! - val cultureCircleColor = Color.PURPLE.cpy().lerp(Color.WHITE, 0.5f)!! - val scienceCircleColor = Color.BLUE.cpy().lerp(Color.WHITE, 0.5f)!! - fun getColorFromStats(stats: Stats) = when { + private val productionCircleColor = Color.BROWN.cpy().lerp(Color.WHITE, 0.5f) + private val goldCircleColor = Color.GOLD.cpy().lerp(Color.WHITE, 0.5f) + private val cultureCircleColor = Color.PURPLE.cpy().lerp(Color.WHITE, 0.5f) + private val scienceCircleColor = Color.BLUE.cpy().lerp(Color.WHITE, 0.5f) + private fun getColorFromStats(stats: Stats) = when { stats.food > 0 -> foodCircleColor stats.production > 0 -> productionCircleColor stats.gold > 0 -> goldCircleColor @@ -211,7 +208,7 @@ object ImageGetter { fun getImprovementIcon(improvementName: String, size: Float = 20f): Actor { if (improvementName.startsWith("Remove") || improvementName == Constants.cancelImprovementOrder) - return getImage("OtherIcons/Stop") + return Table().apply { add(getImage("OtherIcons/Stop")).size(size) } if (improvementName.startsWith("StartingLocation ")) { val nationName = improvementName.removePrefix("StartingLocation ") val nation = ruleset.nations[nationName]!! @@ -277,8 +274,7 @@ object ImageGetter { fun getResourceImage(resourceName: String, size: Float): Actor { val iconGroup = getImage("ResourceIcons/$resourceName").surroundWithCircle(size) - val resource = ruleset.tileResources[resourceName] - if (resource == null) return iconGroup // This is the result of a bad modding setup, just give em an empty circle. Their problem. + val resource = ruleset.tileResources[resourceName] ?: return iconGroup // This is the result of a bad modding setup, just give em an empty circle. Their problem. iconGroup.circle.color = getColorFromStats(resource) if (resource.resourceType == ResourceType.Luxury) { @@ -356,13 +352,13 @@ object ImageGetter { val line = getWhiteDot() val deltaX = (startX - endX).toDouble() val deltaY = (startY - endY).toDouble() - line.width = Math.sqrt(deltaX * deltaX + deltaY * deltaY).toFloat() + line.width = 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() + line.rotation = (atan2(deltaY, deltaX) * radiansToDegrees).toFloat() // C line.x = (startX + endX) / 2 - line.width / 2