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/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/clickgui/LambdaClickGui.kt b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt index 09ca83968..7de0eef7f 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,37 +38,24 @@ 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() - /* 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 { category -> + val window = ListWindow(category.displayName, posX, 0.0f, 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 */ - 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) 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..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,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 }) + private var heightSetting = setting("Height", heightIn, 0.0f..69420.914f, 0.1f, { false }) - 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 9c7d981e5..951a9f3e9 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt @@ -1,14 +1,17 @@ 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 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 open class WindowComponent( name: String, @@ -106,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 @@ -114,30 +122,28 @@ 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 = (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) + 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(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 +153,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) @@ -156,7 +162,7 @@ open class WindowComponent( width = newWidth } else -> { - // Nothing lol + // Ignored } } } @@ -164,8 +170,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,20 +181,26 @@ 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) height = newHeight } - else -> { - // Nothing lol + VAlign.CENTER -> { + // Ignored } } } + 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 && 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/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 7e542993e..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 @@ -32,6 +32,7 @@ open class BasicWindow( ClickGUI.radius, color = GuiColors.backGround ) + if (ClickGUI.windowOutline) { RenderUtils2D.drawRoundedRectOutline( vertexHelper, 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..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 @@ -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 @@ -11,9 +9,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 @@ -29,7 +24,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 @@ -48,12 +42,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 @@ -65,65 +59,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.verticalMargin + + children + .filter { it.visible } + .forEach { + it.posX = ClickGUI.horizontalMargin + it.posY = y + it.width = width - ClickGUI.horizontalMargin * 2 + y += it.height + ClickGUI.verticalMargin } - } } } 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,32 +121,35 @@ 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) } + val maxScrollProgress = lastVisible?.let { max(it.posY + it.height + ClickGUI.verticalMargin + ClickGUI.resizeBar - height, 0.01f) } ?: draggableHeight scrollProgress = (scrollProgress + scrollSpeed) scrollSpeed *= 0.5f - if (scrollTimer.tick(100L, false)) { - if (scrollProgress < 0.0) { - scrollSpeed = scrollProgress * -0.25f + + 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) * -0.25f + scrollSpeed = (scrollProgress - maxScrollProgress) * -ClickGUI.scrollRubberbandSpeed } } 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,37 +157,32 @@ 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( - ((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()).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) - 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 +206,12 @@ 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 + 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 } } @@ -271,8 +260,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 = sum + draggableHeight + ClickGUI.verticalMargin + ClickGUI.resizeBar 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..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.entryMargin } + ClickGUI.entryMargin + 6.0f + FontRenderAdapter.getFontHeight() + 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() { 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..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 @@ -24,10 +24,15 @@ object ClickGUI : Module( val windowOutline by setting("Window Outline", false) val buttonOutline by setting("Button Outline", false) 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 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", 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 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) @@ -92,6 +97,7 @@ object ClickGUI : Module( if (mc.currentScreen !is LambdaClickGui) { HudEditor.disable() mc.displayGuiScreen(LambdaClickGui) + LambdaClickGui.isFocused = true LambdaClickGui.onDisplayed() } } 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("/")) {