DailySupplyView.cs 8.6 KB

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