using System.Collections; using System.Collections.Generic; using Games.ChatHistory; using Games.GlobeDefine; using GCGame; using GCGame.Table; using Module.Log; using UnityEngine; public class ChatHelperInfo { public ChatHistoryItem ChatItem; public Tab_ChatHelper HelperRecord; public string KeyWord; } public class ChatHelperRoot : UIControllerBase { private void Start() { SetInstance(this); } private void OnEnable() { _TagPanel.ShowPage(0); InitHotPage(); gameObject.GetComponent().SetAsFirstSibling(); } private void OnDestroy() { SetInstance(null); } #region public static void ShowChatHelperStr(string showKeyWord) { UIManager.ShowUI(UIInfo.ChatHelperRoot, (sucess, uiObj) => { if (sucess) Instance().OnInputQ(showKeyWord); }); } #endregion public void Close() { UIManager.CloseUI(UIInfo.ChatHelperRoot); } #region public UITagPanel _TagPanel; public ChatInputLogic _ChatInputLogic; public ChatHistoryLogicHelper _ChatHistoryLogic; private readonly Dictionary _QADict = new Dictionary(); public void OnInputQ(string strQuestion) { if (string.IsNullOrEmpty(strQuestion)) return; _TagPanel.ShowPage(1); var chatHelperRecords = TableManager.GetChatHelper().Values; var strDictID = -1; Tab_ChatHelper actRecord = null; foreach (var chatHelperRecord in chatHelperRecords) if (strQuestion.Contains(chatHelperRecord.KeyWord)) { actRecord = chatHelperRecord; strDictID = chatHelperRecord.ValueWord; } var qChatHistory = new ChatHistoryItem(); qChatHistory.CleanUp(); qChatHistory.SenderGuid = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid; qChatHistory.SenderName = ""; qChatHistory.SenderIcon = Utils.GetProfessionSpriteName(GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession); qChatHistory.SenderPro = 0; qChatHistory.SenderVIPLevel = 0; qChatHistory.SenderPrivilegeVIP = 0; qChatHistory.SenderLevel = 0; qChatHistory.ChatInfo = strQuestion; qChatHistory.EChannel = GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND; _ChatHistoryLogic.OnReceiveChat(qChatHistory); var history = new ChatHistoryItem(); history.CleanUp(); history.SenderGuid = GlobeVar.SYSFRIEND_GUID; history.SenderName = ""; history.SenderIcon = Utils.GetSysIconName(Utils.SysIconType.AI); history.SenderPro = 0; history.SenderVIPLevel = 0; history.SenderPrivilegeVIP = 0; history.SenderLevel = 0; history.EChannel = GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND; if (strDictID < 0) { history.ChatInfo = StrDictionary.GetClientDictionaryString("#{84904}"); } else { history.ChatInfo = StrDictionary.GetClientDictionaryString("#{" + strDictID + "}"); var chatHelperInfo = new ChatHelperInfo(); chatHelperInfo.KeyWord = strQuestion; chatHelperInfo.HelperRecord = actRecord; chatHelperInfo.ChatItem = history; _QADict.Add(history, chatHelperInfo); } _ChatHistoryLogic.OnReceiveChat(history); } public void OnQSolved(ChatHistoryItem qChatItem, bool isSolved) { if (!_QADict.ContainsKey(qChatItem)) return; StartCoroutine(NotifyServer(_QADict[qChatItem].KeyWord, isSolved ? 1 : 0)); } private IEnumerator NotifyServer(string keyWord, int isQSolved) { //string imgUrl = SystemParam.GetSystemParam_STRING(40); var imgUrl = ControllUrlManager.FQAKeywordUrl; Debug.Log(imgUrl); var form = new WWWForm(); var timeStamp = Utils.GetTimeStamp(); var randomStr = Utils.GetRandomStr(); var sign = Utils.GetSignString(timeStamp, randomStr, Community.Instance._ApiKey); form.AddField("timestamp", timeStamp); form.AddField("nonce_str", randomStr); form.AddField("sign", sign); form.AddField("guid", GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid.ToString()); form.AddField("keyword", keyWord); form.AddField("solve", isQSolved); // Upload to a cgi script var w = new WWW(imgUrl, form); yield return w; if (!string.IsNullOrEmpty(w.error)) LogModule.ErrorLog("chat helper NotifyServer error:" + w.error + ", " + imgUrl); else LogModule.DebugLog(w.text); } public void OnShareHelper(int chatType, ChatHistoryItem qChatItem) { if (!_QADict.ContainsKey(qChatItem)) return; var keyWord = _QADict[qChatItem].HelperRecord.KeyWord; if (!ChatInputLogic.IsCanChat(chatType)) return; var item = new ChatHistoryItem(); item.CleanUp(); item.EChannel = (GC_CHAT.CHATTYPE) chatType; var chatLink = new ChatLinkCallFunc(); var showText = StrDictionary.GetClientDictionaryString("#{84903}", keyWord); chatLink.SetLinkCallFunc(showText, "ChatHelperRoot", "ShowChatHelperStr", keyWord); item.ChatInfo = chatLink.StrSend; Utils.SendCGChatPak(item.ChatInfo, item); } #endregion ask page #region hot page public UIContainerBase _HotContainer; private void InitHotPage() { _HotContainer.InitContentItem(TableManager.GetChatHelperHot().Keys, OnHotItemClick); } private void OnHotItemClick(object hotGO) { var hotItemIdx = (int) hotGO; var hotRecord = TableManager.GetChatHelperHotByID(hotItemIdx); OnInputQ(hotRecord.KeyWord); } #endregion }