load ui to inject remoCon contents to implement its own submenus

This commit is contained in:
minjaesong
2021-10-19 10:54:39 +09:00
parent 917fc04ad8
commit 8c692aa45e
38 changed files with 87 additions and 64 deletions

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.modulebasegame.ui.UIRemoCon
import net.torvald.terrarum.ui.UICanvas
class ModOptionsHost : UICanvas() {
class ModOptionsHost(val remoCon: UIRemoCon) : UICanvas() {
override var openCloseTime: Second = 0f

View File

@@ -15,7 +15,7 @@ import net.torvald.terrarum.ui.UIItemToggleButton
/**
* Created by minjaesong on 2021-10-06.
*/
class GraphicsControlPanel : UICanvas() {
class GraphicsControlPanel(val remoCon: UIRemoCon) : UICanvas() {
override var width = 400
override var height = 400

View File

@@ -74,7 +74,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
)
private val savingUI = UIItemSaving(this, (width - UIItemSaving.WIDTH) / 2, (height - UIItemSaving.HEIGHT) / 2)
private val keyConfigUI = UIKeyboardControlPanel()
private val keyConfigUI = UIKeyboardControlPanel(null)
private var oldScreen = 0
private var screen = 0

View File

@@ -16,7 +16,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2021-09-15.
*/
class UIKeyboardControlPanel : UICanvas() {
class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
init {
CommonResourcePool.addToLoadingList("inventory_category") {

View File

@@ -41,7 +41,7 @@ val SAVE_CELL_HEIGHT = 120
*
* Created by minjaesong on 2021-09-09.
*/
class UILoadDemoSavefiles : UICanvas() {
class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
init {
CommonResourcePool.addToLoadingList("inventory_category") {
@@ -129,8 +129,6 @@ class UILoadDemoSavefiles : UICanvas() {
override fun show() {
try {
val remoCon = (App.getCurrentScreen() as TitleScreen).uiRemoCon
remoCon.handler.lockToggle()
showSpinner = true
@@ -181,11 +179,24 @@ class UILoadDemoSavefiles : UICanvas() {
}
private fun getCells() = if (mode == 0) playerCells else worldCells
private val menuTree = arrayOf(UITitleRemoConYaml.injectedMenuSingleCharSel, UITitleRemoConYaml.injectedMenuSingleWorldSel).map { Yaml(it).parse() }
private var loadFired = 0
private var oldMode = -1
private val remoConParentNode = remoCon.currentRemoConContents
private fun modeChangedHandler(mode: Int) {
remoCon.setNewRemoConContents(menuTree[mode], remoConParentNode)
}
override fun updateUI(delta: Float) {
if (mode < 2) {
if (oldMode != mode) {
modeChangedHandler(mode)
oldMode = mode
}
if (scrollTarget != listScroll) {
if (scrollAnimCounter < scrollAnimLen) {
scrollAnimCounter += delta
@@ -293,7 +304,7 @@ class UILoadDemoSavefiles : UICanvas() {
batch.draw(saveTex, (width - uiWidth - 10) / 2f, 0f)
// draw texts
val loadGameTitleStr = Lang["MENU_IO_LOAD_GAME"]
val loadGameTitleStr = Lang["MENU_IO_LOAD"]
// "Game Load"
App.fontGame.draw(batch, loadGameTitleStr, (width - App.fontGame.getWidth(loadGameTitleStr)).div(2).toFloat(), titleTextPosY.toFloat())
// Control help

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.ui.UICanvas
/**
* Created by minjaesong on 2021-09-13.
*/
class UIProxyLoadLatestSave : UICanvas() {
class UIProxyLoadLatestSave(val remoCon: UIRemoCon) : UICanvas() {
override var width: Int = 0
override var height: Int = 0

View File

@@ -17,7 +17,7 @@ import net.torvald.terrarum.utils.RandomWordsName
/**
* Created by minjaesong on 2018-12-08.
*/
class UIProxyNewRandomGame : UICanvas() {
class UIProxyNewRandomGame(val remoCon: UIRemoCon) : UICanvas() {
override var width: Int = 0
override var height: Int = 0

View File

@@ -59,8 +59,8 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
private fun loadClass(name: String): UICanvas {
val newClass = Class.forName(name)
val newClassConstructor = newClass.getConstructor(/* no args defined */)
val newClassInstance = newClassConstructor.newInstance(/* no args defined */)
val newClassConstructor = newClass.getConstructor(this.javaClass)
val newClassInstance = newClassConstructor.newInstance(this)
return newClassInstance as UICanvas
}
@@ -118,18 +118,7 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
//currentRemoConContents.children.forEach { println("- ${it.data}") }
if (currentRemoConContents.children.size > selectedIndex ?: 0x7FFFFFFF) {
val newCurrentRemoConContents = currentRemoConContents.children[selectedIndex!!]
// only go deeper if that node has child to navigate
if (currentRemoConContents.children[selectedIndex].children.size != 0) {
remoConTray.consume()
remoConTray = generateNewRemoCon(newCurrentRemoConContents)
currentRemoConContents = newCurrentRemoConContents
}
currentlySelectedRemoConItem = newCurrentRemoConContents.data
setNewRemoConContents(currentRemoConContents.children[selectedIndex!!])
}
else {
throw RuntimeException("Index: $selectedIndex, Size: ${currentRemoConContents.children.size}")
@@ -165,6 +154,22 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
}
}
fun setNewRemoConContents(newCurrentRemoConContents: QNDTreeNode<String>, forceSetParent: QNDTreeNode<String>? = null) {
if (forceSetParent != null) {
newCurrentRemoConContents.parent = forceSetParent
}
// only go deeper if that node has child to navigate
if (newCurrentRemoConContents.children.size != 0) {
remoConTray.consume()
remoConTray = generateNewRemoCon(newCurrentRemoConContents)
currentRemoConContents = newCurrentRemoConContents
}
currentlySelectedRemoConItem = newCurrentRemoConContents.data
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
remoConTray.render(batch, camera)
openUI?.render(batch, camera)

View File

@@ -10,7 +10,7 @@ import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButtonList
class UITitleLanguage : UICanvas() {
class UITitleLanguage(val remoCon: UIRemoCon) : UICanvas() {
val menuLabels = arrayOf(
"MENU_LABEL_RETURN"

View File

@@ -11,8 +11,8 @@ object UITitleRemoConYaml {
*
* The class must be the UICanvas
*/
private val menuBase = """
- MENU_LABEL_NEW_GAME : net.torvald.terrarum.modulebasegame.ui.UIProxyNewRandomGame
val menuBase = """
- MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadDemoSavefiles
- MENU_OPTIONS
- MENU_LABEL_GRAPHICS : net.torvald.terrarum.modulebasegame.ui.GraphicsControlPanel
- MENU_OPTIONS_CONTROLS : net.torvald.terrarum.modulebasegame.ui.UIKeyboardControlPanel
@@ -26,18 +26,25 @@ object UITitleRemoConYaml {
- MENU_LABEL_QUIT
"""
private val menuWithSavefile = """
val menuWithSavefile = """
- MENU_LABEL_CONTINUE : net.torvald.terrarum.modulebasegame.ui.UIProxyLoadLatestSave
- MENU_IO_LOAD : net.torvald.terrarum.modulebasegame.ui.UILoadDemoSavefiles
- MENU_LABEL_NEW_WORLD
- MENU_LABEL_RETURN"""
private val menuNewGame = """
"""
val menuNewGame = """
"""
val injectedMenuSingleCharSel = """
- CONTEXT_CHARACTER_NEW
- MENU_LABEL_RETURN
"""
val injectedMenuSingleWorldSel = """
- CONTEXT_WORLD_NEW
- MENU_LABEL_RETURN
"""
operator fun invoke(hasSave: Boolean) =
//Yaml((if (hasSave) menuWithSavefile else menuNewGame) + menuBase).parse()
Yaml((if (true) menuWithSavefile else menuNewGame) + menuBase).parse()
// Yaml((if (hasSave) menuWithSavefile else menuNewGame) + menuBase).parse()
Yaml(menuBase).parse()
}

View File

@@ -56,5 +56,5 @@ open class UITitleWallOfText(private val text: List<String>) : UICanvas() {
}
}
class UITitleCredits : UITitleWallOfText(CreditSingleton.credit)
class UITitleGPL3 : UITitleWallOfText(CreditSingleton.gpl3)
class UITitleCredits(val remoCon: UIRemoCon) : UITitleWallOfText(CreditSingleton.credit)
class UITitleGPL3(val remoCon: UIRemoCon) : UITitleWallOfText(CreditSingleton.gpl3)