when a unit is selected, use the ? button to read about it in the Civilopedia

This commit is contained in:
martin
2019-05-13 12:14:12 +02:00
committed by Yair Morgenstern
parent 0ce55feb39
commit eaa0a9dbad
3 changed files with 48 additions and 40 deletions

View File

@ -1058,7 +1058,7 @@
Russian:"Город будет расширяться между раундами [turnsToExpansion]"
French:"La ville se développera entre [turnsToExpansion] tours"
Romanian:"Orașul se va extinde între rundă [turnsToExpansion]"
German:"Die Stadt wird sich zwischen [turnsToExpansion]-Runden erweitern"
German:"Erweiterung in [turnsToExpansion] Runden"
Dutch:"De stad breidt zich uit tussen [turnsToExpansion]-rondes"
Spanish:"La ciudad se expandirá entre [turnsToExpansion] rondas"
Simplified_Chinese:"这座城市将在[turnsToExpansion]回合后扩张"
@ -1084,7 +1084,7 @@
Russian:"В городе будет новый житель в раундах [turnsToPopulation]"
French:"La ville aura un nouveau résident dans [turnsToPopulation]"
Romanian:"Orașul va avea un nou rezident în runde [turnsToPopulation]"
German:"Die Stadt wird einen neuen Einwohner in [turnsToPopulation]-Runden haben"
German:"Neuer Einwohner in [turnsToPopulation] Runden"
Dutch:"De stad krijgt een nieuwe inwoner in [turnsToPopulation]-rondes"
Spanish:"La ciudad tendrá un nuevo residente en las rondas de [turnsToPopulation]"
Simplified_Chinese:"这座城市将在[turnsToPopulation]轮后有1个新市民"
@ -1863,8 +1863,9 @@
}
"Technologies":{ //You misses this translation, said Smashfanful
Italian:"Tecnologie"
French:"Technologies"
Italian:"Tecnologie",
German:"Technologien",
French:"Technologies",
Simplified_Chinese:"科技"
}
@ -3009,7 +3010,7 @@
"Terrains":{
Italian:"Terreni e caratteristiche"
German:"Gelände und Geländearten"
German:"Gelände"
French:"Terrains"
Simplified_Chinese:"地形"
}

View File

@ -14,8 +14,32 @@ import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.toLabel
import java.util.*
import kotlin.math.max
class CivilopediaScreen : CameraStageBaseScreen() {
val categoryToInfos = LinkedHashMap<String, Collection<ICivilopedia>>()
val categoryToButtons = LinkedHashMap<String, Button>()
val civPediaEntries = Array<ICivilopedia>()
val nameList = List<String>(skin)
val description = "".toLabel()
fun select(category: String, entry: String? = null) {
val nameItems=Array<String>()
civPediaEntries.clear()
for (civilopediaEntry in categoryToInfos[category]!!.sortedBy { it.toString().tr() }){ // Alphabetical order of localized names
civPediaEntries.add(civilopediaEntry)
nameItems.add(civilopediaEntry.toString().tr())
}
nameList.setItems(nameItems)
val index = max(0, nameList.items.indexOf(entry?.tr()))
nameList.selected = nameList.items.get(index)
description.setText(civPediaEntries.get(index).description)
for (btn in categoryToButtons.values) btn.isChecked = false
categoryToButtons[category]?.isChecked = true
}
init {
onBackButtonClicked { UnCivGame.Current.setWorldScreen() }
val buttonTable = Table()
@ -27,8 +51,7 @@ class CivilopediaScreen : CameraStageBaseScreen() {
stage.addActor(splitPane)
val label = "".toLabel()
label.setWrap(true)
description.setWrap(true)
val goToGameButton = TextButton("Close".tr(), skin)
goToGameButton.onClick {
@ -37,7 +60,7 @@ class CivilopediaScreen : CameraStageBaseScreen() {
}
buttonTable.add(goToGameButton)
val categoryToInfos = LinkedHashMap<String, Collection<ICivilopedia>>()
val language = UnCivGame.Current.settings.language.replace(" ","_")
val basicHelpFileName = if(Gdx.files.internal("jsons/BasicHelp/BasicHelp_$language.json").exists())"BasicHelp/BasicHelp_$language"
@ -51,49 +74,27 @@ class CivilopediaScreen : CameraStageBaseScreen() {
categoryToInfos["Units"] = GameBasics.Units.values
categoryToInfos["Technologies"] = GameBasics.Technologies.values
val nameList = List<String>(skin)
val newArray = Array<ICivilopedia>()
val nameListClickListener = {
if(nameList.selected!=null) label.setText(newArray.get(nameList.selectedIndex).description)
nameList.onClick {
if(nameList.selected!=null) description.setText(civPediaEntries.get(nameList.selectedIndex).description)
}
nameList.onClick (nameListClickListener)
nameList.style = List.ListStyle(nameList.style)
nameList.style.fontColorSelected = Color.BLACK
val buttons = ArrayList<Button>()
var first = true
for (str in categoryToInfos.keys) {
val button = TextButton(str.tr(), skin)
for (category in categoryToInfos.keys) {
val button = TextButton(category.tr(), skin)
button.style = TextButton.TextButtonStyle(button.style)
button.style.checkedFontColor = Color.BLACK
buttons.add(button)
val buttonClicked = {
newArray.clear()
val civArray=Array<String>()
for (civilopediaEntry in categoryToInfos[str]!!.sortedBy { it.toString() }){ // Alphabetical order
newArray.add(civilopediaEntry)
civArray.add(civilopediaEntry.toString().tr())
}
nameList.setItems(civArray)
nameList.selected = nameList.items.get(0)
label.setText(newArray.get(0).description)
for (btn in buttons) btn.isChecked = false
button.isChecked = true
}
button.onClick(buttonClicked)
if (first) {// Fake-click the first button so that the user sees results immediately
first = false
buttonClicked()
}
button.style.checkedFontColor = Color.YELLOW
categoryToButtons[category] = button
button.onClick { select(category) }
buttonTable.add(button)
}
select("Basics")
val sp = ScrollPane(nameList)
sp.setupOverscroll(5f, 1f, 200f)
entryTable.add(sp).width(Value.percentWidth(0.25f, entryTable)).height(Value.percentHeight(0.7f, entryTable))
.pad(Value.percentWidth(0.02f, entryTable))
entryTable.add(label).colspan(4).width(Value.percentWidth(0.65f, entryTable)).height(Value.percentHeight(0.7f, entryTable))
entryTable.add(description).colspan(4).width(Value.percentWidth(0.65f, entryTable)).height(Value.percentHeight(0.7f, entryTable))
.pad(Value.percentWidth(0.02f, entryTable))
// Simply changing these to x*width, y*height won't work

View File

@ -49,7 +49,13 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
helpUnitButton.add(Label("?",CameraStageBaseScreen.skin).setFontColor(Color.WHITE)).pad(10f)
helpUnitButton.pack()
helpUnitButton.touchable = Touchable.enabled
helpUnitButton.onClick { UnCivGame.Current.screen = CivilopediaScreen() }
helpUnitButton.onClick {
val pedia = CivilopediaScreen()
if (selectedUnit != null) {
pedia.select("Units", selectedUnit?.name)
}
UnCivGame.Current.screen = pedia
}
addActor(helpUnitButton)
}).left()