Skip to content

Commit

Permalink
WLTK decorations (#6253)
Browse files Browse the repository at this point in the history
* WLTK decoration png's and atlas

* UncivTooltip anchor to stage so tips won't get clipped by some ScrollPane

* Empire Overview Cities add WLTK column

* Make WLTK line on CityScreen stats box link to Civilopedia

* Make Civilopedia return to previous screen for _both_ ESC/Back and the Close Button

* Revive Civilopedia links in WorldScreen.TileInfoTable

* Festive decoration for WLTK day on CityScreen
  • Loading branch information
SomeTroglodyte authored Mar 5, 2022
1 parent 20f34eb commit fb7cb70
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 133 deletions.
Binary file added android/Images.Construction/OtherIcons/WLTK 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/Images.Construction/OtherIcons/WLTK 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
211 changes: 102 additions & 109 deletions android/assets/Construction.atlas

Large diffs are not rendered by default.

Binary file modified android/assets/Construction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 25 additions & 3 deletions core/src/com/unciv/ui/cityscreen/CityScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.unciv.ui.cityscreen

import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align
import com.unciv.UncivGame
Expand All @@ -22,6 +23,9 @@ class CityScreen(
companion object {
/** Distance from stage edges to floating widgets */
const val posFromEdge = 5f

/** Size of the decoration icons shown besides the raze button */
const val wltkIconSize = 40f
}

/** Toggles or adds/removes all state changing buttons */
Expand Down Expand Up @@ -176,6 +180,14 @@ class CityScreen(
private fun updateAnnexAndRazeCityButton() {
razeCityButtonHolder.clear()

fun addWltkIcon(name: String, apply: Image.()->Unit = {}) =
razeCityButtonHolder.add(ImageGetter.getImage(name).apply(apply)).size(wltkIconSize)

if (city.isWeLoveTheKingDayActive()) {
addWltkIcon("OtherIcons/WLTK LR") { color = Color.GOLD }
addWltkIcon("OtherIcons/WLTK 1") { color = Color.FIREBRICK }.padRight(10f)
}

if (city.isPuppet) {
val annexCityButton = "Annex city".toTextButton()
annexCityButton.labelCell.pad(10f)
Expand All @@ -184,22 +196,32 @@ class CityScreen(
update()
}
if (!canChangeState) annexCityButton.disable()
razeCityButtonHolder.add(annexCityButton).colspan(cityPickerTable.columns)
razeCityButtonHolder.add(annexCityButton) //.colspan(cityPickerTable.columns)
} else if (!city.isBeingRazed) {
val razeCityButton = "Raze city".toTextButton()
razeCityButton.labelCell.pad(10f)
razeCityButton.onClick { city.isBeingRazed = true; update() }
if (!canChangeState || !city.canBeDestroyed())
razeCityButton.disable()

razeCityButtonHolder.add(razeCityButton).colspan(cityPickerTable.columns)
razeCityButtonHolder.add(razeCityButton) //.colspan(cityPickerTable.columns)
} else {
val stopRazingCityButton = "Stop razing city".toTextButton()
stopRazingCityButton.labelCell.pad(10f)
stopRazingCityButton.onClick { city.isBeingRazed = false; update() }
if (!canChangeState) stopRazingCityButton.disable()
razeCityButtonHolder.add(stopRazingCityButton).colspan(cityPickerTable.columns)
razeCityButtonHolder.add(stopRazingCityButton) //.colspan(cityPickerTable.columns)
}

if (city.isWeLoveTheKingDayActive()) {
addWltkIcon("OtherIcons/WLTK 2") { color = Color.FIREBRICK }.padLeft(10f)
addWltkIcon("OtherIcons/WLTK LR") {
color = Color.GOLD
scaleX = -scaleX
originX = wltkIconSize * 0.5f
}
}

razeCityButtonHolder.pack()
val centerX = if (!isPortrait()) stage.width / 2
else constructionsTable.getUpperWidth().let { it + (stage.width - cityStatsTable.width - it) / 2 }
Expand Down
1 change: 0 additions & 1 deletion core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class CityScreenTileTable(private val cityScreen: CityScreen): Table() {
innerTable.pad(5f)

innerTable.add( MarkupRenderer.render(selectedTile.toMarkup(city.civInfo), iconDisplay = IconDisplay.None) {
// Sorry, this will leave the city screen
UncivGame.Current.setScreen(CivilopediaScreen(city.getRuleset(), cityScreen, link = it))
} )
innerTable.row()
Expand Down
29 changes: 22 additions & 7 deletions core/src/com/unciv/ui/cityscreen/CityStatsTable.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.unciv.ui.cityscreen

import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align
import com.unciv.UncivGame
import com.unciv.logic.city.CityFlags
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.stats.Stat
import com.unciv.models.translations.tr
import com.unciv.ui.civilopedia.CivilopediaScreen
import com.unciv.ui.utils.*
import kotlin.math.ceil
import kotlin.math.round
Expand Down Expand Up @@ -80,20 +84,31 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
innerTable.add(unassignedPopString.toLabel()).row()
innerTable.add(turnsToExpansionString.toLabel()).row()
innerTable.add(turnsToPopString.toLabel()).row()

val tableWithIcons = Table()
tableWithIcons.defaults().pad(2f)
if (cityInfo.isInResistance()) {
tableWithIcons.add(ImageGetter.getImage("StatIcons/Resistance")).size(20f)
tableWithIcons.add("In resistance for another [${cityInfo.getFlag(CityFlags.Resistance)}] turns".toLabel()).row()
}
if (cityInfo.isWeLoveTheKingDayActive()) {
tableWithIcons.add(ImageGetter.getStatIcon("Food")).size(20f)
tableWithIcons.add("We Love The King Day for another [${cityInfo.getFlag(CityFlags.WeLoveTheKing)}] turns".toLabel()).row()
} else if (cityInfo.demandedResource != "") {
tableWithIcons.add(ImageGetter.getResourceImage(cityInfo.demandedResource, 20f)).padRight(5f)
tableWithIcons.add("Demanding [${cityInfo.demandedResource}]".toLabel()).left().row()

val (wltkIcon: Actor?, wltkLabel: Label?) = when {
cityInfo.isWeLoveTheKingDayActive() ->
ImageGetter.getStatIcon("Food") to
"We Love The King Day for another [${cityInfo.getFlag(CityFlags.WeLoveTheKing)}] turns".toLabel(Color.LIME)
cityInfo.demandedResource.isNotEmpty() ->
ImageGetter.getResourceImage(cityInfo.demandedResource, 20f) to
"Demanding [${cityInfo.demandedResource}]".toLabel(Color.CORAL)
else -> null to null
}
if (wltkLabel != null) {
tableWithIcons.add(wltkIcon!!).size(20f).padRight(5f)
wltkLabel.onClick {
UncivGame.Current.setScreen(CivilopediaScreen(cityInfo.getRuleset(), cityScreen, link = "We Love The King Day"))
}
tableWithIcons.add(wltkLabel).row()
}

innerTable.add(tableWithIcons).row()
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class CivilopediaScreen(

val goToGameButton = Constants.close.toTextButton()
goToGameButton.onClick {
game.setWorldScreen()
game.setScreen(previousScreen)
dispose()
}

Expand Down
30 changes: 27 additions & 3 deletions core/src/com/unciv/ui/overviewscreen/CityOverviewTable.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.unciv.ui.overviewscreen

import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Cell
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align
import com.unciv.Constants
import com.unciv.logic.city.CityFlags
import com.unciv.logic.city.CityInfo
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.stats.Stat
import com.unciv.models.translations.tr
import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.utils.*
import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
import kotlin.math.max
import kotlin.math.roundToInt

Expand Down Expand Up @@ -62,6 +64,11 @@ class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val
for (name in columnsNames) {
addSortIcon(name)
}
val wltkSortIcon: IconCircleGroup = ImageGetter.getImage("OtherIcons/WLTK 2")
.apply { color = Color.BLACK }
.surroundWithCircle(iconSize, color = Color.TAN)
wltkSortIcon.addTooltip("We Love The King Day", 18f, tipAlign = Align.center )
addSortIcon("WLTK", wltkSortIcon)
cityInfoTableIcons.pack()

// Prepare middle third: cityInfoScrollPane (a ScrollPane containing cityInfoTableDetails)
Expand All @@ -78,7 +85,7 @@ class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val

// place the button for sorting by city name on top of the cities names
// by sizing the filler to: subtract width of other columns and one cell padding from overall width
val headingFillerWidth = max(0f, cityInfoTableDetails.width - (iconSize + 2*paddingHorz) * (numHeaderCells-1) - 2*paddingHorz)
val headingFillerWidth = max(0f, cityInfoTableDetails.width - (iconSize + 2*paddingHorz) * numHeaderCells - 2*paddingHorz)
headerFillerCell.width(headingFillerWidth)
cityInfoTableIcons.width = cityInfoTableDetails.width

Expand All @@ -94,6 +101,7 @@ class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val
if (stat == Stat.Food || stat == Stat.Production) cityInfoTableTotal.add() // an intended empty space
else cityInfoTableTotal.add(viewingPlayer.cities.sumOf { getStatOfCity(it, stat) }.toLabel()).myAlign(Align.center)
}
cityInfoTableTotal.add(viewingPlayer.cities.count { it.isWeLoveTheKingDayActive() }.toLabel()).myAlign(Align.center)
cityInfoTableTotal.pack()

// Stack cityInfoTableIcons, cityInfoScrollPane, and cityInfoTableTotal vertically
Expand Down Expand Up @@ -125,6 +133,7 @@ class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val
val stat = Stat.valueOf(sortType)
getStatOfCity(city1, stat) - getStatOfCity(city2, stat)
}
sortType == "WLTK" -> city1.isWeLoveTheKingDayActive().compareTo(city2.isWeLoveTheKingDayActive())
else -> city2.name.tr().compareTo(city1.name.tr())
}
}
Expand All @@ -142,7 +151,7 @@ class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val
}
citiesTable.add(button)

if (city.cityConstructions.currentConstructionFromQueue.length > 0) {
if (city.cityConstructions.currentConstructionFromQueue.isNotEmpty()) {
citiesTable.add(ImageGetter.getConstructionImage(city.cityConstructions.currentConstructionFromQueue).surroundWithCircle(iconSize*0.8f)).padRight(paddingHorz)
} else {
citiesTable.add()
Expand All @@ -156,6 +165,21 @@ class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val
if (!column.isStat()) continue
citiesTable.add(getStatOfCity(city, Stat.valueOf(column)).toLabel()).myAlign(Align.center)
}

when {
city.isWeLoveTheKingDayActive() -> {
val image = ImageGetter.getImage("OtherIcons/WLTK 1").surroundWithCircle(iconSize, color = Color.CLEAR)
image.addTooltip("[${city.getFlag(CityFlags.WeLoveTheKing)}] turns", 18f, tipAlign = Align.topLeft)
citiesTable.add(image)
}
city.demandedResource.isNotEmpty() -> {
val image = ImageGetter.getResourceImage(city.demandedResource, iconSize*0.7f)
image.addTooltip("Demanding [${city.demandedResource}]", 18f, tipAlign = Align.topLeft)
citiesTable.add(image).padLeft(iconSize*0.3f)
}
else -> citiesTable.add()
}

citiesTable.row()
}

Expand Down
18 changes: 11 additions & 7 deletions core/src/com/unciv/ui/utils/UncivTooltip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.unciv.models.translations.tr
* @param forceContentSize Force virtual [content] width/height for alignment calculation
* - because Gdx auto layout reports wrong dimensions on scaled actors.
*/
@Suppress("unused") // reported incorrectly even when a use is right here in the Companion
class UncivTooltip <T: Actor>(
val target: Group,
val content: T,
Expand Down Expand Up @@ -53,17 +52,20 @@ class UncivTooltip <T: Actor>(
//region show, hide and positioning
/** Show the Tooltip ([immediate]ly or begin the animation). _Can_ be called programmatically. */
fun show(immediate: Boolean = false) {
if (target.stage == null) return

val useAnimation = animate && !immediate
if (state == TipState.Shown || state == TipState.Showing && useAnimation || !target.hasParent()) return
if (state == TipState.Showing || state == TipState.Hiding) {
container.clearActions()
state = TipState.Hidden
container.remove()
}
val pos = target.localToParentCoordinates(target.getEdgePoint(targetAlign)).add(offset)

val pos = target.localToStageCoordinates(target.getEdgePoint(targetAlign)).add(offset)
container.run {
val originX = getOriginX(contentWidth,tipAlign)
val originY = getOriginY(contentHeight,tipAlign)
val originX = getOriginX(contentWidth, tipAlign)
val originY = getOriginY(contentHeight, tipAlign)
setOrigin(originX, originY)
setPosition(pos.x - originX, pos.y - originY)
if (useAnimation) {
Expand All @@ -76,7 +78,8 @@ class UncivTooltip <T: Actor>(
setScale(1f)
}
}
target.parent.addActor(container)
target.stage.addActor(container)

if (useAnimation) {
state = TipState.Showing
container.addAction(Actions.sequence(
Expand Down Expand Up @@ -155,8 +158,9 @@ class UncivTooltip <T: Actor>(
* @param text Automatically translated tooltip text
* @param size _Vertical_ size of the entire Tooltip including background
* @param always override requirement: presence of physical keyboard
* @param tipAlign Point on the Tooltip to align with the top right of the [target]
*/
fun Group.addTooltip(text: String, size: Float = 26f, always: Boolean = false) {
fun Group.addTooltip(text: String, size: Float = 26f, always: Boolean = false, tipAlign: Int = Align.top) {
if (!(always || KeyPressDispatcher.keyboardAvailable) || text.isEmpty()) return

val label = text.toLabel(ImageGetter.getBlue(), 38)
Expand All @@ -183,7 +187,7 @@ class UncivTooltip <T: Actor>(
labelWithBackground,
forceContentSize = Vector2(size * widthHeightRatio, size),
offset = Vector2(-size/4, size/4),
tipAlign = Align.top
tipAlign = tipAlign
))
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/com/unciv/ui/worldscreen/bottombar/TileInfoTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Align
import com.unciv.UncivGame
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.map.TileInfo
import com.unciv.ui.civilopedia.CivilopediaScreen
import com.unciv.ui.civilopedia.FormattedLine.IconDisplay
import com.unciv.ui.civilopedia.MarkupRenderer
import com.unciv.ui.utils.BaseScreen
Expand All @@ -24,8 +25,7 @@ class TileInfoTable(private val viewingCiv :CivilizationInfo) : Table(BaseScreen
if (tile != null && (UncivGame.Current.viewEntireMapForDebug || viewingCiv.exploredTiles.contains(tile.position)) ) {
add(getStatsTable(tile))
add( MarkupRenderer.render(tile.toMarkup(viewingCiv), padding = 0f, iconDisplay = IconDisplay.None) {
// We need to pass the current screen here to get this to work and I can't be bothered now
// UncivGame.Current.setScreen(CivilopediaScreen(viewingCiv.gameInfo.ruleSet, link = it))
UncivGame.Current.setScreen(CivilopediaScreen(viewingCiv.gameInfo.ruleSet, UncivGame.Current.worldScreen, link = it))
} ).pad(5f).row()
if (UncivGame.Current.viewEntireMapForDebug)
add(tile.position.run { "(${x.toInt()},${y.toInt()})" }.toLabel()).colspan(2).pad(5f)
Expand Down
3 changes: 3 additions & 0 deletions docs/Credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ Unless otherwise specified, all the following are from [the Noun Project](https:
* [East side of stela C, Quirigua](https://en.wikipedia.org/wiki/File:East_side_of_stela_C,_Quirigua.PNG) for Mayan calendar symbols
* [Footprints](https://thenounproject.com/icon/footprints-1393611/) by Abdul Wahhab for movement overlay toggle, slightly modified. Currently unused.
* Arrows.svg by Intralexical (@will-ca), CC0.
* [favor](https://thenounproject.com/icon/favor-1029350/) by MICHAEL G BROWN for WLTK marker on City Overview
* [Party](https://thenounproject.com/icon/party-1784941/) by Adrien Coquet for WLTK header on City Overview
* [Party](https://thenounproject.com/icon/party-2955155/) by Lars Meiertoberens as additional WLKT decoration

## Main menu

Expand Down

0 comments on commit fb7cb70

Please sign in to comment.