2026-01-17 11:11:21 +00:00
|
|
|
class_name CardPicker
|
|
|
|
|
extends Playable
|
2023-05-25 08:39:39 +00:00
|
|
|
|
2023-06-29 22:54:34 +00:00
|
|
|
#fixme INI is probably redundant.
|
2023-05-25 08:39:39 +00:00
|
|
|
enum {
|
2024-09-15 09:30:31 +00:00
|
|
|
INI,
|
|
|
|
|
CARDS,
|
|
|
|
|
CARDS_SELECTED,
|
|
|
|
|
TRANSITION,
|
|
|
|
|
POSTS,
|
|
|
|
|
POSTS_SELECTED,
|
|
|
|
|
DONE
|
2023-05-25 08:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-11 22:53:23 +00:00
|
|
|
@export var current_scene_id : Scenes.id = Scenes.id.NONE
|
|
|
|
|
|
2026-01-19 10:49:31 +00:00
|
|
|
var _input_locked: bool:
|
|
|
|
|
get: return (selection_state != CARDS and selection_state != POSTS) or not visible
|
2026-01-11 22:53:23 +00:00
|
|
|
|
2026-01-11 20:33:37 +00:00
|
|
|
|
2025-12-13 12:31:31 +00:00
|
|
|
var selection_state := INI:
|
2024-09-15 09:30:31 +00:00
|
|
|
set(state):
|
2026-01-21 21:35:35 +00:00
|
|
|
print("Setting picker state to %s" % ["INI","CARDS","CARDS_SELECTED","TRANSITION","POSTS","POSTS_SELECTED","DONE"][state])
|
2024-09-15 09:30:31 +00:00
|
|
|
selection_state = state
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
if state == CARDS_SELECTED:
|
2025-12-13 12:31:31 +00:00
|
|
|
var tween: Tween = get_tree().create_tween()
|
2024-09-15 09:30:31 +00:00
|
|
|
tween.tween_property($thought_prompt, "modulate", Color(1, 1, 1, 0), 0.5)
|
|
|
|
|
elif state == DONE:
|
|
|
|
|
reset()
|
2023-05-25 08:39:39 +00:00
|
|
|
|
2024-02-11 23:24:13 +00:00
|
|
|
var anim_players:Array[AnimationPlayer] = []
|
2026-01-11 20:33:37 +00:00
|
|
|
|
2023-05-25 08:39:39 +00:00
|
|
|
var curr_selection_id: int = -1:
|
2024-09-15 09:30:31 +00:00
|
|
|
set(new_id):
|
|
|
|
|
if selection_state == CARDS or selection_state == POSTS:
|
2026-01-19 10:49:31 +00:00
|
|
|
# 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)
|
2024-09-15 09:30:31 +00:00
|
|
|
else:
|
|
|
|
|
curr_selection_id = new_id
|
2023-05-25 08:39:39 +00:00
|
|
|
|
2023-07-19 11:50:19 +00:00
|
|
|
var output:Array = []
|
|
|
|
|
var options:Array = []
|
2023-05-25 08:39:39 +00:00
|
|
|
|
2025-02-06 17:55:05 +00:00
|
|
|
signal cards_picked(cardnames: Array[String])
|
2023-07-03 21:06:07 +00:00
|
|
|
|
2026-01-19 10:49:31 +00:00
|
|
|
func play() -> void:
|
|
|
|
|
await pick_cards(Scenes.id.YOUTH_CHILDHOOD)
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2023-07-19 11:50:19 +00:00
|
|
|
func reset():
|
2025-05-16 11:08:35 +00:00
|
|
|
card_anim_skipped = false
|
2024-09-15 09:30:31 +00:00
|
|
|
output = []
|
|
|
|
|
options = []
|
|
|
|
|
anim_players = []
|
2025-12-13 12:31:31 +00:00
|
|
|
var card_controls: Array[Node] = $cards.get_children()
|
2024-09-15 09:30:31 +00:00
|
|
|
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")
|
2023-05-25 08:39:39 +00:00
|
|
|
|
2023-07-14 23:08:42 +00:00
|
|
|
func fill_card_slots(id: int):
|
2026-01-15 12:04:52 +00:00
|
|
|
var new_cards : Array[Card] = HardCards.get_cards_by_scene_id(id)
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
for i in range(new_cards.size()):
|
|
|
|
|
$cards.get_child(i).remove_child($cards.get_child(i).get_child(1))
|
2025-02-24 15:14:08 +00:00
|
|
|
var new_card:Card = new_cards[i]
|
2025-04-13 17:07:31 +00:00
|
|
|
$cards.get_child(i).add_child(new_card)
|
2026-01-19 14:52:26 +00:00
|
|
|
#new_card.owner = self
|
2025-02-24 15:14:08 +00:00
|
|
|
|
2026-01-19 10:49:31 +00:00
|
|
|
# No need to connect signals - Draggable base class handles this
|
2024-09-15 09:30:31 +00:00
|
|
|
options.append(new_card)
|
|
|
|
|
anim_players.append($cards.get_child(i).get_child(0))
|
2023-05-28 13:25:26 +00:00
|
|
|
|
|
|
|
|
func fill_post_slots():
|
2024-09-15 09:30:31 +00:00
|
|
|
var sticky_notes: Array[StickyNote] = []
|
2025-04-13 17:07:31 +00:00
|
|
|
for card: Card in output:
|
|
|
|
|
sticky_notes.append_array(HardCards.get_children_of(card.card_id))
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2025-02-24 15:14:08 +00:00
|
|
|
for note:StickyNote in sticky_notes:
|
|
|
|
|
note.current_handle = self
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
sticky_notes.shuffle()
|
|
|
|
|
options = []
|
|
|
|
|
for ancor in $sticky_notes.get_children():
|
|
|
|
|
ancor.remove_child(ancor.get_child(1))
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
for i in range(sticky_notes.size()):
|
|
|
|
|
options.append(sticky_notes[i])
|
|
|
|
|
$sticky_notes.get_child(i).add_child(options[i], false)
|
2026-01-19 14:52:26 +00:00
|
|
|
#options[i].owner = self # TODO: I think this is not necessary.
|
2025-05-07 17:52:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
var picked_player: AnimationPlayer
|
|
|
|
|
var random_player: AnimationPlayer
|
|
|
|
|
|
2025-05-16 11:08:35 +00:00
|
|
|
var card_anim_skipped:bool = false
|
2025-12-16 22:21:54 +00:00
|
|
|
|
2026-01-11 20:33:37 +00:00
|
|
|
func _input(event):
|
2026-01-19 10:49:31 +00:00
|
|
|
if _input_locked: return
|
|
|
|
|
|
|
|
|
|
# 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)
|
2026-01-11 20:33:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func pick(id: int) -> void:
|
2026-01-21 21:35:35 +00:00
|
|
|
print("%s picked card %s at id %d" % [name, options[id].text, id])
|
2024-09-15 09:30:31 +00:00
|
|
|
if id == -1:
|
|
|
|
|
curr_selection_id = 0
|
|
|
|
|
return
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
if selection_state == CARDS:
|
|
|
|
|
selection_state = CARDS_SELECTED
|
|
|
|
|
elif selection_state == POSTS:
|
|
|
|
|
selection_state = POSTS_SELECTED
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
anim_players[id].play("pick")
|
2025-05-07 17:52:57 +00:00
|
|
|
picked_player = anim_players[id]
|
2026-01-11 20:33:37 +00:00
|
|
|
var yield_to := anim_players[id].animation_finished
|
2026-01-15 12:04:52 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
output.append(options[id])
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
options.remove_at(id)
|
|
|
|
|
anim_players.remove_at(id)
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2025-05-07 17:52:57 +00:00
|
|
|
var parent_id:StringName
|
2024-09-15 09:30:31 +00:00
|
|
|
if selection_state == POSTS_SELECTED:
|
2025-05-07 17:52:57 +00:00
|
|
|
parent_id = output[-1].parent_id
|
2025-05-06 22:28:48 +00:00
|
|
|
var i:int = 0
|
|
|
|
|
for option:StickyNote in options:
|
|
|
|
|
if option.parent_id == parent_id:
|
2025-06-08 16:36:20 +00:00
|
|
|
options.erase(option)
|
2025-05-06 22:28:48 +00:00
|
|
|
anim_players[i].play("unshuffle")
|
|
|
|
|
anim_players.remove_at(i)
|
2026-01-21 21:35:35 +00:00
|
|
|
print("Removed StickyNote %s from options pool" % HardCards.get_obscure_name(option.name))
|
2025-05-06 22:28:48 +00:00
|
|
|
i += 1
|
2025-12-08 09:43:02 +00:00
|
|
|
|
|
|
|
|
var winning_id
|
2026-01-21 21:35:35 +00:00
|
|
|
print("Randomly selected card %s" % HardCards.get_obscure_name(options[1].name))
|
2025-06-04 11:58:53 +00:00
|
|
|
if not (current_scene_id == Scenes.id.YOUTH_JUI_JUTSU and selection_state == CARDS_SELECTED):
|
2024-09-15 09:30:31 +00:00
|
|
|
randomize()
|
2025-06-04 11:58:53 +00:00
|
|
|
winning_id = randi() % options.size() - ( 1 if selection_state == POSTS_SELECTED else 0)
|
2024-09-15 09:30:31 +00:00
|
|
|
else:
|
2025-05-12 17:05:13 +00:00
|
|
|
winning_id = 1 if id == 0 else 0
|
2025-06-04 11:58:53 +00:00
|
|
|
if Steamworks.has_initialized:
|
|
|
|
|
Steam.setAchievement("FIGHT_BACK")
|
|
|
|
|
Steam.storeStats()
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
output.append(options.pop_at(winning_id))
|
2025-05-07 17:52:57 +00:00
|
|
|
random_player = anim_players[winning_id]
|
2024-09-15 09:30:31 +00:00
|
|
|
anim_players.pop_at(winning_id).play("shuffle")
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
for anim in anim_players:
|
|
|
|
|
anim.play("unshuffle")
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2025-06-10 19:09:47 +00:00
|
|
|
await yield_to
|
2025-05-16 11:08:35 +00:00
|
|
|
if not card_anim_skipped: transition()
|
2023-05-25 08:39:39 +00:00
|
|
|
|
2024-02-11 23:24:13 +00:00
|
|
|
func transition():
|
2024-09-15 09:30:31 +00:00
|
|
|
if selection_state == CARDS_SELECTED:
|
|
|
|
|
selection_state = TRANSITION
|
|
|
|
|
options = []
|
|
|
|
|
anim_players = []
|
|
|
|
|
for control in $sticky_notes.get_children():
|
|
|
|
|
options.append(control.get_child(1))
|
|
|
|
|
anim_players.append(control.get_child(0))
|
|
|
|
|
control.get_child(0).play("post")
|
|
|
|
|
curr_selection_id = -1
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
fill_post_slots()
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
await anim_players[0].animation_finished
|
2026-01-15 12:04:52 +00:00
|
|
|
|
2025-04-13 17:07:31 +00:00
|
|
|
if selection_state != POSTS:
|
|
|
|
|
show_posts()
|
2026-01-12 18:24:26 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
elif selection_state == POSTS_SELECTED:
|
2025-04-13 17:07:31 +00:00
|
|
|
var out_str:Array[StringName] = []
|
2026-01-12 18:24:26 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
for card in output:
|
2026-01-16 20:46:26 +00:00
|
|
|
out_str.append(card.name if card.name != "" else "c_void")
|
2026-01-12 18:24:26 +00:00
|
|
|
|
2024-09-19 10:29:35 +00:00
|
|
|
cards_picked.emit(out_str)
|
2024-09-15 09:30:31 +00:00
|
|
|
selection_state = DONE
|
2023-06-29 22:54:34 +00:00
|
|
|
|
2024-02-11 23:24:13 +00:00
|
|
|
func show_posts():
|
2024-09-15 09:30:31 +00:00
|
|
|
for player:AnimationPlayer in anim_players:
|
2025-04-13 17:07:31 +00:00
|
|
|
player.play("RESET")
|
2025-06-03 21:12:22 +00:00
|
|
|
selection_state = POSTS
|
2025-12-08 09:43:02 +00:00
|
|
|
|
2024-02-11 23:24:13 +00:00
|
|
|
|
2026-01-19 10:49:31 +00:00
|
|
|
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)
|
2023-06-29 22:54:34 +00:00
|
|
|
|
2026-01-19 10:49:31 +00:00
|
|
|
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))
|
2023-07-14 23:08:42 +00:00
|
|
|
|
2025-05-10 13:59:52 +00:00
|
|
|
|
2026-01-16 21:40:28 +00:00
|
|
|
func pick_cards(id: Scenes.id):
|
2026-01-19 10:49:31 +00:00
|
|
|
prints("------------- PICKING CARDS -------------")
|
2025-05-10 13:59:52 +00:00
|
|
|
current_scene_id = id
|
2026-01-16 21:40:28 +00:00
|
|
|
hide()
|
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
|
fill_card_slots(id)
|
|
|
|
|
reset()
|
|
|
|
|
show()
|
|
|
|
|
selection_state = CARDS
|
|
|
|
|
|
|
|
|
|
if id == Scenes.id.YOUTH_DRAVEN:
|
|
|
|
|
$Meaning.play()
|
|
|
|
|
State.room.scene_player.play("intro")
|
|
|
|
|
|
|
|
|
|
await cards_picked
|
|
|
|
|
hide()
|