using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; using GCGame; using GCGame.Table; public class HornInputPanelCtr : MonoBehaviour { public Image _TiltleImage; public List _SpriteList; public static HornInputPanelCtr Instance; private void Awake() { Instance = this; _InputText.onValueChanged.AddListener(OnInputChange); } private void OnDestroy() { Instance = null; } //public Text remainWordText; //剩余字数 public InputField _InputText; public Button emojBtn; //public GameObject motionPanel; private List _ChatLinks = new List(); public void CloseWindow() { UIManager.CloseUI(UIInfo.HornEmojiRoot); UIManager.CloseUI(UIInfo.HornInputPanel); } private int _SubClassType = -1; public void RecordHornType(int subClassType) { _SubClassType = subClassType; var spIndex = 0; switch(_SubClassType) { case (int)Games.Item.PrizeSubClass.SPEAKER: spIndex = 0; break; case (int)Games.Item.PrizeSubClass.AllSERVERHORN: spIndex = 1; break; case (int)Games.Item.PrizeSubClass.CROSSSERVERHORN: spIndex = 2; break; } _TiltleImage.overrideSprite = _SpriteList[spIndex]; _TiltleImage.SetNativeSize(); } public void OnEmojiClick(int emojiID) { var chatLink = ChatLinkBase.CreateChatLink(emojiID); if (_InputText.text.Length + chatLink.StrInput.Length > _InputText.characterLimit) { return; } else { _ChatLinks.Add(chatLink); chatLink.StartPosInText = _InputText.text.Length; _InputText.text += chatLink.StrInput; chatLink.EndPosInText = _InputText.text.Length; } } public void OnInputChange(string newInput) { if (newInput.Length == 0) { _ChatLinks.Clear(); } } private bool hasOpenEmojiUI = false; public void OnEmojBtnClick() { if (!hasOpenEmojiUI) { HornEmojiLogic.ShowChatEmoji(_InputText, _ChatLinks); }else { UIManager.CloseUI(UIInfo.HornEmojiRoot); } hasOpenEmojiUI = !hasOpenEmojiUI; } public void OnSubmitBtnClick() { PopHornInfo(); } public void PopHornInfo() { //判断输入的名字 if (string.IsNullOrEmpty(_InputText.text)) { GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{46207}")); return; } string strCurName = ""; // 过滤掉 0 非法字符 foreach (char curChar in _InputText.text) { if ((int)curChar != 0) { strCurName += curChar; } } if (string.IsNullOrEmpty(strCurName)) { GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{46207}")); return; } int curCharNum = 0; // 英文算一个,中文算两个 foreach (char curChar in strCurName) { if ((int)curChar >= 128) { curCharNum += 2; } else if ((int)curChar >= 65 && (int)curChar <= 90) { curCharNum += 2; } else { curCharNum++; } // curCharNum += 2; if (char.IsWhiteSpace(curChar)) { MessageBoxLogic.OpenOKBox(46227, 1000); return; } } if (_InputText.text.Contains("*")) { MessageBoxLogic.OpenOKBox(1278, 1000); return; } if (_InputText.text.Contains("*")) { MessageBoxLogic.OpenOKBox(1278, 1000); return; } if (null == Utils.GetStrFilter(strCurName, (int)Games.GlobeDefine.GameDefine_Globe.STRFILTER_TYPE.STRFILTER_CHAT)) { //Utils.SendLoudSpeaker(ModifyText(_InputText.text), 1); //发送协议 CG_CHAT packet = (CG_CHAT)PacketDistributed.CreatePacket(MessageID.PACKET_CG_CHAT); switch(_SubClassType) { case (int)Games.Item.PrizeSubClass.SPEAKER: packet.Chattype = (int)CG_CHAT.CHATTYPE.CHAT_TYPE_LOUDSPEAKER; break; case (int)Games.Item.PrizeSubClass.AllSERVERHORN: packet.Chattype = (int)CG_CHAT.CHATTYPE.CHAT_TYPE_ALLSERSPEAKER; break; case (int)Games.Item.PrizeSubClass.CROSSSERVERHORN: packet.Chattype = (int)CG_CHAT.CHATTYPE.CHAT_TYPE_CROSSSERSPEAKER; break; } packet.Chatinfo = ModifyText(_InputText.text); packet.LoudSpeakerNum = 1; packet.SendPacket(); CloseWindow(); } else { // 包含非法字符 MessageBoxLogic.OpenOKBox(1278, 1000); } } string ModifyText(string inputText) { string newInputText = inputText; int replaceIdx = 0; for (int i = 0; i < _ChatLinks.Count; ++i) { if (replaceIdx < 0 || replaceIdx >= newInputText.Length) { continue; } replaceIdx = newInputText.IndexOf(_ChatLinks[i].StrInput, replaceIdx); if (replaceIdx < 0 || replaceIdx >= newInputText.Length) { continue; } newInputText = newInputText.Remove(replaceIdx, _ChatLinks[i].StrInput.Length); newInputText = newInputText.Insert(replaceIdx, _ChatLinks[i].StrSend); //newInputText = newInputText.Replace(_ChatLinks[i].StrInput, _ChatLinks[i].StrSend); } //newInputText += inputText.Substring(newInputEnd, inputText.Length - newInputEnd); return Utils.StrFilter_Chat(newInputText); ; } private void OnDisable() { _InputText.text = ""; hasOpenEmojiUI = false; _ChatLinks.Clear(); } }