Update Log UI
This commit is contained in:
parent
535b8b69cf
commit
7ea7de55ff
3 changed files with 33 additions and 2 deletions
|
@ -51,6 +51,8 @@ Enables or disables Log UI.
|
||||||
The Log UI background color.. Set to `Color.TRANSPARENT` for a transparent background.
|
The Log UI background color.. Set to `Color.TRANSPARENT` for a transparent background.
|
||||||
### *int* <u>logui_font_size</u> = *14*
|
### *int* <u>logui_font_size</u> = *14*
|
||||||
What font size the graphical log should have.
|
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
|
## Miscellaneous
|
||||||
### *bool* <u>misc_stringify_show_type</u> = *false*
|
### *bool* <u>misc_stringify_show_type</u> = *false*
|
||||||
|
|
|
@ -46,6 +46,8 @@ class_name CoreConfiguration
|
||||||
@export var logui_background_color: Color
|
@export var logui_background_color: Color
|
||||||
## What font size the graphical log should have.
|
## What font size the graphical log should have.
|
||||||
@export var logui_font_size: int
|
@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")
|
@export_category("Miscellaneous")
|
||||||
## Shows or hides the type when calling [code]stringify_variables[/code].
|
## Shows or hides the type when calling [code]stringify_variables[/code].
|
||||||
|
@ -83,6 +85,7 @@ func _init() -> void:
|
||||||
logui_enabled = true
|
logui_enabled = true
|
||||||
logui_background_color = Color.BLACK # To disable the background, use Color.TRANSPARENT
|
logui_background_color = Color.BLACK # To disable the background, use Color.TRANSPARENT
|
||||||
logui_font_size = 14
|
logui_font_size = 14
|
||||||
|
logui_max_lines = 100
|
||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
misc_stringify_show_type = false
|
misc_stringify_show_type = false
|
||||||
|
|
30
src/logui.gd
30
src/logui.gd
|
@ -28,12 +28,21 @@ var logrtl: RichTextLabel
|
||||||
var font_normal: Font
|
var font_normal: Font
|
||||||
var font_bold: Font
|
var font_bold: Font
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
var config_max_lines: int
|
||||||
|
|
||||||
# +++ module +++
|
# +++ module +++
|
||||||
func _pull_config() -> void:
|
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
|
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("normal_font_size", core.config.logui_font_size)
|
||||||
logrtl.add_theme_font_size_override("bold_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:
|
func _cleanup() -> void:
|
||||||
background.remove_child(logrtl)
|
background.remove_child(logrtl)
|
||||||
|
@ -90,7 +99,9 @@ func _ready() -> void:
|
||||||
vsbar.add_theme_stylebox_override("grabber_pressed", StyleBoxEmpty.new())
|
vsbar.add_theme_stylebox_override("grabber_pressed", StyleBoxEmpty.new())
|
||||||
|
|
||||||
# Connect log_event
|
# 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 +++
|
# +++ process +++
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
|
@ -98,3 +109,18 @@ func _process(_delta: float) -> void:
|
||||||
var window_size: Vector2i = DisplayServer.window_get_size()
|
var window_size: Vector2i = DisplayServer.window_get_size()
|
||||||
background.size = window_size
|
background.size = window_size
|
||||||
logrtl.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
|
||||||
|
|
Loading…
Reference in a new issue