mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
fix: 'q' would close the ui when you're typing in something
This commit is contained in:
BIN
assets/graphics/fonts/code.tga
LFS
BIN
assets/graphics/fonts/code.tga
LFS
Binary file not shown.
25
src/net/torvald/terrarum/TerrarumGlobalState.kt
Normal file
25
src/net/torvald/terrarum/TerrarumGlobalState.kt
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package net.torvald.terrarum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2023-09-05.
|
||||||
|
*/
|
||||||
|
object TerrarumGlobalState {
|
||||||
|
|
||||||
|
var HAS_KEYBOARD_INPUT_FOCUS = CountedBool()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class CountedBool {
|
||||||
|
private var counter = 0L
|
||||||
|
|
||||||
|
fun set() {
|
||||||
|
counter += 1
|
||||||
|
}
|
||||||
|
fun unset() {
|
||||||
|
if (counter >= 1) counter -= 1
|
||||||
|
}
|
||||||
|
val value: Boolean
|
||||||
|
get() = counter > 0
|
||||||
|
fun isOn() = value
|
||||||
|
fun isOff() = !value
|
||||||
|
}
|
||||||
@@ -12,6 +12,9 @@ import net.torvald.terrarum.ui.Toolkit
|
|||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.utils.PasswordBase32
|
import net.torvald.terrarum.utils.PasswordBase32
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2023-09-04.
|
||||||
|
*/
|
||||||
class UIShare : UICanvas() {
|
class UIShare : UICanvas() {
|
||||||
|
|
||||||
override var width = 434
|
override var width = 434
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ import net.torvald.terrarum.ui.UICanvas
|
|||||||
import net.torvald.terrarum.ui.UIItemTextButton
|
import net.torvald.terrarum.ui.UIItemTextButton
|
||||||
import net.torvald.terrarum.utils.PasswordBase32
|
import net.torvald.terrarum.utils.PasswordBase32
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2023-09-03.
|
||||||
|
*/
|
||||||
class UIWorldPortalShare(private val full: UIWorldPortal) : UICanvas() {
|
class UIWorldPortalShare(private val full: UIWorldPortal) : UICanvas() {
|
||||||
|
|
||||||
override var width = 434
|
override var width = 434
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ object Base32Test {
|
|||||||
val testStr = UUID.fromString("145efab2-d465-4e1e-abae-db6c809817a9").let {
|
val testStr = UUID.fromString("145efab2-d465-4e1e-abae-db6c809817a9").let {
|
||||||
it.mostSignificantBits.toBig64() + it.leastSignificantBits.toBig64()
|
it.mostSignificantBits.toBig64() + it.leastSignificantBits.toBig64()
|
||||||
}
|
}
|
||||||
// val pwd = "béchamel".toByteArray()
|
val pwd = "béchamel".toByteArray()
|
||||||
|
|
||||||
val enc = PasswordBase32.encode(testStr)
|
val enc = PasswordBase32.encode(testStr, pwd)
|
||||||
val dec = PasswordBase32.decode(enc, testStr.size)
|
val dec = PasswordBase32.decode(enc, testStr.size, pwd)
|
||||||
|
|
||||||
println("Encoded text: $enc")
|
println("Encoded text: $enc")
|
||||||
println("Encoded bytes: ${testStr.joinToString(" ") { it.toInt().and(255).toString(16).padStart(2, '0') }}")
|
println("Encoded bytes: ${testStr.joinToString(" ") { it.toInt().and(255).toString(16).padStart(2, '0') }}")
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.ControlPresets
|
|
||||||
import net.torvald.terrarum.FlippingSpriteBatch
|
|
||||||
import net.torvald.terrarum.Terrarum
|
|
||||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
|
|
||||||
@@ -189,7 +186,7 @@ void main() {
|
|||||||
// open/close UI by key pressed
|
// open/close UI by key pressed
|
||||||
// some UIs will pause the game, and they still need to be closed
|
// some UIs will pause the game, and they still need to be closed
|
||||||
if (!uiToggleLocked && (Terrarum.ingame?.consoleOpened == false && (Terrarum.ingame?.paused == false || isOpened))) {
|
if (!uiToggleLocked && (Terrarum.ingame?.consoleOpened == false && (Terrarum.ingame?.paused == false || isOpened))) {
|
||||||
if (toggleKey != null && Gdx.input.isKeyJustPressed(toggleKey!!)) {
|
if (toggleKey != null && Gdx.input.isKeyJustPressed(toggleKey!!) && TerrarumGlobalState.HAS_KEYBOARD_INPUT_FOCUS.isOff()) {
|
||||||
if (uiTogglerFunctionDefault == null) {
|
if (uiTogglerFunctionDefault == null) {
|
||||||
if (isClosed)
|
if (isClosed)
|
||||||
setAsOpen()
|
setAsOpen()
|
||||||
@@ -200,7 +197,7 @@ void main() {
|
|||||||
|
|
||||||
// for the case of intermediate states, do nothing.
|
// for the case of intermediate states, do nothing.
|
||||||
}
|
}
|
||||||
if (toggleButton != null && Gdx.input.isButtonJustPressed(toggleButton!!)) {
|
if (toggleButton != null && Gdx.input.isButtonJustPressed(toggleButton!!) && TerrarumGlobalState.HAS_KEYBOARD_INPUT_FOCUS.isOff()) {
|
||||||
if (uiTogglerFunctionDefault == null) {
|
if (uiTogglerFunctionDefault == null) {
|
||||||
if (isClosed)
|
if (isClosed)
|
||||||
setAsOpen()
|
setAsOpen()
|
||||||
@@ -211,7 +208,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toggleKeyExtra.forEachIndexed { index, control ->
|
toggleKeyExtra.forEachIndexed { index, control ->
|
||||||
if (Gdx.input.isKeyJustPressed(ControlPresets.getKey(control))) {
|
if (Gdx.input.isKeyJustPressed(ControlPresets.getKey(control)) && TerrarumGlobalState.HAS_KEYBOARD_INPUT_FOCUS.isOff()) {
|
||||||
toggleKeyExtraAction[index].invoke(this)
|
toggleKeyExtraAction[index].invoke(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,6 +216,9 @@ void main() {
|
|||||||
// ESC is a master key for closing
|
// ESC is a master key for closing
|
||||||
if (!alwaysVisible && allowESCtoClose && Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE) && isOpened) {
|
if (!alwaysVisible && allowESCtoClose && Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE) && isOpened) {
|
||||||
setAsClose()
|
setAsClose()
|
||||||
|
|
||||||
|
// just in case...
|
||||||
|
TerrarumGlobalState.HAS_KEYBOARD_INPUT_FOCUS.unset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -415,13 +415,25 @@ class UIItemTextLineInput(
|
|||||||
fboUpdateLatch = true
|
fboUpdateLatch = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun hide() {
|
||||||
|
super.hide()
|
||||||
|
if (this.isEnabled) {
|
||||||
|
this.isEnabled = false
|
||||||
|
TerrarumGlobalState.HAS_KEYBOARD_INPUT_FOCUS.unset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
if (mouseoverUpdateLatch) {
|
if (mouseoverUpdateLatch) {
|
||||||
super.update(delta)
|
super.update(delta)
|
||||||
val mouseDown = Terrarum.mouseDown
|
val mouseDown = Terrarum.mouseDown
|
||||||
|
|
||||||
if (mouseDown) {
|
if (mouseDown) {
|
||||||
|
val oldEnabled = isEnabled
|
||||||
isEnabled = mouseUp
|
isEnabled = mouseUp
|
||||||
|
|
||||||
|
if (oldEnabled && !isEnabled) TerrarumGlobalState.HAS_KEYBOARD_INPUT_FOCUS.unset()
|
||||||
|
if (!oldEnabled && isEnabled) TerrarumGlobalState.HAS_KEYBOARD_INPUT_FOCUS.set()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (App.getConfigString("inputmethod") == "none") imeOn = false
|
if (App.getConfigString("inputmethod") == "none") imeOn = false
|
||||||
|
|||||||
Reference in New Issue
Block a user