CORE/src/logui.gd

87 lines
3.4 KiB
GDScript3
Raw Normal View History

# CORE FRAMEWORK SOURCE FILE
# Copyright (c) 2024 The StarOpenSource Project & Contributors
# Licensed under the GNU General Public License v3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
## Displays the log graphically.
##
## Displays the log output graphically in the background of the application.
2024-02-04 21:36:30 +01:00
extends CoreBaseModule
# Objects
var background: ColorRect
var logrtl: RichTextLabel
# Resources
var font_normal: Font
var font_bold: Font
func _initialize() -> void:
# Load fonts into memory
font_normal = ResourceLoader.load(core.basepath + "dist/FiraCode/Regular.ttf")
font_bold = ResourceLoader.load(core.basepath + "dist/FiraCode/Bold.ttf")
# Create LogUI
background = ColorRect.new()
2024-02-09 21:18:14 +01:00
background.name = "LOGUI"
2024-02-04 21:36:30 +01:00
# Create LogRTL
logrtl = RichTextLabel.new()
logrtl.name = "LogRTL"
logrtl.bbcode_enabled = true
## Interaction
logrtl.selection_enabled = false
logrtl.deselect_on_focus_loss_enabled = true
logrtl.drag_and_drop_selection_enabled = false
logrtl.mouse_filter = Control.MOUSE_FILTER_IGNORE
## Scrolling
logrtl.scroll_active = true
logrtl.scroll_following = true
## Disable localization
logrtl.auto_translate = false
logrtl.localize_numeral_system = false
## Override fonts
logrtl.add_theme_font_override("normal_font", font_normal)
logrtl.add_theme_font_override("bold_font", font_bold)
logrtl.add_theme_font_size_override("normal_font_size", 14)
logrtl.add_theme_font_size_override("bold_font_size", 14)
func _pull_config() -> void:
background.visible = !core.config.headless and core.config.logui_enabled
2024-02-04 21:36:30 +01:00
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)
func _ready() -> void:
# Add to SceneTree
2024-02-09 21:18:14 +01:00
core.sms.add_child(background)
2024-02-09 23:03:41 +01:00
core.sms.move_child(background, 0)
2024-02-04 21:36:30 +01:00
background.add_child(logrtl)
# Hide VScrollBar
var vsbar: VScrollBar = logrtl.get_child(0, true)
vsbar.set_deferred("size", Vector2i(1, 1))
vsbar.mouse_filter = Control.MOUSE_FILTER_IGNORE
vsbar.add_theme_stylebox_override("scroll", StyleBoxEmpty.new())
vsbar.add_theme_stylebox_override("scroll_focus", StyleBoxEmpty.new())
vsbar.add_theme_stylebox_override("grabber", StyleBoxEmpty.new())
vsbar.add_theme_stylebox_override("grabber_highlight", StyleBoxEmpty.new())
vsbar.add_theme_stylebox_override("grabber_pressed", StyleBoxEmpty.new())
# Connect log_event
logger.connect("log_event", func(allowed: bool, _level: CoreTypes.LoggerLevel, _origin: Dictionary, _message: String, format: String) -> void: if allowed: logrtl.text = logrtl.text + format + "\n")
func _process(_delta: float) -> void:
if !core.config.headless:
var window_size: Vector2i = DisplayServer.window_get_size()
background.size = window_size
logrtl.size = window_size