mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-10 07:48:31 +07:00
Unit icon alpha control (#7343)
* Unit icon alpha/size control Implemented sliders in Options -> Display to give user control over unit icon opacity and size. * Simplified sliders and re-added idle 50% transparency * Minor fixes from PR review * Removed unit icon size adjustment
This commit is contained in:

committed by
GitHub

parent
8203557633
commit
716d5d3214
@ -697,6 +697,7 @@ Show pixel units =
|
||||
Show pixel improvements =
|
||||
Enable Nuclear Weapons =
|
||||
Experimental Demographics scoreboard =
|
||||
Unit icon opacity =
|
||||
Show zoom buttons in world screen =
|
||||
Enable display cutout (requires restart) =
|
||||
Show tile yields =
|
||||
|
@ -45,6 +45,7 @@ class GameSettings {
|
||||
|
||||
var showMinimap: Boolean = true
|
||||
var minimapSize: Int = 6 // default corresponds to 15% screen space
|
||||
var unitIconOpacity = 1f // default corresponds to fully opaque
|
||||
var showPixelUnits: Boolean = true
|
||||
var showPixelImprovements: Boolean = true
|
||||
var continuousRendering = false
|
||||
|
@ -42,6 +42,8 @@ fun displayTab(
|
||||
|
||||
addMinimapSizeSlider(this, settings, optionsPopup.selectBoxMinWidth)
|
||||
|
||||
addUnitIconAlphaSlider(this, settings, optionsPopup.selectBoxMinWidth)
|
||||
|
||||
addResolutionSelectBox(this, settings, optionsPopup.selectBoxMinWidth, onResolutionChange)
|
||||
|
||||
addTileSetSelectBox(this, settings, optionsPopup.selectBoxMinWidth, onTilesetChange)
|
||||
@ -94,6 +96,25 @@ private fun addMinimapSizeSlider(table: Table, settings: GameSettings, selectBox
|
||||
table.add(minimapSlider).minWidth(selectBoxMinWidth).pad(10f).row()
|
||||
}
|
||||
|
||||
private fun addUnitIconAlphaSlider(table: Table, settings: GameSettings, selectBoxMinWidth: Float) {
|
||||
table.add("Unit icon opacity".toLabel()).left().fillX()
|
||||
|
||||
val getTipText: (Float) -> String = {"%.0f".format(it*100) + "%"}
|
||||
|
||||
val unitIconAlphaSlider = UncivSlider(
|
||||
0f, 1f, 0.1f, initial = settings.unitIconOpacity, getTipText = getTipText
|
||||
) {
|
||||
settings.unitIconOpacity = it
|
||||
settings.save()
|
||||
|
||||
val worldScreen = UncivGame.Current.getWorldScreenIfActive()
|
||||
if (worldScreen != null)
|
||||
worldScreen.shouldUpdate = true
|
||||
|
||||
}
|
||||
table.add(unitIconAlphaSlider).minWidth(selectBoxMinWidth).pad(10f).row()
|
||||
}
|
||||
|
||||
private fun addResolutionSelectBox(table: Table, settings: GameSettings, selectBoxMinWidth: Float, onResolutionChange: () -> Unit) {
|
||||
table.add("Resolution".toLabel()).left().fillX()
|
||||
|
||||
|
@ -66,6 +66,7 @@ class TileGroupIcons(val tileGroup: TileGroup) {
|
||||
|
||||
if (unit != null && isViewable) { // Tile is visible
|
||||
newImage = UnitGroup(unit, 25f)
|
||||
|
||||
if (UncivGame.Current.settings.continuousRendering && oldUnitGroup?.blackSpinningCircle != null) {
|
||||
newImage.blackSpinningCircle = ImageGetter.getCircle()
|
||||
.apply { rotation = oldUnitGroup.blackSpinningCircle!!.rotation }
|
||||
@ -99,13 +100,18 @@ class TileGroupIcons(val tileGroup: TileGroup) {
|
||||
newImage.addActor(holder)
|
||||
}
|
||||
|
||||
newImage.unitBaseImage.color.a = UncivGame.Current.settings.unitIconOpacity //0f (invisible) to 1f (fully opaque)
|
||||
newImage.actionGroup?.color?.a = UncivGame.Current.settings.unitIconOpacity //0f (invisible) to 1f (fully opaque)
|
||||
|
||||
// Instead of fading out the entire unit with its background, we just fade out its central icon,
|
||||
// that way it remains much more visible on the map
|
||||
if (!unit.isIdle() && unit.civInfo == viewingCiv) {
|
||||
newImage.unitBaseImage.color.a = 0.5f
|
||||
newImage.actionGroup?.color?.a = 0.5f
|
||||
newImage.unitBaseImage.color.a *= 0.5f
|
||||
newImage.actionGroup?.color?.a = 0.5f * UncivGame.Current.settings.unitIconOpacity
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return newImage
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,13 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
||||
var actionGroup :Group? = null
|
||||
val unitBaseImage = ImageGetter.getUnitIcon(unit.name, unit.civInfo.nation.getInnerColor())
|
||||
.apply { setSize(size * 0.75f, size * 0.75f) }
|
||||
var background: Image? = null
|
||||
|
||||
init {
|
||||
val background = getBackgroundImageForUnit()
|
||||
background.apply {
|
||||
background = getBackgroundImageForUnit()
|
||||
background?.apply {
|
||||
this.color = unit.civInfo.nation.getOuterColor()
|
||||
this.color.a = UncivGame.Current.settings.unitIconOpacity
|
||||
setSize(size, size)
|
||||
}
|
||||
setSize(size, size)
|
||||
@ -68,6 +70,11 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
||||
|
||||
|
||||
fun selectUnit() {
|
||||
|
||||
//Make unit icons fully opaque when units are selected
|
||||
unitBaseImage.color.a = 1f
|
||||
background?.color?.a = 1f
|
||||
|
||||
val whiteHalo = getBackgroundImageForUnit()
|
||||
val whiteHaloSize = 30f
|
||||
whiteHalo.setSize(whiteHaloSize, whiteHaloSize)
|
||||
@ -75,6 +82,7 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
||||
addActor(whiteHalo)
|
||||
whiteHalo.toBack()
|
||||
|
||||
|
||||
if (UncivGame.Current.settings.continuousRendering) {
|
||||
val spinningCircle = if (blackSpinningCircle != null) blackSpinningCircle!!
|
||||
else ImageGetter.getCircle()
|
||||
|
Reference in New Issue
Block a user