Fix not being able to close just terminal amount dialog
This commit is contained in:
parent
b87a36caa4
commit
e41c9e3ccb
|
@ -13,6 +13,7 @@ import net.shadowfacts.cacao.util.MouseButton
|
|||
import net.shadowfacts.cacao.util.RenderHelper
|
||||
import net.shadowfacts.cacao.window.ScreenHandlerWindow
|
||||
import net.shadowfacts.cacao.window.Window
|
||||
import org.lwjgl.glfw.GLFW
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
|
@ -48,6 +49,9 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
|||
|
||||
override fun removeWindow(window: Window) {
|
||||
_windows.remove(window)
|
||||
if (windows.isEmpty()) {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
|
@ -151,11 +155,16 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
|||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
val modifiersSet by lazy { KeyModifiers(modifiers) }
|
||||
if (findResponder { it.keyPressed(keyCode, modifiersSet) }) {
|
||||
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
windows.lastOrNull()?.removeFromScreen()
|
||||
return true
|
||||
} else {
|
||||
val modifiersSet by lazy { KeyModifiers(modifiers) }
|
||||
if (findResponder { it.keyPressed(keyCode, modifiersSet) }) {
|
||||
return true
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, modifiers)
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, modifiers)
|
||||
}
|
||||
|
||||
override fun charTyped(char: Char, modifiers: Int): Boolean {
|
||||
|
@ -166,4 +175,8 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
|||
return super.charTyped(char, modifiers)
|
||||
}
|
||||
|
||||
override fun shouldCloseOnEsc(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.shadowfacts.cacao.util.KeyModifiers
|
|||
import net.shadowfacts.cacao.util.MouseButton
|
||||
import net.shadowfacts.cacao.util.RenderHelper
|
||||
import net.shadowfacts.cacao.window.Window
|
||||
import org.lwjgl.glfw.GLFW
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
|
@ -60,7 +61,9 @@ open class CacaoScreen(title: Text = LiteralText("CacaoScreen")): Screen(title),
|
|||
*/
|
||||
override fun removeWindow(window: Window) {
|
||||
_windows.remove(window)
|
||||
// todo: VC callbacks
|
||||
if (windows.isEmpty()) {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
|
@ -126,11 +129,16 @@ open class CacaoScreen(title: Text = LiteralText("CacaoScreen")): Screen(title),
|
|||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
val modifiersSet by lazy { KeyModifiers(modifiers) }
|
||||
if (findResponder { it.keyPressed(keyCode, modifiersSet) }) {
|
||||
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
windows.lastOrNull()?.removeFromScreen()
|
||||
return true
|
||||
} else {
|
||||
val modifiersSet by lazy { KeyModifiers(modifiers) }
|
||||
if (findResponder { it.keyPressed(keyCode, modifiersSet) }) {
|
||||
return true
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, modifiers)
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, modifiers)
|
||||
}
|
||||
|
||||
override fun keyReleased(i: Int, j: Int, k: Int): Boolean {
|
||||
|
@ -145,6 +153,10 @@ open class CacaoScreen(title: Text = LiteralText("CacaoScreen")): Screen(title),
|
|||
return super.charTyped(char, modifiers)
|
||||
}
|
||||
|
||||
override fun shouldCloseOnEsc(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun AbstractCacaoScreen.findResponder(fn: (Responder) -> Boolean): Boolean {
|
||||
|
|
Loading…
Reference in New Issue