LuckyBoxActivityView.cs 15 KB

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