123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- using UnityEngine;
- using FairyGUI;
- using UI.LuckyBox;
- using System.Collections.Generic;
- using System.Collections;
- namespace GFGGame
- {
- public class LuckyBoxBonusShowView : BaseWindow
- {
- private UI_LuckBoxBonusShowUI _ui;
- private List<ItemData> _rewardList = new List<ItemData>();
- private List<ItemData> _rewardItemList = new List<ItemData>();
- private Dictionary<int , Dictionary<int, EffectUI>> _effListTen = new Dictionary<int, Dictionary<int, EffectUI>>();
- private Dictionary<int, EffectUI> _effList = new Dictionary<int, EffectUI>();
- private Dictionary<int, int> _itemIdList = new Dictionary<int, int>();
- private Dictionary<int, GComponent> _itemObjList = new Dictionary<int, GComponent>();
- private List<int> _recordOpenIndex = new List<int>(); //记录打开过得item位置
- private int _chooseIndex = -1; //当前选中的index
- private int _countShow = 0; //第几次展示
- private int _countNewRecord = 0; //展示步骤
- private bool _handClick = false; //手动点击开启
- private EffectUI _effectUI1;
- private EffectUI _effectUI2;
- private EffectUI _effectUI3;
- public override void Dispose()
- {
- EffectUIPool.Recycle(_effectUI1);
- _effectUI1 = null;
- EffectUIPool.Recycle(_effectUI2);
- _effectUI2 = null;
- EffectUIPool.Recycle(_effectUI3);
- _effectUI3 = null;
- for (int key = 0; key < _effListTen.Count; key++) {
- if (_effListTen.ContainsKey(key))
- {
- for (int key1 = 0; key1 < _effListTen[key].Count; key1++)
- {
- if (_effListTen[key].ContainsKey(key1))
- {
- EffectUIPool.Recycle(_effListTen[key][key1]);
- _effListTen[key][key1] = null;
- }
- }
- }
- }
- _effListTen.Clear();
- for (int key = 0; key < _effList.Count; key++)
- {
- if (_effList.ContainsKey(key))
- {
- EffectUIPool.Recycle(_effList[key]);
- _effList[key] = null;
- }
- }
- _effList.Clear();
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_LuckBoxBonusShowUI.PACKAGE_NAME;
- _ui = UI_LuckBoxBonusShowUI.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- _ui.m_loaBg.onClick.Add(OnClickLoaBg);
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
- _ui.m_BtnPass.onClick.Add(OnClickBtnPass);
-
- UpdateEffect();
- }
- private void UpdateEffect()
- {
- _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder_star, "ui_LuckyBox", "bg_liuxing");
- _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holder_bg, "ui_LuckyBox", "CK_UI");
- _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holder_cloud, "ui_LuckyBox", "bg_cloud");
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_REWARD_SHOW, ReferNextShow);
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_REWARD_SHOW, ReferNextShow);
- }
- protected void ReferNextShow()
- {
- if (_chooseIndex != -1)
- ClickItem(_chooseIndex);
- }
- protected override void OnShown()
- {
- base.OnShown();
- _rewardList.AddRange(this.viewData as List<ItemData>);
- _itemIdList.Clear();
- _itemObjList.Clear();
- _recordOpenIndex.Clear();
- _ui.m_BtnPass.visible = true;
- _ui.m_touchFlipOpen.touchable = false;
- if (_rewardList.Count == 1)
- {
- _ui.m_c1.selectedIndex = 0;
- UpdateItem(_ui.m_itemOne.target, 0, 1);
- }
- else
- {
- _ui.m_c1.selectedIndex = 1;
- for (int i = 0; i < _rewardList.Count; i++)
- {
- UpdateItem(_ui.target.GetChild("item" + i).asCom, i, 10);
- }
- }
- }
- protected override void OnHide()
- {
- _rewardList.Clear();
- base.OnHide();
- Timers.inst.Remove(UpDataTime);
- Timers.inst.Remove(UpClickDataTime);
- }
- private void UpdateItem(GComponent com, int index, int countType)
- {
- UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
- ItemData itemData = _rewardList[index];
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
- item.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
- item.m_comIcon.m_txtName.text = itemCfg.name;
- item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
- item.m_comIcon.m_FlipOpenType.selectedIndex = 1;
- item.m_comIcon.m_t1.Play();
- //带特效的处理先注释
- //item.m_comIcon.m_holder.visible = false;
- //item.m_comIcon.m_holder1.visible = false;
- //if (itemCfg.rarity > 2) {
- // string resPath = itemCfg.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_01" : "CK_all_02";
- // GGraph holder = itemCfg.rarity == 3 ? item.m_comIcon.m_holder : item.m_comIcon.m_holder1;
- // holder.visible = true;
- // if (countType == 10 && (!_effListTen.ContainsKey(index) ||
- // ((itemCfg.rarity == 3 && !_effListTen[index].ContainsKey(0)) || (itemCfg.rarity == 4 && !_effListTen[index].ContainsKey(1)))))
- // {
- // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
- // if (!_effListTen.ContainsKey(index))
- // {
- // Dictionary<int, EffectUI> effectList = new Dictionary<int, EffectUI>();
- // if (itemCfg.rarity == 3)
- // effectList.Add(0, _effectUI);
- // else if (itemCfg.rarity == 4)
- // effectList.Add(1, _effectUI);
- // _effListTen.Add(index, effectList);
- // }
- // else {
- // if (itemCfg.rarity == 3)
- // _effListTen[index].Add(0, _effectUI);
- // else if (itemCfg.rarity == 4)
- // _effListTen[index].Add(1, _effectUI);
- // }
- // }
- // if (countType == 1 &&
- // ((itemCfg.rarity == 3 && !_effList.ContainsKey(0)) || (itemCfg.rarity == 4 && !_effList.ContainsKey(1))))
- // {
- // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
- // if (itemCfg.rarity == 3)
- // _effList.Add(0, _effectUI);
- // else if (itemCfg.rarity == 4)
- // _effList.Add(1, _effectUI);
- // }
- //}
- int count = 0;
- bool isFirst = false;
- for (int i = 0; i < _rewardList.Count; i++)
- {
- if (_rewardList[i].id == itemData.id) count++;
- if (count == 1 && i == index) isFirst = true;
- }
- item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
- item.m_t0.Play();
- if (item.target.data == null)
- {
- item.target.onClick.Add(ShowItemTips);
- }
- item.target.data = index;
- _itemIdList.Add(index,itemCfg.id);
- _itemObjList.Add(index, com);
- UI_LuckyBoxBonusShowItem.ProxyEnd();
- }
- private void ShowItemTips(EventContext context)
- {
- GObject obj = context.sender as GObject;
- int index = (int)obj.data;
- _chooseIndex = index;
- HandClickItem(index);
- }
- private void HandClickItem(int index)
- {
- _ui.m_touchFlipOpen.touchable = true;
- _handClick = true;
- ClickItem(index);
- Timers.inst.Add(1f, 1, UpClickDataTime,index);
- }
- void ClickItem(int index)
- {
- if (!_recordOpenIndex.Contains(index))
- {
- UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]);
- if (_recordOpenIndex.Count >= _rewardList.Count - 1)
- _ui.m_BtnPass.visible = false;
- //先翻开牌面
- if (!item.m_comIcon.m_imgNew.visible || _countNewRecord < 1)
- {
- HideOtherShowWindow();
- item.m_comIcon.m_FlipOpenType.selectedIndex = 0;
- //item.m_t1.Play();
- item.m_t2.Play();
- item.m_comIcon.m_t0.Play();
- if (!item.m_comIcon.m_imgNew.visible) {
- if (_handClick)
- _ui.m_touchFlipOpen.touchable = false;
- _recordOpenIndex.Add(index);
- }
- else if (_countNewRecord < 1)
- _countNewRecord += 1;
- return;
- }
- if (item.m_comIcon.m_imgNew.visible && _countNewRecord >= 1)
- {
- //判断是否有套装需要展示
- if (GetSuitItemController.GetSuitWaitingToId(_itemIdList[index]))
- {
- if (_countShow < 1)
- {
- _countShow += 1;
- ViewManager.Hide<GetSuitItemVIew>();
- _rewardItemList.Clear();
- _rewardItemList.Add(_rewardList[index]);
- ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
- }
- else
- {
- ViewManager.Hide<LuckyBoxNewDressView>();
- ViewManager.Hide<LuckyBoxNewCardView>();
- GetSuitItemController.TryShow(_itemIdList[index]);
- _recordOpenIndex.Add(index);
- _countShow = 0;
- _countNewRecord = 0;
- }
- }
- else
- {
- ViewManager.Hide<GetSuitItemVIew>();
- _rewardItemList.Clear();
- _rewardItemList.Add(_rewardList[index]);
- ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
- _recordOpenIndex.Add(index);
- _countNewRecord = 0;
- }
- }
- UI_LuckyBoxBonusShowItem.ProxyEnd();
- if (_handClick)
- {
- _ui.m_touchFlipOpen.touchable = false;
- Timers.inst.Remove(UpClickDataTime);
- }
- }
- else{
- GoodsItemTipsController.ShowItemTips(_itemIdList[index]);
- }
- }
- private void OnClickLoaBg()
- {
- if (_recordOpenIndex.Count >= _rewardList.Count)
- {
- _chooseIndex = -1;
- this.Hide();
- }
- else {
- for (int index = 0; index < _rewardList.Count; index++)
- {
- if (!_recordOpenIndex.Contains(index))
- {
- _chooseIndex = index;
- HandClickItem(index);
- break;
- }
- }
- }
- }
- private void OnClickBtnPass()
- {
- for (int index = 0; index < _rewardList.Count; index++)
- {
- if (!_recordOpenIndex.Contains(index))
- {
- int count = 0;
- bool isFirst = false;
- for (int i = 0; i < _rewardList.Count; i++)
- {
- if (_rewardList[i].id == _rewardList[index].id) count++;
- if (count == 1 && i == index) isFirst = true;
- }
- bool open = count == ItemDataManager.GetItemNum(_rewardList[index].id) && isFirst;
- if (!open)
- {
- _chooseIndex = index;
- ClickItem(index);
- }
- }
- }
- ClickPass();
- }
- private void ClickPass()
- {
- _ui.m_touchFlipOpen.touchable = true;
- Timers.inst.Add(1f, 0, UpDataTime);
- }
- private void UpDataTime(object param = null)
- {
- if (_recordOpenIndex.Count >= _rewardList.Count) {
- Timers.inst.Remove(UpDataTime);
- _ui.m_touchFlipOpen.touchable = false;
- HideOtherShowWindow();
- }
- for (int i = 0; i < _rewardList.Count; i++)
- {
- if (!_recordOpenIndex.Contains(i)) {
- ClickItem(i);
- break;
- }
- }
- }
- private void UpClickDataTime(object param = null)
- {
- int index = (int)param;
- if (_recordOpenIndex.Contains(index))
- {
- Timers.inst.Remove(UpClickDataTime);
- _ui.m_touchFlipOpen.touchable = false;
- HideOtherShowWindow();
- }
- else
- ClickItem(index);
- }
- private void HideOtherShowWindow()
- {
- ViewManager.Hide<GetSuitItemVIew>();
- ViewManager.Hide<LuckyBoxNewDressView>();
- ViewManager.Hide<LuckyBoxNewCardView>();
- }
- }
- }
|