more remoCon thingies

This commit is contained in:
minjaesong
2018-08-30 21:30:39 +09:00
parent ad26b0f80c
commit 0658d95b12
9 changed files with 241 additions and 219 deletions

View File

@@ -23,7 +23,6 @@ import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.ui.UIRemoCon import net.torvald.terrarum.modulebasegame.ui.UIRemoCon
import net.torvald.terrarum.serialise.ReadLayerData import net.torvald.terrarum.serialise.ReadLayerData
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.modulebasegame.ui.UITitleRemoConRoot
import net.torvald.terrarum.modulebasegame.ui.UITitleRemoConYaml import net.torvald.terrarum.modulebasegame.ui.UITitleRemoConYaml
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.* import net.torvald.terrarum.worlddrawer.*

View File

@@ -16,7 +16,7 @@ import kotlin.collections.ArrayList
/** /**
* Created by minjaesong on 2018-08-29. * Created by minjaesong on 2018-08-29.
*/ */
class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() { open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
override var openCloseTime = 0f override var openCloseTime = 0f
@@ -28,14 +28,38 @@ class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
get() = remoConTray.height get() = remoConTray.height
set(value) {} set(value) {}
private val screens = ArrayList<Pair<String, UICanvas>>()
private val yamlSep = Regex(" : ")
init { init {
remoConTray = generateNewRemoCon(currentRemoConContents) remoConTray = generateNewRemoCon(currentRemoConContents)
treeRepresentation.traversePreorder { node, _ ->
val splittedNodeName = node.data?.split(yamlSep)
if (splittedNodeName?.size == 2) {
val attachedClass = loadClass(splittedNodeName[1])
attachedClass.posX = 0
attachedClass.posY = 0
screens.add((node.data ?: "(null)") to attachedClass)
}
}
}
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 */)
return newClassInstance as UICanvas
} }
private var mouseActionAvailable = true private var mouseActionAvailable = true
private fun generateNewRemoCon(node: QNDTreeNode<String>): UIRemoConElement { private fun generateNewRemoCon(node: QNDTreeNode<String>): UIRemoConElement {
val dynamicStrArray = Array(node.children.size, { node.children[it].data ?: "(null)" }) val dynamicStrArray = Array(node.children.size, { node.children[it].data?.split(yamlSep)?.get(0) ?: "(null)" })
return UIRemoConElement(this, dynamicStrArray) return UIRemoConElement(this, dynamicStrArray)
} }
@@ -50,7 +74,11 @@ class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
val selectedIndex = remoConTray.selectedIndex val selectedIndex = remoConTray.selectedIndex
selectedItem?.let { selectedItem?.let {
if (it.labelText == "MENU_LABEL_RETURN") { // selection change
if (it.labelText == "MENU_LABEL_QUIT") {
System.exit(0)
}
else if (it.labelText == "MENU_LABEL_RETURN") {
if (currentRemoConContents.parent != null) { if (currentRemoConContents.parent != null) {
remoConTray.consume() remoConTray.consume()
@@ -79,6 +107,23 @@ class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
throw RuntimeException("Index: $selectedIndex, Size: ${currentRemoConContents.children.size}") throw RuntimeException("Index: $selectedIndex, Size: ${currentRemoConContents.children.size}")
} }
} }
// do something with the actual selection
println(currentRemoConContents.data)
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.setAsOpen()
}
else {
it.second.setAsClose()
}
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
}
} }
@@ -90,6 +135,11 @@ class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
remoConTray.render(batch, camera) remoConTray.render(batch, camera)
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.render(batch, camera) // again, underlying handler will block unnecessary renders
}
}
} }
override fun doOpening(delta: Float) { override fun doOpening(delta: Float) {
@@ -112,6 +162,88 @@ class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
} }
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.mouseMoved(screenX, screenY) // again, underlying handler will block unnecessary renders
}
}
return true
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.touchDragged(screenX, screenY, pointer) // again, underlying handler will block unnecessary renders
}
}
return true
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.touchDown(screenX, screenY, pointer, button) // again, underlying handler will block unnecessary renders
}
}
return true
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.touchUp(screenX, screenY, pointer, button) // again, underlying handler will block unnecessary renders
}
}
return true
}
override fun scrolled(amount: Int): Boolean {
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.scrolled(amount) // again, underlying handler will block unnecessary renders
}
}
return true
}
override fun keyDown(keycode: Int): Boolean {
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.keyDown(keycode) // again, underlying handler will block unnecessary renders
}
}
return true
}
override fun keyUp(keycode: Int): Boolean {
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.keyUp(keycode) // again, underlying handler will block unnecessary renders
}
}
return true
}
override fun keyTyped(character: Char): Boolean {
screens.forEach {
if (currentRemoConContents.data == it.first) {
it.second.keyTyped(character) // again, underlying handler will block unnecessary renders
}
}
return true
}
class UIRemoConElement(uiRemoCon: UIRemoCon, val labels: Array<String>) { class UIRemoConElement(uiRemoCon: UIRemoCon, val labels: Array<String>) {

View File

@@ -14,39 +14,19 @@ import net.torvald.terrarum.ui.UIItemTextButtonList
/** /**
* Created by minjaesong on 2017-08-01. * Created by minjaesong on 2017-08-01.
*/ */
class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() { class UITitleModules : UICanvas() {
val menuLabels = arrayOf(
"MENU_LABEL_RETURN"
)
override var width: Int = UITitleRemoConRoot.remoConWidth
override var height: Int = UITitleRemoConRoot.getRemoConHeight(menuLabels)
override var openCloseTime: Second = 0f override var openCloseTime: Second = 0f
private val menubar = UIItemTextButtonList(
this,
menuLabels,
0, UITitleRemoConRoot.menubarOffY,
this.width, this.height,
textAreaWidth = this.width,
readFromLang = true,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
)
private val moduleAreaHMargin = 48 private val moduleAreaHMargin = 48
private val moduleAreaBorder = 8 private val moduleAreaBorder = 8
private val moduleAreaWidth = (Terrarum.WIDTH * 0.75).toInt() - moduleAreaHMargin override var width = (Terrarum.WIDTH * 0.75).toInt() - moduleAreaHMargin
private val moduleAreaHeight = Terrarum.HEIGHT - moduleAreaHMargin * 2 override var height = Terrarum.HEIGHT - moduleAreaHMargin * 2
private val moduleInfoCells = ArrayList<UIItemModuleInfoCell>() private val moduleInfoCells = ArrayList<UIItemModuleInfoCell>()
// build module list // build module list
@@ -55,7 +35,7 @@ class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() {
moduleInfoCells.add(UIItemModuleInfoCell( moduleInfoCells.add(UIItemModuleInfoCell(
this, this,
it.first, it.first,
moduleAreaWidth - 2 * moduleAreaBorder, width - 2 * moduleAreaBorder,
0, 0 // placeholder 0, 0 // placeholder
)) ))
} }
@@ -65,41 +45,22 @@ class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() {
this, this,
moduleInfoCells, moduleInfoCells,
(Terrarum.WIDTH * 0.25f).toInt(), moduleAreaHMargin, (Terrarum.WIDTH * 0.25f).toInt(), moduleAreaHMargin,
moduleAreaWidth, width,
moduleAreaHeight, height,
inactiveCol = Color.WHITE, inactiveCol = Color.WHITE,
border = moduleAreaBorder border = moduleAreaBorder
) )
init { init {
uiItems.add(menubar)
uiItems.add(mouduleArea) uiItems.add(mouduleArea)
////////////////////////////
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
menubar.selectedIndex = menubar.defaultSelection
superMenu.setAsOpen()
}
} }
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {
menubar.update(delta)
mouduleArea.update(delta) mouduleArea.update(delta)
} }
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch, camera)
batch.color = Color.WHITE batch.color = Color.WHITE
blendNormal() blendNormal()
mouduleArea.render(batch, camera) mouduleArea.render(batch, camera)

View File

@@ -1,116 +0,0 @@
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.terrarum.CreditSingleton
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.Second
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextArea
import net.torvald.terrarum.ui.UIItemTextButtonList
class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
val menuLabels = arrayOf(
"MENU_LABEL_CREDITS",
"MENU_CREDIT_GPL_DNT",
"MENU_LABEL_RETURN"
)
override var width: Int = UITitleRemoConRoot.remoConWidth
override var height: Int = UITitleRemoConRoot.getRemoConHeight(menuLabels)
override var openCloseTime: Second = 0f
private val textAreaHMargin = 48
private val textAreaWidth = (Terrarum.WIDTH * 0.75).toInt()
private val textAreaHeight = Terrarum.HEIGHT - textAreaHMargin * 2
private val textArea = UIItemTextArea(this,
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
textAreaWidth, textAreaHeight
)
private var drawTextArea = true
private val menubar = UIItemTextButtonList(
this,
menuLabels,
0, UITitleRemoConRoot.menubarOffY,
this.width, this.height,
textAreaWidth = this.width,
readFromLang = true,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = 0 // show CREDITS
)
init {
uiItems.add(menubar)
uiItems.add(textArea)
////////////////////////////
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
menubar.selectedIndex = menubar.defaultSelection
superMenu.setAsOpen()
}
menubar.selectionChangeListener = { _, newIndex ->
textArea.scrollPos = 0
if (newIndex == menuLabels.indexOf("MENU_LABEL_CREDITS")) {
textArea.setWallOfText(CreditSingleton.credit)
drawTextArea = true
}
else if (newIndex == menuLabels.indexOf("MENU_CREDIT_GPL_DNT")) {
textArea.setWallOfText(CreditSingleton.gpl3)
drawTextArea = true
}
else {
drawTextArea = false
}
}
}
override fun updateUI(delta: Float) {
menubar.update(delta)
if (drawTextArea) {
textArea.update(delta)
}
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch, camera)
if (drawTextArea) {
batch.color = Color.WHITE
textArea.render(batch, camera)
}
}
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

@@ -17,40 +17,19 @@ class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
) )
override var width: Int = UITitleRemoConRoot.remoConWidth
override var height: Int = UITitleRemoConRoot.getRemoConHeight(menuLabels)
override var openCloseTime: Second = 0f override var openCloseTime: Second = 0f
private val menubar = UIItemTextButtonList(
this,
menuLabels,
0, UITitleRemoConRoot.menubarOffY,
this.width, this.height,
textAreaWidth = this.width,
readFromLang = true,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
)
private val textAreaHMargin = 48 private val textAreaHMargin = 48
private val textAreaWidth = (Terrarum.WIDTH * 0.75).toInt() override var width = (Terrarum.WIDTH * 0.75).toInt()
private val textAreaHeight = Terrarum.HEIGHT - textAreaHMargin * 2 override var height = Terrarum.HEIGHT - textAreaHMargin * 2
/*private val textArea = UIItemTextArea(this,
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
textAreaWidth, textAreaHeight,
align = UIItemTextArea.Align.CENTRE
)*/
private val localeList = Lang.languageList.toList().sorted() private val localeList = Lang.languageList.toList().sorted()
private val textArea = UIItemTextButtonList(this, private val textArea = UIItemTextButtonList(this,
localeList.map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }.toTypedArray(), localeList.map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }.toTypedArray(),
Terrarum.WIDTH - textAreaWidth, textAreaHMargin, Terrarum.WIDTH - width, textAreaHMargin,
textAreaWidth, textAreaHeight, width, height,
textAreaWidth = textAreaWidth, textAreaWidth = width,
readFromLang = false, readFromLang = false,
activeBackCol = Color(0), activeBackCol = Color(0),
highlightBackCol = Color(0), highlightBackCol = Color(0),
@@ -61,7 +40,6 @@ class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
init { init {
uiItems.add(menubar)
//textArea.entireText = Lang.languageList.toList().sorted().map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" } //textArea.entireText = Lang.languageList.toList().sorted().map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }
@@ -76,21 +54,14 @@ class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
AppLoader.GAME_LOCALE = localeList[newSelectionIndex] AppLoader.GAME_LOCALE = localeList[newSelectionIndex]
} }
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
menubar.selectedIndex = menubar.defaultSelection
superMenu.setAsOpen()
}
} }
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {
menubar.update(delta)
textArea.update(delta) textArea.update(delta)
} }
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch, camera)
batch.color = Color.WHITE batch.color = Color.WHITE
textArea.render(batch, camera) textArea.render(batch, camera)

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.BuildingMaker
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButtonList import net.torvald.terrarum.ui.UIItemTextButtonList
class UITitleRemoConRoot : UICanvas() { /*class UITitleRemoConRoot : UICanvas() {
companion object { companion object {
val remoConWidth = 240 val remoConWidth = 240
@@ -63,7 +63,7 @@ class UITitleRemoConRoot : UICanvas() {
private val remoConCredits = UITitleRemoConCredits(this) private val remoConCredits = UITitleRemoConCredits(this)
private val remoConLanguage = UITitleRemoConLanguage(this) private val remoConLanguage = UITitleRemoConLanguage(this)
private val remoConModules = UITitleRemoConModules(this) private val remoConModules = UITitleModules(this)
init { init {
remoConLanguage.setPosition(0, 0) remoConLanguage.setPosition(0, 0)
@@ -159,4 +159,4 @@ class UITitleRemoConRoot : UICanvas() {
} }
} }*/

View File

@@ -6,7 +6,7 @@ import java.util.*
object UITitleRemoConYaml { object UITitleRemoConYaml {
// YAML indent with a space! // YAML indent with a space, separate label and class with " : " verbatim!
val menus = """ val menus = """
- MENU_MODE_SINGLEPLAYER - MENU_MODE_SINGLEPLAYER
@@ -18,13 +18,13 @@ object UITitleRemoConYaml {
- MENU_OPTIONS_CONTROLS - MENU_OPTIONS_CONTROLS
- MENU_OPTIONS_SOUND - MENU_OPTIONS_SOUND
- MENU_LABEL_RETURN - MENU_LABEL_RETURN
- MENU_MODULES - MENU_MODULES : net.torvald.terrarum.modulebasegame.ui.UITitleModules
- MENU_LABEL_RETURN - MENU_LABEL_RETURN
- MENU_LABEL_LANGUAGE - MENU_LABEL_LANGUAGE
- MENU_LABEL_RETURN - MENU_LABEL_RETURN
- MENU_LABEL_CREDITS - MENU_LABEL_CREDITS : net.torvald.terrarum.modulebasegame.ui.UITitleCredits
- MENU_LABEL_CREDITS - MENU_LABEL_CREDITS : net.torvald.terrarum.modulebasegame.ui.UITitleCredits
- MENU_CREDIT_GPL_DNT - MENU_CREDIT_GPL_DNT : net.torvald.terrarum.modulebasegame.ui.UITitleGPL3
- MENU_LABEL_RETURN - MENU_LABEL_RETURN
- MENU_LABEL_QUIT - MENU_LABEL_QUIT
""".trimIndent() """.trimIndent()
@@ -74,16 +74,11 @@ object UITitleRemoConYaml {
// test traverse resulting tree // test traverse resulting tree
fun preorder(node: QNDTreeNode<String>, depth: Int = 1) { /*root.traversePreorder { node, depth ->
//if (node == null) return repeat(depth + 1) { print("-") }
repeat(depth) { print("-") }
println("${node.data} -> ${node.parent}") println("${node.data} -> ${node.parent}")
}*/
node.children.forEach { preorder(it, depth + 1) }
}
preorder(root)
return root return root
} }
@@ -103,4 +98,25 @@ object UITitleRemoConYaml {
class QNDTreeNode<T>(var data: T? = null, var parent: QNDTreeNode<T>? = null) { class QNDTreeNode<T>(var data: T? = null, var parent: QNDTreeNode<T>? = null) {
var children = ArrayList<QNDTreeNode<T>>() var children = ArrayList<QNDTreeNode<T>>()
private fun traverse1(node: QNDTreeNode<T>, action: (QNDTreeNode<T>, Int) -> Unit, depth: Int = 0) {
//if (node == null) return
action(node, depth)
node.children.forEach { traverse1(it, action, depth + 1) }
}
private fun traverse2(node: QNDTreeNode<T>, action: (QNDTreeNode<T>, Int) -> Unit, depth: Int = 0) {
//if (node == null) return
node.children.forEach { traverse2(it, action, depth + 1) }
action(node, depth)
}
fun traversePreorder(action: (QNDTreeNode<T>, Int) -> Unit) {
this.traverse1(this, action)
}
fun traversePostorder(action: (QNDTreeNode<T>, Int) -> Unit) {
this.traverse2(this, action)
}
} }

View File

@@ -0,0 +1,59 @@
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.terrarum.CreditSingleton
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.Second
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextArea
import net.torvald.terrarum.ui.UIItemTextButtonList
open class UITitleWallOfText(text: List<String>) : UICanvas() {
override var openCloseTime: Second = 0f
private val textAreaHMargin = 48
override var width = (Terrarum.WIDTH * 0.75).toInt()
override var height = Terrarum.HEIGHT - textAreaHMargin * 2
private val textArea = UIItemTextArea(this,
Terrarum.WIDTH - width, textAreaHMargin,
width, height
)
init {
uiItems.add(textArea)
textArea.setWallOfText(text)
}
override fun updateUI(delta: Float) {
textArea.update(delta)
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
batch.color = Color.WHITE
textArea.render(batch, camera)
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
}
}
class UITitleCredits : UITitleWallOfText(CreditSingleton.credit)
class UITitleGPL3 : UITitleWallOfText(CreditSingleton.gpl3)

View File

@@ -23,7 +23,7 @@ class UIItemTextArea(
var entireText: List<String> = listOf("") // placeholder private var entireText: List<String> = listOf("") // placeholder
var scrollPos = 0 var scrollPos = 0