Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ class HudEditorUIScreen : ComposeScreen() {
UiSounds.play(UiSoundEvent.CLOSE)
}

private fun cancelClose(): Boolean {
if (!closeRequested) return false
closeRequested = false
requestOpenCallback?.invoke()
UiSounds.play(UiSoundEvent.OPEN)
return true
}

@Volatile private var returningToOneConfig = false

private var requestCloseCallback: (() -> Unit)? = null
private var requestOpenCallback: (() -> Unit)? = null

override val scrollSpeed: Float get() = 0.5f

Expand Down Expand Up @@ -79,12 +88,11 @@ class HudEditorUIScreen : ComposeScreen() {
}
val toggleKey = OneConfigConfig.oneConfigKeybind.keyCodes?.firstOrNull()
if (toggleKey != null && key == toggleKey && !KeybindRecordingBus.isRecording) {
if (closeRequested) return cancelClose()
if (OneConfigConfig.keybindClosesGui) {
if (!closeRequested) {
OneConfigConfig.notifyKeybindClosedGui()
beginClose()
requestCloseCallback?.invoke()
}
OneConfigConfig.notifyKeybindClosedGui()
beginClose()
requestCloseCallback?.invoke()
} else {
returningToOneConfig = true
Platform.screen().display(OneConfigUIScreen())
Expand Down Expand Up @@ -131,8 +139,10 @@ class HudEditorUIScreen : ComposeScreen() {
LaunchedEffect(Unit) { visible = true }

val requestClose: () -> Unit = { visible = false }
val requestOpen: () -> Unit = { visible = true }
SideEffect {
requestCloseCallback = requestClose
requestOpenCallback = requestOpen
}

val exitMs = guiCloseAnimationMillis().toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,24 @@ class OneConfigUIScreen @JvmOverloads constructor(
closeRequested = true
closeRequestedAt = System.currentTimeMillis()
closeAnimationMs = guiCloseAnimationMillis()
markClosed()
UiSounds.play(UiSoundEvent.CLOSE)
}

private fun cancelClose(): Boolean {
if (!closeRequested) return false

// Resume the opening blur animation from current blur intensity
val now = System.currentTimeMillis()
val blurProgress = if (closeAnimationMs <= 0L) 0f
else 1f - easeOutExpo((now - closeRequestedAt).toFloat() / closeAnimationMs)
openedAt = now - (blurProgress.coerceIn(0f, 1f) * OPEN_ANIMATION_MS).toLong()

closeRequested = false
requestOpenCallback?.invoke()
UiSounds.play(UiSoundEvent.OPEN)
return true
}

/** The page this screen is showing which survives the scene being disposed and rebuilt */
private var route: Any? = null

Expand Down Expand Up @@ -225,12 +239,11 @@ class OneConfigUIScreen @JvmOverloads constructor(
}
val toggleKey = OneConfigConfig.oneConfigKeybind.keyCodes?.firstOrNull()
if (toggleKey != null && key == toggleKey && !KeybindRecordingBus.isRecording) {
if (closeRequested) return cancelClose()
if (OneConfigConfig.keybindClosesGui) {
if (!closeRequested) {
OneConfigConfig.notifyKeybindClosedGui()
beginClose()
requestCloseCallback?.invoke()
}
OneConfigConfig.notifyKeybindClosedGui()
beginClose()
requestCloseCallback?.invoke()
} else {
HudManager.openEditor()
}
Expand Down Expand Up @@ -264,6 +277,7 @@ class OneConfigUIScreen @JvmOverloads constructor(
// and that would queue a fullscreen blur which smears over the popup so bail unless we are current
if (Platform.screen().current<Any?>() !== this) return
if (closeRequested && System.currentTimeMillis() - closeRequestedAt >= closeAnimationMs) {
markClosed()
//? if < 1.21.8
//renderBackground(ctx, mouseX, mouseY, tickDelta)
Platform.screen().close()
Expand Down Expand Up @@ -321,6 +335,7 @@ class OneConfigUIScreen @JvmOverloads constructor(

/** Holds a reference to the close-animation trigger from Compose */
private var requestCloseCallback: (() -> Unit)? = null
private var requestOpenCallback: (() -> Unit)? = null

@Composable
override fun compose() {
Expand All @@ -337,6 +352,9 @@ class OneConfigUIScreen @JvmOverloads constructor(
onCloseReady = { closeRequest ->
requestCloseCallback = closeRequest
},
onOpenReady = { openRequest ->
requestOpenCallback = openRequest
},
) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fun OneConfigInterface(
restoring: Boolean = false,
onCloseRequest: () -> Unit = {},
onCloseReady: ((requestClose: () -> Unit) -> Unit)? = null,
onOpenReady: ((requestOpen: () -> Unit) -> Unit)? = null,
shellBackdrop: DrawScope.(Offset) -> Unit = {}
) {
ThemeRegistry.init()
Expand Down Expand Up @@ -139,9 +140,11 @@ fun OneConfigInterface(
}

val requestClose: () -> Unit = { visible = false }
val requestOpen: () -> Unit = { visible = true }

SideEffect {
onCloseReady?.invoke(requestClose)
onOpenReady?.invoke(requestOpen)
}

CompositionLocalProvider(LocalCloseRequest provides requestClose) {
Expand Down
Loading