added right click to return post it panels

This commit is contained in:
Adrian Schmid 2023-08-12 13:02:00 +02:00
parent 5c487f55df
commit 3640f29170
3 changed files with 18 additions and 14 deletions

View File

@ -130,6 +130,7 @@ func is_in_dropzone(to_check: Node) -> bool:
# called if a mouse button is pressed # called if a mouse button is pressed
func handle_mouse_button(to_handle: Area2D, input: InputEvent): func handle_mouse_button(to_handle: Area2D, input: InputEvent):
# No two areas can be dragged at the same time. # No two areas can be dragged at the same time.
# Make sure that only the same area is dragged. # Make sure that only the same area is dragged.
# Otherwise overlapping areas are dragged at the same time. # Otherwise overlapping areas are dragged at the same time.
@ -141,11 +142,8 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
to_handle.is_dragged = input.pressed to_handle.is_dragged = input.pressed
is_area_dragged = input.pressed is_area_dragged = input.pressed
# TODO: We need a better way to recognize whether "to_handle" is a Card or a Post-It. # Check what is being dragged
# (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))
if to_handle is Card: if to_handle is Card:
active_context = ui_context.DROPZONE active_context = ui_context.DROPZONE
if input.is_pressed(): if input.is_pressed():
reorder_areas("dropzone_content") reorder_areas("dropzone_content")
@ -154,13 +152,17 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
dropzone.move_child(currently_dragged_area, -1) dropzone.move_child(currently_dragged_area, -1)
currently_dragged_area = null currently_dragged_area = null
elif to_handle is PostIt: elif to_handle is PostIt:
if input.is_pressed(): if input.is_action_pressed("mouse_left"):
to_handle.reparent(dropzone) to_handle.reparent(dropzone)
to_handle.on_board = true to_handle.on_board = true
to_handle.set_owner(self) # needs to be here otherwise the owner disappears to_handle.set_owner(self) # needs to be here otherwise the owner disappears
area_dict["post_its_in_list"].erase(to_handle) area_dict["post_its_in_list"].erase(to_handle)
area_dict["dropzone_content"].push_back(to_handle) area_dict["dropzone_content"].push_back(to_handle)
# TODO (if needed): Add function to rearrange the array based on positions in the dropzone elif input.is_action_pressed("mouse_right"):
_return_postit_to_panels(to_handle)
to_handle.is_dragged = false
is_area_dragged = false
currently_dragged_area = null
else: else:
if is_in_dropzone(to_handle): if is_in_dropzone(to_handle):
if to_handle.has_overlapping_areas(): if to_handle.has_overlapping_areas():
@ -284,8 +286,6 @@ func _input(event):
else: else:
_enter_assignment_context() _enter_assignment_context()
# TODO: I forgor the HECKING RIGHT-CLICK!!!!111 AAAAAAAAAAAAAAAAAAAA
# do some adjustments to loop elements (after last element, select first one etc.) # do some adjustments to loop elements (after last element, select first one etc.)
if selected_dropzone_element < 0: if selected_dropzone_element < 0:
selected_dropzone_element = area_dict["dropzone_content"].size()-1 selected_dropzone_element = area_dict["dropzone_content"].size()-1
@ -358,15 +358,14 @@ func _leave_assignment_context():
# handles everything to return a post it to the panels # handles everything to return a post it to the panels
func _return_postit_to_panels(post_it: Area2D): func _return_postit_to_panels(post_it: Area2D):
for panel in area_dict["post_it_panels"]: for panel in area_dict["post_it_panels"]:
print(area_dict["post_it_panels"])
if panel.get_child_count() == 1: if panel.get_child_count() == 1:
area_dict["dropzone_content"].erase(post_it) area_dict["dropzone_content"].erase(post_it)
post_it.on_board = false post_it.on_board = false
area_dict["post_its_in_list"].push_back(post_it) area_dict["post_its_in_list"].push_back(post_it)
#post_it.tween_transform_to(panel.get_child(0).position)
post_it.reparent(panel) post_it.reparent(panel)
post_it.transform = panel.get_child(0).transform post_it.transform = panel.get_child(0).transform
post_it.set_owner(self) post_it.set_owner(self)
#post_it.position = Vector2(0,0)
reorder_areas("dropzone_content") reorder_areas("dropzone_content")
reorder_areas("post_its_in_list") reorder_areas("post_its_in_list")
break break

View File

@ -106,7 +106,7 @@ func _on_input_event(viewport, event, shape_idx):
_move_post_it() _move_post_it()
if event is InputEventMouseButton: if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT: if event.button_index == MOUSE_BUTTON_LEFT or event.button_index == MOUSE_BUTTON_RIGHT:
if "handle_mouse_button" in owner: if "handle_mouse_button" in owner:
mouse_offset = (get_viewport().get_mouse_position() - global_position) mouse_offset = (get_viewport().get_mouse_position() - global_position)
owner.handle_mouse_button(self, event) owner.handle_mouse_button(self, event)

View File

@ -12,7 +12,7 @@ config_version=5
config/name="Frame of Mind" config/name="Frame of Mind"
run/main_scene="res://main.tscn" run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.1", "Forward Plus") config/features=PackedStringArray("4.0", "Forward Plus")
run/max_fps=60 run/max_fps=60
boot_splash/bg_color=Color(0.0313726, 0.0117647, 0.129412, 1) boot_splash/bg_color=Color(0.0313726, 0.0117647, 0.129412, 1)
boot_splash/image="res://splash.png" boot_splash/image="res://splash.png"
@ -31,7 +31,7 @@ gdscript/warnings/native_method_override=0
[display] [display]
window/size/viewport_width=1440 window/size/viewport_width=1440
window/size/viewport_height=1080 window/size/viewport_height=960
window/stretch/mode="canvas_items" window/stretch/mode="canvas_items"
window/stretch/aspect="expand" window/stretch/aspect="expand"
mouse_cursor/custom_image="res://import/interface-elements/cursor.png" mouse_cursor/custom_image="res://import/interface-elements/cursor.png"
@ -80,7 +80,12 @@ player_backwards={
} }
mouse_left={ mouse_left={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null)
]
}
mouse_right={
"deadzone": 0.5,
"events": [null, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"pressed":false,"double_click":false,"script":null)
] ]
} }
look_right={ look_right={