LuckyBoxActivityView.cs 10 KB

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