diff --git a/assets/graphics/gui/toggler.tga b/assets/graphics/gui/toggler.tga deleted file mode 100644 index 14b0ea51b..000000000 --- a/assets/graphics/gui/toggler.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c689d744b38e69b68f95194f1065e2fa5c0745b69361e8debbf46bb3c0b3a9ee -size 46610 diff --git a/assets/graphics/gui/toggler_back.tga b/assets/graphics/gui/toggler_back.tga index bbe3002f9..33f4d90e7 100644 --- a/assets/graphics/gui/toggler_back.tga +++ b/assets/graphics/gui/toggler_back.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:717a4599ff734abdb6301131e5ed1e6d1f915cd6bd7901aebc122eb8734ee8c0 -size 3218 +oid sha256:f9e930f8554aed90d0a63677d1a92227facac1d11d668b2c132f1d1651f8f319 +size 7218 diff --git a/assets/graphics/gui/toggler_switch.tga b/assets/graphics/gui/toggler_switch.tga index 884b84947..23e1f4d1b 100644 --- a/assets/graphics/gui/toggler_switch.tga +++ b/assets/graphics/gui/toggler_switch.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:aa6d161b17a8d1337e9413d82f460f6afe244dd27e7594e0c52eaaf467ca84ba -size 1388 +oid sha256:815caec2526f759cf62d451351db0f30bc8e18327ef89b5811ba8ae7203ef327 +size 3090 diff --git a/src/net/torvald/UniTextShortcuts.kt b/src/net/torvald/UniTextShortcuts.kt index cd04817df..6097092df 100644 --- a/src/net/torvald/UniTextShortcuts.kt +++ b/src/net/torvald/UniTextShortcuts.kt @@ -7,6 +7,7 @@ package net.torvald const val CURRENCY = 0xA4.toChar() const val MIDDOT = 0xB7.toChar() +const val TIMES = 0xD7.toChar() const val ENDASH = 0x2013.toChar() const val EMDASH = 0x2014.toChar() diff --git a/src/net/torvald/terrarum/modulebasegame/ui/GraphicsControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/GraphicsControlPanel.kt new file mode 100644 index 000000000..637f39117 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/GraphicsControlPanel.kt @@ -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() { + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIKeyboardControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIKeyboardControlPanel.kt index 3f74c351f..d5705ebc3 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIKeyboardControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIKeyboardControlPanel.kt @@ -20,7 +20,7 @@ class UIKeyboardControlPanel : UICanvas() { init { CommonResourcePool.addToLoadingList("inventory_category") { - TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20) + TextureRegionPack("assets/graphics/gui/inventory/category.tga", 20, 20) } CommonResourcePool.loadAll() } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt index cf24a560a..396ef7d0f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt @@ -283,8 +283,8 @@ class UILoadDemoSavefiles : UICanvas() { } override fun dispose() { - shapeRenderer.dispose() - sliderFBO.dispose() + try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {} + try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {} } override fun resize(width: Int, height: Int) { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt index 82e064c5a..ec258ef7d 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt @@ -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>() + //private val screens = ArrayList>() + private val screenNames = HashMap() private val yamlSep = Yaml.SEPARATOR private val tagSep = "+" @@ -45,14 +45,10 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode 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 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