|
@@ -0,0 +1,276 @@
|
|
|
+using FairyGUI;
|
|
|
+using UI.BlindBox;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using ET;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Linq;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
+
|
|
|
+namespace GFGGame
|
|
|
+{
|
|
|
+ public struct BlindBoxType
|
|
|
+ {
|
|
|
+ public int type;
|
|
|
+ public bool check;
|
|
|
+ }
|
|
|
+
|
|
|
+ public class BlindBoxView : BaseWindow
|
|
|
+ {
|
|
|
+ private UI_BlindBoxUI _ui;
|
|
|
+ private EffectUI _effectUI1;
|
|
|
+ private Dictionary<string, EffectUI> _effectUIDic = new Dictionary<string, EffectUI>();
|
|
|
+ private ItemCfg itemcfg;
|
|
|
+ private int listIndex = 0;
|
|
|
+ BlindBoxCfg blindBoxCfg = BlindBoxCfgArray.Instance.GetCfg(1);
|
|
|
+ public override void Dispose()
|
|
|
+ {
|
|
|
+ EffectUIPool.Recycle(_effectUI1);
|
|
|
+ _effectUI1 = null;
|
|
|
+ foreach (var v in _effectUIDic)
|
|
|
+ {
|
|
|
+ EffectUIPool.Recycle(v.Value);
|
|
|
+ }
|
|
|
+
|
|
|
+ _effectUIDic.Clear();
|
|
|
+ if (_ui != null)
|
|
|
+ {
|
|
|
+ _ui.Dispose();
|
|
|
+ _ui = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ base.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnInit()
|
|
|
+ {
|
|
|
+ base.OnInit();
|
|
|
+ packageName = UI_BlindBoxUI.PACKAGE_NAME;
|
|
|
+ _ui = UI_BlindBoxUI.Create();
|
|
|
+ this.viewCom = _ui.target;
|
|
|
+ modal = true;
|
|
|
+ this.viewCom.Center();
|
|
|
+ //viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
|
|
|
+
|
|
|
+ _ui.m_backBtn.onClick.Add(this.Hide);
|
|
|
+ _ui.m_buyBtn.target.onClick.Add(OnClickBuyAll);
|
|
|
+ _ui.m_hiddenItem.onClick.Add(OnClickRewardBtn);
|
|
|
+ _ui.m_rewardList.onClick.Add(OnClickRewardBtn);
|
|
|
+ _ui.m_ruleBtn.onClick.Add(OnClickRuleBtn);
|
|
|
+ _ui.m_rewardList.itemRenderer = RenderRewardList;
|
|
|
+
|
|
|
+ List<DropOutCfg> dropOutCfgList = DropOutCfgArray.Instance.GetCfgsByid(blindBoxCfg.OrdinaryDropDisplay);
|
|
|
+ List<DropOutCfg> hidDropOutCfgList = DropOutCfgArray.Instance.GetCfgsByid(blindBoxCfg.HideDropDisplay);
|
|
|
+ ItemCfg hidItemCfg = ItemCfgArray.Instance.GetCfg(hidDropOutCfgList[0].item);
|
|
|
+ _ui.m_rewardList.numItems = dropOutCfgList.Count;
|
|
|
+ _ui.m_hiddenItem.url = ResPathUtil.GetIconPath(hidItemCfg);
|
|
|
+
|
|
|
+ _ui.m_boxList.itemRenderer = RenderBoxList;
|
|
|
+ _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_effect, "ui_Activity", "WSJ_UI_DX/WSJ_UI_DX");
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnShown()
|
|
|
+ {
|
|
|
+ base.OnShown();
|
|
|
+ _ui.m_bg.visible = false;
|
|
|
+ _ui.m_t1.Play();
|
|
|
+ clickBlankToClose = false;
|
|
|
+ itemcfg = ItemCfgArray.Instance.GetCfg(blindBoxCfg.CostID);
|
|
|
+ if (itemcfg == null)
|
|
|
+ {
|
|
|
+ Log.Error(string.Format("没有{0}物品"));
|
|
|
+ }
|
|
|
+
|
|
|
+ //_ui.m_buyBtn.m_img.url = ResPathUtil.GetIconPath(itemcfg);
|
|
|
+ _ui.m_boxList.numItems = 6;
|
|
|
+ _ui.m_rewardList.numItems = 6;
|
|
|
+ UpdateTime(null);
|
|
|
+ Timers.inst.Add(1, 0, UpdateTime);
|
|
|
+ Timers.inst.Add(0.75f, 1, TimeUpdateShow);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnHide()
|
|
|
+ {
|
|
|
+ base.OnHide();
|
|
|
+ ActivityDataManager.Instance.BlindBoxType = 0;
|
|
|
+ Timers.inst.Remove(UpdateTime);
|
|
|
+ Timers.inst.Remove(TimeUpdateShow);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void AddEventListener()
|
|
|
+ {
|
|
|
+ base.AddEventListener();
|
|
|
+ EventAgent.AddEventListener(ConstMessage.BlindBox_BuyOne, ReqBuyOne);
|
|
|
+ EventAgent.AddEventListener(ConstMessage.BlindBox_BuyAll, ReqBuyAll);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void RemoveEventListener()
|
|
|
+ {
|
|
|
+ base.RemoveEventListener();
|
|
|
+ EventAgent.RemoveEventListener(ConstMessage.BlindBox_BuyOne, ReqBuyOne);
|
|
|
+ EventAgent.RemoveEventListener(ConstMessage.BlindBox_BuyAll, ReqBuyAll);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnClickRewardBtn()
|
|
|
+ {
|
|
|
+ ViewManager.Show<BlindBoxRewardView>(new object[] { 30000066, 30000078 });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnClickRuleBtn()
|
|
|
+ {
|
|
|
+ ViewManager.Show<BlindBoxRuleView>(300036);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RenderRewardList(int index, GObject obj)
|
|
|
+ {
|
|
|
+ UI_rewardItem uiItemChild = UI_rewardItem.Proxy(obj);
|
|
|
+ List<DropOutCfg> dropOutCfgList = DropOutCfgArray.Instance.GetCfgsByid(blindBoxCfg.OrdinaryDropDisplay);
|
|
|
+ ItemCfg itemCfgChild = ItemCfgArray.Instance.GetCfg(dropOutCfgList[index].item);
|
|
|
+
|
|
|
+ uiItemChild.target.data = itemCfgChild;
|
|
|
+ uiItemChild.m_reward.url = ResPathUtil.GetIconPath(itemCfgChild);
|
|
|
+
|
|
|
+ UI_rewardItem.ProxyEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RenderBoxList(int index, GObject obj)
|
|
|
+ {
|
|
|
+ UI_boxItem item = UI_boxItem.Proxy(obj);
|
|
|
+ item.target.onClick.Add(OnClickBuyOne);
|
|
|
+ if (!_effectUIDic.ContainsKey("WSJ_Box" + index.ToString()))
|
|
|
+ {
|
|
|
+ _effectUIDic.Add("WSJ_Box" + index.ToString(),
|
|
|
+ EffectUIPool.CreateEffectUI(item.m_effect, "ui_Activity", "WSJ_Box/WSJ_Box"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!_effectUIDic.ContainsKey("WSJ_OpenBox" + index.ToString()))
|
|
|
+ {
|
|
|
+ _effectUIDic.Add("WSJ_OpenBox" + index.ToString(),
|
|
|
+ EffectUIPool.CreateEffectUI(item.m_effectOpen, "ui_Activity", "WSJ_OpenBox/WSJ_OpenBox"));
|
|
|
+ item.m_effectOpen.visible = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ UI_boxItem.ProxyEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnClickBuyAll()
|
|
|
+ {
|
|
|
+ ActivityDataManager.Instance.BlindBoxType = 6;
|
|
|
+ int costNum = blindBoxCfg.CostIDNumArr[1];
|
|
|
+ ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemcfg.id);
|
|
|
+ if (ActivityDataManager.Instance.typeAll.check == false)
|
|
|
+ {
|
|
|
+ string desc = string.Format("确认是否消耗{0}{1}打开{2}个盲盒?", costNum, itemCfg.name, _ui.m_boxList.numItems);
|
|
|
+ ViewManager.Show<BlindBoxBuyTIpView>(desc);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ReqBuyAll();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void ReqBuyAll()
|
|
|
+ {
|
|
|
+ bool result;
|
|
|
+ result = await LuckyBoxSProxy.ReqGetBlindBox(1, 6);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ UpdateAllBoxAni();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void ReqBuyOne()
|
|
|
+ {
|
|
|
+ bool result;
|
|
|
+ result = await LuckyBoxSProxy.ReqGetBlindBox(1, 1);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ UI_boxItem listItem = UI_boxItem.Proxy(_ui.m_boxList.GetChildAt(listIndex));
|
|
|
+ _ui.m_backBtn.touchable = false;
|
|
|
+ _ui.m_buyBtn.target.touchable = false;
|
|
|
+ _ui.m_boxList.touchable = false;
|
|
|
+ clickBlankToClose = false;
|
|
|
+ listItem.m_t0.Play(() =>
|
|
|
+ {
|
|
|
+ BonusController.TryShowBonusList(
|
|
|
+ ItemUtil.CreateItemDataList(LuckyBoxDataManager.Instance.BlindBoxReward));
|
|
|
+ _ui.m_backBtn.touchable = true;
|
|
|
+ _ui.m_buyBtn.target.touchable = true;
|
|
|
+ _ui.m_boxList.touchable = true;
|
|
|
+ clickBlankToClose = true;
|
|
|
+ });
|
|
|
+ UI_boxItem.ProxyEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnClickBuyOne(EventContext context)
|
|
|
+ {
|
|
|
+ GObject sender = context.sender as GObject;
|
|
|
+ GObject obj = sender.parent;
|
|
|
+ listIndex = _ui.m_boxList.GetChildIndex(sender);
|
|
|
+ ActivityDataManager.Instance.BlindBoxType = 1;
|
|
|
+ int costNum = blindBoxCfg.CostIDNumArr[0];
|
|
|
+ ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemcfg.id);
|
|
|
+ if (ActivityDataManager.Instance.typeOne.check == false)
|
|
|
+ {
|
|
|
+ string desc = string.Format("确认是否消耗{0}{1}打开一个盲盒?", costNum, itemCfg.name);
|
|
|
+ ViewManager.Show<BlindBoxBuyTIpView>(desc);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ReqBuyOne();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void UpdateAllBoxAni()
|
|
|
+ {
|
|
|
+ _ui.m_backBtn.touchable = false;
|
|
|
+ _ui.m_buyBtn.target.touchable = false;
|
|
|
+ _ui.m_boxList.touchable = false;
|
|
|
+ clickBlankToClose = false;
|
|
|
+ for (int i = 0; i < _ui.m_boxList.numItems; i++)
|
|
|
+ {
|
|
|
+ UI_boxItem item = UI_boxItem.Proxy(_ui.m_boxList.GetChildAt(i));
|
|
|
+ item.m_effect.visible = false;
|
|
|
+ item.m_effectOpen.visible = true;
|
|
|
+ await Task.Delay(200);
|
|
|
+ UI_boxItem.ProxyEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(LuckyBoxDataManager.Instance.BlindBoxReward));
|
|
|
+ for (int i = 0; i < _ui.m_boxList.numItems; i++)
|
|
|
+ {
|
|
|
+ UI_boxItem item = UI_boxItem.Proxy(_ui.m_boxList.GetChildAt(i));
|
|
|
+ item.m_effect.visible = true;
|
|
|
+ item.m_effectOpen.visible = false;
|
|
|
+ UI_boxItem.ProxyEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ _ui.m_backBtn.touchable = true;
|
|
|
+ _ui.m_buyBtn.target.touchable = true;
|
|
|
+ _ui.m_boxList.touchable = true;
|
|
|
+ clickBlankToClose = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void TimeUpdateShow(object param)
|
|
|
+ {
|
|
|
+ clickBlankToClose = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void UpdateTime(object param)
|
|
|
+ {
|
|
|
+ if (!ActivityAfuGiftDataManager.Instance.IsOpen)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ long curTime = TimeHelper.ServerNow();
|
|
|
+ var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfoOneByType(ActivityType.BlindBoxType);
|
|
|
+ if (activityInfo != null)
|
|
|
+ {
|
|
|
+ long endTime = activityInfo.EndTime;
|
|
|
+ _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|