mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
added missing code pieces
This commit is contained in:
@@ -2,6 +2,7 @@ package net.torvald.terrarum.tests
|
|||||||
|
|
||||||
import com.badlogic.gdx.ApplicationAdapter
|
import com.badlogic.gdx.ApplicationAdapter
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.Input
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
@@ -13,10 +14,7 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
|||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.*
|
||||||
import net.torvald.terrarum.ui.UIItem
|
|
||||||
import net.torvald.terrarum.ui.UIItemTextButton
|
|
||||||
import net.torvald.terrarum.ui.UIItemToggleButton
|
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +51,12 @@ class UIElemTest : ApplicationAdapter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DummyTogglePane : UICanvas() {
|
class DummyTogglePane : UICanvas() {
|
||||||
private val button1 = UIItemToggleButton(this, 10, 10)
|
private val button1 = UIItemToggleButton(this, 0, 0)
|
||||||
|
|
||||||
|
private val key1 = UIItemConfigKeycap(this, 0, 20, 4, Input.Keys.A)
|
||||||
|
private val key2 = UIItemConfigKeycap(this, 36, 20, 4, Input.Keys.S)
|
||||||
|
private val key3 = UIItemConfigKeycap(this, 36*2, 20, 4, Input.Keys.D)
|
||||||
|
private val key4 = UIItemConfigKeycap(this, 36*3, 20, 4, Input.Keys.F)
|
||||||
|
|
||||||
override var width = 100
|
override var width = 100
|
||||||
override var height = 25
|
override var height = 25
|
||||||
@@ -62,21 +65,29 @@ class DummyTogglePane : UICanvas() {
|
|||||||
|
|
||||||
private var timer = 0f
|
private var timer = 0f
|
||||||
|
|
||||||
|
init {
|
||||||
|
uiItems.add(button1)
|
||||||
|
uiItems.add(key1)
|
||||||
|
uiItems.add(key2)
|
||||||
|
uiItems.add(key3)
|
||||||
|
uiItems.add(key4)
|
||||||
|
}
|
||||||
|
|
||||||
override fun updateUI(delta: Float) {
|
override fun updateUI(delta: Float) {
|
||||||
timer += delta
|
timer += delta
|
||||||
|
|
||||||
if (timer >= 1.5f) {
|
if (timer >= 1f) {
|
||||||
timer -= 1.5f
|
timer -= 1f
|
||||||
button1.toggle()
|
button1.toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
button1.update(delta)
|
uiItems.forEach { it.update(delta) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
batch.color = Color(0x404040ff)
|
|
||||||
button1.render(batch, camera)
|
uiItems.forEach { it.render(batch, camera) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Camera
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
|
import net.torvald.terrarum.imagefont.TinyAlphNum
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,14 +19,14 @@ class UIItemConfigKeycap(
|
|||||||
private val keySize: Int,
|
private val keySize: Int,
|
||||||
|
|
||||||
private val keycode: Int, // also used to draw key label
|
private val keycode: Int, // also used to draw key label
|
||||||
private var keyItem: Int // internal index for the key's behaviour, also used to choose appropriate icon
|
private var keyItem: Int? = null // internal index for the key's behaviour, also used to choose appropriate icon
|
||||||
) : UIItem(parent) {
|
) : UIItem(parent) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (keySize < 3) throw IllegalArgumentException("Key size must be greater than 2 (got $keySize)")
|
if (keySize < 3) throw IllegalArgumentException("Key size must be greater than 2 (got $keySize)")
|
||||||
|
|
||||||
CommonResourcePool.addToLoadingList("ui_item_keymap_keycap") {
|
CommonResourcePool.addToLoadingList("ui_item_keymap_keycap") {
|
||||||
TextureRegionPack("./assets/graphics/gui/ui_config_keymap_keycap.tga", 4, 32)
|
TextureRegionPack("./assets/graphics/gui/ui_config_keymap_keycap.tga", 8, 32)
|
||||||
}
|
}
|
||||||
CommonResourcePool.loadAll()
|
CommonResourcePool.loadAll()
|
||||||
}
|
}
|
||||||
@@ -51,13 +52,17 @@ class UIItemConfigKeycap(
|
|||||||
batch.draw(capTex.get(2, 0), (posX + (keySize - 1) * capTex.tileW).toFloat(), posY.toFloat())
|
batch.draw(capTex.get(2, 0), (posX + (keySize - 1) * capTex.tileW).toFloat(), posY.toFloat())
|
||||||
|
|
||||||
// draw label
|
// draw label
|
||||||
AppLoader.fontSmallNumbers.draw(batch, KeyDict.keycodeToLabel[keycode]!!, posX + 2f, posY + 2f)
|
TinyAlphNum.draw(batch, KeyDict.keycodeToLabel[keycode]!!, posX + 2f, posY + 2f)
|
||||||
|
|
||||||
// draw icon
|
// draw icon
|
||||||
|
|
||||||
|
|
||||||
super.render(batch, camera)
|
super.render(batch, camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -201,7 +206,7 @@ object KeyDict {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
keyDict.forEach {
|
keyDict.forEach {
|
||||||
keycodeToLabel[it[1]] = it[2]
|
keycodeToLabel[it[1] as Int] = it[2] as String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user