LuckyBoxActivityView.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. private void UpdateView()
  83. {
  84. _ui.m_txtCount.SetVar("value", ActivityDataManager.Instance.lastDrawCount.ToString()).FlushVars();
  85. _ui.m_txtCount.SetVar("name", _activityCfg.themeName).FlushVars();
  86. UI_ComBox_4 comBox = UI_ComBox_4.Proxy(_ui.m_comBox.target);
  87. LuckyBoxDataManager.Instance.InitData(_luckyBoxCfg.id);
  88. comBox.m_comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[0]);
  89. LuckyBoxDataManager.Instance.GetOwnedCount(_luckyBoxCfg.id, out int count, out int totalCount);
  90. comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  91. comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
  92. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  93. comBox.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", _luckyBoxCfg.maxCount - boughtCount);
  94. comBox.m_comCostOne.m_txtCost.text = _luckyBoxCfg.costNum.ToString();
  95. comBox.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(_luckyBoxCfg.costID).res);
  96. comBox.m_comCostTen.m_txtCost.text = _luckyBoxCfg.costNumTen.ToString();
  97. comBox.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(_luckyBoxCfg.costID).res);
  98. if (comBox.m_btnBuyOne.target.data == null)
  99. {
  100. comBox.m_btnBuyOne.target.onClick.Add(OnClickBtnBuyOne);
  101. }
  102. comBox.m_btnBuyOne.target.data = _luckyBoxCfg.id;
  103. if (comBox.m_btnBuyTen.target.data == null)
  104. {
  105. comBox.m_btnBuyTen.target.onClick.Add(OnClickBtnBuyTen);
  106. }
  107. comBox.m_btnBuyTen.target.data = _luckyBoxCfg.id;
  108. if (comBox.m_btnPreview.data == null)
  109. {
  110. comBox.m_btnPreview.onClick.Add(OnClickBtnPreview);
  111. }
  112. comBox.m_btnPreview.data = _luckyBoxCfg.id;
  113. comBox.target.data = _luckyBoxCfg.id;
  114. UI_ComBox_4.ProxyEnd();
  115. }
  116. private void OnClickBtnPreview(EventContext context)
  117. {
  118. GObject obj = context.sender as GObject;
  119. int boxId = (int)obj.data;
  120. ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW, boxId);
  121. }
  122. private void OnClickBtnBuyOne(EventContext context)
  123. {
  124. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  125. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > _luckyBoxCfg.maxCount)
  126. {
  127. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  128. return;
  129. }
  130. LuckyBoxDataManager.Instance.CheckItemEnough(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME, async () =>
  131. {
  132. bool result = await LuckyBoxSProxy.ReqGetBonus(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME);
  133. if (result)
  134. {
  135. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
  136. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  137. }
  138. });
  139. }
  140. private void OnClickBtnBuyTen(EventContext context)
  141. {
  142. GObject obj = context.sender as GObject;
  143. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  144. if (boughtCount + LuckyBoxDataManager.TEN_TIME > _luckyBoxCfg.maxCount)
  145. {
  146. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  147. return;
  148. }
  149. LuckyBoxDataManager.Instance.CheckItemEnough(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME, async () =>
  150. {
  151. bool result = await LuckyBoxSProxy.ReqGetBonus(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME);
  152. if (result)
  153. {
  154. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
  155. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  156. }
  157. });
  158. }
  159. private void OnClikcBtnReward()
  160. {
  161. ViewManager.Show<ActivityThemeLuckyBoxBonusView>();
  162. }
  163. private void OnClikcBtnShop()
  164. {
  165. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY });
  166. }
  167. private void OnClikcBtnGiftBag()
  168. {
  169. }
  170. protected override void OnHide()
  171. {
  172. base.OnHide();
  173. _valueBarController.OnHide();
  174. _luckyBoxCtrl.OnHide();
  175. Timers.inst.Remove(UpdateTime);
  176. }
  177. protected override void RemoveEventListener()
  178. {
  179. base.RemoveEventListener();
  180. }
  181. private void OnClickBtnBack()
  182. {
  183. ViewManager.GoBackFrom(typeof(LuckyBoxActivityView).FullName);
  184. }
  185. protected override void UpdateToCheckGuide(object param)
  186. {
  187. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  188. }
  189. protected override void TryCompleteGuide()
  190. {
  191. base.TryCompleteGuide();
  192. }
  193. }
  194. }