NewLimitChargeView.cs 11 KB

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