NewLimitChargeView.cs 12 KB

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