mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-08 09:34:30 +08:00
- 实现 RichTextEffectBase 基类提供统一的标签命名和参数读取逻辑 - 添加 RichTextBlueEffect、RichTextGoldEffect、RichTextGreenEffect 和 RichTextRedEffect 颜色标记效果 - 添加 RichTextFadeInEffect、RichTextFlyInEffect、RichTextJitterEffect 和 RichTextSineEffect 动画效果 - 实现 DefaultRichTextEffectRegistry 默认效果注册表 - 创建 GfRichTextLabel 富文本标签宿主组件 - 添加 IRichTextEffectRegistry 效果注册表接口 - 实现 RichTextEffectEntry、RichTextEffectsController 和 RichTextProfile 配置管理类 - 添加 RichTextMarkup 语义化标签构建辅助方法 - 创建 RichTextMarkupTests 和 RichTextProfileTests 单元测试
84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
namespace GFramework.Godot.Text;
|
|
|
|
/// <summary>
|
|
/// GFramework 提供的组合式富文本标签宿主。
|
|
/// 该类型只负责桥接 Godot 的 <see cref="RichTextLabel" /> 与框架的效果装配逻辑,不承载具体效果实现。
|
|
/// </summary>
|
|
[GlobalClass]
|
|
[Tool]
|
|
public partial class GfRichTextLabel : RichTextLabel
|
|
{
|
|
private IRichTextEffectRegistry? _effectRegistry;
|
|
private RichTextEffectsController? _effectsController;
|
|
|
|
/// <summary>
|
|
/// 获取或设置当前标签使用的效果配置。
|
|
/// 为空时将回退到内置默认配置。
|
|
/// </summary>
|
|
[Export]
|
|
public RichTextProfile? Profile { get; set; }
|
|
|
|
/// <summary>
|
|
/// 获取或设置是否启用框架管理的富文本效果装配。
|
|
/// </summary>
|
|
[Export]
|
|
public bool EnableFrameworkEffects { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// 获取或设置是否允许字符级动态效果实际生效。
|
|
/// 关闭后仍然会安装对应标签,使富文本内容保持可解析。
|
|
/// </summary>
|
|
[Export]
|
|
public bool AnimatedEffectsEnabled { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// 获取当前使用的效果注册表。
|
|
/// </summary>
|
|
internal IRichTextEffectRegistry EffectRegistry
|
|
{
|
|
get => _effectRegistry ??= new DefaultRichTextEffectRegistry();
|
|
set => _effectRegistry = value ?? throw new ArgumentNullException(nameof(value));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 节点就绪时初始化控制器并安装效果集合。
|
|
/// </summary>
|
|
public override void _Ready()
|
|
{
|
|
if (EnableFrameworkEffects && !BbcodeEnabled)
|
|
{
|
|
BbcodeEnabled = true;
|
|
}
|
|
|
|
EnsureController().Initialize();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手动刷新框架效果集合。
|
|
/// 当调用方在运行时替换配置或切换动画开关时,可通过该方法同步宿主状态。
|
|
/// </summary>
|
|
public void RefreshFrameworkEffects()
|
|
{
|
|
if (EnableFrameworkEffects && !BbcodeEnabled)
|
|
{
|
|
BbcodeEnabled = true;
|
|
}
|
|
|
|
EnsureController().RefreshEffects();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取或创建控制器实例。
|
|
/// </summary>
|
|
/// <returns>组合式装配控制器。</returns>
|
|
private RichTextEffectsController EnsureController()
|
|
{
|
|
return _effectsController ??= new RichTextEffectsController(
|
|
this,
|
|
EffectRegistry,
|
|
() => Profile,
|
|
() => EnableFrameworkEffects,
|
|
() => AnimatedEffectsEnabled);
|
|
}
|
|
}
|