mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-15 08:06:06 +09:00
working spinner
This commit is contained in:
Binary file not shown.
@@ -33,6 +33,8 @@ data class TerrarumInputMethod(
|
|||||||
*/
|
*/
|
||||||
object IME {
|
object IME {
|
||||||
|
|
||||||
|
class LayoutNotFound(id: String): NullPointerException("Keyboard layout not found: $id")
|
||||||
|
|
||||||
const val KEYLAYOUT_DIR = "assets/keylayout/"
|
const val KEYLAYOUT_DIR = "assets/keylayout/"
|
||||||
const val KEYLAYOUT_EXTENSION = "key"
|
const val KEYLAYOUT_EXTENSION = "key"
|
||||||
const val IME_EXTENSION = "ime"
|
const val IME_EXTENSION = "ime"
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import net.torvald.terrarum.gamecontroller.IME
|
|||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.linearSearch
|
import net.torvald.terrarum.linearSearch
|
||||||
import net.torvald.terrarum.ui.*
|
import net.torvald.terrarum.ui.*
|
||||||
import net.torvald.terrarum.utils.RandomWordsName
|
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,12 +135,12 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
|||||||
|
|
||||||
private val lowLayerCodes = IME.getAllLowLayers()
|
private val lowLayerCodes = IME.getAllLowLayers()
|
||||||
private val lowLayerNames = lowLayerCodes.map { { IME.getLowLayerByName(it).name } }
|
private val lowLayerNames = lowLayerCodes.map { { IME.getLowLayerByName(it).name } }
|
||||||
private val keyboardLayoutSelection = UIItemTextSelector(this, drawX + width - textSelWidth - 3, 400, lowLayerNames, lowLayerCodes.linearSearch { it == App.getConfigString("basekeyboardlayout") }!!, textSelWidth)
|
private val keyboardLayoutSelection = UIItemTextSelector(this, drawX + width - textSelWidth - 3, 400, lowLayerNames, lowLayerCodes.linearSearch { it == App.getConfigString("basekeyboardlayout") } ?: throw IME.LayoutNotFound(App.getConfigString("basekeyboardlayout")), textSelWidth)
|
||||||
|
|
||||||
private val imeCodes0 = IME.getAllHighLayers()
|
private val imeCodes0 = IME.getAllHighLayers()
|
||||||
private val imeCodes = listOf("none") + IME.getAllHighLayers()
|
private val imeCodes = listOf("none") + IME.getAllHighLayers()
|
||||||
private val imeNames = listOf({"$EMDASH"}) + imeCodes0.map { { IME.getHighLayerByName(it).name } }
|
private val imeNames = listOf({"$EMDASH"}) + imeCodes0.map { { IME.getHighLayerByName(it).name } }
|
||||||
private val imeSelection = UIItemTextSelector(this, drawX + width - textSelWidth - 3, 440, imeNames, imeCodes.linearSearch { it == App.getConfigString("inputmethod") }!!, textSelWidth)
|
private val imeSelection = UIItemTextSelector(this, drawX + width - textSelWidth - 3, 440, imeNames, imeCodes.linearSearch { it == App.getConfigString("inputmethod") } ?: throw IME.LayoutNotFound(App.getConfigString("inputmethod")), textSelWidth)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
131
src/net/torvald/terrarum/ui/UIItemSpinner.kt
Normal file
131
src/net/torvald/terrarum/ui/UIItemSpinner.kt
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
package net.torvald.terrarum.ui
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Camera
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
|
import net.torvald.terrarum.*
|
||||||
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2021-10-23.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class UIItemSpinner(
|
||||||
|
parentUI: UICanvas,
|
||||||
|
initialX: Int, initialY: Int,
|
||||||
|
initialValue: Int,
|
||||||
|
val min: Int,
|
||||||
|
val max: Int,
|
||||||
|
val step: Int,
|
||||||
|
override val width: Int,
|
||||||
|
private val drawBorder: Boolean = true
|
||||||
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
CommonResourcePool.addToLoadingList("inventory_category") {
|
||||||
|
TextureRegionPack("assets/graphics/gui/inventory/category.tga", 20, 20)
|
||||||
|
}
|
||||||
|
CommonResourcePool.loadAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
|
||||||
|
|
||||||
|
override val height = 24
|
||||||
|
private val buttonW = 30
|
||||||
|
|
||||||
|
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, true)
|
||||||
|
|
||||||
|
var value = initialValue.coerceIn(min, max)
|
||||||
|
private var fboUpdateLatch = true
|
||||||
|
|
||||||
|
private var mouseOnButton = 0 // 0: nothing, 1: left, 2: right
|
||||||
|
|
||||||
|
var selectionChangeListener: (Int) -> Unit = {}
|
||||||
|
|
||||||
|
override fun update(delta: Float) {
|
||||||
|
super.update(delta)
|
||||||
|
|
||||||
|
mouseOnButton =
|
||||||
|
if (relativeMouseX in 0..buttonW && relativeMouseY in 0..height)
|
||||||
|
1
|
||||||
|
else if (relativeMouseX in width - buttonW..width && relativeMouseY in 0..height)
|
||||||
|
2
|
||||||
|
else
|
||||||
|
0
|
||||||
|
|
||||||
|
if (!mouseLatched && Terrarum.mouseDown && mouseOnButton != 0) {
|
||||||
|
mouseLatched = true
|
||||||
|
value = (value + step * ((mouseOnButton * 2) - 3)).coerceIn(min, max)
|
||||||
|
fboUpdateLatch = true
|
||||||
|
selectionChangeListener(value)
|
||||||
|
}
|
||||||
|
else if (!Terrarum.mouseDown) mouseLatched = false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|
||||||
|
batch.end()
|
||||||
|
|
||||||
|
if (fboUpdateLatch) {
|
||||||
|
fboUpdateLatch = false
|
||||||
|
fbo.inAction(camera as OrthographicCamera, batch) { batch.inUse {
|
||||||
|
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
|
||||||
|
|
||||||
|
it.color = Color.WHITE
|
||||||
|
val t = "$value"
|
||||||
|
val tw = App.fontGame.getWidth(t)
|
||||||
|
App.fontGameFBO.draw(it, t, (fbo.width - tw) / 2, 0)
|
||||||
|
} }
|
||||||
|
}
|
||||||
|
|
||||||
|
batch.begin()
|
||||||
|
|
||||||
|
if (drawBorder) {
|
||||||
|
batch.color = UIItemTextLineInput.TEXTINPUT_COL_BACKGROUND
|
||||||
|
// left button cell back
|
||||||
|
Toolkit.fillArea(batch, posX, posY, buttonW, height)
|
||||||
|
// text area cell back
|
||||||
|
Toolkit.fillArea(batch, posX + buttonW + 3, posY, width - 2*buttonW - 6, height)
|
||||||
|
// right button cell back
|
||||||
|
Toolkit.fillArea(batch, posX + width - buttonW, posY, buttonW, height)
|
||||||
|
|
||||||
|
// text area border
|
||||||
|
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||||
|
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
|
||||||
|
|
||||||
|
// left button border
|
||||||
|
batch.color = if (mouseOnButton == 1 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
|
||||||
|
else if (mouseOnButton == 1) Toolkit.Theme.COL_ACTIVE else Toolkit.Theme.COL_INACTIVE
|
||||||
|
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, buttonW + 2, height + 2)
|
||||||
|
|
||||||
|
// right button border
|
||||||
|
batch.color = if (mouseOnButton == 2 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
|
||||||
|
else if (mouseOnButton == 2) Toolkit.Theme.COL_ACTIVE else Toolkit.Theme.COL_INACTIVE
|
||||||
|
Toolkit.drawBoxBorder(batch, posX + width - buttonW - 1, posY - 1, buttonW + 2, height + 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// left button icon
|
||||||
|
batch.color = if (mouseOnButton == 1 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
|
||||||
|
else if (mouseOnButton == 1) Toolkit.Theme.COL_ACTIVE else UIItemTextLineInput.TEXTINPUT_COL_TEXT
|
||||||
|
batch.draw(labels.get(9,2), posX + (buttonW - labels.tileW) / 2f, posY + (height - labels.tileH) / 2f)
|
||||||
|
|
||||||
|
// right button icon
|
||||||
|
batch.color = if (mouseOnButton == 2 && mousePushed) Toolkit.Theme.COL_HIGHLIGHT
|
||||||
|
else if (mouseOnButton == 2) Toolkit.Theme.COL_ACTIVE else UIItemTextLineInput.TEXTINPUT_COL_TEXT
|
||||||
|
batch.draw(labels.get(10,2), posX + width - buttonW + (buttonW - labels.tileW) / 2f, posY + (height - labels.tileH) / 2f)
|
||||||
|
|
||||||
|
// draw text
|
||||||
|
batch.color = UIItemTextLineInput.TEXTINPUT_COL_TEXT
|
||||||
|
batch.draw(fbo.colorBufferTexture, posX + buttonW + 3f, posY + 2f, fbo.width.toFloat(), fbo.height.toFloat())
|
||||||
|
|
||||||
|
|
||||||
|
super.render(batch, camera)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
fbo.dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ class UIItemTextSelector(
|
|||||||
override val height = 24
|
override val height = 24
|
||||||
private val buttonW = 30
|
private val buttonW = 30
|
||||||
|
|
||||||
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 54 - 4, height - 4, true)
|
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, true)
|
||||||
|
|
||||||
var selection = intialSelection
|
var selection = intialSelection
|
||||||
private var fboUpdateLatch = true
|
private var fboUpdateLatch = true
|
||||||
@@ -120,7 +120,7 @@ class UIItemTextSelector(
|
|||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
batch.color = UIItemTextLineInput.TEXTINPUT_COL_TEXT
|
batch.color = UIItemTextLineInput.TEXTINPUT_COL_TEXT
|
||||||
batch.draw(fbo.colorBufferTexture, posX + buttonW + 5f, posY + 2f, fbo.width.toFloat(), fbo.height.toFloat())
|
batch.draw(fbo.colorBufferTexture, posX + buttonW + 3f, posY + 2f, fbo.width.toFloat(), fbo.height.toFloat())
|
||||||
|
|
||||||
|
|
||||||
super.render(batch, camera)
|
super.render(batch, camera)
|
||||||
@@ -130,29 +130,3 @@ class UIItemTextSelector(
|
|||||||
fbo.dispose()
|
fbo.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UIItemSpinner(
|
|
||||||
parentUI: UICanvas,
|
|
||||||
initialX: Int, initialY: Int,
|
|
||||||
intialValue: Int,
|
|
||||||
val min: Int,
|
|
||||||
val max: Int,
|
|
||||||
val step: Int,
|
|
||||||
override val width: Int
|
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
|
||||||
|
|
||||||
init {
|
|
||||||
CommonResourcePool.addToLoadingList("inventory_category") {
|
|
||||||
TextureRegionPack("assets/graphics/gui/inventory/category.tga", 20, 20)
|
|
||||||
}
|
|
||||||
CommonResourcePool.loadAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
|
|
||||||
|
|
||||||
override val height = 24
|
|
||||||
|
|
||||||
override fun dispose() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user