LuckyBoxActivityView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. }
  55. protected override void OnShown()
  56. {
  57. base.OnShown();
  58. _activityId = (int)this.viewData;
  59. _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(_activityId);
  60. _luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(_activityCfg.paramsArr[0]);
  61. _valueBarController.OnShown();
  62. _valueBarController.UpdateList(new List<int>() { _luckyBoxCfg.costID });
  63. _luckyBoxCtrl.OnShown(_luckyBoxCfg.id);
  64. UpdateView();
  65. Timers.inst.Add(1, 0, UpdateTime);
  66. }
  67. private void UpdateTime(object param = null)
  68. {
  69. long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.endTime);
  70. long curTime = TimeHelper.ServerNow();
  71. if (endTime < curTime)
  72. {
  73. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  74. Timers.inst.Remove(UpdateTime);
  75. OnClickBtnBack();
  76. return;
  77. }
  78. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  79. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  80. }
  81. private void UpdateView()
  82. {
  83. UI_ComBox_4 comBox = UI_ComBox_4.Proxy(_ui.m_comBox.target);
  84. LuckyBoxDataManager.Instance.InitData(_luckyBoxCfg.id);
  85. comBox.m_comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[0]);
  86. comBox.m_btnPreview.m_c1.selectedIndex = 1;
  87. LuckyBoxDataManager.Instance.GetOwnedCount(_luckyBoxCfg.id, out int count, out int totalCount);
  88. comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  89. comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
  90. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  91. comBox.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", _luckyBoxCfg.maxCount - boughtCount);
  92. comBox.m_comCostOne.m_txtCost.text = _luckyBoxCfg.costNum.ToString();
  93. comBox.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(_luckyBoxCfg.costID).res);
  94. comBox.m_comCostTen.m_txtCost.text = _luckyBoxCfg.costNumTen.ToString();
  95. comBox.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(_luckyBoxCfg.costID).res);
  96. if (comBox.m_btnBuyOne.target.data == null)
  97. {
  98. comBox.m_btnBuyOne.target.onClick.Add(OnClickBtnBuyOne);
  99. }
  100. comBox.m_btnBuyOne.target.data = _luckyBoxCfg.id;
  101. if (comBox.m_btnBuyTen.target.data == null)
  102. {
  103. comBox.m_btnBuyTen.target.onClick.Add(OnClickBtnBuyTen);
  104. }
  105. comBox.m_btnBuyTen.target.data = _luckyBoxCfg.id;
  106. if (comBox.m_btnPreview.target.data == null)
  107. {
  108. comBox.m_btnPreview.target.onClick.Add(OnClickBtnPreview);
  109. }
  110. comBox.m_btnPreview.target.data = _luckyBoxCfg.id;
  111. comBox.target.data = _luckyBoxCfg.id;
  112. UI_ComBox_4.ProxyEnd();
  113. }
  114. private void OnClickBtnPreview(EventContext context)
  115. {
  116. GObject obj = context.sender as GObject;
  117. int boxId = (int)obj.data;
  118. ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW, boxId);
  119. }
  120. private void OnClickBtnBuyOne(EventContext context)
  121. {
  122. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  123. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > _luckyBoxCfg.maxCount)
  124. {
  125. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  126. return;
  127. }
  128. LuckyBoxDataManager.Instance.CheckItemEnough(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME, async () =>
  129. {
  130. bool result = await LuckyBoxSProxy.ReqGetBonus(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME);
  131. if (result)
  132. {
  133. ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, null, new object[] { ViewName.LUCKY_BOX_VIEW, _luckyBoxCfg.id });
  134. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  135. }
  136. });
  137. }
  138. private void OnClickBtnBuyTen(EventContext context)
  139. {
  140. GObject obj = context.sender as GObject;
  141. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  142. if (boughtCount + LuckyBoxDataManager.TEN_TIME > _luckyBoxCfg.maxCount)
  143. {
  144. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  145. return;
  146. }
  147. LuckyBoxDataManager.Instance.CheckItemEnough(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME, async () =>
  148. {
  149. bool result = await LuckyBoxSProxy.ReqGetBonus(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME);
  150. if (result)
  151. {
  152. ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, null, new object[] { ViewName.LUCKY_BOX_VIEW, this._luckyBoxCfg.id });
  153. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  154. }
  155. });
  156. }
  157. private void OnClikcBtnReward()
  158. {
  159. }
  160. private void OnClikcBtnShop()
  161. {
  162. }
  163. private void OnClikcBtnGiftBag()
  164. {
  165. }
  166. protected override void OnHide()
  167. {
  168. base.OnHide();
  169. _valueBarController.OnHide();
  170. _luckyBoxCtrl.OnHide();
  171. Timers.inst.Remove(UpdateTime);
  172. }
  173. protected override void RemoveEventListener()
  174. {
  175. base.RemoveEventListener();
  176. }
  177. private void OnClickBtnBack()
  178. {
  179. ViewManager.GoBackFrom(typeof(LuckyBoxActivityView).FullName);
  180. }
  181. protected override void UpdateToCheckGuide(object param)
  182. {
  183. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  184. }
  185. protected override void TryCompleteGuide()
  186. {
  187. base.TryCompleteGuide();
  188. }
  189. }
  190. }