LuckyBoxActivityView.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using FairyGUI;
  2. using UI.LuckyBox;
  3. using UI.CommonGame;
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using ET;
  8. namespace GFGGame
  9. {
  10. public class LuckyBoxActivityView : BaseWindow
  11. {
  12. private UI_LuckyBoxActivityUI _ui;
  13. private ValueBarController _valueBarController;
  14. private LuckyBoxController _luckyBoxCtrl;
  15. private ActivityOpenCfg _activityCfg;
  16. private LuckyBoxCfg _luckyBoxCfg;
  17. private int _activityId;
  18. public override void Dispose()
  19. {
  20. if (_valueBarController != null)
  21. {
  22. _valueBarController.Dispose();
  23. _valueBarController = null;
  24. }
  25. if (_luckyBoxCtrl != null)
  26. {
  27. _luckyBoxCtrl.Dispose();
  28. _luckyBoxCtrl = null;
  29. }
  30. if (_ui != null)
  31. {
  32. _ui.Dispose();
  33. _ui = null;
  34. }
  35. base.Dispose();
  36. }
  37. protected override void OnInit()
  38. {
  39. base.OnInit();
  40. packageName = UI_LuckyBoxActivityUI.PACKAGE_NAME;
  41. _ui = UI_LuckyBoxActivityUI.Create();
  42. this.viewCom = _ui.target;
  43. isfullScreen = true;
  44. _valueBarController = new ValueBarController(_ui.m_valueBar);
  45. _luckyBoxCtrl = new LuckyBoxController(_ui.m_comBox.m_comModel.target);
  46. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  47. _ui.m_btnReward.onClick.Add(OnClikcBtnReward);
  48. _ui.m_btnShop.onClick.Add(OnClikcBtnShop);
  49. _ui.m_btnGiftBag.onClick.Add(OnClikcBtnGiftBag);
  50. }
  51. protected override void AddEventListener()
  52. {
  53. base.AddEventListener();
  54. EventAgent.AddEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateView);
  55. }
  56. protected override void OnShown()
  57. {
  58. base.OnShown();
  59. _activityId = (int)this.viewData;
  60. _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(_activityId);
  61. _luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(_activityCfg.paramsArr[0]);
  62. _valueBarController.OnShown();
  63. _valueBarController.UpdateList(new List<int>() { _luckyBoxCfg.costID });
  64. _luckyBoxCtrl.OnShown(_luckyBoxCfg.id);
  65. UpdateView();
  66. Timers.inst.Add(1, 0, UpdateTime);
  67. }
  68. private void UpdateTime(object param = null)
  69. {
  70. long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.endTime);
  71. long curTime = TimeHelper.ServerNow();
  72. if (endTime < curTime)
  73. {
  74. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  75. Timers.inst.Remove(UpdateTime);
  76. OnClickBtnBack();
  77. return;
  78. }
  79. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  80. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  81. //限时礼包窗口内的倒计时
  82. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_ACTIVITY_TIMERS);
  83. }
  84. private void UpdateView()
  85. {
  86. _ui.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastDrawCount.ToString()).FlushVars();
  87. _ui.m_txtCount.SetVar("name", _activityCfg.themeName).FlushVars();
  88. UI_ComBox_4 comBox = UI_ComBox_4.Proxy(_ui.m_comBox.target);
  89. LuckyBoxDataManager.Instance.InitData(_luckyBoxCfg.id);
  90. comBox.m_comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[0]);
  91. comBox.m_btnPreview.m_c1.selectedIndex = 1;
  92. LuckyBoxDataManager.Instance.GetOwnedCount(_luckyBoxCfg.id, out int count, out int totalCount);
  93. comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  94. comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
  95. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  96. comBox.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", _luckyBoxCfg.maxCount - boughtCount);
  97. comBox.m_comCostOne.m_txtCost.text = _luckyBoxCfg.costNum.ToString();
  98. comBox.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(_luckyBoxCfg.costID).res);
  99. comBox.m_comCostTen.m_txtCost.text = _luckyBoxCfg.costNumTen.ToString();
  100. comBox.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(_luckyBoxCfg.costID).res);
  101. if (comBox.m_btnBuyOne.target.data == null)
  102. {
  103. comBox.m_btnBuyOne.target.onClick.Add(OnClickBtnBuyOne);
  104. }
  105. comBox.m_btnBuyOne.target.data = _luckyBoxCfg.id;
  106. if (comBox.m_btnBuyTen.target.data == null)
  107. {
  108. comBox.m_btnBuyTen.target.onClick.Add(OnClickBtnBuyTen);
  109. }
  110. comBox.m_btnBuyTen.target.data = _luckyBoxCfg.id;
  111. if (comBox.m_btnPreview.target.data == null)
  112. {
  113. comBox.m_btnPreview.target.onClick.Add(OnClickBtnPreview);
  114. }
  115. comBox.m_btnPreview.target.data = _luckyBoxCfg.id;
  116. comBox.target.data = _luckyBoxCfg.id;
  117. UI_ComBox_4.ProxyEnd();
  118. }
  119. private void OnClickBtnPreview(EventContext context)
  120. {
  121. GObject obj = context.sender as GObject;
  122. int boxId = (int)obj.data;
  123. ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW, boxId);
  124. }
  125. private void OnClickBtnBuyOne(EventContext context)
  126. {
  127. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  128. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > _luckyBoxCfg.maxCount)
  129. {
  130. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  131. return;
  132. }
  133. LuckyBoxDataManager.Instance.CheckItemEnough(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME, async () =>
  134. {
  135. bool result = await LuckyBoxSProxy.ReqGetBonus(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME);
  136. if (result)
  137. {
  138. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
  139. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  140. }
  141. });
  142. }
  143. private void OnClickBtnBuyTen(EventContext context)
  144. {
  145. GObject obj = context.sender as GObject;
  146. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  147. if (boughtCount + LuckyBoxDataManager.TEN_TIME > _luckyBoxCfg.maxCount)
  148. {
  149. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  150. return;
  151. }
  152. LuckyBoxDataManager.Instance.CheckItemEnough(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME, async () =>
  153. {
  154. bool result = await LuckyBoxSProxy.ReqGetBonus(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME);
  155. if (result)
  156. {
  157. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
  158. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  159. }
  160. });
  161. }
  162. private void OnClikcBtnReward()
  163. {
  164. ViewManager.Show<ActivityThemeLuckyBoxBonusView>();
  165. }
  166. private void OnClikcBtnShop()
  167. {
  168. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY });
  169. }
  170. private void OnClikcBtnGiftBag()
  171. {
  172. }
  173. protected override void OnHide()
  174. {
  175. base.OnHide();
  176. _valueBarController.OnHide();
  177. _luckyBoxCtrl.OnHide();
  178. Timers.inst.Remove(UpdateTime);
  179. }
  180. protected override void RemoveEventListener()
  181. {
  182. base.RemoveEventListener();
  183. }
  184. private void OnClickBtnBack()
  185. {
  186. ViewManager.GoBackFrom(typeof(LuckyBoxActivityView).FullName);
  187. }
  188. protected override void UpdateToCheckGuide(object param)
  189. {
  190. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  191. }
  192. protected override void TryCompleteGuide()
  193. {
  194. base.TryCompleteGuide();
  195. }
  196. }
  197. }