Files
whale-town/scripts/LoadingIndicator.gd
2025-12-05 19:00:14 +08:00

114 lines
3.2 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends Control
class_name LoadingIndicator
## 加载状态指示器
## 显示加载动画和状态文本
# UI 元素
@onready var loading_panel: Panel = $LoadingPanel
@onready var loading_label: Label = $LoadingPanel/VBoxContainer/LoadingLabel
@onready var spinner: ColorRect = $LoadingPanel/VBoxContainer/Spinner
@onready var progress_bar: ProgressBar = $LoadingPanel/VBoxContainer/ProgressBar
# 加载状态
var is_loading: bool = false
var rotation_speed: float = 3.0 # 旋转速度(弧度/秒)
func _ready():
"""初始化加载指示器"""
# 默认隐藏
hide()
# 设置统一的字体样式
_setup_font_style()
print("LoadingIndicator initialized")
func _process(delta: float) -> void:
"""更新加载动画"""
if is_loading and spinner:
# 旋转加载图标
spinner.rotation += rotation_speed * delta
## 显示加载状态
func show_loading(message: String = "加载中...", show_progress: bool = false) -> void:
"""
显示加载状态
@param message: 加载消息
@param show_progress: 是否显示进度条
"""
is_loading = true
# 设置消息
if loading_label:
loading_label.text = message
# 设置进度条可见性
if progress_bar:
progress_bar.visible = show_progress
if show_progress:
progress_bar.value = 0
# 使用动画显示面板
UIAnimationManager.scale_popup(self, 0.3, UIAnimationManager.EaseType.BOUNCE)
preload("res://scripts/Utils.gd").debug_print("Loading: " + message, "UI")
## 更新加载进度
func update_progress(progress: float, message: String = "") -> void:
"""
更新加载进度
@param progress: 进度值0-100
@param message: 可选的消息更新
"""
if progress_bar:
progress_bar.value = progress
if not message.is_empty() and loading_label:
loading_label.text = message
## 隐藏加载状态
func hide_loading() -> void:
"""隐藏加载状态"""
is_loading = false
# 使用动画隐藏面板
UIAnimationManager.fade_out(self, 0.25)
preload("res://scripts/Utils.gd").debug_print("Loading complete", "UI")
## 显示连接中状态
func show_connecting() -> void:
"""显示连接中状态"""
show_loading("正在连接服务器...", false)
## 显示登录中状态
func show_logging_in() -> void:
"""显示登录中状态"""
show_loading("正在登录...", false)
## 显示加载世界状态
func show_loading_world() -> void:
"""显示加载世界状态"""
show_loading("正在加载游戏世界...", true)
## 显示创建角色状态
func show_creating_character() -> void:
"""显示创建角色状态"""
show_loading("正在创建角色...", false)
## 设置字体样式
func _setup_font_style() -> void:
"""设置统一的字体样式"""
if loading_label:
# 设置字体大小
loading_label.add_theme_font_size_override("font_size", 18)
# 设置文字颜色
loading_label.add_theme_color_override("font_color", Color.WHITE)
# 添加阴影效果使文字更清晰
loading_label.add_theme_color_override("font_shadow_color", Color(0, 0, 0, 0.8))
loading_label.add_theme_constant_override("shadow_offset_x", 1)
loading_label.add_theme_constant_override("shadow_offset_y", 1)
# 确保文字居中
loading_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
loading_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER