mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 20:44:05 +09:00
preliminary gui thing for teleportation
This commit is contained in:
@@ -64,7 +64,7 @@ class ConsoleWindow : UICanvas() {
|
||||
init {
|
||||
reset()
|
||||
addUIitem(textinput)
|
||||
textinput.isActive = false
|
||||
textinput.isEnabled = false
|
||||
}
|
||||
|
||||
private val lb = ArrayList<String>()
|
||||
@@ -99,7 +99,7 @@ class ConsoleWindow : UICanvas() {
|
||||
clickLatched = false
|
||||
}
|
||||
|
||||
textinput.isActive = (isOpened && !isClosing)
|
||||
textinput.isEnabled = (isOpened && !isClosing)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
@@ -269,14 +269,14 @@ class ConsoleWindow : UICanvas() {
|
||||
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
|
||||
0f, -height.toFloat()
|
||||
)*/
|
||||
textinput.isActive = false
|
||||
textinput.isEnabled = false
|
||||
textinput.mouseoverUpdateLatch = false
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
drawOffY = 0f
|
||||
openingTimeCounter = 0f
|
||||
textinput.isActive = true
|
||||
textinput.isEnabled = true
|
||||
textinput.mouseoverUpdateLatch = true
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,11 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
/**
|
||||
* Whether the button is "available" or not to the player
|
||||
*/
|
||||
open var isEnabled = true
|
||||
|
||||
/**
|
||||
* Whether the button should receive updates
|
||||
*/
|
||||
open var isActive = true
|
||||
|
||||
|
||||
@@ -140,9 +145,9 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
|
||||
open fun update(delta: Float) {
|
||||
if (parentUI.isVisible) {
|
||||
updateListener.invoke(delta)
|
||||
if (isActive) {
|
||||
updateListener.invoke(delta)
|
||||
|
||||
// if (isActive) {
|
||||
mouseOverCall?.update(delta)
|
||||
|
||||
if (mouseUp) {
|
||||
@@ -158,9 +163,9 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
mouseOverCall?.setAsClose()
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
if (!mouseUp) mouseLatched = false
|
||||
if (!mouseUp) mouseLatched = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +186,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
|
||||
// keyboard controlled
|
||||
open fun keyDown(keycode: Int): Boolean {
|
||||
if (parentUI.isVisible && isActive) {
|
||||
if (parentUI.isVisible && isEnabled) {
|
||||
keyDownListener.invoke(keycode)
|
||||
return true
|
||||
}
|
||||
@@ -189,7 +194,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
return false
|
||||
}
|
||||
open fun keyUp(keycode: Int): Boolean {
|
||||
if (parentUI.isVisible && isActive) {
|
||||
if (parentUI.isVisible && isEnabled) {
|
||||
keyUpListener.invoke(keycode)
|
||||
return true
|
||||
}
|
||||
@@ -197,7 +202,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
return false
|
||||
}
|
||||
open fun keyTyped(character: Char): Boolean {
|
||||
if (parentUI.isVisible && isActive) {
|
||||
if (parentUI.isVisible && isEnabled) {
|
||||
keyTypedListener.invoke(character)
|
||||
return true
|
||||
}
|
||||
@@ -207,7 +212,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
|
||||
// mouse controlled
|
||||
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||
if (parentUI.isVisible && isActive) {
|
||||
if (parentUI.isVisible && isEnabled) {
|
||||
touchDraggedListener.invoke(itemRelativeMouseX, itemRelativeMouseY, pointer)
|
||||
return true
|
||||
}
|
||||
@@ -217,7 +222,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
var actionDone = false
|
||||
|
||||
if (parentUI.isVisible && isActive) {
|
||||
if (parentUI.isVisible && isEnabled) {
|
||||
if (mouseUp) {
|
||||
touchDownListener.invoke(itemRelativeMouseX, itemRelativeMouseY, pointer, button)
|
||||
actionDone = true
|
||||
@@ -242,7 +247,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
return false
|
||||
}
|
||||
open fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||
if (parentUI.isVisible && mouseUp && isActive) {
|
||||
if (parentUI.isVisible && mouseUp && isEnabled) {
|
||||
scrolledListener.invoke(amountX, amountY)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -23,21 +23,21 @@ open class UIItemTextButton(
|
||||
val readFromLang: Boolean = false,
|
||||
|
||||
/** Colour when mouse is over */
|
||||
val activeCol: Color = Toolkit.Theme.COL_MOUSE_UP,
|
||||
var activeCol: Color = Toolkit.Theme.COL_MOUSE_UP,
|
||||
/** Colour when mouse is over */
|
||||
val activeBackCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUND_ACTIVECOL,
|
||||
var activeBackCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUND_ACTIVECOL,
|
||||
/** Colour when mouse is over */
|
||||
val activeBackBlendMode: String = BlendMode.NORMAL,
|
||||
var activeBackBlendMode: String = BlendMode.NORMAL,
|
||||
/** Colour when clicked/selected */
|
||||
val highlightCol: Color = Toolkit.Theme.COL_SELECTED,
|
||||
var highlightCol: Color = Toolkit.Theme.COL_SELECTED,
|
||||
/** Colour when clicked/selected */
|
||||
val highlightBackCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUND_HIGHLIGHTCOL,
|
||||
var highlightBackCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUND_HIGHLIGHTCOL,
|
||||
/** Colour when clicked/selected */
|
||||
val highlightBackBlendMode: String = BlendMode.NORMAL,
|
||||
var highlightBackBlendMode: String = BlendMode.NORMAL,
|
||||
/** Colour on normal status */
|
||||
val inactiveCol: Color = Toolkit.Theme.COL_LIST_DEFAULT,
|
||||
var inactiveCol: Color = Toolkit.Theme.COL_LIST_DEFAULT,
|
||||
|
||||
val disabledCol: Color = Toolkit.Theme.COL_INVENTORY_CELL_BORDER,
|
||||
var disabledCol: Color = Toolkit.Theme.COL_INVENTORY_CELL_BORDER,
|
||||
|
||||
val hasBorder: Boolean = false,
|
||||
|
||||
@@ -59,6 +59,8 @@ open class UIItemTextButton(
|
||||
}
|
||||
}
|
||||
|
||||
var skipUpdate = false
|
||||
|
||||
/** Actually displayed text (changes with the app language) */
|
||||
val label: String
|
||||
get() = if (readFromLang) Lang[labelText] else labelText
|
||||
@@ -70,8 +72,6 @@ open class UIItemTextButton(
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
@@ -110,7 +110,8 @@ open class UIItemTextButton(
|
||||
}
|
||||
|
||||
|
||||
batch.color = if (!isActive) disabledCol
|
||||
batch.color = if (skipUpdate) inactiveCol
|
||||
else if (!isEnabled) disabledCol
|
||||
else if (highlighted) highlightCol
|
||||
else if (mouseUp) activeCol
|
||||
else inactiveCol
|
||||
|
||||
@@ -101,7 +101,7 @@ class UIItemTextLineInput(
|
||||
false
|
||||
)
|
||||
|
||||
override var isActive: Boolean = false // keep it false by default!
|
||||
override var isEnabled: Boolean = false // keep it false by default!
|
||||
set(value) {
|
||||
if (field && !value) endComposing(true)
|
||||
field = value
|
||||
@@ -132,7 +132,7 @@ class UIItemTextLineInput(
|
||||
if (!value) {
|
||||
mouseLatched = false
|
||||
fboUpdateLatch = false
|
||||
isActive = false
|
||||
isEnabled = false
|
||||
cursorOn = false
|
||||
cursorBlinkCounter = 0f
|
||||
}
|
||||
@@ -251,10 +251,10 @@ class UIItemTextLineInput(
|
||||
}
|
||||
|
||||
override fun inputStrobed(e: TerrarumKeyboardEvent) {
|
||||
val oldActive = isActive
|
||||
val oldActive = isEnabled
|
||||
|
||||
// process keypresses
|
||||
if (isActive) {
|
||||
if (isEnabled) {
|
||||
|
||||
val (eventType, char, headkey, repeatCount, keycodes) = e
|
||||
|
||||
@@ -416,12 +416,12 @@ class UIItemTextLineInput(
|
||||
val mouseDown = Terrarum.mouseDown
|
||||
|
||||
if (mouseDown) {
|
||||
isActive = mouseUp
|
||||
isEnabled = mouseUp
|
||||
}
|
||||
|
||||
if (App.getConfigString("inputmethod") == "none") imeOn = false
|
||||
|
||||
if (isActive) {
|
||||
if (isEnabled) {
|
||||
cursorBlinkCounter += delta
|
||||
|
||||
while (cursorBlinkCounter >= CURSOR_BLINK_TIME) {
|
||||
@@ -553,7 +553,7 @@ class UIItemTextLineInput(
|
||||
Toolkit.drawBoxBorder(batch, btn1PosX - 1, posY - 1, WIDTH_ONEBUTTON + 2, height + 2)
|
||||
|
||||
// text area border (pop-up for isActive)
|
||||
if (isActive) {
|
||||
if (isEnabled) {
|
||||
batch.color = Toolkit.Theme.COL_SELECTED
|
||||
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2) // this is a full border, not a text area
|
||||
}
|
||||
@@ -567,7 +567,7 @@ class UIItemTextLineInput(
|
||||
batch.color = if (mouseDown) Toolkit.Theme.COL_SELECTED else Toolkit.Theme.COL_MOUSE_UP
|
||||
Toolkit.drawBoxBorder(batch, btn1PosX - 1, posY - 1, WIDTH_ONEBUTTON + 2, height + 2)
|
||||
}
|
||||
else if (mouseUpOnTextArea && !isActive) {
|
||||
else if (mouseUpOnTextArea && !isEnabled) {
|
||||
batch.color = Toolkit.Theme.COL_MOUSE_UP
|
||||
Toolkit.drawBoxBorder(batch, inputPosX - 1, posY - 1, fbo.width + 2 * UI_TEXT_MARGIN+ 2, height + 2)
|
||||
}
|
||||
@@ -579,7 +579,7 @@ class UIItemTextLineInput(
|
||||
|
||||
// draw text cursor
|
||||
val cursorXOnScreen = inputPosX + cursorDrawX + 2 + textDrawOffset
|
||||
if (isActive && cursorOn) {
|
||||
if (isEnabled && cursorOn) {
|
||||
val baseCol = if (maxLen.exceeds(textbuf, listOf(32))) TEXTINPUT_COL_TEXT_NOMORE else TEXTINPUT_COL_TEXT
|
||||
|
||||
batch.color = baseCol.cpy().mul(0.5f,0.5f,0.5f,1f)
|
||||
|
||||
Reference in New Issue
Block a user