using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using GCGame.Table; public class InteractionPanelCtr : MonoBehaviour { public static InteractionPanelCtr Instance; private void Awake() { Instance = this; } private void OnEnable() { ShowDefaultFirst(); } void ShowDefaultFirst() { OnMenuItemClick(1); } private void OnDestroy() { Instance = null; } public Image _bgIcon; //根据类型分类s public List _bgIconlist; public List _titleIconlist; public List _markIconList; public UIContainerBase _nodeItemContainer; public UIContainerBase _finalRewContainer; public Text _finalRewDesc; public List _bigBGList; public List _subBGList; public List _btnList; public List _btnDesc; public List _menuItemRedIconList = new List(); public GameObject _finalRewRedIcon; private int _CurSelectType = -1; //默认值 public void OnMenuItemClick(int _Index) { if(_Index == 1) { _bigBGList[0].SetActive(true); _bigBGList[1].SetActive(false); _subBGList[0].SetActive(false); _subBGList[1].SetActive(false); } else { _bigBGList[0].SetActive(false); _bigBGList[1].SetActive(true); _subBGList[0].SetActive(false); _subBGList[1].SetActive(true); } for(int index = 0; index < _titleIconlist.Count; index++) { _titleIconlist[index].SetActive(index + 1 == _Index); } if (_CurSelectType == _Index) return; _CurSelectType = _Index; //服务器要从1开始,这边用来做下标要-1 for(int index = 0; index < _markIconList.Count; index++) { _markIconList[index].SetActive(index + 1 == _Index); } if (_Index != 1) { _bgIcon.overrideSprite = _bgIconlist[_CurSelectType - 1]; StartCoroutine(ShowPage()); } } private int _clickWait; IEnumerator ShowPage() { yield return new WaitForEndOfFrame(); var _typeDic = TableManager.GetInteractionNode(); //初始化Item Tab_InteractionNode node; if (_typeDic.TryGetValue(_CurSelectType, out node)) { var array = new[]{ node }; _nodeItemContainer.InitContentItem(array); } var interactionSummaryTab = TableManager.GetInteractionSummaryByID(_CurSelectType, 0); if (interactionSummaryTab == null) yield break; _clickWait = interactionSummaryTab.CD; _finalRewDesc.text = interactionSummaryTab.Title; List _finalRewList = new List(); for (int index = 0; index < interactionSummaryTab.getRewardCount(); index++) { _finalRewList.Add(new InteractionRewItem.InteractionRewItemData( interactionSummaryTab.GetRewardbyIndex(index), interactionSummaryTab.GetNumbyIndex(index))); } _finalRewContainer.InitContentItem(_finalRewList); for(int index = 0; index < interactionSummaryTab.getInteractionBtnCount(); index++) { _btnList[index].SetActive(!interactionSummaryTab.GetInteractionBtnbyIndex(index).Equals("-1")); _btnDesc[index].text = interactionSummaryTab.GetInteractionBtnbyIndex(index); } ReqInteractionState(); yield break; } public void OnIneractionBtnClick(int index) { if (GlobalData._InteractionLastMessageTime == 0) //第一次点击 { GlobalData._InteractionLastMessageTime = Time.realtimeSinceStartup; } else //第二次判断时差 { if(Time.realtimeSinceStartup - GlobalData._InteractionLastMessageTime >= _clickWait) { GlobalData._InteractionLastMessageTime = Time.realtimeSinceStartup; } else { GUIData.AddNotifyData("#{1076}"); return; } } ReqInteractionPublishInfo req = new ReqInteractionPublishInfo(); req._type = _CurSelectType; req._strIndex = index + 1; req.SendMsg(); //打开对应界面 StartCoroutine(ShowFunctionPage()); } IEnumerator ShowFunctionPage() { yield return new WaitForEndOfFrame(); switch (_CurSelectType - 1) { case 0: UIManager.ShowUI(UIInfo.MarryRoot); break; case 1: //师徒 StopAllCoroutines(); StartCoroutine(ShowFunction(1)); break; case 2://结义 StopAllCoroutines(); StartCoroutine(ShowFunction(2)); break; } yield break; } IEnumerator ShowFunction(int index) { yield return new WaitForEndOfFrame(); switch(index) { case 1: //师徒 UIManager.ShowUI(UIInfo.FriendAndMail, delegate (bool bSucess, object param) { FriendAndMailRoot.Instance()._TagPanel.ShowPage(2); //师徒 }); break; case 2://结义 UIManager.ShowUI(UIInfo.FriendAndMail, delegate (bool bSucess, object param) { FriendAndMailRoot.Instance()._TagPanel.ShowPage(1); //结义 }); break; } yield break; } public void ReqInteractionState() { ReqInteraction req = new ReqInteraction(); req._type = _CurSelectType; req.SendMsg(); } private RetInteractionState _nodeItemSatePacket; private Dictionary _nodeItemStateDic = new Dictionary(); public void OnStatePacket(RetInteractionState packet) { _nodeItemSatePacket = packet; RefreshMenuitemRedIconState(); if(packet._type == 1) { if (MarryInteractionPanelCtr.Instance) MarryInteractionPanelCtr.Instance.OnPacket(packet); return; } RefreshFinalRewState(); for (int index = 0; index < packet._itemStateList.Count; index++) { if (_nodeItemStateDic.ContainsKey(packet._itemStateList[index]._nodeId)) { _nodeItemStateDic[packet._itemStateList[index]._nodeId] = packet._itemStateList[index]._state; } else { _nodeItemStateDic.Add(packet._itemStateList[index]._nodeId, packet._itemStateList[index]._state); } } var dictionary = TableManager.GetInteractionNode(); Tab_InteractionNode node; if (dictionary.TryGetValue(_CurSelectType, out node)) { var array = new[] { node }; _nodeItemContainer.InitContentItem(array); } _nodeItemContainer.ForeachActiveItem((item) => { for (int index = 0; index < packet._itemStateList.Count; index++) { if (item._interactionNodeId == packet._itemStateList[index]._nodeId) { item.InitState(packet._itemStateList[index]._state); } } }); } public void RefreshFinalRewState() { _finalRewRedIcon.SetActive(_nodeItemSatePacket._extraRewState == 1); } public void RefreshMenuitemRedIconState() { for(int index = 0; index < _nodeItemSatePacket._pageState.Count; index++) { _menuItemRedIconList[index].SetActive(_nodeItemSatePacket._pageState[index] == 1); } } public void OnFinalRewGetBtnClick() { ReqGetInteractionRew req = new ReqGetInteractionRew(); req._type = _CurSelectType; req._nodeId = 0; //特殊值 req.SendMsg(); } public void OnCloseBtnClick() { UIManager.CloseUI(UIInfo.InteractionPanel); } }