LuckyBoxActivityView.cs 7.6 KB

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