//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, September 13, 2017 //-------------------------------------------------------- using Snxxz.UI; using System; using System.Collections; using System.Collections.Generic; using TableConfig; using UnityEngine; using UnityEngine.UI; //装备捐献面板 namespace Snxxz.UI { public class DonateEquipTipsWin : Window { [SerializeField] ScrollerController _GridlineCtrl; [SerializeField] Button _CloseBtn; ItemTipsModel _itemTipsModel; ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel()); } } PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } PlayerFairyAuTreasureData m_PlayerFairyAuTreasureData; PlayerFairyAuTreasureData playerFairyAuTreasureData { get { return m_PlayerFairyAuTreasureData ?? (m_PlayerFairyAuTreasureData = ModelCenter.Instance.GetModel()); } } private int _BagIndex = 0;//标记背包物品下标 private int MaxDonationAmount = 0;//最大捐献数量 List phagocytosisID = new List();//存储可以捐献的物品 #region Built-in protected override void BindController() { MaxDonationAmount = int.Parse(Config.Instance.Get("FamilyStoreSpace").Numerical1)+1; } protected override void AddListeners() { _CloseBtn.onClick.AddListener(CloseButton); } protected override void OnPreOpen() { playerPack.RefreshItemCountAct += BackpackRefresh;//背包物品清理 _GridlineCtrl.OnRefreshCell += OnRefreshGridCell; Backpacking();//背包物品读取和创建 OnCreateGridLineCell(_GridlineCtrl); } protected override void OnAfterOpen() { } protected override void OnPreClose() { } protected override void OnAfterClose() { playerPack.RefreshItemCountAct -= BackpackRefresh;//背包物品清理 _GridlineCtrl.OnRefreshCell -= OnRefreshGridCell; } #endregion void CloseButton()//关闭按钮 { Close(); } void Backpacking()//物品读取 { Dictionary backpack_dic = playerPack.GetSinglePackModel(PackType.rptItem).GetPackModelIndexDict(); Dictionary _ProductOrderJudgment = new Dictionary(); phagocytosisID.Clear(); _ProductOrderJudgment = AttributeJudgment();///属性判断 if (backpack_dic.Count == 0)//得到背包的所有物品 return; foreach (int item_id in backpack_dic.Keys) { ItemConfig _ChinItem = Config.Instance.Get((int)backpack_dic[item_id].itemInfo.ItemID); if (backpack_dic[item_id].itemInfo.IsBind == 1) continue; foreach (int key in _ProductOrderJudgment.Keys) { if (_ChinItem.EquipPlace == key && _ChinItem.LV >= _ProductOrderJudgment[key].Class && _ChinItem.StarLevel >= _ProductOrderJudgment[key].TheStar && _ChinItem.ItemColor >= _ProductOrderJudgment[key].Color) { string IDnumber = backpack_dic[item_id].itemInfo.ItemID.ToString() + "|" + item_id.ToString();//添加ID和位置索引 phagocytosisID.Add(IDnumber); } } } } class ProductOrderJudgment { public int Class;//阶级 public int TheStar;//星级 public int Color;//颜色 } Dictionary AttributeJudgment()//属性判断 { Dictionary _DicConditions = new Dictionary();//条件字典 FuncConfigConfig Number1 = Config.Instance.Get("FamilyStoreItemRule1"); FuncConfigConfig Number2 = Config.Instance.Get("FamilyStoreItemRule2"); string[] strA = Number1.Numerical1.Split('|'); string[] strA1 = Number1.Numerical2.Split('|'); for (int i = 0; i < strA.Length; i++) { if (!_DicConditions.ContainsKey(int.Parse(strA[i]))) { ProductOrderJudgment _ProductOrder = new ProductOrderJudgment(); _ProductOrder.Class = int.Parse(strA1[0]); _ProductOrder.TheStar = int.Parse(strA1[1]); _ProductOrder.Color = int.Parse(strA1[2]); _DicConditions.Add(int.Parse(strA[i]), _ProductOrder); } } string[] strB = Number2.Numerical1.Split('|'); string[] strB1 = Number2.Numerical2.Split('|'); for (int j = 0; j < strB.Length; j++) { if (!_DicConditions.ContainsKey(int.Parse(strB[j]))) { ProductOrderJudgment _ProductOrder = new ProductOrderJudgment(); _ProductOrder.Class = int.Parse(strB1[0]); _ProductOrder.TheStar = int.Parse(strB1[1]); _ProductOrder.Color = int.Parse(strB1[2]); _DicConditions.Add(int.Parse(strB[j]), _ProductOrder); } } return _DicConditions; } void OnCreateGridLineCell(ScrollerController gridCtrl)//预制体创建 { gridCtrl.Refresh(); int Index = Mathf.CeilToInt((float)phagocytosisID.Count / 5); for (int i = 0; i < Index; i++) { gridCtrl.AddCell(ScrollerDataType.Header, i); } gridCtrl.Restart(); } void OnRefreshGridCell(ScrollerDataType type, CellView cell) { int line = cell.index; for (int i = 0; i < 5; i++) { int index = line * 5 + i; GameObject obj = cell.transform.GetChild(i).gameObject; ItemCell _itemCell = obj.transform.Find("ItemCell").GetComponent(); Button _ItemBtn = _itemCell.GetComponent