DailySupplyView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_Activity", "Time_thing_book");
  61. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_comSupply.m_holder, "ui_Activity", "Time_thing_hudie");
  62. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_comSupply.m_comSupply0.m_holder, "ui_Activity",
  63. "Time_thing_zhuti");
  64. _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_comSupply.m_comSupply1.m_holder, "ui_Activity",
  65. "Time_thing_zhuti");
  66. }
  67. protected override void AddEventListener()
  68. {
  69. base.AddEventListener();
  70. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSupplyView);
  71. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  72. }
  73. protected override void OnShown()
  74. {
  75. base.OnShown();
  76. _month = TimeUtil.GetCurMonth();
  77. _day = TimeUtil.GetCurDay();
  78. UpdateSupplyView();
  79. _ui.m_t0.Play();
  80. UpdateRedDot();
  81. }
  82. protected override void OnHide()
  83. {
  84. // _valueBarController.OnHide();
  85. base.OnHide();
  86. _ui.m_t0.Stop();
  87. }
  88. protected override void RemoveEventListener()
  89. {
  90. base.RemoveEventListener();
  91. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSupplyView);
  92. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  93. }
  94. private void OnBtnBackClick()
  95. {
  96. ViewManager.GoBackFrom(typeof(DailyWelfareView).FullName);
  97. }
  98. private void UpdateView()
  99. {
  100. UpdateSupplyView();
  101. }
  102. private void UpdateSupplyView()
  103. {
  104. UpdateReward(_ui.m_comSupply.m_comSupply0.target,
  105. CommonDataManager.Tables.TblDailySupplyCfg.DataList[0].Id);
  106. UpdateReward(_ui.m_comSupply.m_comSupply1.target,
  107. CommonDataManager.Tables.TblDailySupplyCfg.DataList[1].Id);
  108. }
  109. private void UpdateReward(GObject obj, int id)
  110. {
  111. DailySupplyCfg supplyCfg = CommonDataManager.Tables.TblDailySupplyCfg.GetOrDefault(id);
  112. UI_ComSupplyItem item = UI_ComSupplyItem.Proxy(obj);
  113. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.OpenTime).ToString("HH:mm:ss"));
  114. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.EndTime).ToString("HH:mm:ss"));
  115. item.m_txtTime.text =
  116. TimeUtil.FormattingTimeTo_HHmm(openTime) + "-" + TimeUtil.FormattingTimeTo_HHmm(endTime);
  117. item.m_txtCount.text = supplyCfg.Bonus[0].Count.ToString();
  118. ItemUtil.UpdateItemNeedNum(item.m_comCost,
  119. CommonDataManager.Tables.TblGlobalCfg.DailySupplyConsume[0].ToGfgGameItemParam(), false, "#FFF6ED");
  120. item.m_comCost.visible = false;
  121. if (MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.DailySupplyReward), supplyCfg.Id))
  122. {
  123. item.m_btnGet.title = "已领取";
  124. item.m_btnGet.enabled = false;
  125. return;
  126. }
  127. long curTime = TimeHelper.ServerNow();
  128. if (curTime < openTime && curTime >
  129. TimeUtil.GetCurDayTime(CommonDataManager.Tables.TblGlobalCfg.RefreshTime.Split(' ')[1]))
  130. {
  131. item.m_btnGet.title = "领取";
  132. item.m_btnGet.enabled = false;
  133. }
  134. else if (curTime > openTime && curTime < endTime)
  135. {
  136. item.m_btnGet.title = "领取";
  137. item.m_btnGet.enabled = true;
  138. }
  139. else
  140. {
  141. item.m_comCost.visible = true;
  142. item.m_btnGet.title = "补领";
  143. item.m_btnGet.enabled = true;
  144. }
  145. if (item.m_btnGet.data == null)
  146. {
  147. item.m_btnGet.onClick.Add(OnBtnGetSupplyClick);
  148. }
  149. item.m_btnGet.data = supplyCfg;
  150. UI_ComSupplyItem.ProxyEnd();
  151. }
  152. private void OnBtnGetSupplyClick(EventContext context)
  153. {
  154. GObject obj = context.sender as GObject;
  155. DailySupplyCfg supplyCfg = obj.data as DailySupplyCfg;
  156. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.OpenTime).ToString("HH:mm:ss"));
  157. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.EndTime).ToString("HH:mm:ss"));
  158. if (TimeHelper.ServerNow() > endTime)
  159. {
  160. ItemParamProto cost = CommonDataManager.Tables.TblGlobalCfg.DailySupplyConsume[0].ToGfgGameItemParam();
  161. AlertUI.Show(string.Format("是否确定花费{0}{1}补领?", cost.Count,
  162. CommonDataManager.Tables.TblItemCfg.GetOrDefault(cost.ItemId).Name)).SetLeftButton(true, "否")
  163. .SetRightButton(true, "是", (object param) =>
  164. {
  165. if (ItemDataManager.GetItemNum(cost.ItemId) < cost.Count)
  166. {
  167. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  168. return;
  169. }
  170. ReqSupplyAsync(supplyCfg.Id);
  171. });
  172. }
  173. else
  174. {
  175. ReqSupplyAsync(supplyCfg.Id);
  176. }
  177. }
  178. private async void ReqSupplyAsync(int id)
  179. {
  180. bool result = await DailyWelfareSProxy.ReqGetSupplyReward(id);
  181. if (result)
  182. {
  183. UpdateSupplyView();
  184. }
  185. }
  186. private void UpdateRedDot()
  187. {
  188. RedDotController.Instance.SetComRedDot(_ui.m_comSupply.m_comSupply0.m_btnGet,
  189. RedDotDataManager.Instance.DailySupplyRed(CommonDataManager.Tables.TblDailySupplyCfg.DataList[0]));
  190. RedDotController.Instance.SetComRedDot(_ui.m_comSupply.m_comSupply1.m_btnGet,
  191. RedDotDataManager.Instance.DailySupplyRed(CommonDataManager.Tables.TblDailySupplyCfg.DataList[1]));
  192. }
  193. }
  194. }