123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using ET;
- using FairyGUI;
- using Hutool;
- using UI.DailyWelfare;
- using UnityEngine;
- namespace GFGGame
- {
- public class DailySupplyView : BaseWindow
- {
- private UI_DailySupplyUI _ui;
- // private ValueBarController _valueBarController;
- private EffectUI _effectUI1;
- private EffectUI _effectUI2;
- private EffectUI _effectUI3;
- private EffectUI _effectUI4;
- private int _signCount;
- private int _month;
- private int _day;
- public override void Dispose()
- {
- // if (_valueBarController != null)
- // {
- // _valueBarController.Dispose();
- // _valueBarController = null;
- // }
- EffectUIPool.Recycle(_effectUI1);
- _effectUI1 = null;
- EffectUIPool.Recycle(_effectUI2);
- _effectUI2 = null;
- EffectUIPool.Recycle(_effectUI3);
- _effectUI3 = null;
- EffectUIPool.Recycle(_effectUI4);
- _effectUI4 = null;
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_DailySupplyUI.PACKAGE_NAME;
- _ui = UI_DailySupplyUI.Create();
- this.viewCom = _ui.target;
- this.viewCom.Center();
- this.modal = true;
- viewAnimationType = EnumViewAnimationType.None;
- // _valueBarController = new ValueBarController(_ui.m_comValueBar);
- // _ui.m_btnback.onClick.Add(OnBtnBackClick);
- UpdateEffect();
- }
- private void UpdateEffect()
- {
- _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_Activity", "Time_thing_book");
- _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_comSupply.m_holder, "ui_Activity", "Time_thing_hudie");
- _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_comSupply.m_comSupply0.m_holder, "ui_Activity", "Time_thing_zhuti");
- _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_comSupply.m_comSupply1.m_holder, "ui_Activity", "Time_thing_zhuti");
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSupplyView);
- EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
- }
- protected override void OnShown()
- {
- base.OnShown();
- _month = TimeUtil.GetCurMonth();
- _day = TimeUtil.GetCurDay();
- UpdateSupplyView();
- _ui.m_t0.Play();
- UpdateRedDot();
- }
- protected override void OnHide()
- {
- // _valueBarController.OnHide();
- base.OnHide();
- _ui.m_t0.Stop();
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSupplyView);
- EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
- }
- private void OnBtnBackClick()
- {
- ViewManager.GoBackFrom(typeof(DailyWelfareView).FullName);
- }
- private void UpdateView()
- {
- UpdateSupplyView();
- }
- private void UpdateSupplyView()
- {
- UpdateReward(_ui.m_comSupply.m_comSupply0.target, DailySupplyCfgArray.Instance.dataArray[0].id);
- UpdateReward(_ui.m_comSupply.m_comSupply1.target, DailySupplyCfgArray.Instance.dataArray[1].id);
- }
- private void UpdateReward(GObject obj, int id)
- {
- DailySupplyCfg supplyCfg = DailySupplyCfgArray.Instance.GetCfg(id);
- UI_ComSupplyItem item = UI_ComSupplyItem.Proxy(obj);
- long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
- long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
- item.m_txtTime.text = TimeUtil.FormattingTimeTo_HHmm(openTime) + "-" + TimeUtil.FormattingTimeTo_HHmm(endTime);
- item.m_txtCount.text = supplyCfg.bonusArr[0][1].ToString();
- ItemUtil.UpdateItemNeedNum(item.m_comCost, GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0], false, "#FFF6ED");
- item.m_comCost.visible = false;
- if (MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.DailySupplyReward), supplyCfg.id))
- {
- item.m_btnGet.title = "已领取";
- item.m_btnGet.enabled = false;
- return;
- }
- long curTime = TimeHelper.ServerNow();
- if (curTime < openTime && curTime > TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.refreshTime))
- {
- item.m_btnGet.title = "领取";
- item.m_btnGet.enabled = false;
- }
- else if (curTime > openTime && curTime < endTime)
- {
- item.m_btnGet.title = "领取";
- item.m_btnGet.enabled = true;
- }
- else
- {
- item.m_comCost.visible = true;
- item.m_btnGet.title = "补领";
- item.m_btnGet.enabled = true;
- }
- if (item.m_btnGet.data == null)
- {
- item.m_btnGet.onClick.Add(OnBtnGetSupplyClick);
- }
- item.m_btnGet.data = supplyCfg;
- UI_ComSupplyItem.ProxyEnd();
- }
- private void OnBtnGetSupplyClick(EventContext context)
- {
- GObject obj = context.sender as GObject;
- DailySupplyCfg supplyCfg = obj.data as DailySupplyCfg;
- long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
- long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
- if (TimeHelper.ServerNow() > endTime)
- {
- int[] cost = GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0];
- AlertUI.Show(string.Format("是否确定花费{0}{1}补领?", cost[1], ItemCfgArray.Instance.GetCfg(cost[0]).name)).
- SetLeftButton(true, "否").
- SetRightButton(true, "是", (object param) =>
- {
- if (ItemDataManager.GetItemNum(cost[0]) < cost[1])
- {
- PromptController.Instance.ShowFloatTextPrompt("消耗不足");
- return;
- }
- ReqSupplyAsync(supplyCfg.id);
- });
- }
- else
- {
- ReqSupplyAsync(supplyCfg.id);
- }
- }
- private async void ReqSupplyAsync(int id)
- {
- bool result = await DailyWelfareSProxy.ReqGetSupplyReward(id);
- if (result)
- {
- UpdateSupplyView();
- }
- }
- private void UpdateRedDot()
- {
- RedDotController.Instance.SetComRedDot(_ui.m_comSupply.m_comSupply0.m_btnGet, RedDotDataManager.Instance.DailySupplyRed(DailySupplyCfgArray.Instance.dataArray[0]));
- RedDotController.Instance.SetComRedDot(_ui.m_comSupply.m_comSupply1.m_btnGet, RedDotDataManager.Instance.DailySupplyRed(DailySupplyCfgArray.Instance.dataArray[1]));
- }
- }
- }
|