From 2fed7255a726a8a60dd15e94974336144119d449 Mon Sep 17 00:00:00 2001 From: nextdayy <79922345+nextdayy@users.noreply.github.com> Date: Wed, 13 Nov 2024 13:34:53 +0000 Subject: [PATCH] fix scale blob --- gradle/libs.versions.toml | 2 +- .../config/v1/internal/ConfigVisualizer.kt | 8 +++---- .../api/hud/v1/internal/hud_utils.kt | 21 ++++++++++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index de3698753..832e33db6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ kotlin = "2.0.20" kotlinx-coroutines = "1.8.1" kotlinx-atomicfu = "0.24.0" fabric-language-kotlin = "1.12.2+kotlin.2.0.20" -polyui = "1.7.25" +polyui = "1.7.26" annotations = "24.1.0" hypixel-modapi = "1.0" hypixel-data = "0.1.2" # Dep of hypixel-modapi diff --git a/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/internal/ConfigVisualizer.kt b/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/internal/ConfigVisualizer.kt index 5eec45108..7fbf0d50b 100644 --- a/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/internal/ConfigVisualizer.kt +++ b/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/internal/ConfigVisualizer.kt @@ -319,15 +319,15 @@ open class ConfigVisualizer { if (!initialized) { this.afterParentInit(Int.MAX_VALUE) { layoutIgnored = true - x = -100f - y = -100f + x = 1000000f + y = 1000000f parent.position() renders = false } } else { layoutIgnored = true - x = -100f - y = -100f + x = 1000000f + y = 1000000f parent.position() renders = false } diff --git a/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/internal/hud_utils.kt b/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/internal/hud_utils.kt index 9585fd1aa..6c99d9580 100644 --- a/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/internal/hud_utils.kt +++ b/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/internal/hud_utils.kt @@ -40,6 +40,7 @@ import org.polyfrost.polyui.event.Event import org.polyfrost.polyui.unit.Point import org.polyfrost.polyui.unit.by import org.polyfrost.polyui.utils.fastEach +import kotlin.math.sqrt private val LOGGER = LogManager.getLogger("OneConfig/HUD") @@ -53,18 +54,21 @@ private val scaleBlob by lazy { ).radius(10f).draggable().onDragStart { sx = polyUI.mouseX sy = polyUI.mouseY - st = scaleX - }.onDragEnd { + st = cur?.scaleX ?: 1f + }.onDrag { cur?.let { val dx = polyUI.mouseX - sx val dy = polyUI.mouseY - sy - val s = st + (((dx + dy) / (it.width + it.height))).coerceIn(0.5f, 3f) + val dst = sqrt(dx * dx + dy * dy) + val init = sqrt(it.width * it.width + it.height * it.height) + val sign = if(dx + dy < 0f) -1f else 1f + val s = (st + sign * (dst / init)).coerceIn(0.5f, 3f) + it.scaleX = s it.scaleY = s x = it.x + (it.width * s) - (width / 2f) y = it.y + (it.height * s) - (height / 2f) } - true }.apply { // addEventHandler(Event.Mouse.Pressed(0)) { // if(!polyUI.inputManager.hasFocused) polyUI.focus(this) @@ -261,6 +265,13 @@ private fun Drawable.trySnapY(ly: Float): Boolean { * Method to be used as the `onDrag` handler for HUD elements. */ fun Drawable.snapHandler() { + if (cur === this) { + val vs = visibleSize + scaleBlob.let { + it.x = x + vs.x - (it.width / 2f) + it.y = y + vs.y - (it.height / 2f) + } + } HudManager.slinex = -1f HudManager.sliney = -1f if (HudManager.panelOpen) return @@ -281,7 +292,7 @@ fun Drawable.snapHandler() { // expensive! polyUI.master.children?.fastEach { if (it === this) return@fastEach - if (it === HudManager.panel) return@fastEach + if (it === HudManager.panel || it === scaleBlob) return@fastEach if (!it.renders) return@fastEach if (!hran) {