From 25875b162e88eeaa0b66455dc88458db8f7e2957 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 18 Jul 2023 01:54:21 +0700 Subject: [PATCH] Improve blocker flashing --- .../otm/client/screen/panels/EditablePanel.kt | 46 +++++++------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt index dc154f555..cad6d06bb 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt @@ -403,12 +403,10 @@ open class EditablePanel @JvmOverloads constructor( var isFlashing: Boolean get() { - if (flashingSince == null) { - return false - } + val flashingSince = flashingSince ?: return false - if (flashingSince!!.millis >= 1200L) { - flashingSince = null + if (flashingSince.millis >= 1200L) { + this.flashingSince = null return false } @@ -416,8 +414,14 @@ open class EditablePanel @JvmOverloads constructor( } set(value) { if (value) { - flashingSince = SystemTime() - popup() + if (screen is MatteryScreen<*>) { + screen.popup(findAbsoluteRoot() as EditablePanel>) + } + + if (!flashAnyBlocker(true)) { + flashingSince = SystemTime() + findAbsoluteRoot().requestFocus() + } } else { flashingSince = null } @@ -466,23 +470,7 @@ open class EditablePanel @JvmOverloads constructor( } protected fun flashAnyBlocker(doFlash: Boolean = true): Boolean { - var blockingWindow = blockingWindow - var parent = parent - - while (blockingWindow == null && parent != null) { - blockingWindow = parent.blockingWindow - parent = parent.parent - } - - if (blockingWindow == null) { - return flashAnyBlockerInner(doFlash) - } - - if (doFlash) { - blockingWindow.isFlashing = true - } - - return true + return findAbsoluteRoot().flashAnyBlockerInner(doFlash) } @JvmOverloads @@ -1732,17 +1720,17 @@ open class EditablePanel @JvmOverloads constructor( isRemoved = true } - fun popup(focus: Boolean = true) { + fun popup(focus: Boolean = true, doFlash: Boolean = true) { if (isRemoved) { return } - if (screen is MatteryScreen<*> && parent == null) { - screen.popup(this as EditablePanel>) + if (screen is MatteryScreen<*>) { + screen.popup(findAbsoluteRoot() as EditablePanel>) } - if (focus) { - requestFocus() + if (focus && !flashAnyBlocker(doFlash)) { + findAbsoluteRoot().requestFocus() } }