2023-01-07 20:26:17 +01:00
|
|
|
extends Node2D
|
2024-01-06 11:27:15 +01:00
|
|
|
# ##############################################################################
|
|
|
|
# This is a wrapper around the normal and compact gui controls and serves as
|
|
|
|
# the interface between gut.gd and the gui. The GutRunner creates an instance
|
|
|
|
# of this and then this takes care of managing the different GUI controls.
|
|
|
|
# ##############################################################################
|
|
|
|
@onready var _normal_gui = $Normal
|
|
|
|
@onready var _compact_gui = $Compact
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
var gut = null:
|
|
|
|
set(val):
|
|
|
|
gut = val
|
|
|
|
_set_gut(val)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
func _ready():
|
|
|
|
_normal_gui.switch_modes.connect(use_compact_mode.bind(true))
|
|
|
|
_compact_gui.switch_modes.connect(use_compact_mode.bind(false))
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
_normal_gui.set_title("GUT")
|
|
|
|
_compact_gui.set_title("GUT")
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
_normal_gui.align_right()
|
|
|
|
_compact_gui.to_bottom_right()
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
use_compact_mode(false)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
if get_parent() == get_tree().root:
|
|
|
|
_test_running_setup()
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
func _test_running_setup():
|
|
|
|
set_font_size(100)
|
|
|
|
_normal_gui.get_textbox().text = "hello world, how are you doing?"
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
# ------------------------
|
|
|
|
# Private
|
|
|
|
# ------------------------
|
|
|
|
func _set_gut(val):
|
|
|
|
if _normal_gui.get_gut() == val:
|
|
|
|
return
|
|
|
|
_normal_gui.set_gut(val)
|
|
|
|
_compact_gui.set_gut(val)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
val.start_run.connect(_on_gut_start_run)
|
|
|
|
val.end_run.connect(_on_gut_end_run)
|
|
|
|
val.start_pause_before_teardown.connect(_on_gut_pause)
|
|
|
|
val.end_pause_before_teardown.connect(_on_pause_end)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
func _set_both_titles(text):
|
|
|
|
_normal_gui.set_title(text)
|
|
|
|
_compact_gui.set_title(text)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
# ------------------------
|
|
|
|
# Events
|
|
|
|
# ------------------------
|
|
|
|
func _on_gut_start_run():
|
|
|
|
_set_both_titles("Running")
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
func _on_gut_end_run():
|
|
|
|
_set_both_titles("Finished")
|
|
|
|
|
|
|
|
|
|
|
|
func _on_gut_pause():
|
|
|
|
_set_both_titles("-- Paused --")
|
|
|
|
|
|
|
|
|
|
|
|
func _on_pause_end():
|
|
|
|
_set_both_titles("Running")
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------
|
|
|
|
# Public
|
|
|
|
# ------------------------
|
2023-01-07 20:26:17 +01:00
|
|
|
func get_textbox():
|
2024-01-06 11:27:15 +01:00
|
|
|
return _normal_gui.get_textbox()
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
func set_font_size(new_size):
|
2024-01-06 11:27:15 +01:00
|
|
|
var rtl = _normal_gui.get_textbox()
|
|
|
|
|
|
|
|
rtl.set("theme_override_font_sizes/bold_italics_font_size", new_size)
|
|
|
|
rtl.set("theme_override_font_sizes/bold_font_size", new_size)
|
|
|
|
rtl.set("theme_override_font_sizes/italics_font_size", new_size)
|
|
|
|
rtl.set("theme_override_font_sizes/normal_font_size", new_size)
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
func set_font(font_name):
|
2024-01-06 11:27:15 +01:00
|
|
|
_set_all_fonts_in_rtl(_normal_gui.get_textbox(), font_name)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2022-06-02 04:13:43 +02:00
|
|
|
func _set_font(rtl, font_name, custom_name):
|
2024-01-06 11:27:15 +01:00
|
|
|
if font_name == null:
|
|
|
|
rtl.add_theme_font_override(custom_name, null)
|
|
|
|
else:
|
|
|
|
var dyn_font = FontFile.new()
|
|
|
|
dyn_font.load_dynamic_font("res://addons/gut/fonts/" + font_name + ".ttf")
|
|
|
|
rtl.add_theme_font_override(custom_name, dyn_font)
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _set_all_fonts_in_rtl(rtl, base_name):
|
2023-01-20 23:34:39 +01:00
|
|
|
if base_name == "Default":
|
|
|
|
_set_font(rtl, null, "normal_font")
|
|
|
|
_set_font(rtl, null, "bold_font")
|
|
|
|
_set_font(rtl, null, "italics_font")
|
|
|
|
_set_font(rtl, null, "bold_italics_font")
|
2022-06-02 04:13:43 +02:00
|
|
|
else:
|
2023-01-20 23:34:39 +01:00
|
|
|
_set_font(rtl, base_name + "-Regular", "normal_font")
|
|
|
|
_set_font(rtl, base_name + "-Bold", "bold_font")
|
|
|
|
_set_font(rtl, base_name + "-Italic", "italics_font")
|
|
|
|
_set_font(rtl, base_name + "-BoldItalic", "bold_italics_font")
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
func set_default_font_color(color):
|
2024-01-06 11:27:15 +01:00
|
|
|
_normal_gui.get_textbox().set("custom_colors/default_color", color)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
func set_background_color(color):
|
2024-01-06 11:27:15 +01:00
|
|
|
_normal_gui.set_bg_color(color)
|
|
|
|
|
|
|
|
|
|
|
|
func use_compact_mode(should = true):
|
|
|
|
_compact_gui.visible = should
|
|
|
|
_normal_gui.visible = !should
|
|
|
|
|
|
|
|
|
|
|
|
func set_opacity(val):
|
|
|
|
_normal_gui.modulate.a = val
|
|
|
|
_compact_gui.modulate.a = val
|