mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
graphics config panel; titlescreen no longer updates every single popup ui it contains
This commit is contained in:
BIN
assets/graphics/gui/toggler.tga
LFS
BIN
assets/graphics/gui/toggler.tga
LFS
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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()
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ object UITitleRemoConYaml {
|
||||
*/
|
||||
private val menuBase = """
|
||||
- MENU_OPTIONS
|
||||
- MENU_LABEL_GRAPHICS
|
||||
- MENU_LABEL_GRAPHICS : net.torvald.terrarum.modulebasegame.ui.GraphicsControlPanel
|
||||
- MENU_OPTIONS_CONTROLS : net.torvald.terrarum.modulebasegame.ui.UIKeyboardControlPanel
|
||||
- MENU_LABEL_LANGUAGE : net.torvald.terrarum.modulebasegame.ui.UITitleLanguage
|
||||
- MENU_MODULES : net.torvald.terrarum.ModOptionsHost
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.toInt
|
||||
@@ -22,23 +23,27 @@ class UIItemToggleButton(
|
||||
|
||||
init {
|
||||
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") {
|
||||
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()
|
||||
}
|
||||
|
||||
override val width: Int
|
||||
get() = togglerBase.width
|
||||
get() = togglerBase.regionWidth
|
||||
override val height: Int
|
||||
get() = togglerBase.height
|
||||
get() = togglerBase.regionHeight
|
||||
|
||||
private var togglerBase = CommonResourcePool.getAsTexture("ui_item_toggler_base")
|
||||
private var togglerHandle = CommonResourcePool.getAsTexture("ui_item_toggler_handle")
|
||||
private var togglerBase = CommonResourcePool.getAsTextureRegion("ui_item_toggler_base")
|
||||
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 animTimer = 0f
|
||||
@@ -64,6 +69,8 @@ class UIItemToggleButton(
|
||||
if (status) setAsFalse() else setAsTrue()
|
||||
}
|
||||
|
||||
// define clickOnceListener by yourself!
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user