using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace BrewMonster.Scripts.UI
{
///
/// Helper class to set text on both legacy Text and TextMeshPro components
/// Supports automatic formatting for Perfect World text codes
///
[System.Serializable]
public class TextOutlet
{
[SerializeField] public Text legacy;
[SerializeField] public TMPro.TextMeshProUGUI tmp;
public void Set(string value)
{
if (legacy != null)
{
legacy.text = EC_Utility.FormatForLegacyText(value ?? string.Empty);
}
if (tmp != null)
{
tmp.text = EC_Utility.FormatForTextMeshPro(value ?? string.Empty);
}
}
///
/// Set text with explicit formatting preference
///
/// Raw text with formatting codes
/// Whether to prefer TextMeshPro formatting
public void SetFormatted(string value, bool preferTextMeshPro = true)
{
string formattedText = preferTextMeshPro ?
EC_Utility.FormatForTextMeshPro(value ?? string.Empty) :
EC_Utility.FormatForLegacyText(value ?? string.Empty);
if (legacy != null)
{
legacy.text = formattedText;
}
if (tmp != null)
{
tmp.text = formattedText;
}
}
public void SetColor(Color color)
{
if (legacy != null)
{
legacy.color = color;
}
if (tmp != null)
{
tmp.color = color;
}
}
}
}