update logic receive Command.TASK_VER_DATA
This commit is contained in:
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using CSNetwork.GPDataType;
|
||||
using BrewMonster.Network;
|
||||
using BrewMonster;
|
||||
using BrewMonster.Common;
|
||||
@@ -79,95 +79,7 @@ namespace BrewMonster.Scripts.Managers
|
||||
/// <returns>Formatted text for TextMeshPro</returns>
|
||||
private static string FormatForTextMeshPro(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return string.Empty;
|
||||
|
||||
StringBuilder result = new StringBuilder(text);
|
||||
|
||||
// Handle line breaks (\r)
|
||||
result.Replace("\\r", "\n");
|
||||
|
||||
// Handle color codes (^RRGGBB format)
|
||||
string processedText = ProcessColorCodes(result);
|
||||
|
||||
return processedText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Format text for legacy Text components (limited rich text support)
|
||||
/// </summary>
|
||||
/// <param name="text">Raw text with formatting codes</param>
|
||||
/// <returns>Formatted text for legacy Text</returns>
|
||||
private static string FormatForLegacyText(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return string.Empty;
|
||||
|
||||
StringBuilder result = new StringBuilder(text);
|
||||
|
||||
// Handle line breaks (\r)
|
||||
result.Replace("\\r", "\n");
|
||||
|
||||
// Handle color codes (^RRGGBB format) - convert to Unity's rich text format
|
||||
string processedText = ProcessColorCodesForLegacy(result);
|
||||
|
||||
return processedText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process color codes for TextMeshPro (supports hex colors directly)
|
||||
/// </summary>
|
||||
private static string ProcessColorCodes(StringBuilder text)
|
||||
{
|
||||
// Pattern to match color codes: ^ followed by 6 hex characters
|
||||
string pattern = @"\^([0-9A-Fa-f]{6})";
|
||||
|
||||
return Regex.Replace(text.ToString(), pattern, match =>
|
||||
{
|
||||
string hexColor = match.Groups[1].Value;
|
||||
return $"<color=#{hexColor}>";
|
||||
}, RegexOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process color codes for legacy Text (convert to Unity rich text format)
|
||||
/// </summary>
|
||||
private static string ProcessColorCodesForLegacy(StringBuilder text)
|
||||
{
|
||||
// Pattern to match color codes: ^ followed by 6 hex characters
|
||||
string pattern = @"\^([0-9A-Fa-f]{6})";
|
||||
|
||||
return Regex.Replace(text.ToString(), pattern, match =>
|
||||
{
|
||||
string hexColor = match.Groups[1].Value;
|
||||
// Convert hex to Unity color format
|
||||
Color color = HexToColor(hexColor);
|
||||
return $"<color=#{ColorUtility.ToHtmlStringRGB(color)}>";
|
||||
}, RegexOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert hex color string to Unity Color
|
||||
/// </summary>
|
||||
/// <param name="hex">Hex color string (e.g., "ffcb4a")</param>
|
||||
/// <returns>Unity Color object</returns>
|
||||
private static Color HexToColor(string hex)
|
||||
{
|
||||
if (hex.Length != 6)
|
||||
return Color.white;
|
||||
|
||||
try
|
||||
{
|
||||
int r = Convert.ToInt32(hex.Substring(0, 2), 16);
|
||||
int g = Convert.ToInt32(hex.Substring(2, 2), 16);
|
||||
int b = Convert.ToInt32(hex.Substring(4, 2), 16);
|
||||
|
||||
return new Color(r / 255f, g / 255f, b / 255f, 1f);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Color.white;
|
||||
}
|
||||
return EC_Utility.FormatForTextMeshPro(text);
|
||||
}
|
||||
|
||||
// Current selected item for equip/unequip operations
|
||||
@@ -749,7 +661,7 @@ namespace BrewMonster.Scripts.Managers
|
||||
{
|
||||
if (legacy != null)
|
||||
{
|
||||
legacy.text = FormatForLegacyText(value ?? string.Empty);
|
||||
legacy.text = EC_Utility.FormatForLegacyText(value ?? string.Empty);
|
||||
}
|
||||
if (tmp != null)
|
||||
{
|
||||
@@ -766,7 +678,7 @@ namespace BrewMonster.Scripts.Managers
|
||||
{
|
||||
string formattedText = preferTextMeshPro ?
|
||||
FormatForTextMeshPro(value ?? string.Empty) :
|
||||
FormatForLegacyText(value ?? string.Empty);
|
||||
EC_Utility.FormatForLegacyText(value ?? string.Empty);
|
||||
|
||||
if (legacy != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user