1296 lines
47 KiB
C#
1296 lines
47 KiB
C#
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;
|
||
using Thousandto.Core.Asset;
|
||
using Thousandto.Core.Framework;
|
||
using Thousandto.Code.Global;
|
||
using System.Text.RegularExpressions;
|
||
using UnityEngine.Gonbest.MagicCube;
|
||
|
||
namespace Thousandto.Code.Logic
|
||
{
|
||
/// <summary>
|
||
/// UIEntergameForm的逻辑处理类
|
||
/// </summary>
|
||
public partial class ChatSystem
|
||
{
|
||
#region //私有数据 及 get set
|
||
//聊天翻译开关
|
||
private bool _translateSwitch = false;
|
||
//大聊天框宽度,会根据面板去计算
|
||
public const int MAX_MAIN_CHAT_LINE_WIDTH = 250;
|
||
public const int MAX_MAIN_SYS_CHAT_LINE_WIDTH = 340;
|
||
//主界面小聊天框宽度
|
||
#if USE_PC_MODEL
|
||
public const int MAX_MINI_CHAT_LINE_WIDTH = 294;
|
||
#else
|
||
public const int MAX_MINI_CHAT_LINE_WIDTH = 294;
|
||
#endif
|
||
//私聊界面,每条聊天信息最大宽度
|
||
public const int MAX_PRIVATE_CHAT_LINE_WIDTH = 290;
|
||
//私聊窗体, 聊天面板宽度
|
||
public const int PRIVATE_CHAT_PANEL_WIDTH = 420;
|
||
//移除的chatnode个数,用于scrollview上删除对应个数的child
|
||
public Dictionary<int, int> RemovedChatNodeCountByChannel = new Dictionary<int, int>();
|
||
|
||
private ChatInfo _cacheInfo = null;
|
||
private ChatNode _senderNode = null;
|
||
|
||
private List<ChatNode> _cacheSendNodes; //用于存储消息节点
|
||
//private List<ChatNode> _cacheRecvNodes; //用于存储接收消息节点
|
||
|
||
//logic代码和UI代码中间转换的工具类,消除logic代码对NGUI的直接使用
|
||
private Dictionary<int, bool> _cacheImageTypeDic = new Dictionary<int, bool>();
|
||
private IChatSystemTool _chatTool;
|
||
|
||
public const int CHATER_SHIELD_ID = 50000;
|
||
|
||
public bool TranslateSwitch
|
||
{
|
||
get
|
||
{
|
||
return _translateSwitch;
|
||
}
|
||
}
|
||
|
||
public IChatSystemTool ChatTool
|
||
{
|
||
get {return _chatTool; }
|
||
set { _chatTool = value; }
|
||
}
|
||
|
||
public ChatInfo CacheInfo
|
||
{
|
||
get { return _cacheInfo; }
|
||
set { _cacheInfo = value; }
|
||
}
|
||
|
||
public int CurrentChannel { get; set; }
|
||
|
||
public List<ChatNode> CacheSendNodes
|
||
{
|
||
get
|
||
{
|
||
if (_cacheSendNodes == null)
|
||
{
|
||
_cacheSendNodes = new List<ChatNode>();
|
||
}
|
||
return _cacheSendNodes;
|
||
}
|
||
set { _cacheSendNodes = value; }
|
||
}
|
||
|
||
public Dictionary<int, bool> CacheImageTypeDic
|
||
{
|
||
get
|
||
{
|
||
return _cacheImageTypeDic;
|
||
}
|
||
}
|
||
|
||
public static int ImgWidth = 30;
|
||
public static int ImgHeight = 30;
|
||
public static int RealImgWidth = 30;
|
||
public static int RealImgHeight = 30;
|
||
|
||
public const int BigImgWidth = 30;
|
||
public const int BigImgHeight = 30;
|
||
|
||
public const int LineHeight = 30;
|
||
private int _imgPhotoWidth = 24;
|
||
private int _imgPhotoHeight = 24;
|
||
private int _fontSize = 21;
|
||
private object[] _labelSkin = null;
|
||
private int _loadFontCounter = 0;
|
||
|
||
//表情
|
||
private string _expression1 = "#{0:D2}"; //静态表情
|
||
private string _expression2 = "@{0:D2}_{1}"; //动态表情,一直loop
|
||
private string _expression3 = "^{0:D2}_{1}"; //动态表情,只播放一遍
|
||
|
||
private string _expression1Big = "##{0:D2}"; //静态表情
|
||
private string _expression2Big = "@@{0:D2}_{1}"; //动态表情,一直loop
|
||
private string _expression3Big = "^^{0:D2}_{1}"; //动态表情,只播放一遍
|
||
|
||
public static int ExpressionCount1 = 0; //静态表情个数
|
||
public static int ExpressionCount2 = 0; //动态表情1 个数
|
||
public static int ExpressionCount3 = 0; //动态表情2 个数
|
||
|
||
public static int ExpressionCount1Big = 0; //静态表情个数
|
||
public static int ExpressionCount2Big = 0; //动态表情1 个数
|
||
public static int ExpressionCount3Big = 0; //动态表情2 个数
|
||
|
||
public Transform ExpressionGO; //动态load的表情,实例化表情图片就靠它
|
||
public Transform ExpressionBigGO; //大表情动态load的表情,实例化表情图片就靠它
|
||
//public Transform ItemGO;
|
||
public Transform HistoryGO;
|
||
public Transform VipGO; //vip等级
|
||
public Transform VoiceGO; //vip等级
|
||
|
||
public Dictionary<int, string> LabelSkinDic = new Dictionary<int, string>()
|
||
{
|
||
{(int)TLabelType.World, "FontWorld_yellow"},
|
||
{(int)TLabelType.Team, "FontTeam_blue"},
|
||
{(int)TLabelType.Guild, "FontGuild_green"},
|
||
{(int)TLabelType.System, "FontSystem_red"},
|
||
{(int)TLabelType.Private, "FontPrivate_orange"},
|
||
{(int)TLabelType.Position, "FontGuild_green"},
|
||
{(int)TLabelType.Player, "FontContent_white"},
|
||
{(int)TLabelType.Content, "FontContent_white"},
|
||
{(int)TLabelType.Extra_1, "Font_purple"},
|
||
{(int)TLabelType.Extra_2, "Font_golden"},
|
||
};
|
||
|
||
//频道背景sprite名字
|
||
public Dictionary<int, Color> ChanelBgDict = new Dictionary<int, Color>()
|
||
{
|
||
//talk_talkback
|
||
{(int)ChatChanelType.WORLD, new Color(208/255f,197/255f,129/255f)},
|
||
{(int)ChatChanelType.GUILD, new Color(45/255f,202/255f,171/255f)},
|
||
{(int)ChatChanelType.TEAM, new Color(166/255f,200/255f,134/255f)},
|
||
{(int)ChatChanelType.PERSONAL, new Color(255/255f,0/255f,255/255f)},
|
||
{(int)ChatChanelType.SYSTEM, new Color(249/255f,118/255f,2/255f)},
|
||
{(int)ChatChanelType.ALL, new Color()},
|
||
{(int)ChatChanelType.PALACE, new Color()},
|
||
{(int)ChatChanelType.CURRENT, new Color(117/255f,194/255f,201/255f)},
|
||
{(int)ChatChanelType.JOINTEAM, new Color(134/255f,136/255f,234/255f)},
|
||
{(int)ChatChanelType.Live, new Color()},
|
||
{(int)ChatChanelType.Friend, new Color(227/255f,165/255f,219/255f)},
|
||
{(int)ChatChanelType.Experience, new Color(227/255f,165/255f,219/255f)},
|
||
};
|
||
|
||
private Dictionary<int, string> _channelToString;
|
||
public Dictionary<int, string> ChannelToString
|
||
{
|
||
get
|
||
{
|
||
if (_channelToString == null)
|
||
{
|
||
_channelToString = new Dictionary<int, string>() {
|
||
{(int)ChatChanelType.WORLD, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_GROUP_WORLD)},
|
||
{(int)ChatChanelType.ChuanWen, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_GROUP_ChuanWen)},
|
||
{(int)ChatChanelType.GUILD, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_GROUP_GUILD)},
|
||
{(int)ChatChanelType.TEAM, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_GROUP_TEAM)},
|
||
{(int)ChatChanelType.PERSONAL, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_GROUP_PERSONAL)},
|
||
{(int)ChatChanelType.SYSTEM, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_GROUP_SYSTEM)},
|
||
{(int)ChatChanelType.ALL, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_GROUP_ALL)},
|
||
{(int)ChatChanelType.PALACE, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_GROUP_PALACE)},
|
||
{(int)ChatChanelType.CURRENT, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHATSYSTEM_CHANNEL_CURRENT)},
|
||
{(int)ChatChanelType.JOINTEAM, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHATSYSTEM_CHANNEL_TEAMINVITE)},
|
||
{(int)ChatChanelType.Live, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHATSYSTEM_CHANNEL_LIVE)},
|
||
{(int)ChatChanelType.Friend, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_CHANNEL_BIRTH)},
|
||
{(int)ChatChanelType.Experience, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_CHANNEL_EXPRESION)},
|
||
{(int)ChatChanelType.Cross, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_CHANNEL_CROSS)},
|
||
{(int)ChatChanelType.CH, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_LANG_CN)},
|
||
{(int)ChatChanelType.EN, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_LANG_EN)},
|
||
{(int)ChatChanelType.TH, Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_LANG_TH)},
|
||
};
|
||
}
|
||
|
||
return _channelToString;
|
||
}
|
||
}
|
||
|
||
|
||
//物品颜色对应的label
|
||
public Dictionary<int, int> ItemColorToLabelID = new Dictionary<int, int>()
|
||
{
|
||
{(int)TLabelColor.White, (int)TLabelType.Content},
|
||
{(int)TLabelColor.Green, (int)TLabelType.Guild},
|
||
{(int)TLabelColor.Blue, (int)TLabelType.Team},
|
||
{(int)TLabelColor.Purple, (int)TLabelType.Extra_1},
|
||
{(int)TLabelColor.Orange, (int)TLabelType.Private},
|
||
{(int)TLabelColor.Golden, (int)TLabelType.Extra_2},
|
||
{(int)TLabelColor.Red, (int)TLabelType.System},
|
||
};
|
||
|
||
//颜色id对应颜色值
|
||
public Dictionary<int, string> ItemColorIDToColorStr = new Dictionary<int, string>()
|
||
{
|
||
{(int)TLabelColor.White, "FFFFFF"},
|
||
{(int)TLabelColor.Green, "00FF00"},
|
||
{(int)TLabelColor.Blue, "006BFF"},
|
||
{(int)TLabelColor.Purple, "FF00FF"},
|
||
{(int)TLabelColor.Orange, "FF8000"},
|
||
{(int)TLabelColor.Golden, "FFFF00"},
|
||
{(int)TLabelColor.Red, "FF0000"},
|
||
};
|
||
|
||
//文本类型对应颜色值
|
||
public Dictionary<int, string> LabelColorDic = new Dictionary<int, string>()
|
||
{
|
||
{(int)TLabelType.World, "d0c581"},
|
||
{(int)TLabelType.Team, "a6c886"},
|
||
{(int)TLabelType.Guild, "2dcaab"},
|
||
{(int)TLabelType.System, "f97602"},
|
||
{(int)TLabelType.Private, "ff00ff"},
|
||
{(int)TLabelType.Position, "03ba03"},
|
||
{(int)TLabelType.Player, "03ba03"},
|
||
{(int)TLabelType.Content, "5e5754"},
|
||
{(int)TLabelType.Extra_1, "FF00FF"},
|
||
{(int)TLabelType.Extra_2, "FFFF00"},
|
||
{(int)TLabelType.JoinTeam, "3ae95f"},
|
||
{(int)TLabelType.Live, "FFFF00"},
|
||
{(int)TLabelType.Friend, "e3a5db"},
|
||
{(int)TLabelType.Current, "75c2c9"},
|
||
{(int)TLabelType.ChuanWen , "f97602"},
|
||
};
|
||
|
||
//每个频道聊天记录最大数
|
||
public const int MAX_MSG_COUNT = 40;
|
||
public const int MAX_MSG_COUNT_MINI = 6;
|
||
|
||
public Dictionary<int, Queue<ChatNode[]>> ChannelData = new Dictionary<int, Queue<ChatNode[]>>(); //保存各频道聊天数据
|
||
public List<ChatNode[]> HistoryData = new List<ChatNode[]>(); //存放历史聊天信息
|
||
public List<ChatNode> DynamicExpresion = new List<ChatNode>();//保存动态表情信息,管理播放动态表情的协程
|
||
public List<ChatNode> DynamicBigExpresion = new List<ChatNode>();//保存动态表情信息,管理播放动态表情的协程
|
||
public Dictionary<int, Queue<ChatInfo>> NewChannelData = new Dictionary<int, Queue<ChatInfo>>(); //保存各频道聊天数据
|
||
|
||
//缓存被释放的label控件
|
||
public static Queue<GameObject> CacheLabels = new Queue<GameObject>();
|
||
public static Queue<GameObject> CacheSprite = new Queue<GameObject>();
|
||
|
||
//聊天内容管理, 用于缓存及销毁
|
||
//<频道, 聊天内容>
|
||
public Dictionary<int, Queue<OneTalkManager>> TalkManagerDic = new Dictionary<int, Queue<OneTalkManager>>();
|
||
|
||
public Queue<GameObject> CacheLabelGO = new Queue<GameObject>();
|
||
public List<GameObject> UseFullLabelGo = new List<GameObject>();
|
||
//小聊天框中的图片缓存
|
||
public Queue<GameObject> CacheMiniChatSpriteGO = new Queue<GameObject>();
|
||
public Queue<GameObject> CacheMiniChatSpriteGOBig = new Queue<GameObject>();
|
||
//大聊天框中的图片缓存
|
||
public Queue<GameObject> CacheMainChatSpriteGO = new Queue<GameObject>();
|
||
public Queue<GameObject> CacheMainChatSpriteGOBig = new Queue<GameObject>();
|
||
public Queue<GameObject> CacheVoiceGO = new Queue<GameObject>();
|
||
|
||
public bool IsInitLocalLeaveMsg = false;
|
||
public bool IsCheckLeaveMsg = false;
|
||
public float CacheMsgTick = 0;
|
||
public float CacheMsgTime = 60;
|
||
#endregion
|
||
public void Initialize()
|
||
{
|
||
IsInitLocalLeaveMsg = false;
|
||
_translateSwitch = false;
|
||
var lanDic = FLanguage.EnabledSelectLans();
|
||
if (lanDic != null)
|
||
_translateSwitch = lanDic.Count > 1;
|
||
}
|
||
public void Destroy()
|
||
{
|
||
DestroyCachedUI();
|
||
|
||
RemovedChatNodeCountByChannel.Clear();
|
||
ChannelData.Clear();
|
||
}
|
||
|
||
//界面销毁的时候调用
|
||
public void DestroyCachedUI()
|
||
{
|
||
destroyCacheData(CacheLabels);
|
||
destroyCacheData(CacheSprite);
|
||
destroyCacheData(CacheMiniChatSpriteGO);
|
||
destroyCacheData(CacheMainChatSpriteGO);
|
||
destroyCacheData(CacheMainChatSpriteGOBig);
|
||
destroyCacheData(CacheVoiceGO);
|
||
}
|
||
|
||
private void destroyCacheData(Queue<GameObject> cache)
|
||
{
|
||
for (int i = 0; i < cache.Count; ++i)
|
||
{
|
||
if (cache.Peek() != null)
|
||
{
|
||
GameObject.Destroy(cache.Peek());
|
||
}
|
||
}
|
||
|
||
cache.Clear();
|
||
}
|
||
|
||
/*
|
||
* Text: m_param1 = content; m_param2 = nil;
|
||
* Player: m_param1 = player name; m_param2 = player id;
|
||
* Item: m_param1 = item name; m_param2 = item id;
|
||
* Equipment: m_param1 = equip name; m_param2 = equip uuid; m_param3 = quality
|
||
* Image: m_param1 = image ; m_param2 = fps; m_param3 = loop
|
||
* Position: m_param1 = content; m_param2 = map id;
|
||
* Private: m_param1 = name; m_param2 = target player id; m_param3 = target player code
|
||
* Audio: m_param1 = key; m_param2 = length m_param3 = ""
|
||
* Team: m_param1 = mapid; m_param2 = roleid m_param3 = "code_rolename"
|
||
* PlayerEx: m_param1 = player name; m_param2 = player code; m_param3 = "playerid"
|
||
* TextEx: m_param1 = content; m_param2 = nil;
|
||
* ImageEx: m_param1 = image ; m_param2 = fps; m_param3 = loop
|
||
*/
|
||
public void AddNode(int type, string params1, string params2 = "", string params3 = "")
|
||
{
|
||
ChatNode node = new ChatNode();
|
||
node.Type = type;
|
||
node.Param1 = params1;
|
||
node.Param2 = params2;
|
||
node.Param3 = params3;
|
||
|
||
CacheSendNodes.Add(node);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加一条聊天内容
|
||
/// </summary>
|
||
/// <param name="channel"></param>
|
||
/// <param name="oneTalk"></param>
|
||
public void AddTalk(int channel, OneTalkManager oneTalk)
|
||
{
|
||
if (TalkManagerDic.ContainsKey(channel))
|
||
{
|
||
TalkManagerDic[channel].Enqueue(oneTalk);
|
||
}
|
||
else
|
||
{
|
||
Queue<OneTalkManager> otmList = new Queue<OneTalkManager>();
|
||
otmList.Enqueue(oneTalk);
|
||
TalkManagerDic.Add(channel, otmList);
|
||
}
|
||
}
|
||
|
||
//获取频道名字
|
||
public string GetChannelName(ChatChanelType channelID)
|
||
{
|
||
string name = "";
|
||
if (ChannelToString.ContainsKey((int)channelID))
|
||
{
|
||
name = ChannelToString[(int)channelID];
|
||
}
|
||
|
||
name = name.Trim('[', ']');
|
||
|
||
return name;
|
||
}
|
||
|
||
public string GetLabelColor(int labelType, int useDefaultColor = 0)
|
||
{
|
||
//大聊天窗固定text文字颜色
|
||
if (useDefaultColor == 2)
|
||
return "354b7f";
|
||
//小聊天窗固定text文字颜色
|
||
if (useDefaultColor == 1)
|
||
return "d0c581";
|
||
|
||
if (LabelColorDic.ContainsKey(labelType))
|
||
{
|
||
return LabelColorDic[labelType];
|
||
}
|
||
|
||
return LabelColorDic[(int)TLabelType.World];
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当关闭界面或者切换频道会清除界面数据,则保存的聊天内容信息也要相应的清除掉
|
||
/// </summary>
|
||
/// <param name="channel"></param>
|
||
public void RemoveAllTalk(int channel)
|
||
{
|
||
if (TalkManagerDic.ContainsKey(channel))
|
||
{
|
||
TalkManagerDic.Remove(channel);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断输入的是否是GM命令还是普通消息
|
||
/// 以&开头为GM命令
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
public void IsGM(string input, bool isPrivateChat = false)
|
||
{
|
||
if (input.StartsWith("&"))
|
||
{
|
||
CacheSendNodes.Clear();
|
||
ChatNode node = new ChatNode();
|
||
node.isPrivateChatNode = isPrivateChat;
|
||
node.Type = (int)TNodeType.CMD;
|
||
node.Param1 = input;
|
||
CacheSendNodes.Clear();
|
||
CacheSendNodes.Add(node);
|
||
GameCenter.ClientGMSystem.IsLevelChangedGM(input);
|
||
return;
|
||
}
|
||
int privateNodeCount = 0;
|
||
if (isPrivateChat)
|
||
{
|
||
for (int i = 0; i < GameCenter.ChatSystem.CacheSendNodes.Count; ++i)
|
||
{
|
||
var node = CacheSendNodes[i];
|
||
if (!node.isPrivateChatNode)
|
||
continue;
|
||
privateNodeCount += 1;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
privateNodeCount = CacheSendNodes.Count;
|
||
}
|
||
if (privateNodeCount == 0)
|
||
{
|
||
ChatNode node = new ChatNode();
|
||
node.isPrivateChatNode = isPrivateChat;
|
||
node.Type = (int)TNodeType.Text;
|
||
node.Param1 = input;
|
||
CacheSendNodes.Add(node);
|
||
}
|
||
}
|
||
|
||
|
||
//设置中间工具
|
||
public void SetTool(IChatSystemTool tool)
|
||
{
|
||
ChatTool = tool;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除发送缓存
|
||
/// </summary>
|
||
public void ClearCache()
|
||
{
|
||
CacheSendNodes.Clear();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 将msg显示在聊天面板,这里不支持私聊面板,要使用私聊,请用ChatPrivateSystem
|
||
/// </summary>
|
||
/// <param name="channel"></param>
|
||
/// <param name="msg"></param>
|
||
public void AddChat(ChatChanelType channel, string msg)
|
||
{
|
||
|
||
MSG_Chat.ChatResInfo myChat = new MSG_Chat.ChatResInfo();
|
||
myChat.chatchannel = (int)channel;
|
||
myChat.condition = msg;
|
||
if (channel == ChatChanelType.ChuanWen)
|
||
{
|
||
var gCfg = DeclareGlobal.Get(2032);
|
||
if (gCfg != null)
|
||
{
|
||
myChat.chater = ChatSystem.CHATER_SHIELD_ID - 1;
|
||
string[] strs = gCfg.Params.Split('_');
|
||
long uId = long.TryParse(strs[0], out uId) ? uId : 0;
|
||
int headId = int.TryParse(strs[1], out headId) ? headId : 0;
|
||
int frameId = int.TryParse(strs[2], out frameId) ? frameId : 0;
|
||
int paopaoId = int.TryParse(strs[3], out paopaoId) ? paopaoId : 0;
|
||
myChat.chatBgId = paopaoId;
|
||
myChat.head = new MSG_Common.HeadAttribute();
|
||
myChat.head.fashionHead = headId;
|
||
myChat.head.fashionFrame = frameId;
|
||
myChat.head.customHeadPath = "";
|
||
myChat.head.useCustomHead = false;
|
||
}
|
||
}
|
||
GS2U_ChatResSC(myChat);
|
||
string s1 = DeclareMessageString.Get(DeclareMessageString.C_ENTERMAPTIPS_SAFE);
|
||
string s2 = DeclareMessageString.Get(DeclareMessageString.C_ENTERMAPTIPS_WEIXIAN);
|
||
if(!string.Equals(msg,s1) && !string.Equals(msg, s2))
|
||
GameCenter.ChatSystem.CacheLocalLeavelMsg(myChat, null);
|
||
}
|
||
|
||
public void AddWorldPersonChat(ChatChanelType channel, string msg)
|
||
{
|
||
if (channel == ChatChanelType.WORLD)
|
||
{
|
||
MSG_Chat.ChatResInfo myChat = new MSG_Chat.ChatResInfo();
|
||
myChat.chatchannel = (int)channel;
|
||
myChat.condition = msg;
|
||
myChat.chater = ChatSystem.CHATER_SHIELD_ID - 1;
|
||
var gCfg = DeclareGlobal.Get(2032);
|
||
if (gCfg != null)
|
||
{
|
||
string[] strs = gCfg.Params.Split('_');
|
||
long uId = long.TryParse(strs[0], out uId) ? uId : 0;
|
||
int headId = int.TryParse(strs[1], out headId) ? headId : 0;
|
||
int frameId = int.TryParse(strs[2], out frameId) ? frameId : 0;
|
||
int paopaoId = int.TryParse(strs[3], out paopaoId) ? paopaoId : 0;
|
||
myChat.chatBgId = paopaoId;
|
||
myChat.head = new MSG_Common.HeadAttribute();
|
||
myChat.head.fashionHead = headId;
|
||
myChat.head.fashionFrame = frameId;
|
||
myChat.head.customHeadPath = "";
|
||
myChat.head.useCustomHead = false;
|
||
GS2U_ChatResSC(myChat);
|
||
string s1 = DeclareMessageString.Get(DeclareMessageString.C_ENTERMAPTIPS_SAFE);
|
||
string s2 = DeclareMessageString.Get(DeclareMessageString.C_ENTERMAPTIPS_WEIXIAN);
|
||
if (!string.Equals(msg, s1) && !string.Equals(msg, s2))
|
||
GameCenter.ChatSystem.CacheLocalLeavelMsg(myChat, null);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 将msg添加到系统频道
|
||
/// </summary>
|
||
/// <param name="msg"></param>
|
||
public void AddSystemChat(string msg)
|
||
{
|
||
AddChat(ChatChanelType.SYSTEM, msg);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取聊天数据
|
||
/// </summary>
|
||
/// <param name="channel"></param>
|
||
/// <returns></returns>
|
||
public Queue<ChatInfo> GetChatDataByChannel(int channel)
|
||
{
|
||
Queue<ChatInfo> ret = null;
|
||
|
||
if(!NewChannelData.ContainsKey(channel))
|
||
{
|
||
NewChannelData.Add(channel, new Queue<ChatInfo>());
|
||
}
|
||
ret = NewChannelData[channel];
|
||
|
||
return ret;
|
||
}
|
||
|
||
|
||
Camera _uiCamera;
|
||
|
||
/// <summary>
|
||
/// 获取UI相机
|
||
/// </summary>
|
||
public Camera UICamera
|
||
{
|
||
get
|
||
{
|
||
if (_uiCamera == null)
|
||
{
|
||
GameObject cameraGO = GameObject.Find("UIRoot(Clone)/Cameras/Camera_UI");
|
||
if (cameraGO == null)
|
||
{
|
||
cameraGO = GameObject.Find("UIRoot/Cameras/Camera_UI");
|
||
}
|
||
if (cameraGO == null)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
_uiCamera = cameraGO.GetComponent<Camera>();
|
||
}
|
||
|
||
return _uiCamera;
|
||
}
|
||
set { _uiCamera = value; }
|
||
}
|
||
|
||
|
||
#region//UI界面按钮的回调函数
|
||
bool _opening = false;
|
||
public void Open(int channel = (int)ChatChanelType.WORLD)
|
||
{
|
||
if(_opening)
|
||
{
|
||
_opening = false;
|
||
Close();
|
||
return;
|
||
}
|
||
|
||
if (channel == (int)ChatChanelType.PERSONAL)
|
||
{
|
||
if (GameCenter.ChatPrivateSystem.PrivateChatDatas != null && GameCenter.ChatPrivateSystem.PrivateChatDatas.Count > 0)
|
||
{
|
||
//GameCenter.ChatPrivateSystem.Open();
|
||
return;
|
||
}
|
||
else
|
||
channel = (int)ChatChanelType.ALL;
|
||
}
|
||
else if (channel == (int)ChatChanelType.TEAM)
|
||
{
|
||
if (!GameCenter.LuaSystem.Adaptor.IsTeamExist())
|
||
{
|
||
//没有队伍,不能切换频道
|
||
channel = (int)ChatChanelType.ALL;
|
||
}
|
||
}
|
||
else if(channel == (int)ChatChanelType.GUILD)
|
||
{
|
||
if(!GameCenter.LuaSystem.Adaptor.HasJoinedGuild())
|
||
{
|
||
//没有公会
|
||
channel = (int)ChatChanelType.ALL;
|
||
}
|
||
}
|
||
|
||
_opening = true;
|
||
GameCenter.PushFixEvent((int)UIEventDefine.UIChatMainForm_OPEN, new int[] { channel, -1});
|
||
}
|
||
|
||
public void Close()
|
||
{
|
||
_opening = false;
|
||
GameCenter.PushFixEvent((int)UIEventDefine.UIChatMainForm_CLOSE);
|
||
}
|
||
|
||
public bool IsOpened()
|
||
{
|
||
return _opening;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 添加字体皮肤,在聊天界面初始化的时候调用
|
||
/// </summary>
|
||
/// <param name="label"></param>
|
||
/// <param name="type"></param>
|
||
public void AddUILabelSkin(object label, int type)
|
||
{
|
||
if (_labelSkin == null)
|
||
{
|
||
_labelSkin = new object[(int)TLabelType.EndID];
|
||
}
|
||
|
||
_labelSkin[type] = label;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取对应类型的字体,用于计算字符宽度
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
/// <returns></returns>
|
||
public object GetLabelSkin(int type)
|
||
{
|
||
if (_labelSkin != null && type < _labelSkin.Length)
|
||
{
|
||
return _labelSkin[type];
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 通过频道id获取对应的字体风格
|
||
/// </summary>
|
||
/// <param name="channel"></param>
|
||
/// <returns></returns>
|
||
public int GetLabelTypeByChannel(int channel)
|
||
{
|
||
int type = -1;
|
||
|
||
switch ((ChatChanelType)channel)
|
||
{
|
||
case ChatChanelType.WORLD:
|
||
type = (int)TLabelType.World;
|
||
break;
|
||
case ChatChanelType.GUILD:
|
||
type = (int)TLabelType.Guild;
|
||
break;
|
||
case ChatChanelType.SYSTEM:
|
||
type = (int)TLabelType.System;
|
||
break;
|
||
case ChatChanelType.TEAM:
|
||
type = (int)TLabelType.Team;
|
||
break;
|
||
case ChatChanelType.PERSONAL:
|
||
type = (int)TLabelType.Private;
|
||
break;
|
||
case ChatChanelType.PALACE:
|
||
type = (int)TLabelType.Extra_1;
|
||
break;
|
||
case ChatChanelType.CURRENT:
|
||
type = (int)TLabelType.Current;
|
||
break;
|
||
case ChatChanelType.JOINTEAM:
|
||
type = (int)TLabelType.JoinTeam;
|
||
break;
|
||
case ChatChanelType.Friend:
|
||
type = (int)TLabelType.Friend;
|
||
break;
|
||
case ChatChanelType.Live:
|
||
type = (int)TLabelType.Live;
|
||
break;
|
||
case ChatChanelType.Experience:
|
||
type = (int)TLabelType.System;
|
||
break;
|
||
}
|
||
|
||
return type;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 静态表情
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public string GetExpressionName1(int id, bool big = false)
|
||
{
|
||
if (big)
|
||
return string.Format(_expression1Big, id);
|
||
return string.Format(_expression1, id);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 一直循环播放的动态表情
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public string GetExpressionName2(int id, bool big = false)
|
||
{
|
||
if (big)
|
||
return string.Format(_expression2Big, id, 1);
|
||
return string.Format(_expression2, id, 1);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 播放一遍的动态表情
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public string GetExpressionName3(int id, bool big = false)
|
||
{
|
||
if (big)
|
||
return string.Format(_expression3Big, id, 1);
|
||
return string.Format(_expression3, id, 1);
|
||
}
|
||
|
||
|
||
//月卡、终生卡等类似vip等级提示的global表配置id
|
||
//月卡1,终身卡2,月卡和终身卡都有为3
|
||
public int GetGlobalIdByVipLevel(int level)
|
||
{
|
||
string configIdStr = null;
|
||
if (level == 1)
|
||
configIdStr = Cfg.Data.DeclareGlobal.Get(1194).Params;
|
||
else if (level == 2)
|
||
configIdStr = Cfg.Data.DeclareGlobal.Get(1195).Params;
|
||
else if (level == 3)
|
||
configIdStr = Cfg.Data.DeclareGlobal.Get(1197).Params;
|
||
|
||
int id = 0;
|
||
int.TryParse(configIdStr, out id);
|
||
return id;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region //功能函数
|
||
|
||
/// <summary>
|
||
/// 添加聊天数据到各个频道,保存起来
|
||
/// </summary>
|
||
/// <param name="channel"></param>
|
||
/// <param name="nodes"></param>
|
||
private void InsertData(int channel, ChatInfo info, int maxMsgCount = MAX_MSG_COUNT)
|
||
{
|
||
if (info.IsTranslate)
|
||
return;
|
||
if (NewChannelData.ContainsKey(channel))
|
||
{
|
||
if (NewChannelData[channel].Count >= maxMsgCount)
|
||
{
|
||
//ChatInfo popInfo = NewChannelData[channel].Dequeue();
|
||
//popInfo.Destroy();
|
||
NewChannelData[channel].Dequeue();
|
||
}
|
||
NewChannelData[channel].Enqueue(info);
|
||
}
|
||
else
|
||
{
|
||
Queue<ChatInfo> newNodes = new Queue<ChatInfo>();
|
||
newNodes.Enqueue(info);
|
||
NewChannelData.Add(channel, newNodes);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加聊天数据到各个频道,保存起来
|
||
/// </summary>
|
||
/// <param name="channel"></param>
|
||
/// <param name="nodes"></param>
|
||
private void insertData(int channel, ChatNode[] nodes, int maxMsgCount = MAX_MSG_COUNT)
|
||
{
|
||
if (ChannelData.ContainsKey(channel))
|
||
{
|
||
if (ChannelData[channel].Count >= maxMsgCount)
|
||
{
|
||
//移除逻辑端最早的ChatNode
|
||
ChannelData[channel].Dequeue();
|
||
if (GameCenter.ChatSystem.TalkManagerDic.ContainsKey(channel))
|
||
{
|
||
CacheMiniChatNode(false);
|
||
}
|
||
}
|
||
ChannelData[channel].Enqueue(nodes);
|
||
//var enumer = ChannelData[channel].GetEnumerator();
|
||
//UnityEngine.Debug.LogError(string.Format("111111111111111111--{0}", ChannelData[channel].))
|
||
}
|
||
else
|
||
{
|
||
Queue<ChatNode[]> newNodes = new Queue<ChatNode[]>();
|
||
newNodes.Enqueue(nodes);
|
||
ChannelData.Add(channel, newNodes);
|
||
}
|
||
}
|
||
|
||
//缓存小聊天所有节点
|
||
public void CacheMiniChatNode(bool all)
|
||
{
|
||
if (TalkManagerDic == null || TalkManagerDic.Count == 0 || !TalkManagerDic.ContainsKey((int)ChatChanelType.MINI))
|
||
return;
|
||
|
||
//移除UI端最早的ChatNode
|
||
Queue<OneTalkManager> talkList = GameCenter.ChatSystem.TalkManagerDic[(int)ChatChanelType.MINI];
|
||
while(true)
|
||
{
|
||
if (talkList.Count == 0)
|
||
break;
|
||
OneTalkManager earlistTalk = talkList.Dequeue();
|
||
if (earlistTalk != null && earlistTalk.Label != null)
|
||
{
|
||
//earlistTalk.Label.SetActive(false);
|
||
|
||
GameCenter.ChatSystem.CacheLabelGO.Enqueue(earlistTalk.Label);
|
||
for (int i = 0; i < GameCenter.ChatSystem.UseFullLabelGo.Count; i++)
|
||
{
|
||
if (GameCenter.ChatSystem.UseFullLabelGo[i] == earlistTalk.Label.gameObject)
|
||
{
|
||
GameCenter.ChatSystem.UseFullLabelGo.RemoveAt(i);
|
||
}
|
||
}
|
||
|
||
List<ChatNode> imgNodes = earlistTalk.GetImageChatNode((int)ChatChanelType.MINI);
|
||
for (int i = 0; i < imgNodes.Count; ++i)
|
||
{
|
||
if (imgNodes[i] != null && imgNodes[i].GO != null)
|
||
{
|
||
if (imgNodes[i].Type == (int)TNodeType.Image)
|
||
{
|
||
imgNodes[i].StopPlayAnim();
|
||
imgNodes[i].GO.SetActive(false);
|
||
GameCenter.ChatSystem.CacheMiniChatSpriteGO.Enqueue(imgNodes[i].GO);
|
||
}
|
||
else if (imgNodes[i].Type == (int)TNodeType.Vip || imgNodes[i].Type == (int)TNodeType.Audio)
|
||
{
|
||
imgNodes[i].Destory();
|
||
}
|
||
else if (imgNodes[i].Type == (int)TNodeType.BigImage)
|
||
{
|
||
imgNodes[i].StopPlayAnim();
|
||
imgNodes[i].GO.SetActive(false);
|
||
CacheMiniChatSpriteGOBig.Enqueue(imgNodes[i].GO);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
if (!all)
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除动态表情缓存,实际上是关闭协程
|
||
/// </summary>
|
||
public void ClearDynamicExpresion()
|
||
{
|
||
destoryChatNode(ref DynamicExpresion, true);
|
||
destoryChatNode(ref DynamicBigExpresion, true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 销毁聊天节点
|
||
/// </summary>
|
||
/// <param name="nodes"></param>
|
||
private void destoryChatNode(ref List<ChatNode> nodes, bool clearList = false)
|
||
{
|
||
for (int i = 0; i < nodes.Count; i++)
|
||
{
|
||
GameObject.Destroy(nodes[i].GO);
|
||
nodes[i].GO = null;
|
||
}
|
||
|
||
if (clearList)
|
||
{
|
||
nodes.Clear();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除频道GO数据,避免添加到scrollview后GO被替换或者数据被重置
|
||
/// </summary>
|
||
/// <param name="channel"></param>
|
||
public void ResetGameObjectDataByChannel(int channel)
|
||
{
|
||
if (!ChannelData.ContainsKey(channel))
|
||
{
|
||
return;
|
||
}
|
||
|
||
//先清除之前频道的gameobject数据
|
||
Queue<ChatNode[]>.Enumerator iterclear = ChannelData[channel].GetEnumerator();
|
||
while (iterclear.MoveNext())
|
||
{
|
||
ChatNode[] nodes = iterclear.Current;
|
||
for (int i = 0; i < nodes.Length; i++)
|
||
{
|
||
nodes[i].Destory();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 太多引用传值了,这里就做拷贝
|
||
/// </summary>
|
||
/// <param name="nodes"></param>
|
||
/// <returns></returns>
|
||
public ChatNode[] copyList(List<ChatNode> nodes)
|
||
{
|
||
ChatNode[] newNodes = new ChatNode[nodes.Count];
|
||
|
||
for (int i = 0; i < nodes.Count; i++)
|
||
{
|
||
newNodes[i] = new ChatNode(nodes[i]);
|
||
}
|
||
|
||
return newNodes;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 通过color id获取对应的label
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public object GetLabelByColorID(int id)
|
||
{
|
||
if (!ItemColorToLabelID.ContainsKey(id))
|
||
{
|
||
return null;
|
||
}
|
||
|
||
int labelId = ItemColorToLabelID[id];
|
||
|
||
if (!LabelSkinDic.ContainsKey(labelId) || labelId > _labelSkin.Length)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
return _labelSkin[labelId];
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过color id获取对应的label
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public string GetColorByColorID(int id)
|
||
{
|
||
if (!ItemColorIDToColorStr.ContainsKey(id))
|
||
{
|
||
return null;
|
||
}
|
||
|
||
string labelId = ItemColorIDToColorStr[id];
|
||
return labelId;
|
||
}
|
||
|
||
|
||
//附近玩家
|
||
public List<ChatPrivateInfo> GetNearPlayers()
|
||
{
|
||
List<ChatPrivateInfo> chatInfos = new List<ChatPrivateInfo>();
|
||
|
||
List<RemotePlayer> players = GameCenter.GameSceneSystem.ActivedScene.FindAll<RemotePlayer>();
|
||
if (players != null)
|
||
{
|
||
for (int i = 0; i < players.Count; i++)
|
||
{
|
||
ChatPrivateInfo info = new ChatPrivateInfo();
|
||
info.ID = players[i].ID;
|
||
info.Name = players[i].Name;
|
||
info.Occ = (int)players[i].Occ;
|
||
info.Level = players[i].Level;
|
||
|
||
chatInfos.Add(info);
|
||
}
|
||
}
|
||
|
||
return chatInfos;
|
||
}
|
||
|
||
//好友数据
|
||
public List<ChatPrivateInfo> GetFriends()
|
||
{
|
||
//List<MyFriendInfo> friends = GameCenter.FriendSystem.FriendList;
|
||
List<ChatPrivateInfo> chatInfos = new List<ChatPrivateInfo>();
|
||
//if (friends != null)
|
||
//{
|
||
// for (int i = 0; i < friends.Count; i++)
|
||
// {
|
||
// ChatPrivateInfo info = new ChatPrivateInfo();
|
||
// info.ID = friends[i].PlayerID;
|
||
// info.Name = friends[i].Name;
|
||
|
||
// chatInfos.Add(info);
|
||
// }
|
||
//}
|
||
|
||
return chatInfos;
|
||
}
|
||
|
||
//移动到目标点
|
||
public void MoveTo(ChatNode node)
|
||
{
|
||
if (node.Type != (int)TNodeType.Position)
|
||
{
|
||
return;
|
||
}
|
||
|
||
string[] position = node.Position.Split(',');
|
||
|
||
int mapId = 0;
|
||
int.TryParse(node.Param2, out mapId);
|
||
|
||
float pX = 0;
|
||
float pY = 0;
|
||
float.TryParse(position[0], out pX);
|
||
float.TryParse(position[1], out pY);
|
||
|
||
//GameCenter.GameSceneSystem.GetLocalPlayer().blackboard.MapMove.Write2D(mapId, new Vector2(pX, pY), 0.0f, true);
|
||
GameCenter.PathSearchSystem.SearchPathToPos(mapId, new Vector3(pX, 0, pY));
|
||
}
|
||
|
||
public void TransTo(ChatNode node)
|
||
{
|
||
int mapid = -1;
|
||
int type = 0;
|
||
if (node.Param2.IndexOf("_") > 0)
|
||
{
|
||
string[] args = node.Param2.Split('_');
|
||
mapid = int.Parse(args[0]);
|
||
type = int.Parse(args[1]);
|
||
}
|
||
|
||
string[] position = node.Position.Split(',');
|
||
|
||
float pX = 0;
|
||
float pY = 0;
|
||
float.TryParse(position[0], out pX);
|
||
float.TryParse(position[1], out pY);
|
||
|
||
//先传送到对应地图在寻路过去
|
||
GameCenter.PathSearchSystem.SearchPathToPos(mapid, new Vector3(pX, 0, pY));
|
||
}
|
||
|
||
public void CloneMapTransTo(ChatNode node)
|
||
{
|
||
int mapid = -1;
|
||
long cloneMapId = 0;
|
||
try
|
||
{
|
||
if (node.Param2.IndexOf("_") > 0)
|
||
{
|
||
string[] args = node.Param2.Split('_');
|
||
mapid = int.Parse(args[0]);
|
||
cloneMapId = long.Parse(args[1]);
|
||
}
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
//UnityEngine.Debug.LogError("Chat trans fail: format error: " + node.Param2);
|
||
UnityEngine.Debug.LogError(ex.Message);
|
||
return;
|
||
}
|
||
|
||
string[] position = node.Position.Split(',');
|
||
|
||
float pX = 0;
|
||
float pY = 0;
|
||
float.TryParse(position[0], out pX);
|
||
float.TryParse(position[1], out pY);
|
||
|
||
//先传送到对应地图在寻路过去
|
||
GameCenter.PathSearchSystem.SearchPathToPos(mapid, new Vector3(pX, 0, pY), cloneMapId);
|
||
}
|
||
|
||
public string RemoveColorTag(string text, List<ChatColorFlag> colorflags)
|
||
{
|
||
int start = 0;
|
||
int end = 0;
|
||
if (colorflags != null)
|
||
{
|
||
colorflags.Clear();
|
||
}
|
||
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
||
end = text.IndexOf("[", start);
|
||
while (end >= 0)
|
||
{
|
||
var nextTag = text.IndexOf("[", end + 1);
|
||
if (nextTag - end == 1)
|
||
{
|
||
end = nextTag;
|
||
continue;
|
||
}
|
||
int offset = text.IndexOf("]", end) - end;
|
||
if (offset < 0)
|
||
{
|
||
break;
|
||
}
|
||
|
||
sb.Append(text.Substring(start, end - start));
|
||
string colorTag = text.Substring(end, offset + 1);
|
||
if (offset == 7)
|
||
{
|
||
//不在颜色区间中
|
||
if (colorTag.CompareTo("[000000]") < 0 || colorTag.CompareTo("[ffffff]") > 0)
|
||
{
|
||
sb.Append(colorTag);
|
||
}
|
||
else
|
||
{
|
||
ChatColorFlag flag = new ChatColorFlag();
|
||
flag.ColorText = colorTag;
|
||
flag.Left = end;
|
||
colorflags.Add(flag);
|
||
}
|
||
}
|
||
else if (offset == 2)
|
||
{
|
||
if (colorTag != "[-]")
|
||
{
|
||
sb.Append(colorTag);
|
||
}
|
||
else
|
||
{
|
||
ChatColorFlag flag = new ChatColorFlag();
|
||
flag.ColorText = colorTag;
|
||
flag.Left = end;
|
||
colorflags.Add(flag);
|
||
}
|
||
}
|
||
else
|
||
sb.Append(colorTag);
|
||
|
||
start = end + offset + 1;
|
||
|
||
end = text.IndexOf("[", start);
|
||
}
|
||
|
||
sb.Append(text.Substring(start));
|
||
return sb.ToString();
|
||
}
|
||
|
||
public string GetTranlateLan()
|
||
{
|
||
string ret = "zh-CN";
|
||
if (LanguageSystem.Lang == LanguageConstDefine.CH)
|
||
ret = "zh-CN";
|
||
else if (LanguageSystem.Lang == LanguageConstDefine.TW)
|
||
ret = "zh-TW";
|
||
else if (LanguageSystem.Lang == LanguageConstDefine.EN)
|
||
ret = "en";
|
||
else if (LanguageSystem.Lang == LanguageConstDefine.KR)
|
||
ret = "ko";
|
||
else if (LanguageSystem.Lang == LanguageConstDefine.VIE)
|
||
ret = "vi";
|
||
else if (LanguageSystem.Lang == LanguageConstDefine.JP)
|
||
ret = "ja";
|
||
else if (LanguageSystem.Lang == LanguageConstDefine.TH)
|
||
ret = "th";
|
||
return ret;
|
||
}
|
||
|
||
public string CheckLan(string str)
|
||
{
|
||
bool checkJp = false;
|
||
string ret = string.Empty;
|
||
Regex regChina = new Regex("^[^\x00-\xFF]");
|
||
Regex regEnglish = new Regex("^[a-zA-Z]");
|
||
if (regEnglish.IsMatch(str))
|
||
{
|
||
ret = "en";
|
||
}
|
||
else
|
||
{
|
||
//检查语言
|
||
for (int i = 0; i < str.Length; ++i)
|
||
{
|
||
var ch = str[i];
|
||
if (ch >= '\x0102' && ch <= '\x1EF1')
|
||
{
|
||
//越南文
|
||
ret = "vi";
|
||
break;
|
||
}
|
||
if (ch >= '\x0E00' && ch <= '\x0E7F')
|
||
{
|
||
//泰文
|
||
ret = "th";
|
||
break;
|
||
}
|
||
if (!checkJp)
|
||
{
|
||
if (ch >= '\x4E00' && ch <= '\x9FD5')
|
||
{
|
||
//中文
|
||
ret = "zh-CN";
|
||
checkJp = true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (ch >= '\x3040' && ch <= '\x309F')
|
||
{
|
||
//针对性的检查一下是否是日文
|
||
ret = "ja";
|
||
break;
|
||
}
|
||
if (ch >= '\x30A0' && ch <= '\x30FF')
|
||
{
|
||
//针对性的检查一下是否是日文
|
||
ret = "ja";
|
||
break;
|
||
}
|
||
if (ch >= '\x31F0' && ch <= '\x31FF')
|
||
{
|
||
//针对性的检查一下是否是日文
|
||
ret = "ja";
|
||
break;
|
||
}
|
||
|
||
}
|
||
if (ch >= '\xAC00' && ch <= '\xD7AF')
|
||
{
|
||
//韩文
|
||
ret = "ko";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
public void Update(float dt)
|
||
{
|
||
if (CacheMsgTick > 0)
|
||
{
|
||
CacheMsgTick -= dt;
|
||
}
|
||
else
|
||
{
|
||
CacheMsgTick = 0;
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|