NewLimitChargeView.cs 13 KB

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