81 lines
2.7 KiB
GDScript
81 lines
2.7 KiB
GDScript
class_name UIManager extends HBoxContainer
|
|
|
|
const uuid_util = preload('res://addons/uuid/uuid.gd')
|
|
|
|
@export_category("Main Panel")
|
|
@export var current_active_panel: MainPanel
|
|
@export var panel_array: Array[MainPanel] = []
|
|
@export var main_panel_scene: PackedScene
|
|
|
|
@export_category("Container Selection")
|
|
@export var container_collection_box: ContainerBox
|
|
@export var container_selection_buttons: Array[ContainerSelectionButton] = []
|
|
@export var container_button_scene: PackedScene
|
|
|
|
var instantiated_window: Window
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
#current_active_panel.id = 0
|
|
#panel_array.append(current_active_panel)
|
|
|
|
SignalBus.on_panel_created.connect(_on_panel_created)
|
|
SignalBus.on_panel_requested.connect(_on_panel_requested)
|
|
SignalBus.on_new_container_requested.connect(_on_new_container_requested)
|
|
|
|
SignalBus.edit_window_text_saved.connect(_on_edit_window_text_saved)
|
|
#SignalBus.on_entry_deleted.connect(on_entry_deleted)
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
|
|
|
|
func _on_panel_created() -> void:
|
|
var new_panel: MainPanel = main_panel_scene.instantiate()
|
|
new_panel.id = uuid_util.v4()
|
|
panel_array.append(new_panel)
|
|
|
|
func _on_panel_requested(index) -> void:
|
|
if current_active_panel == panel_array[index]:
|
|
print("Already active")
|
|
return
|
|
print("Panel: %d requested" % index)
|
|
|
|
if current_active_panel != null:
|
|
current_active_panel.hide()
|
|
|
|
current_active_panel = panel_array[index]
|
|
if not current_active_panel.is_inside_tree():
|
|
add_child(current_active_panel)
|
|
else:
|
|
current_active_panel.show()
|
|
|
|
|
|
func _on_new_container_requested() -> void:
|
|
var new_button: ContainerSelectionButton = container_button_scene.instantiate()
|
|
new_button.container_box = container_collection_box
|
|
container_selection_buttons.append(new_button)
|
|
new_button.button_index = container_selection_buttons.find(new_button)
|
|
container_collection_box.add_child(new_button)
|
|
container_collection_box.move_child(new_button, -2)
|
|
|
|
func _on_edit_window_text_saved(window: Window, text: String, node: Node) -> void:
|
|
print("save: ", text)
|
|
if is_instance_of(window, EditCollectionNameWindow):
|
|
var i: int = container_selection_buttons.find(node)
|
|
container_selection_buttons[i].button.text = text
|
|
rename_container_text_box_when_button_is_renamed(i)
|
|
elif is_instance_of(window, Editmenu):
|
|
for panel in panel_array:
|
|
if panel.done_boxes.has(node):
|
|
var i: int = panel.done_boxes.find(node)
|
|
panel.done_boxes[i].entry_text_box.text = text
|
|
else:
|
|
print("Else")
|
|
|
|
func rename_container_text_box_when_button_is_renamed(id) -> void:
|
|
panel_array[id].container_name_label.text = container_selection_buttons[id].button.text
|
|
|
|
|