DailySupplyView.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using ET;
  5. using FairyGUI;
  6. using Hutool;
  7. using UI.DailyWelfare;
  8. using UnityEngine;
  9. namespace GFGGame
  10. {
  11. public class DailySupplyView : BaseWindow
  12. {
  13. private UI_DailySupplyUI _ui;
  14. // private ValueBarController _valueBarController;
  15. private EffectUI _effectUI1;
  16. private EffectUI _effectUI2;
  17. private EffectUI _effectUI3;
  18. private EffectUI _effectUI4;
  19. private int _signCount;
  20. private int _month;
  21. private int _day;
  22. public override void Dispose()
  23. {
  24. // if (_valueBarController != null)
  25. // {
  26. // _valueBarController.Dispose();
  27. // _valueBarController = null;
  28. // }
  29. EffectUIPool.Recycle(_effectUI1);
  30. _effectUI1 = null;
  31. EffectUIPool.Recycle(_effectUI2);
  32. _effectUI2 = null;
  33. EffectUIPool.Recycle(_effectUI3);
  34. _effectUI3 = null;
  35. EffectUIPool.Recycle(_effectUI4);
  36. _effectUI4 = null;
  37. if (_ui != null)
  38. {
  39. _ui.Dispose();
  40. _ui = null;
  41. }
  42. base.Dispose();
  43. }
  44. protected override void OnInit()
  45. {
  46. base.OnInit();
  47. packageName = UI_DailySupplyUI.PACKAGE_NAME;
  48. _ui = UI_DailySupplyUI.Create();
  49. this.viewCom = _ui.target;
  50. this.viewCom.Center();
  51. this.modal = true;
  52. viewAnimationType = EnumViewAnimationType.None;
  53. // _valueBarController = new ValueBarController(_ui.m_comValueBar);
  54. // _ui.m_btnback.onClick.Add(OnBtnBackClick);
  55. UpdateEffect();
  56. }
  57. private void UpdateEffect()
  58. {
  59. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_Activity", "Time_thing_book");
  60. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_comSupply.m_holder, "ui_Activity", "Time_thing_hudie");
  61. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_comSupply.m_comSupply0.m_holder, "ui_Activity", "Time_thing_zhuti");
  62. _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_comSupply.m_comSupply1.m_holder, "ui_Activity", "Time_thing_zhuti");
  63. }
  64. protected override void AddEventListener()
  65. {
  66. base.AddEventListener();
  67. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSupplyView);
  68. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  69. }
  70. protected override void OnShown()
  71. {
  72. base.OnShown();
  73. _month = TimeUtil.GetCurMonth();
  74. _day = TimeUtil.GetCurDay();
  75. UpdateSupplyView();
  76. _ui.m_t0.Play();
  77. UpdateRedDot();
  78. }
  79. protected override void OnHide()
  80. {
  81. // _valueBarController.OnHide();
  82. base.OnHide();
  83. _ui.m_t0.Stop();
  84. }
  85. protected override void RemoveEventListener()
  86. {
  87. base.RemoveEventListener();
  88. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSupplyView);
  89. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  90. }
  91. private void OnBtnBackClick()
  92. {
  93. ViewManager.GoBackFrom(typeof(DailyWelfareView).FullName);
  94. }
  95. private void UpdateView()
  96. {
  97. UpdateSupplyView();
  98. }
  99. private void UpdateSupplyView()
  100. {
  101. UpdateReward(_ui.m_comSupply.m_comSupply0.target, DailySupplyCfgArray.Instance.dataArray[0].id);
  102. UpdateReward(_ui.m_comSupply.m_comSupply1.target, DailySupplyCfgArray.Instance.dataArray[1].id);
  103. }
  104. private void UpdateReward(GObject obj, int id)
  105. {
  106. DailySupplyCfg supplyCfg = DailySupplyCfgArray.Instance.GetCfg(id);
  107. UI_ComSupplyItem item = UI_ComSupplyItem.Proxy(obj);
  108. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
  109. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
  110. item.m_txtTime.text = TimeUtil.FormattingTimeTo_HHmm(openTime) + "-" + TimeUtil.FormattingTimeTo_HHmm(endTime);
  111. item.m_txtCount.text = supplyCfg.bonusArr[0][1].ToString();
  112. ItemUtil.UpdateItemNeedNum(item.m_comCost, GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0], false, "#FFF6ED");
  113. item.m_comCost.visible = false;
  114. if (MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.DailySupplyReward), supplyCfg.id))
  115. {
  116. item.m_btnGet.title = "已领取";
  117. item.m_btnGet.enabled = false;
  118. return;
  119. }
  120. long curTime = TimeHelper.ServerNow();
  121. if (curTime < openTime && curTime > TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.refreshTime))
  122. {
  123. item.m_btnGet.title = "领取";
  124. item.m_btnGet.enabled = false;
  125. }
  126. else if (curTime > openTime && curTime < endTime)
  127. {
  128. item.m_btnGet.title = "领取";
  129. item.m_btnGet.enabled = true;
  130. }
  131. else
  132. {
  133. item.m_comCost.visible = true;
  134. item.m_btnGet.title = "补领";
  135. item.m_btnGet.enabled = true;
  136. }
  137. if (item.m_btnGet.data == null)
  138. {
  139. item.m_btnGet.onClick.Add(OnBtnGetSupplyClick);
  140. }
  141. item.m_btnGet.data = supplyCfg;
  142. UI_ComSupplyItem.ProxyEnd();
  143. }
  144. private void OnBtnGetSupplyClick(EventContext context)
  145. {
  146. GObject obj = context.sender as GObject;
  147. DailySupplyCfg supplyCfg = obj.data as DailySupplyCfg;
  148. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
  149. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
  150. if (TimeHelper.ServerNow() > endTime)
  151. {
  152. int[] cost = GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0];
  153. AlertUI.Show(string.Format("是否确定花费{0}{1}补领?", cost[1], ItemCfgArray.Instance.GetCfg(cost[0]).name)).
  154. SetLeftButton(true, "否").
  155. SetRightButton(true, "是", (object param) =>
  156. {
  157. if (ItemDataManager.GetItemNum(cost[0]) < cost[1])
  158. {
  159. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  160. return;
  161. }
  162. ReqSupplyAsync(supplyCfg.id);
  163. });
  164. }
  165. else
  166. {
  167. ReqSupplyAsync(supplyCfg.id);
  168. }
  169. }
  170. private async void ReqSupplyAsync(int id)
  171. {
  172. bool result = await DailyWelfareSProxy.ReqGetSupplyReward(id);
  173. if (result)
  174. {
  175. UpdateSupplyView();
  176. }
  177. }
  178. private void UpdateRedDot()
  179. {
  180. RedDotController.Instance.SetComRedDot(_ui.m_comSupply.m_comSupply0.m_btnGet, RedDotDataManager.Instance.DailySupplyRed(DailySupplyCfgArray.Instance.dataArray[0]));
  181. RedDotController.Instance.SetComRedDot(_ui.m_comSupply.m_comSupply1.m_btnGet, RedDotDataManager.Instance.DailySupplyRed(DailySupplyCfgArray.Instance.dataArray[1]));
  182. }
  183. }
  184. }