51 lines
1.5 KiB
GDScript
51 lines
1.5 KiB
GDScript
class_name ContainerSelectionButton extends MarginContainer
|
|
|
|
@export var button: Button
|
|
@export var container_box: ContainerBox
|
|
@export var popup_menu: PopupMenu
|
|
@export var edit_collection_name_window: PackedScene
|
|
|
|
var button_index: int
|
|
var instantiated_menu
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
SignalBus.on_window_closed.connect(_on_window_closed)
|
|
|
|
func _enter_tree() -> void:
|
|
var text: String = "Collection %d" % button_index
|
|
button.text = text
|
|
|
|
|
|
## Request to change to a panel with the ID - 1 of the button. [br]
|
|
## Buttons are 1-indexed, while [member UIManager.panel_array] is 0-index
|
|
func _on_button_pressed() -> void:
|
|
SignalBus.on_panel_requested.emit(button_index)
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if get_global_rect().has_point(get_global_mouse_position()):
|
|
if event.is_action_released("right_click"):
|
|
popup_menu.popup_on_parent(
|
|
Rect2(
|
|
button.get_global_rect().position.x,
|
|
button.get_global_rect().position.y+20,
|
|
button.get_global_rect().size.x,
|
|
button.get_global_rect().size.y)
|
|
)
|
|
|
|
|
|
func _on_popup_menu_index_pressed(index: int) -> void:
|
|
if instantiated_menu != null:
|
|
return
|
|
if index == 0:
|
|
instantiated_menu = edit_collection_name_window.instantiate()
|
|
add_child(instantiated_menu)
|
|
SignalBus.edit_window_requested.emit(instantiated_menu, button.text, button_index)
|
|
|
|
|
|
func _on_window_closed(window: Window) -> void:
|
|
if not is_instance_of(window, EditCollectionNameWindow):
|
|
return
|
|
if instantiated_menu != null:
|
|
instantiated_menu.queue_free()
|