mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
graphics config panel; titlescreen no longer updates every single popup ui it contains
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
@@ -35,7 +34,8 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
|
||||
get() = remoConTray.height
|
||||
set(value) {}
|
||||
|
||||
private val screens = ArrayList<Pair<String, UICanvas>>()
|
||||
//private val screens = ArrayList<Pair<String, UICanvas>>()
|
||||
private val screenNames = HashMap<String, String>()
|
||||
|
||||
private val yamlSep = Yaml.SEPARATOR
|
||||
private val tagSep = "+"
|
||||
@@ -45,14 +45,10 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
|
||||
treeRepresentation.traversePreorder { node, _ ->
|
||||
val splittedNodeName = node.data?.split(yamlSep)
|
||||
|
||||
if (splittedNodeName?.size == 2) {
|
||||
if (splittedNodeName?.size == 2 && node.data != null) {
|
||||
try {
|
||||
val attachedClass = loadClass(splittedNodeName[1])
|
||||
|
||||
attachedClass.posX = 0
|
||||
attachedClass.posY = 0
|
||||
|
||||
screens.add((node.data ?: "(null)") to attachedClass)
|
||||
val attachedClass = loadClass(splittedNodeName[1]) // check existance
|
||||
screenNames[node.data!!] = splittedNodeName[1]
|
||||
}
|
||||
catch (e: java.lang.ClassNotFoundException) {
|
||||
printdbgerr(this, "class '${splittedNodeName[1]}' was not found, skipping")
|
||||
@@ -76,108 +72,102 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
|
||||
return UIRemoConElement(this, labels, tags)
|
||||
}
|
||||
|
||||
// currently there's no resetter for this!
|
||||
private var startNewGameCalled = false
|
||||
|
||||
private var oldSelectedItem: UIItemTextButton? = null
|
||||
private var openUI: UICanvas? = null
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
if (mouseActionAvailable) {
|
||||
if (mouseActionAvailable && Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary"))) {
|
||||
mouseActionAvailable = false
|
||||
|
||||
remoConTray.update(delta)
|
||||
|
||||
mouseActionAvailable = false
|
||||
}
|
||||
val selectedItem = remoConTray.selectedItem
|
||||
val selectedIndex = remoConTray.selectedIndex
|
||||
|
||||
val selectedItem = remoConTray.selectedItem
|
||||
val selectedIndex = remoConTray.selectedIndex
|
||||
if (!handler.uiToggleLocked) {
|
||||
selectedItem?.let { if (selectedItem != oldSelectedItem) {
|
||||
oldSelectedItem?.highlighted = false
|
||||
|
||||
if (!handler.uiToggleLocked) {
|
||||
selectedItem?.let {
|
||||
// selection change
|
||||
if (it.labelText == "MENU_LABEL_QUIT") {
|
||||
//System.exit(0)
|
||||
Gdx.app.exit()
|
||||
}
|
||||
else if (it.labelText.startsWith("MENU_LABEL_RETURN")) {
|
||||
val tag = it.tags
|
||||
if (tag.contains("WRITETOCONFIG")) WriteConfig()
|
||||
|
||||
|
||||
if (currentRemoConContents.parent != null) {
|
||||
remoConTray.consume()
|
||||
|
||||
currentRemoConContents = currentRemoConContents.parent!!
|
||||
currentlySelectedRemoConItem = currentRemoConContents.data
|
||||
remoConTray = generateNewRemoCon(currentRemoConContents)
|
||||
|
||||
parent.uiFakeBlurOverlay.setAsClose()
|
||||
// selection change
|
||||
if (it.labelText == "MENU_LABEL_QUIT") {
|
||||
//System.exit(0)
|
||||
Gdx.app.exit()
|
||||
}
|
||||
else {
|
||||
throw NullPointerException("No parent node to return")
|
||||
}
|
||||
}
|
||||
else {
|
||||
// check if target exists
|
||||
//println("current node: ${currentRemoConContents.data}")
|
||||
//currentRemoConContents.children.forEach { println("- ${it.data}") }
|
||||
|
||||
if (currentRemoConContents.children.size > selectedIndex ?: 0x7FFFFFFF) {
|
||||
else if (it.labelText.startsWith("MENU_LABEL_RETURN")) {
|
||||
val tag = it.tags
|
||||
if (tag.contains("WRITETOCONFIG")) WriteConfig()
|
||||
|
||||
|
||||
val newCurrentRemoConContents = currentRemoConContents.children[selectedIndex!!]
|
||||
|
||||
// only go deeper if that node has child to navigate
|
||||
if (currentRemoConContents.children[selectedIndex].children.size != 0) {
|
||||
if (currentRemoConContents.parent != null) {
|
||||
remoConTray.consume()
|
||||
remoConTray = generateNewRemoCon(newCurrentRemoConContents)
|
||||
currentRemoConContents = newCurrentRemoConContents
|
||||
|
||||
currentRemoConContents = currentRemoConContents.parent!!
|
||||
currentlySelectedRemoConItem = currentRemoConContents.data
|
||||
remoConTray = generateNewRemoCon(currentRemoConContents)
|
||||
|
||||
parent.uiFakeBlurOverlay.setAsClose()
|
||||
}
|
||||
else {
|
||||
throw NullPointerException("No parent node to return")
|
||||
}
|
||||
|
||||
currentlySelectedRemoConItem = newCurrentRemoConContents.data
|
||||
}
|
||||
else {
|
||||
throw RuntimeException("Index: $selectedIndex, Size: ${currentRemoConContents.children.size}")
|
||||
// check if target exists
|
||||
//println("current node: ${currentRemoConContents.data}")
|
||||
//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
|
||||
}
|
||||
else {
|
||||
throw RuntimeException("Index: $selectedIndex, Size: ${currentRemoConContents.children.size}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// do something with the actual selection
|
||||
//printdbg(this, "$currentlySelectedRemoConItem")
|
||||
// do something with the actual selection
|
||||
//printdbg(this, "$currentlySelectedRemoConItem")
|
||||
openUI?.setAsClose()
|
||||
openUI?.dispose()
|
||||
|
||||
screens.forEach {
|
||||
//printdbg(this, "> ${it.first}")
|
||||
|
||||
if (currentlySelectedRemoConItem == it.first) {
|
||||
screenNames[currentlySelectedRemoConItem]?.let {
|
||||
val ui = loadClass(it)
|
||||
ui.setPosition(0,0)
|
||||
parent.uiFakeBlurOverlay.setAsOpen()
|
||||
it.second.setAsOpen()
|
||||
|
||||
//printdbg(this, ">> ding - ${it.second.javaClass.canonicalName}")
|
||||
ui.setAsOpen()
|
||||
openUI = ui
|
||||
}
|
||||
else {
|
||||
it.second.setAsClose()
|
||||
}
|
||||
}
|
||||
} }
|
||||
}
|
||||
|
||||
|
||||
oldSelectedItem = remoConTray.selectedItem
|
||||
}
|
||||
|
||||
|
||||
screens.forEach {
|
||||
it.second.update(delta) // update is required anyway
|
||||
// but this is not updateUI, so whenever the UI is completely hidden,
|
||||
// underlying handler will block any update until the UI is open again
|
||||
}
|
||||
openUI?.update(delta)
|
||||
|
||||
|
||||
|
||||
if (!Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
|
||||
if (!Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary"))) {
|
||||
mouseActionAvailable = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
remoConTray.render(batch, camera)
|
||||
|
||||
screens.forEach {
|
||||
it.second.render(batch, camera) // again, underlying handler will block unnecessary renders
|
||||
}
|
||||
openUI?.render(batch, camera)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
@@ -197,62 +187,41 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
|
||||
openUI?.dispose()
|
||||
}
|
||||
|
||||
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||
screens.forEach {
|
||||
it.second.touchDragged(screenX, screenY, pointer) // again, underlying handler will block unnecessary renders
|
||||
}
|
||||
|
||||
openUI?.touchDragged(screenX, screenY, pointer)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
screens.forEach {
|
||||
it.second.touchDown(screenX, screenY, pointer, button) // again, underlying handler will block unnecessary renders
|
||||
}
|
||||
|
||||
openUI?.touchDown(screenX, screenY, pointer, button)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
screens.forEach {
|
||||
it.second.touchUp(screenX, screenY, pointer, button) // again, underlying handler will block unnecessary renders
|
||||
}
|
||||
|
||||
openUI?.touchUp(screenX, screenY, pointer, button)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||
screens.forEach {
|
||||
it.second.scrolled(amountX, amountY) // again, underlying handler will block unnecessary renders
|
||||
}
|
||||
|
||||
openUI?.scrolled(amountX, amountY)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
screens.forEach {
|
||||
it.second.keyDown(keycode) // again, underlying handler will block unnecessary renders
|
||||
}
|
||||
|
||||
openUI?.keyDown(keycode)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyUp(keycode: Int): Boolean {
|
||||
screens.forEach {
|
||||
it.second.keyUp(keycode) // again, underlying handler will block unnecessary renders
|
||||
}
|
||||
|
||||
openUI?.keyUp(keycode)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyTyped(character: Char): Boolean {
|
||||
screens.forEach {
|
||||
it.second.keyTyped(character) // again, underlying handler will block unnecessary renders
|
||||
}
|
||||
|
||||
openUI?.keyTyped(character)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user