Long tech descriptions are now scrollable

This commit is contained in:
Yair Morgenstern 2020-12-19 20:53:48 +02:00
parent e3f1c33654
commit d56433857b

View File

@ -1,26 +1,26 @@
package com.unciv.ui.worldscreen package com.unciv.ui.worldscreen
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.Constants import com.unciv.Constants
import com.unciv.logic.civilization.AlertType import com.unciv.logic.civilization.AlertType
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.PopupAlert import com.unciv.logic.civilization.PopupAlert
import com.unciv.models.translations.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popup(worldScreen){ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popup(worldScreen) {
fun getCloseButton(text: String, action: (() -> Unit)?=null): TextButton { fun getCloseButton(text: String, action: (() -> Unit)? = null): TextButton {
val button = text.toTextButton() val button = text.toTextButton()
button.onClick { button.onClick {
if(action!=null) action() if (action != null) action()
worldScreen.shouldUpdate=true worldScreen.shouldUpdate = true
close() close()
} }
return button return button
} }
fun addLeaderName(civInfo : CivilizationInfo){ fun addLeaderName(civInfo: CivilizationInfo) {
val otherCivLeaderName = civInfo.getLeaderDisplayName() val otherCivLeaderName = civInfo.getLeaderDisplayName()
add(otherCivLeaderName.toLabel()) add(otherCivLeaderName.toLabel())
addSeparator() addSeparator()
@ -28,7 +28,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
init { init {
when(popupAlert.type){ when (popupAlert.type) {
AlertType.WarDeclaration -> { AlertType.WarDeclaration -> {
val civInfo = worldScreen.gameInfo.getCivilization(popupAlert.value) val civInfo = worldScreen.gameInfo.getCivilization(popupAlert.value)
addLeaderName(civInfo) addLeaderName(civInfo)
@ -132,11 +132,11 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
add(responseTable) add(responseTable)
} }
AlertType.DemandToStopSettlingCitiesNear -> { AlertType.DemandToStopSettlingCitiesNear -> {
val otherciv= worldScreen.gameInfo.getCivilization(popupAlert.value) val otherciv = worldScreen.gameInfo.getCivilization(popupAlert.value)
val playerDiploManager = worldScreen.viewingCiv.getDiplomacyManager(otherciv) val playerDiploManager = worldScreen.viewingCiv.getDiplomacyManager(otherciv)
addLeaderName(otherciv) addLeaderName(otherciv)
addGoodSizedLabel("Please don't settle new cities near us.").row() addGoodSizedLabel("Please don't settle new cities near us.").row()
add(getCloseButton("Very well, we shall look for new lands to settle."){ add(getCloseButton("Very well, we shall look for new lands to settle.") {
playerDiploManager.agreeNotToSettleNear() playerDiploManager.agreeNotToSettleNear()
}).row() }).row()
add(getCloseButton("We shall do as we please.") { add(getCloseButton("We shall do as we please.") {
@ -144,7 +144,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
}).row() }).row()
} }
AlertType.CitySettledNearOtherCivDespiteOurPromise -> { AlertType.CitySettledNearOtherCivDespiteOurPromise -> {
val otherciv= worldScreen.gameInfo.getCivilization(popupAlert.value) val otherciv = worldScreen.gameInfo.getCivilization(popupAlert.value)
addLeaderName(otherciv) addLeaderName(otherciv)
addGoodSizedLabel("We noticed your new city near our borders, despite your promise. This will have....implications.").row() addGoodSizedLabel("We noticed your new city near our borders, despite your promise. This will have....implications.").row()
add(getCloseButton("Very well.")) add(getCloseButton("Very well."))
@ -154,10 +154,10 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
addGoodSizedLabel(wonder.name) addGoodSizedLabel(wonder.name)
addSeparator() addSeparator()
val centerTable = Table() val centerTable = Table()
centerTable.add(wonder.quote.toLabel().apply { setWrap(true) }).width(worldScreen.stage.width/3) centerTable.add(wonder.quote.toLabel().apply { wrap = true }).width(worldScreen.stage.width / 3)
centerTable.add(ImageGetter.getConstructionImage(wonder.name).surroundWithCircle(100f)).pad(20f) centerTable.add(ImageGetter.getConstructionImage(wonder.name).surroundWithCircle(100f)).pad(20f)
centerTable.add(wonder.getShortDescription(worldScreen.gameInfo.ruleSet) centerTable.add(wonder.getShortDescription(worldScreen.gameInfo.ruleSet)
.toLabel().apply { setWrap(true) }).width(worldScreen.stage.width/3) .toLabel().apply { wrap = true }).width(worldScreen.stage.width / 3)
add(centerTable).row() add(centerTable).row()
add(getCloseButton(Constants.close)) add(getCloseButton(Constants.close))
} }
@ -167,9 +167,10 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
addGoodSizedLabel(tech.name) addGoodSizedLabel(tech.name)
addSeparator() addSeparator()
val centerTable = Table() val centerTable = Table()
centerTable.add(tech.quote.toLabel().apply { setWrap(true) }).width(worldScreen.stage.width/3) centerTable.add(tech.quote.toLabel().apply { wrap = true }).width(worldScreen.stage.width / 3)
centerTable.add(ImageGetter.getTechIconGroup(tech.name,100f)).pad(20f) centerTable.add(ImageGetter.getTechIconGroup(tech.name, 100f)).pad(20f)
centerTable.add(tech.getDescription(gameBasics).toLabel().apply { setWrap(true) }).width(worldScreen.stage.width/3) val descriptionScroll = ScrollPane(tech.getDescription(gameBasics).toLabel().apply { wrap = true })
centerTable.add(descriptionScroll).width(worldScreen.stage.width / 3).maxHeight(worldScreen.stage.height / 2)
add(centerTable).row() add(centerTable).row()
add(getCloseButton(Constants.close)) add(getCloseButton(Constants.close))
} }
@ -192,8 +193,8 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
} }
} }
override fun close(){ override fun close() {
worldScreen.viewingCiv.popupAlerts.remove(popupAlert) worldScreen.viewingCiv.popupAlerts.remove(popupAlert)
super.close() super.close()
} }
} }