LuckyBoxActivityView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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", _luckyBoxCfg.name).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. 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.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. bool isSoldOut = true;
  141. foreach (var activityInfo in list)
  142. {
  143. ActivityOpenCfg activityOpenCfg = ActivityOpenCfgArray.Instance.GetCfg(activityInfo.ActivityId);
  144. var paramsArr = activityOpenCfg.paramsArr;
  145. foreach (var shopCfgId in paramsArr)
  146. {
  147. var shopCfg = ShopCfgArray.Instance.GetCfg(shopCfgId);
  148. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfgId);
  149. //只要有一个商品还能购买,就不是售罄
  150. if (remainBuyNum > 0)
  151. {
  152. isSoldOut = false;
  153. break;
  154. }
  155. }
  156. }
  157. if (isSoldOut)
  158. {
  159. _ui.m_comBagTime.target.visible = false;
  160. _ui.m_btnGiftBag.visible = false;
  161. }
  162. else
  163. {
  164. _ui.m_comBagTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  165. _ui.m_comBagTime.target.visible = true;
  166. _ui.m_btnGiftBag.visible = true;
  167. }
  168. }
  169. }
  170. private void OnClickBtnPreview(EventContext context)
  171. {
  172. GObject obj = context.sender as GObject;
  173. int boxId = (int)obj.data;
  174. ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW, boxId);
  175. }
  176. private void OnClickBtnBuyOne(EventContext context)
  177. {
  178. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  179. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > _luckyBoxCfg.maxCount)
  180. {
  181. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  182. return;
  183. }
  184. LuckyBoxDataManager.Instance.CheckItemEnough(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME, async () =>
  185. {
  186. bool result = await LuckyBoxSProxy.ReqGetBonus(_luckyBoxCfg.id, LuckyBoxDataManager.ONCE_TIME);
  187. if (result)
  188. {
  189. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
  190. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  191. }
  192. });
  193. }
  194. private void OnClickBtnBuyTen(EventContext context)
  195. {
  196. GObject obj = context.sender as GObject;
  197. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.numericType);
  198. if (boughtCount + LuckyBoxDataManager.TEN_TIME > _luckyBoxCfg.maxCount)
  199. {
  200. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  201. return;
  202. }
  203. LuckyBoxDataManager.Instance.CheckItemEnough(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME, async () =>
  204. {
  205. bool result = await LuckyBoxSProxy.ReqGetBonus(this._luckyBoxCfg.id, LuckyBoxDataManager.TEN_TIME);
  206. if (result)
  207. {
  208. ViewManager.Show<LuckyBoxStarView>(null, new object[] { typeof(LuckyBoxActivityView).FullName, _activityId }, true);
  209. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  210. }
  211. });
  212. }
  213. private void OnClikcBtnReward()
  214. {
  215. ViewManager.Show<ActivityThemeLuckyBoxBonusView>();
  216. }
  217. private void OnClikcBtnShop()
  218. {
  219. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY });
  220. }
  221. //限时礼包按钮点击执行方法
  222. private void OnClikcBtnGiftBag()
  223. {
  224. var activityInfoByTypeList =
  225. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  226. var list = activityInfoByTypeList
  227. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  228. if (list.Count == 0)
  229. {
  230. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  231. }
  232. else
  233. {
  234. ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });
  235. }
  236. }
  237. protected override void OnHide()
  238. {
  239. base.OnHide();
  240. _valueBarController.OnHide();
  241. _luckyBoxCtrl.OnHide();
  242. Timers.inst.Remove(UpdateTime);
  243. }
  244. protected override void RemoveEventListener()
  245. {
  246. base.RemoveEventListener();
  247. }
  248. private void OnClickBtnBack()
  249. {
  250. ViewManager.GoBackFrom(typeof(LuckyBoxActivityView).FullName);
  251. }
  252. protected override void UpdateToCheckGuide(object param)
  253. {
  254. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  255. }
  256. protected override void TryCompleteGuide()
  257. {
  258. base.TryCompleteGuide();
  259. }
  260. }
  261. }