card-board dictionary + move post-its to dropboard

This commit is contained in:
Adrian Schmid 2023-07-01 13:43:27 +02:00
parent 27d3497fde
commit 00ca4abc1f
3 changed files with 38 additions and 3 deletions

View File

@ -1,11 +1,44 @@
extends PanelContainer extends PanelContainer
var obj_dict = {}
@onready var dropzone = $HBoxContainer/dropzone
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass
# TODO: Currently populating the dictionary with the Nodes currently in the scene
# When opening the scene we need to pass some kind of collection to the Board
# Then it can display the Card/PostIts and populate its dictionary at the same time
var cards = dropzone.get_children()
var post_it_panels = get_child(0).get_child(1).get_child(0).get_children()
var post_its = Array()
for panel in post_it_panels:
post_its.push_back(panel.get_child(0))
obj_dict["Cards"] = cards
obj_dict["Post_it_panels"] = post_it_panels
obj_dict["Post_its"] = post_its
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
pass pass
func populate_board():
pass
func handle_mouse_button(to_handle: Node, input: InputEvent, dragableType: int):
print_debug(input)
# TODO: We need a better way to recognize
# whether to_handle is a Card or a Post-It
# (Tried checking for a script, didn't work, because script has no name attached.
# Alternative might be to check for specific values within the script ("is_card" f.e))
match dragableType:
1: # 1 = Card
print_debug("I'm a card")
2: # 2 = PostIt
print_debug("I'm a Post-It")
to_handle.reparent(dropzone)
to_handle.set_owner(self) # needs to be here otherwise the owner disappears

View File

@ -101,6 +101,7 @@ func _on_mouse_exited():
highlighted = false highlighted = false
func _on_input_event(viewport, event, shape_idx): func _on_input_event(viewport, event, shape_idx):
if event is InputEventMouseMotion and is_dragged: if event is InputEventMouseMotion and is_dragged:
position += event.relative position += event.relative
@ -109,5 +110,5 @@ func _on_input_event(viewport, event, shape_idx):
if is_dragable: if is_dragable:
is_dragged = event.pressed is_dragged = event.pressed
if "handle_mouse_button" in owner: if "handle_mouse_button" in owner:
owner.handle_mouse_button(self, event) owner.handle_mouse_button(self, event, 1)

View File

@ -85,4 +85,5 @@ func _on_input_event(viewport, event, shape_idx):
if is_dragable: if is_dragable:
is_dragged = event.pressed is_dragged = event.pressed
if "handle_mouse_button" in owner: if "handle_mouse_button" in owner:
owner.handle_mouse_button(self, event) owner.handle_mouse_button(self, event, 2)