using Thousandto.Code.Center;
using Thousandto.Plugins.Common;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Thousandto.Core.RootSystem;
using Thousandto.Core.Base;
using System;
using Thousandto.Cfg.Data;
namespace Thousandto.Code.Logic
{
///
/// UIEntergameForm的逻辑处理类
///
public class ChatParse
{
///
/// 解析接收到的字符串
///
/// 接收到的字符串
/// 解析后生成的节点,用于创建对应的控件,如UILabel、UISprite
public static List ParseContent(String content, ulong specialId = 0, bool isPrivateChatNode = false)
{
List nodes = new List();
//以&开头,是GM命令,直接跳过解析
if (!content.StartsWith("{1},{2},{3}", Type, Param3, Param2, Param1);
const string flag_s = ""
if (s_p < e_p)
{
ChatNode node = new ChatNode();
node.isPrivateChatNode = isPrivateChatNode;
node.specialId = specialId;
// chunk p3,p2,p1
tmp = content.Substring(s_p, e_p - s_p);
ParseNode(tmp, flag_s, flag_e, ref node);
nodes.Add(node);
}//if (s_p < e_p)
s_p = e_p + flag_e.Length; // reset start position
} // while(s_p < content.Length)
}
catch (System.Exception ex)
{
UnityEngine.Debug.LogError(ex.Message);
nodes.Clear();
ChatNode node = new ChatNode();
node.isPrivateChatNode = isPrivateChatNode;
node.Type = (int)TNodeType.Text;
node.Param1 = content;
nodes.Add(node);
}
return nodes;
}
///
/// 解析单个字符串节点 如 p3,p2,p1
///
///
///
///
///
static void ParseNode(string tmp, string flag_s, string flag_e, ref ChatNode node)
{
if (node != null && tmp.Length > 0)
{
int len = 0;
//
int type_e = tmp.IndexOf(">", flag_s.Length);
if (type_e > flag_s.Length && type_e < tmp.Length)
{
//real text
len = type_e - flag_s.Length;
if (len >= 0)
{
string type = tmp.Substring(flag_s.Length, len);
node.Type = Convert.ToInt32(type);
}
else
{
node.Type = (int)TNodeType.Text;
}
}
// >p3,p2,p1<
int p3_e = tmp.IndexOf(",", type_e + 1); // ">"
if (p3_e < tmp.Length)
{
//real text
len = p3_e - type_e - 1;// 1 ">"
string p3 = len <= 0 ? "" : tmp.Substring(type_e + 1, len);
node.Param3 = p3;//Convert.ToUInt64(p2);
}
// >p3,p2,p1<
int p2_e = tmp.IndexOf(",", p3_e + 1); // ","
if (p2_e < tmp.Length)
{
//real text
len = p2_e - p3_e - 1; // 1 ">"
string p2 = len <= 0 ? "" : tmp.Substring(p3_e + 1, len);
node.Param2 = p2;//Convert.ToUInt64(p2);
}
// >p3,p2,p1<
{
//real text
len = tmp.Length - flag_e.Length - (p2_e + 1); // 1 ","
node.Param1 = len <= 0 ? "" : tmp.Substring(p2_e + 1, len);
}
switch (node.Type)
{
case (int)TNodeType.Equipment:
node.ItemParam = ItemBase.ToItemBase(node.Param3);
if (node.ItemParam != null)
{
node.Param1 = DeclareMessageString.Format(DeclareMessageString.C_CHAT_ITEMEQUIP_LINK, node.ItemParam.Name);
}
break;
case (int)TNodeType.Item:
int itemId = 0;
if(int.TryParse(node.Param2, out itemId))
{
node.ItemParam = ItemBase.CreateItemBase(itemId, true);
if (node.ItemParam != null)
{
node.Param1 = DeclareMessageString.Format(DeclareMessageString.C_CHAT_ITEMEQUIP_LINK, node.ItemParam.Name);
}
}
else
{
node.Param1 = string.Empty;
}
break;
case (int)TNodeType.Function:
node.Param1 = GameCenter.LanguageConvertSystem.ConvertLan(node.Param1);
break;
}
}
}
///
/// 将结构转成纯字符串,便于发送
///
///
///
public static string GetTransferContent(List msg, bool isPrivateChatNode = false)
{
string content = "";
for (int i = 0; i < msg.Count; ++i)
{
if (isPrivateChatNode)
{
if (msg[i].isPrivateChatNode)
{
content += msg[i].GetTransferText();
}
}
else
{
content += msg[i].GetTransferText();
}
}
return content;
}
public void OnInputChange()
{
}
}
}