DailySupplyView.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 GameObject _gameObject0;
  16. private GameObject _gameObject1;
  17. private GameObject _gameObject2;
  18. private GameObject _gameObject3;
  19. private GoWrapper _wrapper0;
  20. private GoWrapper _wrapper1;
  21. private GoWrapper _wrapper2;
  22. private GoWrapper _wrapper3;
  23. private int _signCount;
  24. private int _month;
  25. private int _day;
  26. public override void Dispose()
  27. {
  28. base.Dispose();
  29. // if (_valueBarController != null)
  30. // {
  31. // _valueBarController.Dispose();
  32. // _valueBarController = null;
  33. // }
  34. SceneController.DestroyObjectFromView(_gameObject0, _wrapper0);
  35. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  36. SceneController.DestroyObjectFromView(_gameObject2, _wrapper2);
  37. SceneController.DestroyObjectFromView(_gameObject3, _wrapper3);
  38. if (_ui != null)
  39. {
  40. _ui.Dispose();
  41. _ui = null;
  42. }
  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. string resPath = ResPathUtil.GetViewEffectPath("ui_Activity", "Time_thing_book");
  60. SceneController.AddObjectToView(null, null, _ui.m_holder, resPath, out _gameObject0, out _wrapper0);
  61. string resPath1 = ResPathUtil.GetViewEffectPath("ui_Activity", "Time_thing_hudie");
  62. SceneController.AddObjectToView(null, null, _ui.m_comSupply.m_holder, resPath1, out _gameObject1, out _wrapper1);
  63. string resPath2 = ResPathUtil.GetViewEffectPath("ui_Activity", "Time_thing_zhuti");
  64. SceneController.AddObjectToView(null, null, _ui.m_comSupply.m_comSupply0.m_holder, resPath2, out _gameObject2, out _wrapper2);
  65. SceneController.AddObjectToView(null, null, _ui.m_comSupply.m_comSupply1.m_holder, resPath2, out _gameObject3, out _wrapper3);
  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, DailySupplyCfgArray.Instance.dataArray[0].id);
  105. UpdateReward(_ui.m_comSupply.m_comSupply1.target, DailySupplyCfgArray.Instance.dataArray[1].id);
  106. }
  107. private void UpdateReward(GObject obj, int id)
  108. {
  109. DailySupplyCfg supplyCfg = DailySupplyCfgArray.Instance.GetCfg(id);
  110. UI_ComSupplyItem item = UI_ComSupplyItem.Proxy(obj);
  111. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
  112. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
  113. item.m_txtTime.text = TimeUtil.FormattingTimeTo_HHmm(openTime) + "-" + TimeUtil.FormattingTimeTo_HHmm(endTime);
  114. item.m_txtCount.text = supplyCfg.bonusArr[0][1].ToString();
  115. ItemUtil.UpdateItemNeedNum(item.m_comCost, GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0], false, "#FFF6ED");
  116. item.m_comCost.visible = false;
  117. if (MathUtil.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 && curTime > TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.refreshTime))
  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_ComSupplyItem.ProxyEnd();
  146. }
  147. private 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. if (TimeHelper.ServerNow() > endTime)
  154. {
  155. int[] cost = GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0];
  156. AlertUI.Show(string.Format("是否确定花费{0}{1}补领?", cost[1], ItemCfgArray.Instance.GetCfg(cost[0]).name)).
  157. SetLeftButton(true, "否").
  158. SetRightButton(true, "是", (object param) =>
  159. {
  160. if (ItemDataManager.GetItemNum(cost[0]) < cost[1])
  161. {
  162. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  163. return;
  164. }
  165. ReqSupplyAsync(supplyCfg.id);
  166. });
  167. }
  168. else
  169. {
  170. ReqSupplyAsync(supplyCfg.id);
  171. }
  172. }
  173. private async void ReqSupplyAsync(int id)
  174. {
  175. bool result = await DailyWelfareSProxy.ReqGetSupplyReward(id);
  176. if (result)
  177. {
  178. UpdateSupplyView();
  179. }
  180. }
  181. private void UpdateRedDot()
  182. {
  183. RedDotController.Instance.SetComRedDot(_ui.m_comSupply.m_comSupply0.m_btnGet, RedDotDataManager.Instance.DailySupplyRed(DailySupplyCfgArray.Instance.dataArray[0]));
  184. RedDotController.Instance.SetComRedDot(_ui.m_comSupply.m_comSupply1.m_btnGet, RedDotDataManager.Instance.DailySupplyRed(DailySupplyCfgArray.Instance.dataArray[1]));
  185. }
  186. }
  187. }