wip: restructuring card board so it can handle being empty

This commit is contained in:
betalars 2023-07-15 13:05:47 +02:00
parent fc1cd50430
commit 44a5d653fb
1 changed files with 12 additions and 10 deletions

View File

@ -1,6 +1,9 @@
extends PanelContainer
var area_dict = {}
var area_dict = {
"dropzone_content": [],
"post_its_in_list": []
}
enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT}
var has_stage = false:
@ -40,8 +43,8 @@ func _ready():
var test_arr = ["c_Joy","p_effort","c_backlash","c_body","c_hit","p_slut","p_worried_mother","p_cross_friend"]
#var test_arr = ["c_Joy","c_body","c_hit"]
populate_board(test_arr)
reorder_areas("dropzone_content")
#populate_board(test_arr)
#reorder_areas("dropzone_content")
active_context = ui_context.DROPZONE
has_stage = has_stage
@ -54,6 +57,8 @@ func _process(delta):
currently_dragged_area.is_dragged = false
is_area_dragged = false
currently_dragged_area = null
if Input.is_action_just_pressed("ui_cancel"):
populate_board(["c_Joy","p_effort","c_backlash","c_body","c_hit","p_slut","p_worried_mother","p_cross_friend"])
# Will be used later to spawn Cards and Post-Its and remember them in the dictionary
@ -61,10 +66,6 @@ func populate_board(card_names: Array):
var all_cards = Array()
var all_postits = Array()
# define entries in dictionary
area_dict["dropzone_content"] = Array()
area_dict["post_its_in_list"] = Array()
# to remember panel positions
area_dict["post_it_panels"] = [base_postit_panel]
@ -95,10 +96,11 @@ func populate_board(card_names: Array):
for child in new_card.get_children(): # We need to clear all the post-its from the cards on the dev-board
if "p_" in child.name:
new_card.remove_child(child) # dev-board has post-its attached to the cards, which need to be removed
new_card.position = Vector2(randi_range(0, dropzone.size.x), randi_range(0, dropzone.size.y))
dropzone.add_child(new_card)
new_card.set_owner(self)
area_dict["dropzone_content"].push_back(new_card)
new_card.global_position = Vector2(500, 500) # using hard-coded position because I'm lazy
#new_card.position = Vector2(randf_range(new_card.diameter, dropzone.size.x), randf_range(new_card.diameter, dropzone.size.y)) - Vector2(new_card.diameter/2, new_card.diameter/2)
new_card.is_dragable = true
if "p_" in card_name: # spawning a post-it
var new_postit = _find_area_by_string(all_postits, card_name).duplicate()
@ -222,7 +224,7 @@ func reorder_areas(reorder: String):
# Takes the inputs for control inputs
func _input(event):
# Return, if the input is a mouse event (mouse events are handled separately)
if event is InputEventMouse or !has_stage: return
if event is InputEventMouse or !has_stage or not is_instance_valid(currently_selected_node): return
if event.is_action_pressed("ui_up"): # up to select an element above
match active_context:
@ -252,7 +254,7 @@ func _input(event):
if active_context > 2:
active_context = ui_context.DROPZONE
elif event.is_action_pressed("ui_select"): # select the selected post it
elif event.is_action_pressed("ui_accept"): # select the selected post it
if active_context == ui_context.ASSIGN_POST_IT: # to assign it to a card
attach_postit_to_card(currently_selected_node,
currently_selected_card_for_assigning, true)