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() { _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(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(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true); // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2); } }); } private void OnClikcBtnReward() { ViewManager.Show(); } private void OnClikcBtnShop() { ViewManager.Show(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(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(); } } }