Map overlay toggle buttons rework (#10505)

* Simplify MapOverlayToggleButton signature and let the instances use individually moddable images

* Gimp sources of new images (all from existing attributions)

* New images and atlas
This commit is contained in:
SomeTroglodyte 2023-11-22 23:00:19 +01:00 committed by GitHub
parent a6ac9aa24d
commit 0cf8ea2619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 68 additions and 49 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -125,21 +125,21 @@ EmojiIcons/Happiness
index: -1
EmojiIcons/Production
rotate: false
xy: 552, 215
xy: 544, 1087
size: 50, 50
orig: 50, 50
offset: 0, 0
index: -1
EmojiIcons/Science
rotate: false
xy: 552, 41
xy: 544, 913
size: 50, 50
orig: 50, 50
offset: 0, 0
index: -1
EmojiIcons/Turn
rotate: false
xy: 544, 1029
xy: 544, 797
size: 50, 50
orig: 50, 50
offset: 0, 0
@ -755,7 +755,7 @@ OtherIcons/NationSwap
index: -1
OtherIcons/Nations
rotate: false
xy: 552, 331
xy: 552, 99
size: 50, 50
orig: 50, 50
offset: 0, 0
@ -783,7 +783,7 @@ OtherIcons/Options
index: -1
OtherIcons/Pause
rotate: false
xy: 552, 273
xy: 552, 41
size: 50, 50
orig: 50, 50
offset: 0, 0
@ -1322,14 +1322,14 @@ TileIcons/Worked
index: -1
StatIcons/Range
rotate: false
xy: 552, 157
xy: 544, 1029
size: 50, 50
orig: 50, 50
offset: 0, 0
index: -1
StatIcons/RangedStrength
rotate: false
xy: 552, 99
xy: 544, 971
size: 50, 50
orig: 50, 50
offset: 0, 0
@ -1357,7 +1357,7 @@ StatIcons/Specialist
index: -1
StatIcons/Strength
rotate: false
xy: 544, 1087
xy: 544, 855
size: 50, 50
orig: 50, 50
offset: 0, 0
@ -1390,6 +1390,34 @@ TileIcons/Locked
orig: 100, 100
offset: 0, 0
index: -1
TileIcons/MapOverlayToggleMovement
rotate: false
xy: 552, 331
size: 50, 50
orig: 50, 50
offset: 0, 0
index: -1
TileIcons/MapOverlayToggleResources
rotate: false
xy: 552, 273
size: 50, 50
orig: 50, 50
offset: 0, 0
index: -1
TileIcons/MapOverlayToggleWorkedTiles
rotate: false
xy: 552, 215
size: 50, 50
orig: 50, 50
offset: 0, 0
index: -1
TileIcons/MapOverlayToggleYields
rotate: false
xy: 552, 157
size: 50, 50
orig: 50, 50
offset: 0, 0
index: -1
TileIcons/NotWorked
rotate: false
xy: 1399, 1607

Binary file not shown.

Before

Width:  |  Height:  |  Size: 523 KiB

After

Width:  |  Height:  |  Size: 532 KiB

View File

@ -7,7 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.utils.Align
import com.unciv.ui.components.extensions.center
class IconCircleGroup(
open class IconCircleGroup(
size: Float,
val actor: Actor,
resizeActor: Boolean = true,

View File

@ -1,42 +1,37 @@
package com.unciv.ui.screens.worldscreen.minimap
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.unciv.GUI
import com.unciv.ui.images.IconCircleGroup
import com.unciv.ui.components.extensions.setSize
import com.unciv.ui.components.input.onClick
import com.unciv.ui.components.extensions.surroundWithCircle
import com.unciv.ui.images.IconCircleGroup
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.screens.worldscreen.WorldScreen
/**
* Class that unifies the behaviour of the little green map overlay toggle buttons shown next to the minimap.
*
* @param icon An [Image] to display.
* @param iconPath Path to an [Image] to display, will be fetched via [ImageGetter.getImage].
* @param iconSize inner icon size (2f outer circle will be added).
* @property getter A function that returns the current backing state of the toggle.
* @property setter A function for setting the backing state of the toggle.
* @param backgroundColor If non-null, a background colour to show behind the image.
*/
class MapOverlayToggleButton(
icon: Image,
iconPath: String,
iconSize: Float = 30f,
private val getter: () -> Boolean,
private val setter: (Boolean) -> Unit,
backgroundColor: Color? = null
private val setter: (Boolean) -> Unit
) : IconCircleGroup(
size = iconSize + 2f,
actor = ImageGetter.getImage(iconPath).apply {
setSize(iconSize)
},
resizeActor = false
) {
/** [Actor] of the button. Add this to whatever layout. */
val actor: IconCircleGroup by lazy {
var innerActor: Actor = icon
val iconSize = 30f
if (backgroundColor != null) {
innerActor = innerActor
.surroundWithCircle(iconSize)
.apply { circle.color = backgroundColor }
} else innerActor.setSize(iconSize,iconSize)
// So, the "Food" and "Population" stat icons have green as part of their image, but the "Cattle" icon needs a background colour, which is… An interesting mixture/reuse of texture data and render-time processing.
innerActor.surroundWithCircle(32f, resizeActor = false).apply { circle.color = Color.BLACK }
}
init {
actor.onClick(::toggle)
circle.color = Color.BLACK
onClick(::toggle)
}
/** Toggle overlay. Called on click. */
@ -48,6 +43,6 @@ class MapOverlayToggleButton(
/** Update. Called via [WorldScreen.shouldUpdate] on toggle. */
fun update() {
actor.actor.color.a = if (getter()) 1f else 0.5f
actor.color.a = if (getter()) 1f else 0.5f
}
}

View File

@ -7,7 +7,6 @@ import com.badlogic.gdx.utils.Align
import com.unciv.GUI
import com.unciv.UncivGame
import com.unciv.logic.civilization.Civilization
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.screens.basescreen.BaseScreen
import com.unciv.ui.screens.worldscreen.WorldMapHolder
@ -18,40 +17,37 @@ class MinimapHolder(val mapHolder: WorldMapHolder) : Table() {
/** Button, next to the minimap, to toggle the unit movement map overlay. */
val movementsImageButton = MapOverlayToggleButton(
ImageGetter.getImage("StatIcons/Movement").apply { setColor(0f, 0f, 0f, 1f) },
"TileIcons/MapOverlayToggleMovement",
getter = { UncivGame.Current.settings.showUnitMovements },
setter = { UncivGame.Current.settings.showUnitMovements = it },
backgroundColor = Color.GREEN
setter = { UncivGame.Current.settings.showUnitMovements = it }
)
/** Button, next to the minimap, to toggle the tile yield map overlay. */
val yieldImageButton = MapOverlayToggleButton(
ImageGetter.getImage("StatIcons/Food"),
"TileIcons/MapOverlayToggleYields",
// This is a use in the UI that has little to do with the stat… These buttons have more in common with each other than they do with other uses of getStatIcon().
getter = { UncivGame.Current.settings.showTileYields },
setter = { UncivGame.Current.settings.showTileYields = it }
)
/** Button, next to the minimap, to toggle the worked tiles map overlay. */
val populationImageButton = MapOverlayToggleButton(
ImageGetter.getImage("StatIcons/Population"),
"TileIcons/MapOverlayToggleWorkedTiles",
getter = { UncivGame.Current.settings.showWorkedTiles },
setter = { UncivGame.Current.settings.showWorkedTiles = it }
)
/** Button, next to the minimap, to toggle the resource icons map overlay. */
val resourceImageButton = MapOverlayToggleButton(
ImageGetter.getImage("ResourceIcons/Cattle"),
"TileIcons/MapOverlayToggleResources",
getter = { UncivGame.Current.settings.showResourcesAndImprovements },
setter = { UncivGame.Current.settings.showResourcesAndImprovements = it },
backgroundColor = Color.GREEN
setter = { UncivGame.Current.settings.showResourcesAndImprovements = it }
)
private fun rebuildIfSizeChanged(civInfo: Civilization) {
// For Spectator should not restrict minimap
var civInfo: Civilization? = civInfo
if(GUI.getViewingPlayer().isSpectator()) civInfo = null
val civ: Civilization? = civInfo.takeUnless { GUI.getViewingPlayer().isSpectator() }
val newMinimapSize = worldScreen.game.settings.minimapSize
if (newMinimapSize == minimapSize && civInfo?.exploredRegion?.shouldUpdateMinimap() != true) return
if (newMinimapSize == minimapSize && civ?.exploredRegion?.shouldUpdateMinimap() != true) return
minimapSize = newMinimapSize
rebuild(civInfo)
rebuild(civ)
}
private fun rebuild(civInfo: Civilization?) {
@ -88,10 +84,10 @@ class MinimapHolder(val mapHolder: WorldMapHolder) : Table() {
private fun getToggleIcons(): Table {
val toggleIconTable = Table()
toggleIconTable.add(movementsImageButton.actor).row()
toggleIconTable.add(yieldImageButton.actor).row()
toggleIconTable.add(populationImageButton.actor).row()
toggleIconTable.add(resourceImageButton.actor).row()
toggleIconTable.add(movementsImageButton).row()
toggleIconTable.add(yieldImageButton).row()
toggleIconTable.add(populationImageButton).row()
toggleIconTable.add(resourceImageButton).row()
return toggleIconTable
}