add new transaction and add splash screen
This commit is contained in:
@@ -4,41 +4,85 @@ extends CanvasLayer
|
||||
@onready var color_rect = $ColorRect
|
||||
@onready var loading_screen = $LoadingScreen
|
||||
@export var transition_duration: float = 1
|
||||
|
||||
const SHADER_PATH := "res://core/transition.gdshader"
|
||||
|
||||
func _ready() -> void:
|
||||
color_rect.color.a = 0.0
|
||||
color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
loading_screen.hide()
|
||||
_build_material()
|
||||
_update_resolution()
|
||||
get_viewport().size_changed.connect(_update_resolution)
|
||||
_set_factor(0.0)
|
||||
color_rect.visible = false
|
||||
|
||||
func change_scene(scene_enum: SceneConfig.SceneName) -> void:
|
||||
func _build_material() -> void:
|
||||
var mat := ShaderMaterial.new()
|
||||
mat.shader = load(SHADER_PATH)
|
||||
|
||||
#directional gradient: botto-left-> black; top-right -> white
|
||||
var g := Gradient.new()
|
||||
g.set_color(0, Color.BLACK)
|
||||
g.set_color(1, Color.WHITE)
|
||||
var grad_tex := GradientTexture2D.new()
|
||||
grad_tex.gradient = g
|
||||
grad_tex.fill = GradientTexture2D.FILL_LINEAR
|
||||
grad_tex.fill_from = Vector2(0.0, 1.0) # bottom-left
|
||||
grad_tex.fill_to = Vector2(1.0, 0.0) # top-right
|
||||
grad_tex.width = 256
|
||||
grad_tex.height = 256
|
||||
|
||||
#shape: sphere (white at the center, black around)
|
||||
var sg := Gradient.new()
|
||||
sg.set_color(0, Color.WHITE)
|
||||
sg.set_color(1, Color.BLACK)
|
||||
var shape_tex := GradientTexture2D.new()
|
||||
shape_tex.gradient = sg
|
||||
shape_tex.fill = GradientTexture2D.FILL_RADIAL
|
||||
shape_tex.fill_from = Vector2(0.5, 0.5) # center
|
||||
shape_tex.fill_to = Vector2(0.5, 0.0) # ray
|
||||
shape_tex.width = 64
|
||||
shape_tex.height = 64
|
||||
|
||||
mat.set_shader_parameter("base_color", Color.BLACK)
|
||||
mat.set_shader_parameter("gradient_texture", grad_tex)
|
||||
mat.set_shader_parameter("gradient_fixed", false)
|
||||
mat.set_shader_parameter("shape_texture", shape_tex)
|
||||
mat.set_shader_parameter("shape_tiling", 16.0)
|
||||
mat.set_shader_parameter("shape_rotation", 0.0)
|
||||
mat.set_shader_parameter("shape_scroll", Vector2.ZERO)
|
||||
mat.set_shader_parameter("shape_feathering", 0.0)
|
||||
mat.set_shader_parameter("shape_treshold", 1.15) # >1 = full at the end of the transation
|
||||
mat.set_shader_parameter("width", 0.5)
|
||||
|
||||
color_rect.material = mat
|
||||
|
||||
func _update_resolution() -> void:
|
||||
var s := get_viewport().get_visible_rect().size
|
||||
color_rect.material.set_shader_parameter("node_resolution", s)
|
||||
|
||||
func _set_factor(v: float) -> void:
|
||||
color_rect.material.set_shader_parameter("factor", v)
|
||||
|
||||
func cover(duration := 0.5) -> void:
|
||||
color_rect.visible = true
|
||||
var t := create_tween()
|
||||
t.tween_method(_set_factor, 0.0, 1.0, duration)
|
||||
await t.finished
|
||||
|
||||
func reveal(duration := 0.5) -> void:
|
||||
var t := create_tween()
|
||||
t.tween_method(_set_factor, 1.0, 0.0, duration)
|
||||
await t.finished
|
||||
color_rect.visible = false
|
||||
|
||||
func change_scene(scene_enum: SceneConfig.SceneName) -> void:
|
||||
if not config or not config.scenes.has(scene_enum):
|
||||
return
|
||||
|
||||
var target_scene: PackedScene = config.scenes[scene_enum]
|
||||
|
||||
color_rect.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
|
||||
var tween_in = create_tween()
|
||||
tween_in.tween_property(color_rect, "color:a", 1.0, transition_duration)
|
||||
await tween_in.finished
|
||||
|
||||
loading_screen.show()
|
||||
await get_tree().process_frame
|
||||
|
||||
await cover(transition_duration)
|
||||
get_tree().change_scene_to_packed(target_scene)
|
||||
|
||||
loading_screen.hide()
|
||||
|
||||
var tween_out = create_tween()
|
||||
tween_out.tween_property(color_rect, "color:a", 0.0, transition_duration)
|
||||
await tween_out.finished
|
||||
await reveal(transition_duration)
|
||||
|
||||
color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
||||
func quit_game() -> void:
|
||||
color_rect.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
var tween = create_tween()
|
||||
tween.tween_property(color_rect, "color:a", 1.0, transition_duration)
|
||||
await tween.finished
|
||||
get_tree().quit()
|
||||
|
||||
Reference in New Issue
Block a user