NewLimitChargeView.cs 13 KB

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