NewLimitChargeView.cs 11 KB

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