123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- using FairyGUI;
- using UI.LuckyBox;
- using UI.CommonGame;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using ET;
- namespace GFGGame
- {
- public class LuckyBoxActivityView : BaseWindow
- {
- private UI_LuckyBoxActivityUI _ui;
- private ValueBarController _valueBarController;
- private LuckyBoxController _luckyBoxCtrl;
- private ActivityOpenCfg _activityCfg;
- private LuckyBoxCfg _luckyBoxCfg;
- private int _activityId;
- public override void Dispose()
- {
- if (_valueBarController != null)
- {
- _valueBarController.Dispose();
- _valueBarController = null;
- }
- if (_luckyBoxCtrl != null)
- {
- _luckyBoxCtrl.Dispose();
- _luckyBoxCtrl = null;
- }
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_LuckyBoxActivityUI.PACKAGE_NAME;
- _ui = UI_LuckyBoxActivityUI.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- _valueBarController = new ValueBarController(_ui.m_valueBar);
- _luckyBoxCtrl = new LuckyBoxController(_ui.m_comBox.m_comModel.target);
- _ui.m_btnBack.onClick.Add(OnClickBtnBack);
- _ui.m_btnReward.onClick.Add(OnClikcBtnReward);
- _ui.m_btnShop.onClick.Add(OnClikcBtnShop);
- _ui.m_btnGiftBag.onClick.Add(OnClikcBtnGiftBag);
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- EventAgent.AddEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateView);
- }
- protected override void OnShown()
- {
- base.OnShown();
- _activityId = (int)this.viewData;
- _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(_activityId);
- _luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(_activityCfg.paramsArr[0]);
- _valueBarController.OnShown();
- _valueBarController.UpdateList(new List<int>() { _luckyBoxCfg.costID });
- _luckyBoxCtrl.OnShown(_luckyBoxCfg.id);
- Timers.inst.Add(1, 0, UpdateTime);
- UpdateView();
- }
- private void UpdateTime(object param = null)
- {
- long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.endTime);
- long curTime = TimeHelper.ServerNow();
- if (endTime < curTime)
- {
- PromptController.Instance.ShowFloatTextPrompt("活动已结束");
- Timers.inst.Remove(UpdateTime);
- OnClickBtnBack();
- return;
- }
- TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
- _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
- //=====限时礼包倒计时
- UpGiftBox();
- if (ViewManager.isViewOpen(nameof(RushSaleGiftBoxView)))
- {
- var rushSaleGiftBoxView =
- ViewManager.GetUIView(nameof(RushSaleGiftBoxView)) as RushSaleGiftBoxView;
- rushSaleGiftBoxView?.UpTime();
- }
- //=====限时礼包倒计时END
- }
- private void UpdateView()
- {
- _ui.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastDrawCount.ToString()).FlushVars();
- _ui.m_txtCount.SetVar("name", _activityCfg.themeName).FlushVars();
- UI_ComBox comBox = UI_ComBox.Proxy(_ui.m_comBox.target);
- LuckyBoxDataManager.Instance.InitData(_luckyBoxCfg.id);
- comBox.m_comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[0]);
- comBox.m_btnPreview.m_c1.selectedIndex = 1;
- LuckyBoxDataManager.Instance.GetOwnedCount(_luckyBoxCfg.id, out int count, out int totalCount);
- comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
- comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
- int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
- comBox.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", _luckyBoxCfg.maxCount - boughtCount);
- comBox.m_comCostOne.m_txtCost.text = _luckyBoxCfg.costNum.ToString();
- comBox.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(_luckyBoxCfg.costID).res);
- comBox.m_comCostTen.m_txtCost.text = _luckyBoxCfg.costNumTen.ToString();
- comBox.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(_luckyBoxCfg.costID).res);
- if (comBox.m_btnBuyOne.target.data == null)
- {
- comBox.m_btnBuyOne.target.onClick.Add(OnClickBtnBuyOne);
- }
- comBox.m_btnBuyOne.target.data = _luckyBoxCfg.id;
- if (comBox.m_btnBuyTen.target.data == null)
- {
- comBox.m_btnBuyTen.target.onClick.Add(OnClickBtnBuyTen);
- }
- comBox.m_btnBuyTen.target.data = _luckyBoxCfg.id;
- comBox.m_imgActLuckyBox.visible = true;
- comBox.m_grpLuckyBox.visible = false;
- if (comBox.m_btnPreview.target.data == null)
- {
- comBox.m_btnPreview.target.onClick.Add(OnClickBtnPreview);
- }
- comBox.m_btnPreview.target.data = _luckyBoxCfg.id;
- comBox.target.data = _luckyBoxCfg.id;
- UI_ComBox.ProxyEnd();
- }
- private void UpGiftBox()
- {
- var activityInfoByTypeList =
- ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
- var list = activityInfoByTypeList
- .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
- if (list.Count == 0)
- {
- _ui.m_comBagTime.target.visible = false;
- _ui.m_btnGiftBag.visible = false;
- }
- else
- {
- _ui.m_comBagTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
- _ui.m_comBagTime.target.visible = true;
- _ui.m_btnGiftBag.visible = true;
- }
- }
- private void OnClickBtnPreview(EventContext context)
- {
- GObject obj = context.sender as GObject;
- int boxId = (int)obj.data;
- ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW, boxId);
- }
- private void OnClickBtnBuyOne(EventContext context)
- {
- int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
- if (boughtCount + LuckyBoxDataManager.ONCE_TIME > _luckyBoxCfg.maxCount)
- {
- PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
- return;
- }
- LuckyBoxDataManager.Instance.CheckItemEnough(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME, async () =>
- {
- bool result = await LuckyBoxSProxy.ReqGetBonus(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME);
- if (result)
- {
- ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
- // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
- }
- });
- }
- private void OnClickBtnBuyTen(EventContext context)
- {
- GObject obj = context.sender as GObject;
- int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
- if (boughtCount + LuckyBoxDataManager.TEN_TIME > _luckyBoxCfg.maxCount)
- {
- PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
- return;
- }
- LuckyBoxDataManager.Instance.CheckItemEnough(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME, async () =>
- {
- bool result = await LuckyBoxSProxy.ReqGetBonus(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME);
- if (result)
- {
- ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
- // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
- }
- });
- }
- private void OnClikcBtnReward()
- {
- ViewManager.Show<ActivityThemeLuckyBoxBonusView>();
- }
- private void OnClikcBtnShop()
- {
- ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY });
- }
- //限时礼包按钮点击执行方法
- private void OnClikcBtnGiftBag()
- {
- var activityInfoByTypeList =
- ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
- var list = activityInfoByTypeList
- .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
- if (list.Count == 0)
- {
- PromptController.Instance.ShowFloatTextPrompt("活动已结束");
- }
- else
- {
- ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });
- }
- }
- protected override void OnHide()
- {
- base.OnHide();
- _valueBarController.OnHide();
- _luckyBoxCtrl.OnHide();
- Timers.inst.Remove(UpdateTime);
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- }
- private void OnClickBtnBack()
- {
- ViewManager.GoBackFrom(typeof(LuckyBoxActivityView).FullName);
- }
- protected override void UpdateToCheckGuide(object param)
- {
- if (!ViewManager.CheckIsTopView(this.viewCom)) return;
- }
- protected override void TryCompleteGuide()
- {
- base.TryCompleteGuide();
- }
- }
- }
|