//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, December 11, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { [XLua.Hotfix] public class GatherSoulEquipListWin : Window { [SerializeField] RectTransform m_Container; [SerializeField] Button m_Close; [SerializeField] ScrollerController m_ScrollerControl; public static int selectHole = 0; bool existHoleItem = false; GatheringSoulModel model { get { return ModelCenter.Instance.GetModel(); } } List equipList = new List(); #region Built-in protected override void BindController() { } protected override void AddListeners() { m_Close.onClick.AddListener(CloseClick); m_ScrollerControl.OnRefreshCell += OnRefreshCell; } protected override void OnPreOpen() { GatherSoulItem item; if (model.TryGetItem(selectHole, out item)) { existHoleItem = true; } else { existHoleItem = false; } Display(); model.gatherSoulPackRefresh += GatherSoulPackRefresh; } protected override void OnAfterOpen() { } protected override void OnPreClose() { equipList.Clear(); model.gatherSoulPackRefresh -= GatherSoulPackRefresh; } protected override void OnAfterClose() { } #endregion private void OnRefreshCell(ScrollerDataType type, CellView cell) { var equipCell = cell as GatherSoulEquipCell; if (cell.index < equipList.Count) { equipCell.Display(equipList[cell.index], false); } } void Display() { GatherSoulItem item; if (model.TryGetItem(selectHole, out item)) { model.TryGetSatisfyReplaceSouls(selectHole, ref equipList); } else { model.TryGetSatisfyEquipSouls(selectHole, ref equipList); } EliminateSameItem(); equipList.Sort(model.CommonSort); m_ScrollerControl.Refresh(); for (int i = 0; i < equipList.Count; i++) { m_ScrollerControl.AddCell(ScrollerDataType.Header, i, EquipGatherSoul); } m_ScrollerControl.Restart(); } void EliminateSameItem() { List removeIndexs = new List(); for (int i = 0; i < equipList.Count; i++) { var item = equipList[i]; if (removeIndexs.Contains(i)) { continue; } for (int k = i + 1; k < equipList.Count; k++) { if (removeIndexs.Contains(k)) { continue; } var compare = item.Compare(equipList[k]); if (item.ExistSameProperty(equipList[k].id)) { if(compare == 1 || compare == 0) { removeIndexs.Add(k); } else { removeIndexs.Add(i); break; } } } } removeIndexs.Sort(); for (int i = removeIndexs.Count - 1; i >= 0; i--) { equipList.RemoveAt(removeIndexs[i]); } } private void GatherSoulPackRefresh() { Display(); } private void EquipGatherSoul(CellView cell) { if (cell.index < equipList.Count) { var item = equipList[cell.index]; GatherSoulItem holeItem; if(model.TryGetItem(selectHole,out holeItem)) { model.TryExecuteReplaceSoul(selectHole, item); } else { model.ExecuteEquipSoul(item, selectHole); } CloseImmediately(); } } } }