using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using GCGame.Table; using Games.Item; using Module.Log; // 礼包物品选择控制 public class GiftBagChooseCtr : MonoBehaviour { public UIContainerMultiSelect itemContainer; // 物品列表容器 public Button confirmBtn; // 确认按钮 public Button cancelBtn; // 取消按钮 public UIBackRayBehind bgMask; // 背景遮罩(点击空白取消功能) public UIImgText needSelectCount; // 需要选择的数量 private int itemID; // 物品id,服务端用,需要原封返回 private int scriptID; // 物品脚本ID,服务端用,需要原封返回 private int chooseNum; // 需要选择数目 private static GiftBagChooseCtr _instance; // Single public static GiftBagChooseCtr Instance { get { return _instance; } } private void Awake() { if(_instance == null) { _instance = this; } // 按钮相关初始化 if(confirmBtn == null || cancelBtn == null) { LogModule.ErrorLog("Need sepcify confirmBtn and cancelBtn !!!"); } else { confirmBtn.onClick.AddListener(ConfirmAward); cancelBtn.onClick.AddListener(Close); } if(bgMask != null) { bgMask._BackClick.AddListener(Close); } } private void OnEnable() { itemID = -1; scriptID = -1; chooseNum = -1; } private void OnItemSelect(object item) { List selects = itemContainer.GetSelecteds(); SpecialGiftSelectInfo selectObj = item as SpecialGiftSelectInfo; if(selects != null && selectObj != null) { int index = selects.IndexOf(selectObj); if (selects.Count == chooseNum && index == -1) { GUIData.AddNotifyData("超出可选择数量,重复点击可取消选中!"); } } ItemTooltipsLogic.ShowItemTooltip(selectObj.itemid, ItemTooltipsLogic.ShowType.Info, Vector3.zero); } public void Show(object packet) { ReqSpecialGiftSelect data = packet as ReqSpecialGiftSelect; if (data == null) { return; } itemID = data.itemid; scriptID = data.script; chooseNum = data.selectcount; if (itemContainer != null) { itemContainer._IsMultiSelect = true; itemContainer.multiSelectNum = chooseNum; itemContainer.InitSelectContent(data.info, null, OnItemSelect); } else { LogModule.ErrorLog("No container !!!"); } needSelectCount.text = chooseNum.ToString(); } #region 接收发送协议 // 确认礼包 private void ConfirmAward() { List selectItems = itemContainer.GetSelecteds(); if(selectItems.Count < chooseNum) { GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{86718}", chooseNum)); return; } if(selectItems.Count == chooseNum) { if(IsNeedRandomPanel(itemID)) { UIManager.CloseUI(UIInfo.BackPackRoot); UIManager.ShowUI(UIInfo.GiftBagRandomPanel); } List indexList = new List(); for (int i = 0; i < selectItems.Count; ++i) { indexList.Add(selectItems[i].index); } RetSpecialGiftSelect packet = new RetSpecialGiftSelect(); packet.itemid = itemID; packet.script = scriptID; packet.indexlist = indexList; packet.SendMsg(); Close(); } } // 检查物品是否需要随机面板 public bool IsNeedRandomPanel(int itemID) { Tab_CommonItem tab = TableManager.GetCommonItemByID(itemID, 0); if(tab != null) { if(tab.ClassID == (int)ItemClass.GIFTBAG && tab.SubClassID == (int)GiftBagSubType.MultiSelection_Random) { return true; } } return false; } #endregion private void Close() { UIManager.CloseUI(UIInfo.GiftBagItemChooseCtr); } private void OnDestroy() { _instance = null; } }