graphics config panel; titlescreen no longer updates every single popup ui it contains

This commit is contained in:
minjaesong
2021-10-06 14:16:38 +09:00
parent fb13922ad9
commit 5e867f7db3
10 changed files with 213 additions and 127 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -7,6 +7,7 @@ package net.torvald
const val CURRENCY = 0xA4.toChar() const val CURRENCY = 0xA4.toChar()
const val MIDDOT = 0xB7.toChar() const val MIDDOT = 0xB7.toChar()
const val TIMES = 0xD7.toChar()
const val ENDASH = 0x2013.toChar() const val ENDASH = 0x2013.toChar()
const val EMDASH = 0x2014.toChar() const val EMDASH = 0x2014.toChar()

View File

@@ -0,0 +1,112 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.TIMES
import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButton
import net.torvald.terrarum.ui.UIItemToggleButton
/**
* Created by minjaesong on 2021-10-06.
*/
class GraphicsControlPanel : UICanvas() {
override var width = 400
override var height = 400
override var openCloseTime = 0f
private val drawX = (Toolkit.drawWidth - width) / 2
private val drawY = (App.scr.height - height) / 2
private val linegap = 16
private val panelgap = 20
private val options = arrayOf(
arrayOf("fx_dither", "Dither"),
arrayOf("fx_backgroundblur", "Blur"),
arrayOf("fx_streamerslayout", Lang["MENU_OPTION_STREAMERS_LAYOUT"])
)
private val togglers = options.mapIndexed { index, strings ->
UIItemToggleButton(this,
drawX + width - panelgap - 75,
drawY + panelgap - 2 + index * (20 + linegap),
App.getConfigBoolean(options[index][0])
)
}
init {
togglers.forEachIndexed { i, it ->
it.clickOnceListener = { _,_,_ ->
it.toggle()
App.setConfig(options[i][0], it.getStatus())
}
addUIitem(it)
}
}
override fun updateUI(delta: Float) {
uiItems.forEach { it.update(delta) }
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
batch.color = Color.WHITE
Toolkit.drawBoxBorder(batch, drawX, drawY, width, height)
batch.color = CELLCOLOUR_BLACK
Toolkit.fillArea(batch, drawX, drawY, width, height)
batch.color = Color.WHITE
options.forEachIndexed { index, strings ->
App.fontGame.draw(batch, strings[1], drawX + panelgap.toFloat(), drawY + panelgap + index * (20f + linegap))
}
uiItems.forEach { it.render(batch, camera) }
if (App.getConfigBoolean("fx_streamerslayout")) {
val xstart = App.scr.width - App.scr.chatWidth
batch.color = Color(0x00f8ff_40)
Toolkit.fillArea(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2)
batch.color = UIItemTextButton.defaultActiveCol
Toolkit.drawBoxBorder(batch, xstart + 1, 1, App.scr.chatWidth - 2, App.scr.height - 2)
val overlayResTxt = "${App.scr.chatWidth}$TIMES${App.scr.height}"
App.fontGame.draw(batch, overlayResTxt,
(xstart + (App.scr.chatWidth - App.fontGame.getWidth(overlayResTxt)) / 2).toFloat(),
((App.scr.height - App.fontGame.lineHeight) / 2).toFloat()
)
}
}
override fun show() {
super.show()
}
override fun hide() {
super.hide()
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
}
}

View File

@@ -20,7 +20,7 @@ class UIKeyboardControlPanel : UICanvas() {
init { init {
CommonResourcePool.addToLoadingList("inventory_category") { CommonResourcePool.addToLoadingList("inventory_category") {
TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20) TextureRegionPack("assets/graphics/gui/inventory/category.tga", 20, 20)
} }
CommonResourcePool.loadAll() CommonResourcePool.loadAll()
} }

View File

@@ -283,8 +283,8 @@ class UILoadDemoSavefiles : UICanvas() {
} }
override fun dispose() { override fun dispose() {
shapeRenderer.dispose() try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {}
sliderFBO.dispose() try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {}
} }
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {

View File

@@ -1,7 +1,6 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
@@ -35,7 +34,8 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
get() = remoConTray.height get() = remoConTray.height
set(value) {} 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 yamlSep = Yaml.SEPARATOR
private val tagSep = "+" private val tagSep = "+"
@@ -45,14 +45,10 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
treeRepresentation.traversePreorder { node, _ -> treeRepresentation.traversePreorder { node, _ ->
val splittedNodeName = node.data?.split(yamlSep) val splittedNodeName = node.data?.split(yamlSep)
if (splittedNodeName?.size == 2) { if (splittedNodeName?.size == 2 && node.data != null) {
try { try {
val attachedClass = loadClass(splittedNodeName[1]) val attachedClass = loadClass(splittedNodeName[1]) // check existance
screenNames[node.data!!] = splittedNodeName[1]
attachedClass.posX = 0
attachedClass.posY = 0
screens.add((node.data ?: "(null)") to attachedClass)
} }
catch (e: java.lang.ClassNotFoundException) { catch (e: java.lang.ClassNotFoundException) {
printdbgerr(this, "class '${splittedNodeName[1]}' was not found, skipping") 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) 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) { override fun updateUI(delta: Float) {
if (mouseActionAvailable) { if (mouseActionAvailable && Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary"))) {
mouseActionAvailable = false
remoConTray.update(delta) remoConTray.update(delta)
mouseActionAvailable = false val selectedItem = remoConTray.selectedItem
} val selectedIndex = remoConTray.selectedIndex
val selectedItem = remoConTray.selectedItem if (!handler.uiToggleLocked) {
val selectedIndex = remoConTray.selectedIndex selectedItem?.let { if (selectedItem != oldSelectedItem) {
oldSelectedItem?.highlighted = false
if (!handler.uiToggleLocked) { // selection change
selectedItem?.let { if (it.labelText == "MENU_LABEL_QUIT") {
// selection change //System.exit(0)
if (it.labelText == "MENU_LABEL_QUIT") { Gdx.app.exit()
//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()
} }
else { else if (it.labelText.startsWith("MENU_LABEL_RETURN")) {
throw NullPointerException("No parent node to return") val tag = it.tags
} if (tag.contains("WRITETOCONFIG")) WriteConfig()
}
else {
// 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!!] if (currentRemoConContents.parent != null) {
// only go deeper if that node has child to navigate
if (currentRemoConContents.children[selectedIndex].children.size != 0) {
remoConTray.consume() 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 { 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 // do something with the actual selection
//printdbg(this, "$currentlySelectedRemoConItem") //printdbg(this, "$currentlySelectedRemoConItem")
openUI?.setAsClose()
openUI?.dispose()
screens.forEach { screenNames[currentlySelectedRemoConItem]?.let {
//printdbg(this, "> ${it.first}") val ui = loadClass(it)
ui.setPosition(0,0)
if (currentlySelectedRemoConItem == it.first) {
parent.uiFakeBlurOverlay.setAsOpen() parent.uiFakeBlurOverlay.setAsOpen()
it.second.setAsOpen() ui.setAsOpen()
openUI = ui
//printdbg(this, ">> ding - ${it.second.javaClass.canonicalName}")
} }
else { } }
it.second.setAsClose()
}
}
} }
oldSelectedItem = remoConTray.selectedItem
} }
screens.forEach { openUI?.update(delta)
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
}
if (!Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary"))) {
if (!Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
mouseActionAvailable = true mouseActionAvailable = true
} }
} }
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
remoConTray.render(batch, camera) remoConTray.render(batch, camera)
openUI?.render(batch, camera)
screens.forEach {
it.second.render(batch, camera) // again, underlying handler will block unnecessary renders
}
} }
override fun doOpening(delta: Float) { override fun doOpening(delta: Float) {
@@ -197,62 +187,41 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
} }
override fun dispose() { override fun dispose() {
openUI?.dispose()
} }
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
screens.forEach { openUI?.touchDragged(screenX, screenY, pointer)
it.second.touchDragged(screenX, screenY, pointer) // again, underlying handler will block unnecessary renders
}
return true return true
} }
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
screens.forEach { openUI?.touchDown(screenX, screenY, pointer, button)
it.second.touchDown(screenX, screenY, pointer, button) // again, underlying handler will block unnecessary renders
}
return true return true
} }
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
screens.forEach { openUI?.touchUp(screenX, screenY, pointer, button)
it.second.touchUp(screenX, screenY, pointer, button) // again, underlying handler will block unnecessary renders
}
return true return true
} }
override fun scrolled(amountX: Float, amountY: Float): Boolean { override fun scrolled(amountX: Float, amountY: Float): Boolean {
screens.forEach { openUI?.scrolled(amountX, amountY)
it.second.scrolled(amountX, amountY) // again, underlying handler will block unnecessary renders
}
return true return true
} }
override fun keyDown(keycode: Int): Boolean { override fun keyDown(keycode: Int): Boolean {
screens.forEach { openUI?.keyDown(keycode)
it.second.keyDown(keycode) // again, underlying handler will block unnecessary renders
}
return true return true
} }
override fun keyUp(keycode: Int): Boolean { override fun keyUp(keycode: Int): Boolean {
screens.forEach { openUI?.keyUp(keycode)
it.second.keyUp(keycode) // again, underlying handler will block unnecessary renders
}
return true return true
} }
override fun keyTyped(character: Char): Boolean { override fun keyTyped(character: Char): Boolean {
screens.forEach { openUI?.keyTyped(character)
it.second.keyTyped(character) // again, underlying handler will block unnecessary renders
}
return true return true
} }

View File

@@ -13,7 +13,7 @@ object UITitleRemoConYaml {
*/ */
private val menuBase = """ private val menuBase = """
- MENU_OPTIONS - MENU_OPTIONS
- MENU_LABEL_GRAPHICS - MENU_LABEL_GRAPHICS : net.torvald.terrarum.modulebasegame.ui.GraphicsControlPanel
- MENU_OPTIONS_CONTROLS : net.torvald.terrarum.modulebasegame.ui.UIKeyboardControlPanel - MENU_OPTIONS_CONTROLS : net.torvald.terrarum.modulebasegame.ui.UIKeyboardControlPanel
- MENU_LABEL_LANGUAGE : net.torvald.terrarum.modulebasegame.ui.UITitleLanguage - MENU_LABEL_LANGUAGE : net.torvald.terrarum.modulebasegame.ui.UITitleLanguage
- MENU_MODULES : net.torvald.terrarum.ModOptionsHost - MENU_MODULES : net.torvald.terrarum.ModOptionsHost

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.blendNormal import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.toInt import net.torvald.terrarum.toInt
@@ -22,23 +23,27 @@ class UIItemToggleButton(
init { init {
CommonResourcePool.addToLoadingList("ui_item_toggler_base") { CommonResourcePool.addToLoadingList("ui_item_toggler_base") {
Texture(Gdx.files.internal("./assets/graphics/gui/toggler_back.tga")) val t = TextureRegion(Texture(Gdx.files.internal("./assets/graphics/gui/toggler_back.tga")))
t.flip(false, true)
t
} }
CommonResourcePool.addToLoadingList("ui_item_toggler_handle") { CommonResourcePool.addToLoadingList("ui_item_toggler_handle") {
Texture(Gdx.files.internal("./assets/graphics/gui/toggler_switch.tga")) val t = TextureRegion(Texture(Gdx.files.internal("./assets/graphics/gui/toggler_switch.tga")))
t.flip(false, true)
t
} }
CommonResourcePool.loadAll() CommonResourcePool.loadAll()
} }
override val width: Int override val width: Int
get() = togglerBase.width get() = togglerBase.regionWidth
override val height: Int override val height: Int
get() = togglerBase.height get() = togglerBase.regionHeight
private var togglerBase = CommonResourcePool.getAsTexture("ui_item_toggler_base") private var togglerBase = CommonResourcePool.getAsTextureRegion("ui_item_toggler_base")
private var togglerHandle = CommonResourcePool.getAsTexture("ui_item_toggler_handle") private var togglerHandle = CommonResourcePool.getAsTextureRegion("ui_item_toggler_handle")
private var handleTravelDist = togglerBase.width - togglerHandle.width private var handleTravelDist = togglerBase.regionWidth - togglerHandle.regionWidth
private var handlePos = handleTravelDist * status.toInt() private var handlePos = handleTravelDist * status.toInt()
private var animTimer = 0f private var animTimer = 0f
@@ -64,6 +69,8 @@ class UIItemToggleButton(
if (status) setAsFalse() else setAsTrue() if (status) setAsFalse() else setAsTrue()
} }
// define clickOnceListener by yourself!
override fun update(delta: Float) { override fun update(delta: Float) {
super.update(delta) super.update(delta)