123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- using UnityEngine;
- using FairyGUI;
- using UI.LuckyBox;
- using System.Collections.Generic;
- namespace GFGGame
- {
- public class LuckyBoxBonusView : BaseWindow
- {
- private UI_LuckBoxBonusUI _ui;
- private List<ItemData> itemList;
- private int openCount = 0;
- private List<GameObject> _effects = new List<GameObject>();
- private List<GoWrapper> _wrappers = new List<GoWrapper>();
- private GameObject _effect;
- private GoWrapper _wrapper;
- public override void Dispose()
- {
- base.Dispose();
- for (int i = 0; i < _effects.Count; i++)
- {
- SceneController.DestroyObjectFromView(_effects[i], _wrappers[i]);
- }
- SceneController.DestroyObjectFromView(_effect, _wrapper);
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_LuckBoxBonusUI.PACKAGE_NAME;
- _ui = UI_LuckBoxBonusUI.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- InitAllItem();
- _ui.m_loaBg.onClick.Add(OnClickBg);
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bj_ckzxin");
- _ui.m_loaOpen.onClick.Add(OnClickOpen);
- }
- protected override void OnShown()
- {
- base.OnShown();
- itemList = (viewData as object[])[0] as List<ItemData>;
- if (itemList != null)
- {
- _ui.m_loaOpen.visible = true;
- int count = itemList.Count;
- if (count == 10)
- {
- _ui.m_c1.selectedIndex = 1;
- }
- else if (count > 0)
- {
- _ui.m_c1.selectedIndex = 0;
- }
- ShowBonusList();
- }
- else
- {
- _ui.m_loaOpen.visible = false;
- }
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- private void OnClickBg()
- {
- this.Hide();
- ViewManager.Show(ViewName.LUCKY_BOX_VIEW, ViewManager.GetGoBackDatas(ViewName.LUCKY_BOX_STAR_VIEW));
- GetSuitItemController.TryShow(0);
- }
- private void ShowBonusList()
- {
- if (itemList.Count > 1)
- {
- for (int i = 0; i < itemList.Count; i++)
- {
- GObject itemObject = _ui.target.GetChild("item" + i);
- if (itemObject != null)
- {
- UpdateItem(i, itemObject);
- }
- }
- }
- else
- {
- UpdateItem(0, _ui.m_itemOne.target);
- }
- }
- private void HideAllItem()
- {
- _ui.m_itemOne.target.visible = false;
- for (int i = 0; i < 10; i++)
- {
- GObject itemObject = _ui.target.GetChild("item" + i);
- if (itemObject != null)
- {
- itemObject.visible = false;
- }
- }
- }
- private void UpdateItem(int index, GObject obj)
- {
- ItemData itemData = itemList[index];
- UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(obj);
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
- bool isFirst = true;
- int count = 0;
- for (int i = 0; i < itemList.Count; i++)
- {
- if (i < index && itemList[i].id == itemData.id)
- {
- isFirst = false;
- }
- if (itemList[i].id == itemData.id)
- {
- count++;
- }
- }
- itemUI.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
- itemUI.m_comIcon.m_imgNew.visible = ItemDataManager.GetItemNum(itemData.id) == count && isFirst ? true : false;
- string itemName = itemCfg.name;
- if (itemData.num > 1)
- {
- itemName += "x" + itemData.num;
- }
- itemUI.m_comIcon.m_txtName.text = itemName;
- itemUI.m_c1.selectedIndex = itemCfg.rarity;
- itemUI.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
- RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.m_rarity, itemData.id, false);
- itemUI.m_comIcon.m_icon.data = itemData.id;
- // itemUI.m_comIcon.target.SetScale(0, 0);
- itemUI.m_t0.Play();
- UI_LuckyBoxBonusItem.ProxyEnd();
- }
- private void InitAllItem()
- {
- UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(_ui.m_itemOne.target);
- itemUI.target.onClick.Add(OnClickItem);
- itemUI.m_comIcon.m_icon.onClick.Add(OnClickItemTips);
- UI_LuckyBoxBonusItem.ProxyEnd();
- for (int i = 0; i < 10; i++)
- {
- GObject itemObject = _ui.target.GetChild("item" + i);
- if (itemObject != null)
- {
- UI_LuckyBoxBonusItem itemUITen = UI_LuckyBoxBonusItem.Proxy(itemObject);
- itemUITen.target.onClick.Add(OnClickItem);
- itemUITen.m_comIcon.m_icon.onClick.Add(OnClickItemTips);
- UI_LuckyBoxBonusItem.ProxyEnd();
- }
- }
- }
- private void OnClickItem(EventContext context)
- {
- GComponent item = context.sender as GComponent;
- PlayOpenAni(item);
- }
- private void OnClickOpen()
- {
- for (int i = 0; i < itemList.Count; i++)
- {
- GComponent component = _ui.target.GetChild("item" + i).asCom;
- if (component != null)
- {
- bool playing = PlayOpenAni(component);
- if (!playing) continue;
- if (playing) break;
- }
- }
- }
- private bool PlayOpenAni(GComponent component)
- {
- Transition transition = component.GetTransition("t1");
- GComponent comIcon = component.GetChild("comIcon").asCom;
- if (transition.playing || comIcon.skew == Vector2.zero) return false;
- transition.Play(UpdateOpenCount);
- return true;
- }
- private void UpdateOpenCount()
- {
- openCount++;
- if (openCount == itemList.Count)
- {
- _ui.m_loaOpen.visible = false;
- }
- }
- private void OnClickItemTips(EventContext context)
- {
- GLoader item = context.sender as GLoader;
- int itemID = (int)item.data;
- GoodsItemTipsController.ShowItemTips(itemID);
- }
- }
- }
|