2024-02-12 19:47:28 +01:00
|
|
|
# CORE FRAMEWORK SOURCE FILE
|
|
|
|
# Copyright (c) 2024 The StarOpenSource Project & Contributors
|
2024-03-03 18:53:09 +01:00
|
|
|
# Licensed under the GNU Affero General Public License v3
|
2024-02-12 19:47:28 +01:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2024-03-03 18:53:09 +01:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2024-02-12 19:47:28 +01:00
|
|
|
#
|
|
|
|
# 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
|
2024-03-03 18:53:09 +01:00
|
|
|
# GNU Affero General Public License for more details.
|
2024-02-12 19:47:28 +01:00
|
|
|
#
|
2024-03-03 18:53:09 +01:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2024-02-12 19:47:28 +01:00
|
|
|
# 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)
|
2024-03-22 21:12:11 +01:00
|
|
|
|
|
|
|
# Mark as initialized
|
|
|
|
initialized = true
|
2024-02-04 21:36:30 +01:00
|
|
|
|
|
|
|
func _pull_config() -> void:
|
2024-02-09 14:27:55 +01:00
|
|
|
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
|
2024-03-05 21:32:13 +01:00
|
|
|
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")
|
2024-02-04 21:36:30 +01:00
|
|
|
|
|
|
|
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
|