68 lines
1.7 KiB
GDScript
68 lines
1.7 KiB
GDScript
extends Panel
|
|
class_name Curtain
|
|
|
|
var _tween : Tween = null
|
|
|
|
func _ready() -> void:
|
|
print("curtain.gd: ready()")
|
|
visible = true
|
|
_check_boot()
|
|
|
|
func _check_boot():
|
|
self.visible = Main.normal_boot
|
|
if visible:
|
|
self.modulate = Color.BLACK
|
|
_tween_with_interrupt(Color.WHITE, 1.0, true)
|
|
|
|
## Conceals the Game Stage
|
|
func close() -> bool:
|
|
if visible and modulate == Color.WHITE:
|
|
return true
|
|
if await blackout():
|
|
return await _tween_with_interrupt(Color.WHITE, 0.7, true)
|
|
return false
|
|
|
|
## Conceals the Game Stage
|
|
func blackout() -> bool:
|
|
if visible and modulate == Color.BLACK:
|
|
return true
|
|
visible = true
|
|
print("curtain.gd: show()")
|
|
return await _tween_with_interrupt(Color.BLACK, 0.2, true)
|
|
|
|
## Makes the Game Stage Visible
|
|
func open() -> bool:
|
|
if not visible:
|
|
return true
|
|
print("curtain.gd: hide()")
|
|
if not visible: return true
|
|
var no_interrupt = await _tween_with_interrupt(Color.TRANSPARENT, 0.2, false)
|
|
if no_interrupt:
|
|
visible = false
|
|
return true
|
|
else:
|
|
return false
|
|
|
|
signal _tween_finished(successful: bool)
|
|
var _target_visibility: bool = false
|
|
## This allows multiple places to call the curtain close to each other with the only interference caused by mismatched visibility requirements.
|
|
func _tween_with_interrupt(to_color: Color, for_duration: float, target_visible: bool) -> bool:
|
|
if _tween:
|
|
if target_visible and _target_visibility:
|
|
return await _tween_finished
|
|
else:
|
|
_tween.kill()
|
|
|
|
_tween = create_tween()
|
|
_tween.tween_property(self, "modulate", to_color, for_duration)
|
|
while true:
|
|
if _tween.is_valid():
|
|
if not _tween.is_running():
|
|
_tween_finished.emit(true)
|
|
return true
|
|
await get_tree().process_frame
|
|
else:
|
|
_tween_finished.emit(false)
|
|
return false
|
|
return false
|