Skip to content

Commit fb7da09

Browse files
committed
Merge remote-tracking branch 'NeoLambda/feature/manager-loggers' into feature/manager-loggers
2 parents 8b4d87b + fb96e62 commit fb7da09

File tree

17 files changed

+407
-21
lines changed

17 files changed

+407
-21
lines changed

src/main/kotlin/com/lambda/gui/components/HudGuiLayout.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ object HudGuiLayout : Loadable {
3939
.filterIsInstance<HudModule>()
4040
.filter { it.isEnabled }
4141
.forEach { hud ->
42-
window("##${hud.name}", flags = DEFAULT_HUD_FLAGS) {
43-
with(hud) { buildLayout() }
44-
}
42+
if (!hud.customWindow)
43+
window("##${hud.name}", flags = DEFAULT_HUD_FLAGS) {
44+
with(hud) { buildLayout() }
45+
}
46+
else with(hud) { buildLayout() }
4547
}
4648
}
4749
}

src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt

Lines changed: 137 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,127 @@ package com.lambda.gui.dsl
3939
import com.lambda.gui.dsl.ImGuiBuilder.text
4040
import com.lambda.module.modules.client.ClickGui
4141
import com.lambda.util.math.Vec2d
42-
import imgui.*
43-
import imgui.ImGui.*
44-
import imgui.flag.*
45-
import imgui.type.*
42+
import imgui.ImDrawList
43+
import imgui.ImFont
44+
import imgui.ImGui
45+
import imgui.ImGui.begin
46+
import imgui.ImGui.beginChild
47+
import imgui.ImGui.beginCombo
48+
import imgui.ImGui.beginDragDropSource
49+
import imgui.ImGui.beginDragDropTarget
50+
import imgui.ImGui.beginGroup
51+
import imgui.ImGui.beginMainMenuBar
52+
import imgui.ImGui.beginMenu
53+
import imgui.ImGui.beginMenuBar
54+
import imgui.ImGui.beginPopup
55+
import imgui.ImGui.beginPopupContextItem
56+
import imgui.ImGui.beginPopupContextVoid
57+
import imgui.ImGui.beginPopupContextWindow
58+
import imgui.ImGui.beginPopupModal
59+
import imgui.ImGui.beginTabBar
60+
import imgui.ImGui.beginTabItem
61+
import imgui.ImGui.beginTooltip
62+
import imgui.ImGui.calcTextSize
63+
import imgui.ImGui.collapsingHeader
64+
import imgui.ImGui.colorButton
65+
import imgui.ImGui.colorEdit4
66+
import imgui.ImGui.colorPicker4
67+
import imgui.ImGui.dragFloat
68+
import imgui.ImGui.dragInt
69+
import imgui.ImGui.end
70+
import imgui.ImGui.endChild
71+
import imgui.ImGui.endCombo
72+
import imgui.ImGui.endDragDropSource
73+
import imgui.ImGui.endDragDropTarget
74+
import imgui.ImGui.endGroup
75+
import imgui.ImGui.endMainMenuBar
76+
import imgui.ImGui.endMenu
77+
import imgui.ImGui.endMenuBar
78+
import imgui.ImGui.endPopup
79+
import imgui.ImGui.endTabBar
80+
import imgui.ImGui.endTabItem
81+
import imgui.ImGui.endTooltip
82+
import imgui.ImGui.getBackgroundDrawList
83+
import imgui.ImGui.getColorU32
84+
import imgui.ImGui.getFont
85+
import imgui.ImGui.getFontSize
86+
import imgui.ImGui.getForegroundDrawList
87+
import imgui.ImGui.getIO
88+
import imgui.ImGui.getItemID
89+
import imgui.ImGui.getStyle
90+
import imgui.ImGui.getVersion
91+
import imgui.ImGui.getWindowDrawList
92+
import imgui.ImGui.getWindowHeight
93+
import imgui.ImGui.getWindowPos
94+
import imgui.ImGui.getWindowPosX
95+
import imgui.ImGui.getWindowPosY
96+
import imgui.ImGui.getWindowSize
97+
import imgui.ImGui.getWindowViewport
98+
import imgui.ImGui.getWindowWidth
99+
import imgui.ImGui.inputDouble
100+
import imgui.ImGui.inputFloat
101+
import imgui.ImGui.inputFloat2
102+
import imgui.ImGui.inputFloat3
103+
import imgui.ImGui.inputFloat4
104+
import imgui.ImGui.isAnyItemActive
105+
import imgui.ImGui.isAnyItemFocused
106+
import imgui.ImGui.isAnyItemHovered
107+
import imgui.ImGui.isItemActivated
108+
import imgui.ImGui.isItemActive
109+
import imgui.ImGui.isItemClicked
110+
import imgui.ImGui.isItemDeactivated
111+
import imgui.ImGui.isItemDeactivatedAfterEdit
112+
import imgui.ImGui.isItemEdited
113+
import imgui.ImGui.isItemFocused
114+
import imgui.ImGui.isItemHovered
115+
import imgui.ImGui.isItemToggledOpen
116+
import imgui.ImGui.isMouseClicked
117+
import imgui.ImGui.isWindowAppearing
118+
import imgui.ImGui.isWindowCollapsed
119+
import imgui.ImGui.isWindowHovered
120+
import imgui.ImGui.popFont
121+
import imgui.ImGui.popID
122+
import imgui.ImGui.popItemWidth
123+
import imgui.ImGui.popStyleColor
124+
import imgui.ImGui.popStyleVar
125+
import imgui.ImGui.popTextWrapPos
126+
import imgui.ImGui.pushFont
127+
import imgui.ImGui.pushID
128+
import imgui.ImGui.pushItemWidth
129+
import imgui.ImGui.pushStyleColor
130+
import imgui.ImGui.pushStyleVar
131+
import imgui.ImGui.pushTextWrapPos
132+
import imgui.ImGui.setClipboardText
133+
import imgui.ImGui.setCursorPosX
134+
import imgui.ImGui.sliderFloat
135+
import imgui.ImGui.sliderInt
136+
import imgui.ImGui.textColored
137+
import imgui.ImGui.textUnformatted
138+
import imgui.ImGui.treeNode
139+
import imgui.ImGui.treePop
140+
import imgui.ImGuiIO
141+
import imgui.ImGuiStyle
142+
import imgui.ImGuiTextFilter
143+
import imgui.ImGuiViewport
144+
import imgui.ImVec2
145+
import imgui.flag.ImDrawListFlags
146+
import imgui.flag.ImGuiCol
147+
import imgui.flag.ImGuiColorEditFlags
148+
import imgui.flag.ImGuiComboFlags
149+
import imgui.flag.ImGuiDir
150+
import imgui.flag.ImGuiHoveredFlags
151+
import imgui.flag.ImGuiInputTextFlags
152+
import imgui.flag.ImGuiMouseButton
153+
import imgui.flag.ImGuiPopupFlags
154+
import imgui.flag.ImGuiSelectableFlags
155+
import imgui.flag.ImGuiTabBarFlags
156+
import imgui.flag.ImGuiTreeNodeFlags
157+
import imgui.flag.ImGuiWindowFlags
158+
import imgui.type.ImBoolean
159+
import imgui.type.ImDouble
160+
import imgui.type.ImFloat
161+
import imgui.type.ImInt
162+
import imgui.type.ImString
46163
import net.minecraft.util.math.Vec2f
47164
import net.minecraft.util.math.Vec3d
48165
import net.minecraft.util.math.Vec3i
@@ -312,6 +429,22 @@ object ImGuiBuilder {
312429
@ImGuiDsl
313430
fun text(text: String) = textUnformatted(text)
314431

432+
/**
433+
* Text with coloring
434+
*
435+
* @param text The text to display
436+
*/
437+
@ImGuiDsl
438+
fun textColored(text: String, color: Color) = textColored(
439+
getColorU32(
440+
color.red / 255f,
441+
color.green / 255f,
442+
color.blue / 255f,
443+
color.alpha / 255f
444+
),
445+
text
446+
)
447+
315448
/**
316449
* Text with disabled coloring.
317450
*

src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import com.lambda.graphics.renderer.esp.DirectionMask
2222
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2323
import com.lambda.interaction.material.StackSelection
2424
import com.lambda.interaction.request.breaking.BreakConfig
25-
import com.lambda.interaction.request.breaking.BreakRequest
2625
import com.lambda.interaction.request.hotbar.HotbarManager
27-
import com.lambda.interaction.request.hotbar.HotbarRequest
2826
import com.lambda.interaction.request.rotating.RotationRequest
2927
import com.lambda.util.BlockUtils.emptyState
3028
import net.minecraft.block.BlockState
@@ -76,11 +74,4 @@ data class BreakContext(
7674
withState(cachedState, blockPos, baseColor, DirectionMask.ALL.exclude(result.side))
7775
withState(cachedState, blockPos, sideColor, result.side)
7876
}
79-
80-
fun requestSwap(breakRequest: BreakRequest, minKeepTicks: Int = 0): Boolean =
81-
HotbarRequest(
82-
hotbarIndex,
83-
breakRequest.hotbar,
84-
breakRequest.hotbar.keepTicks.coerceAtLeast(minKeepTicks)
85-
).submit(false).done
8677
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.request
19+
20+
import com.lambda.gui.dsl.ImGuiBuilder
21+
import com.lambda.module.HudModule
22+
import com.lambda.module.tag.ModuleTag
23+
import imgui.ImGui
24+
import imgui.flag.ImGuiWindowFlags
25+
import java.awt.Color
26+
import java.util.*
27+
28+
abstract class DebugLogger(
29+
name: String,
30+
description: String
31+
) : HudModule(
32+
name,
33+
description,
34+
ModuleTag.HUD,
35+
customWindow = true
36+
) {
37+
private val logs = LinkedList<LogEntry>()
38+
39+
private val autoScroll by setting("Auto-Scroll", true, "Automatically scrolls to the bottom of the log")
40+
private val wrapText by setting("Wrap Text", false, "Wraps the text to the next line if it gets too long")
41+
private val showDebug by setting("Show Debug", true, "Shows debug logs")
42+
private val showSuccess by setting("Show Success", true, "Shows success logs")
43+
private val showWarning by setting("Show Warning", true, "Shows warning logs")
44+
private val showError by setting("Show Errors", true, "Shows error logs")
45+
private val maxLogEntries by setting("Max Log Entries", 100, 1..1000, 1, "Maximum amount of entries in the log")
46+
.onValueChange { from, to ->
47+
if (to < from) {
48+
while(logs.size > to) {
49+
logs.removeFirst()
50+
}
51+
}
52+
}
53+
private val backgroundAlpha by setting("Background Alpha", 0.3f, 0f..1f, 0.01f, "Sets the opacity for the elements background")
54+
55+
private fun log(message: String, logColor: LogType) {
56+
logs.add(LogEntry(message, logColor))
57+
if (logs.size > maxLogEntries) {
58+
logs.removeFirst()
59+
}
60+
}
61+
62+
fun debug(message: String) = log(message, LogType.Debug)
63+
fun success(message: String) = log(message, LogType.Success)
64+
fun warning(message: String) = log(message, LogType.Warning)
65+
fun error(message: String) = log(message, LogType.Error)
66+
fun system(message: String) = log(message, LogType.System)
67+
68+
override fun ImGuiBuilder.buildLayout() {
69+
ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY)
70+
ImGui.setNextWindowBgAlpha(backgroundAlpha)
71+
window(name, flags = ImGuiWindowFlags.NoCollapse) {
72+
val noScroll = if (autoScroll) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0
73+
button("Clear") { clear() }
74+
child("Log Content", extraFlags = noScroll) {
75+
if (wrapText) ImGui.pushTextWrapPos()
76+
77+
logs.forEach { logEntry ->
78+
if (shouldDisplay(logEntry)) {
79+
when (val type = logEntry.type) {
80+
LogType.Debug -> textColored("[DEBUG]", type.color)
81+
LogType.Success -> textColored("[SUCCESS]", type.color)
82+
LogType.Warning -> textColored("[WARNING]", type.color)
83+
LogType.Error -> textColored("[ERROR]", type.color)
84+
LogType.System -> textColored("[SYSTEM]", type.color)
85+
}
86+
87+
sameLine()
88+
textColored(logEntry.message, logEntry.type.color)
89+
}
90+
}
91+
92+
if (wrapText) ImGui.popTextWrapPos()
93+
94+
if (autoScroll) {
95+
ImGui.setScrollHereY(1f)
96+
}
97+
}
98+
}
99+
}
100+
101+
fun shouldDisplay(logEntry: LogEntry) =
102+
when (logEntry.type) {
103+
LogType.Debug -> showDebug
104+
LogType.Success -> showSuccess
105+
LogType.Warning -> showWarning
106+
LogType.Error -> showError
107+
LogType.System -> true
108+
}
109+
110+
fun clear() = logs.clear()
111+
112+
data class LogEntry(
113+
val message: String,
114+
val type: LogType
115+
)
116+
117+
enum class LogType(val color: Color) {
118+
Debug(Color(255, 255, 255)),
119+
Success(Color(70, 255, 70)),
120+
Warning(Color(255, 255, 70)),
121+
Error(Color(255, 70, 70)),
122+
System(Color(70, 70, 255))
123+
}
124+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.request
19+
20+
interface Logger {
21+
val logger: DebugLogger
22+
}

src/main/kotlin/com/lambda/interaction/request/Request.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.interaction.request
1919

2020
abstract class Request {
21+
abstract val requestID: Int
2122
abstract val config: RequestConfig
2223
var fresh = true
2324

src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,6 @@ data class BreakInfo(
147147
sequence
148148
)
149149
}
150+
151+
override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}"
150152
}

0 commit comments

Comments
 (0)