Skip to content

Window grid snapping and GUI fixes #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 9 additions & 10 deletions src/main/kotlin/com/lambda/client/gui/AbstractLambdaGui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ abstract class AbstractLambdaGui<S : SettingWindow<*>, E : Any> : GuiScreen() {
safeListener<TickEvent.ClientTickEvent> { 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() }
}
}

Expand Down Expand Up @@ -143,7 +143,7 @@ abstract class AbstractLambdaGui<S : SettingWindow<*>, E : Any> : GuiScreen() {

displayed.value = true

for (window in windowList) window.onDisplayed()
windowList.forEach { it.onDisplayed() }
}

override fun initGui() {
Expand All @@ -153,7 +153,7 @@ abstract class AbstractLambdaGui<S : SettingWindow<*>, E : Any> : GuiScreen() {
width = scaledResolution.scaledWidth + 16
height = scaledResolution.scaledHeight + 16

for (window in windowList) window.onGuiInit()
windowList.forEach { it.onGuiInit() }
}

override fun onGuiClosed() {
Expand All @@ -165,7 +165,7 @@ abstract class AbstractLambdaGui<S : SettingWindow<*>, E : Any> : GuiScreen() {

displayed.value = false

for (window in windowList) window.onClosed()
windowList.forEach { it.onClosed() }
updateSettingWindow()
}
// End of gui init
Expand Down Expand Up @@ -318,11 +318,10 @@ abstract class AbstractLambdaGui<S : SettingWindow<*>, 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()
}
}
Expand Down
24 changes: 6 additions & 18 deletions src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,37 +38,24 @@ object LambdaClickGui : AbstractLambdaGui<ModuleSettingWindow, AbstractModule>()
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)

Expand Down
43 changes: 17 additions & 26 deletions src/main/kotlin/com/lambda/client/gui/hudgui/LambdaHudGui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.*
Expand All @@ -26,43 +26,35 @@ object LambdaHudGui : AbstractLambdaGui<HudSettingWindow, AbstractHudElement>()

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<InputEvent.KeyInputEvent> {
val eventKey = Keyboard.getEventKey()

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<AbstractHudElement>()
.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)
}

Expand Down Expand Up @@ -98,27 +90,26 @@ object LambdaHudGui : AbstractLambdaGui<HudSettingWindow, AbstractHudElement>()
}

private fun setHudButtonVisibility(function: (HudButton) -> Boolean) {
windowList.filterIsInstance<ListWindow>().forEach {
for (child in it.children) {
if (child !is HudButton) continue
child.visible = function(child)
windowList.filterIsInstance<ListWindow>().forEach { window ->
window.children.filterIsInstance<HudButton>().forEach { button ->
button.visible = function(button)
}
}
}

init {
listener<RenderOverlayEvent>(0) {
if (mc?.world == null || mc?.player == null || mc?.currentScreen == this || mc?.gameSettings?.showDebugInfo != false) return@listener
safeListener<RenderOverlayEvent>(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<AbstractHudElement>()
.filter { it.visible }
.forEach { window ->
renderHudElement(vertexHelper, window)
}
}

GlStateUtils.rescaleMc()
GlStateUtils.depth(true)
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/com/lambda/client/gui/rgui/Component.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 36 additions & 24 deletions src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -106,38 +109,41 @@ 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
in preDragSize.y - centerSplitterV..preDragSize.y + 2.0 -> VAlign.BOTTOM
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)
Expand All @@ -147,25 +153,25 @@ 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)

width = newWidth
}
else -> {
// Nothing lol
// Ignored
}
}
}

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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ open class BasicWindow(
ClickGUI.radius,
color = GuiColors.backGround
)

if (ClickGUI.windowOutline) {
RenderUtils2D.drawRoundedRectOutline(
vertexHelper,
Expand Down
Loading