diff options
Diffstat (limited to 'option_set')
| -rw-r--r-- | option_set/option_set.gd | 4 | ||||
| -rw-r--r-- | option_set/option_set_list.gd | 26 |
2 files changed, 20 insertions, 10 deletions
diff --git a/option_set/option_set.gd b/option_set/option_set.gd index 637d033..0e8f90e 100644 --- a/option_set/option_set.gd +++ b/option_set/option_set.gd @@ -35,14 +35,10 @@ func show_options(options_array: Array): options.unselect() options.connect("item_selected", self, "popup_result", []) options.connect("nothing_selected", self, "popup_result", [-1, ""]) - popup.connect("dismissed", self, "popup_result", [selected_idx, input.text]) popup.open_popup(input.placeholder_text, options) func popup_result(index: int, text: String): - options.disconnect("item_selected", self, "popup_result") - options.disconnect("nothing_selected", self, "popup_result") - popup.disconnect("dismissed", self, "popup_result") selected_idx = index input.text = text input.caret_position = input.max_length diff --git a/option_set/option_set_list.gd b/option_set/option_set_list.gd index ea6b2d8..8aad1b1 100644 --- a/option_set/option_set_list.gd +++ b/option_set/option_set_list.gd @@ -5,6 +5,8 @@ const POINTER_VELOCITY_DECAYING_FACTOR: float = PI const POINTER_VELOCITY_BOOST_FACTOR: float = 1.25 const EXACT_SELECTION: bool = false +export var clear_signals_on_hide := true + signal item_selected # (idx: int, text: String) signal nothing_selected # () @@ -17,7 +19,7 @@ var pointer_drag_velocity := 0.0 var when_last_dragged := 0 var labels : Control -var labels_end_positions: Array +var labels_end_positions : Array var labels_sizes : Array var items : Array @@ -35,7 +37,8 @@ func _init(): self.anchor_right = 1.0 self.anchor_bottom = 1.0 self.rect_clip_content = true - + self.connect("hide", self, "_clear_signals") + labels = Control.new() labels.anchor_right = 1.0 labels.anchor_bottom = 1.0 @@ -219,6 +222,7 @@ func get_item_at_position(mouse_position: Vector2) -> int: var position := mouse_position.y + labels_offset var item_idx := labels_end_positions.bsearch(position) + # @DAM Fix this to return -1 if no item was selected. return int(min(item_idx, items.size()-1)) # Return last item when position is below it. @@ -227,6 +231,7 @@ func select(index: int): emit_signal("item_selected", selected_idx, items[selected_idx]) +# @DAM Do we really need this? We should have just one signal to the selection. func unselect(): selected_idx = -1 emit_signal("nothing_selected") @@ -256,10 +261,10 @@ func pointer_input_on_end_drag_handler(pointer: PointerInputSensor.PointerInputD func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData): - var selected_idx := get_item_at_position(pointer.current_position - rect_global_position) - if selected_idx >= 0: - select(selected_idx) - emit_signal("item_selected", selected_idx) + var item_idx := get_item_at_position(pointer.current_position - rect_global_position) + if item_idx >= 0: + select(item_idx) + emit_signal("item_selected", item_idx) else: unselect() emit_signal("nothing_selected") @@ -269,3 +274,12 @@ func pointer_input_on_scroll_handler(pointer: PointerInputSensor.PointerInputDat pointer_drag_velocity -= pointer.scroll * POINTER_VELOCITY_BOOST_FACTOR * screen_dpcm +func _clear_signals(): + if clear_signals_on_hide == false: + return + + for signal_name in ["item_selected", "nothing_selected"]: + for it in get_signal_connection_list(signal_name): + disconnect(it.signal, it.target, it.method) + + |
