diff --git a/src/main/kotlin/net/shadowfacts/cacao/CacaoScreen.kt b/src/main/kotlin/net/shadowfacts/cacao/CacaoScreen.kt index 709d343..996a1a5 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/CacaoScreen.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/CacaoScreen.kt @@ -72,16 +72,12 @@ open class CacaoScreen: Screen(TextComponent("CacaoScreen")) { override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean { val window = windows.lastOrNull() val result = window?.mouseClicked(Point(mouseX, mouseY), MouseButton.fromMC(button)) - when (result) { - true -> - RenderHelper.playSound(SoundEvents.UI_BUTTON_CLICK) - false -> - if (windows.size > 1) { - removeWindow(windows.last()) - } + return if (result == true) { + RenderHelper.playSound(SoundEvents.UI_BUTTON_CLICK) + true + } else { + false } - - return result == true } } \ No newline at end of file diff --git a/src/main/kotlin/net/shadowfacts/cacao/Window.kt b/src/main/kotlin/net/shadowfacts/cacao/Window.kt index f15c9ec..353c2da 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/Window.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/Window.kt @@ -195,6 +195,11 @@ class Window { if (view != null) { val pointInView = Point(point.x - view.frame.left, point.y - view.frame.top) return view.mouseClicked(pointInView, mouseButton) + } else { + // remove the window from the screen when the mouse clicks outside the window and this is not the primary window + if (screen.windows.size > 1) { + removeFromScreen() + } } return false }