DailySupplyView.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. }
  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. }
  79. protected override void OnHide()
  80. {
  81. // _valueBarController.OnHide();
  82. base.OnHide();
  83. _ui.m_t0.Stop();
  84. }
  85. protected override void RemoveEventListener()
  86. {
  87. base.RemoveEventListener();
  88. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSupplyView);
  89. }
  90. private void OnBtnBackClick()
  91. {
  92. ViewManager.GoBackFrom(typeof(DailyWelfareView).FullName);
  93. }
  94. private void UpdateView()
  95. {
  96. UpdateSupplyView();
  97. }
  98. private void UpdateSupplyView()
  99. {
  100. UpdateReward(_ui.m_comSupply.m_comSupply0.target, DailySupplyCfgArray.Instance.dataArray[0].id);
  101. UpdateReward(_ui.m_comSupply.m_comSupply1.target, DailySupplyCfgArray.Instance.dataArray[1].id);
  102. }
  103. private void UpdateReward(GObject obj, int id)
  104. {
  105. DailySupplyCfg supplyCfg = DailySupplyCfgArray.Instance.GetCfg(id);
  106. UI_ComSupplyItem item = UI_ComSupplyItem.Proxy(obj);
  107. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
  108. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
  109. item.m_txtTime.text = TimeUtil.FormattingTimeTo_HHmm(openTime) + "-" + TimeUtil.FormattingTimeTo_HHmm(endTime);
  110. item.m_txtCount.text = supplyCfg.bonusArr[0][1].ToString();
  111. ItemUtil.UpdateItemNeedNum(item.m_comCost, GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0], false, "#FFF6ED");
  112. item.m_comCost.visible = false;
  113. if (MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.DailySupplyReward), supplyCfg.id))
  114. {
  115. item.m_btnGet.title = "已领取";
  116. item.m_btnGet.enabled = false;
  117. return;
  118. }
  119. long curTime = TimeHelper.ServerNow();
  120. if (curTime < openTime && curTime > TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.refreshTime))
  121. {
  122. item.m_btnGet.title = "领取";
  123. item.m_btnGet.enabled = false;
  124. }
  125. else if (curTime > openTime && curTime < endTime)
  126. {
  127. item.m_btnGet.title = "领取";
  128. item.m_btnGet.enabled = true;
  129. }
  130. else
  131. {
  132. item.m_comCost.visible = true;
  133. item.m_btnGet.title = "补领";
  134. item.m_btnGet.enabled = true;
  135. }
  136. if (item.m_btnGet.data == null)
  137. {
  138. item.m_btnGet.onClick.Add(OnBtnGetSupplyClick);
  139. }
  140. item.m_btnGet.data = supplyCfg;
  141. UI_ComSupplyItem.ProxyEnd();
  142. }
  143. private void OnBtnGetSupplyClick(EventContext context)
  144. {
  145. GObject obj = context.sender as GObject;
  146. DailySupplyCfg supplyCfg = obj.data as DailySupplyCfg;
  147. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
  148. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
  149. if (TimeHelper.ServerNow() > endTime)
  150. {
  151. int[] cost = GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0];
  152. AlertUI.Show(string.Format("是否确定花费{0}{1}补领?", cost[1], ItemCfgArray.Instance.GetCfg(cost[0]).name)).
  153. SetLeftButton(true, "否").
  154. SetRightButton(true, "是", (object param) =>
  155. {
  156. if (ItemDataManager.GetItemNum(cost[0]) < cost[1])
  157. {
  158. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  159. return;
  160. }
  161. ReqSupplyAsync(supplyCfg.id);
  162. });
  163. }
  164. else
  165. {
  166. ReqSupplyAsync(supplyCfg.id);
  167. }
  168. }
  169. private async void ReqSupplyAsync(int id)
  170. {
  171. bool result = await DailyWelfareSProxy.ReqGetSupplyReward(id);
  172. if (result)
  173. {
  174. UpdateSupplyView();
  175. }
  176. }
  177. }
  178. }