DailySupplyView.cs 8.0 KB

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