NewLimitChargeView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. using UI.CommonGame;
  2. using FairyGUI;
  3. using System.Collections.Generic;
  4. using ET;
  5. using System;
  6. using cfg.GfgCfg;
  7. using Hutool;
  8. using UI.DailyWelfare;
  9. namespace GFGGame
  10. {
  11. public class NewLimitChargeView : BaseWindow
  12. {
  13. private UI_NewLimitChargeUI _ui;
  14. private List<ShopCfg> _shopCfgs;
  15. private int _curSelectIndex = 0;
  16. private int _activityId = 0;
  17. private ActivityInfo _activityInfo;
  18. private List<ActivityRechargeCfg> _rechargeCfgs;
  19. private int previousIndex = 0;
  20. private bool isGoChargeView = false;
  21. public override void Dispose()
  22. {
  23. if (_ui != null)
  24. {
  25. _ui.Dispose();
  26. }
  27. _ui = null;
  28. base.Dispose();
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. packageName = UI_LimitChargeUI.PACKAGE_NAME;
  34. _ui = UI_NewLimitChargeUI.Create();
  35. this.viewCom = _ui.target;
  36. isfullScreen = true;
  37. isReturnView = true;
  38. this.clickBlankToClose = false;
  39. this.bringToFontOnClick = false;
  40. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  41. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  42. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  43. _ui.m_btnCharge.onClick.Add(OnBtnChargeClick);
  44. }
  45. protected override void AddEventListener()
  46. {
  47. base.AddEventListener();
  48. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  49. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  50. EventAgent.AddEventListener(ConstMessage.NEWLIMITCHARGE_GET, UpdateSuitView);
  51. }
  52. protected override void OnShown()
  53. {
  54. base.OnShown();
  55. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zjm_bg1", "jpg");
  56. _activityId = (int)(this.viewData as object[])[0];
  57. _rechargeCfgs = CommonDataManager.Tables.TblActivityRechargeCfg.GetGroup1ByActivityId(_activityId);
  58. _activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(_activityId);
  59. //RefreshList();
  60. //由于这个需要外部参数所以在onshown里面预加载
  61. PreDownloadManager.Instance.PreDownloadSuitRes(_rechargeCfgs[0].SuitId, ResType.Both,
  62. new int[] { ConstDressUpItemType.BEI_JING }, false);
  63. string name = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_rechargeCfgs[0].SuitId).Name;
  64. _ui.m_packageName.text = name;
  65. if (!isGoChargeView)
  66. {
  67. for (int i = 0; i < _rechargeCfgs.Count; i++)
  68. {
  69. if (_activityInfo.CountValue >= _rechargeCfgs[i].Value)
  70. {
  71. if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[i].Id) < 0)
  72. {
  73. _curSelectIndex = i;
  74. break;
  75. }
  76. }
  77. }
  78. }
  79. isGoChargeView = false;
  80. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  81. _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false;
  82. _ui.m_packageName.text = CommonDataManager.Tables.TblSuitCfg
  83. .GetOrDefault(_rechargeCfgs[_curSelectIndex].SuitId).Name;
  84. UpdateRedDot();
  85. //预加载套装,对于不同suitid
  86. for (int i = 1; i < _rechargeCfgs.Count; i++)
  87. {
  88. if (_rechargeCfgs[i].SuitId != _rechargeCfgs[i - 1].SuitId)
  89. {
  90. PreDownloadManager.Instance.PreDownloadSuitRes(_rechargeCfgs[i].SuitId, ResType.Both,
  91. new int[] { ConstDressUpItemType.BEI_JING }, false);
  92. }
  93. }
  94. ItemRenderer(_curSelectIndex);
  95. Timers.inst.Add(1, 0, UpdateTime);
  96. }
  97. protected override void OnHide()
  98. {
  99. base.OnHide();
  100. DressUpObjUI dressUpObjUI = _ui.m_showItem.m_holder.data as DressUpObjUI;
  101. if (dressUpObjUI != null)
  102. {
  103. dressUpObjUI.Dispose();
  104. }
  105. _ui.m_showItem.m_holder.data = null;
  106. previousIndex = 0;
  107. Timers.inst.Remove(UpdateTime);
  108. }
  109. protected override void RemoveEventListener()
  110. {
  111. base.RemoveEventListener();
  112. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  113. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  114. EventAgent.RemoveEventListener(ConstMessage.NEWLIMITCHARGE_GET, UpdateSuitView);
  115. }
  116. private void RefreshList()
  117. {
  118. ItemRenderer(_curSelectIndex);
  119. }
  120. private void ItemRenderer(int index)
  121. {
  122. ActivityRechargeCfg lastVipCfg = _rechargeCfgs[index];
  123. ActivityRechargeCfg vipCfg = _rechargeCfgs[index];
  124. UI_ListShowItem item = _ui.m_showItem;
  125. string name = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(vipCfg.SuitId).Name;
  126. item.m_txtName0.text = name;
  127. if (vipCfg.Res != "")
  128. {
  129. item.m_cardIcon.visible = true;
  130. item.m_cardBg.visible = true;
  131. item.m_cardIcon.url = "ui://DailyWelfare/" + vipCfg.Res;
  132. }
  133. else
  134. {
  135. item.m_cardIcon.visible = false;
  136. item.m_cardBg.visible = false;
  137. }
  138. if (item.m_listGiftBag.data == null)
  139. {
  140. item.m_listGiftBag.itemRenderer = ListRewardItemRender;
  141. item.m_listGiftBag.onClickItem.Add(OnListItemClick);
  142. }
  143. item.m_listGiftBag.data = lastVipCfg.Bonus;
  144. item.m_listGiftBag.numItems = lastVipCfg.Bonus.Count;
  145. item.m_listGiftBag.scrollPane.SetPosX(0, false);
  146. if (_rechargeCfgs[index].SuitId != previousIndex)
  147. {
  148. DressUpObjUI dressUpObjUI;
  149. if (item.m_holder.data == null)
  150. {
  151. item.m_holder.data = new DressUpObjUI("SceneSuitFoster");
  152. }
  153. dressUpObjUI = item.m_holder.data as DressUpObjUI;
  154. // 修改为异步加载,并添加回调处理
  155. dressUpObjUI.ResetSceneObjAsync(120, false, true, null, false, (go) =>
  156. {
  157. if (go != null)
  158. {
  159. dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.SuitId, true,
  160. new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  161. dressUpObjUI.UpdateWrapper(item.m_holder);
  162. }
  163. });
  164. // 原同步代码注释掉
  165. // dressUpObjUI.ResetSceneObj(120, false, true, null, false);
  166. // dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.SuitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  167. // dressUpObjUI.UpdateWrapper(item.m_holder);
  168. }
  169. previousIndex = _rechargeCfgs[index].SuitId;
  170. if (item.m_btnShow.data == null)
  171. {
  172. item.m_btnShow.onClick.Add(OnBtnShowClick);
  173. }
  174. item.m_btnShow.data = vipCfg.SuitId;
  175. if (item.m_btnGetGiftBag.data == null)
  176. {
  177. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  178. }
  179. item.m_btnGetGiftBag.data = vipCfg.Id;
  180. //bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  181. long limitChargeExp = _activityInfo.CountValue;
  182. //item.m_btnGetGiftBag.grayed = limitChargeExp < _rechargeCfgs[index].value;
  183. item.m_txtGiftBag.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].Value,
  184. limitChargeExp, _rechargeCfgs[index].Value);
  185. if (limitChargeExp >= _rechargeCfgs[index].Value)
  186. {
  187. if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].Id) >= 0)
  188. {
  189. item.m_btnGetGiftBag.grayed = true;
  190. item.m_btnGetGiftBag.title = "已领取";
  191. }
  192. else
  193. {
  194. item.m_btnGetGiftBag.grayed = false;
  195. item.m_btnGetGiftBag.title = "领取";
  196. }
  197. }
  198. else
  199. {
  200. item.m_btnGetGiftBag.grayed = true;
  201. item.m_btnGetGiftBag.title = "领取";
  202. }
  203. }
  204. private void ListRewardItemRender(int index, GObject obj)
  205. {
  206. List<ItemParamProto> rewards = (List<ItemParamProto>)obj.parent.data;
  207. UI_ComItem item = UI_ComItem.Proxy(obj);
  208. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  209. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemData.id);
  210. item.m_txtCount.text = itemData.num.ToString();
  211. item.target.data = itemCfg;
  212. item.m_QualityType.selectedIndex = itemCfg.Rarity - 1;
  213. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  214. UI_ComItem.ProxyEnd();
  215. }
  216. private void OnBtnShowClick(EventContext context)
  217. {
  218. GObject obj = context.sender as GObject;
  219. int suitId = (int)obj.data;
  220. int _suitTypeId = 0;
  221. for (int i = 0; i < CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList.Count; i++)
  222. {
  223. List<string> suitIds = CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList[i].SuitIds;
  224. if (suitIds.IndexOf(suitId.ToString()) >= 0)
  225. {
  226. _suitTypeId = CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList[i].Id;
  227. break;
  228. }
  229. }
  230. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  231. }
  232. private void OnBtnGetGiftBagClick(EventContext context)
  233. {
  234. GObject obj = context.sender as GObject;
  235. int id = (int)obj.data;
  236. ActivityGlobalSProxy.ReqGetActivityBonus(_activityId, id).Coroutine();
  237. }
  238. private void OnBtnLeftClick()
  239. {
  240. if (_curSelectIndex == 0) return;
  241. _curSelectIndex = _curSelectIndex - 1;
  242. string name = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_rechargeCfgs[_curSelectIndex].SuitId).Name;
  243. _ui.m_packageName.text = name;
  244. UpdateSuitView();
  245. UpdateRedDot();
  246. }
  247. private void OnBtnRightClick()
  248. {
  249. if (_curSelectIndex == _rechargeCfgs.Count - 1)
  250. {
  251. ItemRenderer(_curSelectIndex);
  252. return;
  253. }
  254. _curSelectIndex = _curSelectIndex + 1;
  255. string name = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_rechargeCfgs[_curSelectIndex].SuitId).Name;
  256. _ui.m_packageName.text = name;
  257. UpdateSuitView();
  258. UpdateRedDot();
  259. }
  260. private void UpdateRedDot()
  261. {
  262. int indexPrior = Math.Max(0, _curSelectIndex - 1);
  263. int indexNext = Math.Min(_rechargeCfgs.Count - 1, _curSelectIndex + 1);
  264. TraverseList(indexPrior);
  265. TraverseList(indexNext);
  266. }
  267. private void TraverseList(int index)
  268. {
  269. if (index < _curSelectIndex)
  270. {
  271. for (int i = index; i >= 0; i--)
  272. {
  273. if (SetRedDot(i))
  274. {
  275. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, true);
  276. break;
  277. }
  278. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, false);
  279. }
  280. }
  281. else
  282. {
  283. for (int i = index; i < _rechargeCfgs.Count; i++)
  284. {
  285. if (SetRedDot(i))
  286. {
  287. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, true);
  288. break;
  289. }
  290. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, false);
  291. }
  292. }
  293. }
  294. private bool SetRedDot(int index)
  295. {
  296. long limitChargeExp = _activityInfo.CountValue;
  297. if (limitChargeExp >= _rechargeCfgs[index].Value)
  298. {
  299. if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].Id) < 0)
  300. {
  301. return true;
  302. }
  303. }
  304. return false;
  305. }
  306. private void OnBtnChargeClick()
  307. {
  308. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE });
  309. isGoChargeView = true;
  310. }
  311. private void UpdateSuitView()
  312. {
  313. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  314. _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false;
  315. ItemRenderer(_curSelectIndex);
  316. }
  317. private void UpdateTime(object param)
  318. {
  319. long curTime = TimeHelper.ServerNow();
  320. long endTime = _activityInfo.EndTime;
  321. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  322. }
  323. private void OnListItemClick(EventContext context)
  324. {
  325. GComponent comItem = (context.data as GComponent);
  326. ItemCfg itemCfg = comItem.data as ItemCfg;
  327. GoodsItemTipsController.ShowItemTips(itemCfg.Id);
  328. }
  329. private void OnBtnBackClick()
  330. {
  331. ViewManager.GoBackFrom(typeof(NewLimitChargeView).FullName);
  332. }
  333. }
  334. }