Skip to content

Commit b93e060

Browse files
committed
move logger settings to hud module settings. This also saves the settings in the config
1 parent 54d5c15 commit b93e060

File tree

2 files changed

+25
-39
lines changed

2 files changed

+25
-39
lines changed

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

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,26 @@
1717

1818
package com.lambda.interaction.request
1919

20-
import com.lambda.Lambda.mc
21-
import com.lambda.gui.LambdaScreen
2220
import com.lambda.gui.dsl.ImGuiBuilder
2321
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
22+
import com.lambda.module.hud.ManagerDebugLoggers.autoScroll
2423
import com.lambda.module.hud.ManagerDebugLoggers.maxLogEntries
24+
import com.lambda.module.hud.ManagerDebugLoggers.showDebug
25+
import com.lambda.module.hud.ManagerDebugLoggers.showError
26+
import com.lambda.module.hud.ManagerDebugLoggers.showSuccess
27+
import com.lambda.module.hud.ManagerDebugLoggers.showSystem
28+
import com.lambda.module.hud.ManagerDebugLoggers.showWarning
29+
import com.lambda.module.hud.ManagerDebugLoggers.wrapText
2530
import com.lambda.util.math.a
2631
import imgui.ImGui
2732
import imgui.flag.ImGuiCol
2833
import imgui.flag.ImGuiWindowFlags
29-
import imgui.type.ImBoolean
30-
import imgui.type.ImFloat
3134
import java.awt.Color
3235
import java.util.*
3336

3437
class DebugLogger(
3538
val name: String
3639
) {
37-
private val autoScroll = ImBoolean(true)
38-
private val wrapText = ImBoolean(true)
39-
private val showDebug = ImBoolean(true)
40-
private val showSuccess = ImBoolean(true)
41-
private val showWarning = ImBoolean(true)
42-
private val showError = ImBoolean(true)
43-
private val showSystem = ImBoolean(true)
44-
private val backgroundAlpha = ImFloat(0.3f)
45-
4640
val logs = LinkedList<LogEntry>()
4741

4842
private fun log(message: String, logColor: LogType, extraContext: List<String?>) {
@@ -75,25 +69,10 @@ class DebugLogger(
7569

7670
fun ImGuiBuilder.buildLayout() {
7771
ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY)
78-
ImGui.setNextWindowBgAlpha(backgroundAlpha.get())
79-
val noScroll = if (autoScroll.get()) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0
80-
if (mc.currentScreen == LambdaScreen) {
81-
checkbox("Auto-Scroll", autoScroll)
82-
sameLine()
83-
checkbox("Warp Text", wrapText)
84-
sameLine()
85-
checkbox("Show Debug", showDebug)
86-
checkbox("Show Success", showSuccess)
87-
sameLine()
88-
checkbox("Show Warning", showWarning)
89-
sameLine()
90-
checkbox("Show Error", showError)
91-
checkbox("Show System", showSystem)
92-
slider("Background Alpha", backgroundAlpha, 0.0f, 1.0f)
93-
button("Clear") { clear() }
94-
}
95-
child("Log Content", extraFlags = noScroll) {
96-
if (wrapText.get()) ImGui.pushTextWrapPos()
72+
var flags = if (autoScroll) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0
73+
flags = flags or ImGuiWindowFlags.NoBackground
74+
child("Log Content", extraFlags = flags) {
75+
if (wrapText) ImGui.pushTextWrapPos()
9776

9877
logs.forEach { logEntry ->
9978
if (shouldDisplay(logEntry)) {
@@ -124,21 +103,21 @@ class DebugLogger(
124103
}
125104
}
126105

127-
if (wrapText.get()) ImGui.popTextWrapPos()
106+
if (wrapText) ImGui.popTextWrapPos()
128107

129-
if (autoScroll.get()) {
108+
if (autoScroll) {
130109
ImGui.setScrollHereY(1f)
131110
}
132111
}
133112
}
134113

135114
fun shouldDisplay(logEntry: LogEntry) =
136115
when (logEntry.type) {
137-
LogType.Debug -> showDebug.get()
138-
LogType.Success -> showSuccess.get()
139-
LogType.Warning -> showWarning.get()
140-
LogType.Error -> showError.get()
141-
LogType.System -> showSystem.get()
116+
LogType.Debug -> showDebug
117+
LogType.Success -> showSuccess
118+
LogType.Warning -> showWarning
119+
LogType.Error -> showError
120+
LogType.System -> showSystem
142121
}
143122

144123
fun clear() = logs.clear()

src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ object ManagerDebugLoggers : HudModule(
4242

4343
private val loggers = mutableMapOf<() -> Boolean, DebugLogger>()
4444

45+
val autoScroll by setting("Auto-Scroll", true, "Locks the page at the bottom of the logs").group(Group.General)
46+
val wrapText by setting("Wrap Text", true, "Wraps the logs to new lines if they go off the panel").group(Group.General)
47+
val showDebug by setting("Show Debug", true, "Shows debug logs").group(Group.General)
48+
val showSuccess by setting("Show Success", true, "Shows success logs").group(Group.General)
49+
val showWarning by setting("Show Warning", true, "Shows warning logs").group(Group.General)
50+
val showError by setting("Show Error", true, "Shows error logs").group(Group.General)
51+
val showSystem by setting("Show System", true, "Shows system logs").group(Group.General)
4552
val maxLogEntries by setting("Max Log Entries", 100, 1..1000, 1, "Maximum amount of entries in the log").group(Group.General)
4653
.onValueChange { from, to ->
4754
if (to < from) {

0 commit comments

Comments
 (0)