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,12 +155,17 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
|||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
override fun charTyped(char: Char, modifiers: Int): Boolean {
|
||||
val modifiersSet by lazy { KeyModifiers(modifiers) }
|
||||
|
@ -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,12 +129,17 @@ open class CacaoScreen(title: Text = LiteralText("CacaoScreen")): Screen(title),
|
|||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
override fun keyReleased(i: Int, j: Int, k: Int): Boolean {
|
||||
return super.keyReleased(i, j, k)
|
||||
|
@ -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