fixing up issues with internal state handling and animation referencing
This commit is contained in:
parent
bc38a177d5
commit
f507b9b890
|
|
@ -4,6 +4,7 @@ extends CenterContainer
|
|||
enum {
|
||||
INI,
|
||||
CARDS,
|
||||
CARDS_SELECTED,
|
||||
TRANSITION,
|
||||
POSTS,
|
||||
DONE
|
||||
|
|
@ -24,9 +25,11 @@ var has_stage = false:
|
|||
self.hide()
|
||||
has_stage = focus
|
||||
|
||||
|
||||
var selection_state = INI
|
||||
var input_locked = true
|
||||
var _input_locked = true
|
||||
var selection_state = INI:
|
||||
set(state):
|
||||
selection_state = state
|
||||
_input_locked = !(state == CARDS or state == POSTS)
|
||||
|
||||
var anim_players:Array
|
||||
var curr_selection_id: int = -1:
|
||||
|
|
@ -51,6 +54,8 @@ 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
|
||||
|
||||
var card_controls = $cards.get_children()
|
||||
for control in card_controls:
|
||||
options.append(control.get_child(1))
|
||||
|
|
@ -58,13 +63,12 @@ func _ready():
|
|||
|
||||
fill_card_slots(0)
|
||||
|
||||
input_locked = false
|
||||
|
||||
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
|
||||
|
||||
func fill_post_slots():
|
||||
var post_its: Array[PostIt] = []
|
||||
|
|
@ -74,9 +78,10 @@ func fill_post_slots():
|
|||
|
||||
for i in range(post_its.size()):
|
||||
options[i].replace_with(post_its[i])
|
||||
options[i].owner = self
|
||||
|
||||
func _unhandled_input(event):
|
||||
if has_stage and not input_locked:
|
||||
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"):
|
||||
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"):
|
||||
|
|
@ -91,7 +96,10 @@ func pick(id: int):
|
|||
curr_selection_id = 0
|
||||
return
|
||||
|
||||
input_locked = true
|
||||
if selection_state == CARDS:
|
||||
selection_state = CARDS_SELECTED
|
||||
elif selection_state == POSTS:
|
||||
selection_state = DONE
|
||||
|
||||
anim_players[id].play("pick")
|
||||
var yield_to = anim_players[id].animation_finished
|
||||
|
|
@ -123,7 +131,7 @@ func pick(id: int):
|
|||
|
||||
await yield_to
|
||||
|
||||
if selection_state == CARDS:
|
||||
if selection_state == CARDS_SELECTED:
|
||||
selection_state = TRANSITION
|
||||
options = []
|
||||
anim_players = []
|
||||
|
|
@ -137,8 +145,7 @@ func pick(id: int):
|
|||
|
||||
await anim_players[0].animation_finished
|
||||
selection_state = POSTS
|
||||
input_locked = false
|
||||
else:
|
||||
elif selection_state == DONE:
|
||||
var out_str:Array[String] = []
|
||||
for card in output:
|
||||
out_str.append(card.name)
|
||||
|
|
@ -146,15 +153,14 @@ func pick(id: int):
|
|||
State.leave_stage(self)
|
||||
|
||||
func handle_hover(new_highlight):
|
||||
if not input_locked:
|
||||
if not _input_locked:
|
||||
curr_selection_id = options.find(new_highlight)
|
||||
|
||||
func handle_mouse_button(new_selection: Node, button_event: InputEventMouseButton):
|
||||
if not input_locked:
|
||||
if not _input_locked:
|
||||
if button_event.button_index == MOUSE_BUTTON_LEFT and button_event.pressed:
|
||||
pick(options.find(new_selection))
|
||||
|
||||
|
||||
func scene_finished(id: int):
|
||||
fill_card_slots(id)
|
||||
State.transition_stage_to(self)
|
||||
|
|
|
|||
|
|
@ -1531,7 +1531,7 @@ offset_top = -150.0
|
|||
offset_bottom = -150.0
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_1"]
|
||||
root_node = NodePath("../post-it")
|
||||
root_node = NodePath(".")
|
||||
autoplay = "ini"
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_ga4dm")
|
||||
|
|
@ -1547,7 +1547,7 @@ offset_top = -50.0
|
|||
offset_bottom = -50.0
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_2"]
|
||||
root_node = NodePath("../post-it")
|
||||
root_node = NodePath(".")
|
||||
autoplay = "ini"
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_sxnmi")
|
||||
|
|
@ -1563,7 +1563,7 @@ offset_top = 50.0
|
|||
offset_bottom = 50.0
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_3"]
|
||||
root_node = NodePath("../post-it")
|
||||
root_node = NodePath(".")
|
||||
autoplay = "ini"
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_xs06v")
|
||||
|
|
@ -1579,7 +1579,7 @@ offset_top = 150.0
|
|||
offset_bottom = 150.0
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="postIts/postIt_4"]
|
||||
root_node = NodePath("../post-it")
|
||||
root_node = NodePath(".")
|
||||
autoplay = "ini"
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_tdl1s")
|
||||
|
|
|
|||
Loading…
Reference in New Issue