NewLimitChargeView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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("bg_fhl");
  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. if (_rechargeCfgs[index].suitId != previousIndex)
  135. {
  136. if (item.m_holder.data == null)
  137. {
  138. DressUpObjUI dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  139. item.m_holder.data = dressUpObjUI;
  140. _dressUpObjUIs.Add(dressUpObjUI);
  141. }
  142. DressUpObjUI _dressUpObjUI = item.m_holder.data as DressUpObjUI;
  143. _dressUpObjUI.ResetSceneObj(120, false, true, null, false);
  144. _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.suitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  145. _dressUpObjUI.UpdateWrapper(item.m_holder);
  146. }
  147. previousIndex = _rechargeCfgs[index].suitId;
  148. if (item.m_btnShow.data == null)
  149. {
  150. item.m_btnShow.onClick.Add(OnBtnShowClick);
  151. }
  152. item.m_btnShow.data = vipCfg.suitId;
  153. if (item.m_btnGetGiftBag.data == null)
  154. {
  155. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  156. }
  157. item.m_btnGetGiftBag.data = vipCfg.id;
  158. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  159. long limitChargeExp = _activityInfo.CountValue;
  160. //item.m_btnGetGiftBag.grayed = limitChargeExp < _rechargeCfgs[index].value;
  161. item.m_txtGiftBag.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].value, limitChargeExp, _rechargeCfgs[index].value);
  162. if (limitChargeExp >= _rechargeCfgs[index].value)
  163. {
  164. if(_activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].id) >= 0)
  165. {
  166. item.m_btnGetGiftBag.grayed = true;
  167. item.m_btnGetGiftBag.title = "已领取";
  168. }
  169. else
  170. {
  171. item.m_btnGetGiftBag.grayed = false;
  172. item.m_btnGetGiftBag.title = "领取";
  173. }
  174. }
  175. else
  176. {
  177. item.m_btnGetGiftBag.grayed = true;
  178. item.m_btnGetGiftBag.title = "领取";
  179. }
  180. }
  181. private void ListRewardItemRender(int index, GObject obj)
  182. {
  183. int[][] rewards = (int[][])obj.parent.data;
  184. UI_ComItem item = UI_ComItem.Proxy(obj);
  185. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  186. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  187. item.m_txtCount.text = itemData.num.ToString();
  188. item.target.data = itemCfg;
  189. item.m_QualityType.selectedIndex = itemData.rarity - 1;
  190. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  191. UI_ComItem.ProxyEnd();
  192. }
  193. private void OnBtnShowClick(EventContext context)
  194. {
  195. GObject obj = context.sender as GObject;
  196. int suitId = (int)obj.data;
  197. int _suitTypeId = 0;
  198. for (int i = 0; i < SuitGuideMenuCfgArray.Instance.dataArray.Length; i++)
  199. {
  200. string[] suitIds = SuitGuideMenuCfgArray.Instance.dataArray[i].suitIds.Split(';');
  201. if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
  202. {
  203. _suitTypeId = SuitGuideMenuCfgArray.Instance.dataArray[i].id;
  204. break;
  205. }
  206. }
  207. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  208. }
  209. private void OnBtnGetGiftBagClick(EventContext context)
  210. {
  211. GObject obj = context.sender as GObject;
  212. int id = (int)obj.data;
  213. ActivityGlobalSProxy.ReqGetActivityBonus(_activityId, id).Coroutine();
  214. }
  215. private void OnBtnLeftClick()
  216. {
  217. if (_curSelectIndex == 0) return;
  218. _curSelectIndex = _curSelectIndex - 1;
  219. string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name;
  220. _ui.m_packageName.text = name;
  221. UpdateSuitView();
  222. //UpdateRedDot();
  223. }
  224. private void OnBtnRightClick()
  225. {
  226. if (_curSelectIndex == _rechargeCfgs.Count - 1) return;
  227. _curSelectIndex = _curSelectIndex + 1;
  228. string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name;
  229. _ui.m_packageName.text = name;
  230. UpdateSuitView();
  231. //UpdateRedDot();
  232. }
  233. private void OnBtnChargeClick()
  234. {
  235. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE });
  236. isGoChargeView = true;
  237. }
  238. private void UpdateSuitView()
  239. {
  240. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  241. _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false;
  242. ItemRenderer(_curSelectIndex);
  243. }
  244. private void UpdateTime(object param)
  245. {
  246. long curTime = TimeHelper.ServerNow();
  247. long endTime = _activityInfo.EndTime;
  248. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  249. }
  250. private void OnListItemClick(EventContext context)
  251. {
  252. GComponent comItem = (context.data as GComponent);
  253. ItemCfg itemCfg = comItem.data as ItemCfg;
  254. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  255. }
  256. private void OnBtnBackClick()
  257. {
  258. ViewManager.GoBackFrom(typeof(NewLimitChargeView).FullName);
  259. }
  260. }
  261. }