LimitChargeView.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. _ui = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. packageName = UI_LimitChargeUI.PACKAGE_NAME;
  26. _ui = UI_LimitChargeUI.Create();
  27. this.viewCom = _ui.target;
  28. this.modal = true;
  29. this.viewCom.Center();
  30. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  31. _ui.m_list.itemRenderer = RenderListItem;
  32. _ui.m_btnCharge.onClick.Add(OnBtnChargeClick);
  33. }
  34. protected override void OnShown()
  35. {
  36. base.OnShown();
  37. _rechargeCfgs = ActivityRechargeCfgArray.Instance.GetCfgsByid(ActivityDataManager.Instance.actLimitChargeId);
  38. UpdateView();
  39. Timers.inst.Add(1, 0, UpdateTime);
  40. }
  41. protected override void OnHide()
  42. {
  43. base.OnHide();
  44. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  45. Timers.inst.Remove(UpdateTime);
  46. }
  47. private void UpdateTime(object param)
  48. {
  49. ActivityOpenCfg openCfg = ActivityOpenCfgArray.Instance.GetCfg(ActivityDataManager.Instance.actLimitChargeId);
  50. long curTime = TimeHelper.ServerNow();
  51. long endTime = TimeUtil.DateTimeToTimestamp(openCfg.endTime);
  52. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  53. }
  54. private void OnBtnChargeClick()
  55. {
  56. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE });
  57. }
  58. private void UpdateView()
  59. {
  60. _ui.m_list.numItems = _rechargeCfgs.Count;
  61. }
  62. private void RenderListItem(int index, GObject obj)
  63. {
  64. UI_ListChargeItem item = UI_ListChargeItem.Proxy(obj);
  65. item.m_txtTitle.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].value, RoleDataManager.vipExp, _rechargeCfgs[index].value);
  66. if (item.m_btnGet.data == null)
  67. {
  68. item.m_btnGet.onClick.Add(OnBtnGetClick);
  69. }
  70. item.m_btnGet.data = _rechargeCfgs[index].value;
  71. if (item.m_listRewards.data == null)
  72. {
  73. item.m_listRewards.itemRenderer = RenderListRewardItem;
  74. }
  75. item.m_listRewards.data = _rechargeCfgs[index].bonusArr;
  76. item.m_listRewards.numItems = _rechargeCfgs[index].bonusArr.Length;
  77. UI_ListChargeItem.ProxyEnd();
  78. }
  79. private void RenderListRewardItem(int index, GObject obj)
  80. {
  81. UI_ComItem item = UI_ComItem.Proxy(obj);
  82. int[] reward = GlobalCfgArray.globalCfg.firstChargeBonusArr[index];
  83. ItemData itemData = ItemUtil.createItemData(reward);
  84. if (obj.data == null)
  85. {
  86. obj.data = new ItemView(obj as GComponent);
  87. }
  88. (obj.data as ItemView).SetData(itemData);
  89. UI_ComItem.ProxyEnd();
  90. }
  91. private async void OnBtnGetClick(EventContext context)
  92. {
  93. GObject obj = context.sender as GObject;
  94. int value = (int)obj.data;
  95. bool result = await ActivitySProxy.ReqGetLimitChargeBonus(ActivityDataManager.Instance.actLimitChargeId, value);
  96. if (result)
  97. {
  98. UpdateView();
  99. }
  100. }
  101. }
  102. }