dirty way to go back a step with multiple uis in coordination

This commit is contained in:
minjaesong
2021-10-28 15:11:52 +09:00
parent 5cb407f5ac
commit 1dc7d46c39
4 changed files with 66 additions and 15 deletions

View File

@@ -29,6 +29,7 @@ import net.torvald.terrarum.ui.Movement
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.utils.RandomWordsName
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.time.Instant
import java.time.format.DateTimeFormatter
@@ -39,6 +40,34 @@ import kotlin.math.roundToInt
val SAVE_CELL_WIDTH = 480
val SAVE_CELL_HEIGHT = 120
/**
* The pinnacle of the dirty coding! This object exists only because I couldn't make
* UILoadDemoSavefiles persistent.
*
* This objects holds which Player and World has been chosen.
*
* WARNING: the values are not guaranteed to reset when the selector UI is closed!
*/
object UILoadGovernor {
var playerDisk: DiskSkimmer? = null
set(value) {
printdbg(this, "Player selected: ${value?.diskFile?.name}")
field = value
}
var worldDisk: DiskSkimmer? = null
set(value) {
printdbg(this, "World selected: ${value?.diskFile?.name}")
field = value
}
fun reset() {
printdbg(this, "Resetting player and world selection")
playerDisk = null
worldDisk = null
}
}
/**
* Only works if current screen set by the App is [TitleScreen]
*
@@ -46,6 +75,8 @@ val SAVE_CELL_HEIGHT = 120
*/
class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
private val hash = RandomWordsName(3)
init {
CommonResourcePool.addToLoadingList("inventory_category") {
TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20)
@@ -110,15 +141,15 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
private var showSpinner = false
// used by UIItem*Cells
internal var playerDisk: DiskSkimmer? = null
internal var worldDisk: DiskSkimmer? = null
private val worldCells = ArrayList<UIItemWorldCells>()
private val playerCells = ArrayList<UIItemPlayerCells>()
var mode = 0; private set// 0: show players, 1: show worlds
constructor(remoCon: UIRemoCon, mode: Int) : this(remoCon) {
this.mode = mode
}
fun advanceMode() {
mode += 1
uiScroll = 0f
@@ -189,6 +220,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
private val mode2Node = Yaml(UITitleRemoConYaml.injectedMenuSingleWorldSel).parse()
private val menus = listOf(mode1Node, mode2Node)
private val titles = listOf("CONTEXT_CHARACTER", "MENU_LABEL_WORLD")
init {
// this UI will NOT persist; the parent of the mode1Node must be set using an absolute value (e.g. treeRoot, not remoCon.currentRemoConContents)
@@ -199,8 +231,8 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
mode1Node.parent = remoCon.treeRoot
mode2Node.parent = mode1Node
mode1Node.data = "MENU_MODE_SINGLEPLAYER+NODISPOSE : net.torvald.terrarum.modulebasegame.ui.UILoadDemoSavefiles"
mode2Node.data = "MENU_MODE_SINGLEPLAYER+NODISPOSE : net.torvald.terrarum.modulebasegame.ui.UILoadDemoSavefiles"
mode1Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadDemoSavefiles"
mode2Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadDemoSavefiles"
printdbg(this, "mode1Node parent: ${mode1Node.parent?.data}") // will be 'null' because the parent is the root node
printdbg(this, "mode1Node data: ${mode1Node.data}")
@@ -267,7 +299,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
App.fontGame.draw(batch, txt, (App.scr.width - App.fontGame.getWidth(txt)) / 2f, (App.scr.height - App.fontGame.lineHeight) / 2f)
if (loadFired == 2) {
LoadSavegame(playerDisk!!, worldDisk)
LoadSavegame(UILoadGovernor.playerDisk!!, UILoadGovernor.worldDisk)
}
}
else {
@@ -327,7 +359,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
batch.draw(saveTex, (width - uiWidth - 10) / 2f, 0f)
// draw texts
val loadGameTitleStr = Lang["MENU_IO_LOAD"]
val loadGameTitleStr = Lang[titles[mode]] + "$EMDASH$hash"
// "Game Load"
App.fontGame.draw(batch, loadGameTitleStr, (width - App.fontGame.getWidth(loadGameTitleStr)).div(2).toFloat(), titleTextPosY.toFloat())
// Control help
@@ -445,7 +477,7 @@ class UIItemPlayerCells(
private var thumb: TextureRegion? = null
override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int ->
parent.playerDisk = skimmer
UILoadGovernor.playerDisk = skimmer
parent.advanceMode()
}
@@ -641,7 +673,7 @@ class UIItemWorldCells(
}
override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int ->
parent.worldDisk = skimmer
UILoadGovernor.worldDisk = skimmer
parent.advanceMode()
}

View File

@@ -73,7 +73,7 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
printdbg(this, "generate! Size=${sizeSelector.selection}, Name=${nameInput.getTextOrPlaceholder()}, Seed=${seedInput.getTextOrPlaceholder()}")
}
backButton.touchDownListener = { _, _, _, _ ->
printdbg(this, "back!")
remoCon.openUI(UILoadDemoSavefiles(remoCon, 1))
}
addUIitem(sizeSelector)

View File

@@ -43,6 +43,8 @@ open class UIRemoCon(val parent: TitleScreen, val treeRoot: QNDTreeNode<String>)
registerUIclasses(treeRoot)
}
var currentRemoConLabelCount = 0; private set
private fun registerUIclasses(tree: QNDTreeNode<String>) {
tree.traversePreorder { node, _ ->
val splittedNodeName = node.data?.split(yamlSep)
@@ -72,6 +74,7 @@ open class UIRemoCon(val parent: TitleScreen, val treeRoot: QNDTreeNode<String>)
private fun generateNewRemoCon(node: QNDTreeNode<String>): UIRemoConElement {
val labels = Array(node.children.size) { node.children[it].data?.split(yamlSep)?.get(0)?.split(tagSep)?.get(0) ?: "(null)" }
val tags = Array(node.children.size) { arrayOf(node.children[it].data?.split(yamlSep)?.get(0)?.split(tagSep)?.getOrNull(1) ?: "") }
currentRemoConLabelCount = labels.size
return UIRemoConElement(this, labels, tags)
}
@@ -189,6 +192,20 @@ open class UIRemoCon(val parent: TitleScreen, val treeRoot: QNDTreeNode<String>)
}
}
fun openUI(external: UICanvas) {
openUI?.let {
it.setAsClose()
it.dispose()
}
printdbg(this, "Displaying external UI ${external.javaClass.canonicalName}")
external.setPosition(0,0)
parent.uiFakeBlurOverlay.setAsOpen()
external.setAsOpen()
openUI = external
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
remoConTray.render(batch, camera)
openUI?.render(batch, camera)
@@ -253,8 +270,10 @@ open class UIRemoCon(val parent: TitleScreen, val treeRoot: QNDTreeNode<String>)
class UIRemoConElement(uiRemoCon: UIRemoCon, val labels: Array<String>, val tags: Array<Array<String>>) {
private val lineHeight = 36
private val paddingLeft = 48
companion object {
const val lineHeight = 36
const val paddingLeft = 48
}
private val menubar = UIItemTextButtonList(
uiRemoCon,

View File

@@ -76,7 +76,7 @@ open class UIItemTransitionContainer(
uis.forEachIndexed { index, ui ->
if (currentPosition > index - 1 + epsilon && currentPosition < index + 1 - epsilon) {
ui.setAsOpen()
if (!ui.isOpened && !ui.isOpening) ui.setAsOpen()
ui.render(batch, camera)
if (debugvals) {
@@ -84,7 +84,7 @@ open class UIItemTransitionContainer(
}
}
else {
ui.setAsClose()
if (!ui.isClosed && !ui.isClosing) ui.setAsClose()
}
}