diff options
| author | dam <dam@gudinoff> | 2022-01-14 01:11:38 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-01-14 01:11:38 +0000 |
| commit | 4d8709e47afc2eb8b4e46ced2747b662a849da29 (patch) | |
| tree | a579a48682cb52210cf1a72ceeb47bb10569137a | |
| parent | c9724e10f4a1e008d97aa53d7d2cf9a987c011c8 (diff) | |
| download | surgery-log-4d8709e47afc2eb8b4e46ced2747b662a849da29.tar.zst surgery-log-4d8709e47afc2eb8b4e46ced2747b662a849da29.zip | |
Fix PointerInputSensor. Simplify TouchItemList and TouchVerticalContainer.
| -rw-r--r-- | logic/database.gd | 1 | ||||
| -rw-r--r-- | logic/stage.gd | 25 | ||||
| -rw-r--r-- | main.gd | 6 | ||||
| -rw-r--r-- | pointer_input_sensor.gd | 2 | ||||
| -rw-r--r-- | touch_item_list/touch_item_list.gd | 31 | ||||
| -rw-r--r-- | touch_vertical_container/touch_vertical_container.gd | 27 |
6 files changed, 41 insertions, 51 deletions
diff --git a/logic/database.gd b/logic/database.gd index de978b7..3d74da3 100644 --- a/logic/database.gd +++ b/logic/database.gd @@ -151,7 +151,6 @@ func store_database(file_path: String = DATABASE_FILE_PATH): file.open(file_path, File.WRITE) var header := PoolStringArray(DatabaseEntry.ENTRY_PROTOTYPE.keys()) file.store_csv_line(header) - var entry := PoolStringArray() for it in db: # @DAM This approach depends on the order the dictionary fields are created. file.store_csv_line(it.values()) diff --git a/logic/stage.gd b/logic/stage.gd index 12457c9..e4627c2 100644 --- a/logic/stage.gd +++ b/logic/stage.gd @@ -69,6 +69,13 @@ func _ready(): save_button.connect("pressed", self, "save_action") discard_button.connect("pressed", self, "discard_action") + for it in get_node("controls").get_children(): + it = it as Control + if it is LineEdit: + it.connect("focus_entered", it, "set_cursor_position", [99999999]) # @DAM Use MAX_INT + it.connect("focus_exited", it, "deselect") + + var auto_place := place.get_node("auto") as Button auto_place.connect("pressed", self, "auto_populate", ["place"]) @@ -168,3 +175,21 @@ func clear_filters(save_changes: bool = false): store_filters() +func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData): + .pointer_input_on_click_handler(pointer) + + var target: Control = pointer.target.get_parent() + var button: Button + if target is Button: + button = target + elif target.get_node("auto") is Button: + button = target.get_node("auto") + + if button != null && button.get_global_rect().has_point(pointer.current_position): + if button is CheckBox || button is CheckButton: + button.pressed = !button.pressed + button.emit_signal("button_down") + button.emit_signal("pressed") + button.emit_signal("button_up") + + @@ -26,15 +26,15 @@ func _process(delta: float): if timeout > 0.0: timeout -= delta else: - Engine.target_fps = 10.0 + Engine.target_fps = 10 -func _input(event): +func _input(event: InputEvent): Engine.target_fps = 0 timeout = 3.5 -func _unhandled_input(event): +func _unhandled_input(event: InputEvent): Engine.target_fps = 0 timeout = 3.5 diff --git a/pointer_input_sensor.gd b/pointer_input_sensor.gd index ee5e390..be4d158 100644 --- a/pointer_input_sensor.gd +++ b/pointer_input_sensor.gd @@ -54,7 +54,7 @@ func _ready(): pointer = PointerInputData.new() pointer.target = self connect("mouse_entered", self, "_on_enter_exit", [true]) - connect("mouse_entered", self, "_on_enter_exit", [false]) + connect("mouse_exited", self, "_on_enter_exit", [false]) func _on_enter_exit(is_inside: bool): diff --git a/touch_item_list/touch_item_list.gd b/touch_item_list/touch_item_list.gd index 0534bb2..07d8f30 100644 --- a/touch_item_list/touch_item_list.gd +++ b/touch_item_list/touch_item_list.gd @@ -27,6 +27,7 @@ func _process(delta: float): func pointer_input_on_press_handler(pointer: PointerInputSensor.PointerInputData): is_pointer_dragging = true + grab_focus() func pointer_input_on_drag_handler(pointer: PointerInputSensor.PointerInputData): @@ -40,29 +41,13 @@ func pointer_input_on_end_drag_handler(pointer: PointerInputSensor.PointerInputD func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData): - var target := self - var position := target.get_global_mouse_position() - target.rect_global_position - - var event_touch := InputEventScreenTouch.new() - event_touch.index = 0 - event_touch.position = position - - var event_mouse := InputEventMouseButton.new() - event_mouse.button_index = BUTTON_LEFT - event_mouse.button_mask = BUTTON_MASK_LEFT - event_mouse.position = position - - event_mouse.pressed = true - event_touch.pressed = true - target._gui_input(event_mouse) - target._gui_input(event_touch) - - target.grab_focus() - - event_mouse.pressed = false - event_touch.pressed = false - target._gui_input(event_mouse) - target._gui_input(event_touch) + var selected_idx := get_item_at_position(pointer.current_position - rect_global_position, true) + if selected_idx >= 0: + select(selected_idx) + emit_signal("item_selected", selected_idx) + else: + unselect_all() + emit_signal("nothing_selected") func pointer_input_on_scroll_handler(pointer: PointerInputSensor.PointerInputData): diff --git a/touch_vertical_container/touch_vertical_container.gd b/touch_vertical_container/touch_vertical_container.gd index 10462fd..f9c43e9 100644 --- a/touch_vertical_container/touch_vertical_container.gd +++ b/touch_vertical_container/touch_vertical_container.gd @@ -27,13 +27,8 @@ func _ready(): 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_mouse_filter", [Control.MOUSE_FILTER_IGNORE]) - it.connect("focus_entered", sensor, "mouse_default_cursor_shape", [Control.CURSOR_IBEAM]) - it.connect("focus_exited", sensor, "set_mouse_filter", [Control.MOUSE_FILTER_STOP]) - it.connect("focus_exited", sensor, "mouse_default_cursor_shape", [Control.CURSOR_ARROW]) - - if it is LineEdit: - it.connect("focus_exited", it, "deselect") + it.connect("focus_entered", sensor, "set_visible", [false]) + it.connect("focus_exited", sensor, "set_visible", [true]) func _process(delta: float): @@ -45,6 +40,7 @@ func _process(delta: float): func pointer_input_on_press_handler(pointer: PointerInputSensor.PointerInputData): is_pointer_dragging = true + grab_focus() func pointer_input_on_drag_handler(pointer: PointerInputSensor.PointerInputData): @@ -58,21 +54,6 @@ func pointer_input_on_end_drag_handler(pointer: PointerInputSensor.PointerInputD func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData): - var target: Control = pointer.target.get_parent() - var position := target.get_global_mouse_position() - target.grab_focus() - - var button: Button - if target is Button: - button = target - elif target.get_node("auto") is Button: - button = target.get_node("auto") - - if button != null && button.get_global_rect().has_point(position): - if button is CheckBox || button is CheckButton: - button.pressed = !button.pressed - button.emit_signal("button_down") - button.emit_signal("pressed") - button.emit_signal("button_up") + pointer.target.get_parent().grab_focus() |
