From a169add7d16afa4919c5596f4dda1446989165c0 Mon Sep 17 00:00:00 2001 From: Tiger Jove Date: Mon, 19 Jan 2026 11:49:31 +0100 Subject: [PATCH] fix: picker wasn't propagate up --- src/dev-util/debug_save.tres | 20 ++++- src/dev-util/hardcoded_cards.gd | 3 +- src/dev-util/room_template.gd | 1 + src/logic-scenes/card_burner/card_burner.gd | 26 ++++-- src/logic-scenes/card_picker/card_picker.gd | 90 +++++++------------ src/logic-scenes/card_picker/card_picker.tscn | 11 ++- src/logic-scenes/playable.gd | 2 + src/singletons/main/main.gd | 1 + src/singletons/main/main.tscn | 1 + ...cker_tests.tscn => card_picker_tests.tscn} | 0 10 files changed, 85 insertions(+), 70 deletions(-) rename src/tests/{picker_tests.tscn => card_picker_tests.tscn} (100%) diff --git a/src/dev-util/debug_save.tres b/src/dev-util/debug_save.tres index 764715f..7261447 100644 --- a/src/dev-util/debug_save.tres +++ b/src/dev-util/debug_save.tres @@ -1,10 +1,24 @@ -[gd_resource type="Resource" script_class="SaveGame" load_steps=2 format=3 uid="uid://bgplfqxa852wo"] +[gd_resource type="Resource" script_class="SaveGame" load_steps=2 format=3 uid="uid://vycsxg8kexkp"] [ext_resource type="Script" uid="uid://d06gpwuxmkxkt" path="res://dev-util/savegame.gd" id="1_jr18u"] [resource] script = ExtResource("1_jr18u") unique_save_name = "DEBUG" -mementos_complete = 1 -last_saved = 1756993270 +current_room = 1 +mementos_complete = 5 +board_positions = Dictionary[StringName, Vector2]({ +&"@Area2D@363": Vector2(458, 300), +&"@Area2D@364": Vector2(37.973812, 125.31358), +&"c_boy_stuff": Vector2(1345, 549), +&"c_comic_heroes": Vector2(848, 557), +&"c_teasing": Vector2(1047, 408), +&"p_effort": Vector2(133.33333, 110), +&"p_girls": Vector2(133.33333, 220), +&"p_my_own_good": Vector2(37.973812, 93.98519) +}) +player_position = Vector3(2.6459198, -0.012512123, -0.10338242) +player_yaw = -1.2473134 +player_pitch = -0.31394038 +last_saved = 1768818601 metadata/_custom_type_script = "uid://d06gpwuxmkxkt" diff --git a/src/dev-util/hardcoded_cards.gd b/src/dev-util/hardcoded_cards.gd index 9e12970..7603dcb 100644 --- a/src/dev-util/hardcoded_cards.gd +++ b/src/dev-util/hardcoded_cards.gd @@ -202,7 +202,8 @@ func get_cards_by_name_array(names: Array[StringName]) -> Dictionary[String, Arr else: if not card_name in sticky_ids: push_error("No card or sticky with name '%s'!" % card_name) - output["sticky_notes"].append(create_from_id(all_ids[card_name])) + else: + output["sticky_notes"].append(create_from_id(all_ids[card_name])) return output diff --git a/src/dev-util/room_template.gd b/src/dev-util/room_template.gd index 06a06c1..973c557 100644 --- a/src/dev-util/room_template.gd +++ b/src/dev-util/room_template.gd @@ -20,6 +20,7 @@ func _ready() -> void: save_game = State.save_game save_game.current_room = id + save_game.player_position = %PlayerController.global_position if not Main.normal_boot: start_room.call_deferred() diff --git a/src/logic-scenes/card_burner/card_burner.gd b/src/logic-scenes/card_burner/card_burner.gd index fa6571c..eb5c58c 100644 --- a/src/logic-scenes/card_burner/card_burner.gd +++ b/src/logic-scenes/card_burner/card_burner.gd @@ -10,6 +10,9 @@ signal card_burned var cards : Array[Card] = [] var _submitted := false +var _input_locked : bool: + get: return _submitted or not visible + func _ready(): print_debug("CardBurner.gd: %s._ready()" % self.name) super._ready() @@ -19,7 +22,7 @@ func vanish(): super.vanish() await Main.curtain.black() # Go straight to loading screen State.room.proceed.emit(Main.transition_room_path) - + ## Main play coroutine - simple linear flow for burning a card func play() -> void: @@ -62,13 +65,18 @@ func play() -> void: func handle_hover(card: Draggable) -> void: - if _submitted: return - if not card is Card: return - selection = cards.find(card) + if _input_locked: return + + if card.mouse_over: + selection = cards.find(card) + else: + card.highlighted = false cursor.gamepad_mode = false func handle_mouse_button(event: InputEventMouseButton, card: Card) -> void: + if _input_locked: return + if event.button_index == MOUSE_BUTTON_MASK_LEFT and event.is_pressed() and not event.is_echo(): _submit(card) @@ -82,7 +90,8 @@ func _submit(card : Card): func _input(event: InputEvent) -> void: - if _submitted: return + if _input_locked: return + if event.is_action_pressed("ui_up"): handle_direction_input(Vector2.UP) elif event.is_action_pressed("ui_down"): @@ -97,7 +106,7 @@ func _input(event: InputEvent) -> void: var focus_cards: bool = false: set(focus): - if _submitted: return + if _input_locked: return focus_cards = focus if focus_cards: cursor.visible = true @@ -109,7 +118,7 @@ var focus_cards: bool = false: var selection: int: set(value): - if _submitted: return + if _input_locked: return selection = value % len(cards) for i in range(len(cards)): var card := cards[i] @@ -121,7 +130,8 @@ var selection: int: func handle_direction_input(direction: Vector2) -> void: - if _submitted: return + if _input_locked: return + if not cursor.gamepad_mode: cursor.gamepad_mode = true focus_cards = focus_cards diff --git a/src/logic-scenes/card_picker/card_picker.gd b/src/logic-scenes/card_picker/card_picker.gd index 64d7863..7861bc9 100644 --- a/src/logic-scenes/card_picker/card_picker.gd +++ b/src/logic-scenes/card_picker/card_picker.gd @@ -14,14 +14,14 @@ enum { @export var current_scene_id : Scenes.id = Scenes.id.NONE +var _input_locked: bool: + get: return (selection_state != CARDS and selection_state != POSTS) or not visible -var _input_locked: bool = true var selection_state := INI: set(state): print_debug("Setting picker state to %s" % ["INI","CARDS","CARDS_SELECTED","TRANSITION","POSTS","POSTS_SELECTED","DONE"][state]) selection_state = state - _input_locked = !(state == CARDS or state == POSTS) if state == CARDS_SELECTED: var tween: Tween = get_tree().create_tween() @@ -34,13 +34,12 @@ var anim_players:Array[AnimationPlayer] = [] var curr_selection_id: int = -1: set(new_id): if selection_state == CARDS or selection_state == POSTS: - if not curr_selection_id == -1: options[curr_selection_id].highlighted = false - - if new_id > options.size() -1: curr_selection_id = 0 - elif new_id < 0: curr_selection_id = options.size() - 1 - else: curr_selection_id = new_id - - options[curr_selection_id].highlighted = true + # Wrap around + curr_selection_id = new_id % options.size() + + # Update all highlights + for i in range(options.size()): + options[i].highlighted = (i == curr_selection_id) else: curr_selection_id = new_id @@ -49,11 +48,8 @@ var options:Array = [] signal cards_picked(cardnames: Array[String]) -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - if current_scene_id != Scenes.id.NONE: - pick_cards(current_scene_id) - +func play() -> void: + await pick_cards(Scenes.id.YOUTH_CHILDHOOD) func reset(): card_anim_skipped = false @@ -76,7 +72,7 @@ func fill_card_slots(id: int): $cards.get_child(i).add_child(new_card) new_card.owner = self - new_card.connect("mouse_entered", Callable(self, "get_highlight")) + # No need to connect signals - Draggable base class handles this options.append(new_card) anim_players.append($cards.get_child(i).get_child(0)) @@ -102,47 +98,24 @@ func fill_post_slots(): var picked_player: AnimationPlayer var random_player: AnimationPlayer -var on_cooldown: bool = false var card_anim_skipped:bool = false func _input(event): - if not _input_locked: - if not on_cooldown: - # Navigation: keyboard arrows, gamepad D-pad, and analog stick - if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left") or event.is_action_pressed("ui_focus_next"): - curr_selection_id -= 1 - on_cooldown = true - get_tree().create_timer(0.15).timeout.connect(func(): on_cooldown = false, CONNECT_ONE_SHOT) - elif event.is_action_pressed("ui_down") or event.is_action_pressed("ui_right") or event.is_action_pressed("ui_focus_prev"): - curr_selection_id += 1 - on_cooldown = true - get_tree().create_timer(0.15).timeout.connect(func(): on_cooldown = false, CONNECT_ONE_SHOT) + if _input_locked: return - # Selection: Enter/Space on keyboard, A button (Joy 0) on gamepad, or left click - if event.is_action_pressed("ui_accept") or event.is_action_pressed("collect_memento_ui"): - pick(curr_selection_id) - elif event.is_action_pressed("skip"): - $Meaning.stop() - if selection_state == CARDS_SELECTED: - picked_player.play("skip_pick", .1) - random_player.play("skip_shuffle", .1) - for player in anim_players: - player.advance(10.0) - transition() - card_anim_skipped = true - show_posts() - elif selection_state == POSTS_SELECTED: - for player:AnimationPlayer in anim_players + [picked_player, random_player]: - player.play("ini") - # I do not know, why process_frame won't work here, but this is workaround seems to prevent the notes from flashing the next selection. - await(get_tree().create_timer(0.1).timeout) - transition() - elif selection_state == TRANSITION: - show_posts() + # Navigation + if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left"): + curr_selection_id -= 1 + elif event.is_action_pressed("ui_down") or event.is_action_pressed("ui_right"): + curr_selection_id += 1 + + # Selection + elif event.is_action_pressed("ui_accept"): + pick(curr_selection_id) func pick(id: int) -> void: - print_debug("%s picked card %s at id %d" % [name, options[id].text, id]) + print_debug("%s picked card %s at id %d" % [name, options[id].text, id]) if id == -1: curr_selection_id = 0 return @@ -227,17 +200,22 @@ func show_posts(): selection_state = POSTS -func handle_hover(new_highlight): - if not _input_locked: - curr_selection_id = options.find(new_highlight) +func handle_hover(draggable: Draggable) -> void: + if _input_locked: return + + draggable.highlighted = draggable.mouse_over + if draggable.mouse_over: + curr_selection_id = options.find(draggable) -func handle_mouse_button(button_event: InputEventMouseButton, new_selection: Node): - if not _input_locked: - if button_event.button_index == MOUSE_BUTTON_LEFT and button_event.pressed and not button_event.is_echo(): - pick(options.find(new_selection)) +func handle_mouse_button(event: InputEventMouseButton, draggable: Draggable) -> void: + if _input_locked: return + + if event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() and not event.is_echo(): + pick(options.find(draggable)) func pick_cards(id: Scenes.id): + prints("------------- PICKING CARDS -------------") current_scene_id = id hide() Input.mouse_mode = Input.MOUSE_MODE_VISIBLE diff --git a/src/logic-scenes/card_picker/card_picker.tscn b/src/logic-scenes/card_picker/card_picker.tscn index 96c5a61..6331ada 100644 --- a/src/logic-scenes/card_picker/card_picker.tscn +++ b/src/logic-scenes/card_picker/card_picker.tscn @@ -1741,11 +1741,9 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -mouse_filter = 2 script = ExtResource("1_pjntm") [node name="Control" type="Control" parent="."] -visible = false layout_mode = 2 [node name="label" type="Label" parent="Control"] @@ -1759,6 +1757,7 @@ horizontal_alignment = 1 [node name="cards" type="Panel" parent="."] layout_mode = 2 +mouse_filter = 2 [node name="card_1" type="Control" parent="cards"] anchors_preset = 0 @@ -1767,6 +1766,7 @@ offset_top = 25.0 offset_right = -317.0 offset_bottom = 25.0 rotation = -0.109599 +mouse_filter = 1 [node name="AnimationPlayer" type="AnimationPlayer" parent="cards/card_1"] libraries = { @@ -1777,6 +1777,7 @@ libraries = { [node name="card_2" type="Control" parent="cards"] anchors_preset = 0 +mouse_filter = 2 [node name="AnimationPlayer" type="AnimationPlayer" parent="cards/card_2"] libraries = { @@ -1802,11 +1803,13 @@ libraries = { [node name="sticky_notes" type="Panel" parent="."] layout_mode = 2 +mouse_filter = 2 [node name="sticky_note_1" type="Control" parent="sticky_notes"] anchors_preset = 0 offset_top = -150.0 offset_bottom = -150.0 +mouse_filter = 2 [node name="AnimationPlayer" type="AnimationPlayer" parent="sticky_notes/sticky_note_1"] root_node = NodePath(".") @@ -1821,6 +1824,7 @@ autoplay = "ini" anchors_preset = 0 offset_top = -50.0 offset_bottom = -50.0 +mouse_filter = 2 [node name="AnimationPlayer" type="AnimationPlayer" parent="sticky_notes/sticky_note_2"] root_node = NodePath(".") @@ -1835,6 +1839,7 @@ autoplay = "ini" anchors_preset = 0 offset_top = 50.0 offset_bottom = 50.0 +mouse_filter = 2 [node name="AnimationPlayer" type="AnimationPlayer" parent="sticky_notes/sticky_note_3"] root_node = NodePath(".") @@ -1849,6 +1854,7 @@ autoplay = "ini" anchors_preset = 0 offset_top = 150.0 offset_bottom = 150.0 +mouse_filter = 2 [node name="AnimationPlayer" type="AnimationPlayer" parent="sticky_notes/sticky_note_4"] root_node = NodePath(".") @@ -1861,6 +1867,7 @@ autoplay = "ini" [node name="thought_prompt" type="Control" parent="."] layout_mode = 2 +mouse_filter = 2 [node name="Label" type="Label" parent="thought_prompt"] layout_mode = 1 diff --git a/src/logic-scenes/playable.gd b/src/logic-scenes/playable.gd index da24df8..0c250e8 100644 --- a/src/logic-scenes/playable.gd +++ b/src/logic-scenes/playable.gd @@ -3,6 +3,8 @@ class_name Playable func _ready() -> void: hide() + if get_parent() == get_tree().root: + play.call_deferred() ## Awaitable that encapsulates the core interaction with this Playable func play() -> void: diff --git a/src/singletons/main/main.gd b/src/singletons/main/main.gd index b468af7..207e3b2 100644 --- a/src/singletons/main/main.gd +++ b/src/singletons/main/main.gd @@ -66,6 +66,7 @@ func _ready() -> void: else: print_debug("main.gd: direct boot (hiding menus and entering main loop)") app_state = AppState.PLAY + curtain.open() func start_game(save: SaveGame) -> void: diff --git a/src/singletons/main/main.tscn b/src/singletons/main/main.tscn index 186d4a8..d64d3a0 100644 --- a/src/singletons/main/main.tscn +++ b/src/singletons/main/main.tscn @@ -93,6 +93,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 script = ExtResource("1_rqkns") youth_room_path = "uid://b3b0gyvklqn50" transition_room_path = "uid://fgp3s28h7msy" diff --git a/src/tests/picker_tests.tscn b/src/tests/card_picker_tests.tscn similarity index 100% rename from src/tests/picker_tests.tscn rename to src/tests/card_picker_tests.tscn