WIP: refactoring card_board
This commit is contained in:
parent
a1e186c2c6
commit
5f1322fe93
|
|
@ -1,11 +1,11 @@
|
|||
extends PanelContainer
|
||||
|
||||
var area_dict = {
|
||||
"dropzone_content": [],
|
||||
"cards": [],
|
||||
"post_its_in_list": [],
|
||||
"post_it_panels": []
|
||||
}
|
||||
#var area_dict = {
|
||||
# "dropzone_content": [],
|
||||
# "cards": [],
|
||||
# "post_its_in_list": [],
|
||||
# "post_it_panels": []
|
||||
#}
|
||||
enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT}
|
||||
|
||||
var has_stage = false:
|
||||
|
|
@ -18,11 +18,10 @@ var has_stage = false:
|
|||
has_stage = false
|
||||
self.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
if is_node_ready():
|
||||
for child in area_dict["dropzone_content"]+area_dict["post_its_in_list"]:
|
||||
if focus:
|
||||
child.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
else:
|
||||
child.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
if focus:
|
||||
process_mode = Node.PROCESS_MODE_INHERIT
|
||||
else:
|
||||
process_mode = Node.PROCESS_MODE_DISABLED
|
||||
visible = has_stage
|
||||
|
||||
@onready var dropzone = $HBoxContainer/dropzone
|
||||
|
|
@ -99,21 +98,22 @@ func populate_board(card_names: Array):
|
|||
new_card.position = Vector2(randi_range(dropzone_padding, dropzone_size.x), randi_range(dropzone_padding, dropzone_size.y))
|
||||
new_card.reparent(dropzone, false)
|
||||
new_card.set_owner(self)
|
||||
area_dict["dropzone_content"].push_back(new_card)
|
||||
area_dict["cards"].push_back(new_card)
|
||||
#area_dict["dropzone_content"].push_back(new_card)
|
||||
#area_dict["cards"].push_back(new_card)
|
||||
new_card.is_dragable = true
|
||||
for new_postit in all_new["postIts"]: # spawning a post-it
|
||||
var new_panel = base_postit_panel.duplicate()
|
||||
postit_container.add_child(new_panel)
|
||||
new_panel.set_owner(self)
|
||||
area_dict["post_it_panels"].append(new_panel)
|
||||
#area_dict["post_it_panels"].append(new_panel)
|
||||
new_panel.add_child(new_postit)
|
||||
new_postit.set_owner(self)
|
||||
area_dict["post_its_in_list"].push_back(new_postit)
|
||||
#area_dict["post_its_in_list"].push_back(new_postit)
|
||||
new_postit.position = new_panel.get_child(0).position
|
||||
new_postit.is_dragable = true
|
||||
|
||||
currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default
|
||||
#currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default
|
||||
currently_selected_node = dropzone.get_child(0)
|
||||
|
||||
reorder_areas("dropzone_content")
|
||||
reorder_areas("cards")
|
||||
|
|
@ -121,12 +121,7 @@ func populate_board(card_names: Array):
|
|||
|
||||
# Checks if a Node is currently inside the dropzone
|
||||
func is_in_dropzone(to_check: Node) -> bool:
|
||||
if (dropzone.size.x < to_check.global_position.x or dropzone.size.y < to_check.global_position.y):
|
||||
return false
|
||||
elif (to_check.global_position.x < 0 or to_check.global_position.y < 0):
|
||||
return false
|
||||
else:
|
||||
return true
|
||||
return dropzone.get_rect().has_point(to_check.global_position)
|
||||
|
||||
# called if a mouse button is pressed
|
||||
func handle_mouse_button(to_handle: Area2D, input: InputEvent):
|
||||
|
|
@ -156,8 +151,8 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
|
|||
to_handle.reparent(dropzone)
|
||||
to_handle.on_board = true
|
||||
to_handle.set_owner(self) # needs to be here otherwise the owner disappears
|
||||
area_dict["post_its_in_list"].erase(to_handle)
|
||||
area_dict["dropzone_content"].push_back(to_handle)
|
||||
#area_dict["post_its_in_list"].erase(to_handle)
|
||||
#area_dict["dropzone_content"].push_back(to_handle)
|
||||
elif input.is_action_pressed("mouse_right"):
|
||||
_return_postit_to_panels(to_handle)
|
||||
to_handle.is_dragged = false
|
||||
|
|
@ -180,7 +175,7 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
|
|||
|
||||
|
||||
# Logic for attaching a postit to a card. Also reset postit positions if the card cannot be attached
|
||||
func attach_postit_to_card(postit: Area2D, card: Area2D, update_dict = false):
|
||||
func attach_postit_to_card(postit: Area2D, card: Area2D, preview = false):
|
||||
|
||||
if card.has_postit_attached():
|
||||
if active_context == ui_context.ASSIGN_POST_IT:
|
||||
|
|
@ -190,26 +185,27 @@ func attach_postit_to_card(postit: Area2D, card: Area2D, update_dict = false):
|
|||
|
||||
postit.set_owner(self)
|
||||
|
||||
if update_dict:
|
||||
area_dict["post_its_in_list"].erase(postit)
|
||||
area_dict["dropzone_content"].push_back(postit)
|
||||
#if update_dict:
|
||||
# area_dict["post_its_in_list"].erase(postit)
|
||||
# area_dict["dropzone_content"].push_back(postit)
|
||||
|
||||
reorder_areas("dropzone_content")
|
||||
reorder_areas("cards")
|
||||
reorder_areas("post_its_in_list")
|
||||
|
||||
func is_board_complete() -> bool:
|
||||
if mementos_collected == 4:
|
||||
for fluff in area_dict["dropzone_content"]:
|
||||
if fluff is Card:
|
||||
if not fluff.has_postit_attached():
|
||||
return
|
||||
emit_signal("board_completed")
|
||||
for card in dropzone.get_children():
|
||||
if card is Card:
|
||||
if not card.has_postit_attached():
|
||||
return false
|
||||
return true
|
||||
return false
|
||||
|
||||
func is_board_lore() -> bool:
|
||||
for post_it in area_dict["dropzone_content"]:
|
||||
if post_it is PostIt:
|
||||
var card = post_it.get_parent().get_parent()
|
||||
if not post_it.is_in_group(card.name): return false
|
||||
for card in dropzone.get_children():
|
||||
if card.has_postit_attached():
|
||||
if not card.current_post_it.is_in_group(card.name): return false
|
||||
return true
|
||||
|
||||
# Mark area that was hovered over as currently selected
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
[ext_resource type="Shader" path="res://logic-scenes/board/physics-board.gdshader" id="1_ggnth"]
|
||||
[ext_resource type="Script" path="res://logic-scenes/board/card-board.gd" id="3_8v4c4"]
|
||||
[ext_resource type="PackedScene" uid="uid://bvowj4l8dtceu" path="res://dev-util/board of devs.tscn" id="4_sskx2"]
|
||||
[ext_resource type="PackedScene" path="res://logic-scenes/board/empty_postIt_panel.tscn" id="5_dr0qs"]
|
||||
[ext_resource type="PackedScene" uid="uid://chwf61qpn2sqw" path="res://logic-scenes/board/empty_postIt_panel.tscn" id="5_dr0qs"]
|
||||
[ext_resource type="Script" path="res://logic-scenes/board/card collider.gd" id="6_wpxls"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ttqei"]
|
||||
|
|
@ -30,6 +30,7 @@ size_flags_horizontal = 6
|
|||
size_flags_vertical = 6
|
||||
mouse_filter = 1
|
||||
script = ExtResource("3_8v4c4")
|
||||
dropzone_padding = null
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
|
|
|||
Loading…
Reference in New Issue