//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, December 10, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class GatherSoulWin : Window { [SerializeField] GatherSoulHoleBehaviour[] m_GatherSoulHoles; [SerializeField] Text[] m_baseAttrText; [SerializeField] ScrollerController m_AttrScrollerControl; [SerializeField] Text m_SoulDust; [SerializeField] ScrollerController m_ScrollerControl; [SerializeField] Button m_GetSoul; [SerializeField] Button m_BattlePass; GatheringSoulModel model { get { return ModelCenter.Instance.GetModel(); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { m_BattlePass.AddListener(() => { //WindowCenter.Instance.Open(); WindowJumpMgr.Instance.WindowJumpToEx("GatheringSoulZhanLingWin"); }); m_GetSoul.AddListener(() => { WindowJumpMgr.Instance.WindowJumpToEx("GatherSoulBaseWin", 0, 0, 1); }); } protected override void OnPreOpen() { model.selectEmptyHole = 0; model.SortGatherSoulPack(); model.UpdateSoulInfos += UpdateSoulInfo; model.OnGatherSoulHoleRefresh += UpdateHoleInfo; m_AttrScrollerControl.OnRefreshCell += OnRefreshCell; PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent; m_ScrollerControl.OnRefreshCell += OnRefreshPackCell; model.OnSelectEmptyHoleChange += ClickEmptyHole; } protected override void OnAfterOpen() { Display(); } protected override void OnPreClose() { model.UpdateSoulInfos -= UpdateSoulInfo; model.OnGatherSoulHoleRefresh -= UpdateHoleInfo; m_AttrScrollerControl.OnRefreshCell -= OnRefreshCell; PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent; m_ScrollerControl.OnRefreshCell -= OnRefreshPackCell; model.OnSelectEmptyHoleChange -= ClickEmptyHole; } protected override void OnAfterClose() { } #endregion void Display() { DisplayHole(); DisplayAttr(); m_SoulDust.text = UIHelper.GetMoneyCnt(44).ToString(); DisplayPack(); } void DisplayHole() { for (int i = 0; i < m_GatherSoulHoles.Length; i++) { m_GatherSoulHoles[i].Display(); } } void UpdateHoleInfo() { DisplayHole(); DisplayPack(); } void UpdateSoulInfo(bool noChangeCnt) { DisplayHole(); DisplayAttr(); if (noChangeCnt) { m_ScrollerControl.m_Scorller.RefreshActiveCellViews(); } else { DisplayPack(); } } void DisplayAttr() { var attrDict = model.GetAllSoulAttr(); for (int i = 0; i < m_baseAttrText.Length; i++) { int id = model.baseAttrArray[i]; m_baseAttrText[i].text = PlayerPropertyConfig.GetFullDescription(id, attrDict.ContainsKey(id) ? attrDict[id] : 0); } CreateAttrScroller(); } void CreateAttrScroller() { m_AttrScrollerControl.Refresh(); for (int i = 0; i < model.attrIDList.Count; i++) { if (i % 3 == 0) m_AttrScrollerControl.AddCell(ScrollerDataType.Header, i); } m_AttrScrollerControl.Restart(); } void CreatePackScroller() { m_ScrollerControl.Refresh(); var soulPack = model.GetGatherSoulPack(); for (int i = 0; i < soulPack.Count; i++) { if (i % 4 == 0) m_ScrollerControl.AddCell(ScrollerDataType.Header, i); } m_ScrollerControl.Restart(); } void DisplayPack() { var soulPack = model.GetGatherSoulPack(); if (soulPack.IsNullOrEmpty()) { m_GetSoul.SetActive(true); m_ScrollerControl.SetActive(false); } else { m_GetSoul.SetActive(false); m_ScrollerControl.SetActive(true); CreatePackScroller(); } } private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType) { if (refreshType == PlayerDataType.default35) { m_SoulDust.text = UIHelper.GetMoneyCnt(44).ToString(); } } private void OnRefreshPackCell(ScrollerDataType type, CellView cell) { var packCell = cell as GatherSoulPackCell; packCell.Display(cell.index); } void OnRefreshCell(ScrollerDataType type, CellView cell) { var _cell = cell as GatherSoulAttrCell; _cell.Display(cell.index); } void ClickEmptyHole() { model.SortGatherSoulPack(); m_ScrollerControl.m_Scorller.RefreshActiveCellViews(); Clock.AlarmAfter(0.1f, () => { m_ScrollerControl.JumpIndex(0); }); } } }