Update Log UI

This commit is contained in:
JeremyStar™ 2024-05-15 01:52:12 +02:00
parent 535b8b69cf
commit 7ea7de55ff
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
3 changed files with 33 additions and 2 deletions

View file

@ -51,6 +51,8 @@ Enables or disables Log UI.
The Log UI background color.. Set to `Color.TRANSPARENT` for a transparent background.
### *int* <u>logui_font_size</u> = *14*
What font size the graphical log should have.
### *int* <u>logui_max_lines</u> = *100*
How many lines can be visible on the screen at any given time. **Never** set this higher than 100 or it will cause tremendous amounts of lag for no real benefit. Instead *lowering* that amount helps performance.
## Miscellaneous
### *bool* <u>misc_stringify_show_type</u> = *false*

View file

@ -46,6 +46,8 @@ class_name CoreConfiguration
@export var logui_background_color: Color
## What font size the graphical log should have.
@export var logui_font_size: int
## How many lines can be visible on the screen at any given time. [b]Never[/b] set this higher than 100 or it will cause tremendous amounts of lag for no real benefit. Instead [i]lowering[/i] that amount helps performance.
@export var logui_max_lines: int
@export_category("Miscellaneous")
## Shows or hides the type when calling [code]stringify_variables[/code].
@ -83,6 +85,7 @@ func _init() -> void:
logui_enabled = true
logui_background_color = Color.BLACK # To disable the background, use Color.TRANSPARENT
logui_font_size = 14
logui_max_lines = 100
# Misc
misc_stringify_show_type = false

View file

@ -28,12 +28,21 @@ var logrtl: RichTextLabel
var font_normal: Font
var font_bold: Font
# Configuration
var config_max_lines: int
# +++ module +++
func _pull_config() -> void:
background.visible = !core.config.headless and core.config.logui_enabled
if !core.config.logui_enabled:
background.visible = false
logrtl.text = ""
else:
background.visible = !core.config.headless
background.color = core.config.logui_background_color
logrtl.add_theme_font_size_override("normal_font_size", core.config.logui_font_size)
logrtl.add_theme_font_size_override("bold_font_size", core.config.logui_font_size)
config_max_lines = core.config.logui_max_lines
func _cleanup() -> void:
background.remove_child(logrtl)
@ -90,7 +99,9 @@ func _ready() -> void:
vsbar.add_theme_stylebox_override("grabber_pressed", StyleBoxEmpty.new())
# Connect log_event
core.logger.connect("log_event", func(allowed: bool, _level: CoreTypes.LoggerLevel, _origin: String, _message: String, format: String) -> void: if allowed: logrtl.text = logrtl.text + format + "\n")
core.logger.connect("log_event", func(allowed: bool, _level: CoreTypes.LoggerLevel, _origin: String, _message: String, format: String) -> void:
if allowed and core.config.logui_enabled: logrtl.text = logrtl.text + format + "\n"
)
# +++ process +++
func _process(_delta: float) -> void:
@ -98,3 +109,18 @@ func _process(_delta: float) -> void:
var window_size: Vector2i = DisplayServer.window_get_size()
background.size = window_size
logrtl.size = window_size
var stripped_text: String = ""
if logrtl.text.count("\n") > config_max_lines:
printerr("Stripping text")
var lines: PackedStringArray = logrtl.text.split("\n")
var index: int = 0
for line in lines:
if index >= lines.size()-config_max_lines:
if stripped_text == "": stripped_text = line
else: stripped_text += "\n" + line
index += 1
logrtl.text = stripped_text