diff options
| -rw-r--r-- | logic/popup_list.gd | 1 | ||||
| -rw-r--r-- | logic/stage.gd | 31 | ||||
| -rw-r--r-- | main.tscn | 3 | ||||
| -rw-r--r-- | option_set/option_set.gd | 23 | ||||
| -rw-r--r-- | option_set/option_set.tscn | 3 | ||||
| -rw-r--r-- | project.godot | 6 | ||||
| -rw-r--r-- | readme.md | 5 | ||||
| -rw-r--r-- | test_input.gd | 42 | ||||
| -rw-r--r-- | test_input.tscn | 58 | ||||
| -rw-r--r-- | touch_vertical_container/touch_vertical_container.gd | 71 |
10 files changed, 82 insertions, 161 deletions
diff --git a/logic/popup_list.gd b/logic/popup_list.gd index 43bf2a1..7e049fb 100644 --- a/logic/popup_list.gd +++ b/logic/popup_list.gd @@ -1,4 +1,5 @@ extends Popup +class_name PopupList signal item_selected diff --git a/logic/stage.gd b/logic/stage.gd index 3cc5943..892dee4 100644 --- a/logic/stage.gd +++ b/logic/stage.gd @@ -49,11 +49,9 @@ func _ready(): save_button.connect("pressed", self, "save_action") discard_button.connect("pressed", self, "discard_action") - # @DAM Not working because we changed the stage/controls/.. estructure with the new option_sets. - # @DAM We could try to do a recursive approach or, build a stack of next items to process. for it in get_node("controls").get_children(): if it is LineEdit: - it.connect("focus_entered", it, "set_cursor_position", [99999999]) # @DAM Use MAX_INT + it.connect("focus_entered", it, "set", ["caret_position", it.max_length]) it.connect("focus_exited", it, "deselect") # Map option sets buttons. @@ -68,16 +66,12 @@ func _ready(): "intervention": intervention } for key in option_sets_map: -# var button := option_sets_map[key].get_node("option_set") as Button -# button.connect("pressed", self, "show_option_sets", [key]) - -# if key != "place": # @DAM DEBUG -# continue - var button := option_sets_map[key].get_node("options") as Button - button.connect("pressed", self, "show_option_sets", [key]) + var button := option_sets_map[key].get_node("options") as Button # @DAM Maybe rename "options". Also requires rename on option_set. + button.connect("pressed", self, "show_options", [key]) -func get_option_sets(field: String): +func show_options(field: String): + var option_set_field := self[field] as OptionSet var options: Array match field: @@ -92,20 +86,7 @@ func get_option_sets(field: String): options.append(OPTION_SETS_NOT_AVAILABLE) options.sort() - return options - - -# @DAM WIP I suspect that these should go inside the option_set class... -func show_option_sets(field: String): - var stage_options = get_node("/root/main/popup_list") as Popup - stage_options.connect("item_selected", self, "option_set_selected", [field], CONNECT_ONESHOT) - stage_options.popup_options(get_option_sets(field)) - - -func option_set_selected(index: int, field: String): - var field_input: LineEdit = self[field].get_node("input") - field_input.text = get_option_sets(field)[index] - field_input.caret_position = field_input.text.length() + option_set_field.show_options(options) func save_action(): @@ -97,6 +97,7 @@ script = ExtResource( 9 ) [node name="process_id" type="LineEdit" parent="stage/controls" index="0"] margin_right = 1080.0 margin_bottom = 62.0 +max_length = 32 placeholder_text = "Nº Processo" caret_blink = true caret_blink_speed = 0.5 @@ -105,6 +106,7 @@ caret_blink_speed = 0.5 margin_top = 66.0 margin_right = 1080.0 margin_bottom = 128.0 +max_length = 32 placeholder_text = "Nº Cirurgia" caret_blink = true caret_blink_speed = 0.5 @@ -193,6 +195,7 @@ text = "Urgência" margin_top = 928.0 margin_right = 1080.0 margin_bottom = 990.0 +max_length = 4096 placeholder_text = "Notas" caret_blink = true caret_blink_speed = 0.5 diff --git a/option_set/option_set.gd b/option_set/option_set.gd index e9cac3f..62d10d0 100644 --- a/option_set/option_set.gd +++ b/option_set/option_set.gd @@ -1,6 +1,7 @@ extends Control class_name OptionSet +var options: Array var text: String setget set_text, get_text func set_text(var value: String): @@ -9,7 +10,27 @@ func set_text(var value: String): func get_text() -> String: return input.text +onready var input := get_node("input") as LineEdit +onready var button := get_node("options") as Button # @DAM Maybe rename this. Also requires renaming on stage. +onready var popup := get_node("/root/main/popup_list") as PopupList -onready var input := get_node("input") as LineEdit +func _ready(): + assert(popup != null, "OptionSet failed to get 'popup' node.") + + input.connect("focus_entered", input, "set", ["caret_position", input.max_length]) + input.connect("focus_exited", input, "deselect") + + +func show_options(options_array: Array): + options = options_array + popup.connect("item_selected", self, "option_selected", [], CONNECT_ONESHOT) + popup.popup_options(options) + + +func option_selected(index: int): + if index >= 0 && index < options.size(): + input.text = options[index] + input.caret_position = input.max_length + button.release_focus() diff --git a/option_set/option_set.tscn b/option_set/option_set.tscn index fc2aff5..bf15806 100644 --- a/option_set/option_set.tscn +++ b/option_set/option_set.tscn @@ -15,7 +15,8 @@ anchor_right = 1.0 anchor_bottom = 1.0 margin_right = -100.0 size_flags_horizontal = 3 -placeholder_text = "option set placeholder" +text = "placeholder" +max_length = 4096 caret_blink = true caret_blink_speed = 0.5 __meta__ = { diff --git a/project.godot b/project.godot index aed55ea..b414dff 100644 --- a/project.godot +++ b/project.godot @@ -34,6 +34,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://pointer_input_sensor.gd" }, { +"base": "Popup", +"class": "PopupList", +"language": "GDScript", +"path": "res://logic/popup_list.gd" +}, { "base": "TouchVerticalContainer", "class": "Stage", "language": "GDScript", @@ -60,6 +65,7 @@ _global_script_class_icons={ "DatePicker": "", "OptionSet": "", "PointerInputSensor": "", +"PopupList": "", "Stage": "", "TouchItemList": "", "TouchVerticalContainer": "", @@ -42,9 +42,9 @@ Surgery Log else: has_permissions = true ``` -- [ ] Fix the show option sets buttons; they are drawn over the input fields and hide inserted text; +- [x] Fix the show option sets buttons; they are drawn over the input fields and hide inserted text; +- [ ] Allow to parse option sets from database file; - [ ] Database menu and action buttons are not nice; Improve appearance; -- [ ] Show title of database (Log/Historico) and stage (New entry/Novo registo); - [ ] check if import_option_sets, store_option_sets, store_database require the parameter save_changes; this requires changes on databse, stage and menu scripts; - [ ] fix back button: - on stage screen should show pop-up asking it changes are to be discarded; @@ -52,7 +52,6 @@ Surgery Log - on about screen should close it; - on auto-fill pop-up, should close it; - on database screen, should deselect selected item, otherwise should quit the app; -- [ ] Add title to current window (on top, left of the menu); - [ ] Improve menu appearance; - [ ] Setup two themes: - [ ] theme_light diff --git a/test_input.gd b/test_input.gd deleted file mode 100644 index bae409d..0000000 --- a/test_input.gd +++ /dev/null @@ -1,42 +0,0 @@ -extends ColorRect - -onready var debug: RichTextLabel = get_node("/root/main/debug") - - -func _gui_input(event): -# if name == "a": -# accept_event() -# if name == "b" : #&& (event is InputEventScreenTouch): -# if name == "b": -# get_tree().set_input_as_handled() -# accept_event() -# if name == "b" && event is InputEventScreenTouch && event.is_pressed() == false: -# simulate_click() -# call_deferred("simulate_click") - - if event is InputEventScreenTouch || event is InputEventMouseButton: - debug.text += "%s> %-24s\t:\t%s\n" % [name, event.get_class(), event.is_pressed()] - else: - debug.text += "%s> %s\n" % [name, event.get_class()] - - -func simulate_click(): - var event_touch = InputEventScreenTouch.new() - event_touch.index = 0 - event_touch.position = self.get_global_mouse_position() - - var event_mouse = InputEventMouseButton.new() - event_mouse.button_index = BUTTON_LEFT - event_mouse.button_mask = BUTTON_MASK_LEFT - event_mouse.position = self.get_global_mouse_position() - - self.mouse_filter = Control.MOUSE_FILTER_IGNORE - event_mouse.pressed = true - event_touch.pressed = true -# Input.parse_input_event(event_mouse) - Input.parse_input_event(event_touch) - event_mouse.pressed = false - event_touch.pressed = false -# Input.parse_input_event(event_mouse) - Input.parse_input_event(event_touch) - self.mouse_filter = Control.MOUSE_FILTER_STOP diff --git a/test_input.tscn b/test_input.tscn deleted file mode 100644 index 4b507fe..0000000 --- a/test_input.tscn +++ /dev/null @@ -1,58 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://test_input.gd" type="Script" id=1] -[ext_resource path="res://fonts/font_regular.tres" type="DynamicFont" id=2] - -[node name="main" type="Control"] -anchor_right = 1.0 -anchor_bottom = 1.0 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="debug" type="RichTextLabel" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 -mouse_filter = 2 -custom_fonts/normal_font = ExtResource( 2 ) -scroll_following = true -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="a" type="ColorRect" parent="."] -anchor_right = 0.66 -anchor_bottom = 0.66 -color = Color( 1, 0, 0, 0.196078 ) -script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="b" type="ColorRect" parent="a"] -anchor_left = 0.5 -anchor_right = 1.502 -anchor_bottom = 1.0 -mouse_filter = 1 -color = Color( 0, 1, 0, 0.196078 ) -script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="c" type="ColorRect" parent="."] -anchor_top = 0.333 -anchor_right = 0.666 -anchor_bottom = 1.0 -color = Color( 0, 0, 1, 0.196078 ) -script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="d" type="ColorRect" parent="c"] -anchor_left = 0.5 -anchor_right = 1.502 -anchor_bottom = 1.0 -color = Color( 1, 1, 1, 0.196078 ) -script = ExtResource( 1 ) diff --git a/touch_vertical_container/touch_vertical_container.gd b/touch_vertical_container/touch_vertical_container.gd index 7c2ba84..1a7236c 100644 --- a/touch_vertical_container/touch_vertical_container.gd +++ b/touch_vertical_container/touch_vertical_container.gd @@ -26,9 +26,6 @@ func _ready(): sensor.connect("on_drag", self, "pointer_input_on_drag_handler") sensor.connect("on_end_drag", self, "pointer_input_on_end_drag_handler") sensor.connect("on_click", self, "pointer_input_on_click_handler") - -# it.connect("focus_entered", sensor, "set_visible", [false]) -# it.connect("focus_exited", sensor, "set_visible", [true]) func _process(delta: float): @@ -54,33 +51,45 @@ func pointer_input_on_end_drag_handler(pointer: PointerInputSensor.PointerInputD func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData): - propagate_click(pointer.target.get_parent(), pointer) - - -# @DAM Maybe replace this with a stack of next items to process approach. -func propagate_click(control: Control, pointer: PointerInputSensor.PointerInputData) -> bool: - if control is PointerInputSensor || control.mouse_filter == MOUSE_FILTER_IGNORE || control.visible == false: - return false - var click_processed := false - if control.get_global_rect().has_point(pointer.current_position): - var children = control.get_children() - children.invert() # @DAM Use inverted index for loop to avoid invert() operation. - for child in children: - if child is Control: - click_processed = click_processed || propagate_click(child, pointer) - if click_processed == true: - break - - if click_processed == false: - if control is CheckBox || control is CheckButton: - control.pressed = !control.pressed - control.grab_focus() - control.emit_signal("button_down") - control.emit_signal("pressed") - control.emit_signal("button_up") - click_processed = true - pointer.target.visible = false - control.connect("focus_exited", pointer.target, "set_visible", [true]) + # Get last leaf node. + var root := pointer.target.get_parent() as Control + var leaf := root as Node + while leaf.get_child_count() > 0: + leaf = leaf.get_child(leaf.get_child_count() - 1) - return click_processed + # Navigate backwards from leaf to root until we find a node accepting the input. + var tried_leaf_as_root := false + while leaf != root || tried_leaf_as_root == false: + tried_leaf_as_root = leaf == root # Allow a final iteration cycle when leaf reaches root. + var node := leaf + + if node is PointerInputSensor \ + || node is Control == false \ + || node.mouse_filter == MOUSE_FILTER_IGNORE \ + || node.visible == false \ + || node.get_global_rect().has_point(pointer.current_position) == false: + # Get next node to be processed. + var leaf_index_in_parent := leaf.get_position_in_parent() + var parent := leaf.get_parent() + if leaf_index_in_parent == 0: + leaf = parent + else: + leaf = parent.get_child(leaf_index_in_parent - 1) + # Drill down into the new tree branch. + while leaf.get_child_count() > 0: + leaf = leaf.get_child(leaf.get_child_count() - 1) + continue + + var control: Control = node + if control is CheckBox || control is CheckButton: + control.pressed = !control.pressed + + control.grab_focus() + control.emit_signal("button_down") + control.emit_signal("pressed") + control.emit_signal("button_up") + control.connect("focus_exited", pointer.target, "set_visible", [true], CONNECT_ONESHOT) + pointer.target.visible = false + break + |
