LimitedRechargeDBGiftView.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using ET;
  2. using FairyGUI;
  3. using System;
  4. using System.Collections.Generic;
  5. using UI.DailyWelfare;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class LimitedRechargeDBGiftView : BaseWindow
  10. {
  11. private UI_LimitedRechargeDBGiftUI _ui;
  12. private int _minProgressOffset = 6;
  13. private int _maxProgressOffset = -8;
  14. private ActivityInfo _activityInfo;
  15. private ActivityRecharge2Cfg[] _rechargeCfgs;
  16. public override void Dispose()
  17. {
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void OnInit()
  26. {
  27. base.OnInit();
  28. packageName = UI_LimitedRechargeDBGiftUI.PACKAGE_NAME;
  29. _ui = UI_LimitedRechargeDBGiftUI.Create();
  30. this.viewCom = _ui.target;
  31. this.viewCom.Center();
  32. this.modal = true;
  33. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  34. _ui.m_btnTest.onClick.Add(OnClickBtnTest);
  35. _rechargeCfgs = ActivityRecharge2CfgArray.Instance.dataArray;
  36. InitProgressValueList();
  37. InitReward();
  38. }
  39. protected override void AddEventListener()
  40. {
  41. base.AddEventListener();
  42. EventAgent.AddEventListener(ConstMessage.ACTIVITY_REWARD_ADD, UpdateView);
  43. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateView);
  44. EventAgent.AddEventListener(ConstMessage.ACTIVITY_COUNT_VALUE_CHANGE, UpdateView);
  45. }
  46. protected override void RemoveEventListener()
  47. {
  48. base.RemoveEventListener();
  49. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_REWARD_ADD, UpdateView);
  50. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateView);
  51. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_COUNT_VALUE_CHANGE, UpdateView);
  52. }
  53. protected override void OnShown()
  54. {
  55. base.OnShown();
  56. UpdateView();
  57. UpdateProgress();
  58. Timers.inst.Add(1, 0, UpdateTime);
  59. }
  60. protected override void OnHide()
  61. {
  62. base.OnHide();
  63. Timers.inst.Remove(UpdateTime);
  64. }
  65. private void OnClickBtnTest(EventContext context)
  66. {
  67. UpdateProgress();
  68. }
  69. private int[] _progressValuePart;
  70. private int _partNum = 4;
  71. private void InitProgressValueList()
  72. {
  73. _progressValuePart = new int[_partNum];
  74. _ui.m_progress.target.max = _rechargeCfgs[_rechargeCfgs.Length - 1].value;
  75. int max = (int)_ui.m_progress.target.max;
  76. int average = (int)Mathf.Ceil((float)(_ui.m_progress.target.max / (_partNum - 1)));
  77. _progressValuePart[0] = 0;
  78. _progressValuePart[_partNum - 1] = max;
  79. for (int i = 1; i < _partNum - 1; i++)
  80. {
  81. _progressValuePart[i] = i * average;
  82. }
  83. }
  84. /// <summary>
  85. /// 初始化奖励的UI
  86. /// </summary>
  87. private void InitReward()
  88. {
  89. // 包子图
  90. // 大奖icon
  91. }
  92. private void UpdateProgress()
  93. {
  94. int max = (int)_ui.m_progress.target.max;
  95. long count = _activityInfo.CountValue;
  96. // 确定count的区间
  97. if (count == 0 || count == max)
  98. {
  99. _ui.m_progress.target.value = count;
  100. }
  101. else
  102. {
  103. int index = 1;
  104. for (; index < _progressValuePart.Length; index++)
  105. {
  106. if (count < _progressValuePart[index])
  107. {
  108. --index;
  109. break;
  110. }
  111. }
  112. // 计算进度条最小取值和最大取值,避免因为图标遮挡造成视觉错误
  113. int minProgressValue = _progressValuePart[index] + _minProgressOffset;
  114. int maxProgressValue = _progressValuePart[index + 1] + _maxProgressOffset;
  115. if (count == _progressValuePart[index] || count == _progressValuePart[index + 1])
  116. {
  117. _ui.m_progress.target.value = count;
  118. }
  119. else
  120. {
  121. _ui.m_progress.target.value = Mathf.Clamp(count, minProgressValue, maxProgressValue);
  122. }
  123. // 检测玩家是否领取奖励
  124. UpdateRewardState(index);
  125. }
  126. }
  127. private void UpdateTime(object param)
  128. {
  129. long curTime = TimeHelper.ServerNow();
  130. long endTime = _activityInfo.EndTime;
  131. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  132. }
  133. private void UpdateView()
  134. {
  135. _activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfoOneByType(ActivityType.DBGift);
  136. UpdateProgress();
  137. }
  138. private struct GetState
  139. {
  140. public int index;
  141. public bool canGet;
  142. }
  143. /// <summary>
  144. ///
  145. /// </summary>
  146. /// <param name="index">玩家可领取的最大奖励index</param>
  147. private void UpdateRewardState(int index)
  148. {
  149. GComponent comProBonusGroup = _ui.m_progress.m_comProBonusGroup.asCom;
  150. for(int i = 0; i < _partNum; i++)
  151. {
  152. bool arrive = (i <= index);
  153. UI_ComProBonus2 bonus = UI_ComProBonus2.Proxy(comProBonusGroup.GetChildAt(i));
  154. bonus.target.data = new GetState
  155. {
  156. index = i,
  157. canGet = arrive
  158. };
  159. // 玩家已经达到的奖励
  160. if (arrive)
  161. {
  162. // 已领
  163. if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[i].id) > 0)
  164. {
  165. bonus.m_imgGot.visible = true;
  166. bonus.target.touchable = false;
  167. // 隐藏红点
  168. RedDotController.Instance.SetComRedDot(bonus.target, false);
  169. }
  170. // 未领
  171. else
  172. {
  173. bonus.m_imgGot.visible = false;
  174. // 显示红点
  175. RedDotController.Instance.SetComRedDot(bonus.target, true);
  176. }
  177. }
  178. bonus.target.onClick.Set(OnClickGift);
  179. UI_ComProBonus2.ProxyEnd();
  180. }
  181. }
  182. private void OnClickGift(EventContext eventContext)
  183. {
  184. GObject gObject = (GObject)eventContext.data;
  185. GetState getState = (GetState)gObject.data;
  186. if (getState.canGet)
  187. {
  188. ActivityGlobalSProxy.ReqGetActivityBonus(_activityInfo.ActivityId, _rechargeCfgs[getState.index].id).Coroutine();
  189. }
  190. else
  191. {
  192. // 显示奖励详细列表
  193. //ViewManager.Show<UI_GiftDetailUI>
  194. }
  195. }
  196. }
  197. }