|
| 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 | +var gut = null : |
| 10 | + set(val): |
| 11 | + gut = val |
| 12 | + _set_gut(val) |
| 13 | + |
| 14 | + |
| 15 | +func _ready(): |
| 16 | + _normal_gui.switch_modes.connect(use_compact_mode.bind(true)) |
| 17 | + _compact_gui.switch_modes.connect(use_compact_mode.bind(false)) |
| 18 | + |
| 19 | + _normal_gui.set_title("GUT") |
| 20 | + _compact_gui.set_title("GUT") |
| 21 | + |
| 22 | + _normal_gui.align_right() |
| 23 | + _compact_gui.to_bottom_right() |
| 24 | + |
| 25 | + use_compact_mode(false) |
| 26 | + |
| 27 | + if(get_parent() == get_tree().root): |
| 28 | + _test_running_setup() |
| 29 | + |
| 30 | +func _test_running_setup(): |
| 31 | + _normal_gui.get_textbox().text = "hello world, how are you doing?" |
| 32 | + |
| 33 | +# ------------------------ |
| 34 | +# Private |
| 35 | +# ------------------------ |
| 36 | +func _set_gut(val): |
| 37 | + _normal_gui.set_gut(val) |
| 38 | + _compact_gui.set_gut(val) |
| 39 | + |
| 40 | + val.start_run.connect(_on_gut_start_run) |
| 41 | + val.end_run.connect(_on_gut_end_run) |
| 42 | + val.start_pause_before_teardown.connect(_on_gut_pause) |
| 43 | + val.end_pause_before_teardown.connect(_on_pause_end) |
| 44 | + |
| 45 | +func _set_both_titles(text): |
| 46 | + _normal_gui.set_title(text) |
| 47 | + _compact_gui.set_title(text) |
| 48 | + |
| 49 | + |
| 50 | +# ------------------------ |
| 51 | +# Events |
| 52 | +# ------------------------ |
| 53 | +func _on_gut_start_run(): |
| 54 | + _set_both_titles('Running') |
| 55 | + |
| 56 | +func _on_gut_end_run(): |
| 57 | + _set_both_titles('Finished') |
| 58 | + |
| 59 | +func _on_gut_pause(): |
| 60 | + _set_both_titles('-- Paused --') |
| 61 | + |
| 62 | +func _on_pause_end(): |
| 63 | + _set_both_titles('Running') |
| 64 | + |
| 65 | + |
| 66 | +# ------------------------ |
| 67 | +# Public |
| 68 | +# ------------------------ |
| 69 | +func get_textbox(): |
| 70 | + return _normal_gui.get_textbox() |
| 71 | + |
| 72 | + |
| 73 | +func set_font_size(new_size): |
| 74 | + return |
| 75 | + var rtl = _normal_gui.get_textbox() |
| 76 | + if(rtl.get('custom_fonts/normal_font') != null): |
| 77 | + rtl.get('custom_fonts/bold_italics_font').size = new_size |
| 78 | + rtl.get('custom_fonts/bold_font').size = new_size |
| 79 | + rtl.get('custom_fonts/italics_font').size = new_size |
| 80 | + rtl.get('custom_fonts/normal_font').size = new_size |
| 81 | + |
| 82 | + |
| 83 | +func set_font(font_name): |
| 84 | + _set_all_fonts_in_rtl(_normal_gui.get_textbox(), font_name) |
| 85 | + |
| 86 | + |
| 87 | +func _set_font(rtl, font_name, custom_name): |
| 88 | + if(font_name == null): |
| 89 | + rtl.add_theme_font_override(custom_name, null) |
| 90 | + else: |
| 91 | + var dyn_font = FontFile.new() |
| 92 | + dyn_font.load_dynamic_font('res://addons/gut/fonts/' + font_name + '.ttf') |
| 93 | + rtl.add_theme_font_override(custom_name, dyn_font) |
| 94 | + |
| 95 | + |
| 96 | +func _set_all_fonts_in_rtl(rtl, base_name): |
| 97 | + if(base_name == 'Default'): |
| 98 | + _set_font(rtl, null, 'normal_font') |
| 99 | + _set_font(rtl, null, 'bold_font') |
| 100 | + _set_font(rtl, null, 'italics_font') |
| 101 | + _set_font(rtl, null, 'bold_italics_font') |
| 102 | + else: |
| 103 | + _set_font(rtl, base_name + '-Regular', 'normal_font') |
| 104 | + _set_font(rtl, base_name + '-Bold', 'bold_font') |
| 105 | + _set_font(rtl, base_name + '-Italic', 'italics_font') |
| 106 | + _set_font(rtl, base_name + '-BoldItalic', 'bold_italics_font') |
| 107 | + |
| 108 | + |
| 109 | +func set_default_font_color(color): |
| 110 | + _normal_gui.get_textbox().set('custom_colors/default_color', color) |
| 111 | + |
| 112 | + |
| 113 | +func set_background_color(color): |
| 114 | + _normal_gui.set_bg_color(color) |
| 115 | + |
| 116 | + |
| 117 | +func use_compact_mode(should=true): |
| 118 | + _compact_gui.visible = should |
| 119 | + _normal_gui.visible = !should |
| 120 | + |
| 121 | + |
| 122 | +func set_opacity(val): |
| 123 | + _normal_gui.modulate.a = val |
| 124 | + _compact_gui.modulate.a = val |
0 commit comments