DailySupplyView.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.DailyWelfare;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class DailySupplyView : BaseWindow
  10. {
  11. private UI_DailySupplyUI _ui;
  12. // private ValueBarController _valueBarController;
  13. private int _signCount;
  14. private int _month;
  15. private int _day;
  16. public override void Dispose()
  17. {
  18. base.Dispose();
  19. // if (_valueBarController != null)
  20. // {
  21. // _valueBarController.Dispose();
  22. // _valueBarController = null;
  23. // }
  24. if (_ui != null)
  25. {
  26. _ui.Dispose();
  27. _ui = null;
  28. }
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. packageName = UI_DailySupplyUI.PACKAGE_NAME;
  34. _ui = UI_DailySupplyUI.Create();
  35. this.viewCom = _ui.target;
  36. isfullScreen = true;
  37. // _valueBarController = new ValueBarController(_ui.m_comValueBar);
  38. // _ui.m_btnback.onClick.Add(OnBtnBackClick);
  39. }
  40. protected override void AddEventListener()
  41. {
  42. base.AddEventListener();
  43. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateView);
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. // _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("mrqd_bjbj");
  49. // _valueBarController.OnShown();
  50. if (TimeHelper.ClientNow() < TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.refreshTime))
  51. {
  52. if (DateTime.Now.Day == 1)
  53. {
  54. if (DateTime.Now.Month == 1)
  55. {
  56. _month = 12;
  57. }
  58. else
  59. {
  60. _month = DateTime.Now.Month - 1;
  61. }
  62. List<DailySignBonusCfg> cfgs = DailySignBonusCfgArray.Instance.GetCfgsBymonth(_month);
  63. _day = cfgs[cfgs.Count - 1].day;
  64. }
  65. else
  66. {
  67. _day = DateTime.Now.Day - 1;
  68. }
  69. }
  70. else
  71. {
  72. _month = DateTime.Now.Month;
  73. _day = DateTime.Now.Day;
  74. }
  75. // _ui.m_list.ScrollToView(0);
  76. UpdateView();
  77. }
  78. protected override void OnHide()
  79. {
  80. // _valueBarController.OnHide();
  81. base.OnHide();
  82. }
  83. protected override void RemoveEventListener()
  84. {
  85. base.RemoveEventListener();
  86. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateView);
  87. }
  88. private void OnBtnBackClick()
  89. {
  90. ViewManager.GoBackFrom(typeof(DailyWelfareView).FullName);
  91. }
  92. private void UpdateView()
  93. {
  94. UpdateSupplyView();
  95. }
  96. private void UpdateSupplyView()
  97. {
  98. UpdateReward(_ui.m_comSupply0.target, DailySupplyCfgArray.Instance.dataArray[0].id);
  99. UpdateReward(_ui.m_comSupply1.target, DailySupplyCfgArray.Instance.dataArray[1].id);
  100. }
  101. private void UpdateReward(GObject obj, int id)
  102. {
  103. DailySupplyCfg supplyCfg = DailySupplyCfgArray.Instance.GetCfg(id);
  104. UI_ComSupply item = UI_ComSupply.Proxy(obj);
  105. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
  106. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
  107. item.m_txtTime.text = TimeUtil.FormattingTime6(openTime) + "-" + TimeUtil.FormattingTime6(endTime);
  108. if (item.m_comItem.data == null)
  109. {
  110. item.m_comItem.data = new ItemView(item.m_comItem);
  111. }
  112. ItemData itemData = ItemUtil.createItemData(supplyCfg.bonusArr[0]);
  113. (item.m_comItem.data as ItemView).SetData(itemData);
  114. (item.m_comItem.data as ItemView).ShowTips = false;
  115. ItemUtil.UpdateItemNeedNum(item.m_comCost, GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0]);
  116. item.m_comCost.visible = false;
  117. if (MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.DailySupplyReward), supplyCfg.id))
  118. {
  119. item.m_btnGet.title = "已领取";
  120. item.m_btnGet.enabled = false;
  121. return;
  122. }
  123. long curTime = TimeHelper.ServerNow();
  124. if (curTime < openTime)
  125. {
  126. item.m_btnGet.title = "领取";
  127. item.m_btnGet.enabled = false;
  128. }
  129. else if (curTime > openTime && curTime < endTime)
  130. {
  131. item.m_btnGet.title = "领取";
  132. item.m_btnGet.enabled = true;
  133. }
  134. else
  135. {
  136. item.m_comCost.visible = true;
  137. item.m_btnGet.title = "补领";
  138. item.m_btnGet.enabled = true;
  139. }
  140. if (item.m_btnGet.data == null)
  141. {
  142. item.m_btnGet.onClick.Add(OnBtnGetSupplyClick);
  143. }
  144. item.m_btnGet.data = supplyCfg;
  145. UI_ComSupply.ProxyEnd();
  146. }
  147. private async void OnBtnGetSupplyClick(EventContext context)
  148. {
  149. GObject obj = context.sender as GObject;
  150. DailySupplyCfg supplyCfg = obj.data as DailySupplyCfg;
  151. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
  152. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
  153. bool result = await DailyWelfareSProxy.ReqGetSupplyReward(supplyCfg.id);
  154. if (result)
  155. {
  156. UpdateSupplyView();
  157. }
  158. }
  159. }
  160. }