123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- using ET;
- using FairyGUI;
- using System;
- using System.Collections.Generic;
- using UI.DailyWelfare;
- using UnityEngine;
- namespace GFGGame
- {
- public class LimitedRechargeDBGiftView : BaseWindow
- {
- private UI_LimitedRechargeDBGiftUI _ui;
- private int _minProgressOffset = 6;
- private int _maxProgressOffset = -8;
- private ActivityInfo _activityInfo;
- private ActivityRecharge2Cfg[] _rechargeCfgs;
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_LimitedRechargeDBGiftUI.PACKAGE_NAME;
- _ui = UI_LimitedRechargeDBGiftUI.Create();
- this.viewCom = _ui.target;
- this.viewCom.Center();
- this.modal = true;
- viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
- _ui.m_btnTest.onClick.Add(OnClickBtnTest);
- _rechargeCfgs = ActivityRecharge2CfgArray.Instance.dataArray;
- InitProgressValueList();
- InitReward();
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- EventAgent.AddEventListener(ConstMessage.ACTIVITY_REWARD_ADD, UpdateView);
- EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateView);
- EventAgent.AddEventListener(ConstMessage.ACTIVITY_COUNT_VALUE_CHANGE, UpdateView);
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_REWARD_ADD, UpdateView);
- EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateView);
- EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_COUNT_VALUE_CHANGE, UpdateView);
- }
- protected override void OnShown()
- {
- base.OnShown();
- UpdateView();
- UpdateProgress();
- Timers.inst.Add(1, 0, UpdateTime);
- }
- protected override void OnHide()
- {
- base.OnHide();
- Timers.inst.Remove(UpdateTime);
- }
- private void OnClickBtnTest(EventContext context)
- {
- UpdateProgress();
- }
- private int[] _progressValuePart;
- private int _partNum = 4;
- private void InitProgressValueList()
- {
- _progressValuePart = new int[_partNum];
- _ui.m_progress.target.max = _rechargeCfgs[_rechargeCfgs.Length - 1].value;
- int max = (int)_ui.m_progress.target.max;
- int average = (int)Mathf.Ceil((float)(_ui.m_progress.target.max / (_partNum - 1)));
- _progressValuePart[0] = 0;
- _progressValuePart[_partNum - 1] = max;
- for (int i = 1; i < _partNum - 1; i++)
- {
- _progressValuePart[i] = i * average;
- }
- }
- /// <summary>
- /// 初始化奖励的UI
- /// </summary>
- private void InitReward()
- {
- // 包子图
- // 大奖icon
- }
- private void UpdateProgress()
- {
- int max = (int)_ui.m_progress.target.max;
- long count = _activityInfo.CountValue;
- // 确定count的区间
- if (count == 0 || count == max)
- {
- _ui.m_progress.target.value = count;
- }
- else
- {
- int index = 1;
- for (; index < _progressValuePart.Length; index++)
- {
- if (count < _progressValuePart[index])
- {
- --index;
- break;
- }
- }
- // 计算进度条最小取值和最大取值,避免因为图标遮挡造成视觉错误
- int minProgressValue = _progressValuePart[index] + _minProgressOffset;
- int maxProgressValue = _progressValuePart[index + 1] + _maxProgressOffset;
- if (count == _progressValuePart[index] || count == _progressValuePart[index + 1])
- {
- _ui.m_progress.target.value = count;
- }
- else
- {
- _ui.m_progress.target.value = Mathf.Clamp(count, minProgressValue, maxProgressValue);
- }
- // 检测玩家是否领取奖励
- UpdateRewardState(index);
- }
- }
- private void UpdateTime(object param)
- {
- long curTime = TimeHelper.ServerNow();
- long endTime = _activityInfo.EndTime;
- _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
- }
- private void UpdateView()
- {
- _activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfoOneByType(ActivityType.DBGift);
- UpdateProgress();
- }
- private struct GetState
- {
- public int index;
- public bool canGet;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="index">玩家可领取的最大奖励index</param>
- private void UpdateRewardState(int index)
- {
- GComponent comProBonusGroup = _ui.m_progress.m_comProBonusGroup.asCom;
- for(int i = 0; i < _partNum; i++)
- {
- bool arrive = (i <= index);
- UI_ComProBonus2 bonus = UI_ComProBonus2.Proxy(comProBonusGroup.GetChildAt(i));
- bonus.target.data = new GetState
- {
- index = i,
- canGet = arrive
- };
- // 玩家已经达到的奖励
- if (arrive)
- {
- // 已领
- if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[i].id) > 0)
- {
- bonus.m_imgGot.visible = true;
- bonus.target.touchable = false;
- // 隐藏红点
- RedDotController.Instance.SetComRedDot(bonus.target, false);
- }
- // 未领
- else
- {
- bonus.m_imgGot.visible = false;
- // 显示红点
- RedDotController.Instance.SetComRedDot(bonus.target, true);
- }
- }
- bonus.target.onClick.Set(OnClickGift);
- UI_ComProBonus2.ProxyEnd();
- }
- }
- private void OnClickGift(EventContext eventContext)
- {
- GObject gObject = (GObject)eventContext.data;
- GetState getState = (GetState)gObject.data;
- if (getState.canGet)
- {
- ActivityGlobalSProxy.ReqGetActivityBonus(_activityInfo.ActivityId, _rechargeCfgs[getState.index].id).Coroutine();
- }
- else
- {
- // 显示奖励详细列表
- //ViewManager.Show<UI_GiftDetailUI>
- }
- }
- }
- }
|