DailySupplyView.cs 7.7 KB

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