84 lines
2.0 KiB
GDScript
84 lines
2.0 KiB
GDScript
extends CanvasLayer
|
||
|
||
signal finished
|
||
|
||
@onready var paperback = %"封面"
|
||
@onready var paper = %"页面"
|
||
@onready var p1 = %"p1"
|
||
@onready var signature = %"陆小蝶"
|
||
|
||
var mode := 0:
|
||
set(value):
|
||
mode = value
|
||
match mode:
|
||
0:
|
||
open_paperback()
|
||
1:
|
||
open_p1()
|
||
2:
|
||
open_signature()
|
||
mode = clampi(mode, 0, 3)
|
||
if mode == 0:
|
||
%ButtonPaperback.visible = true
|
||
%ButtonLeft.visible = false
|
||
%ButtonRight.visible = false
|
||
else:
|
||
%ButtonPaperback.visible = false
|
||
%ButtonLeft.visible = true
|
||
%ButtonRight.visible = true
|
||
|
||
|
||
func _ready() -> void:
|
||
# 盖在书架上层,所以 +1
|
||
layer = GlobalConfig.CANVAS_LAYER_LITTLE_GAME + 1
|
||
mode = 0
|
||
%ButtonPaperback.pressed.connect(_on_button_pressed.bind(1))
|
||
# 从右到左翻页,所以右侧-1,左侧+1
|
||
%ButtonLeft.pressed.connect(_on_button_pressed.bind(1))
|
||
%ButtonRight.pressed.connect(_on_button_pressed.bind(-1))
|
||
signature.finished.connect(finished.emit)
|
||
visibility_changed.connect(_on_visibility_changed)
|
||
|
||
# # test 闪红效果
|
||
# await get_tree().create_timer(1.0).timeout
|
||
# var shading_layer = SceneManager.get_shading_layer()
|
||
# shading_layer.flash_vignette(Color(1.0, 0.0, 0.0))
|
||
|
||
func _on_visibility_changed() -> void:
|
||
if visible:
|
||
create_tween().tween_property($Control, "modulate:a", 1.0, 1.0).from(0.0)
|
||
|
||
|
||
var press_time := 0.0
|
||
|
||
func _on_button_pressed(direction: int) -> void:
|
||
# 0: paperback, 1: p1, 2: signature
|
||
# 第二页后不再翻页
|
||
if mode >= 2:
|
||
return
|
||
if Time.get_ticks_msec() - press_time < 1000:
|
||
return
|
||
press_time = Time.get_ticks_msec()
|
||
mode += direction
|
||
|
||
func open_paperback() -> void:
|
||
$SfxPage.play()
|
||
paperback.visible = true
|
||
paper.visible = false
|
||
p1.visible = false
|
||
signature.visible = false
|
||
|
||
func open_p1() -> void:
|
||
$SfxPage.play()
|
||
paperback.visible = false
|
||
paper.visible = true
|
||
p1.visible = true
|
||
signature.visible = false
|
||
|
||
func open_signature() -> void:
|
||
$SfxPage.play()
|
||
paperback.visible = false
|
||
paper.visible = true
|
||
p1.visible = false
|
||
signature.visible = true
|
||
signature.play() |