From daf073c6b42fbed9fbd87894c5c08175577679f0 Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Mon, 3 Jul 2023 20:27:09 +0200 Subject: [PATCH] populate_board() to spawn cards/postits --- src/logic-scenes/board/card-board.gd | 83 ++++++++++++++++++++-------- src/logic-scenes/board/post-it.gd | 6 +- 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index 3130171..6478ab6 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -4,6 +4,8 @@ var area_dict = {} enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT} @onready var dropzone = $HBoxContainer/dropzone +@onready var postit_container = $HBoxContainer/ScrollContainer/VBoxContainer +@onready var board_of_devs = $"board of devs" @onready var active_context = ui_context.DROPZONE # 0 = dropzone, 1 = post it list var currently_selected_node: Area2D = null @@ -17,9 +19,11 @@ var selected_card_for_assignment # Called when the node enters the scene tree for the first time. func _ready(): - populate_board() - reorder_areas("dropzone_content") + var test_arr = ["c_Joy","p_effort","c_backlash","c_body","c_hit","p_slut","p_worried_mother","p_cross_friend"] + + populate_board(test_arr) + reorder_areas("dropzone_content") active_context = ui_context.DROPZONE @@ -31,29 +35,60 @@ func _process(delta): currently_dragged_area.is_dragged = false is_area_dragged = false currently_dragged_area = null - - #if active_context == ui_context.ASSIGN_POST_IT: # Will be used later to spawn Cards and Post-Its and remember them in the dictionary -func populate_board(): - # 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() +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"] = get_child(0).get_child(1).get_child(0).get_children() + + # get all the cards and post-its from the board of devs + for child in board_of_devs.get_children(): + for child_2 in child.get_children(): # put all cards in all_cards array + all_cards.push_back(child_2) + for child_3 in child_2.get_children(): # put all post-its in all_postits array + if "p_" in child_3.name: # post-its are currently children of cards. + all_postits.push_back(child_3) # If this changes, this logic needs to be adjusted. + + # spawning the cards and adding them to the dictionary + for card_name in card_names: + if "c_" in card_name: # spawning a card + var new_card = _find_area_by_string(all_cards, card_name).duplicate() + 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 + dropzone.add_child(new_card) + new_card.set_owner(self) + area_dict["dropzone_content"].push_back(new_card) + new_card.global_position = Vector2(300, 200) # using hard-coded position because I'm lazy + 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() + for panel in area_dict["post_it_panels"]: # still mad I can't use the return_postit-func for this... + if panel.get_child_count() == 1: + panel.add_child(new_postit) + new_postit.set_owner(self) + area_dict["post_its_in_list"].push_back(new_postit) + new_postit.position = panel.get_child(0).position + new_postit.is_dragable = true + break - for panel in post_it_panels: - post_its.push_back(panel.get_child(1)) - - area_dict["dropzone_content"] = cards # will be selected on the left side - area_dict["post_it_panels"] = post_it_panels # to remember panel positions - area_dict["post_its_in_list"] = post_its # will be selected on the right side - currently_selected_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default +# Handy function to filter an array of areas by the name of a card +func _find_area_by_string(area_arr: Array, name: String) -> Area2D: + for area in area_arr: + if area.name == name: + return area + return null # Checks if a Node is currently inside the dropzone func is_in_dropzone(to_check: Node) -> bool: @@ -64,7 +99,7 @@ func is_in_dropzone(to_check: Node) -> bool: else: return true - +# called if a mouse button is pressed func handle_mouse_button(to_handle: Area2D, input: InputEvent): # No two areas can be dragged at the same time. # Make sure that only the same area is dragged. @@ -126,7 +161,8 @@ func attach_postit_to_card(postit: Area2D, card: Area2D, update_dict = false): # Mark area that was hovered over as currently selected func handle_hover(to_handle: Area2D): - currently_selected_node.highlighted = false + if to_handle != currently_selected_node: + currently_selected_node.highlighted = false currently_selected_node = to_handle if is_in_dropzone(to_handle): @@ -138,7 +174,7 @@ func handle_hover(to_handle: Area2D): # Reorders the areas in any of the dictionaries entries -# Pass the entries key in order to reorder it +# Pass the entry's key in order to reorder it func reorder_areas(reorder: String): var old_order = area_dict[reorder] var new_order = Array() @@ -192,7 +228,8 @@ func _input(event): _leave_assignment_context() else: _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.) if selected_dropzone_element < 0: @@ -248,14 +285,12 @@ func _enter_assignment_context(): currently_selected_card_for_assigning = area_dict["dropzone_content"][0] currently_selected_card_for_assigning.highlighted = true - # leaves the context for assigning postit via button controls func _leave_assignment_context(): currently_selected_node.highlighted = false active_context = ui_context.DROPZONE currently_selected_node = currently_selected_card_for_assigning - # handles everything to return a post it to the panels func _return_postit_to_panels(postit: Area2D): for panel in area_dict["post_it_panels"]: diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index 246cf8c..e426b24 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -46,15 +46,13 @@ var modulate_tween @export var voice_line: AudioStream = null @export var is_dragable: bool = false -var base_rotation = null -var base_scale = null +@onready var base_rotation = rotation +@onready var base_scale = scale var is_dragged = false func _ready() -> void: self.set_meta("type", "post-it") # set type information to find out if this node is a post-it - base_rotation = rotation - base_scale = scale $Content/Label.text = self.text $Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation)