aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-04-01 11:32:45 +0000
committerdam <dam@gudinoff>2022-04-01 11:32:45 +0000
commit8491abc4805cee3b2dfb74817ef8908df085c5cf (patch)
tree041687da080004a8d105ce1c451f972b4d1df0c6
parent9b619b8c5f117e53b121c2d868b024c7c7d08f4c (diff)
downloadsurgery-log-8491abc4805cee3b2dfb74817ef8908df085c5cf.tar.zst
surgery-log-8491abc4805cee3b2dfb74817ef8908df085c5cf.zip
Option set changed to work with empty list instead of creating dummy -- entry.
-rw-r--r--logic/stage.gd3
-rw-r--r--option_set/option_set.gd15
-rw-r--r--option_set/option_set_list.gd35
-rw-r--r--readme.md4
4 files changed, 24 insertions, 33 deletions
diff --git a/logic/stage.gd b/logic/stage.gd
index fde67d3..ef9ce3d 100644
--- a/logic/stage.gd
+++ b/logic/stage.gd
@@ -94,9 +94,6 @@ func show_options(field: String):
_:
options = option_sets.get(field, {}).keys()
- if options.size() == 0:
- options.append(OPTION_SETS_NOT_AVAILABLE)
-
options.sort()
option_set_field.show_options(options)
diff --git a/option_set/option_set.gd b/option_set/option_set.gd
index 0e8f90e..bb37736 100644
--- a/option_set/option_set.gd
+++ b/option_set/option_set.gd
@@ -29,19 +29,16 @@ func _ready():
func show_options(options_array: Array):
options.clear_items()
options.add_items(options_array)
- if options_array[selected_idx] == input.text:
- options.select(selected_idx)
- else:
- options.unselect()
- options.connect("item_selected", self, "popup_result", [])
- options.connect("nothing_selected", self, "popup_result", [-1, ""])
+ options.select(options_array.find(input.text))
+ options.connect("selection_changed", self, "popup_result")
popup.open_popup(input.placeholder_text, options)
func popup_result(index: int, text: String):
- selected_idx = index
- input.text = text
- input.caret_position = input.max_length
+ if index != -1:
+ selected_idx = index
+ input.text = text
+ input.caret_position = input.max_length
popup.close_popup()
diff --git a/option_set/option_set_list.gd b/option_set/option_set_list.gd
index 8aad1b1..4a8841f 100644
--- a/option_set/option_set_list.gd
+++ b/option_set/option_set_list.gd
@@ -7,8 +7,7 @@ const EXACT_SELECTION: bool = false
export var clear_signals_on_hide := true
-signal item_selected # (idx: int, text: String)
-signal nothing_selected # ()
+signal selection_changed # (idx: int, text: String)
export var autowrap := true
@@ -24,6 +23,7 @@ var labels_sizes : Array
var items : Array
var selected_idx := -1
+var selected_item := ""
var is_dirty := true
var normal_style : StyleBoxFlat
@@ -78,6 +78,11 @@ func _init():
sensor.connect("on_scroll", self, "pointer_input_on_scroll_handler")
+#func _ready():
+# for idx in range(5):
+# add_item(">> %d" % idx)
+
+
func mark_as_dirty():
is_dirty = true
@@ -119,6 +124,8 @@ func remove_items(indices: Array):
func clear_items():
items.clear()
+ selected_idx = -1
+ selected_item = ""
v_scroll_bar.value = 0.0
is_dirty = true
@@ -215,26 +222,23 @@ func _process(delta):
func get_item_at_position(mouse_position: Vector2) -> int:
- if items.size() == 0:
- return -1
-
var labels_offset := v_scroll_bar.value
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.
+ if item_idx == items.size():
+ item_idx = -1
+ return item_idx
func select(index: int):
selected_idx = index
- emit_signal("item_selected", selected_idx, items[selected_idx])
+ selected_item = items[selected_idx] if selected_idx >= 0 && selected_idx < items.size() else ""
+ emit_signal("selection_changed", selected_idx, selected_item)
-# @DAM Do we really need this? We should have just one signal to the selection.
func unselect():
- selected_idx = -1
- emit_signal("nothing_selected")
+ select(-1)
func pointer_input_on_press_handler(pointer: PointerInputSensor.PointerInputData):
@@ -262,12 +266,7 @@ func pointer_input_on_end_drag_handler(pointer: PointerInputSensor.PointerInputD
func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData):
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")
+ select(item_idx)
func pointer_input_on_scroll_handler(pointer: PointerInputSensor.PointerInputData):
@@ -278,7 +277,7 @@ func _clear_signals():
if clear_signals_on_hide == false:
return
- for signal_name in ["item_selected", "nothing_selected"]:
+ for signal_name in ["selection_changed"]:
for it in get_signal_connection_list(signal_name):
disconnect(it.signal, it.target, it.method)
diff --git a/readme.md b/readme.md
index 5d48eff..7b73115 100644
--- a/readme.md
+++ b/readme.md
@@ -57,9 +57,7 @@ Surgery Log
- [x] Hide dialogs title bar (appear in the top with 1 or 2 pixels height);
- [x] Fix automation to automatically disconnect acceptance signal handlers when reject is chosen on file_picker/confirm_action;
- [x] Use popup to display confirmation messages;
-- [ ] Improve option sets:
- - [ ] selecting outside optionset entry should select none
- - [ ] if no options are available, show nothing instead of "--"
+- [x] Improve option sets: selecting outside optionset entry should select none; if no options are available, show nothing instead of "--";
- [ ] Fix back button:
- on stage screen should show pop-up asking it changes are to be discarded;
- on file-pickers screen should close them;