Files
test/Assets/PerfectWorld/Scripts/Chat/CECPateText.cs
2026-03-06 16:45:35 +07:00

239 lines
6.4 KiB
C#

using System.Collections.Generic;
using BrewMonster.Network;
using BrewMonster.Scripts.Managers;
using BrewMonster.UI;
using UnityEngine;
namespace BrewMonster.Scripts.Chat
{
public class CECPateText
{
protected List<string> m_aTextStrs;
//protected List<> m_aEmotions;
//protected List<ITEM, ITEM> m_aItems;
//protected EditBoxItemSet m_ItemSet;
// Text item type
public enum ETextType
{
TYPE_TEXT = 0,
TYPE_EMOTION,
TYPE_BOOTHNAME,
}
// Text item
public struct ITEM
{
public int iType; // Text type
public int iIndex; // Index of item
public int iExtX; // Extent
public int iExtY;
public int iLine;
//A3DCOLOR clItem;
public Color clItem;
};
public int SetText(string szText,
bool bIncEmotion,
out string pstrTextConverted,
bool bEllipsis = true,
EC_IvtrItem pIvtrItem = null)
{
// Clear old content
Clear();
pstrTextConverted = null;
if (string.IsNullOrEmpty(szText))
return 0;
CECGameUIMan pGameUI =
EC_Game.GetGameRun().GetUIManager().GetInGameUIMan();
/*string str = pGameUI.AUI_FilterEditboxItem(
szText,
CECGameUIMan.AUI_EditboxItemMaskFilter(1 << (int)enumEICoord)
);
string strName;
A3DCOLOR clrName;
pGameUI.TransformNameColor(pIvtrItem, out strName, out clrName);
str = UnmarshalEditBoxText(str, m_ItemsSet, 0, strName, clrName);
szText = str;
pstrTextConverted = str;
int iAddedChar = 0;
if (!bIncEmotion)
{
int iLen = szText.Length;
if (iLen > m_iMaxLineLen)
{
string sub = szText.Substring(0, m_iMaxLineLen);
if (bEllipsis)
sub += "...";
CreateTextItem(sub, -1, 0);
iAddedChar = m_iMaxLineLen;
}
else
{
CreateTextItem(szText, -1, 0);
iAddedChar = iLen;
}
}
else
{
int i = 0;
int iStart = 0;
int iEnd = 0;
int iLenCnt = 0;
bool bTooLong = false;
int iLine = 0;
while (i < szText.Length)
{
char ch = szText[i];
if (IsEditboxItemCode(ch))
{
if (iEnd > iStart)
CreateTextItem(szText.Substring(iStart, iEnd - iStart), -1, iLine);
EditBoxItemBase pItem = m_ItemsSet.GetItemByChar(ch);
if (pItem != null)
{
if (pItem.GetType() == enumEIEmotion)
{
int nSet = 0;
int nIndex = 0;
UnmarshalEmotionInfo(pItem.GetInfo(), out nSet, out nIndex);
CreateEmotionItem(nSet, nIndex, iLine);
iLenCnt += 2;
}
else
{
string szName = pItem.GetName();
CreateTextItem(szName, -1, iLine, pItem.GetColor());
iLenCnt += szName.Length;
}
}
i++;
iStart = i;
iEnd = i;
goto CheckLength;
}
iEnd++;
i++;
iLenCnt++;
CheckLength:
if (iLenCnt > m_iMaxLineLen)
{
if (iLine + 1 >= m_iMaxLines)
{
bTooLong = true;
break;
}
if (iEnd > iStart)
CreateTextItem(szText.Substring(iStart, iEnd - iStart), -1, iLine);
iStart = i;
iLine++;
iLenCnt = 0;
}
}
iAddedChar = i;
if (iEnd > iStart)
{
if (bTooLong)
{
string strEnd = szText.Substring(iStart, iEnd - iStart);
if (bEllipsis)
strEnd += "...";
CreateTextItem(strEnd, -1, iLine);
}
else
{
CreateTextItem(szText.Substring(iStart, iEnd - iStart), -1, iLine);
}
}
else if (bTooLong)
{
if (bEllipsis)
CreateTextItem("...", -1, iLine);
}
}
// Calculate extent
m_iExtX = 0;
m_iExtY = 0;
int iLineExtX = 0;
int iLastLine = 0;
for (int i = 0; i < m_aItems.GetSize(); i++)
{
ITEM item = m_aItems[i];
if (item.iLine != iLastLine)
{
iLastLine = item.iLine;
if (m_iExtX < iLineExtX)
m_iExtX = iLineExtX;
iLineExtX = item.iExtX;
}
else
{
iLineExtX += item.iExtX;
}
if (m_iExtY < item.iExtY)
m_iExtY = item.iExtY;
}
m_iLines = iLastLine + 1;
if (m_iExtX < iLineExtX)
m_iExtX = iLineExtX;*/
//return iAddedChar;
return 0;
}
public void Clear()
{
m_aTextStrs.Clear();
/*m_aEmotions.Clear();
m_aItems.Clear();
m_ItemsSet.Clear();*/
}
}
}