1717
1818package com.lambda.gui.components
1919
20+ import com.lambda.config.Configurable
21+ import com.lambda.config.configurations.HudConfig
2022import com.lambda.core.Loadable
2123import com.lambda.event.events.GuiEvent
2224import com.lambda.event.listener.SafeListener.Companion.listen
23- import com.lambda.gui.components.ModuleEntry.Companion.buildModuleSettingsContext
25+ import com.lambda.gui.components.SettingsWidget.buildConfigSettingsContext
2426import com.lambda.gui.dsl.ImGuiBuilder
2527import com.lambda.gui.dsl.ImGuiBuilder.buildLayout
2628import com.lambda.gui.snap.Guide
2729import com.lambda.gui.snap.RectF
2830import com.lambda.gui.snap.SnapManager
2931import com.lambda.module.HudModule
3032import com.lambda.module.ModuleRegistry
31- import com.lambda.module.modules.client.GuiSettings
3233import com.lambda.module.modules.client.ClickGui
34+ import com.lambda.util.NamedEnum
3335import imgui.ImColor
3436import imgui.ImGui
3537import imgui.ImDrawList
3638import imgui.flag.ImDrawListFlags
3739import imgui.flag.ImGuiWindowFlags
3840import imgui.flag.ImGuiStyleVar
41+ import java.awt.Color
3942import kotlin.math.PI
4043import kotlin.math.max
4144
42- object HudGuiLayout : Loadable {
45+ object HudGuiLayout : Loadable, Configurable(HudConfig ) {
46+ override val name = " HUD"
47+
48+ enum class Group (override val displayName : String ) : NamedEnum {
49+ Snapping (" Snapping" ),
50+ HudOutline (" HUD Outline" )
51+ }
52+
53+ // Snapping
54+ val snapEnabled by setting(" Enable Snapping" , true , " Master toggle for HUD snapping" ).group(Group .Snapping )
55+ val gridSize by setting(" Grid Size" , 16f , 2f .. 128f , 1f , " Grid step in pixels" ) { snapEnabled }.group(Group .Snapping )
56+ val snapToEdges by setting(" Snap To Element Edges" , true ) { snapEnabled }.group(Group .Snapping )
57+ val snapToCenters by setting(" Snap To Element Centers" , true ) { snapEnabled }.group(Group .Snapping )
58+ val snapToScreenCenter by setting(" Snap To Screen Center" , true ) { snapEnabled }.group(Group .Snapping )
59+ val snapToGrid by setting(" Snap To Grid" , true ) { snapEnabled }.group(Group .Snapping )
60+ val snapDistanceElement by setting(" Snap Distance (Elements)" , 20f , 1f .. 48f , 1f , " Distance threshold in px" ) { snapEnabled }.group(Group .Snapping )
61+ val snapDistanceScreen by setting(" Snap Distance (Screen Center)" , 14f , 1f .. 48f , 1f ) { snapEnabled }.group(Group .Snapping )
62+ val snapDistanceGrid by setting(" Snap Distance (Grid)" , 12f , 1f .. 48f , 1f ) { snapEnabled }.group(Group .Snapping )
63+ val snapLineColor by setting(" Snap Line Color" , Color (255 , 160 , 0 , 220 )) { snapEnabled }.group(Group .Snapping )
64+
65+ // HUD Outline
66+ val hudOutlineCornerRadius by setting(" HUD Corner Radius" , 6.0f , 0.0f .. 24.0f , 0.5f ).group(Group .HudOutline )
67+ val hudOutlineHaloColor by setting(" HUD Corner Halo Color" , Color (140 , 140 , 140 , 90 )).group(Group .HudOutline )
68+ val hudOutlineBorderColor by setting(" HUD Corner Border Color" , Color (190 , 190 , 190 , 200 )).group(Group .HudOutline )
69+ val hudOutlineHaloThickness by setting(" HUD Corner Halo Thickness" , 3.0f , 1.0f .. 6.0f , 0.5f ).group(Group .HudOutline )
70+ val hudOutlineBorderThickness by setting(" HUD Corner Border Thickness" , 1.5f , 1.0f .. 4.0f , 0.5f ).group(Group .HudOutline )
71+ val hudOutlineCornerInflate by setting(" HUD Corner Inflate" , 1.0f , 0.0f .. 4.0f , 0.5f , " Extra radius for the halo arc" ).group(Group .HudOutline )
72+
4373 const val DEFAULT_HUD_FLAGS =
4474 ImGuiWindowFlags .NoDecoration or
4575 ImGuiWindowFlags .NoBackground or
@@ -78,7 +108,7 @@ object HudGuiLayout : Loadable {
78108 }
79109 separator()
80110 menu(" HUD Settings" ) {
81- buildModuleSettingsContext( GuiSettings )
111+ buildConfigSettingsContext( this @HudGuiLayout )
82112 }
83113 }
84114 return @buildLayout
@@ -162,7 +192,7 @@ object HudGuiLayout : Loadable {
162192 SnapManager .unregisterElement(hud.name)
163193 }
164194 separator()
165- buildModuleSettingsContext (hud)
195+ buildConfigSettingsContext (hud)
166196 }
167197
168198 if (ClickGui .isEnabled && ! isLocked) {
@@ -189,20 +219,20 @@ object HudGuiLayout : Loadable {
189219 }
190220 separator()
191221 menu(" HUD Settings" ) {
192- buildModuleSettingsContext( GuiSettings )
222+ buildConfigSettingsContext( this @HudGuiLayout )
193223 }
194224 separator()
195225 if (notShown.isEmpty()) {
196226 textDisabled(" No hidden HUD elements" )
197227 } else {
198- text (" Add HUD Element: " )
199- separator()
200- notShown.sortedBy { it.name.lowercase() }.forEach { hud ->
201- menuItem( " + ${hud.name} " ) {
202- val mx = io.mousePos.x
203- val my = io.mousePos.y
204- hud.enable()
205- pendingPositions[hud.name] = mx to my
228+ menu (" Add HUD Element" ) {
229+ notShown.sortedBy { it.name.lowercase() }.forEach { hud ->
230+ menuItem( " + ${ hud.name} " ) {
231+ val mx = io.mousePos.x
232+ val my = io.mousePos.y
233+ hud.enable()
234+ pendingPositions[ hud.name] = mx to my
235+ }
206236 }
207237 }
208238 }
@@ -240,9 +270,9 @@ object HudGuiLayout : Loadable {
240270 }
241271
242272 private fun ImGuiBuilder.drawDragGrid () {
243- if (! GuiSettings . snapEnabled || ! GuiSettings . snapToGrid) return
273+ if (! snapEnabled || ! snapToGrid) return
244274 val vp = ImGui .getMainViewport()
245- val step = max(4f , GuiSettings . gridSize * io.fontGlobalScale)
275+ val step = max(4f , gridSize * io.fontGlobalScale)
246276 if (step <= 0f ) return
247277
248278 val x0 = vp.posX
@@ -267,24 +297,24 @@ object HudGuiLayout : Loadable {
267297 }
268298
269299 private fun ImGuiBuilder.drawHudCornerArcs (draw : ImDrawList , x : Float , y : Float , w : Float , h : Float ) {
270- val baseRadius = GuiSettings . hudOutlineCornerRadius
300+ val baseRadius = hudOutlineCornerRadius
271301 val rounding = if (baseRadius > 0f ) baseRadius else style.windowRounding
272- val inflate = GuiSettings . hudOutlineCornerInflate
302+ val inflate = hudOutlineCornerInflate
273303 // Soft halo corners
274304 drawCornerArcs(
275305 draw,
276306 x, y, w, h,
277307 (rounding + inflate).coerceAtLeast(0f ),
278- GuiSettings . hudOutlineHaloColor.rgb,
279- GuiSettings . hudOutlineHaloThickness
308+ hudOutlineHaloColor.rgb,
309+ hudOutlineHaloThickness
280310 )
281311 // Crisp inner corner arcs
282312 drawCornerArcs(
283313 draw,
284314 x, y, w, h,
285315 rounding.coerceAtLeast(0f ),
286- GuiSettings . hudOutlineBorderColor.rgb,
287- GuiSettings . hudOutlineBorderThickness
316+ hudOutlineBorderColor.rgb,
317+ hudOutlineBorderThickness
288318 )
289319 }
290320
0 commit comments