text input config panel with keymap preview

This commit is contained in:
minjaesong
2021-11-11 12:09:23 +09:00
parent 7797e1308d
commit 8efe51a248
16 changed files with 227 additions and 137 deletions

Binary file not shown.

View File

@@ -1,4 +1,4 @@
{"n":"Colemak-DH","capslock":"back","t":[[""],[undefined],
{"n":"Colemak Mod\u2013DH","capslock":"back","t":[[""],[undefined],
[undefined],
["<HOME>"],
[undefined],

View File

@@ -344,6 +344,7 @@ let bufAssemble = (isPreview) => {
//let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `${buf[i]}`).join(' ')
return Object.freeze({"n":"두벌식 표준","v":"one","c":"CuriousTo\uA75Bvald",
"t":states.keylayouts.map(it => [it[0],it[1]]),
// return: [displayed output, composed output]
"accept":(headkey,shiftin,altgrin)=>{
let layer = 1*shiftin// + 2*altgrin

View File

@@ -370,6 +370,7 @@ let bufAssemble = (isPreview) => {
}
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
return Object.freeze({"n":"세벌식 3-90","v":"one","c":"CuriousTo\uA75Bvald",
"t":states.keylayouts.map(it => [it[0],it[1]]),
// return: [displayed output, composed output]
"accept":(headkey,shiftin,altgrin)=>{
let layer = 1*shiftin// + 2*altgrin

View File

@@ -65,7 +65,7 @@ let states = {"keylayouts":[[""],[undefined],
[undefined],
["\n"],
["\x08"],
["`","~"],
["¤","~"],
["-","_"],
["=","+"],
["[","{"],
@@ -381,6 +381,7 @@ let bufAssemble = (isPreview) => {
}
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
return Object.freeze({"n":"신세벌식 P2","v":"one","c":"CuriousTo\uA75Bvald",
"t":states.keylayouts.map(it => [it[0],it[1]]),
// return: [displayed output, composed output]
"accept":(headkey,shiftin,altgrin)=>{
let layer = 1*shiftin// + 2*altgrin

View File

@@ -261,6 +261,7 @@ let reset = () => {
let inRange = (s,a,b) => (a <= s && s <= b)
let isDiacritics = (s) => s !== undefined && inRange(s.charCodeAt(0), 0x0300, 0x036F)
return Object.freeze({"n":"Русс. ЙЦУКЕН","v":"none","c":"CuriousTo\uA75Bvald",
"t":states.keylayouts.map(it => [it[0],it[1]]),
// return: [displayed output, composed output]
"accept":(headkey,shiftin,altgrin)=>{
let layer = 1*shiftin// + 2*altgrin

View File

@@ -26,32 +26,32 @@ let states = {"keylayouts":[[""],[undefined],
[undefined],
[undefined],
[undefined],
["a","A"],
["b","B"],
["c","C"],
["d","D"],
["e","E"],
["f","F"],
["g","G"],
["h","H"],
["i","I"],
["j","J"],
["k","K"],
["l","L"],
["m","M"],
["n","N"],
["o","O"],
["p","P"],
["q","Q"],
["r","R"],
["s","S"],
["t","T"],
["u","U"],
["v","V"],
["w","W"],
["x","X"],
["y","Y"],
["z","Z"],
["a","A","日"],
["b","B","月"],
["c","C","金"],
["d","D","木"],
["e","E","水"],
["f","F","火"],
["g","G","土"],
["h","H","竹"],
["i","I","戈"],
["j","J","十"],
["k","K","大"],
["l","L","中"],
["m","M","一"],
["n","N","弓"],
["o","O","人"],
["p","P","心"],
["q","Q","手"],
["r","R","口"],
["s","S","尸"],
["t","T","廿"],
["u","U","山"],
["v","V","女"],
["w","W","田"],
["x","X","难"],
["y","Y","卜"],
["z","Z","造"],
["","《"],
["。","》"],
[undefined],
@@ -270,6 +270,7 @@ let getCandidatesUsingBuf = () => {
return `${states.buf},${states.candidates}`
}
return Object.freeze({"n":"五仓简体 Qwerty","v":"many","c":"CuriousTo\uA75Bvald, 倉頡之友 。馬來西亞 http://www.chinesecj.com",
"t":states.keylayouts.map(it => [(it[2]||it[0]),it[1]]),
// return: [displayed output, composed output]
"accept":(headkey,shiftin,altgrin)=>{
let layer = 1*shiftin// + 2*altgrin

View File

@@ -26,32 +26,32 @@ let states = {"keylayouts":[[""],[undefined],
[undefined],
[undefined],
[undefined],
["a","A"],
["b","B"],
["c","C"],
["d","D"],
["e","E"],
["f","F"],
["g","G"],
["h","H"],
["i","I"],
["j","J"],
["k","K"],
["l","L"],
["m","M"],
["n","N"],
["o","O"],
["p","P"],
["q","Q"],
["r","R"],
["s","S"],
["t","T"],
["u","U"],
["v","V"],
["w","W"],
["x","X"],
["y","Y"],
["z","Z"],
["a","A","日"],
["b","B","月"],
["c","C","金"],
["d","D","木"],
["e","E","水"],
["f","F","火"],
["g","G","土"],
["h","H","竹"],
["i","I","戈"],
["j","J","十"],
["k","K","大"],
["l","L","中"],
["m","M","一"],
["n","N","弓"],
["o","O","人"],
["p","P","心"],
["q","Q","手"],
["r","R","口"],
["s","S","尸"],
["t","T","廿"],
["u","U","山"],
["v","V","女"],
["w","W","田"],
["x","X","難"],
["y","Y","卜"],
["z","Z","造"],
["","《"],
["。","》"],
[undefined],
@@ -270,6 +270,7 @@ let getCandidatesUsingBuf = () => {
return `${states.buf},${states.candidates}`
}
return Object.freeze({"n":"五倉正體 Qwerty","v":"many","c":"CuriousTo\uA75Bvald, 倉頡之友 。馬來西亞 http://www.chinesecj.com",
"t":states.keylayouts.map(it => [(it[2]||it[0]),it[1]]),
// return: [displayed output, composed output]
"accept":(headkey,shiftin,altgrin)=>{
let layer = 1*shiftin// + 2*altgrin

View File

@@ -5,11 +5,13 @@ import java.io.File
typealias IMECanditates = List<String>
typealias IMEOutput = String
typealias Keysyms = Array<Array<String?>>
data class TerrarumKeyLayout(
val name: String,
val capsMode: TerrarumKeyCapsMode,
val symbols: Array<Array<String?>>?
val symbols: Keysyms
)
enum class TerrarumKeyCapsMode {
@@ -30,7 +32,8 @@ data class TerrarumIME(
data class TerrarumIMEConf(
val name: String,
val copying: String,
val candidates: TerrarumIMEViewCount
val candidates: TerrarumIMEViewCount,
val symbols: Keysyms
)
enum class TerrarumIMEViewCount {
@@ -156,12 +159,25 @@ object IME {
val name = jsval.getMember("n").asString()
val candidatesCount = jsval.getMember("v").asString().toViewCount()
val copying = jsval.getMember("c").asString()
val keysyms = Array(256) { Array<String?>(4) { null } }
for (keycode in 0L until 256L) {
val a = jsval.getMember("t").getArrayElement(keycode)
if (!a.isNull) {
for (layer in 0L until 4L) {
if (a.arraySize > layer) {
val b = a.getArrayElement(layer)
if (!b.isNull) {
keysyms[keycode.toInt()][layer.toInt()] = b.asString()
}
}
}
}
}
return TerrarumIME(
name,
TerrarumIMEConf(
name, copying, candidatesCount
),
TerrarumIMEConf(name, copying, candidatesCount, keysyms),
{ headkey, shifted, alted, lowLayerKeysym ->
val a = jsval.invokeMember("accept", headkey, shifted, alted, lowLayerKeysym)
a.getArrayElement(0).asString().toCanditates() to a.getArrayElement(1).asString()

View File

@@ -62,15 +62,15 @@ object InputStrober {
val newKeysym0 = keysToStr(keymap, keyDiff)
val keysym =
if (keysym0 == null) null
else if (shiftin && altgrin && keysym0[3]?.isNotBlank() == true) keysym0[3]
else if (altgrin && keysym0[2]?.isNotBlank() == true) keysym0[2]
else if (shiftin && keysym0[1]?.isNotBlank() == true) keysym0[1]
else if (shiftin && altgrin && keysym0[3]?.isNotEmpty() == true) keysym0[3]
else if (altgrin && keysym0[2]?.isNotEmpty() == true) keysym0[2]
else if (shiftin && keysym0[1]?.isNotEmpty() == true) keysym0[1]
else keysym0[0]
val newKeysym =
if (newKeysym0 == null) null
else if (shiftin && altgrin && newKeysym0[3]?.isNotBlank() == true) newKeysym0[3]
else if (altgrin && newKeysym0[2]?.isNotBlank() == true) newKeysym0[2]
else if (shiftin && newKeysym0[1]?.isNotBlank() == true) newKeysym0[1]
else if (shiftin && altgrin && newKeysym0[3]?.isNotEmpty() == true) newKeysym0[3]
else if (altgrin && newKeysym0[2]?.isNotEmpty() == true) newKeysym0[2]
else if (shiftin && newKeysym0[1]?.isNotEmpty() == true) newKeysym0[1]
else newKeysym0[0]
val headKeyCode = if (keyDiff.size < 1) keys[0] else keyDiff[0]

View File

@@ -107,7 +107,7 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
-2 to UIItemKeycap(this, 49,129, null, oneu, ""),
Input.Keys.ALT_LEFT to UIItemKeycap(this, 81,129, Input.Keys.ALT_LEFT, onehalfu, "22,3"),
Input.Keys.SPACE to UIItemKeycap(this, 129,129, Input.Keys.SPACE, spaceu, ""),
Input.Keys.ALT_RIGHT to UIItemKeycap(this, 321,129, Input.Keys.ALT_RIGHT, onehalfu, "22,3"),
Input.Keys.ALT_RIGHT to UIItemKeycap(this, 321,129, Input.Keys.ALT_RIGHT, onehalfu, "23,2"),
-3 to UIItemKeycap(this, 369,129, null, oneu, ""),
-4 to UIItemKeycap(this, 401,129, null, oneu, ""),
Input.Keys.CONTROL_RIGHT to UIItemKeycap(this, 433,129, Input.Keys.CONTROL_RIGHT, onehalfu, "21,3"),
@@ -277,7 +277,7 @@ private class UIItemKeycap(
this.posX = initialX + parent.kbx
this.posY = initialY + parent.kby
}
else if (parent is UIKeyboardInputPanel) {
else if (parent is UIKeyboardInputConfig) {
this.posX = initialX + parent.kbx
this.posY = initialY + parent.kby
}

View File

@@ -9,6 +9,9 @@ import net.torvald.EMDASH
import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.gamecontroller.IME
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gamecontroller.TerrarumIME
import net.torvald.terrarum.gamecontroller.TerrarumKeyCapsMode
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.linearSearch
import net.torvald.terrarum.ui.*
@@ -16,7 +19,7 @@ import net.torvald.terrarum.ui.*
/**
* Created by minjaesong on 2021-11-10.
*/
class UIKeyboardInputPanel(remoCon: UIRemoCon?) : UICanvas() {
class UIKeyboardInputConfig(remoCon: UIRemoCon?) : UICanvas() {
override var width = 480
override var height = 600
@@ -113,7 +116,6 @@ class UIKeyboardInputPanel(remoCon: UIRemoCon?) : UICanvas() {
private val y1 = 400
private val y2 = y1 + 40
private val y3 = y2 + 48
private val lowLayerCodes = IME.getAllLowLayers().sorted()
private val lowLayerNames = lowLayerCodes.map { { IME.getLowLayerByName(it).name } }
@@ -140,7 +142,7 @@ class UIKeyboardInputPanel(remoCon: UIRemoCon?) : UICanvas() {
private val keyboardTestPanel = UIItemTextLineInput(this,
drawX + (width - 480) / 2 + 3,
y3,
height - 40,
474
)
@@ -162,12 +164,16 @@ class UIKeyboardInputPanel(remoCon: UIRemoCon?) : UICanvas() {
}
override fun updateUI(delta: Float) {
keyboardTestPanel.mouseoverUpdateLatch =
(!keyboardLayoutSelection.paletteShowing &&
!imeSelection.paletteShowing)
uiItems.forEach { it.update(delta) }
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
batch.color = Color.WHITE
val txt1 = Lang["MENU_LABEL_KEYBOARD_LAYOUT"]; val tw1 = App.fontGame.getWidth(txt1)
App.fontGame.draw(batch, txt1, selDrawX + (halfselw - tw1) / 2, y1)
@@ -180,6 +186,28 @@ class UIKeyboardInputPanel(remoCon: UIRemoCon?) : UICanvas() {
App.fontGame.draw(batch, title, drawX.toFloat() + (width - App.fontGame.getWidth(title)) / 2, drawY.toFloat())
uiItems.forEach { it.render(batch, camera) }
shiftin = Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) || Gdx.input.isKeyPressed(Input.Keys.SHIFT_RIGHT)
altgrin = Gdx.input.isKeyPressed(Input.Keys.ALT_RIGHT) || (Gdx.input.isKeyPressed(Input.Keys.ALT_LEFT) && Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT))
lowlayer = IME.getLowLayerByName(App.getConfigString("basekeyboardlayout"))
highlayer = getIME()
}
internal var shiftin = false; private set
internal var altgrin = false; private set
internal var lowlayer = IME.getLowLayerByName(App.getConfigString("basekeyboardlayout")); private set
internal var highlayer: TerrarumIME? = null
private fun getIME(): TerrarumIME? {
val selectedIME = App.getConfigString("inputmethod")
if (selectedIME == "none") return null
try {
return IME.getHighLayerByName(selectedIME)
}
catch (e: NullPointerException) {
return null
}
}
override fun doOpening(delta: Float) {
@@ -204,7 +232,7 @@ class UIKeyboardInputPanel(remoCon: UIRemoCon?) : UICanvas() {
* @param key LibGDX keycode. Set it to `null` to "disable" the key. Also see [com.badlogic.gdx.Input.Keys]
*/
private class UIItemInputKeycap(
parent: UICanvas,
val parent: UIKeyboardInputConfig,
initialX: Int,
initialY: Int,
val key: Int?,
@@ -213,14 +241,8 @@ private class UIItemInputKeycap(
) : UIItem(parent, initialX, initialY) {
init {
if (parent is UIKeyboardControlPanel ) {
this.posX = initialX + parent.kbx
this.posY = initialY + parent.kby
}
else if (parent is UIKeyboardInputPanel) {
this.posX = initialX + parent.kbx
this.posY = initialY + parent.kby
}
this.posX = initialX + parent.kbx
this.posY = initialY + parent.kby
}
override val height = 28
@@ -273,20 +295,45 @@ private class UIItemInputKeycap(
// keysym
if (key == Input.Keys.CONTROL_LEFT || key == Input.Keys.CONTROL_RIGHT)
batch.draw(labels.get(21,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (key == Input.Keys.ALT_LEFT || key == Input.Keys.ALT_RIGHT)
else if (key == Input.Keys.ALT_LEFT)
batch.draw(labels.get(22,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (key == Input.Keys.ALT_RIGHT)
batch.draw(labels.get(23,2), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (key == Input.Keys.SHIFT_LEFT || key == Input.Keys.SHIFT_RIGHT)
batch.draw(labels.get(23,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (key == Input.Keys.TAB)
batch.draw(labels.get(23,5), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (key == Input.Keys.BACKSPACE)
batch.draw(labels.get(24,5), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (key == Input.Keys.CAPS_LOCK)
batch.draw(labels.get(24,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (key == Input.Keys.CAPS_LOCK) {
if (parent.lowlayer.capsMode == TerrarumKeyCapsMode.CAPS)
batch.draw(labels.get(24,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (parent.lowlayer.capsMode == TerrarumKeyCapsMode.SHIFT)
batch.draw(labels.get(24,2), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (parent.lowlayer.capsMode == TerrarumKeyCapsMode.BACK)
batch.draw(labels.get(24,5), (posX + (width - 20) / 2).toFloat(), posY + 4f)
}
else if (key == Input.Keys.ENTER)
batch.draw(labels.get(17,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else {
// the real keysym
else if (key != null) {
val keysym0 = if (KeyToggler.isOn(App.getConfigInt("control_key_toggleime")))
parent.highlayer?.config?.symbols?.get(key) ?: parent.lowlayer.symbols[key]
else
parent.lowlayer.symbols[key]
val keysym =
(if (parent.shiftin && parent.altgrin && keysym0[3]?.isNotEmpty() == true) keysym0[3]
else if (parent.altgrin && keysym0[2]?.isNotEmpty() == true) keysym0[2]
else if (parent.shiftin && keysym0[1]?.isNotEmpty() == true) keysym0[1]
else keysym0[0]) ?: ""
if (keysym[0].code == 0xA0)
batch.draw(labels.get(22, 2), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else if (keysym[0].code == 0x20)
batch.draw(labels.get(21,2), (posX + (width - 20) / 2).toFloat(), posY + 4f)
else {
val keysymw = App.fontGame.getWidth(keysym)
App.fontGame.draw(batch, keysym, posX + (width - keysymw) / 2, posY + 4)
}
}
}

View File

@@ -16,7 +16,7 @@ object UITitleRemoConYaml {
- MENU_OPTIONS
- MENU_LABEL_GRAPHICS : net.torvald.terrarum.modulebasegame.ui.GraphicsControlPanel
- MENU_OPTIONS_CONTROLS : net.torvald.terrarum.modulebasegame.ui.UIKeyboardControlPanel
- MENU_CONTROLS_KEYBOARD : net.torvald.terrarum.modulebasegame.ui.UIKeyboardInputPanel
- MENU_CONTROLS_KEYBOARD : net.torvald.terrarum.modulebasegame.ui.UIKeyboardInputConfig
- MENU_LABEL_LANGUAGE : net.torvald.terrarum.modulebasegame.ui.UITitleLanguage
- MENU_MODULES : net.torvald.terrarum.ModOptionsHost
- MENU_LABEL_RETURN+WRITETOCONFIG

View File

@@ -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

View File

@@ -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() {

View File

@@ -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) {