mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 23:08:35 +07:00
Stats serialize to notifications - see #8446
This commit is contained in:
@ -7,6 +7,8 @@ object Constants {
|
||||
const val spreadReligion = "Spread Religion"
|
||||
const val removeHeresy = "Remove Foreign religions from your own cities"
|
||||
|
||||
const val english = "English"
|
||||
|
||||
const val impassable = "Impassable"
|
||||
const val ocean = "Ocean"
|
||||
|
||||
|
@ -679,7 +679,8 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
|
||||
for (stat in gainedStats)
|
||||
civInfo.addStat(stat.key, stat.value.toInt())
|
||||
civInfo.addNotification("By expending your [$name] you gained [${gainedStats}]!",
|
||||
|
||||
civInfo.addNotification("By expending your [$name] you gained [${gainedStats.toStringForNotifications()}]!",
|
||||
getTile().position, NotificationCategory.Units, name)
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ class GameSettings {
|
||||
var checkForDueUnits: Boolean = true
|
||||
var autoUnitCycle: Boolean = true
|
||||
var singleTapMove: Boolean = false
|
||||
var language: String = "English"
|
||||
var language: String = Constants.english
|
||||
@Transient
|
||||
var locale: Locale? = null
|
||||
@Deprecated("Since 4.3.6 - replaces with screenSize")
|
||||
|
@ -369,7 +369,7 @@ object UniqueTriggerActivation {
|
||||
else notification
|
||||
|
||||
val notificationText = getNotificationText(filledNotification, triggerNotificationText,
|
||||
"Gained [$stats]")
|
||||
"Gained [${stats.toStringForNotifications()}]")
|
||||
?: return true
|
||||
|
||||
civInfo.addNotification(notificationText, LocationAction(tile?.position), NotificationCategory.General, stat.notificationIcon)
|
||||
@ -394,7 +394,7 @@ object UniqueTriggerActivation {
|
||||
else notification
|
||||
|
||||
val notificationText = getNotificationText(filledNotification, triggerNotificationText,
|
||||
"Gained [$stats]")
|
||||
"Gained [${stats.toStringForNotifications()}]")
|
||||
?: return true
|
||||
|
||||
civInfo.addNotification(notificationText, LocationAction(tile?.position), NotificationCategory.General, stat.notificationIcon)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.models.stats
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.models.translations.tr
|
||||
import kotlin.reflect.KMutableProperty0
|
||||
|
||||
@ -149,6 +150,11 @@ open class Stats(
|
||||
}
|
||||
}
|
||||
|
||||
/** Since notificaitons are translated on the fly, when saving stats there we need to do so in English */
|
||||
fun toStringForNotifications() = this.joinToString {
|
||||
(if (it.value > 0) "+" else "") + it.value.toInt() + " " + it.key.toString().tr(Constants.english)
|
||||
}
|
||||
|
||||
// For display in diplomacy window
|
||||
fun toStringWithDecimals(): String {
|
||||
return this.joinToString {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.models.translations
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.models.ruleset.RulesetCache
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
@ -32,7 +33,7 @@ import java.util.*
|
||||
class Translations : LinkedHashMap<String, TranslationEntry>(){
|
||||
|
||||
var percentCompleteOfLanguages = HashMap<String,Int>()
|
||||
.apply { put("English",100) } // So even if we don't manage to load the percentages, we can still pass the language screen
|
||||
.apply { put(Constants.english, 100) } // So even if we don't manage to load the percentages, we can still pass the language screen
|
||||
|
||||
internal var modsWithTranslations: HashMap<String, Translations> = hashMapOf() // key == mod name
|
||||
|
||||
@ -290,9 +291,7 @@ object TranslationActiveModsCache {
|
||||
* defaults to the input string if no translation is available,
|
||||
* but with placeholder or sentence brackets removed.
|
||||
*/
|
||||
fun String.tr(): String {
|
||||
val language = UncivGame.Current.settings.language
|
||||
|
||||
fun String.tr(language:String = UncivGame.Current.settings.language): String {
|
||||
if (contains('<') && contains('>')) { // Conditionals!
|
||||
/**
|
||||
* So conditionals can contain placeholders, such as <vs [unitFilter] units>, which themselves
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.ui
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.MainMenuScreen
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.options.OptionsPopup
|
||||
@ -14,7 +15,7 @@ import com.unciv.ui.utils.extensions.onClick
|
||||
* Reusable code is in [LanguageTable] and [addLanguageTables].
|
||||
*/
|
||||
class LanguagePickerScreen : PickerScreen() {
|
||||
var chosenLanguage = "English"
|
||||
var chosenLanguage = Constants.english
|
||||
|
||||
private val languageTables: ArrayList<LanguageTable>
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.unciv.ui.utils
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.civilopedia.MarkupRenderer
|
||||
@ -58,7 +59,7 @@ internal class LanguageTable(val language:String, val percentComplete: Int): Tab
|
||||
val languageCompletionPercentage = UncivGame.Current.translations
|
||||
.percentCompleteOfLanguages
|
||||
languageTables.addAll(languageCompletionPercentage
|
||||
.map { LanguageTable(it.key, if (it.key == "English") 100 else it.value) }
|
||||
.map { LanguageTable(it.key, if (it.key == Constants.english) 100 else it.value) }
|
||||
.sortedByDescending { it.percentComplete} )
|
||||
|
||||
languageTables.forEach {
|
||||
|
@ -2,6 +2,7 @@
|
||||
package com.unciv.testing
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.models.metadata.GameSettings
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
@ -258,7 +259,7 @@ class TranslationTests {
|
||||
|
||||
fun addTranslation(original:String, result:String){
|
||||
UncivGame.Current.translations[original.getPlaceholderText()] =TranslationEntry(original)
|
||||
.apply { this["English"] = result }
|
||||
.apply { this[Constants.english] = result }
|
||||
}
|
||||
addTranslation("The brother of [person]", "The sibling of [person]")
|
||||
Assert.assertEquals("The sibling of bob", "The brother of [bob]".tr())
|
||||
|
Reference in New Issue
Block a user