DailySupplyView.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 int _signCount;
  15. private int _month;
  16. private int _day;
  17. public override void Dispose()
  18. {
  19. base.Dispose();
  20. // if (_valueBarController != null)
  21. // {
  22. // _valueBarController.Dispose();
  23. // _valueBarController = null;
  24. // }
  25. if (_ui != null)
  26. {
  27. _ui.Dispose();
  28. _ui = null;
  29. }
  30. }
  31. protected override void OnInit()
  32. {
  33. base.OnInit();
  34. packageName = UI_DailySupplyUI.PACKAGE_NAME;
  35. _ui = UI_DailySupplyUI.Create();
  36. this.viewCom = _ui.target;
  37. this.viewCom.Center();
  38. this.modal = true;
  39. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  40. // _valueBarController = new ValueBarController(_ui.m_comValueBar);
  41. // _ui.m_btnback.onClick.Add(OnBtnBackClick);
  42. }
  43. protected override void AddEventListener()
  44. {
  45. base.AddEventListener();
  46. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSupplyView);
  47. }
  48. protected override void OnShown()
  49. {
  50. base.OnShown();
  51. _month = TimeUtil.GetCurMonth();
  52. _day = TimeUtil.GetCurDay();
  53. UpdateSupplyView();
  54. }
  55. protected override void OnHide()
  56. {
  57. // _valueBarController.OnHide();
  58. base.OnHide();
  59. }
  60. protected override void RemoveEventListener()
  61. {
  62. base.RemoveEventListener();
  63. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateSupplyView);
  64. }
  65. private void OnBtnBackClick()
  66. {
  67. ViewManager.GoBackFrom(typeof(DailyWelfareView).FullName);
  68. }
  69. private void UpdateView()
  70. {
  71. UpdateSupplyView();
  72. }
  73. private void UpdateSupplyView()
  74. {
  75. UpdateReward(_ui.m_comSupply0.target, DailySupplyCfgArray.Instance.dataArray[0].id);
  76. UpdateReward(_ui.m_comSupply1.target, DailySupplyCfgArray.Instance.dataArray[1].id);
  77. }
  78. private void UpdateReward(GObject obj, int id)
  79. {
  80. DailySupplyCfg supplyCfg = DailySupplyCfgArray.Instance.GetCfg(id);
  81. UI_ComSupply item = UI_ComSupply.Proxy(obj);
  82. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
  83. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
  84. item.m_txtTime.text = TimeUtil.FormattingTimeTo_HHmm(openTime) + "-" + TimeUtil.FormattingTimeTo_HHmm(endTime);
  85. item.m_txtCount.text = supplyCfg.bonusArr[0][1].ToString();
  86. ItemUtil.UpdateItemNeedNum(item.m_comCost, GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0], false, "#FFF6ED");
  87. item.m_comCost.visible = false;
  88. if (MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.DailySupplyReward), supplyCfg.id))
  89. {
  90. item.m_btnGet.title = "已领取";
  91. item.m_btnGet.enabled = false;
  92. return;
  93. }
  94. long curTime = TimeHelper.ServerNow();
  95. if (curTime < openTime && curTime > TimeUtil.GetCurDayTime(GlobalCfgArray.globalCfg.refreshTime))
  96. {
  97. item.m_btnGet.title = "领取";
  98. item.m_btnGet.enabled = false;
  99. }
  100. else if (curTime > openTime && curTime < endTime)
  101. {
  102. item.m_btnGet.title = "领取";
  103. item.m_btnGet.enabled = true;
  104. }
  105. else
  106. {
  107. item.m_comCost.visible = true;
  108. item.m_btnGet.title = "补领";
  109. item.m_btnGet.enabled = true;
  110. }
  111. if (item.m_btnGet.data == null)
  112. {
  113. item.m_btnGet.onClick.Add(OnBtnGetSupplyClick);
  114. }
  115. item.m_btnGet.data = supplyCfg;
  116. UI_ComSupply.ProxyEnd();
  117. }
  118. private void OnBtnGetSupplyClick(EventContext context)
  119. {
  120. GObject obj = context.sender as GObject;
  121. DailySupplyCfg supplyCfg = obj.data as DailySupplyCfg;
  122. long openTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.openTime).ToString("HH:mm:ss"));
  123. long endTime = TimeUtil.GetCurDayTime(TimeUtil.GetDateTime(supplyCfg.endTime).ToString("HH:mm:ss"));
  124. if (TimeHelper.ServerNow() > endTime)
  125. {
  126. int[] cost = GlobalCfgArray.globalCfg.dailySupplyConsumeArr[0];
  127. AlertUI.Show(string.Format("是否确定花费{0}{1}补领?", cost[1], ItemCfgArray.Instance.GetCfg(cost[0]).name)).
  128. SetLeftButton(true, "否").
  129. SetRightButton(true, "是", (object param) =>
  130. {
  131. if (ItemDataManager.GetItemNum(cost[0]) < cost[1])
  132. {
  133. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  134. return;
  135. }
  136. ReqSupplyAsync(supplyCfg.id);
  137. });
  138. }
  139. else
  140. {
  141. ReqSupplyAsync(supplyCfg.id);
  142. }
  143. }
  144. private async void ReqSupplyAsync(int id)
  145. {
  146. bool result = await DailyWelfareSProxy.ReqGetSupplyReward(id);
  147. if (result)
  148. {
  149. UpdateSupplyView();
  150. }
  151. }
  152. }
  153. }