|
| 1 | +extends Node2D |
| 2 | +# ############################################################################## |
| 3 | +# This is a wrapper around the normal and compact gui controls and serves as |
| 4 | +# the interface between gut.gd and the gui. The GutRunner creates an instance |
| 5 | +# of this and then this takes care of managing the different GUI controls. |
| 6 | +# ############################################################################## |
| 7 | +@onready var _normal_gui = $Normal |
| 8 | +@onready var _compact_gui = $Compact |
| 9 | + |
| 10 | +var gut = null : |
| 11 | + set(val): |
| 12 | + gut = val |
| 13 | + _set_gut(val) |
| 14 | + |
| 15 | + |
| 16 | +func _ready(): |
| 17 | + _normal_gui.switch_modes.connect(use_compact_mode.bind(true)) |
| 18 | + _compact_gui.switch_modes.connect(use_compact_mode.bind(false)) |
| 19 | + |
| 20 | + _normal_gui.set_title("GUT") |
| 21 | + _compact_gui.set_title("GUT") |
| 22 | + |
| 23 | + _normal_gui.align_right() |
| 24 | + _compact_gui.to_bottom_right() |
| 25 | + |
| 26 | + use_compact_mode(false) |
| 27 | + |
| 28 | + if(get_parent() == get_tree().root): |
| 29 | + _test_running_setup() |
| 30 | + |
| 31 | +func _test_running_setup(): |
| 32 | + set_font_size(100) |
| 33 | + _normal_gui.get_textbox().text = "hello world, how are you doing?" |
| 34 | + |
| 35 | +# ------------------------ |
| 36 | +# Private |
| 37 | +# ------------------------ |
| 38 | +func _set_gut(val): |
| 39 | + if(_normal_gui.get_gut() == val): |
| 40 | + return |
| 41 | + _normal_gui.set_gut(val) |
| 42 | + _compact_gui.set_gut(val) |
| 43 | + |
| 44 | + val.start_run.connect(_on_gut_start_run) |
| 45 | + val.end_run.connect(_on_gut_end_run) |
| 46 | + val.start_pause_before_teardown.connect(_on_gut_pause) |
| 47 | + val.end_pause_before_teardown.connect(_on_pause_end) |
| 48 | + |
| 49 | +func _set_both_titles(text): |
| 50 | + _normal_gui.set_title(text) |
| 51 | + _compact_gui.set_title(text) |
| 52 | + |
| 53 | + |
| 54 | +# ------------------------ |
| 55 | +# Events |
| 56 | +# ------------------------ |
| 57 | +func _on_gut_start_run(): |
| 58 | + _set_both_titles('Running') |
| 59 | + |
| 60 | +func _on_gut_end_run(): |
| 61 | + _set_both_titles('Finished') |
| 62 | + |
| 63 | +func _on_gut_pause(): |
| 64 | + _set_both_titles('-- Paused --') |
| 65 | + |
| 66 | +func _on_pause_end(): |
| 67 | + _set_both_titles('Running') |
| 68 | + |
| 69 | + |
| 70 | +# ------------------------ |
| 71 | +# Public |
| 72 | +# ------------------------ |
| 73 | +func get_textbox(): |
| 74 | + return _normal_gui.get_textbox() |
| 75 | + |
| 76 | + |
| 77 | +func set_font_size(new_size): |
| 78 | + var rtl = _normal_gui.get_textbox() |
| 79 | + |
| 80 | + rtl.set('theme_override_font_sizes/bold_italics_font_size', new_size) |
| 81 | + rtl.set('theme_override_font_sizes/bold_font_size', new_size) |
| 82 | + rtl.set('theme_override_font_sizes/italics_font_size', new_size) |
| 83 | + rtl.set('theme_override_font_sizes/normal_font_size', new_size) |
| 84 | + |
| 85 | + |
| 86 | +func set_font(font_name): |
| 87 | + _set_all_fonts_in_rtl(_normal_gui.get_textbox(), font_name) |
| 88 | + |
| 89 | + |
| 90 | +func _set_font(rtl, font_name, custom_name): |
| 91 | + if(font_name == null): |
| 92 | + rtl.remove_theme_font_override(custom_name) |
| 93 | + else: |
| 94 | + var dyn_font = FontFile.new() |
| 95 | + dyn_font.load_dynamic_font('res://addons/gut/fonts/' + font_name + '.ttf') |
| 96 | + rtl.add_theme_font_override(custom_name, dyn_font) |
| 97 | + |
| 98 | + |
| 99 | +func _set_all_fonts_in_rtl(rtl, base_name): |
| 100 | + if(base_name == 'Default'): |
| 101 | + _set_font(rtl, null, 'normal_font') |
| 102 | + _set_font(rtl, null, 'bold_font') |
| 103 | + _set_font(rtl, null, 'italics_font') |
| 104 | + _set_font(rtl, null, 'bold_italics_font') |
| 105 | + else: |
| 106 | + _set_font(rtl, base_name + '-Regular', 'normal_font') |
| 107 | + _set_font(rtl, base_name + '-Bold', 'bold_font') |
| 108 | + _set_font(rtl, base_name + '-Italic', 'italics_font') |
| 109 | + _set_font(rtl, base_name + '-BoldItalic', 'bold_italics_font') |
| 110 | + |
| 111 | + |
| 112 | +func set_default_font_color(color): |
| 113 | + _normal_gui.get_textbox().set('custom_colors/default_color', color) |
| 114 | + |
| 115 | + |
| 116 | +func set_background_color(color): |
| 117 | + _normal_gui.set_bg_color(color) |
| 118 | + |
| 119 | + |
| 120 | +func use_compact_mode(should=true): |
| 121 | + _compact_gui.visible = should |
| 122 | + _normal_gui.visible = !should |
| 123 | + |
| 124 | + |
| 125 | +func set_opacity(val): |
| 126 | + _normal_gui.modulate.a = val |
| 127 | + _compact_gui.modulate.a = val |
0 commit comments