UI Remote Controller reworked (now 90% less stupidity)

This commit is contained in:
minjaesong
2018-08-30 17:24:53 +09:00
parent 45bcb7a3b5
commit 6070461da9
25 changed files with 348 additions and 27 deletions

1
.gitignore vendored
View File

@@ -10,3 +10,4 @@ assets/mods/basegame/demoworld.gz
external_resource_packs.zip
.idea/workspace.xml
.tmp*
external_resource_packs.zip

Binary file not shown.

View File

@@ -20,9 +20,11 @@ import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.gameactors.*
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.ui.UIRemoCon
import net.torvald.terrarum.serialise.ReadLayerData
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.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.*
import java.io.FileInputStream
@@ -156,7 +158,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
//FeaturesDrawer.world = demoWorld
uiMenu = UITitleRemoConRoot()
uiMenu = UIRemoCon(UITitleRemoConYaml())//UITitleRemoConRoot()
uiMenu.setPosition(0, 0)
uiMenu.setAsOpen()

View File

@@ -1,8 +1,10 @@
package net.torvald.terrarum.modulebasegame.console
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.swingapp.IMStringReader
//import net.torvald.terrarum.swingapp.IMStringReader
/**
* Created by minjaesong on 2017-02-05.
@@ -11,10 +13,19 @@ import net.torvald.terrarum.swingapp.IMStringReader
internal object JavaIMTest : ConsoleCommand {
override fun execute(args: Array<String>) {
IMStringReader(
/*IMStringReader(
{ Echo("[JavaIMTest -> IMStringReader] $it") }, // send input to Echo
"JavaIMTest"
)
)*/
val inputListener = object : Input.TextInputListener {
override fun input(text: String?) {
Echo("[TextInputText] $text")
}
override fun canceled() {
Echo("[TextInputText] (input canceled)")
}
}
Gdx.input.getTextInput(inputListener, "TextInputTest", "Testing the text input", "type anything!")
}
override fun printUsage() {

View File

@@ -60,16 +60,16 @@ class UIInventoryFull(
val catBarWidth = 330
val catBar = UIItemInventoryCatBar(
val categoryBar = UIItemInventoryCatBar(
this,
(Terrarum.WIDTH - catBarWidth) / 2,
66 + (Terrarum.HEIGHT - internalHeight) / 2,
catBarWidth
)
val catSelection: Int
get() = catBar.selectedIndex
get() = categoryBar.selectedIndex
val catSelectedIcon: Int
get() = catBar.selectedIcon
get() = categoryBar.selectedIcon
override var openCloseTime: Second = 0.0f
@@ -101,12 +101,16 @@ class UIInventoryFull(
init {
addItem(catBar)
addItem(categoryBar)
itemList?.let { addItem(it) }
equipped?.let { addItem(it) }
catBar.selectionChangeListener = { old, new -> rebuildList() }
categoryBar.selectionChangeListener = { old, new ->
rebuildList()
itemList?.itemPage = 0 // set scroll to zero
itemList?.rebuild() // have to manually rebuild, too!
}
@@ -125,7 +129,7 @@ class UIInventoryFull(
}
catBar.update(delta)
categoryBar.update(delta)
itemList?.update(delta)
equipped?.update(delta)
}
@@ -163,7 +167,7 @@ class UIInventoryFull(
batch.begin()
// UI items
catBar.render(batch, camera)
categoryBar.render(batch, camera)
itemList?.render(batch, camera)
equipped?.render(batch, camera)
@@ -221,7 +225,7 @@ class UIInventoryFull(
}
override fun dispose() {
catBar.dispose()
categoryBar.dispose()
itemList?.dispose()
equipped?.dispose()
}

View File

@@ -183,12 +183,12 @@ class UIItemInventoryDynamicList(
}
scrollUpButton.clickOnceListener = { _, _, _ ->
itemPage = (itemPage - 1).fmod(itemPageCount)
itemPage = if (itemPageCount == 0) 0 else (itemPage - 1).fmod(itemPageCount)
scrollUpButton.highlighted = false
rebuild()
}
scrollDownButton.clickOnceListener = { _, _, _ ->
itemPage = (itemPage + 1).fmod(itemPageCount)
itemPage = if (itemPageCount == 0) 0 else (itemPage + 1).fmod(itemPageCount)
scrollDownButton.highlighted = false
rebuild()
}

View File

@@ -0,0 +1,161 @@
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
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButton
import net.torvald.terrarum.ui.UIItemTextButtonList
import java.util.*
import kotlin.collections.ArrayList
/**
* Created by minjaesong on 2018-08-29.
*/
class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
override var openCloseTime = 0f
private var remoConTray: UIRemoConElement // this remocon is dynamically generated
private var currentRemoConContents = treeRepresentation
override var width = remoConWidth
override var height: Int
get() = remoConTray.height
set(value) {}
init {
remoConTray = generateNewRemoCon(currentRemoConContents)
}
private var mouseActionAvailable = true
private fun generateNewRemoCon(node: QNDTreeNode<String>): UIRemoConElement {
val dynamicStrArray = Array(node.children.size, { node.children[it].data ?: "(null)" })
return UIRemoConElement(this, dynamicStrArray)
}
override fun updateUI(delta: Float) {
if (mouseActionAvailable) {
remoConTray.update(delta)
mouseActionAvailable = false
}
val selectedItem = remoConTray.selectedItem
val selectedIndex = remoConTray.selectedIndex
selectedItem?.let {
if (it.labelText == "MENU_LABEL_RETURN") {
if (currentRemoConContents.parent != null) {
remoConTray.consume()
currentRemoConContents = currentRemoConContents.parent!!
remoConTray = generateNewRemoCon(currentRemoConContents)
}
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) {
// only go deeper if that node has child to navigate
if (currentRemoConContents.children[selectedIndex!!].children.size != 0) {
remoConTray.consume()
currentRemoConContents = currentRemoConContents.children[selectedIndex!!]
remoConTray = generateNewRemoCon(currentRemoConContents)
}
}
else {
throw RuntimeException("Index: $selectedIndex, Size: ${currentRemoConContents.children.size}")
}
}
}
if (!Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
mouseActionAvailable = true
}
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
remoConTray.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 UIRemoConElement(uiRemoCon: UIRemoCon, val labels: Array<String>) {
private val menubar = UIItemTextButtonList(
uiRemoCon,
labels,
0, menubarOffY,
uiRemoCon.width, getRemoConHeight(labels),
textAreaWidth = uiRemoCon.width,
readFromLang = true,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
)
fun update(delta: Float) {
menubar.update(delta)
}
fun render(batch: SpriteBatch, camera: Camera) {
menubar.render(batch, camera)
}
// nullifies currently selected item
fun consume() {
menubar.selectedIndex = null
}
/** null if none are selected */
val selectedItem: UIItemTextButton?
get() = menubar.selectedButton
/** null if none are selected */
val selectedIndex: Int?
get() = menubar.selectedIndex
val height = getRemoConHeight(labels)
}
companion object {
val remoConWidth = 280
fun getRemoConHeight(menu: ArrayList<String>) = 36 * menu.size.plus(1)
fun getRemoConHeight(menu: Array<String>) = 36 * menu.size.plus(1)
val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (Terrarum.fontGame.lineHeight * 1.5).toInt()
}
}

View File

@@ -0,0 +1,106 @@
package net.torvald.terrarum.modulebasegame.ui
import java.util.*
object UITitleRemoConYaml {
// YAML indent with a space!
val menus = """
- MENU_MODE_SINGLEPLAYER
- MENU_LABEL_RETURN
- MENU_MODE_MULTIPLAYER
- MENU_LABEL_RETURN
- MENU_OPTIONS
- MENU_OPTIONS_GRAPHICS
- MENU_OPTIONS_CONTROLS
- MENU_OPTIONS_SOUND
- MENU_LABEL_RETURN
- MENU_MODULES
- MENU_LABEL_RETURN
- MENU_LABEL_LANGUAGE
- MENU_LABEL_RETURN
- MENU_LABEL_CREDITS
- MENU_LABEL_CREDITS
- MENU_CREDIT_GPL_DNT
- MENU_LABEL_RETURN
- MENU_LABEL_QUIT
""".trimIndent()
val debugTools = """
- Development Tools $
- Building Maker
""".trimIndent()
operator fun invoke() = parseYamlList(menus)
fun parseYamlList(yaml: String): QNDTreeNode<String> {
var currentIndentLevel = -1
val root = QNDTreeNode<String>()
var currentNode = root
val nodesStack = Stack<QNDTreeNode<String>>()
nodesStack.push(currentNode)
yaml.split('\n') .forEach {
val indentLevel = it.countSpaces()
val it = it.trimIndent()
if (it.startsWith("- ")) {
val nodeName = it.drop(2)
if (indentLevel == currentIndentLevel) {
val sibling = QNDTreeNode(nodeName, currentNode.parent)
currentNode.parent!!.children.add(sibling)
currentNode = sibling
}
else if (indentLevel > currentIndentLevel) {
val childNode = QNDTreeNode(nodeName, currentNode)
currentNode.children.add(childNode)
nodesStack.push(currentNode)
currentNode = childNode
currentIndentLevel = indentLevel
}
else {
repeat(currentIndentLevel - indentLevel) { currentNode = nodesStack.pop() }
currentIndentLevel = indentLevel
val sibling = QNDTreeNode(nodeName, currentNode.parent)
currentNode.parent!!.children.add(sibling)
currentNode = sibling
}
}
}
// test traverse resulting tree
fun preorder(node: QNDTreeNode<String>, depth: Int = 1) {
//if (node == null) return
repeat(depth) { print("-") }
println("${node.data} -> ${node.parent}")
node.children.forEach { preorder(it, depth + 1) }
}
preorder(root)
return root
}
private fun String.countSpaces(): Int {
var c = 0
while (c <= this.length) {
if (this[c] == ' ')
c++
else
break
}
return c
}
}
class QNDTreeNode<T>(var data: T? = null, var parent: QNDTreeNode<T>? = null) {
var children = ArrayList<QNDTreeNode<T>>()
}

View File

@@ -24,6 +24,7 @@ import javax.swing.*
*
* Created by minjaesong on 2017-02-05.
*/
@Deprecated("Use Gdx.input.GetTextInput")
class IMStringReader(feedInput: (String) -> Unit, message: String? = null) : JFrame() {
private val inputArea = JTextField()

View File

@@ -14,6 +14,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
*/
open class UIItemTextButton(
parentUI: UICanvas,
/** Stored text (independent to the Langpack) */
val labelText: String,
override var posX: Int,
override var posY: Int,
@@ -37,6 +38,7 @@ open class UIItemTextButton(
val defaultHighlightCol: Color = Color(0x00f8ff_ff)
}
/** Actually displayed text (changes with the app language) */
val label: String
get() = if (readFromLang) Lang[labelText] else labelText

View File

@@ -25,6 +25,36 @@ When the atmos is dusty, "colours" of sunrise/sunsets are more apparent: when in
Colour of the mie scattering DOES follow the colourimeter observation (orange -> red -> wine bordeaux -> (very short term of) grey -> blueish grey)
Overcast/Rainy sky has following colour temperature (measured three times):
```
Result is XYZ: 809.379324 850.192752 1033.330908, D50 Lab: 220.753889 -4.325124 -56.292269
CCT = 7388K (Delta E 3.094551)
Closest Planckian temperature = 7185K (Delta E 2.752967)
Closest Daylight temperature = 7428K (Delta E 0.462706)
Color Rendering Index (Ra) = 99.1 [ R9 = 92.0 ]
R1 = 99.3 R2 = 99.9 R3 = 99.4 R4 = 99.2 R5 = 99.4 R6 = 99.9 R7 = 98.8
R8 = 97.2 R9 = 92.0 R10 = 99.7 R11 = 99.4 R12 = 99.1 R13 = 99.7 R14 = 99.6
Television Lighting Consistency Index 2012 (Qa) = 99.9
Result is XYZ: 799.049876 839.524181 1015.426500, D50 Lab: 219.759423 -4.379982 -55.308508
CCT = 7344K (Delta E 3.137397)
Closest Planckian temperature = 7142K (Delta E 2.790319)
Closest Daylight temperature = 7381K (Delta E 0.430938)
Color Rendering Index (Ra) = 99.2 [ R9 = 92.1 ]
R1 = 99.4 R2 = 99.9 R3 = 99.4 R4 = 99.2 R5 = 99.4 R6 = 99.9 R7 = 98.8
R8 = 97.3 R9 = 92.1 R10 = 99.7 R11 = 99.4 R12 = 99.2 R13 = 99.7 R14 = 99.6
Television Lighting Consistency Index 2012 (Qa) = 99.9
Result is XYZ: 787.300466 827.265267 1011.192183, D50 Lab: 218.606255 -4.393304 -56.653947
CCT = 7448K (Delta E 3.152185)
Closest Planckian temperature = 7236K (Delta E 2.805598)
Closest Daylight temperature = 7483K (Delta E 0.402978)
Color Rendering Index (Ra) = 99.2 [ R9 = 92.5 ]
R1 = 99.4 R2 = 99.9 R3 = 99.3 R4 = 99.2 R5 = 99.5 R6 = 99.8 R7 = 98.8
R8 = 97.4 R9 = 92.5 R10 = 99.7 R11 = 99.5 R12 = 99.3 R13 = 99.8 R14 = 99.5
Television Lighting Consistency Index 2012 (Qa) = 99.9
```
## Weather effects ##

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.