LuckyBoxActivityView.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. using System.Runtime.InteropServices;
  10. using cfg.GfgCfg;
  11. namespace GFGGame
  12. {
  13. public class LuckyBoxActivityView : BaseWindow
  14. {
  15. private UI_LuckyBoxActivityUI _ui;
  16. private ValueBarController _valueBarController;
  17. private LuckyBoxController _luckyBoxCtrl;
  18. private ActivityOpenCfg _activityCfg;
  19. private LuckyBoxCfg _luckyBoxCfg;
  20. private int _activityId;
  21. private int _activityType;
  22. private Dictionary<string, EffectUI> _effectUIDic = new Dictionary<string, EffectUI>();
  23. private EffectUI _effectUI1;
  24. public override void Dispose()
  25. {
  26. // Clear Effect
  27. foreach (var v in _effectUIDic)
  28. {
  29. EffectUIPool.Recycle(v.Value);
  30. }
  31. _effectUIDic.Clear();
  32. if (_valueBarController != null)
  33. {
  34. _valueBarController.Dispose();
  35. _valueBarController = null;
  36. }
  37. if (_luckyBoxCtrl != null)
  38. {
  39. _luckyBoxCtrl.Dispose();
  40. _luckyBoxCtrl = null;
  41. }
  42. if (_ui != null)
  43. {
  44. _ui.Dispose();
  45. _ui = null;
  46. }
  47. base.Dispose();
  48. }
  49. protected override void OnInit()
  50. {
  51. base.OnInit();
  52. packageName = UI_LuckyBoxActivityUI.PACKAGE_NAME;
  53. _ui = UI_LuckyBoxActivityUI.Create();
  54. this.viewCom = _ui.target;
  55. isfullScreen = true;
  56. isReturnView = true;
  57. _valueBarController = new ValueBarController(_ui.m_valueBar);
  58. _luckyBoxCtrl = new LuckyBoxController(_ui.m_comBox.m_comModel.target);
  59. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  60. _ui.m_btnReward.target.onClick.Add(OnClickBtnReward);
  61. _ui.m_btnShop.target.onClick.Add(OnClickBtnShop);
  62. _ui.m_btnGiftBag.target.onClick.Add(OnClickBtnGiftBag);
  63. _ui.m_btnLuckyDiscount.target.onClick.Add(OnClickBtnLuckyDiscount);
  64. _effectUIDic.Add("Button_public", EffectUIPool.CreateEffectUI(_ui.m_comBox.m_btnBuyTen_eff, "ui_LuckyBox", "Button_public"));
  65. _effectUIDic.Add("Button_Text_DianCang", EffectUIPool.CreateEffectUI(_ui.m_comBox.m_Special_eff, "ui_LuckyBox", "Button_Text_DianCang"));
  66. }
  67. protected override void AddEventListener()
  68. {
  69. base.AddEventListener();
  70. EventAgent.AddEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateView);
  71. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  72. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpLuckyDiscount);
  73. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_BONUS_VIEW_CLOSE, UpLuckyDiscount);
  74. }
  75. protected override void OnShown()
  76. {
  77. base.OnShown();
  78. LimitedTimeGiftBoxDataManager.Instance.UpLtgGbItemData16();
  79. _activityType = (int)this.viewData;
  80. _activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(_activityType);
  81. _activityCfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(_activityId);
  82. _luckyBoxCfg = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(_activityCfg.Params1[0]);
  83. _valueBarController.OnShown();
  84. _valueBarController.UpdateList(new List<int>() { _luckyBoxCfg.CostID, ConstItemID.DIAMOND_RED, ConstItemID.DIAMOND_PURPLE });
  85. _luckyBoxCtrl.OnShown(_luckyBoxCfg.Id);
  86. LuckyBoxDataManager.Instance.currentBoxId = _luckyBoxCfg.Id;
  87. LuckyBoxDataManager.Instance.luckyBoxIndex = 2;
  88. UpGiftBox();
  89. UpLuckyDiscount();
  90. UpdateTime(null);
  91. Timers.inst.Add(1, 0, UpdateTime);
  92. UpdateListItemData();
  93. ChangeUIByActivity();
  94. UpdateRedDot();
  95. ActivityOpenCfg activityOpenCfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(_activityId);
  96. if(activityOpenCfg.Params2.Count > 0)
  97. GetWishingPoolInfo(_activityId);
  98. }
  99. private void UpdateTime(object param = null)
  100. {
  101. long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.EndTime);
  102. long curTime = TimeHelper.ServerNow();
  103. if (endTime < curTime + 1)
  104. {
  105. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  106. Timers.inst.Remove(UpdateTime);
  107. ViewManager.DeleteViewStackCountDown(null, 2);
  108. ViewManager.Hide<LuckyBoxWishView>();
  109. OnClickBtnBack();
  110. return;
  111. }
  112. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  113. _ui.m_txtTime.text = "剩余时间:" + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  114. //=====限时礼包倒计时
  115. UpGiftBox();
  116. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_TIME);
  117. //=====限时礼包倒计时END
  118. }
  119. private void UpdateListItemData()
  120. {
  121. UI_ComBox comBox = UI_ComBox.Proxy(_ui.m_comBox.target);
  122. LuckyBoxDataManager.Instance.InitData(_luckyBoxCfg.Id);
  123. //comBox.m_comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[0]);
  124. comBox.m_btnPreview.m_c1.selectedIndex = 1;
  125. comBox.m_comCostOne.m_txtCost.text = _luckyBoxCfg.CostNum.ToString();
  126. comBox.m_comCostOne.m_loaCost.url = ResPathUtil.GetIconPath(CommonDataManager.Tables.TblItemCfg.GetOrDefault(_luckyBoxCfg.CostID).Res, "png");
  127. comBox.m_comCostTen.m_txtCost.text = _luckyBoxCfg.CostNumTen.ToString();
  128. comBox.m_comCostTen.m_loaCost.url = ResPathUtil.GetIconPath(CommonDataManager.Tables.TblItemCfg.GetOrDefault(_luckyBoxCfg.CostID).Res, "png");
  129. if (comBox.m_btnBuyOne.data == null)
  130. {
  131. comBox.m_btnBuyOne.onClick.Add(OnClickBtnBuyOne);
  132. }
  133. comBox.m_btnBuyOne.data = _luckyBoxCfg.Id;
  134. if (comBox.m_btnBuyTen.data == null)
  135. {
  136. comBox.m_btnBuyTen.onClick.Add(OnClickBtnBuyTen);
  137. }
  138. comBox.m_btnBuyTen.data = _luckyBoxCfg.Id;
  139. if (comBox.m_btnPreview.target.data == null)
  140. {
  141. comBox.m_btnPreview.target.onClick.Add(OnClickBtnPreview);
  142. comBox.m_btnOpenServer.onClick.Add(OnClickBtnPreview);
  143. }
  144. comBox.m_btnPreview.target.data = _luckyBoxCfg.Id;
  145. comBox.m_btnOpenServer.data = _luckyBoxCfg.Id;
  146. comBox.target.data = _luckyBoxCfg.Id;
  147. UI_ComBox.ProxyEnd();
  148. UpdateView();
  149. }
  150. private void UpdateView()
  151. {
  152. UI_ComBox comBox = UI_ComBox.Proxy(_ui.m_comBox.target);
  153. LuckyBoxDataManager.Instance.GetOwnedCount(_luckyBoxCfg.Id, out int count, out int totalCount);
  154. comBox.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  155. comBox.m_txtOwned.SetVar("v2", "" + totalCount).FlushVars();
  156. comBox.m_txtOpenServerOwned.SetVar("v1", "" + count).FlushVars();
  157. comBox.m_txtOpenServerOwned.SetVar("v2", "" + totalCount).FlushVars();
  158. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.NumericType);
  159. comBox.m_txtRemainTimes.text = string.Format("今日剩余次数:{0}", _luckyBoxCfg.MaxCount - boughtCount);
  160. if (_activityType == ConstLimitTimeActivityType.ActLimitLuckyBox) {
  161. string strDrawCount = ActivityDataManager.Instance.lastDrawCount.ToString();
  162. comBox.m_txtCount.SetVar("value", strDrawCount).FlushVars();
  163. comBox.m_txtCount.SetVar("name", _luckyBoxCfg.Name).FlushVars();
  164. }
  165. else if (_activityType == ConstLimitTimeActivityType.ActLimitStlyc){
  166. string strLimitStlycDrawCount = (ActivityDataManager.Instance.lastStlycDrawCount + _activityCfg.Params1[3]).ToString();
  167. comBox.m_txtOpenServerCount.SetVar("value", strLimitStlycDrawCount).FlushVars();
  168. comBox.m_txtOpenServerCount.SetVar("name", _luckyBoxCfg.Name).FlushVars();
  169. }
  170. UI_ComBox.ProxyEnd();
  171. }
  172. private void UpLuckyDiscount()
  173. {
  174. var activityOpenCfgs = CommonDataManager.Tables.TblActivityOpenCfg.GetGroup1ByType(ConstLimitTimeActivityType.LuckyDiscount);
  175. var shopCfgId = activityOpenCfgs[0].Params1[0];
  176. var shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(shopCfgId);
  177. var remainBuyNum = shopCfg.MaxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.Id);
  178. var activityInfoByTypeList =
  179. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.LuckyDiscount);
  180. var list = activityInfoByTypeList
  181. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  182. _ui.m_comLuckyDiscount.visible = ActivityDataManager.Instance.allLimitStlycTimes >= 20 && remainBuyNum != 0 && list.Count > 0;
  183. if(_effectUI1 == null)
  184. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_btnLuckyDiscount.m_holderEff, "ui_Activity", "Luckyicon");
  185. if (LuckyBoxDataManager.Instance.OPEN_LUCKY_DISCONT && _ui.m_btnLuckyDiscount.target.visible) {
  186. LimitedTimeGiftBoxDataManager.Instance.UpLtgGbItemData16();
  187. LuckyBoxDataManager.Instance.OPEN_LUCKY_DISCONT = false;
  188. //ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.LuckyDiscount, this.viewData });
  189. }
  190. _ui.m_comBox.target.visible = true;
  191. }
  192. private void UpGiftBox()
  193. {
  194. var activityInfoByTypeList = ActivityGlobalDataManager.Instance.GetActivityInfoByTypeAndID(ActivityType.XSLB3, _activityId);
  195. var list = activityInfoByTypeList.Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  196. if (list.Count == 0)
  197. {
  198. _ui.m_showGiftBag.selectedIndex = 1;
  199. }
  200. else
  201. {
  202. bool isSoldOut = true;
  203. foreach (var activityInfo in list)
  204. {
  205. ActivityOpenCfg activityOpenCfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(activityInfo.ActivityId);
  206. var paramsArr = activityOpenCfg.Params1;
  207. foreach (var shopCfgId in paramsArr)
  208. {
  209. var shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(shopCfgId);
  210. var remainBuyNum = shopCfg.MaxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfgId);
  211. //只要有一个商品还能购买,就不是售罄
  212. if (remainBuyNum > 0)
  213. {
  214. isSoldOut = false;
  215. break;
  216. }
  217. }
  218. }
  219. if (isSoldOut)
  220. {
  221. _ui.m_showGiftBag.selectedIndex = 1;
  222. }
  223. else
  224. {
  225. _ui.m_comBagTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), list[0].EndTime);
  226. _ui.m_showGiftBag.selectedIndex = 0;
  227. }
  228. }
  229. var listSaleGift = LimitedTimeGiftBoxDataManager.Instance.LtgGbItemData16;
  230. if (listSaleGift.Count > 0)
  231. {
  232. _ui.m_comDiscountTime.target.visible = true;
  233. _ui.m_comDiscountTime.m_txtGiftBagTime.text = TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), listSaleGift[0].EndTime);
  234. }
  235. }
  236. private void OnClickBtnPreview(EventContext context)
  237. {
  238. GObject obj = context.sender as GObject;
  239. int boxId = (int)obj.data;
  240. ViewManager.Show<LuckyBoxPreShowView>(boxId);
  241. }
  242. private void OnClickBtnBuyOne(EventContext context)
  243. {
  244. GetSuitItemController.showSingle = true;
  245. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.NumericType);
  246. if (boughtCount + LuckyBoxDataManager.ONCE_TIME > _luckyBoxCfg.MaxCount)
  247. {
  248. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  249. return;
  250. }
  251. LuckyBoxDataManager.Instance.CheckItemEnough(_luckyBoxCfg.Id, LuckyBoxDataManager.ONCE_TIME, async () =>
  252. {
  253. bool result = await LuckyBoxSProxy.ReqGetBonus(_luckyBoxCfg.Id, LuckyBoxDataManager.ONCE_TIME,false, _activityId);
  254. if (result)
  255. {
  256. ViewManager.Show<LuckyBoxStarView>();
  257. _ui.m_comBox.target.visible = false;
  258. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  259. GetSuitItemController.showSingle = false;
  260. }
  261. });
  262. }
  263. private void OnClickBtnBuyTen(EventContext context)
  264. {
  265. GetSuitItemController.showSingle = true;
  266. GObject obj = context.sender as GObject;
  267. int boughtCount = GameGlobal.myNumericComponent.GetAsInt(_luckyBoxCfg.NumericType);
  268. if (boughtCount + LuckyBoxDataManager.TEN_TIME > _luckyBoxCfg.MaxCount)
  269. {
  270. PromptController.Instance.ShowFloatTextPrompt("抽奖次数不足");
  271. return;
  272. }
  273. LuckyBoxDataManager.Instance.CheckItemEnough(this._luckyBoxCfg.Id, LuckyBoxDataManager.TEN_TIME, async () =>
  274. {
  275. bool result = await LuckyBoxSProxy.ReqGetBonus(this._luckyBoxCfg.Id, LuckyBoxDataManager.TEN_TIME,false, _activityId);
  276. if (result)
  277. {
  278. ViewManager.Show<LuckyBoxStarView>();
  279. _ui.m_comBox.target.visible = false;
  280. // LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.ZAI_XING, 2);
  281. GetSuitItemController.showSingle = false;
  282. }
  283. });
  284. }
  285. private void OnClickBtnReward()
  286. {
  287. ViewManager.Show<ActivityThemeLuckyBoxBonusView>(_activityType);
  288. }
  289. private void OnClickBtnShop()
  290. {
  291. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY });
  292. }
  293. //限时礼包按钮点击执行方法
  294. private void OnClickBtnGiftBag()
  295. {
  296. var activityInfoByTypeList =
  297. ActivityGlobalDataManager.Instance.GetActivityInfoByType(ActivityType.XSLB3);
  298. var list = activityInfoByTypeList
  299. .Where(a => a.EndTime > TimeInfo.Instance.ServerNow()).ToList();
  300. if (list.Count == 0)
  301. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  302. else
  303. ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.XSLB3, this.viewData });
  304. }
  305. //幸运折扣按钮点击执行方法
  306. private void OnClickBtnLuckyDiscount()
  307. {
  308. ViewManager.Show<RushSaleGiftBoxView>(new object[] { ActivityType.LuckyDiscount, this.viewData });
  309. }
  310. protected override void OnHide()
  311. {
  312. base.OnHide();
  313. EffectUIPool.Recycle(_effectUI1);
  314. _effectUI1 = null;
  315. _valueBarController.OnHide();
  316. _luckyBoxCtrl.OnHide();
  317. Timers.inst.Remove(UpdateTime);
  318. }
  319. protected override void RemoveEventListener()
  320. {
  321. base.RemoveEventListener();
  322. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_LUCKY_BOX, UpdateView);
  323. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  324. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpLuckyDiscount);
  325. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_BONUS_VIEW_CLOSE, UpLuckyDiscount);
  326. }
  327. private void OnClickBtnBack()
  328. {
  329. var activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(_activityType);
  330. if (activityId <= 0)
  331. {
  332. ViewManager.DeleteViewStackCountDown("MainUIView");
  333. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  334. }
  335. Hide();
  336. }
  337. private void UpdateRedDot()
  338. {
  339. RedDotController.Instance.SetComRedDot(_ui.m_btnReward.target, RedDotDataManager.Instance.GetActLuckyBoxRewardRed(_activityType), "", -18, 11);
  340. RedDotController.Instance.SetComRedDot(_ui.m_btnShop.target, RedDotDataManager.Instance.GetGiftBagRewardRed(), "", -18, 11);
  341. RedDotController.Instance.SetComRedDot(_ui.m_btnGiftBag.target, RedDotDataManager.Instance.GetMeiRiTeHuiRed(), "", -18, 11);
  342. }
  343. protected override void UpdateToCheckGuide(object param)
  344. {
  345. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  346. }
  347. protected override void TryCompleteGuide()
  348. {
  349. base.TryCompleteGuide();
  350. }
  351. private async void GetWishingPoolInfo(int activityId)
  352. {
  353. bool result = await LuckyBoxSProxy.ReqGetWishingPoolInfo();
  354. if (result)
  355. {
  356. int index = LuckyBoxDataManager.Instance.KsActivityId.IndexOf(activityId);
  357. if (index < 0 || !LuckyBoxDataManager.Instance.VsStatus[index])
  358. ViewManager.Show<LuckyBoxWishView>(_activityType);
  359. }
  360. }
  361. /// 修改活动的专属UI
  362. /// </summary>
  363. private void ChangeUIByActivity()
  364. {
  365. _ui.m_comBox.m_c1.SetSelectedPage(_activityId.ToString());
  366. }
  367. }
  368. }