From b3b73433a22c0db1bf91705160a84cda919d7ad6 Mon Sep 17 00:00:00 2001 From: SchimmelSpreu83 Date: Sun, 21 Sep 2025 23:43:16 +0200 Subject: [PATCH] Added a loading text effect --- .../autoloads/scene_fader/scene_fader.gd | 19 ++++++-- .../autoloads/scene_fader/scene_fader.tscn | 22 ++++++++- .../ui/rich_effects/loading_text_effect.gd | 48 +++++++++++++++++++ .../rich_effects/loading_text_effect.gd.uid | 1 + 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 source/src/ui/rich_effects/loading_text_effect.gd create mode 100644 source/src/ui/rich_effects/loading_text_effect.gd.uid diff --git a/source/src/globals/autoloads/scene_fader/scene_fader.gd b/source/src/globals/autoloads/scene_fader/scene_fader.gd index 4eab9d6..cfcad48 100644 --- a/source/src/globals/autoloads/scene_fader/scene_fader.gd +++ b/source/src/globals/autoloads/scene_fader/scene_fader.gd @@ -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() diff --git a/source/src/globals/autoloads/scene_fader/scene_fader.tscn b/source/src/globals/autoloads/scene_fader/scene_fader.tscn index f624103..717a2f2 100644 --- a/source/src/globals/autoloads/scene_fader/scene_fader.tscn +++ b/source/src/globals/autoloads/scene_fader/scene_fader.tscn @@ -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 diff --git a/source/src/ui/rich_effects/loading_text_effect.gd b/source/src/ui/rich_effects/loading_text_effect.gd new file mode 100644 index 0000000..52ab9ee --- /dev/null +++ b/source/src/ui/rich_effects/loading_text_effect.gd @@ -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 diff --git a/source/src/ui/rich_effects/loading_text_effect.gd.uid b/source/src/ui/rich_effects/loading_text_effect.gd.uid new file mode 100644 index 0000000..def596b --- /dev/null +++ b/source/src/ui/rich_effects/loading_text_effect.gd.uid @@ -0,0 +1 @@ +uid://41co2svrlbkc