NewLimitChargeView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[0].suitId).name;
  71. _ui.m_packageName.text = name;
  72. if (!isGoChargeView)
  73. {
  74. for (int i = 0; i < _rechargeCfgs.Count; i++)
  75. {
  76. if (_activityInfo.CountValue >= _rechargeCfgs[i].value)
  77. {
  78. if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[i].id) < 0)
  79. {
  80. _curSelectIndex = i;
  81. break;
  82. }
  83. }
  84. }
  85. }
  86. isGoChargeView = false;
  87. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  88. _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false;
  89. _ui.m_packageName.text = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name;
  90. ItemRenderer(_curSelectIndex);
  91. Timers.inst.Add(1, 0, UpdateTime);
  92. }
  93. protected override void OnHide()
  94. {
  95. base.OnHide();
  96. Timers.inst.Remove(UpdateTime);
  97. }
  98. protected override void RemoveEventListener()
  99. {
  100. base.RemoveEventListener();
  101. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  102. EventAgent.RemoveEventListener(ConstMessage.NEWLIMITCHARGE_GET, OnBtnRightClick);
  103. //EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  104. }
  105. private void RefreshList()
  106. {
  107. ItemRenderer(_curSelectIndex);
  108. }
  109. private void ItemRenderer(int index)
  110. {
  111. ActivityRechargeCfg lastVipCfg = _rechargeCfgs[index];
  112. ActivityRechargeCfg vipCfg = _rechargeCfgs[index];
  113. UI_ListShowItem item = _ui.m_showItem;
  114. string name = SuitCfgArray.Instance.GetCfg(vipCfg.suitId).name;
  115. item.m_txtName0.text = name;
  116. if (vipCfg.res != "")
  117. {
  118. item.m_cardIcon.visible = true;
  119. item.m_cardBg.visible = true;
  120. item.m_cardIcon.url = "ui://DailyWelfare/" + vipCfg.res;
  121. }
  122. else
  123. {
  124. item.m_cardIcon.visible = false;
  125. item.m_cardBg.visible = false;
  126. }
  127. if (item.m_listGiftBag.data == null)
  128. {
  129. item.m_listGiftBag.itemRenderer = ListRewardItemRender;
  130. item.m_listGiftBag.onClickItem.Add(OnListItemClick);
  131. }
  132. item.m_listGiftBag.data = lastVipCfg.bonusArr;
  133. item.m_listGiftBag.numItems = lastVipCfg.bonusArr.Length;
  134. item.m_listGiftBag.scrollPane.SetPosX(0, false);
  135. if (_rechargeCfgs[index].suitId != previousIndex)
  136. {
  137. if (item.m_holder.data == null)
  138. {
  139. DressUpObjUI dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  140. item.m_holder.data = dressUpObjUI;
  141. _dressUpObjUIs.Add(dressUpObjUI);
  142. }
  143. DressUpObjUI _dressUpObjUI = item.m_holder.data as DressUpObjUI;
  144. _dressUpObjUI.ResetSceneObj(120, false, true, null, false);
  145. _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.suitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  146. _dressUpObjUI.UpdateWrapper(item.m_holder);
  147. }
  148. previousIndex = _rechargeCfgs[index].suitId;
  149. if (item.m_btnShow.data == null)
  150. {
  151. item.m_btnShow.onClick.Add(OnBtnShowClick);
  152. }
  153. item.m_btnShow.data = vipCfg.suitId;
  154. if (item.m_btnGetGiftBag.data == null)
  155. {
  156. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  157. }
  158. item.m_btnGetGiftBag.data = vipCfg.id;
  159. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  160. long limitChargeExp = _activityInfo.CountValue;
  161. //item.m_btnGetGiftBag.grayed = limitChargeExp < _rechargeCfgs[index].value;
  162. item.m_txtGiftBag.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].value, limitChargeExp, _rechargeCfgs[index].value);
  163. if (limitChargeExp >= _rechargeCfgs[index].value)
  164. {
  165. if(_activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].id) >= 0)
  166. {
  167. item.m_btnGetGiftBag.grayed = true;
  168. item.m_btnGetGiftBag.title = "已领取";
  169. }
  170. else
  171. {
  172. item.m_btnGetGiftBag.grayed = false;
  173. item.m_btnGetGiftBag.title = "领取";
  174. }
  175. }
  176. else
  177. {
  178. item.m_btnGetGiftBag.grayed = true;
  179. item.m_btnGetGiftBag.title = "领取";
  180. }
  181. }
  182. private void ListRewardItemRender(int index, GObject obj)
  183. {
  184. int[][] rewards = (int[][])obj.parent.data;
  185. UI_ComItem item = UI_ComItem.Proxy(obj);
  186. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  187. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  188. item.m_txtCount.text = itemData.num.ToString();
  189. item.target.data = itemCfg;
  190. item.m_QualityType.selectedIndex = itemData.rarity - 1;
  191. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  192. UI_ComItem.ProxyEnd();
  193. }
  194. private void OnBtnShowClick(EventContext context)
  195. {
  196. GObject obj = context.sender as GObject;
  197. int suitId = (int)obj.data;
  198. int _suitTypeId = 0;
  199. for (int i = 0; i < SuitGuideMenuCfgArray.Instance.dataArray.Length; i++)
  200. {
  201. string[] suitIds = SuitGuideMenuCfgArray.Instance.dataArray[i].suitIds.Split(';');
  202. if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
  203. {
  204. _suitTypeId = SuitGuideMenuCfgArray.Instance.dataArray[i].id;
  205. break;
  206. }
  207. }
  208. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  209. }
  210. private void OnBtnGetGiftBagClick(EventContext context)
  211. {
  212. GObject obj = context.sender as GObject;
  213. int id = (int)obj.data;
  214. ActivityGlobalSProxy.ReqGetActivityBonus(_activityId, id).Coroutine();
  215. }
  216. private void OnBtnLeftClick()
  217. {
  218. if (_curSelectIndex == 0) return;
  219. _curSelectIndex = _curSelectIndex - 1;
  220. string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name;
  221. _ui.m_packageName.text = name;
  222. UpdateSuitView();
  223. //UpdateRedDot();
  224. }
  225. private void OnBtnRightClick()
  226. {
  227. if (_curSelectIndex == _rechargeCfgs.Count - 1) return;
  228. _curSelectIndex = _curSelectIndex + 1;
  229. string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name;
  230. _ui.m_packageName.text = name;
  231. UpdateSuitView();
  232. //UpdateRedDot();
  233. }
  234. private void OnBtnChargeClick()
  235. {
  236. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE });
  237. isGoChargeView = true;
  238. }
  239. private void UpdateSuitView()
  240. {
  241. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  242. _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false;
  243. ItemRenderer(_curSelectIndex);
  244. }
  245. private void UpdateTime(object param)
  246. {
  247. long curTime = TimeHelper.ServerNow();
  248. long endTime = _activityInfo.EndTime;
  249. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  250. }
  251. private void OnListItemClick(EventContext context)
  252. {
  253. GComponent comItem = (context.data as GComponent);
  254. ItemCfg itemCfg = comItem.data as ItemCfg;
  255. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  256. }
  257. private void OnBtnBackClick()
  258. {
  259. ViewManager.GoBackFrom(typeof(NewLimitChargeView).FullName);
  260. }
  261. }
  262. }