NewLimitChargeView.cs 14 KB

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