mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-26 07:39:44 +07:00
Separated tutorials to a separate file
This commit is contained in:
@ -13,24 +13,15 @@ import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator
|
|||||||
import com.badlogic.gdx.scenes.scene2d.*
|
import com.badlogic.gdx.scenes.scene2d.*
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.*
|
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
|
||||||
import com.badlogic.gdx.utils.Align
|
|
||||||
import com.badlogic.gdx.utils.viewport.ExtendViewport
|
import com.badlogic.gdx.utils.viewport.ExtendViewport
|
||||||
import com.unciv.UnCivGame
|
import com.unciv.UnCivGame
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
import java.util.*
|
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
import kotlin.collections.HashMap
|
|
||||||
|
|
||||||
class Tutorial(var name: String, var texts: ArrayList<String>) {}
|
|
||||||
|
|
||||||
open class CameraStageBaseScreen : Screen {
|
open class CameraStageBaseScreen : Screen {
|
||||||
|
|
||||||
var game: UnCivGame = UnCivGame.Current
|
var game: UnCivGame = UnCivGame.Current
|
||||||
var stage: Stage
|
var stage: Stage
|
||||||
|
var tutorials = Tutorials()
|
||||||
private val tutorialTexts = mutableListOf<Tutorial>()
|
|
||||||
|
|
||||||
private var isTutorialShowing = false
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val resolutions: List<Float> = game.settings.resolution.split("x").map { it.toInt().toFloat() }
|
val resolutions: List<Float> = game.settings.resolution.split("x").map { it.toInt().toFloat() }
|
||||||
@ -61,65 +52,10 @@ open class CameraStageBaseScreen : Screen {
|
|||||||
|
|
||||||
override fun dispose() {}
|
override fun dispose() {}
|
||||||
|
|
||||||
fun getTutorialsOfLanguage(language: String): HashMap<String, ArrayList<String>> {
|
|
||||||
if(!Gdx.files.internal("jsons/Tutorials_$language.json").exists()) return hashMapOf()
|
|
||||||
|
|
||||||
// ...Yes. Disgusting. I wish I didn't have to do this.
|
|
||||||
val x = LinkedHashMap<String,com.badlogic.gdx.utils.Array<com.badlogic.gdx.utils.Array<String>>>()
|
|
||||||
val tutorials: LinkedHashMap<String, com.badlogic.gdx.utils.Array<com.badlogic.gdx.utils.Array<String>>> =
|
|
||||||
GameBasics.getFromJson(x.javaClass, "Tutorials_$language")
|
|
||||||
val tutorialMap = HashMap<String,ArrayList<String>>()
|
|
||||||
for (tut in tutorials){
|
|
||||||
val list = ArrayList<String>()
|
|
||||||
for(paragraph in tut.value)
|
|
||||||
list += paragraph.joinToString("\n")
|
|
||||||
tutorialMap[tut.key] = list
|
|
||||||
}
|
|
||||||
return tutorialMap
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTutorials(name:String, language:String):ArrayList<String>{
|
|
||||||
val tutorialsOfLanguage = getTutorialsOfLanguage(language)
|
|
||||||
if(tutorialsOfLanguage.containsKey(name)) return tutorialsOfLanguage[name]!!
|
|
||||||
return getTutorialsOfLanguage("English")[name]!!
|
|
||||||
}
|
|
||||||
|
|
||||||
fun displayTutorials(name: String) {
|
fun displayTutorials(name: String) {
|
||||||
if (UnCivGame.Current.settings.tutorialsShown.contains(name)) return
|
tutorials.displayTutorials(name,stage)
|
||||||
UnCivGame.Current.settings.tutorialsShown.add(name)
|
|
||||||
UnCivGame.Current.settings.save()
|
|
||||||
val texts = getTutorials(name,UnCivGame.Current.settings.language)
|
|
||||||
tutorialTexts.add(Tutorial(name,texts))
|
|
||||||
if (!isTutorialShowing) displayTutorial()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun displayTutorial() {
|
|
||||||
isTutorialShowing = true
|
|
||||||
val tutorialTable = Table().pad(10f)
|
|
||||||
tutorialTable.background = ImageGetter.getBackground(Color(0x101050cf))
|
|
||||||
val currentTutorial = tutorialTexts[0]
|
|
||||||
val label = Label(currentTutorial.texts[0], skin)
|
|
||||||
label.setAlignment(Align.center)
|
|
||||||
if(Gdx.files.internal("ExtraImages/"+currentTutorial.name+".png").exists())
|
|
||||||
tutorialTable.add(Table().apply { add(ImageGetter.getExternalImage(currentTutorial.name)) }).row()
|
|
||||||
tutorialTable.add(label).pad(10f).row()
|
|
||||||
val button = TextButton("Close".tr(), skin)
|
|
||||||
|
|
||||||
currentTutorial.texts.removeAt(0)
|
|
||||||
if(currentTutorial.texts.isEmpty()) tutorialTexts.removeAt(0)
|
|
||||||
|
|
||||||
button.onClick {
|
|
||||||
tutorialTable.remove()
|
|
||||||
if (!tutorialTexts.isEmpty())
|
|
||||||
displayTutorial()
|
|
||||||
else
|
|
||||||
isTutorialShowing = false
|
|
||||||
}
|
|
||||||
tutorialTable.add(button).pad(10f)
|
|
||||||
tutorialTable.pack()
|
|
||||||
tutorialTable.center(stage)
|
|
||||||
stage.addActor(tutorialTable)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -254,3 +190,4 @@ fun Actor.onClick(function: () -> Unit) {
|
|||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
86
core/src/com/unciv/ui/utils/Tutorials.kt
Normal file
86
core/src/com/unciv/ui/utils/Tutorials.kt
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package com.unciv.ui.utils
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Stage
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Label
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
|
import com.badlogic.gdx.utils.Align
|
||||||
|
import com.badlogic.gdx.utils.Array
|
||||||
|
import com.unciv.UnCivGame
|
||||||
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
|
import java.util.LinkedHashMap
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.collections.HashMap
|
||||||
|
import kotlin.collections.set
|
||||||
|
|
||||||
|
class Tutorials{
|
||||||
|
|
||||||
|
class Tutorial(var name: String, var texts: ArrayList<String>) {}
|
||||||
|
|
||||||
|
private val tutorialTexts = mutableListOf<Tutorial>()
|
||||||
|
|
||||||
|
private var isTutorialShowing = false
|
||||||
|
|
||||||
|
|
||||||
|
fun displayTutorials(name: String, stage: Stage) {
|
||||||
|
if (UnCivGame.Current.settings.tutorialsShown.contains(name)) return
|
||||||
|
UnCivGame.Current.settings.tutorialsShown.add(name)
|
||||||
|
UnCivGame.Current.settings.save()
|
||||||
|
val texts = getTutorials(name, UnCivGame.Current.settings.language)
|
||||||
|
tutorialTexts.add(Tutorial(name,texts))
|
||||||
|
if (!isTutorialShowing) displayTutorial(stage)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getTutorialsOfLanguage(language: String): HashMap<String, ArrayList<String>> {
|
||||||
|
if(!Gdx.files.internal("jsons/Tutorials_$language.json").exists()) return hashMapOf()
|
||||||
|
|
||||||
|
// ...Yes. Disgusting. I wish I didn't have to do this.
|
||||||
|
val x = LinkedHashMap<String, Array<Array<String>>>()
|
||||||
|
val tutorials: LinkedHashMap<String, Array<Array<String>>> =
|
||||||
|
GameBasics.getFromJson(x.javaClass, "Tutorials_$language")
|
||||||
|
val tutorialMap = HashMap<String, ArrayList<String>>()
|
||||||
|
for (tut in tutorials){
|
||||||
|
val list = ArrayList<String>()
|
||||||
|
for(paragraph in tut.value)
|
||||||
|
list += paragraph.joinToString("\n")
|
||||||
|
tutorialMap[tut.key] = list
|
||||||
|
}
|
||||||
|
return tutorialMap
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getTutorials(name:String, language:String): ArrayList<String> {
|
||||||
|
val tutorialsOfLanguage = getTutorialsOfLanguage(language)
|
||||||
|
if(tutorialsOfLanguage.containsKey(name)) return tutorialsOfLanguage[name]!!
|
||||||
|
return getTutorialsOfLanguage("English")[name]!!
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun displayTutorial(stage: Stage) {
|
||||||
|
isTutorialShowing = true
|
||||||
|
val tutorialTable = Table().pad(10f)
|
||||||
|
tutorialTable.background = ImageGetter.getBackground(Color(0x101050cf))
|
||||||
|
val currentTutorial = tutorialTexts[0]
|
||||||
|
val label = Label(currentTutorial.texts[0], CameraStageBaseScreen.skin)
|
||||||
|
label.setAlignment(Align.center)
|
||||||
|
if(Gdx.files.internal("ExtraImages/"+currentTutorial.name+".png").exists())
|
||||||
|
tutorialTable.add(Table().apply { add(ImageGetter.getExternalImage(currentTutorial.name)) }).row()
|
||||||
|
tutorialTable.add(label).pad(10f).row()
|
||||||
|
val button = TextButton("Close".tr(), CameraStageBaseScreen.skin)
|
||||||
|
|
||||||
|
currentTutorial.texts.removeAt(0)
|
||||||
|
if(currentTutorial.texts.isEmpty()) tutorialTexts.removeAt(0)
|
||||||
|
|
||||||
|
button.onClick {
|
||||||
|
tutorialTable.remove()
|
||||||
|
if (!tutorialTexts.isEmpty())
|
||||||
|
displayTutorial(stage)
|
||||||
|
else
|
||||||
|
isTutorialShowing = false
|
||||||
|
}
|
||||||
|
tutorialTable.add(button).pad(10f)
|
||||||
|
tutorialTable.pack()
|
||||||
|
tutorialTable.center(stage)
|
||||||
|
stage.addActor(tutorialTable)
|
||||||
|
}
|
||||||
|
}
|
@ -68,6 +68,8 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
stage.addActor(bottomBar)
|
stage.addActor(bottomBar)
|
||||||
stage.addActor(unitActionsTable)
|
stage.addActor(unitActionsTable)
|
||||||
|
|
||||||
|
displayTutorials("NewGame")
|
||||||
|
displayTutorials("TileLayout")
|
||||||
update()
|
update()
|
||||||
|
|
||||||
val tileToCenterOn: Vector2 =
|
val tileToCenterOn: Vector2 =
|
||||||
@ -78,20 +80,12 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
}
|
}
|
||||||
tileMapHolder.setCenterPosition(tileToCenterOn)
|
tileMapHolder.setCenterPosition(tileToCenterOn)
|
||||||
createNextTurnButton() // needs civ table to be positioned
|
createNextTurnButton() // needs civ table to be positioned
|
||||||
displayTutorials("NewGame")
|
|
||||||
displayTutorials("TileLayout")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun update() {
|
fun update() {
|
||||||
// many of the display functions will be called with the game clone and not the actual game,
|
// many of the display functions will be called with the game clone and not the actual game,
|
||||||
// because that's guaranteed to stay the exact same and so we won't get any concurrent modification exceptions
|
// because that's guaranteed to stay the exact same and so we won't get any concurrent modification exceptions
|
||||||
// val showImageTable = PopupTable()
|
|
||||||
// showImageTable.add(ImageGetter.getExternalImage("IconTutorial.png")).row()
|
|
||||||
// showImageTable.addButton("Close"){showImageTable.remove()}
|
|
||||||
// showImageTable.pack()
|
|
||||||
// stage.addActor(showImageTable)
|
|
||||||
|
|
||||||
|
|
||||||
val gameClone = gameInfo.clone()
|
val gameClone = gameInfo.clone()
|
||||||
val cloneCivilization = gameClone.getPlayerCivilization()
|
val cloneCivilization = gameClone.getPlayerCivilization()
|
||||||
|
Reference in New Issue
Block a user