Added a loading text effect

This commit is contained in:
SchimmelSpreu83 2025-09-21 23:43:16 +02:00
parent 2a60380258
commit b3b73433a2
4 changed files with 85 additions and 5 deletions

View File

@ -12,9 +12,11 @@ var is_loading: bool = false
@onready var color_rect: ColorRect = %ColorRect
@onready var loading_hint_animations: AnimationPlayer = %LoadingHintAnimations
@onready var loading_hint: TextureRect = %LoadingHint
@onready var loading_label: RichTextLabel = $LoadingLabel
func _ready() -> void:
loading_label.hide()
color_rect.hide()
color_rect.color.a = 0.0
@ -49,13 +51,11 @@ func fade_in() -> void:
is_fading = false
loading_hint_animations.play(_ANIM_LOADING)
loading_hint.show()
set_loading_hints_visible(true)
func fade_out() -> void:
loading_hint_animations.stop()
loading_hint.hide()
set_loading_hints_visible(false)
is_fading = true
@ -65,3 +65,14 @@ func fade_out() -> void:
color_rect.hide()
is_fading = false
func set_loading_hints_visible(value: bool) -> void:
loading_hint.visible = value
loading_label.visible = value
if value:
loading_label.set_text(loading_label.text) # Restart the effect.
loading_hint_animations.play(_ANIM_LOADING)
else:
loading_hint_animations.stop()

View File

@ -1,8 +1,14 @@
[gd_scene load_steps=7 format=3 uid="uid://dis4efdm5s2fc"]
[gd_scene load_steps=9 format=3 uid="uid://dis4efdm5s2fc"]
[ext_resource type="Script" uid="uid://cynllcoh2smgv" path="res://src/globals/autoloads/scene_fader/scene_fader.gd" id="1_7tt87"]
[ext_resource type="Script" uid="uid://d0k03wk1s7cw0" path="res://src/core/interactive_loader.gd" id="2_dwqb8"]
[ext_resource type="Texture2D" uid="uid://dhw8y2oqxvgwu" path="res://godot_icon.svg" id="3_dwqb8"]
[ext_resource type="Script" uid="uid://41co2svrlbkc" path="res://src/ui/rich_effects/loading_text_effect.gd" id="3_s8mqo"]
[sub_resource type="RichTextEffect" id="RichTextEffect_tvon4"]
resource_name = "RichTextLoading"
script = ExtResource("3_s8mqo")
metadata/_custom_type_script = "uid://41co2svrlbkc"
[sub_resource type="Animation" id="Animation_t3447"]
length = 0.001
@ -85,6 +91,20 @@ grow_vertical = 2
mouse_filter = 2
color = Color(0, 0, 0, 1)
[node name="LoadingLabel" type="RichTextLabel" parent="."]
anchors_preset = -1
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
bbcode_enabled = true
text = "[loading]Loading...[/loading]"
horizontal_alignment = 1
vertical_alignment = 1
custom_effects = [SubResource("RichTextEffect_tvon4")]
[node name="HintMargin" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0

View File

@ -0,0 +1,48 @@
@tool
class_name RichTextLoading
extends RichTextEffect
var bbcode: String = "loading"
func _init() -> void:
resource_name = "RichTextLoading"
func _process_custom_fx(char_fx: CharFXTransform) -> bool:
_process_big_wave(char_fx)
_process_small_wave(char_fx)
_process_fade(char_fx)
return true
func _process_big_wave(char_fx: CharFXTransform) -> void:
var freq: float = char_fx.env.get("freq", 1.0)
var height: float = char_fx.env.get("height", 25.0)
var char_range: float = char_fx.env.get("range", 0.15)
var curve: float = char_fx.env.get("curve", -13.0)
var time_offset := float(-char_fx.relative_index) * char_range
var sined_time: float = (sin((char_fx.elapsed_time + PI) * freq + time_offset) + 1.0) / 2.0
sined_time = ease(sined_time, curve)
var y_offset: float = sined_time * height
char_fx.offset += Vector2.DOWN * y_offset
func _process_small_wave(char_fx: CharFXTransform) -> void:
var freq: float = char_fx.env.get("freq", 4.0)
var height: float = char_fx.env.get("height", 12.5)
var char_range: float = char_fx.env.get("range", 0.5)
var curve: float = char_fx.env.get("curve", 6.5)
var time_offset := float(-char_fx.relative_index) * char_range
var sined_time: float = (sin((char_fx.elapsed_time + PI) * freq + time_offset) + 1.0) / 2.0
sined_time = ease(sined_time, curve)
var y_offset: float = sined_time * height * (1.0 - char_fx.offset.y / 25.0)
char_fx.offset += Vector2.UP * y_offset
func _process_fade(char_fx: CharFXTransform) -> void:
var alpha: float = 1.0 - char_fx.offset.y / 25.0
char_fx.color.a = alpha

View File

@ -0,0 +1 @@
uid://41co2svrlbkc