aboutsummaryrefslogtreecommitdiff
path: root/logic
diff options
context:
space:
mode:
Diffstat (limited to 'logic')
-rw-r--r--logic/database.gd67
-rw-r--r--logic/popup_list.gd24
-rw-r--r--logic/stage.gd75
3 files changed, 96 insertions, 70 deletions
diff --git a/logic/database.gd b/logic/database.gd
index 044681f..de978b7 100644
--- a/logic/database.gd
+++ b/logic/database.gd
@@ -1,21 +1,16 @@
-extends ItemList
+extends TouchItemList
class_name Database
const DATABASE_FILE_PATH: String = "user://database.csv"
-const POINTER_VELOCITY_DECAYING_FACTOR: float = 2.5
var db: Array
var selected_idx: int
var staged_idx: int
-var is_pointer_dragging := false
-var pointer_drag_velocity := 0.0
onready var stage := get_node("/root/main/stage") as Stage
onready var delete_button := get_node("actions/delete") as Button
onready var edit_button := get_node("actions/edit") as Button
onready var add_button := get_node("actions/add") as Button
-onready var v_scroll_bar := get_v_scroll() as ScrollBar
-onready var drag_sensor := get_node("drag_sensor") as PointerInputSensor
func _init():
@@ -36,24 +31,13 @@ func _ready():
stage.connect("save", self, "save_stage")
stage.connect("discard", self, "discard_stage")
- drag_sensor.connect("on_press", self, "pointer_input_handler")
- drag_sensor.connect("on_drag", self, "pointer_input_handler")
- drag_sensor.connect("on_end_drag", self, "pointer_input_handler")
- drag_sensor.connect("on_click", self, "pointer_input_handler")
-
for it in db:
self.add_item(get_entry_view(it))
-func _process(delta: float):
- # Apply drag movement inertia.
- if is_pointer_dragging == false && abs(pointer_drag_velocity) > 0.5:
- pointer_drag_velocity *= clamp((1.0 - POINTER_VELOCITY_DECAYING_FACTOR * delta), 0.0, 1.0)
- v_scroll_bar.value -= pointer_drag_velocity * delta
-
-
func _notification(what: int):
- # @DAM Yet to be polished.
+ # @DAM This code should be moved into the main.gd which should check which node was currently
+ # active and above, and send the signal there.
if visible == false || has_focus() == false:
return
@@ -77,10 +61,6 @@ func clear_selection():
unselect_all()
-func scroll_to_selected():
- v_scroll_bar.value = float(selected_idx)/float(db.size()) * v_scroll_bar.max_value - (v_scroll_bar.page * 0.5)
-
-
func delete_action():
if selected_idx < 0:
return
@@ -125,7 +105,7 @@ func save_stage(entry: Dictionary):
select(next_selected_idx)
emit_signal("item_selected", next_selected_idx) # Calling "select" does not trigger the "item_selected" signal.
set_item_text(selected_idx, get_entry_view(db[selected_idx]))
- call_deferred("scroll_to_selected")
+ ensure_current_is_visible()
store_database()
@@ -203,42 +183,3 @@ func fake_database(save_changes: bool = false):
store_database()
-func pointer_input_handler(pointer: PointerInputSensor.PointerInputData):
- match pointer.action:
- PointerInputSensor.PointerInputAction.ON_PRESS:
- is_pointer_dragging = true
-
- PointerInputSensor.PointerInputAction.ON_DRAG:
- is_pointer_dragging = true
- pointer_drag_velocity = pointer.velocity.y
- v_scroll_bar.value -= pointer.relative_position.y
-
- PointerInputSensor.PointerInputAction.ON_END_DRAG:
- is_pointer_dragging = false
-
- PointerInputSensor.PointerInputAction.ON_CLICK:
- 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)
-
-
diff --git a/logic/popup_list.gd b/logic/popup_list.gd
new file mode 100644
index 0000000..1dd156c
--- /dev/null
+++ b/logic/popup_list.gd
@@ -0,0 +1,24 @@
+extends Popup
+
+signal item_selected
+
+onready var item_list := get_node("list") as TouchItemList
+
+
+func _ready():
+ item_list.connect("item_selected", self, "selected")
+
+
+func popup_options(options: Array):
+ item_list.v_scroll_bar.value = 0.0
+ item_list.clear()
+ for it in options:
+ item_list.add_item(it)
+ self.popup_centered_ratio(0.9)
+
+
+func selected(index: int):
+ self.hide()
+ emit_signal("item_selected", index)
+
+
diff --git a/logic/stage.gd b/logic/stage.gd
index f6f6e47..dc42273 100644
--- a/logic/stage.gd
+++ b/logic/stage.gd
@@ -8,7 +8,42 @@ const FILTERS_FILE_PATH: String = "user://filters.csv"
const POINTER_VELOCITY_DECAYING_FACTOR: float = 2.5
var staged_entry := {}
-var filters := {}
+var filters := {
+ "place": {
+ "bloco central": null,
+ "tondela": null,
+ "xpto_00": null,
+ "xpto_01": null,
+ "xpto_02": null,
+ "xpto_03": null,
+ "xpto_04": null,
+ "xpto_05": null,
+ "xpto_06": null,
+ "xpto_07": null,
+ "xpto_08": null,
+ "xpto_09": null,
+ "xpto_10": null,
+ "xpto_11": null,
+ "xpto_12": null,
+ "xpto_13": null,
+ "xpto_14": null,
+ "xpto_15": null,
+ "xpto_16": null,
+ "xpto_17": null,
+ "xpto_18": null,
+ "xpto_19": null,
+ "xpto_20": null,
+ "xpto_21": null,
+ "xpto_22": null,
+ "xpto_23": null,
+ "xpto_24": null,
+ "xpto_25": null,
+ "xpto_26": null,
+ "xpto_27": null,
+ "xpto_28": null,
+ "xpto_29": null,
+ },
+}
var is_pointer_dragging := false
var pointer_drag_velocity := 0.0
@@ -60,6 +95,22 @@ func _ready():
if it is LineEdit:
it.connect("focus_exited", it, "deselect")
+
+ var auto_place := place.get_node("auto") as Button
+ auto_place.connect("pressed", self, "auto_populate", ["place"])
+
+
+func auto_populate(field: String):
+ var stage_options = get_node("/root/main/popup_list") as Popup
+ stage_options.connect("item_selected", self, "auto_selected", [field], CONNECT_ONESHOT)
+ stage_options.popup_options(filters[field].keys())
+
+
+func auto_selected(index: int, field: String):
+ var field_input: LineEdit = self[field]
+ field_input.text = filters[field].keys()[index]
+ field_input.caret_position = field_input.text.length()
+
func _process(delta: float):
@@ -116,11 +167,6 @@ func get_stage() -> Dictionary:
return staged_entry
-func _notification(what: int):
- if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST:
- discard_action()
-
-
func pointer_input_handler(pointer: PointerInputSensor.PointerInputData):
match pointer.action:
PointerInputSensor.PointerInputAction.ON_PRESS:
@@ -135,9 +181,23 @@ func pointer_input_handler(pointer: PointerInputSensor.PointerInputData):
is_pointer_dragging = false
PointerInputSensor.PointerInputAction.ON_CLICK:
+
+ # @DAM Try this approach on the TouchItemList
+
var target: Control = pointer.target.get_parent()
var position := target.get_global_mouse_position() - target.rect_global_position
+ var button: Button = target.get_node("auto")
+ if button != null && button.get_rect().has_point(position):
+ button.grab_focus()
+# button.emit_signal("button_down")
+ button.emit_signal("pressed")
+# button.emit_signal("button_up")
+ else:
+ target.grab_focus()
+ return
+
+
var event_touch := InputEventScreenTouch.new()
event_touch.index = 0
event_touch.position = position
@@ -153,13 +213,14 @@ func pointer_input_handler(pointer: PointerInputSensor.PointerInputData):
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)
+
func load_filters(file_path: String = FILTERS_FILE_PATH):
var file := File.new()
file.open(file_path, File.READ_WRITE)