NewLimitChargeView.cs 12 KB

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