mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
text input config panel with keymap preview
This commit is contained in:
@@ -24,7 +24,7 @@ object Toolkit : Disposable {
|
||||
|
||||
object Theme {
|
||||
val COL_INVENTORY_CELL_BORDER = Color(1f, 1f, 1f, 0.25f)
|
||||
val COL_CELL_FILL = Color(0x28282888)
|
||||
val COL_CELL_FILL = Color(0x282828C8)
|
||||
|
||||
val COL_LIST_DEFAULT = Color.WHITE
|
||||
val COL_INACTIVE = Color.LIGHT_GRAY
|
||||
|
||||
@@ -118,12 +118,24 @@ class UIItemTextLineInput(
|
||||
private val btn1PosX = posX + width - 2*WIDTH_ONEBUTTON - 3
|
||||
private val btn2PosX = posX + width - WIDTH_ONEBUTTON
|
||||
|
||||
var mouseoverUpdateLatch = false
|
||||
set(value) {
|
||||
field = value
|
||||
if (!value) {
|
||||
mouseLatched = false
|
||||
fboUpdateLatch = false
|
||||
isActive = false
|
||||
cursorOn = false
|
||||
cursorBlinkCounter = 0f
|
||||
}
|
||||
}
|
||||
|
||||
private val mouseUpOnTextArea: Boolean
|
||||
get() = relativeMouseX in 0 until fbo.width + 2* UI_TEXT_MARGIN && relativeMouseY in 0 until height
|
||||
get() = mouseoverUpdateLatch && relativeMouseX in 0 until fbo.width + 2* UI_TEXT_MARGIN && relativeMouseY in 0 until height
|
||||
private val mouseUpOnButton1
|
||||
get() = buttonsShown > 1 && relativeMouseX in btn1PosX - posX until btn1PosX - posX + WIDTH_ONEBUTTON && relativeMouseY in 0 until height
|
||||
get() = mouseoverUpdateLatch && buttonsShown > 1 && relativeMouseX in btn1PosX - posX until btn1PosX - posX + WIDTH_ONEBUTTON && relativeMouseY in 0 until height
|
||||
private val mouseUpOnButton2
|
||||
get() = buttonsShown > 0 && relativeMouseX in btn2PosX - posX until btn2PosX - posX + WIDTH_ONEBUTTON && relativeMouseY in 0 until height
|
||||
get() = mouseoverUpdateLatch && buttonsShown > 0 && relativeMouseX in btn2PosX - posX until btn2PosX - posX + WIDTH_ONEBUTTON && relativeMouseY in 0 until height
|
||||
|
||||
private var imeOn = false
|
||||
private var candidates: List<CodepointSequence> = listOf()
|
||||
@@ -177,10 +189,7 @@ class UIItemTextLineInput(
|
||||
val ime = getIME()
|
||||
val lowLayer = IME.getLowLayerByName(App.getConfigString("basekeyboardlayout"))
|
||||
|
||||
if (keycodes.contains(App.getConfigInt("control_key_toggleime")) && repeatCount == 1) {
|
||||
toggleIME()
|
||||
}
|
||||
else if (keycodes.contains(Input.Keys.V) && keycodes.containsSome(Input.Keys.CONTROL_LEFT, Input.Keys.CONTROL_RIGHT)) {
|
||||
if (keycodes.contains(Input.Keys.V) && keycodes.containsSome(Input.Keys.CONTROL_LEFT, Input.Keys.CONTROL_RIGHT)) {
|
||||
endComposing()
|
||||
paste(Clipboard.fetch().substringBefore('\n').substringBefore('\t').toCodePoints())
|
||||
}
|
||||
@@ -282,35 +291,39 @@ class UIItemTextLineInput(
|
||||
}
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
val mouseDown = Terrarum.mouseDown
|
||||
if (mouseoverUpdateLatch) {
|
||||
super.update(delta)
|
||||
val mouseDown = Terrarum.mouseDown
|
||||
|
||||
if (mouseDown) {
|
||||
isActive = mouseUp
|
||||
}
|
||||
|
||||
if (App.getConfigString("inputmethod") == "none") imeOn = false
|
||||
|
||||
if (isActive) {
|
||||
cursorBlinkCounter += delta
|
||||
|
||||
while (cursorBlinkCounter >= CURSOR_BLINK_TIME) {
|
||||
cursorBlinkCounter -= CURSOR_BLINK_TIME
|
||||
cursorOn = !cursorOn
|
||||
if (mouseDown) {
|
||||
isActive = mouseUp
|
||||
}
|
||||
}
|
||||
|
||||
if (mouseDown && !mouseLatched && (enablePasteButton && enableIMEButton && mouseUpOnButton1 || enableIMEButton && !enablePasteButton && mouseUpOnButton2)) {
|
||||
toggleIME()
|
||||
mouseLatched = true
|
||||
}
|
||||
else if (mouseDown && !mouseLatched && (enablePasteButton && enableIMEButton && mouseUpOnButton2 || enablePasteButton && !enableIMEButton && mouseUpOnButton2)) {
|
||||
endComposing()
|
||||
paste(Clipboard.fetch().substringBefore('\n').substringBefore('\t').toCodePoints())
|
||||
mouseLatched = true
|
||||
}
|
||||
if (App.getConfigString("inputmethod") == "none") imeOn = false
|
||||
|
||||
if (!mouseDown) mouseLatched = false
|
||||
if (isActive) {
|
||||
cursorBlinkCounter += delta
|
||||
|
||||
while (cursorBlinkCounter >= CURSOR_BLINK_TIME) {
|
||||
cursorBlinkCounter -= CURSOR_BLINK_TIME
|
||||
cursorOn = !cursorOn
|
||||
}
|
||||
}
|
||||
|
||||
if (mouseDown && !mouseLatched && (enablePasteButton && enableIMEButton && mouseUpOnButton1 || enableIMEButton && !enablePasteButton && mouseUpOnButton2)) {
|
||||
toggleIME()
|
||||
mouseLatched = true
|
||||
}
|
||||
else if (mouseDown && !mouseLatched && (enablePasteButton && enableIMEButton && mouseUpOnButton2 || enablePasteButton && !enableIMEButton && mouseUpOnButton2)) {
|
||||
endComposing()
|
||||
paste(Clipboard.fetch().substringBefore('\n').substringBefore('\t').toCodePoints())
|
||||
mouseLatched = true
|
||||
}
|
||||
|
||||
if (!mouseDown) mouseLatched = false
|
||||
|
||||
imeOn = KeyToggler.isOn(App.getConfigInt("control_key_toggleime"))
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.toCodePoints() = this.codePoints().toList().filter { it > 0 }
|
||||
@@ -328,12 +341,8 @@ class UIItemTextLineInput(
|
||||
private fun toggleIME() {
|
||||
endComposing()
|
||||
|
||||
if (App.getConfigString("inputmethod") == "none") {
|
||||
imeOn = false
|
||||
return
|
||||
}
|
||||
|
||||
imeOn = !imeOn
|
||||
KeyToggler.forceSet(App.getConfigInt("control_key_toggleime"), imeOn)
|
||||
}
|
||||
|
||||
private fun resetIME() {
|
||||
|
||||
@@ -33,6 +33,12 @@ class UIItemTextSelector(
|
||||
CommonResourcePool.loadAll()
|
||||
}
|
||||
|
||||
override val mouseUp: Boolean
|
||||
get() = (relativeMouseX in 0 until width && relativeMouseY in 0 until height) or (if (paletteShowing)
|
||||
(relativeMouseX in buttonW+3 until buttonW+3 + palW &&
|
||||
relativeMouseY in palY - posY until palY + palH - posY)
|
||||
else false)
|
||||
|
||||
private val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
|
||||
|
||||
override val height = 24
|
||||
@@ -47,8 +53,17 @@ class UIItemTextSelector(
|
||||
|
||||
var selectionChangeListener: (Int) -> Unit = {}
|
||||
|
||||
private var paletteShowing = false
|
||||
// private var paletteScrollUnit = initialSelection
|
||||
|
||||
|
||||
var paletteShowing = false; private set
|
||||
private val palCursorCol = Toolkit.Theme.COL_INACTIVE.cpy().mul(1f,1f,1f,0.5f)
|
||||
private val palCellHeight = height // must be same as the text area height
|
||||
private val palCursorGap = 6 // preferably multiple of 3
|
||||
private var palX = posX + buttonW + 3
|
||||
private var palY = posY - palCellHeight * selection - palCursorGap
|
||||
private var palW = width - 2*buttonW - 6
|
||||
private var palH = palCellHeight * labelfuns.size + 2*palCursorGap
|
||||
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
@@ -64,6 +79,7 @@ class UIItemTextSelector(
|
||||
0
|
||||
|
||||
if (!mouseLatched && Terrarum.mouseDown) {
|
||||
// TODO if (mouse on palette items)
|
||||
if (mouseOnButton in 1..2) {
|
||||
selection = (selection + (mouseOnButton * 2) - 3) fmod labelfuns.size
|
||||
fboUpdateLatch = true
|
||||
@@ -158,23 +174,21 @@ class UIItemTextSelector(
|
||||
}
|
||||
// palette
|
||||
else {
|
||||
val palX = posX + buttonW + 3
|
||||
val palY = posY - palCellHeight * selection - palCursorGap
|
||||
val palW = width - 2*buttonW - 6
|
||||
val palH = palCellHeight * labelCache.size + 2*palCursorGap
|
||||
palX = posX + buttonW + 3
|
||||
palY = posY - palCellHeight * selection - palCursorGap
|
||||
palH = palCellHeight * labelCache.size + 2*palCursorGap
|
||||
|
||||
// palette background
|
||||
batch.color = Color(128)
|
||||
Toolkit.fillArea(batch, palX-1, palY-1, palW+2, palH+2)
|
||||
batch.color = UIItemTextLineInput.TEXTINPUT_COL_BACKGROUND
|
||||
Toolkit.fillArea(batch, palX, palY, palW, palH)
|
||||
Toolkit.fillArea(batch, palX, palY, palW, palH)
|
||||
|
||||
// cursor
|
||||
batch.color = palCursorCol
|
||||
Toolkit.drawBoxBorder(batch, posX + buttonW + 2, posY - 1, width - 2*buttonW - 4, height + 2)
|
||||
// palette border
|
||||
batch.color = Toolkit.Theme.COL_ACTIVE
|
||||
Toolkit.drawBoxBorder(batch, palX - 1, palY - 1, palW + 2, palH + 2)
|
||||
Toolkit.drawBoxBorder(batch, palX, palY, palW, palH)
|
||||
|
||||
// palette items
|
||||
labelCache.forEachIndexed { index, s ->
|
||||
@@ -190,11 +204,9 @@ class UIItemTextSelector(
|
||||
}
|
||||
|
||||
super.render(batch, camera)
|
||||
|
||||
}
|
||||
|
||||
private val palCursorCol = Toolkit.Theme.COL_INACTIVE.cpy().mul(1f,1f,1f,0.5f)
|
||||
private val palCellHeight = height // must be same as the text area height
|
||||
private val palCursorGap = 6 // preferably multiple of 3
|
||||
|
||||
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||
if (mouseUp) {
|
||||
|
||||
Reference in New Issue
Block a user