LuckyBoxActivityView.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 comBox = UI_ComBox.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. comBox.m_imgActLuckyBox.visible = true;
  120. comBox.m_grpLuckyBox.visible = false;
  121. if (comBox.m_btnPreview.target.data == null)
  122. {
  123. comBox.m_btnPreview.target.onClick.Add(OnClickBtnPreview);
  124. }
  125. comBox.m_btnPreview.target.data = _luckyBoxCfg.id;
  126. comBox.target.data = _luckyBoxCfg.id;
  127. UI_ComBox.ProxyEnd();
  128. }
  129. private void UpGiftBox()
  130. {
  131. var activityInfoByTypeList =
  132. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  133. var list = activityInfoByTypeList
  134. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  135. if (list.Count == 0)
  136. {
  137. _ui.m_comBagTime.target.visible = false;
  138. _ui.m_btnGiftBag.visible = false;
  139. }
  140. else
  141. {
  142. _ui.m_comBagTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  143. _ui.m_comBagTime.target.visible = true;
  144. _ui.m_btnGiftBag.visible = true;
  145. }
  146. }
  147. private void OnClickBtnPreview(EventContext context)
  148. {
  149. GObject obj = context.sender as GObject;
  150. int boxId = (int)obj.data;
  151. ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW, boxId);
  152. }
  153. private void OnClickBtnBuyOne(EventContext context)
  154. {
  155. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  156. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > _luckyBoxCfg.maxCount)
  157. {
  158. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  159. return;
  160. }
  161. LuckyBoxDataManager.Instance.CheckItemEnough(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME, async () =>
  162. {
  163. bool result = await LuckyBoxSProxy.ReqGetBonus(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME);
  164. if (result)
  165. {
  166. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
  167. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  168. }
  169. });
  170. }
  171. private void OnClickBtnBuyTen(EventContext context)
  172. {
  173. GObject obj = context.sender as GObject;
  174. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  175. if (boughtCount + LuckyBoxDataManager.TEN_TIME > _luckyBoxCfg.maxCount)
  176. {
  177. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  178. return;
  179. }
  180. LuckyBoxDataManager.Instance.CheckItemEnough(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME, async () =>
  181. {
  182. bool result = await LuckyBoxSProxy.ReqGetBonus(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME);
  183. if (result)
  184. {
  185. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
  186. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  187. }
  188. });
  189. }
  190. private void OnClikcBtnReward()
  191. {
  192. ViewManager.Show<ActivityThemeLuckyBoxBonusView>();
  193. }
  194. private void OnClikcBtnShop()
  195. {
  196. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY });
  197. }
  198. //限时礼包按钮点击执行方法
  199. private void OnClikcBtnGiftBag()
  200. {
  201. var activityInfoByTypeList =
  202. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  203. var list = activityInfoByTypeList
  204. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  205. if (list.Count == 0)
  206. {
  207. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  208. }
  209. else
  210. {
  211. ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });
  212. }
  213. }
  214. protected override void OnHide()
  215. {
  216. base.OnHide();
  217. _valueBarController.OnHide();
  218. _luckyBoxCtrl.OnHide();
  219. Timers.inst.Remove(UpdateTime);
  220. }
  221. protected override void RemoveEventListener()
  222. {
  223. base.RemoveEventListener();
  224. }
  225. private void OnClickBtnBack()
  226. {
  227. ViewManager.GoBackFrom(typeof(LuckyBoxActivityView).FullName);
  228. }
  229. protected override void UpdateToCheckGuide(object param)
  230. {
  231. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  232. }
  233. protected override void TryCompleteGuide()
  234. {
  235. base.TryCompleteGuide();
  236. }
  237. }
  238. }