NewLimitChargeView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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, new int[] { ConstDressUpItemType.BEI_JING }, false);
  62. string name = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_rechargeCfgs[0].SuitId).Name;
  63. _ui.m_packageName.text = name;
  64. if (!isGoChargeView)
  65. {
  66. for (int i = 0; i < _rechargeCfgs.Count; i++)
  67. {
  68. if (_activityInfo.CountValue >= _rechargeCfgs[i].Value)
  69. {
  70. if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[i].Id) < 0)
  71. {
  72. _curSelectIndex = i;
  73. break;
  74. }
  75. }
  76. }
  77. }
  78. isGoChargeView = false;
  79. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  80. _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false;
  81. _ui.m_packageName.text = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_rechargeCfgs[_curSelectIndex].SuitId).Name;
  82. UpdateRedDot();
  83. //预加载套装,对于不同suitid
  84. for (int i = 1; i < _rechargeCfgs.Count; i++)
  85. {
  86. if (_rechargeCfgs[i].SuitId != _rechargeCfgs[i - 1].SuitId)
  87. {
  88. PreDownloadManager.Instance.PreDownloadSuitRes(_rechargeCfgs[i].SuitId, ResType.Both, new int[] { ConstDressUpItemType.BEI_JING }, false);
  89. }
  90. }
  91. ItemRenderer(_curSelectIndex);
  92. Timers.inst.Add(1, 0, UpdateTime);
  93. }
  94. protected override void OnHide()
  95. {
  96. base.OnHide();
  97. DressUpObjUI dressUpObjUI = _ui.m_showItem.m_holder.data as DressUpObjUI;
  98. if (dressUpObjUI != null)
  99. {
  100. dressUpObjUI.Dispose();
  101. }
  102. _ui.m_showItem.m_holder.data = null;
  103. previousIndex = 0;
  104. Timers.inst.Remove(UpdateTime);
  105. }
  106. protected override void RemoveEventListener()
  107. {
  108. base.RemoveEventListener();
  109. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  110. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  111. EventAgent.RemoveEventListener(ConstMessage.NEWLIMITCHARGE_GET, UpdateSuitView);
  112. }
  113. private void RefreshList()
  114. {
  115. ItemRenderer(_curSelectIndex);
  116. }
  117. private void ItemRenderer(int index)
  118. {
  119. ActivityRechargeCfg lastVipCfg = _rechargeCfgs[index];
  120. ActivityRechargeCfg vipCfg = _rechargeCfgs[index];
  121. UI_ListShowItem item = _ui.m_showItem;
  122. string name = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(vipCfg.SuitId).Name;
  123. item.m_txtName0.text = name;
  124. if (vipCfg.Res != "")
  125. {
  126. item.m_cardIcon.visible = true;
  127. item.m_cardBg.visible = true;
  128. item.m_cardIcon.url = "ui://DailyWelfare/" + vipCfg.Res;
  129. }
  130. else
  131. {
  132. item.m_cardIcon.visible = false;
  133. item.m_cardBg.visible = false;
  134. }
  135. if (item.m_listGiftBag.data == null)
  136. {
  137. item.m_listGiftBag.itemRenderer = ListRewardItemRender;
  138. item.m_listGiftBag.onClickItem.Add(OnListItemClick);
  139. }
  140. item.m_listGiftBag.data = lastVipCfg.Bonus;
  141. item.m_listGiftBag.numItems = lastVipCfg.Bonus.Count;
  142. item.m_listGiftBag.scrollPane.SetPosX(0, false);
  143. if (_rechargeCfgs[index].SuitId != previousIndex)
  144. {
  145. DressUpObjUI dressUpObjUI;
  146. if (item.m_holder.data == null)
  147. {
  148. item.m_holder.data = new DressUpObjUI("SceneSuitFoster");
  149. }
  150. dressUpObjUI = item.m_holder.data as DressUpObjUI;
  151. dressUpObjUI.ResetSceneObj(120, false, true, null, false);
  152. dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.SuitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  153. dressUpObjUI.UpdateWrapper(item.m_holder);
  154. }
  155. previousIndex = _rechargeCfgs[index].SuitId;
  156. if (item.m_btnShow.data == null)
  157. {
  158. item.m_btnShow.onClick.Add(OnBtnShowClick);
  159. }
  160. item.m_btnShow.data = vipCfg.SuitId;
  161. if (item.m_btnGetGiftBag.data == null)
  162. {
  163. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  164. }
  165. item.m_btnGetGiftBag.data = vipCfg.Id;
  166. //bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  167. long limitChargeExp = _activityInfo.CountValue;
  168. //item.m_btnGetGiftBag.grayed = limitChargeExp < _rechargeCfgs[index].value;
  169. item.m_txtGiftBag.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].Value, limitChargeExp, _rechargeCfgs[index].Value);
  170. if (limitChargeExp >= _rechargeCfgs[index].Value)
  171. {
  172. if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].Id) >= 0)
  173. {
  174. item.m_btnGetGiftBag.grayed = true;
  175. item.m_btnGetGiftBag.title = "已领取";
  176. }
  177. else
  178. {
  179. item.m_btnGetGiftBag.grayed = false;
  180. item.m_btnGetGiftBag.title = "领取";
  181. }
  182. }
  183. else
  184. {
  185. item.m_btnGetGiftBag.grayed = true;
  186. item.m_btnGetGiftBag.title = "领取";
  187. }
  188. }
  189. private void ListRewardItemRender(int index, GObject obj)
  190. {
  191. List<ItemParam> rewards = (List<ItemParam>)obj.parent.data;
  192. UI_ComItem item = UI_ComItem.Proxy(obj);
  193. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  194. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemData.id);
  195. item.m_txtCount.text = itemData.num.ToString();
  196. item.target.data = itemCfg;
  197. item.m_QualityType.selectedIndex = itemCfg.Rarity - 1;
  198. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  199. UI_ComItem.ProxyEnd();
  200. }
  201. private void OnBtnShowClick(EventContext context)
  202. {
  203. GObject obj = context.sender as GObject;
  204. int suitId = (int)obj.data;
  205. int _suitTypeId = 0;
  206. for (int i = 0; i < CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList.Count; i++)
  207. {
  208. List<string> suitIds = CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList[i].SuitIds;
  209. if (suitIds.IndexOf(suitId.ToString()) >=0 )
  210. {
  211. _suitTypeId = CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList[i].Id;
  212. break;
  213. }
  214. }
  215. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  216. }
  217. private void OnBtnGetGiftBagClick(EventContext context)
  218. {
  219. GObject obj = context.sender as GObject;
  220. int id = (int)obj.data;
  221. ActivityGlobalSProxy.ReqGetActivityBonus(_activityId, id).Coroutine();
  222. }
  223. private void OnBtnLeftClick()
  224. {
  225. if (_curSelectIndex == 0) return;
  226. _curSelectIndex = _curSelectIndex - 1;
  227. string name = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_rechargeCfgs[_curSelectIndex].SuitId).Name;
  228. _ui.m_packageName.text = name;
  229. UpdateSuitView();
  230. UpdateRedDot();
  231. }
  232. private void OnBtnRightClick()
  233. {
  234. if (_curSelectIndex == _rechargeCfgs.Count - 1)
  235. {
  236. ItemRenderer(_curSelectIndex);
  237. return;
  238. }
  239. _curSelectIndex = _curSelectIndex + 1;
  240. string name = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_rechargeCfgs[_curSelectIndex].SuitId).Name;
  241. _ui.m_packageName.text = name;
  242. UpdateSuitView();
  243. UpdateRedDot();
  244. }
  245. private void UpdateRedDot()
  246. {
  247. int indexPrior = Math.Max(0, _curSelectIndex - 1);
  248. int indexNext = Math.Min(_rechargeCfgs.Count - 1, _curSelectIndex + 1);
  249. TraverseList(indexPrior);
  250. TraverseList(indexNext);
  251. }
  252. private void TraverseList(int index)
  253. {
  254. if (index < _curSelectIndex)
  255. {
  256. for (int i = index; i >= 0; i--)
  257. {
  258. if(SetRedDot(i))
  259. {
  260. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, true);
  261. break;
  262. }
  263. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, false);
  264. }
  265. }
  266. else
  267. {
  268. for (int i = index; i < _rechargeCfgs.Count; i++)
  269. {
  270. if (SetRedDot(i))
  271. {
  272. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, true);
  273. break;
  274. }
  275. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, false);
  276. }
  277. }
  278. }
  279. private bool SetRedDot(int index)
  280. {
  281. long limitChargeExp = _activityInfo.CountValue;
  282. if (limitChargeExp >= _rechargeCfgs[index].Value)
  283. {
  284. if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].Id) < 0)
  285. {
  286. return true;
  287. }
  288. }
  289. return false;
  290. }
  291. private void OnBtnChargeClick()
  292. {
  293. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE });
  294. isGoChargeView = true;
  295. }
  296. private void UpdateSuitView()
  297. {
  298. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  299. _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false;
  300. ItemRenderer(_curSelectIndex);
  301. }
  302. private void UpdateTime(object param)
  303. {
  304. long curTime = TimeHelper.ServerNow();
  305. long endTime = _activityInfo.EndTime;
  306. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  307. }
  308. private void OnListItemClick(EventContext context)
  309. {
  310. GComponent comItem = (context.data as GComponent);
  311. ItemCfg itemCfg = comItem.data as ItemCfg;
  312. GoodsItemTipsController.ShowItemTips(itemCfg.Id);
  313. }
  314. private void OnBtnBackClick()
  315. {
  316. ViewManager.GoBackFrom(typeof(NewLimitChargeView).FullName);
  317. }
  318. }
  319. }