From fbe4213c7fdb15ab3071277c335ac6e80c6debbf Mon Sep 17 00:00:00 2001 From: kayomn Date: Thu, 26 Jan 2023 00:08:06 +0000 Subject: [PATCH] Remove dependency on ItemSelection --- map_editor.scn | 4 +- map_editor/brush_selection_button_group.res | 3 + user_interface/button_selection.gd | 86 --------------------- 3 files changed, 5 insertions(+), 88 deletions(-) create mode 100644 map_editor/brush_selection_button_group.res delete mode 100644 user_interface/button_selection.gd diff --git a/map_editor.scn b/map_editor.scn index eafb473..9a25dd8 100644 --- a/map_editor.scn +++ b/map_editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b1bd6e544f9f7711be7f8d59e72ab2f26e40b52ff7d939a999afbf0a6beca810 -size 8474 +oid sha256:a2def289ce26e4987f7d26f54923bfdebe247282b6c8f1277701af6fb4828e74 +size 8664 diff --git a/map_editor/brush_selection_button_group.res b/map_editor/brush_selection_button_group.res new file mode 100644 index 0000000..b00a106 --- /dev/null +++ b/map_editor/brush_selection_button_group.res @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0755c5adedfce65aecf47ce200085de76ed8801f7a17ae387c04fbbec483eba +size 212 diff --git a/user_interface/button_selection.gd b/user_interface/button_selection.gd deleted file mode 100644 index f79eb5c..0000000 --- a/user_interface/button_selection.gd +++ /dev/null @@ -1,86 +0,0 @@ -@tool -class_name ItemSelection extends HFlowContainer - -## -## An item has been selected via GUI selection or [method select_item]. -## -signal item_selected(index: int) - -var _button_group := ButtonGroup.new() - -## -## Number of items in the selection. -## -var item_count: int: - get: - return _button_group.get_buttons().size() - -func _get_configuration_warnings() -> PackedStringArray: - var warnings := PackedStringArray() - var children := get_children() - - if not(children.is_empty()): - var self_class_name := get_class() - - for child in get_children(): - warnings.append( - "{0} can only have Button children, but {1} is of type {2}".format( - [self_class_name, child.name, child.get_class()])) - - return warnings - -## -## Adds a new item with no text and only [code]icon[/code] as the icon to the selection. -## -func add_icon_item(icon: Texture2D) -> void: - var child_count := get_child_count() - var button := Button.new() - - button.icon = icon - button.icon_alignment = HORIZONTAL_ALIGNMENT_CENTER - button.toggle_mode = true - button.button_group = _button_group - button.button_pressed = child_count == 0 - - button.pressed.connect(func () -> void: select_item(child_count)) - add_child(button) - -## -## Returns the icon used by the item at [code]index[/code]. -## -## An assertion is raised if [code]index[/code] is out of bounds from the item count. -## -func get_item_icon(index: int) -> Texture2D: - var buttons := _button_group.get_buttons() - - assert(index < buttons.size(), "index out of range") - - var button := buttons[index] as Button - - return null if (button == null) else button.icon - -## -## Returns the currently selected item index or [code]-1[/code] if no item is selected. -## -func get_selected_item() -> int: - var pressed_button := _button_group.get_pressed_button() - - return -1 if (pressed_button == null) else pressed_button.get_index() - -## -## Selects the item at [code]index[/code], emitting [signal item_selected] at the end. -## -## An assertion is raised if [code]index[/code] is out of bounds from the item count. -## -func select_item(index: int) -> void: - var buttons := _button_group.get_buttons() - - assert(index < buttons.size(), "index out of range") - - var pressed_button := _button_group.get_pressed_button() - - if pressed_button != null: - pressed_button.set_pressed_no_signal(false) - - buttons[index].set_pressed_no_signal(true) - item_selected.emit(index)