LimitChargeView.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.DailyWelfare;
  5. using UI.CommonGame;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class LimitChargeView : BaseWindow
  10. {
  11. private UI_LimitChargeUI _ui;
  12. private List<ActivityRechargeCfg> _rechargeCfgs;
  13. private ActivityInfo _activityInfo;
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_LimitChargeUI.PACKAGE_NAME;
  27. _ui = UI_LimitChargeUI.Create();
  28. this.viewCom = _ui.target;
  29. isfullScreen = true;
  30. _ui.m_list.itemRenderer = RenderListItem;
  31. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  32. _ui.m_btnCharge.onClick.Add(OnBtnChargeClick);
  33. ActivityOpenCfg openCfg = ActivityOpenCfgArray.Instance.GetCfg(ActivityDataManager.Instance.actLimitChargeId);
  34. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath(openCfg.res);
  35. }
  36. protected override void AddEventListener()
  37. {
  38. base.AddEventListener();
  39. EventAgent.AddEventListener(ConstMessage.ACTIVITY_REWARD_ADD, UpdateView);
  40. }
  41. protected override void OnShown()
  42. {
  43. base.OnShown();
  44. _rechargeCfgs = ActivityRechargeCfgArray.Instance.GetCfgsByactivityId(ActivityDataManager.Instance.actLimitChargeId);
  45. UpdateView();
  46. Timers.inst.Add(1, 0, UpdateTime);
  47. }
  48. protected override void OnHide()
  49. {
  50. base.OnHide();
  51. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  52. Timers.inst.Remove(UpdateTime);
  53. }
  54. protected override void RemoveEventListener()
  55. {
  56. base.RemoveEventListener();
  57. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_REWARD_ADD, UpdateView);
  58. }
  59. private void OnBtnBackClick()
  60. {
  61. ViewManager.GoBackFrom(typeof(LimitChargeView).FullName);
  62. }
  63. private void UpdateTime(object param)
  64. {
  65. ActivityOpenCfg openCfg = ActivityOpenCfgArray.Instance.GetCfg(ActivityDataManager.Instance.actLimitChargeId);
  66. long curTime = TimeHelper.ServerNow();
  67. long endTime = TimeUtil.DateTimeToTimestamp(openCfg.endTime);
  68. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  69. }
  70. private void OnBtnChargeClick()
  71. {
  72. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE });
  73. }
  74. private void UpdateView()
  75. {
  76. _activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(ActivityDataManager.Instance.actLimitChargeId);
  77. _ui.m_list.numItems = _rechargeCfgs.Count;
  78. }
  79. private void RenderListItem(int index, GObject obj)
  80. {
  81. UI_ListChargeItem item = UI_ListChargeItem.Proxy(obj);
  82. item.m_txtTitle.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].value, RoleDataManager.vipExp, _rechargeCfgs[index].value);
  83. int limitChargeExp = GameGlobal.myNumericComponent.GetAsInt(NumericType.RechargeTotal);
  84. if (limitChargeExp >= _rechargeCfgs[index].value)
  85. {
  86. item.m_c1.selectedIndex = _activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].id) > 0 ? 2 : 1;
  87. }
  88. else
  89. {
  90. item.m_c1.selectedIndex = 0;
  91. }
  92. if (item.m_btnGet.data == null)
  93. {
  94. item.m_btnGet.onClick.Add(OnBtnGetClick);
  95. }
  96. item.m_btnGet.data = _rechargeCfgs[index].id;
  97. if (item.m_listRewards.data == null)
  98. {
  99. item.m_listRewards.itemRenderer = RenderListRewardItem;
  100. }
  101. item.m_listRewards.data = _rechargeCfgs[index].bonusArr;
  102. item.m_listRewards.numItems = _rechargeCfgs[index].bonusArr.Length;
  103. UI_ListChargeItem.ProxyEnd();
  104. }
  105. private void RenderListRewardItem(int index, GObject obj)
  106. {
  107. UI_ComItem item = UI_ComItem.Proxy(obj);
  108. int[] reward = GlobalCfgArray.globalCfg.firstChargeBonusArr[index];
  109. ItemData itemData = ItemUtil.createItemData(reward);
  110. if (obj.data == null)
  111. {
  112. obj.data = new ItemView(obj as GComponent);
  113. }
  114. (obj.data as ItemView).SetData(itemData);
  115. UI_ComItem.ProxyEnd();
  116. }
  117. private void OnBtnGetClick(EventContext context)
  118. {
  119. GObject obj = context.sender as GObject;
  120. int id = (int)obj.data;
  121. ActivityGlobalSProxy.ReqGetActivityBonus(id, ActivityDataManager.Instance.actLimitChargeId).Coroutine();
  122. }
  123. }
  124. }