mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
custom keyboard handling wip
This commit is contained in:
@@ -86,7 +86,7 @@ abstract class UICanvas(
|
||||
get() = _mouseUpThis || handler.mouseUp
|
||||
/** If mouse is hovering over it and mouse is down */
|
||||
val mousePushed: Boolean
|
||||
get() = mouseUp && Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary"))
|
||||
get() = mouseUp && Terrarum.mouseDown
|
||||
|
||||
private val _mouseUpThis: Boolean
|
||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||
|
||||
@@ -59,8 +59,6 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
abstract val width: Int
|
||||
abstract val height: Int
|
||||
|
||||
protected val mouseButton = App.getConfigInt("config_mouseprimary")
|
||||
|
||||
/** This variable is NOT updated on its own.
|
||||
* ```
|
||||
* val posXDelta = posX - oldPosX
|
||||
@@ -92,10 +90,10 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||
/** If mouse is hovering over it and mouse is down */
|
||||
open val mousePushed: Boolean
|
||||
get() = mouseUp && Gdx.input.isButtonPressed(mouseButton)
|
||||
get() = mouseUp && Terrarum.mouseDown
|
||||
|
||||
|
||||
protected var mouseLatched = Gdx.input.isButtonPressed(mouseButton)
|
||||
protected var mouseLatched = Terrarum.mouseDown
|
||||
|
||||
/** UI to call (show up) while mouse is up */
|
||||
open val mouseOverCall: UICanvas? = null
|
||||
@@ -103,12 +101,13 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
|
||||
// kind of listener implementation
|
||||
/** Fired once for every update
|
||||
* Parametre: delta */
|
||||
* Parameter: delta */
|
||||
open var updateListener: ((Float) -> Unit)? = null
|
||||
/** Parametre: keycode */
|
||||
/** Parameter: keycode */
|
||||
open var keyDownListener: ((Int) -> Unit)? = null
|
||||
/** Parametre: keycode */
|
||||
/** Parameter: keycode */
|
||||
open var keyUpListener: ((Int) -> Unit)? = null
|
||||
open var keyTypedListener: ((Char) -> Unit)? = null
|
||||
open var touchDraggedListener: ((Int, Int, Int) -> Unit)? = null
|
||||
/** Parameters: screenX, screenY, pointer, button */
|
||||
open var touchDownListener: ((Int, Int, Int, Int) -> Unit)? = null
|
||||
@@ -188,6 +187,14 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
|
||||
return false
|
||||
}
|
||||
open fun keyTyped(character: Char): Boolean {
|
||||
if (parentUI.isVisible && keyTypedListener != null) {
|
||||
keyTypedListener!!.invoke(character)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// mouse controlled
|
||||
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||
|
||||
@@ -4,11 +4,8 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.toInt
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
@@ -223,7 +220,7 @@ class UIItemTextButtonList(
|
||||
|
||||
}
|
||||
|
||||
if (!Gdx.input.isButtonPressed(mouseButton)) {
|
||||
if (!Terrarum.mouseDown) {
|
||||
clickLatched = false
|
||||
}
|
||||
|
||||
|
||||
66
src/net/torvald/terrarum/ui/UIItemTextLineInput.kt
Normal file
66
src/net/torvald/terrarum/ui/UIItemTextLineInput.kt
Normal file
@@ -0,0 +1,66 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import java.awt.Color
|
||||
|
||||
/**
|
||||
* @param width width of the text input where the text gets drawn, not the entire item
|
||||
* @param height height of the text input where the text gets drawn, not the entire item
|
||||
*
|
||||
* Created by minjaesong on 2021-10-20.
|
||||
*/
|
||||
class UIItemTextLineInput(
|
||||
parentUI: UICanvas,
|
||||
initialX: Int, initialY: Int,
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
var placeholder: String? = null,
|
||||
val enablePasteButton: Boolean = true,
|
||||
val enableLanguageButton: Boolean = false
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
companion object {
|
||||
val TEXTINPUT_COL_TEXT = Color.WHITE
|
||||
val TEXTINPUT_COL_GREY = Color.GRAY
|
||||
|
||||
}
|
||||
|
||||
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width, height, true)
|
||||
|
||||
var isActive = true
|
||||
var isGreyedOut = false
|
||||
|
||||
val cursorX = 0
|
||||
val keybuf = StringBuilder()
|
||||
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
if (Terrarum.mouseDown) {
|
||||
isActive = mouseUp
|
||||
}
|
||||
|
||||
// process keypresses
|
||||
if (isActive) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
super.render(batch, camera)
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
fbo.dispose()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user