@@ -21,22 +21,26 @@ import com.lambda.gui.dsl.ImGuiBuilder
2121import com.lambda.module.HudModule
2222import com.lambda.module.tag.ModuleTag
2323import imgui.ImGui
24- import imgui.type.ImBoolean
2524import java.awt.Color
2625import java.util.*
2726
28- class DebugLogger (name : String , description : String ) : HudModule(
29- name, description, ModuleTag .HUD
30- ) {
27+ abstract class DebugLogger (name : String , description : String ) : HudModule(name, description, ModuleTag .HUD ) {
3128 private val logs = LinkedList <LogEntry >()
32- private var maxLogEntries: Int = 100
3329
34- private val autoScroll = ImBoolean (true )
35- private val wrapText = ImBoolean (false )
36- private val showDebug = ImBoolean (true )
37- private val showSuccess = ImBoolean (true )
38- private val showWarning = ImBoolean (true )
39- private val showError = ImBoolean (true )
30+ private val autoScroll by setting(" Auto-Scroll" , true , " Automatically scrolls to the bottom of the log" )
31+ private val wrapText by setting(" Wrap Text" , false , " Wraps the text to the next line if it gets too long" )
32+ private val showDebug by setting(" Show Debug" , true , " Shows debug logs" )
33+ private val showSuccess by setting(" Show Success" , true , " Shows success logs" )
34+ private val showWarning by setting(" Show Warning" , true , " Shows warning logs" )
35+ private val showError by setting(" Show Errors" , true , " Shows error logs" )
36+ private val maxLogEntries by setting(" Max Log Entries" , 100 , 1 .. 1000 , 1 , " Maximum amount of entries in the log" )
37+ .onValueChange { from, to ->
38+ if (to < from) {
39+ while (logs.size > to) {
40+ logs.removeFirst()
41+ }
42+ }
43+ }
4044
4145 private fun log (message : String , logColor : LogType ) {
4246 logs.add(LogEntry (message, logColor))
@@ -51,22 +55,8 @@ class DebugLogger(name: String, description: String) : HudModule(
5155 fun error (message : String ) = log(message, LogType .Error )
5256
5357 override fun ImGuiBuilder.buildLayout () {
54- checkbox(" Auto-scroll" , autoScroll)
55- sameLine()
56- checkbox(" Wrap Text" , wrapText)
57- sameLine()
58- checkbox(" Debug" , showDebug)
59- sameLine()
60- checkbox(" Info" , showSuccess)
61- sameLine()
62- checkbox(" Warn" , showWarning)
63- sameLine()
64- checkbox(" Error" , showError)
65-
66- separator()
67-
6858 child(" Log Content" ) {
69- if (wrapText.get() ) ImGui .pushTextWrapPos()
59+ if (wrapText) ImGui .pushTextWrapPos()
7060
7161 logs.forEach { logEntry ->
7262 if (shouldDisplay(logEntry)) {
@@ -82,9 +72,9 @@ class DebugLogger(name: String, description: String) : HudModule(
8272 }
8373 }
8474
85- if (wrapText.get() ) ImGui .popTextWrapPos()
75+ if (wrapText) ImGui .popTextWrapPos()
8676
87- if (autoScroll.get() ) {
77+ if (autoScroll) {
8878 ImGui .setScrollHereY(1f )
8979 }
9080 }
@@ -94,10 +84,10 @@ class DebugLogger(name: String, description: String) : HudModule(
9484
9585 fun shouldDisplay (logEntry : LogEntry ) =
9686 when (logEntry.type) {
97- LogType .Debug -> showDebug.get()
98- LogType .Success -> showSuccess.get()
99- LogType .Warning -> showWarning.get()
100- LogType .Error -> showError.get()
87+ LogType .Debug -> showDebug
88+ LogType .Success -> showSuccess
89+ LogType .Warning -> showWarning
90+ LogType .Error -> showError
10191 }
10292
10393 fun clear () = logs.clear()
0 commit comments