Can now add images to tutorials! Added images for Tile Clicked, Unit Selected and Tile Layout tutorials.

This commit is contained in:
Yair Morgenstern 2018-09-24 22:04:39 +03:00
parent 6143b53157
commit a2b730a279
7 changed files with 59 additions and 20 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

View File

@ -79,13 +79,6 @@
]
],
TileClicked : [
[
"Clicking on a tile selects that tile,",
" and displays information on that tile on the bottom-right,",
" as well as unit actions, if the tile contains a unit"
]
],
CityFounded : [
[
@ -113,11 +106,6 @@
" be guiding you along your first journey.",
"Before we begin, let's review some basic game concepts."
],
[
"This is the world map, which is made up of multiple tiles.",
"Each tile can contain units, as well as resources",
" and improvements, which we'll get to later"
],
[
"You start out with two units -",
" a Settler - who can found a city,",
@ -126,6 +114,32 @@
]
],
TileLayout: [
[
"This is the world map, which is made up of multiple tiles.",
"Each tile can contain units, resources and improvements, which we'll get to later.",
"The position of the icon tells you what it signifies.",
"For more details, you can click on the tile and see the tile information."
]
],
TileClicked : [
[
"Clicking on a tile selects that tile,",
" and displays information on that tile on the bottom-right.",
"If the tile contains a unit, that will become the selected unit,"
" and its info and actions will be displayed on the bottom left."
]
],
UnitSelected : [
[
"When a unit is selected, its information will be displayed on the bottom-left corner.",
"The available actions of that unit will appear above the tile information."
]
],
AfterCityEntered : [
[
"Once you've done everything you can, ",

View File

@ -18,14 +18,17 @@ import com.badlogic.gdx.utils.viewport.ExtendViewport
import com.unciv.UnCivGame
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 {
var game: UnCivGame = UnCivGame.Current
var stage: Stage
private val tutorialTexts = mutableListOf<String>()
private val tutorialTexts = mutableListOf<Tutorial>()
private var isTutorialShowing = false
@ -58,16 +61,16 @@ open class CameraStageBaseScreen : Screen {
override fun dispose() {}
fun getTutorialsOfLanguage(language: String): HashMap<String, List<String>> {
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,List<String>>()
val tutorialMap = HashMap<String,ArrayList<String>>()
for (tut in tutorials){
val list = mutableListOf<String>()
val list = ArrayList<String>()
for(paragraph in tut.value)
list += paragraph.joinToString("\n")
tutorialMap[tut.key] = list
@ -75,7 +78,7 @@ open class CameraStageBaseScreen : Screen {
return tutorialMap
}
fun getTutorials(name:String, language:String):List<String>{
fun getTutorials(name:String, language:String):ArrayList<String>{
val tutorialsOfLanguage = getTutorialsOfLanguage(language)
if(tutorialsOfLanguage.containsKey(name)) return tutorialsOfLanguage[name]!!
return getTutorialsOfLanguage("English")[name]!!
@ -86,7 +89,7 @@ open class CameraStageBaseScreen : Screen {
UnCivGame.Current.settings.tutorialsShown.add(name)
UnCivGame.Current.settings.save()
val texts = getTutorials(name,UnCivGame.Current.settings.language)
tutorialTexts.addAll(texts)
tutorialTexts.add(Tutorial(name,texts))
if (!isTutorialShowing) displayTutorial()
}
@ -94,11 +97,17 @@ open class CameraStageBaseScreen : Screen {
isTutorialShowing = true
val tutorialTable = Table().pad(10f)
tutorialTable.background = ImageGetter.getBackground(Color(0x101050cf))
val label = Label(tutorialTexts[0], skin)
val currentTutorial = tutorialTexts[0]
val label = Label(currentTutorial.texts[0], skin)
label.setAlignment(Align.center)
tutorialTexts.removeAt(0)
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())

View File

@ -1,6 +1,7 @@
package com.unciv.ui.utils
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.TextureAtlas
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.scenes.scene2d.Actor
@ -24,6 +25,10 @@ object ImageGetter {
init{
}
fun getExternalImage(fileName:String): Image {
return Image(TextureRegion(Texture("ExtraImages/$fileName.png")))
}
fun getImage(fileName: String): Image {
return Image(getTextureRegion(fileName))
}

View File

@ -79,12 +79,19 @@ class WorldScreen : CameraStageBaseScreen() {
tileMapHolder.setCenterPosition(tileToCenterOn)
createNextTurnButton() // needs civ table to be positioned
displayTutorials("NewGame")
displayTutorials("TileLayout")
}
fun update() {
// 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
// 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 cloneCivilization = gameClone.getPlayerCivilization()
@ -92,6 +99,10 @@ class WorldScreen : CameraStageBaseScreen() {
civInfo.happiness = gameClone.getPlayerCivilization().getHappinessForNextTurn().values.sum().toInt()
}
if(bottomBar.unitTable.selectedUnit!=null){
displayTutorials("UnitSelected")
}
if(UnCivGame.Current.settings.hasCrashedRecently){
displayTutorials("GameCrashed")
UnCivGame.Current.settings.tutorialsShown.remove("GameCrashed")