@@ -20,6 +20,7 @@ package com.lambda.gui.components
2020import com.lambda.core.Loadable
2121import com.lambda.event.events.GuiEvent
2222import com.lambda.event.listener.SafeListener.Companion.listen
23+ import com.lambda.gui.components.ModuleEntry.Companion.buildModuleSettingsContext
2324import com.lambda.gui.dsl.ImGuiBuilder
2425import com.lambda.gui.dsl.ImGuiBuilder.buildLayout
2526import com.lambda.gui.snap.Guide
@@ -69,9 +70,20 @@ object HudGuiLayout : Loadable {
6970
7071 init {
7172 listen<GuiEvent .NewFrame > {
72- if (ClickGui .isEnabled && ! isShownInGUI) return @listen
73-
7473 buildLayout {
74+ if (ClickGui .isEnabled && ! isShownInGUI) {
75+ popupContextVoid(" ##hud-background" ) {
76+ menuItem(if (isShownInGUI) " Hide HUD" else " Show HUD" ) {
77+ isShownInGUI = ! isShownInGUI
78+ }
79+ separator()
80+ menu(" HUD Settings" ) {
81+ buildModuleSettingsContext(GuiSettings )
82+ }
83+ }
84+ return @buildLayout
85+ }
86+
7587 val vp = ImGui .getMainViewport()
7688 SnapManager .beginFrame(vp.sizeX, vp.sizeY, io.fontGlobalScale)
7789
@@ -93,59 +105,104 @@ object HudGuiLayout : Loadable {
93105
94106 notShown.forEach { SnapManager .unregisterElement(it.name) }
95107
96- val canDrag = ClickGui .isEnabled && ! isLocked
97- if (canDrag) {
108+ registerContextMenu(notShown)
109+
110+ if (ClickGui .isEnabled && ! isLocked) {
98111 if (activeDragHudName == null && mousePressedThisFrame) { tryBeginDrag(huds) }
99112 if (activeDragHudName != null && mouseDown) updateDragAndSnapping()
100113 if (activeDragHudName != null ) drawDragGrid()
101114 }
102115
103116 huds.forEach { hud ->
104- val override = pendingPositions[hud.name]
105- if (override != null ) {
106- ImGui .setNextWindowPos(override .first, override .second)
107- }
117+ registerHudElement(hud)
118+ }
119+ }
120+ }
121+ }
108122
109- val bg = hud.backgroundColor
110- val hasBg = bg.alpha > 0
111- val baseFlags = if (hasBg) {
112- DEFAULT_HUD_FLAGS and ImGuiWindowFlags .NoBackground .inv ()
113- } else DEFAULT_HUD_FLAGS
114- val hudFlags = if (! ClickGui .isEnabled || isLocked) {
115- baseFlags or ImGuiWindowFlags .NoMove
116- } else baseFlags
117-
118- val pushedColor = if (hasBg) {
119- val packed = ImColor .rgba(bg.red, bg.green, bg.blue, bg.alpha)
120- ImGui .pushStyleColor(imgui.flag.ImGuiCol .WindowBg , packed)
121- true
122- } else {
123- false
124- }
123+ private fun ImGuiBuilder.registerHudElement (hud : HudModule ) {
124+ val override = pendingPositions[hud.name]
125+ if (override != null ) {
126+ ImGui .setNextWindowPos(override .first, override .second)
127+ }
125128
126- val outlineWidth = if (hud.outline) hud.outlineWidth else 0f
127- withStyleVar(ImGuiStyleVar .WindowBorderSize , outlineWidth) {
128- window(" ##${hud.name} " , flags = hudFlags) {
129- val vis = snapOverlays[hud.name]
130- if (vis != null ) {
131- SnapManager .drawSnapLines(
132- foregroundDrawList,
133- vis.snapX, vis.kindX,
134- vis.snapY, vis.kindY
135- )
136- }
137- with (hud) { buildLayout() }
138- if (canDrag) {
139- drawHudCornerArcs(foregroundDrawList, windowPos.x, windowPos.y, windowSize.x, windowSize.y)
140- }
141- val rect = RectF (windowPos.x, windowPos.y, windowSize.x, windowSize.y)
142- SnapManager .registerElement(hud.name, rect)
143- lastBounds[hud.name] = rect
144- }
129+ val bg = hud.backgroundColor
130+ val hasBg = bg.alpha > 0
131+ val baseFlags = if (hasBg) {
132+ DEFAULT_HUD_FLAGS and ImGuiWindowFlags .NoBackground .inv ()
133+ } else DEFAULT_HUD_FLAGS
134+ val hudFlags = if (! ClickGui .isEnabled || isLocked) {
135+ baseFlags or ImGuiWindowFlags .NoMove
136+ } else baseFlags
137+
138+ val pushedColor = if (hasBg) {
139+ val packed = ImColor .rgba(bg.red, bg.green, bg.blue, bg.alpha)
140+ ImGui .pushStyleColor(imgui.flag.ImGuiCol .WindowBg , packed)
141+ true
142+ } else {
143+ false
144+ }
145+
146+ val outlineWidth = if (hud.outline) hud.outlineWidth else 0f
147+ withStyleVar(ImGuiStyleVar .WindowBorderSize , outlineWidth) {
148+ window(" ##${hud.name} " , flags = hudFlags) {
149+ val vis = snapOverlays[hud.name]
150+ if (vis != null ) {
151+ SnapManager .drawSnapLines(
152+ foregroundDrawList,
153+ vis.snapX, vis.kindX,
154+ vis.snapY, vis.kindY
155+ )
156+ }
157+ with (hud) { buildLayout() }
158+
159+ popupContextWindow(" ##ctx-${hud.name} " ) {
160+ menuItem(" Remove HUD Element" ) {
161+ hud.disable()
162+ SnapManager .unregisterElement(hud.name)
145163 }
164+ separator()
165+ buildModuleSettingsContext(hud)
166+ }
146167
147- if (pushedColor) {
148- ImGui .popStyleColor()
168+ if (ClickGui .isEnabled && ! isLocked) {
169+ drawHudCornerArcs(foregroundDrawList, windowPos.x, windowPos.y, windowSize.x, windowSize.y)
170+ }
171+ val rect = RectF (windowPos.x, windowPos.y, windowSize.x, windowSize.y)
172+ SnapManager .registerElement(hud.name, rect)
173+ lastBounds[hud.name] = rect
174+ }
175+ }
176+
177+ if (pushedColor) {
178+ ImGui .popStyleColor()
179+ }
180+ }
181+
182+ private fun ImGuiBuilder.registerContextMenu (notShown : List <HudModule >) {
183+ popupContextVoid(" ##hud-background" ) {
184+ menuItem(if (isLocked) " Unlock HUD" else " Lock HUD" ) {
185+ isLocked = ! isLocked
186+ }
187+ menuItem(if (isShownInGUI) " Hide HUD" else " Show HUD" ) {
188+ isShownInGUI = ! isShownInGUI
189+ }
190+ separator()
191+ menu(" HUD Settings" ) {
192+ buildModuleSettingsContext(GuiSettings )
193+ }
194+ separator()
195+ if (notShown.isEmpty()) {
196+ textDisabled(" No hidden HUD elements" )
197+ } 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
149206 }
150207 }
151208 }
0 commit comments