142 lines
4.2 KiB
GDScript
142 lines
4.2 KiB
GDScript
extends CanvasLayer
|
|
|
|
@warning_ignore("unused_signal")
|
|
signal exit(arg)
|
|
|
|
@onready var draggable_spoon = %"Draggable勺" as Draggable2D
|
|
@onready var hover_meat = %"Hover肉" as HoverLightClickArea
|
|
@onready var hover_froth_arr: Array[HoverLightClickArea] = [%"Hover浮沫1", %"Hover浮沫2", %"Hover浮沫3", %"Hover浮沫4", %"Hover浮沫5", %"Hover浮沫6"]
|
|
var appeared_froth := [false, false, false, false, false, false]
|
|
var cleared_froth := [false, false, false, false, false, false]
|
|
var holding_spoon := false
|
|
var meat_has_put := false
|
|
var ready_to_take_meat := false
|
|
|
|
func _ready() -> void:
|
|
layer = GlobalConfig.CANVAS_LAYER_LITTLE_GAME
|
|
for h in hover_froth_arr:
|
|
h.freezing = true
|
|
h.modulate.a = 0.0
|
|
h.interacted.connect(_on_forth_interacted.bind(h))
|
|
draggable_spoon.picked.connect(_on_spoon_picked)
|
|
draggable_spoon.dropped.connect(_on_spoon_dropped)
|
|
|
|
# 提示
|
|
await Util.wait(0.5)
|
|
SceneManager.pop_center_notification("ui_center_notify_c04放肉煮肉")
|
|
|
|
|
|
func _on_spoon_picked(_node) -> void:
|
|
holding_spoon = true
|
|
# 允许清理泡沫
|
|
for i in len(appeared_froth):
|
|
if appeared_froth[i] and not cleared_froth[i]:
|
|
var h = hover_froth_arr[i]
|
|
h.freezing = false
|
|
|
|
|
|
func _on_spoon_dropped(_node) -> void:
|
|
# 不可以放下
|
|
draggable_spoon.force_hold()
|
|
if ready_to_take_meat:
|
|
if hover_meat.is_focused():
|
|
hover_meat.freezing = true
|
|
# 增加肉的 z
|
|
hover_meat.z_index += 1
|
|
wave_spoon()
|
|
var tween = create_tween()
|
|
tween.tween_property(draggable_spoon, "modulate:a", 0.0, 2.0)
|
|
await tween.finished
|
|
draggable_spoon.hide()
|
|
# 取肉
|
|
SceneManager.disable_prop_item("prop_新鲜的肉")
|
|
SceneManager.enable_prop_item("prop_煮熟的肉")
|
|
EventManager.set_stage("c04_stew_meat", 1)
|
|
hover_meat.hide()
|
|
exit.emit(true)
|
|
else:
|
|
for h in hover_froth_arr:
|
|
if h.is_focused():
|
|
var id = hover_froth_arr.find(h)
|
|
if appeared_froth[id] and not cleared_froth[id]:
|
|
_on_forth_interacted(h)
|
|
|
|
|
|
func _on_forth_interacted(h: HoverLightClickArea) -> void:
|
|
# 去除浮沫
|
|
h.freezing = true
|
|
cleared_froth[hover_froth_arr.find(h)] = true
|
|
var tween = create_tween()
|
|
tween.tween_property(h, "modulate:a", 0.0, 3.0)
|
|
wave_spoon(h)
|
|
# 检查是否全部清除
|
|
var all_cleared = true
|
|
for c in cleared_froth:
|
|
if not c:
|
|
all_cleared = false
|
|
break
|
|
if all_cleared:
|
|
_on_all_froth_cleared()
|
|
|
|
|
|
func wave_spoon(forth = null) -> void:
|
|
draggable_spoon.freezing = true
|
|
# weave spoon
|
|
var tween = create_tween()
|
|
tween.tween_property(draggable_spoon, "rotation", 0.3, 0.5)
|
|
tween.parallel().tween_property(draggable_spoon, "position", Vector2(5.0, 25.0), 0.5).as_relative()
|
|
if forth:
|
|
# 增加 froth z
|
|
tween.tween_callback(func(): forth.z_index += 1)
|
|
tween.tween_property(draggable_spoon, "rotation", -0.2, 0.5)
|
|
tween.parallel().tween_property(draggable_spoon, "position", Vector2(-5.0, -20.0), 0.5).as_relative()
|
|
tween.tween_property(draggable_spoon, "rotation", 0.3, 0.5)
|
|
tween.parallel().tween_property(draggable_spoon, "position", Vector2(0.0, -5.0), 0.5).as_relative()
|
|
await tween.finished
|
|
draggable_spoon.freezing = false
|
|
|
|
|
|
func _on_all_froth_cleared() -> void:
|
|
await Util.wait(3.0)
|
|
hover_meat.freezing = false
|
|
ready_to_take_meat = true
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("interact"):
|
|
get_viewport().set_input_as_handled()
|
|
if not meat_has_put:
|
|
if SceneManager.get_current_prop() == "prop_新鲜的肉":
|
|
_on_put_meat()
|
|
else:
|
|
SceneManager.get_prop_hud().on_toggle_invalid_prop()
|
|
elif event.is_action_pressed("cancel"):
|
|
get_viewport().set_input_as_handled()
|
|
# 恢复道具
|
|
SceneManager.reset_temp_disabled_props()
|
|
|
|
|
|
func _on_put_meat() -> void:
|
|
meat_has_put = true
|
|
$"AnimationPlayer".play("meat_floating")
|
|
# 暂时禁用
|
|
SceneManager.disable_prop_item_temp("prop_新鲜的肉")
|
|
hover_meat.show()
|
|
# 煮一会
|
|
SceneManager.pop_debug_dialog_info("音效", "放入鲜肉煮肉")
|
|
# 生肉缓慢消失
|
|
create_tween().tween_property(%"生肉", "modulate:a", 0.0, 8.0)
|
|
await Util.wait(3.0)
|
|
# 允许用勺子
|
|
draggable_spoon.freezing = false
|
|
# 浮末逐个出现
|
|
var tween
|
|
for i in [0,3,2,4,1,5]:
|
|
tween = create_tween()
|
|
var h = hover_froth_arr[i]
|
|
tween.tween_property(h, "modulate:a", 1.0, 2.0)
|
|
await tween.finished
|
|
appeared_froth[i] = true
|
|
if holding_spoon:
|
|
h.freezing = false
|