2024-10-06 09:31:47 +00:00
|
|
|
class_name CardPicker extends CenterContainer
|
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
|
|
|
}
|
|
|
|
|
|
2023-07-11 13:27:44 +00:00
|
|
|
var has_stage = false:
|
2024-09-15 09:30:31 +00:00
|
|
|
set(focus):
|
|
|
|
|
if not focus == has_stage:
|
|
|
|
|
if focus:
|
|
|
|
|
process_mode = Node.PROCESS_MODE_INHERIT
|
|
|
|
|
self.show()
|
|
|
|
|
self.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
|
|
|
else:
|
|
|
|
|
self.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
|
self.hide()
|
|
|
|
|
process_mode = Node.PROCESS_MODE_DISABLED
|
|
|
|
|
has_stage = focus
|
|
|
|
|
|
2023-07-18 12:48:28 +00:00
|
|
|
var _input_locked = true
|
|
|
|
|
var selection_state = INI:
|
2024-09-15 09:30:31 +00:00
|
|
|
set(state):
|
|
|
|
|
selection_state = state
|
|
|
|
|
_input_locked = !(state == CARDS or state == POSTS)
|
|
|
|
|
|
|
|
|
|
if state == CARDS_SELECTED:
|
|
|
|
|
var tween = get_tree().create_tween()
|
|
|
|
|
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] = []
|
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:
|
|
|
|
|
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
|
|
|
|
|
else:
|
|
|
|
|
curr_selection_id = new_id
|
|
|
|
|
|
|
|
|
|
print(curr_selection_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
|
|
|
|
2023-05-25 08:39:39 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready():
|
2025-02-06 17:55:05 +00:00
|
|
|
for id in range(Scenes.id.YOUTH_DRAEVEN, Scenes.id.YOUTH_JUI_JUTSU + 1):
|
|
|
|
|
Scenes.sign_up_for_sequence(pick_cards, id, 1)
|
|
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
reset()
|
|
|
|
|
|
2023-07-19 11:50:19 +00:00
|
|
|
func reset():
|
2024-09-15 09:30:31 +00:00
|
|
|
output = []
|
|
|
|
|
options = []
|
|
|
|
|
anim_players = []
|
|
|
|
|
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")
|
2023-05-25 08:39:39 +00:00
|
|
|
|
2023-07-14 23:08:42 +00:00
|
|
|
func fill_card_slots(id: int):
|
2025-04-13 17:07:31 +00:00
|
|
|
var new_cards = HardCards.get_cards_by_scene_id(id)
|
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)
|
2024-09-15 09:30:31 +00:00
|
|
|
new_card.owner = self
|
2025-02-24 15:14:08 +00:00
|
|
|
|
2024-09-15 09:30:31 +00:00
|
|
|
new_card.connect("mouse_entered", Callable(self, "get_highlight"))
|
|
|
|
|
options.append(new_card)
|
|
|
|
|
anim_players.append($cards.get_child(i).get_child(0))
|
|
|
|
|
reset()
|
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))
|
2024-09-15 09:30:31 +00:00
|
|
|
|
2025-02-24 15:14:08 +00:00
|
|
|
for note:StickyNote in sticky_notes:
|
|
|
|
|
note.current_handle = self
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
for i in range(sticky_notes.size()):
|
|
|
|
|
options.append(sticky_notes[i])
|
|
|
|
|
$sticky_notes.get_child(i).add_child(options[i], false)
|
|
|
|
|
options[i].owner = self
|
|
|
|
|
|
2023-07-19 11:50:19 +00:00
|
|
|
func _input(event):
|
2024-10-18 13:46:19 +00:00
|
|
|
#if event.is_action_pressed("ui_end"):
|
|
|
|
|
# fill_card_slots(3)
|
|
|
|
|
# selection_state = CARDS
|
2024-09-15 09:30:31 +00:00
|
|
|
|
|
|
|
|
if has_stage:
|
|
|
|
|
if !_input_locked:
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
if event.is_action_pressed("ui_accept"):
|
|
|
|
|
pick(curr_selection_id)
|
|
|
|
|
elif event.is_action_pressed("skip"):
|
|
|
|
|
##fixme: using skip causes a lot of invalid state
|
|
|
|
|
if selection_state == CARDS_SELECTED:
|
|
|
|
|
transition()
|
|
|
|
|
show_posts()
|
|
|
|
|
elif selection_state == POSTS_SELECTED:
|
|
|
|
|
transition()
|
|
|
|
|
elif selection_state == TRANSITION:
|
|
|
|
|
show_posts()
|
|
|
|
|
|
2023-05-25 08:39:39 +00:00
|
|
|
|
|
|
|
|
func pick(id: int):
|
2024-09-15 09:30:31 +00:00
|
|
|
print("PICK")
|
|
|
|
|
if id == -1:
|
|
|
|
|
curr_selection_id = 0
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if selection_state == CARDS:
|
|
|
|
|
selection_state = CARDS_SELECTED
|
|
|
|
|
elif selection_state == POSTS:
|
|
|
|
|
selection_state = POSTS_SELECTED
|
|
|
|
|
|
|
|
|
|
anim_players[id].play("pick")
|
|
|
|
|
var yield_to = anim_players[id].animation_finished
|
|
|
|
|
output.append(options[id])
|
|
|
|
|
|
|
|
|
|
options.remove_at(id)
|
|
|
|
|
anim_players.remove_at(id)
|
|
|
|
|
|
2025-05-06 22:28:48 +00:00
|
|
|
var parent_id = -1
|
2024-09-15 09:30:31 +00:00
|
|
|
if selection_state == POSTS_SELECTED:
|
2025-05-06 22:28:48 +00:00
|
|
|
parent_id = options.find(output[-1].parent_id)
|
|
|
|
|
var i:int = 0
|
|
|
|
|
for option:StickyNote in options:
|
|
|
|
|
if option.parent_id == parent_id:
|
|
|
|
|
options.erase(options)
|
|
|
|
|
anim_players[i].play("unshuffle")
|
|
|
|
|
anim_players.remove_at(i)
|
|
|
|
|
print("yeet sibling ", i)
|
|
|
|
|
i += 1
|
2024-09-15 09:30:31 +00:00
|
|
|
|
|
|
|
|
var winning_id
|
|
|
|
|
print(options[1].text)
|
2025-04-30 14:29:01 +00:00
|
|
|
if !(options[1].text == "void" and not id == 1):
|
2024-09-15 09:30:31 +00:00
|
|
|
randomize()
|
|
|
|
|
winning_id = randi() % options.size()
|
|
|
|
|
|
|
|
|
|
print("Winning ID ", id)
|
|
|
|
|
|
|
|
|
|
else:
|
2024-10-18 13:46:19 +00:00
|
|
|
winning_id = 2 if id == 0 else 0
|
2024-09-15 09:30:31 +00:00
|
|
|
Steam.setAchievement("FIGHT_BACK")
|
|
|
|
|
Steam.storeStats()
|
|
|
|
|
|
|
|
|
|
output.append(options.pop_at(winning_id))
|
|
|
|
|
anim_players.pop_at(winning_id).play("shuffle")
|
|
|
|
|
|
|
|
|
|
for anim in anim_players:
|
|
|
|
|
anim.play("unshuffle")
|
|
|
|
|
|
|
|
|
|
await yield_to
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
fill_post_slots()
|
|
|
|
|
|
|
|
|
|
await anim_players[0].animation_finished
|
2025-04-13 17:07:31 +00:00
|
|
|
if selection_state != POSTS:
|
|
|
|
|
show_posts()
|
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] = []
|
2024-09-15 09:30:31 +00:00
|
|
|
for card in output:
|
2025-04-28 13:46:50 +00:00
|
|
|
out_str.append(card.text if card.text != "" else "void")
|
2024-09-19 10:29:35 +00:00
|
|
|
cards_picked.emit(out_str)
|
2024-09-15 09:30:31 +00:00
|
|
|
selection_state = DONE
|
2025-02-06 17:55:05 +00:00
|
|
|
Scenes.end_current_sequence()
|
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
|
|
|
selection_state = POSTS
|
|
|
|
|
for player:AnimationPlayer in anim_players:
|
2025-04-13 17:07:31 +00:00
|
|
|
player.play("RESET")
|
2024-09-15 09:30:31 +00:00
|
|
|
|
2024-02-11 23:24:13 +00:00
|
|
|
|
2023-06-29 22:54:34 +00:00
|
|
|
func handle_hover(new_highlight):
|
2024-09-15 09:30:31 +00:00
|
|
|
if not _input_locked:
|
|
|
|
|
curr_selection_id = options.find(new_highlight)
|
2023-06-29 22:54:34 +00:00
|
|
|
|
2025-02-24 15:14:08 +00:00
|
|
|
func handle_mouse_button(button_event: InputEventMouseButton, new_selection: Node):
|
2024-09-15 09:30:31 +00:00
|
|
|
if not _input_locked:
|
|
|
|
|
if button_event.button_index == MOUSE_BUTTON_LEFT and button_event.pressed:
|
|
|
|
|
pick(options.find(new_selection))
|
2023-07-14 23:08:42 +00:00
|
|
|
|
2025-02-06 17:55:05 +00:00
|
|
|
func pick_cards(id: int, repeat: bool):
|
2024-09-15 09:30:31 +00:00
|
|
|
print(name, id, repeat)
|
|
|
|
|
if not repeat:
|
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
|
fill_card_slots(id)
|
2025-02-06 17:55:05 +00:00
|
|
|
#State.transition_stage_to(self, true)
|
2024-09-15 09:30:31 +00:00
|
|
|
selection_state = CARDS
|
2025-02-06 17:55:05 +00:00
|
|
|
else:
|
|
|
|
|
Scenes.end_current_sequence()
|
2023-07-14 23:08:42 +00:00
|
|
|
|
2023-07-19 11:50:19 +00:00
|
|
|
func play_scene(_id, _repeat):
|
2024-09-15 09:30:31 +00:00
|
|
|
pass
|