adjusting disposing behavs so that we can go back and forth the ingame and titlescr

This commit is contained in:
minjaesong
2019-01-31 00:12:38 +09:00
parent 1475fa08dc
commit b3e323965f
12 changed files with 62 additions and 49 deletions

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
@@ -21,7 +22,7 @@ abstract class UICanvas(
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
customPositioning: Boolean = false, // mainly used by vital meter
doNotWarnConstant: Boolean = false
) {
): Disposable {
abstract var width: Int
abstract var height: Int
@@ -36,7 +37,7 @@ abstract class UICanvas(
/**
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
*/
protected val handler = UIHandler(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant)
val handler = UIHandler(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant)
init {
@@ -111,7 +112,7 @@ abstract class UICanvas(
*/
abstract fun endClosing(delta: Float)
abstract fun dispose()
abstract override fun dispose()
fun addItem(uiItem: UIItem) {
uiItems.add(uiItem)

View File

@@ -3,8 +3,9 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.modulebasegame.Ingame
import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.modulebasegame.Ingame
/**
* UIHandler is a handler for UICanvas. It opens/closes the attached UI, moves the "window" (or "canvas")
@@ -20,7 +21,7 @@ class UIHandler(//var UI: UICanvas,
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
var customPositioning: Boolean = false, // mainly used by vital meter
var doNotWarnConstant: Boolean = false
) {
): Disposable {
// X/Y Position relative to the game window.
var posX: Int = 0
@@ -341,4 +342,10 @@ class UIHandler(//var UI: UICanvas,
return false
}
}
/** Don't dispose common assets, this function is called when the ingame does hide() */
override fun dispose() {
toggleKey?.let { KeyToggler.forceSet(it, false) }
toggleButton?.let { /* ButtonToggler.forceSet(it, false) */ }
}
}

View File

@@ -13,6 +13,7 @@ import net.torvald.terrarum.*
class UINSMenu(
var title: String = "",
val minimumWidth: Int,
/** Optional instance of YamlInvokable can be used */
treeRepresentation: Yaml,
val titleBackCol: Color = Color(0f,0f,0f,.77f),
@@ -29,7 +30,7 @@ class UINSMenu(
val CHILD_ARROW = "${0x2023.toChar()}"
val tree = treeRepresentation.parse()
val tree = treeRepresentation.parseAsYamlInvokable()
override var width = 0
override var height = 0
//override var width = maxOf(minimumWidth, tree.getLevelData(1).map { Terrarum.fontGame.getWidth(it ?: "") }.max() ?: 0)
@@ -53,10 +54,10 @@ class UINSMenu(
addSubMenu(tree)
}
private fun addSubMenu(tree: QNDTreeNode<String>) {
val menuTitle = tree.data ?: title
private fun addSubMenu(tree: QNDTreeNode<Pair<String, YamlInvokable?>>) {
val menuTitle = tree.data?.first ?: title
val stringsFromTree = Array<String>(tree.children.size) {
tree.children[it].toString() + if (tree.children[it].children.isNotEmpty()) " $CHILD_ARROW" else ""
tree.children[it].data?.first + if (tree.children[it].children.isNotEmpty()) " $CHILD_ARROW" else ""
}
val listWidth = maxOf(
@@ -98,6 +99,10 @@ class UINSMenu(
if (tree.children[new].children.isNotEmpty()) {
addSubMenu(tree.children[new])
}
// invoke whatever command there is
//printdbg(this, "Selected: ${tree.children[new].data?.second}")
tree.children[new].data?.second?.invoke()
}
// END List selection change listener