From a96e5630c8c8ab0c59c3a94366ca9bc5510a6624 Mon Sep 17 00:00:00 2001 From: betalars Date: Tue, 1 Aug 2023 10:59:24 +0200 Subject: [PATCH] updating card handling --- src/dev-util/devs_board.gd | 40 +++++++ src/logic-scenes/board/card-board.gd | 102 ++++++------------ src/logic-scenes/board/card.gd | 5 +- .../board/empty_postIt_panel.tscn | 9 ++ src/logic-scenes/board/physics-board.tscn | 13 +-- src/logic-scenes/card_picker/card_picker.gd | 60 ++++++----- .../collectable/collectable_ui.gd | 3 - 7 files changed, 127 insertions(+), 105 deletions(-) create mode 100644 src/dev-util/devs_board.gd create mode 100644 src/logic-scenes/board/empty_postIt_panel.tscn diff --git a/src/dev-util/devs_board.gd b/src/dev-util/devs_board.gd new file mode 100644 index 0000000..b1f00f0 --- /dev/null +++ b/src/dev-util/devs_board.gd @@ -0,0 +1,40 @@ +extends Control + +func get_cards_by_scene_id(id: int) -> Array: + var output:Array + + var scene = get_child(id) + + for i in range(scene.get_child_count()): + output.append(scene.get_child(i)) + for post in output[i].get_children(): + if post is PostIt: + output[i].remove_child(post) + + for card in output: + card.transform = Transform3D() + for postIt in card.own_postits: + postIt.transform = Transform3D() + + return output + +func get_cards_by_name_array(names: Array) -> Dictionary: + var output:Dictionary = { + "cards": [], + "postIts": [] + } + + for scene in get_children(): + for card in scene.get_children(): + for postIt in card.get_children(): + if names.has(postIt.name): + postIt.transform = Transform3D() + output['postIts'].append(postIt) + + if names.has(card.name): + card.transform = Transform3D() + output['cards'].append(card) + for child in card.get_children(): + if child is PostIt: + card.remove_child(child) + return output diff --git a/src/logic-scenes/board/card-board.gd b/src/logic-scenes/board/card-board.gd index 54a4ab9..91eb564 100644 --- a/src/logic-scenes/board/card-board.gd +++ b/src/logic-scenes/board/card-board.gd @@ -13,6 +13,7 @@ var has_stage = false: if focus: has_stage = true self.mouse_filter = Control.MOUSE_FILTER_PASS + get_tree().call_group("interactables", "collapse") else: has_stage = false self.mouse_filter = Control.MOUSE_FILTER_IGNORE @@ -25,9 +26,11 @@ var has_stage = false: visible = has_stage @onready var dropzone = $HBoxContainer/dropzone +var dropzone_size: Vector2 +@export var dropzone_padding = 100 @onready var postit_container = $HBoxContainer/ScrollContainer/VBoxContainer @onready var board_of_devs = $"board of devs" -@onready var base_postit_panel = $HBoxContainer/ScrollContainer/VBoxContainer/Panel +var base_postit_panel: Panel @onready var active_context = ui_context.DROPZONE # 0 = dropzone, 1 = post it list @onready var instructions = $instructions_panel/HBoxContainer/cards_remaining @@ -59,12 +62,15 @@ signal board_completed # Called when the node enters the scene tree for the first time. func _ready(): + base_postit_panel = $HBoxContainer/ScrollContainer/VBoxContainer/Panel + postit_container.remove_child(base_postit_panel) - #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"] + dropzone_size = get_viewport_rect().size - Vector2(dropzone_padding + base_postit_panel.custom_minimum_size.x, dropzone_padding) + + if get_parent() == get_tree().root: + populate_board(["c_void", 'c_joy', "p_wet", "p_thomas"]) + populate_board(["c_fighting", 'c_hit', "p_girly", "p_vent"]) - #populate_board(test_arr) - #reorder_areas("dropzone_content") active_context = ui_context.DROPZONE has_stage = has_stage @@ -81,63 +87,31 @@ func _process(delta): # Will be used later to spawn Cards and Post-Its and remember them in the dictionary func populate_board(card_names: Array): - mementos_collected += 1 - cache.append_array(card_names) - if mementos_collected < 4: return - else: card_names = cache + var all_new:Dictionary = board_of_devs.get_cards_by_name_array(card_names) - var all_cards = Array() - var all_postits = Array() + var new_cards:Array = all_new["cards"] + var new_postits:Array = all_new["postIts"] - # to remember panel positions - area_dict["post_it_panels"] = [base_postit_panel] - - # check how many post-it panels we need - var amount = -1 # starting with -1 to compensate for the base panel - for card_name in card_names: - if "p_" in card_name: - amount += 1 - while amount > 0: # creating panels up to the number of post-its + # spawning the cards and adding them to the dictionary + for new_card in all_new["cards"]: + 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) + 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"].push_back(new_panel) - amount -= 1 - - # 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 - 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) - area_dict["cards"].push_back(new_card) - #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() - 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 + 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) + 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 @@ -145,15 +119,6 @@ func populate_board(card_names: Array): reorder_areas("cards") reorder_areas("post_its_in_list") - -# 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: if (dropzone.size.x < to_check.global_position.x or dropzone.size.y < to_check.global_position.y): @@ -241,8 +206,7 @@ func attach_postit_to_card(postit: Area2D, card: Area2D, update_dict = false): if not fluff.has_postit_attached(): return emit_signal("board_completed") - - + # Mark area that was hovered over as currently selected func handle_hover(to_handle: Area2D): if to_handle != currently_selected_node: @@ -392,14 +356,14 @@ func _leave_assignment_context(): # handles everything to return a post it to the panels func _return_postit_to_panels(post_it: Area2D): for panel in area_dict["post_it_panels"]: + print(area_dict["post_it_panels"]) if panel.get_child_count() == 1: area_dict["dropzone_content"].erase(post_it) post_it.on_board = false area_dict["post_its_in_list"].push_back(post_it) - post_it.tween_transform_to(panel.get_child(0).position) - post_it.rotation = post_it.base_rotation - post_it.scale = post_it.base_scale + #post_it.tween_transform_to(panel.get_child(0).position) post_it.reparent(panel) + post_it.transform = panel.get_child(0).transform post_it.set_owner(self) reorder_areas("dropzone_content") reorder_areas("post_its_in_list") diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index 8910b54..1ca9570 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -96,12 +96,15 @@ func _process(delta: float) -> void: if area is Card or area is CardCollider: if area is CardCollider: position += area.direction * delta - elif not area.highlighted or self.highlighted: + elif not (area.highlighted or self.highlighted) and area.is_dragable: var diff:Vector2 = position - area.position position -= diff.normalized() * ((diff.length()-diameter)/diameter) * bounce_speed * (delta/(1.0/60)) _move_card() +func get_text() -> String: + return $Label.text + func _handle_wiggle(delta): wiggle_pos += delta * wiggle_speed * wiggle_intensity diff --git a/src/logic-scenes/board/empty_postIt_panel.tscn b/src/logic-scenes/board/empty_postIt_panel.tscn new file mode 100644 index 0000000..cb47962 --- /dev/null +++ b/src/logic-scenes/board/empty_postIt_panel.tscn @@ -0,0 +1,9 @@ +[gd_scene format=3 uid="uid://chwf61qpn2sqw"] + +[node name="Panel" type="Panel"] +self_modulate = Color(1, 1, 1, 0) +custom_minimum_size = Vector2(400, 120) +mouse_filter = 1 + +[node name="post-it_anchor1" type="Node2D" parent="."] +position = Vector2(105, 57) diff --git a/src/logic-scenes/board/physics-board.tscn b/src/logic-scenes/board/physics-board.tscn index ed617c1..6935433 100644 --- a/src/logic-scenes/board/physics-board.tscn +++ b/src/logic-scenes/board/physics-board.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=10 format=3 uid="uid://bnskiyx1sksww"] +[gd_scene load_steps=11 format=3 uid="uid://bnskiyx1sksww"] [ext_resource type="Texture2D" uid="uid://bi3xqdknw5tpe" path="res://logic-scenes/board/board-texture/Cork002_2K_Color.png" id="1_8brxc"] [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://dy5rd437h5hsw" path="res://logic-scenes/board/card.tscn" id="3_mg053"] [ext_resource type="PackedScene" uid="uid://bvowj4l8dtceu" path="res://dev-util/board of devs.tscn" id="4_sskx2"] +[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"] @@ -61,14 +62,8 @@ horizontal_scroll_mode = 0 [node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/ScrollContainer"] layout_mode = 2 -[node name="Panel" type="Panel" parent="HBoxContainer/ScrollContainer/VBoxContainer"] -self_modulate = Color(1, 1, 1, 0) -custom_minimum_size = Vector2(400, 120) +[node name="Panel" parent="HBoxContainer/ScrollContainer/VBoxContainer" instance=ExtResource("5_dr0qs")] layout_mode = 2 -mouse_filter = 1 - -[node name="post-it_anchor1" type="Node2D" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel"] -position = Vector2(105, 57) [node name="board of devs" parent="." instance=ExtResource("4_sskx2")] process_mode = 4 @@ -133,9 +128,11 @@ shape = SubResource("RectangleShape2D_ivo5o") layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 0 +mouse_filter = 2 [node name="HBoxContainer" type="HBoxContainer" parent="instructions_panel"] layout_mode = 2 +mouse_filter = 2 [node name="VSeparator2" type="VSeparator" parent="instructions_panel/HBoxContainer"] custom_minimum_size = Vector2(15, 0) diff --git a/src/logic-scenes/card_picker/card_picker.gd b/src/logic-scenes/card_picker/card_picker.gd index b17e170..aadca15 100644 --- a/src/logic-scenes/card_picker/card_picker.gd +++ b/src/logic-scenes/card_picker/card_picker.gd @@ -11,19 +11,19 @@ enum { DONE } -@onready var debug_board:Control = $"board of devs" +@onready var source_board:Control = $"board of devs" var has_stage = false: set(focus): if not focus == has_stage: if focus: - if selection_state == INI or CARDS: - for player in anim_players: player.play("reveal") + process_mode = Node.PROCESS_MODE_INHERIT self.show() self.mouse_filter = Control.MOUSE_FILTER_IGNORE else: self.mouse_filter = Control.MOUSE_FILTER_STOP self.hide() + process_mode = Node.PROCESS_MODE_DISABLED has_stage = focus var _input_locked = true @@ -58,40 +58,51 @@ signal cards_picked(Array) # Called when the node enters the scene tree for the first time. func _ready(): - if get_parent() == get_tree().root: selection_state = CARDS - reset() func reset(): output = [] options = [] anim_players = [] - curr_selection_id = -1 var card_controls = $cards.get_children() for control in card_controls: options.append(control.get_child(1)) anim_players.append(control.get_child(0)) + curr_selection_id = 0 + for player in anim_players: player.play("reveal") func fill_card_slots(id: int): - for i in range($cards.get_child_count()): - var card:Card = $cards.get_child(i).get_child(1) - card.replace_with(debug_board.get_child(id).get_child(i) as Card) - card.connect("mouse_entered", Callable(self, "get_highlight")) - card.owner = self + var new_cards = source_board.get_cards_by_scene_id(id) + + for i in range(new_cards.size()): + $cards.get_child(i).remove_child($cards.get_child(i).get_child(1)) + var new_card = new_cards[i] + new_card.reparent($cards.get_child(i), false) + new_card.owner = self + new_card.connect("mouse_entered", Callable(self, "get_highlight")) + options.append(new_card) + anim_players.append($cards.get_child(i).get_child(0)) + reset() func fill_post_slots(): var post_its: Array[PostIt] = [] for card in output: post_its.append_array(card.own_postits) - print(card.own_postits) + + post_its.shuffle() + options = [] + for ancor in $postIts.get_children(): + ancor.remove_child(ancor.get_child(1)) for i in range(post_its.size()): - options[i].replace_with(post_its[i]) + options.append(post_its[i]) + $postIts.get_child(i).add_child(options[i], false) options[i].owner = self func _input(event): if event.is_action_pressed("ui_end"): - scene_finished(1, false) + fill_card_slots(3) + selection_state = CARDS if has_stage and not _input_locked: if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left") or event.is_action_pressed("ui_focus_next"): @@ -102,6 +113,7 @@ func _input(event): pick(curr_selection_id) func pick(id: int): + print("PICK") if id == -1: curr_selection_id = 0 return @@ -115,25 +127,25 @@ func pick(id: int): var yield_to = anim_players[id].animation_finished output.append(options[id]) - var sibling_id = -1 - if selection_state == POSTS: - - sibling_id = options.find(options[id].sibling) - - print("yeet sibling ", sibling_id) - options.remove_at(id) anim_players.remove_at(id) + var sibling_id = -1 + if selection_state == POSTS_SELECTED: + sibling_id = options.find(output.back().sibling) + options.remove_at(sibling_id) + anim_players[sibling_id].play("unshuffle") + anim_players.remove_at(sibling_id) + print("yeet sibling ", sibling_id) + var winning_id - if options[1].text == "" and not id == 1: + print(options[1].text) + if !(options[1].text == "" and not id == 1): randomize() winning_id = randi() % options.size() print("Winning ID ", id) - if winning_id == sibling_id: - winning_id = (winning_id + 1) % options.size() elif options[0].text == "": winning_id = 0 else: diff --git a/src/logic-scenes/collectable/collectable_ui.gd b/src/logic-scenes/collectable/collectable_ui.gd index 7529a82..973cc85 100644 --- a/src/logic-scenes/collectable/collectable_ui.gd +++ b/src/logic-scenes/collectable/collectable_ui.gd @@ -133,9 +133,6 @@ func _on_pick_button_pressed(): collected = true else: emit_signal("open_board") - - -func _on_pick_button_released(): hide()