123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public class ShopPanel : PopUpPanel
- {
- public GameObject itemPrefab;
- public RectTransform container;
- private List<BuyItemData> dataList;
- private const int countPrePage = 10;
- private int totalPage;
- private int currentPage;
- private BuyUtil.ItemType itemType = BuyUtil.ItemType.None;
- void Awake()
- {
- currentPanel = this;
- }
- void OnDestroy()
- {
- currentPanel = null;
- HaloManager.GetInstance().SyncEquipId();
- }
- // Use this for initialization
- void OnDisable ()
- {
- // ShowItemList(itemType);
- HaloManager.GetInstance().SyncEquipId();
- }
- public void ShowItemList(BuyUtil.ItemType itemType)
- {
- if(this.itemType == BuyUtil.ItemType.Halo)
- HaloManager.GetInstance().SyncEquipId();
- this.itemType = itemType;
- if(itemType == BuyUtil.ItemType.Halo)
- {
- InitHaloData();
- }
- }
- private void InitHaloData()
- {
- HaloManager.GetInstance().RecordStartEquipId();
- HaloManager.GetInstance().RequestDataList(()=>{
- List<HaloData> list = HaloManager.GetInstance().GetDataList();
- dataList = new List<BuyItemData>();
- for(int i=0; i<list.Count; i++)
- {
- HaloData haloData = list[i];
- HaloItemData haloItemData = new HaloItemData(haloData);
- dataList.Add(haloItemData);
- }
- totalPage = dataList.Count/countPrePage;
- totalPage = Mathf.Max(1, totalPage);
-
- ShowPage(0);
- });
- }
- public void ShowPage(int page)
- {
- currentPage = NumberUtil.forceBetween(page, 0, totalPage-1);
- int start = page * countPrePage;
- for(int i=0; i<countPrePage; i++)
- {
- BuyItemData data = null;
- if(start + i < dataList.Count)
- {
- data = dataList[i];
- }
- BuyItem item = null;
- if(i < container.transform.childCount)
- {
- item = container.transform.GetChild(i).GetComponent<BuyItem>();
- }
- else if(data != null)
- {
- GameObject itemObj = Instantiate<GameObject>(itemPrefab);
- PopUpManager.AddToMainCanvas(itemObj, container);
- item = itemObj.GetComponent<BuyItem>();
- }
- if(data == null && item != null)
- {
- item.gameObject.SetActive(false);
- }
- else if(data != null)
- {
- item.gameObject.SetActive(true);
- item.Init(data);
- }
- }
- }
- // public void OnValueChange(Vector2 pos)
- // {
- // Debuger.Log(pos);
- // scrollbar.value = 0;
- // }
- public void UpdateInfo()
- {
- for(int i=0; i<container.childCount; i++)
- {
- container.GetChild(i).GetComponent<BuyItem>().UpdatePrice();
- }
- }
- public static ShopPanel currentPanel;
- public static ShopPanel Show()
- {
- if(currentPanel != null)
- {
- PopUpManager.AddToMainCanvas(currentPanel.gameObject);
- return currentPanel;
- }
- GameObject panelObj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/UI/Shop/ShopPanel"));
- panelObj.GetComponent<ShopPanel>();
- PopUpManager.AddToMainCanvas(panelObj);
- return currentPanel;
- }
- public static void Hide()
- {
- if(currentPanel != null)
- currentPanel.Close();
- }
- public static void Refresh()
- {
- if(currentPanel != null)
- {
- currentPanel.UpdateInfo();
- }
- }
- }
|