Passion & UI
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System.Collections.Generic;
|
||||
using Cielonos.MainGame.Inventory;
|
||||
using SLSUtilities.General;
|
||||
using SLSUtilities.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cielonos.MainGame.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 单条物品描述条目 UI 组件。
|
||||
/// 渲染管线:Localize → DisplayTextResolver.Resolve → InputGlyphParser.Parse → TMP_Text。
|
||||
/// </summary>
|
||||
public class ItemDescriptionEntry : MonoBehaviour
|
||||
{
|
||||
private const string LocalizationTable = "Items";
|
||||
|
||||
[Tooltip("描述文本,显示 descriptionKey 的本地化内容(含动态数值替换和按键图标解析)。")]
|
||||
public TMP_Text descriptionText;
|
||||
|
||||
/// <summary>
|
||||
/// 使用 <see cref="ItemDescription"/> 的数据填充描述条目。
|
||||
/// 完整渲染管线:本地化 → {key} 占位符替换 → [Token] 按键图标解析。
|
||||
/// </summary>
|
||||
/// <param name="description">描述数据。</param>
|
||||
/// <param name="descriptionArgs">可选的动态值字典,用于替换本地化文本中的 {key} 占位符。</param>
|
||||
public void SetDescription(ItemDescription description, Dictionary<string, string> descriptionArgs = null)
|
||||
{
|
||||
if (description == null)
|
||||
{
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (descriptionText == null) return;
|
||||
|
||||
if (string.IsNullOrEmpty(description.descriptionKey))
|
||||
{
|
||||
descriptionText.text = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
string localizedText = description.descriptionKey.Localize(LocalizationTable);
|
||||
localizedText = DisplayTextResolver.Resolve(localizedText, descriptionArgs);
|
||||
descriptionText.text = InputGlyphParser.Parse(localizedText);
|
||||
}
|
||||
|
||||
/// <summary>清空条目内容。</summary>
|
||||
public void Clear()
|
||||
{
|
||||
if (descriptionText != null)
|
||||
{
|
||||
descriptionText.text = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user