From a85e186cd68794e66d74b67b7cbd15c729028ca3 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 8 Nov 2022 00:30:32 +0100 Subject: [PATCH 01/19] Focus test --- .../kotlin/com/lambda/client/module/modules/client/ClickGUI.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt index 6edbb12ce..b8deb70ce 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt @@ -92,6 +92,7 @@ object ClickGUI : Module( if (mc.currentScreen !is LambdaClickGui) { HudEditor.disable() mc.displayGuiScreen(LambdaClickGui) + LambdaClickGui.isFocused = true LambdaClickGui.onDisplayed() } } From 8080b6e1b8ba5b6c92fed0af810018fdfaf9d6d4 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 8 Nov 2022 00:31:14 +0100 Subject: [PATCH 02/19] Hide module feature --- .../client/gui/clickgui/LambdaClickGui.kt | 22 +++++-------------- .../lambda/client/module/AbstractModule.kt | 1 + .../kotlin/com/lambda/client/module/Module.kt | 6 +++-- .../lambda/client/plugin/api/PluginModule.kt | 4 +++- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt index 09ca83968..b4c7280db 100644 --- a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt +++ b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt @@ -9,6 +9,7 @@ import com.lambda.client.gui.clickgui.window.ModuleSettingWindow import com.lambda.client.gui.rgui.Component import com.lambda.client.gui.rgui.windows.ListWindow import com.lambda.client.module.AbstractModule +import com.lambda.client.module.Category import com.lambda.client.module.ModuleManager import com.lambda.client.module.modules.client.ClickGUI import com.lambda.client.plugin.PluginManager @@ -37,26 +38,14 @@ object LambdaClickGui : AbstractLambdaGui() private var moduleCount = ModuleManager.modules.size init { - val allButtons = ModuleManager.modules - .groupBy { it.category.displayName } - .mapValues { (_, modules) -> modules.map { ModuleButton(it) } } - var posX = 0.0f - var posY = 0.0f - val screenWidth = mc.displayWidth / ClickGUI.getScaleFactorFloat() + val posY = 0.0f - /* Modules */ - for ((category, buttons) in allButtons) { - val window = ListWindow(category, posX, posY, 90.0f, 300.0f, Component.SettingGroup.CLICK_GUI) - - window.addAll(buttons.customSort()) + Category.values().forEach { + val window = ListWindow(it.displayName, posX, posY, 90.0f, 300.0f, Component.SettingGroup.CLICK_GUI) windows.add(window) - posX += 90.0f - if (posX > screenWidth) { - posX = 0.0f - posY += 100.0f - } + posX += 90.0f } /* Plugins */ @@ -283,6 +272,7 @@ object LambdaClickGui : AbstractLambdaGui() fun reorderModules() { moduleCount = ModuleManager.modules.size val allButtons = ModuleManager.modules + .filter { !it.hidden } .groupBy { it.category.displayName } .mapValues { (_, modules) -> modules.map { ModuleButton(it) } } diff --git a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt index 98801b158..593aca9e1 100644 --- a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt +++ b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt @@ -27,6 +27,7 @@ abstract class AbstractModule( val showOnArray: Boolean = true, val alwaysEnabled: Boolean = false, val enabledByDefault: Boolean = false, + val hidden: Boolean = false, private val config: NameableConfig ) : Nameable, Alias, SettingRegister by config as NameableConfig { diff --git a/src/main/kotlin/com/lambda/client/module/Module.kt b/src/main/kotlin/com/lambda/client/module/Module.kt index 38413c20d..ca2f390ee 100644 --- a/src/main/kotlin/com/lambda/client/module/Module.kt +++ b/src/main/kotlin/com/lambda/client/module/Module.kt @@ -11,7 +11,8 @@ abstract class Module( alwaysListening: Boolean = false, showOnArray: Boolean = true, alwaysEnabled: Boolean = false, - enabledByDefault: Boolean = false + enabledByDefault: Boolean = false, + hidden: Boolean = false ) : AbstractModule( name, alias, @@ -22,5 +23,6 @@ abstract class Module( showOnArray, alwaysEnabled, enabledByDefault, - ModuleConfig + hidden, + ModuleConfig, ) \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt b/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt index 5ab99d514..00934529f 100644 --- a/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt +++ b/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt @@ -13,7 +13,8 @@ abstract class PluginModule( alwaysListening: Boolean = false, showOnArray: Boolean = true, alwaysEnabled: Boolean = false, - enabledByDefault: Boolean = false + enabledByDefault: Boolean = false, + hidden: Boolean = false ) : IPluginClass, AbstractModule( name, alias, @@ -24,5 +25,6 @@ abstract class PluginModule( showOnArray, alwaysEnabled, enabledByDefault, + hidden, pluginMain.config ) \ No newline at end of file From a9c2272ad35bbc7cbd9e32697018b41e926ca249 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 11 Nov 2022 06:52:56 +0100 Subject: [PATCH 03/19] Window grid snapping --- .../lambda/client/gui/rgui/WindowComponent.kt | 24 +++++++++++-------- .../client/module/modules/client/ClickGUI.kt | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt index 9c7d981e5..580f88e2f 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt @@ -1,6 +1,7 @@ package com.lambda.client.gui.rgui import com.lambda.client.commons.interfaces.Nameable +import com.lambda.client.module.modules.client.ClickGUI.gridSize import com.lambda.client.setting.GuiConfig.setting import com.lambda.client.setting.configs.AbstractConfig import com.lambda.client.util.graphics.AnimationUtils @@ -9,6 +10,7 @@ import com.lambda.client.util.graphics.font.VAlign import com.lambda.client.util.math.Vec2f import kotlin.math.max import kotlin.math.min +import kotlin.math.roundToInt open class WindowComponent( name: String, @@ -123,8 +125,8 @@ open class WindowComponent( onResize() } else if (draggableHeight == height || relativeClickPos.y <= draggableHeight) { - posX = (preDragPos.x + draggedDist.x).coerceIn(1.0f, mc.displayWidth - width - 1.0f) - posY = (preDragPos.y + draggedDist.y).coerceIn(1.0f, mc.displayHeight - height - 1.0f) + posX = roundOnGrid(preDragPos.x + draggedDist.x).coerceIn(.0f, mc.displayWidth - width) + posY = roundOnGrid(preDragPos.y + draggedDist.y).coerceIn(.0f, mc.displayHeight - height) onReposition() } else { @@ -136,8 +138,8 @@ open class WindowComponent( private fun handleResizeX(horizontalSide: HAlign, draggedDist: Vec2f) { when (horizontalSide) { HAlign.LEFT -> { - val draggedX = max(draggedDist.x, 1.0f - preDragPos.x) - var newWidth = max(preDragSize.x - draggedX, minWidth) + val draggedX = max(roundOnGrid(draggedDist.x), 1.0f - preDragPos.x) + var newWidth = max(roundOnGrid(preDragSize.x - draggedX), minWidth) if (maxWidth != -1.0f) newWidth = min(newWidth, maxWidth) newWidth = min(newWidth, scaledDisplayWidth - 2.0f) @@ -147,8 +149,8 @@ open class WindowComponent( posX += prevWidth - newWidth } HAlign.RIGHT -> { - val draggedX = min(draggedDist.x, preDragPos.x + preDragSize.x - 1.0f) - var newWidth = max(preDragSize.x + draggedX, minWidth) + val draggedX = min(roundOnGrid(draggedDist.x), preDragPos.x + preDragSize.x - 1.0f) + var newWidth = max(roundOnGrid(preDragSize.x + draggedX), minWidth) if (maxWidth != -1.0f) newWidth = min(newWidth, maxWidth) newWidth = min(newWidth, scaledDisplayWidth - posX - 2.0f) @@ -164,8 +166,8 @@ open class WindowComponent( private fun handleResizeY(verticalSide: VAlign, draggedDist: Vec2f) { when (verticalSide) { VAlign.TOP -> { - val draggedY = max(draggedDist.y, 1.0f - preDragPos.y) - var newHeight = max(preDragSize.y - draggedY, minHeight) + val draggedY = max(roundOnGrid(draggedDist.y), 1.0f - preDragPos.y) + var newHeight = max(roundOnGrid(preDragSize.y - draggedY), minHeight) if (maxHeight != -1.0f) newHeight = min(newHeight, maxHeight) newHeight = min(newHeight, scaledDisplayHeight - 2.0f) @@ -175,8 +177,8 @@ open class WindowComponent( posY += prevHeight - newHeight } VAlign.BOTTOM -> { - val draggedY = min(draggedDist.y, preDragPos.y + preDragSize.y - 1.0f) - var newHeight = max(preDragSize.y + draggedY, minHeight) + val draggedY = min(roundOnGrid(draggedDist.y), preDragPos.y + preDragSize.y - 1.0f) + var newHeight = max(roundOnGrid(preDragSize.y + draggedY), minHeight) if (maxHeight != -1.0f) newHeight = min(newHeight, maxHeight) newHeight = min(newHeight, scaledDisplayHeight - posY - 2.0f) @@ -189,6 +191,8 @@ open class WindowComponent( } } + private fun roundOnGrid(delta: Float) = if (gridSize > 0) (delta / gridSize).roundToInt() * gridSize else delta + fun isInWindow(mousePos: Vec2f): Boolean { return visible && mousePos.x in preDragPos.x - 2.0f..preDragPos.x + preDragSize.x + 2.0f && mousePos.y in preDragPos.y - 2.0f..preDragPos.y + max(preDragSize.y * renderMinimizeProgress, draggableHeight) + 2.0f diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt index b8deb70ce..79b060a2e 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt @@ -26,6 +26,7 @@ object ClickGUI : Module( val outlineWidth by setting("Outline Width", 2.5f, 0.5f..3.5f, 0.5f, { windowOutline || buttonOutline }) val entryMargin by setting("Margin", 0.0f, 0.0f..10.0f, 0.5f, unit = "px") val darkness by setting("Darkness", 0.25f, 0.0f..1.0f, 0.05f) + val gridSize by setting("Snap Grid Size", 10.0f, 0.0f..50.0f, 1.0f) val fadeInTime by setting("Fade In Time", 0.25f, 0.0f..1.0f, 0.05f, unit = "s") val fadeOutTime by setting("Fade Out Time", 0.1f, 0.0f..1.0f, 0.05f, unit = "s") val showModifiedInBold by setting("Show Modified In Bold", false, description = "Display modified settings in a bold font") From 81fb2975b207390789a8af61664955a48002bf2c Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 11 Nov 2022 06:54:10 +0100 Subject: [PATCH 04/19] Upgrade Kotlin 1.7.20 -> 1.7.21 --- gradle.properties | 2 +- src/main/kotlin/com/lambda/client/plugin/PluginClassLoader.kt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2499d264b..bd25efc90 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,5 +10,5 @@ forgeVersion=14.23.5.2860 mappingsChannel=stable mappingsVersion=39-1.12 -kotlinVersion=1.7.20 +kotlinVersion=1.7.21 kotlinxCoroutinesVersion=1.6.4 diff --git a/src/main/kotlin/com/lambda/client/plugin/PluginClassLoader.kt b/src/main/kotlin/com/lambda/client/plugin/PluginClassLoader.kt index 35bf375d5..eccfe66d9 100644 --- a/src/main/kotlin/com/lambda/client/plugin/PluginClassLoader.kt +++ b/src/main/kotlin/com/lambda/client/plugin/PluginClassLoader.kt @@ -39,7 +39,6 @@ class PluginClassLoader(jar: JarFile, parent: ClassLoader) : ClassLoader(parent) private fun getClasses(jar: JarFile) { for (entry in jar.entries()) { - if (entry.name.endsWith(".class")) { classes[entry.name.removeSuffix(".class").replace("/", ".")] = getDataFromEntry(jar, entry) } else if (!entry.name.endsWith("/")) { From fb746d4c72fa2564da43ef938adb9828d85f6192 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 13 Nov 2022 03:11:38 +0100 Subject: [PATCH 05/19] Fix frame margin --- .../com/lambda/client/gui/rgui/Component.kt | 12 ++-- .../lambda/client/gui/rgui/WindowComponent.kt | 57 ++++++++----------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/Component.kt b/src/main/kotlin/com/lambda/client/gui/rgui/Component.kt index 689d53070..8bdf242bf 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/Component.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/Component.kt @@ -31,13 +31,13 @@ open class Component( protected val dockingHSetting = setting("Docking H", HAlign.LEFT) protected val dockingVSetting = setting("Docking V", VAlign.TOP) - private var widthSetting = setting("Width", widthIn, 0.0f..69420.911f, 0.1f, { false }, { _, it -> it.coerceIn(minWidth, max(scaledDisplayWidth, minWidth)) }) - private var heightSetting = setting("Height", heightIn, 0.0f..69420.911f, 0.1f, { false }, { _, it -> it.coerceIn(minHeight, max(scaledDisplayHeight, minHeight)) }) + private var widthSetting = setting("Width", widthIn, 0.0f..69420.914f, 0.1f, { false }, { _, it -> it.coerceIn(minWidth, max(scaledDisplayWidth, minWidth)) }) + private var heightSetting = setting("Height", heightIn, 0.0f..69420.914f, 0.1f, { false }, { _, it -> it.coerceIn(minHeight, max(scaledDisplayHeight, minHeight)) }) - private var relativePosXSetting = setting("Pos X", posXIn, -69420.911f..69420.911f, 0.1f, { false }, - { _, it -> if (this is WindowComponent && LambdaMod.ready) absToRelativeX(relativeToAbsX(it).coerceIn(1.0f, max(scaledDisplayWidth - width - 1.0f, 1.0f))) else it }) - private var relativePosYSetting = setting("Pos Y", posYIn, -69420.911f..69420.911f, 0.1f, { false }, - { _, it -> if (this is WindowComponent && LambdaMod.ready) absToRelativeY(relativeToAbsY(it).coerceIn(1.0f, max(scaledDisplayHeight - height - 1.0f, 1.0f))) else it }) + private var relativePosXSetting = setting("Pos X", posXIn, -69420.914f..69420.914f, 0.1f, { false }, + { _, it -> if (this is WindowComponent && LambdaMod.ready) absToRelativeX(relativeToAbsX(it).coerceIn(.0f, max(scaledDisplayWidth - width, .0f))) else it }) + private var relativePosYSetting = setting("Pos Y", posYIn, -69420.914f..69420.914f, 0.1f, { false }, + { _, it -> if (this is WindowComponent && LambdaMod.ready) absToRelativeY(relativeToAbsY(it).coerceIn(.0f, max(scaledDisplayHeight - height, .0f))) else it }) var width by widthSetting open var height by heightSetting diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt index 580f88e2f..143a786d6 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt @@ -116,53 +116,46 @@ open class WindowComponent( else -> null } + if (horizontalSide == null || verticalSide == null) return val draggedDist = mousePos.minus(clickPos) - if (horizontalSide != null && verticalSide != null) { - if (resizable && !minimized && (horizontalSide != HAlign.CENTER || verticalSide != VAlign.CENTER)) { - handleResizeX(horizontalSide, draggedDist) - handleResizeY(verticalSide, draggedDist) + if (resizable && !minimized && (horizontalSide != HAlign.CENTER || verticalSide != VAlign.CENTER)) { + handleResizeX(horizontalSide, draggedDist) + handleResizeY(verticalSide, draggedDist) - onResize() - } else if (draggableHeight == height || relativeClickPos.y <= draggableHeight) { - posX = roundOnGrid(preDragPos.x + draggedDist.x).coerceIn(.0f, mc.displayWidth - width) - posY = roundOnGrid(preDragPos.y + draggedDist.y).coerceIn(.0f, mc.displayHeight - height) + onResize() + } else if (draggableHeight == height || relativeClickPos.y <= draggableHeight) { + posX = roundOnGrid(preDragPos.x + draggedDist.x).coerceIn(.0f, mc.displayWidth - width) + posY = roundOnGrid(preDragPos.y + draggedDist.y).coerceIn(.0f, mc.displayHeight - height) - onReposition() - } else { - // TODO - } + onReposition() } } private fun handleResizeX(horizontalSide: HAlign, draggedDist: Vec2f) { when (horizontalSide) { HAlign.LEFT -> { - val draggedX = max(roundOnGrid(draggedDist.x), 1.0f - preDragPos.x) - var newWidth = max(roundOnGrid(preDragSize.x - draggedX), minWidth) - - if (maxWidth != -1.0f) newWidth = min(newWidth, maxWidth) - newWidth = min(newWidth, scaledDisplayWidth - 2.0f) - - val prevWidth = width - width = newWidth - posX += prevWidth - newWidth + resizeHandle(draggedDist,1.0f - preDragPos.x) } HAlign.RIGHT -> { - val draggedX = min(roundOnGrid(draggedDist.x), preDragPos.x + preDragSize.x - 1.0f) - var newWidth = max(roundOnGrid(preDragSize.x + draggedX), minWidth) - - if (maxWidth != -1.0f) newWidth = min(newWidth, maxWidth) - newWidth = min(newWidth, scaledDisplayWidth - posX - 2.0f) - - width = newWidth + resizeHandle(draggedDist,preDragPos.x + preDragSize.x - 1.0f) } - else -> { - // Nothing lol + HAlign.CENTER -> { + // Nothing } } } + private fun resizeHandle(draggedDist: Vec2f, maxDrag: Float) { + val draggedX = min(roundOnGrid(draggedDist.x), maxDrag) + var newWidth = max(roundOnGrid(preDragSize.x + draggedX), minWidth) + + if (maxWidth != -1.0f) newWidth = min(newWidth, maxWidth) + newWidth = min(newWidth, scaledDisplayWidth - posX - 2.0f) + + width = newWidth + } + private fun handleResizeY(verticalSide: VAlign, draggedDist: Vec2f) { when (verticalSide) { VAlign.TOP -> { @@ -185,8 +178,8 @@ open class WindowComponent( height = newHeight } - else -> { - // Nothing lol + VAlign.CENTER -> { + // Nothing } } } From a20d5624c4386a8eaf924ef34f9ff299a65d80cf Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 13 Nov 2022 04:23:37 +0100 Subject: [PATCH 06/19] Resize corner ToDo: change render layer --- .../com/lambda/client/gui/rgui/windows/BasicWindow.kt | 11 +++++++++++ .../lambda/client/module/modules/client/ClickGUI.kt | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/BasicWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/BasicWindow.kt index 7e542993e..ff1b8166f 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/BasicWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/BasicWindow.kt @@ -32,6 +32,7 @@ open class BasicWindow( ClickGUI.radius, color = GuiColors.backGround ) + if (ClickGUI.windowOutline) { RenderUtils2D.drawRoundedRectOutline( vertexHelper, @@ -42,6 +43,16 @@ open class BasicWindow( color = GuiColors.outline ) } + + if (ClickGUI.resizeCorner) { + RenderUtils2D.drawTriangleFilled( + vertexHelper, + Vec2f(renderWidth, renderHeight - ClickGUI.resizeCornerSize).toVec2d(), + Vec2f(renderWidth, renderHeight).toVec2d(), + Vec2f(renderWidth - ClickGUI.resizeCornerSize, renderHeight).toVec2d(), + GuiColors.hover + ) + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt index 79b060a2e..da7136c05 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt @@ -23,6 +23,8 @@ object ClickGUI : Module( val blur by setting("Blur", 0.0f, 0.0f..1.0f, 0.05f) val windowOutline by setting("Window Outline", false) val buttonOutline by setting("Button Outline", false) + val resizeCorner by setting("Resize Corner", true) + val resizeCornerSize by setting("Corner Size", 10, 5..30, 1, { resizeCorner }, unit = "px") val outlineWidth by setting("Outline Width", 2.5f, 0.5f..3.5f, 0.5f, { windowOutline || buttonOutline }) val entryMargin by setting("Margin", 0.0f, 0.0f..10.0f, 0.5f, unit = "px") val darkness by setting("Darkness", 0.25f, 0.0f..1.0f, 0.05f) From d984b8b564b7957e50bf1a9574a30510b946e8ec Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 13 Nov 2022 06:25:51 +0100 Subject: [PATCH 07/19] Change mutex to sync block --- .../client/gui/rgui/windows/ListWindow.kt | 93 ++++++++----------- 1 file changed, 41 insertions(+), 52 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt index dd00cad74..48e91f32d 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt @@ -29,7 +29,6 @@ open class ListWindow( vararg childrenIn: Component ) : TitledWindow(name, posX, posY, width, height, saveToConfig) { val children = ArrayList() - private val contentMutex = Mutex() override val minWidth = 80.0f override val minHeight = 200.0f @@ -65,65 +64,57 @@ open class ListWindow( } fun addAll(all: Collection) { - runBlocking { - contentMutex.withLock { - children.addAll(all) - } + synchronized(this) { + children.addAll(all) } } fun add(c: Component) { - runBlocking { - contentMutex.withLock { - children.add(c) - } + synchronized(this) { + children.add(c) } } fun remove(c: Component) { - runBlocking { - contentMutex.withLock { - children.remove(c) - } + synchronized(this) { + children.remove(c) } } fun clear() { - runBlocking { - contentMutex.withLock { - children.clear() - } + synchronized(this) { + children.clear() } } private fun updateChild() { - runBlocking { - contentMutex.withLock { - var y = (if (draggableHeight != height) draggableHeight else 0.0f) + ClickGUI.entryMargin - for (child in children) { - if (!child.visible) continue - child.posX = ClickGUI.entryMargin * 1.618f - child.posY = y - child.width = width - ClickGUI.entryMargin * 3.236f - y += child.height + ClickGUI.entryMargin + synchronized(this) { + var y = (if (draggableHeight != height) draggableHeight else 0.0f) + ClickGUI.entryMargin + + children + .filter { it.visible } + .forEach { + it.posX = ClickGUI.entryMargin * 1.618f + it.posY = y + it.width = width - ClickGUI.entryMargin * 3.236f + y += it.height + ClickGUI.entryMargin } - } } } override fun onDisplayed() { super.onDisplayed() - for (child in children) child.onDisplayed() + children.forEach { it.onDisplayed() } } override fun onClosed() { super.onClosed() - for (child in children) child.onClosed() + children.forEach { it.onClosed() } } override fun onGuiInit() { super.onGuiInit() - for (child in children) child.onGuiInit() + children.forEach { it.onGuiInit() } updateChild() } @@ -135,12 +126,14 @@ open class ListWindow( override fun onTick() { super.onTick() if (children.isEmpty()) return + val lastVisible = children.lastOrNull { it.visible } val maxScrollProgress = lastVisible?.let { max(it.posY + it.height + ClickGUI.entryMargin - height, 0.01f) } ?: draggableHeight scrollProgress = (scrollProgress + scrollSpeed) scrollSpeed *= 0.5f + if (scrollTimer.tick(100L, false)) { if (scrollProgress < 0.0) { scrollSpeed = scrollProgress * -0.25f @@ -150,17 +143,15 @@ open class ListWindow( } updateChild() - for (child in children) child.onTick() + children.forEach { it.onTick() } } override fun onRender(vertexHelper: VertexHelper, absolutePos: Vec2f) { super.onRender(vertexHelper, absolutePos) - runBlocking { - contentMutex.withLock { - renderChildren { - it.onRender(vertexHelper, absolutePos.plus(it.renderPosX, it.renderPosY - renderScrollProgress)) - } + synchronized(this) { + renderChildren { + it.onRender(vertexHelper, absolutePos.plus(it.renderPosX, it.renderPosY - renderScrollProgress)) } } } @@ -168,19 +159,14 @@ open class ListWindow( override fun onPostRender(vertexHelper: VertexHelper, absolutePos: Vec2f) { super.onPostRender(vertexHelper, absolutePos) - runBlocking { - contentMutex.withLock { - renderChildren { - it.onPostRender(vertexHelper, absolutePos.plus(it.renderPosX, it.renderPosY - renderScrollProgress)) - } + synchronized(this) { + renderChildren { + it.onPostRender(vertexHelper, absolutePos.plus(it.renderPosX, it.renderPosY - renderScrollProgress)) } } } - fun containsName(name: String): Boolean = - children.any { - it.name == name - } + fun containsName(name: String): Boolean = children.any { it.name == name } private fun renderChildren(renderBlock: (Component) -> Unit) { GlStateUtils.scissor( @@ -192,13 +178,13 @@ open class ListWindow( glEnable(GL_SCISSOR_TEST) glTranslatef(0.0f, -renderScrollProgress, 0.0f) - for (child in children) { - if (!child.visible) continue - if (child.renderPosY + child.renderHeight - renderScrollProgress < draggableHeight) continue - if (child.renderPosY - renderScrollProgress > renderHeight) continue + children.filter { it.visible + && it.renderPosY + it.renderHeight - renderScrollProgress > draggableHeight + && it.renderPosY - renderScrollProgress < renderHeight + }.forEach { glPushMatrix() - glTranslatef(child.renderPosX, child.renderPosY, 0.0f) - renderBlock(child) + glTranslatef(it.renderPosX, it.renderPosY, 0.0f) + renderBlock(it) glPopMatrix() } @@ -222,7 +208,10 @@ open class ListWindow( } private fun updateHovered(relativeMousePos: Vec2f) { - hoveredChild = if (relativeMousePos.y < draggableHeight || relativeMousePos.x < ClickGUI.entryMargin || relativeMousePos.x > renderWidth - ClickGUI.entryMargin) null + hoveredChild = if (relativeMousePos.y < draggableHeight + || relativeMousePos.x < ClickGUI.entryMargin + || relativeMousePos.x > renderWidth - ClickGUI.entryMargin + ) null else children.firstOrNull { it.visible && relativeMousePos.y in it.posY..it.posY + it.height } } From 47fbecc1e7e3362fc32f8d8c6915903883cefb98 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 14 Nov 2022 04:26:07 +0100 Subject: [PATCH 08/19] Added freemove --- .../kotlin/com/lambda/client/gui/rgui/WindowComponent.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt index 143a786d6..fde9cd1f0 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt @@ -8,6 +8,7 @@ import com.lambda.client.util.graphics.AnimationUtils import com.lambda.client.util.graphics.font.HAlign import com.lambda.client.util.graphics.font.VAlign import com.lambda.client.util.math.Vec2f +import org.lwjgl.input.Keyboard import kotlin.math.max import kotlin.math.min import kotlin.math.roundToInt @@ -184,7 +185,11 @@ open class WindowComponent( } } - private fun roundOnGrid(delta: Float) = if (gridSize > 0) (delta / gridSize).roundToInt() * gridSize else delta + private fun roundOnGrid(delta: Float) = + if (gridSize == .0f + || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) + || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) + ) delta else (delta / gridSize).roundToInt() * gridSize fun isInWindow(mousePos: Vec2f): Boolean { return visible && mousePos.x in preDragPos.x - 2.0f..preDragPos.x + preDragSize.x + 2.0f From 2642ce21a0a425c543ac7d86f96ea049967b0166 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 14 Nov 2022 05:16:40 +0100 Subject: [PATCH 09/19] Code refactor --- .../client/gui/clickgui/LambdaClickGui.kt | 9 ++-- .../lambda/client/gui/hudgui/LambdaHudGui.kt | 43 ++++++++----------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt index b4c7280db..d965ad53f 100644 --- a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt +++ b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt @@ -39,24 +39,23 @@ object LambdaClickGui : AbstractLambdaGui() init { var posX = 0.0f - val posY = 0.0f - Category.values().forEach { - val window = ListWindow(it.displayName, posX, posY, 90.0f, 300.0f, Component.SettingGroup.CLICK_GUI) + Category.values().forEach { category -> + val window = ListWindow(category.displayName, posX, 0.0f, 90.0f, 300.0f, Component.SettingGroup.CLICK_GUI) windows.add(window) posX += 90.0f } /* Plugins */ - pluginWindow = PluginWindow("Plugins", posX, posY) + pluginWindow = PluginWindow("Plugins", posX, 0.0f) pluginWindow.add(ImportPluginButton) pluginWindow.add(DownloadPluginButton) windows.add(pluginWindow) posX += 120.0f - remotePluginWindow = PluginWindow("Remote plugins", posX, posY) + remotePluginWindow = PluginWindow("Remote plugins", posX, 0.0f) remotePluginWindow.visible = false windows.add(remotePluginWindow) diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/LambdaHudGui.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/LambdaHudGui.kt index f119fab0e..34f179f50 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/LambdaHudGui.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/LambdaHudGui.kt @@ -3,7 +3,6 @@ package com.lambda.client.gui.hudgui import com.lambda.client.event.events.RenderOverlayEvent import com.lambda.client.event.listener.listener import com.lambda.client.gui.AbstractLambdaGui -import com.lambda.client.gui.clickgui.LambdaClickGui import com.lambda.client.gui.hudgui.component.HudButton import com.lambda.client.gui.hudgui.window.HudSettingWindow import com.lambda.client.gui.rgui.Component @@ -14,6 +13,7 @@ import com.lambda.client.module.modules.client.HudEditor import com.lambda.client.util.graphics.GlStateUtils import com.lambda.client.util.graphics.VertexHelper import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.InputEvent import org.lwjgl.input.Keyboard import org.lwjgl.opengl.GL11.* @@ -26,20 +26,13 @@ object LambdaHudGui : AbstractLambdaGui() init { var posX = 0.0f - var posY = 0.0f - val screenWidth = LambdaClickGui.mc.displayWidth / ClickGUI.getScaleFactorFloat() - for (category in AbstractHudElement.Category.values()) { + AbstractHudElement.Category.values().forEach { category -> val window = ListWindow(category.displayName, posX, 0.0f, 90.0f, 300.0f, Component.SettingGroup.HUD_GUI) windowList.add(window) hudWindows[category] = window posX += 90.0f - - if (posX > screenWidth) { - posX = 0.0f - posY += 100.0f - } } listener { @@ -47,22 +40,21 @@ object LambdaHudGui : AbstractLambdaGui() if (eventKey == Keyboard.KEY_NONE || Keyboard.isKeyDown(Keyboard.KEY_F3)) return@listener - for (child in windowList) { - if (child !is AbstractHudElement) continue - if (!child.bind.isDown(eventKey)) continue - child.visible = !child.visible - } + windowList + .filterIsInstance() + .filter { it.bind.isDown(eventKey) } + .forEach { it.visible = !it.visible } } } internal fun register(hudElement: AbstractHudElement) { val button = HudButton(hudElement) - hudWindows[hudElement.category]!!.add(button) + hudWindows[hudElement.category]?.add(button) windowList.add(hudElement) } internal fun unregister(hudElement: AbstractHudElement) { - hudWindows[hudElement.category]!!.children.removeIf { it is HudButton && it.hudElement == hudElement } + hudWindows[hudElement.category]?.children?.removeIf { it is HudButton && it.hudElement == hudElement } windowList.remove(hudElement) } @@ -98,27 +90,26 @@ object LambdaHudGui : AbstractLambdaGui() } private fun setHudButtonVisibility(function: (HudButton) -> Boolean) { - windowList.filterIsInstance().forEach { - for (child in it.children) { - if (child !is HudButton) continue - child.visible = function(child) + windowList.filterIsInstance().forEach { window -> + window.children.filterIsInstance().forEach { button -> + button.visible = function(button) } } } init { - listener(0) { - if (mc?.world == null || mc?.player == null || mc?.currentScreen == this || mc?.gameSettings?.showDebugInfo != false) return@listener + safeListener(0) { + if (Hud.isDisabled) return@safeListener val vertexHelper = VertexHelper(GlStateUtils.useVbo()) GlStateUtils.rescaleLambda() - if (Hud.isEnabled) { - for (window in windowList) { - if (window !is AbstractHudElement || !window.visible) continue + windowList + .filterIsInstance() + .filter { it.visible } + .forEach { window -> renderHudElement(vertexHelper, window) } - } GlStateUtils.rescaleMc() GlStateUtils.depth(true) From 45766d054c491106275500a2dcd025590557cf34 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 14 Nov 2022 05:23:33 +0100 Subject: [PATCH 10/19] Revert hide buttons bc it broke plugins --- .../kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt | 2 +- src/main/kotlin/com/lambda/client/module/AbstractModule.kt | 2 +- src/main/kotlin/com/lambda/client/module/Module.kt | 4 ++-- src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt index d965ad53f..12d2b4f49 100644 --- a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt +++ b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt @@ -271,7 +271,7 @@ object LambdaClickGui : AbstractLambdaGui() fun reorderModules() { moduleCount = ModuleManager.modules.size val allButtons = ModuleManager.modules - .filter { !it.hidden } +// .filter { !it.hidden } .groupBy { it.category.displayName } .mapValues { (_, modules) -> modules.map { ModuleButton(it) } } diff --git a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt index 593aca9e1..fa45b717b 100644 --- a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt +++ b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt @@ -27,7 +27,7 @@ abstract class AbstractModule( val showOnArray: Boolean = true, val alwaysEnabled: Boolean = false, val enabledByDefault: Boolean = false, - val hidden: Boolean = false, +// val hidden: Boolean = false, private val config: NameableConfig ) : Nameable, Alias, SettingRegister by config as NameableConfig { diff --git a/src/main/kotlin/com/lambda/client/module/Module.kt b/src/main/kotlin/com/lambda/client/module/Module.kt index ca2f390ee..910351e2f 100644 --- a/src/main/kotlin/com/lambda/client/module/Module.kt +++ b/src/main/kotlin/com/lambda/client/module/Module.kt @@ -12,7 +12,7 @@ abstract class Module( showOnArray: Boolean = true, alwaysEnabled: Boolean = false, enabledByDefault: Boolean = false, - hidden: Boolean = false +// hidden: Boolean = false ) : AbstractModule( name, alias, @@ -23,6 +23,6 @@ abstract class Module( showOnArray, alwaysEnabled, enabledByDefault, - hidden, +// hidden, ModuleConfig, ) \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt b/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt index 00934529f..3004cd929 100644 --- a/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt +++ b/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt @@ -14,7 +14,7 @@ abstract class PluginModule( showOnArray: Boolean = true, alwaysEnabled: Boolean = false, enabledByDefault: Boolean = false, - hidden: Boolean = false +// hidden: Boolean = false ) : IPluginClass, AbstractModule( name, alias, @@ -25,6 +25,6 @@ abstract class PluginModule( showOnArray, alwaysEnabled, enabledByDefault, - hidden, +// hidden, pluginMain.config ) \ No newline at end of file From b57d62926b31650562a5ebb7d3550eedd091a706 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 14 Nov 2022 05:31:16 +0100 Subject: [PATCH 11/19] Oopsie --- .../kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt | 1 - src/main/kotlin/com/lambda/client/module/AbstractModule.kt | 1 - src/main/kotlin/com/lambda/client/module/Module.kt | 6 ++---- .../kotlin/com/lambda/client/plugin/api/PluginModule.kt | 4 +--- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt index 12d2b4f49..7de0eef7f 100644 --- a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt +++ b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt @@ -271,7 +271,6 @@ object LambdaClickGui : AbstractLambdaGui() fun reorderModules() { moduleCount = ModuleManager.modules.size val allButtons = ModuleManager.modules -// .filter { !it.hidden } .groupBy { it.category.displayName } .mapValues { (_, modules) -> modules.map { ModuleButton(it) } } diff --git a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt index fa45b717b..98801b158 100644 --- a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt +++ b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt @@ -27,7 +27,6 @@ abstract class AbstractModule( val showOnArray: Boolean = true, val alwaysEnabled: Boolean = false, val enabledByDefault: Boolean = false, -// val hidden: Boolean = false, private val config: NameableConfig ) : Nameable, Alias, SettingRegister by config as NameableConfig { diff --git a/src/main/kotlin/com/lambda/client/module/Module.kt b/src/main/kotlin/com/lambda/client/module/Module.kt index 910351e2f..38413c20d 100644 --- a/src/main/kotlin/com/lambda/client/module/Module.kt +++ b/src/main/kotlin/com/lambda/client/module/Module.kt @@ -11,8 +11,7 @@ abstract class Module( alwaysListening: Boolean = false, showOnArray: Boolean = true, alwaysEnabled: Boolean = false, - enabledByDefault: Boolean = false, -// hidden: Boolean = false + enabledByDefault: Boolean = false ) : AbstractModule( name, alias, @@ -23,6 +22,5 @@ abstract class Module( showOnArray, alwaysEnabled, enabledByDefault, -// hidden, - ModuleConfig, + ModuleConfig ) \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt b/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt index 3004cd929..5ab99d514 100644 --- a/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt +++ b/src/main/kotlin/com/lambda/client/plugin/api/PluginModule.kt @@ -13,8 +13,7 @@ abstract class PluginModule( alwaysListening: Boolean = false, showOnArray: Boolean = true, alwaysEnabled: Boolean = false, - enabledByDefault: Boolean = false, -// hidden: Boolean = false + enabledByDefault: Boolean = false ) : IPluginClass, AbstractModule( name, alias, @@ -25,6 +24,5 @@ abstract class PluginModule( showOnArray, alwaysEnabled, enabledByDefault, -// hidden, pluginMain.config ) \ No newline at end of file From 06139db0eef8e16e58a9e537733e06d3be8b61de Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 16 Nov 2022 02:23:25 +0100 Subject: [PATCH 12/19] Fix hover object bug and margin split --- .../lambda/client/gui/AbstractLambdaGui.kt | 19 +++++------ .../client/gui/rgui/component/Slider.kt | 4 ++- .../client/gui/rgui/windows/BasicWindow.kt | 10 ------ .../client/gui/rgui/windows/ListWindow.kt | 33 +++++++++---------- .../client/gui/rgui/windows/SettingWindow.kt | 2 +- .../client/module/modules/client/ClickGUI.kt | 6 ++-- 6 files changed, 32 insertions(+), 42 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/AbstractLambdaGui.kt b/src/main/kotlin/com/lambda/client/gui/AbstractLambdaGui.kt index 16ee3e8fa..8700c1161 100644 --- a/src/main/kotlin/com/lambda/client/gui/AbstractLambdaGui.kt +++ b/src/main/kotlin/com/lambda/client/gui/AbstractLambdaGui.kt @@ -88,15 +88,15 @@ abstract class AbstractLambdaGui, E : Any> : GuiScreen() { safeListener { event -> if (event.phase != TickEvent.Phase.START) return@safeListener - blurShader.shader?.let { + blurShader.shader?.let { shaderGroup -> val multiplier = ClickGUI.blur * fadeMultiplier - for (shader in it.listShaders) { + shaderGroup.listShaders.forEach { shader -> shader.shaderManager.getShaderUniform("multiplier")?.set(multiplier) } } if (displayed.value || alwaysTicking) { - for (window in windowList) window.onTick() + windowList.forEach { it.onTick() } } } @@ -143,7 +143,7 @@ abstract class AbstractLambdaGui, E : Any> : GuiScreen() { displayed.value = true - for (window in windowList) window.onDisplayed() + windowList.forEach { it.onDisplayed() } } override fun initGui() { @@ -153,7 +153,7 @@ abstract class AbstractLambdaGui, E : Any> : GuiScreen() { width = scaledResolution.scaledWidth + 16 height = scaledResolution.scaledHeight + 16 - for (window in windowList) window.onGuiInit() + windowList.forEach { it.onGuiInit() } } override fun onGuiClosed() { @@ -165,7 +165,7 @@ abstract class AbstractLambdaGui, E : Any> : GuiScreen() { displayed.value = false - for (window in windowList) window.onClosed() + windowList.forEach { it.onClosed() } updateSettingWindow() } // End of gui init @@ -318,11 +318,10 @@ abstract class AbstractLambdaGui, E : Any> : GuiScreen() { } private fun drawEachWindow(renderBlock: (WindowComponent) -> Unit) { - for (window in windowList) { - if (!window.visible) continue + windowList.filter { it.visible }.forEach { glPushMatrix() - glTranslatef(window.renderPosX, window.renderPosY, 0.0f) - renderBlock(window) + glTranslatef(it.renderPosX, it.renderPosY, 0.0f) + renderBlock(it) glPopMatrix() } } diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/component/Slider.kt b/src/main/kotlin/com/lambda/client/gui/rgui/component/Slider.kt index 6bc045cfd..61ff711b8 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/component/Slider.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/component/Slider.kt @@ -168,7 +168,9 @@ open class Slider( RenderUtils2D.drawRectFilled( vertexHelper, posEnd = Vec2d(textWidth, textHeight).plus(4.0), - color = GuiColors.backGround.apply { a = (a * alpha).toInt() }) + color = GuiColors.backGround.apply { a = (a * alpha).toInt() } + ) + if (ClickGUI.windowOutline) { RenderUtils2D.drawRectOutline( vertexHelper, diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/BasicWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/BasicWindow.kt index ff1b8166f..f4481512a 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/BasicWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/BasicWindow.kt @@ -43,16 +43,6 @@ open class BasicWindow( color = GuiColors.outline ) } - - if (ClickGUI.resizeCorner) { - RenderUtils2D.drawTriangleFilled( - vertexHelper, - Vec2f(renderWidth, renderHeight - ClickGUI.resizeCornerSize).toVec2d(), - Vec2f(renderWidth, renderHeight).toVec2d(), - Vec2f(renderWidth - ClickGUI.resizeCornerSize, renderHeight).toVec2d(), - GuiColors.hover - ) - } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt index 48e91f32d..677ffe5b2 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt @@ -11,9 +11,6 @@ import com.lambda.client.util.TickTimer import com.lambda.client.util.graphics.GlStateUtils import com.lambda.client.util.graphics.VertexHelper import com.lambda.client.util.math.Vec2f -import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.sync.Mutex -import kotlinx.coroutines.sync.withLock import org.lwjgl.input.Mouse import org.lwjgl.opengl.GL11.* import kotlin.math.max @@ -89,15 +86,15 @@ open class ListWindow( private fun updateChild() { synchronized(this) { - var y = (if (draggableHeight != height) draggableHeight else 0.0f) + ClickGUI.entryMargin + var y = (if (draggableHeight != height) draggableHeight else 0.0f) + ClickGUI.verticalMargin children .filter { it.visible } .forEach { - it.posX = ClickGUI.entryMargin * 1.618f + it.posX = ClickGUI.horizontalMargin it.posY = y - it.width = width - ClickGUI.entryMargin * 3.236f - y += it.height + ClickGUI.entryMargin + it.width = width - ClickGUI.horizontalMargin * 2 + y += it.height + ClickGUI.verticalMargin } } } @@ -128,7 +125,7 @@ open class ListWindow( if (children.isEmpty()) return val lastVisible = children.lastOrNull { it.visible } - val maxScrollProgress = lastVisible?.let { max(it.posY + it.height + ClickGUI.entryMargin - height, 0.01f) } + val maxScrollProgress = lastVisible?.let { max(it.posY + it.height + ClickGUI.horizontalMargin - height, 0.01f) } ?: draggableHeight scrollProgress = (scrollProgress + scrollSpeed) @@ -170,10 +167,10 @@ open class ListWindow( private fun renderChildren(renderBlock: (Component) -> Unit) { GlStateUtils.scissor( - ((renderPosX + ClickGUI.entryMargin * 1.618) * ClickGUI.getScaleFactor() - 0.5f).floorToInt(), - mc.displayHeight - ((renderPosY + renderHeight) * ClickGUI.getScaleFactor() - 0.5f).floorToInt(), - ((renderWidth - ClickGUI.entryMargin * 3.236) * ClickGUI.getScaleFactor() + 1.0f).ceilToInt(), - ((renderHeight - draggableHeight) * ClickGUI.getScaleFactor() + 1.0f).ceilToInt() + ((renderPosX + ClickGUI.horizontalMargin) * ClickGUI.getScaleFactor()).floorToInt(), + mc.displayHeight - ((renderPosY + renderHeight - ClickGUI.resizeBar) * ClickGUI.getScaleFactor()).floorToInt(), + ((renderWidth - ClickGUI.horizontalMargin) * ClickGUI.getScaleFactor()).ceilToInt(), + ((renderHeight - draggableHeight - ClickGUI.resizeBar) * ClickGUI.getScaleFactor()).ceilToInt() ) glEnable(GL_SCISSOR_TEST) glTranslatef(0.0f, -renderScrollProgress, 0.0f) @@ -208,10 +205,12 @@ open class ListWindow( } private fun updateHovered(relativeMousePos: Vec2f) { - hoveredChild = if (relativeMousePos.y < draggableHeight - || relativeMousePos.x < ClickGUI.entryMargin - || relativeMousePos.x > renderWidth - ClickGUI.entryMargin + hoveredChild = if (relativeMousePos.y < draggableHeight + scrollProgress + || relativeMousePos.y > renderHeight + scrollProgress - ClickGUI.resizeBar + || relativeMousePos.x < ClickGUI.horizontalMargin + || relativeMousePos.x > renderWidth - ClickGUI.horizontalMargin ) null + else children.firstOrNull { it.visible && relativeMousePos.y in it.posY..it.posY + it.height } } @@ -260,8 +259,8 @@ open class ListWindow( doubleClickTime = if (currentTime - doubleClickTime > 500L) { currentTime } else { - val sum = children.filter(Component::visible).sumByFloat { it.height + ClickGUI.entryMargin } - val targetHeight = max(height, sum + draggableHeight + ClickGUI.entryMargin) + val sum = children.filter(Component::visible).sumByFloat { it.height + ClickGUI.verticalMargin } + val targetHeight = max(height, sum + draggableHeight + ClickGUI.verticalMargin) val maxHeight = scaledDisplayHeight - 2.0f height = min(targetHeight, scaledDisplayHeight - 2.0f) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/SettingWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/SettingWindow.kt index 9c1fdd639..f8c0f1ad5 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/SettingWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/SettingWindow.kt @@ -25,7 +25,7 @@ abstract class SettingWindow( override val minWidth: Float get() = 100.0f override val minHeight: Float get() = draggableHeight override var height: Float = 0.0f - get() = children.filter { it.visible }.sumByFloat { it.height + ClickGUI.entryMargin } + ClickGUI.entryMargin + 6.0f + FontRenderAdapter.getFontHeight() + get() = children.filter { it.visible }.sumByFloat { it.height + ClickGUI.verticalMargin } + ClickGUI.verticalMargin + draggableHeight override val minimizable get() = false diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt index da7136c05..0d77694d9 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt @@ -23,10 +23,10 @@ object ClickGUI : Module( val blur by setting("Blur", 0.0f, 0.0f..1.0f, 0.05f) val windowOutline by setting("Window Outline", false) val buttonOutline by setting("Button Outline", false) - val resizeCorner by setting("Resize Corner", true) - val resizeCornerSize by setting("Corner Size", 10, 5..30, 1, { resizeCorner }, unit = "px") + val resizeBar by setting("Resize Bar", 5, 0..20, 1, unit = "px") val outlineWidth by setting("Outline Width", 2.5f, 0.5f..3.5f, 0.5f, { windowOutline || buttonOutline }) - val entryMargin by setting("Margin", 0.0f, 0.0f..10.0f, 0.5f, unit = "px") + val horizontalMargin by setting("Horizontal Margin", 0.0f, 0.0f..10.0f, 0.5f, unit = "px") + val verticalMargin by setting("Vertical Margin", 0.0f, 0.0f..10.0f, 0.5f, unit = "px") val darkness by setting("Darkness", 0.25f, 0.0f..1.0f, 0.05f) val gridSize by setting("Snap Grid Size", 10.0f, 0.0f..50.0f, 1.0f) val fadeInTime by setting("Fade In Time", 0.25f, 0.0f..1.0f, 0.05f, unit = "s") From 911487c24190d131b198da2b3faa4336564f33ca Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 16 Nov 2022 02:58:43 +0100 Subject: [PATCH 13/19] Fix bottom margin and adjustable rubberband speed --- .../kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt | 6 +++--- .../com/lambda/client/module/modules/client/ClickGUI.kt | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt index 677ffe5b2..2fea5a0a4 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt @@ -125,7 +125,7 @@ open class ListWindow( if (children.isEmpty()) return val lastVisible = children.lastOrNull { it.visible } - val maxScrollProgress = lastVisible?.let { max(it.posY + it.height + ClickGUI.horizontalMargin - height, 0.01f) } + val maxScrollProgress = lastVisible?.let { max(it.posY + it.height + ClickGUI.verticalMargin + ClickGUI.resizeBar - height, 0.01f) } ?: draggableHeight scrollProgress = (scrollProgress + scrollSpeed) @@ -133,9 +133,9 @@ open class ListWindow( if (scrollTimer.tick(100L, false)) { if (scrollProgress < 0.0) { - scrollSpeed = scrollProgress * -0.25f + scrollSpeed = scrollProgress * -ClickGUI.scrollRubberbandSpeed } else if (scrollProgress > maxScrollProgress) { - scrollSpeed = (scrollProgress - maxScrollProgress) * -0.25f + scrollSpeed = (scrollProgress - maxScrollProgress) * -ClickGUI.scrollRubberbandSpeed } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt index 0d77694d9..1725f1341 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt @@ -23,14 +23,15 @@ object ClickGUI : Module( val blur by setting("Blur", 0.0f, 0.0f..1.0f, 0.05f) val windowOutline by setting("Window Outline", false) val buttonOutline by setting("Button Outline", false) - val resizeBar by setting("Resize Bar", 5, 0..20, 1, unit = "px") val outlineWidth by setting("Outline Width", 2.5f, 0.5f..3.5f, 0.5f, { windowOutline || buttonOutline }) + val resizeBar by setting("Resize Bar", 5, 0..20, 1, unit = "px") val horizontalMargin by setting("Horizontal Margin", 0.0f, 0.0f..10.0f, 0.5f, unit = "px") val verticalMargin by setting("Vertical Margin", 0.0f, 0.0f..10.0f, 0.5f, unit = "px") val darkness by setting("Darkness", 0.25f, 0.0f..1.0f, 0.05f) - val gridSize by setting("Snap Grid Size", 10.0f, 0.0f..50.0f, 1.0f) + val gridSize by setting("Snap Grid", 10.0f, 0.0f..50.0f, 1.0f, unit = "px") val fadeInTime by setting("Fade In Time", 0.25f, 0.0f..1.0f, 0.05f, unit = "s") val fadeOutTime by setting("Fade Out Time", 0.1f, 0.0f..1.0f, 0.05f, unit = "s") + val scrollRubberbandSpeed by setting("Scroll Rubberband Speed", 0.5f, 0.01f..1.0f, 0.05f) val showModifiedInBold by setting("Show Modified In Bold", false, description = "Display modified settings in a bold font") private val resetComponents = setting("Reset Positions", false) private val resetScale = setting("Reset Scale", false) From d6ec5070af2d34f8ef3d18a0382ebebfa301e014 Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 16 Nov 2022 03:30:40 +0100 Subject: [PATCH 14/19] Fix OpenGL 1281: Invalid value --- .../com/lambda/client/gui/rgui/windows/ListWindow.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt index 2fea5a0a4..26f46bda0 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt @@ -167,10 +167,10 @@ open class ListWindow( private fun renderChildren(renderBlock: (Component) -> Unit) { GlStateUtils.scissor( - ((renderPosX + ClickGUI.horizontalMargin) * ClickGUI.getScaleFactor()).floorToInt(), - mc.displayHeight - ((renderPosY + renderHeight - ClickGUI.resizeBar) * ClickGUI.getScaleFactor()).floorToInt(), - ((renderWidth - ClickGUI.horizontalMargin) * ClickGUI.getScaleFactor()).ceilToInt(), - ((renderHeight - draggableHeight - ClickGUI.resizeBar) * ClickGUI.getScaleFactor()).ceilToInt() + ((renderPosX + ClickGUI.horizontalMargin) * ClickGUI.getScaleFactor()).toInt(), + mc.displayHeight - ((renderPosY + renderHeight - ClickGUI.resizeBar) * ClickGUI.getScaleFactor()).toInt(), + ((renderWidth - ClickGUI.horizontalMargin) * ClickGUI.getScaleFactor()).toInt(), + ((renderHeight - draggableHeight - ClickGUI.resizeBar)* ClickGUI.getScaleFactor()).toInt().coerceAtLeast(0) ) glEnable(GL_SCISSOR_TEST) glTranslatef(0.0f, -renderScrollProgress, 0.0f) From 50bfbb3217861ef8e961395ba1077d0b4c586b64 Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 16 Nov 2022 03:44:02 +0100 Subject: [PATCH 15/19] Make SettingWindow unscrollable --- .../kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt | 4 ++-- .../com/lambda/client/gui/rgui/windows/SettingWindow.kt | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt index 26f46bda0..95af1329b 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt @@ -44,12 +44,12 @@ open class ListWindow( private val scrollTimer = TickTimer() private var scrollSpeed = 0.0f - private var scrollProgress = 0.0f + var scrollProgress = 0.0f set(value) { prevScrollProgress = field field = value } - private var prevScrollProgress = 0.0f + var prevScrollProgress = 0.0f private val renderScrollProgress get() = prevScrollProgress + (scrollProgress - prevScrollProgress) * mc.renderPartialTicks diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/SettingWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/SettingWindow.kt index f8c0f1ad5..9f7e52995 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/SettingWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/SettingWindow.kt @@ -1,6 +1,7 @@ package com.lambda.client.gui.rgui.windows import com.lambda.client.commons.extension.sumByFloat +import com.lambda.client.gui.rgui.InteractiveComponent import com.lambda.client.gui.rgui.component.* import com.lambda.client.module.modules.client.ClickGUI import com.lambda.client.setting.settings.AbstractSetting @@ -13,6 +14,7 @@ import com.lambda.client.setting.settings.impl.primitive.StringSetting import com.lambda.client.util.graphics.font.FontRenderAdapter import com.lambda.client.util.math.Vec2f import org.lwjgl.input.Keyboard +import org.lwjgl.input.Mouse abstract class SettingWindow( name: String, @@ -25,7 +27,7 @@ abstract class SettingWindow( override val minWidth: Float get() = 100.0f override val minHeight: Float get() = draggableHeight override var height: Float = 0.0f - get() = children.filter { it.visible }.sumByFloat { it.height + ClickGUI.verticalMargin } + ClickGUI.verticalMargin + draggableHeight + get() = children.filter { it.visible }.sumByFloat { it.height + ClickGUI.verticalMargin } + ClickGUI.verticalMargin + draggableHeight + ClickGUI.resizeBar override val minimizable get() = false @@ -79,6 +81,8 @@ abstract class SettingWindow( super.onTick() if (listeningChild?.listening == false) listeningChild = null Keyboard.enableRepeatEvents(listeningChild != null) + scrollProgress = .0f + prevScrollProgress = .0f } override fun onClosed() { From d7e888c185a1792ff5ae56ca22726032786c9942 Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 16 Nov 2022 16:18:20 +0100 Subject: [PATCH 16/19] Fix saving window size setting and option to disable scroll rubberband --- src/main/kotlin/com/lambda/client/gui/rgui/Component.kt | 4 ++-- .../com/lambda/client/gui/rgui/windows/ListWindow.kt | 7 +++++-- .../com/lambda/client/module/modules/client/ClickGUI.kt | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/Component.kt b/src/main/kotlin/com/lambda/client/gui/rgui/Component.kt index 8bdf242bf..277454355 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/Component.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/Component.kt @@ -31,8 +31,8 @@ open class Component( protected val dockingHSetting = setting("Docking H", HAlign.LEFT) protected val dockingVSetting = setting("Docking V", VAlign.TOP) - private var widthSetting = setting("Width", widthIn, 0.0f..69420.914f, 0.1f, { false }, { _, it -> it.coerceIn(minWidth, max(scaledDisplayWidth, minWidth)) }) - private var heightSetting = setting("Height", heightIn, 0.0f..69420.914f, 0.1f, { false }, { _, it -> it.coerceIn(minHeight, max(scaledDisplayHeight, minHeight)) }) + private var widthSetting = setting("Width", widthIn, 0.0f..69420.914f, 0.1f, { false }) + private var heightSetting = setting("Height", heightIn, 0.0f..69420.914f, 0.1f, { false }) private var relativePosXSetting = setting("Pos X", posXIn, -69420.914f..69420.914f, 0.1f, { false }, { _, it -> if (this is WindowComponent && LambdaMod.ready) absToRelativeX(relativeToAbsX(it).coerceIn(.0f, max(scaledDisplayWidth - width, .0f))) else it }) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt index 95af1329b..a3d42595c 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt @@ -131,8 +131,11 @@ open class ListWindow( scrollProgress = (scrollProgress + scrollSpeed) scrollSpeed *= 0.5f - if (scrollTimer.tick(100L, false)) { - if (scrollProgress < 0.0) { + if (!ClickGUI.scrollRubberband) { + scrollProgress = scrollProgress.coerceIn(.0f, maxScrollProgress) + prevScrollProgress = prevScrollProgress.coerceIn(.0f, maxScrollProgress) + } else if (scrollTimer.tick(100L, false)) { + if (scrollProgress < 0) { scrollSpeed = scrollProgress * -ClickGUI.scrollRubberbandSpeed } else if (scrollProgress > maxScrollProgress) { scrollSpeed = (scrollProgress - maxScrollProgress) * -ClickGUI.scrollRubberbandSpeed diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt index 1725f1341..3705939aa 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/ClickGUI.kt @@ -31,7 +31,8 @@ object ClickGUI : Module( val gridSize by setting("Snap Grid", 10.0f, 0.0f..50.0f, 1.0f, unit = "px") val fadeInTime by setting("Fade In Time", 0.25f, 0.0f..1.0f, 0.05f, unit = "s") val fadeOutTime by setting("Fade Out Time", 0.1f, 0.0f..1.0f, 0.05f, unit = "s") - val scrollRubberbandSpeed by setting("Scroll Rubberband Speed", 0.5f, 0.01f..1.0f, 0.05f) + val scrollRubberband by setting("Scroll Rubberband", false) + val scrollRubberbandSpeed by setting("Scroll Rubberband Speed", 0.5f, 0.01f..1.0f, 0.05f, { scrollRubberband }) val showModifiedInBold by setting("Show Modified In Bold", false, description = "Display modified settings in a bold font") private val resetComponents = setting("Reset Positions", false) private val resetScale = setting("Reset Scale", false) From a03b10e3e56ddf7850284870666716148df5db85 Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 16 Nov 2022 22:38:50 +0100 Subject: [PATCH 17/19] Fix double click height calc --- .../kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt index a3d42595c..2492db539 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt @@ -1,7 +1,5 @@ package com.lambda.client.gui.rgui.windows -import com.lambda.client.commons.extension.ceilToInt -import com.lambda.client.commons.extension.floorToInt import com.lambda.client.commons.extension.sumByFloat import com.lambda.client.gui.AbstractLambdaGui import com.lambda.client.gui.rgui.Component @@ -263,7 +261,7 @@ open class ListWindow( currentTime } else { val sum = children.filter(Component::visible).sumByFloat { it.height + ClickGUI.verticalMargin } - val targetHeight = max(height, sum + draggableHeight + ClickGUI.verticalMargin) + val targetHeight = max(height, sum + draggableHeight + ClickGUI.verticalMargin + ClickGUI.resizeBar) val maxHeight = scaledDisplayHeight - 2.0f height = min(targetHeight, scaledDisplayHeight - 2.0f) From b172717cf9a84861e9d272222215e7304f89e81a Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 16 Nov 2022 23:05:22 +0100 Subject: [PATCH 18/19] Fix left resize event --- .../lambda/client/gui/rgui/WindowComponent.kt | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt index fde9cd1f0..951a9f3e9 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt @@ -109,7 +109,12 @@ open class WindowComponent( else -> null } - val centerSplitterVCenter = if (draggableHeight != height && horizontalSide == HAlign.CENTER) 2.5 else min(15.0, preDragSize.x / 3.0) + val centerSplitterVCenter = if (draggableHeight != height && horizontalSide == HAlign.CENTER) { + 2.5 + } else { + min(15.0, preDragSize.x / 3.0) + } + val verticalSide = when (relativeClickPos.y) { in -2.0..centerSplitterVCenter -> VAlign.TOP in centerSplitterVCenter..preDragSize.y - centerSplitterV -> VAlign.CENTER @@ -118,6 +123,7 @@ open class WindowComponent( } if (horizontalSide == null || verticalSide == null) return + val draggedDist = mousePos.minus(clickPos) if (resizable && !minimized && (horizontalSide != HAlign.CENTER || verticalSide != VAlign.CENTER)) { @@ -136,27 +142,31 @@ open class WindowComponent( private fun handleResizeX(horizontalSide: HAlign, draggedDist: Vec2f) { when (horizontalSide) { HAlign.LEFT -> { - resizeHandle(draggedDist,1.0f - preDragPos.x) + val draggedX = max(roundOnGrid(draggedDist.x), 1.0f - preDragPos.x) + var newWidth = max(roundOnGrid(preDragSize.x - draggedX), minWidth) + + if (maxWidth != -1.0f) newWidth = min(newWidth, maxWidth) + newWidth = min(newWidth, scaledDisplayWidth - 2.0f) + + val prevWidth = width + width = newWidth + posX += prevWidth - newWidth } HAlign.RIGHT -> { - resizeHandle(draggedDist,preDragPos.x + preDragSize.x - 1.0f) + val draggedX = min(roundOnGrid(draggedDist.x), preDragPos.x + preDragSize.x - 1.0f) + var newWidth = max(roundOnGrid(preDragSize.x + draggedX), minWidth) + + if (maxWidth != -1.0f) newWidth = min(newWidth, maxWidth) + newWidth = min(newWidth, scaledDisplayWidth - posX - 2.0f) + + width = newWidth } - HAlign.CENTER -> { - // Nothing + else -> { + // Ignored } } } - private fun resizeHandle(draggedDist: Vec2f, maxDrag: Float) { - val draggedX = min(roundOnGrid(draggedDist.x), maxDrag) - var newWidth = max(roundOnGrid(preDragSize.x + draggedX), minWidth) - - if (maxWidth != -1.0f) newWidth = min(newWidth, maxWidth) - newWidth = min(newWidth, scaledDisplayWidth - posX - 2.0f) - - width = newWidth - } - private fun handleResizeY(verticalSide: VAlign, draggedDist: Vec2f) { when (verticalSide) { VAlign.TOP -> { @@ -180,7 +190,7 @@ open class WindowComponent( height = newHeight } VAlign.CENTER -> { - // Nothing + // Ignored } } } From 486dc06d82d773f31b968841a69b322665945457 Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 16 Nov 2022 23:12:38 +0100 Subject: [PATCH 19/19] Make auto resize fully work --- .../kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt index 2492db539..026f6045a 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/windows/ListWindow.kt @@ -261,7 +261,7 @@ open class ListWindow( currentTime } else { val sum = children.filter(Component::visible).sumByFloat { it.height + ClickGUI.verticalMargin } - val targetHeight = max(height, sum + draggableHeight + ClickGUI.verticalMargin + ClickGUI.resizeBar) + val targetHeight = sum + draggableHeight + ClickGUI.verticalMargin + ClickGUI.resizeBar val maxHeight = scaledDisplayHeight - 2.0f height = min(targetHeight, scaledDisplayHeight - 2.0f)