StoreChargeAddUpView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. namespace GFGGame
  9. {
  10. public class StoreChargeAddUpView : BaseWindow
  11. {
  12. private UI_StoreChargeAddUpUI _ui;
  13. private ValueBarController _valueBarController;
  14. private List<ShopCfg> _shopCfgs;
  15. private DressUpObjUI _dressUpObjUI;
  16. private List<DressUpObjUI> _dressUpObjUIs = new List<DressUpObjUI>();
  17. private int _curSelectIndex = 0;
  18. public override void Dispose()
  19. {
  20. if (_valueBarController != null)
  21. {
  22. _valueBarController.Dispose();
  23. _valueBarController = null;
  24. }
  25. if (_dressUpObjUI != null)
  26. {
  27. _dressUpObjUI.Dispose();
  28. _dressUpObjUI = null;
  29. }
  30. for (int i = 0; i < _dressUpObjUIs.Count; i++)
  31. {
  32. if (_dressUpObjUIs[i] != null)
  33. {
  34. _dressUpObjUIs[i].Dispose();
  35. _dressUpObjUIs[i] = null;
  36. }
  37. }
  38. if (_ui != null)
  39. {
  40. _ui.Dispose();
  41. }
  42. _ui = null;
  43. base.Dispose();
  44. }
  45. protected override void OnInit()
  46. {
  47. base.OnInit();
  48. packageName = UI_StoreChargeAddUpUI.PACKAGE_NAME;
  49. _ui = UI_StoreChargeAddUpUI.Create();
  50. this.viewCom = _ui.target;
  51. isfullScreen = true;
  52. this.clickBlankToClose = false;
  53. this.bringToFontOnClick = false;
  54. _dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  55. _valueBarController = new ValueBarController(_ui.m_valueBar);
  56. _ui.m_list.itemRenderer = ListItemRenderer;
  57. _ui.m_list.SetVirtual();
  58. _ui.m_list.scrollPane.onScrollEnd.Add(UpdateSuitView);
  59. _ui.m_list.scrollPane.decelerationRate = 0.8f;
  60. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  61. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  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. _valueBarController.OnShown();
  73. RefreshList();
  74. _curSelectIndex = Math.Max(0, RoleDataManager.vipLv - 1);
  75. _ui.m_list.selectedIndex = _curSelectIndex;
  76. _ui.m_list.ScrollToView(_curSelectIndex);
  77. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  78. _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 1 ? true : false;
  79. ShopViewManager.Instance.UpdateVipProgressCom(_ui.m_comVipLv.target);
  80. UpdateRedDot();
  81. }
  82. protected override void OnHide()
  83. {
  84. base.OnHide();
  85. _valueBarController.OnHide();
  86. }
  87. protected override void RemoveEventListener()
  88. {
  89. base.RemoveEventListener();
  90. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  91. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  92. }
  93. private void RefreshList()
  94. {
  95. _ui.m_list.numItems = VipCfgArray.Instance.dataArray.Length - 1;
  96. }
  97. private void ListItemRenderer(int index, GObject obj)
  98. {
  99. VipCfg lastVipCfg = VipCfgArray.Instance.dataArray[index];
  100. VipCfg vipCfg = VipCfgArray.Instance.dataArray[index + 1];
  101. UI_ListVipItem item = UI_ListVipItem.Proxy(obj);
  102. string name = SuitCfgArray.Instance.GetCfg(vipCfg.suitId).name;
  103. item.m_txtName0.text = name.Length > 0 ? name.Substring(0, 1) : "";
  104. item.m_txtName1.text = name.Length > 1 ? name.Substring(1, 1) : "";
  105. item.m_txtName2.text = name.Length > 2 ? name.Substring(2, 1) : "";
  106. item.m_txtName3.text = name.Length > 3 ? name.Substring(3, 1) : "";
  107. item.m_txtName4.text = name.Length > 4 ? name.Substring(4) : "";
  108. item.m_txtGiftBag.SetVar("value", vipCfg.id.ToString()).FlushVars();
  109. if (item.m_listGiftBag.data == null)
  110. {
  111. item.m_listGiftBag.itemRenderer = ListRewardItemRender;
  112. }
  113. item.m_listGiftBag.data = lastVipCfg.bonusOnceArr;
  114. item.m_listGiftBag.numItems = lastVipCfg.bonusOnceArr.Length;
  115. if (item.m_holder.data == null)
  116. {
  117. DressUpObjUI dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  118. item.m_holder.data = dressUpObjUI;
  119. _dressUpObjUIs.Add(dressUpObjUI);
  120. }
  121. _dressUpObjUI = item.m_holder.data as DressUpObjUI;
  122. _dressUpObjUI.ResetSceneObj(80, false, true, null, false);
  123. _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.suitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  124. _dressUpObjUI.UpdateWrapper(item.m_holder);
  125. if (item.m_btnShow.data == null)
  126. {
  127. item.m_btnShow.onClick.Add(OnBtnShowClick);
  128. }
  129. item.m_btnShow.data = vipCfg.suitId;
  130. if (item.m_btnGetGiftBag.data == null)
  131. {
  132. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  133. }
  134. item.m_btnGetGiftBag.data = vipCfg.id;
  135. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  136. item.m_btnGetGiftBag.grayed = isGet || vipCfg.id > RoleDataManager.vipLv;
  137. RedDotController.Instance.SetComRedDot(item.m_btnGetGiftBag, !isGet && RoleDataManager.vipLv >= vipCfg.id);
  138. if (item.m_btnWeek.data == null)
  139. {
  140. item.m_btnWeek.onClick.Add(OnBtnWeekClick);
  141. }
  142. item.m_btnWeek.data = vipCfg.id;
  143. bool canGet = GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv == vipCfg.id;
  144. item.m_btnWeek.grayed = !canGet;
  145. RedDotController.Instance.SetComRedDot(item.m_btnWeek, canGet);
  146. UI_ListVipItem.ProxyEnd();
  147. }
  148. private void ListRewardItemRender(int index, GObject obj)
  149. {
  150. int[][] rewards = (int[][])obj.parent.data;
  151. if (obj.data == null)
  152. {
  153. obj.data = new ItemView(obj as GComponent);
  154. }
  155. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  156. (obj.data as ItemView).SetData(itemData);
  157. (obj.data as ItemView).ChangeTxtCountStyle();
  158. }
  159. private void OnBtnShowClick(EventContext context)
  160. {
  161. GObject obj = context.sender as GObject;
  162. int suitId = (int)obj.data;
  163. int _suitTypeId = 0;
  164. for (int i = 0; i < SuitGuideMenuCfgArray.Instance.dataArray.Length; i++)
  165. {
  166. string[] suitIds = SuitGuideMenuCfgArray.Instance.dataArray[i].suitIds.Split(';');
  167. if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
  168. {
  169. _suitTypeId = SuitGuideMenuCfgArray.Instance.dataArray[i].id;
  170. break;
  171. }
  172. }
  173. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  174. }
  175. private void OnBtnWeekClick(EventContext context)
  176. {
  177. GObject obj = context.sender as GObject;
  178. int vipLv = (int)obj.data;
  179. ViewManager.Show<WeekGiftView>(vipLv);
  180. }
  181. private void OnBtnGetGiftBagClick(EventContext context)
  182. {
  183. GObject obj = context.sender as GObject;
  184. int vipLv = (int)obj.data;
  185. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipLv);
  186. if (isGet)
  187. {
  188. PromptController.Instance.ShowFloatTextPrompt("会员等级礼包已领取");
  189. return;
  190. }
  191. if (RoleDataManager.vipLv < vipLv)
  192. {
  193. PromptController.Instance.ShowFloatTextPrompt("会员等级不足");
  194. return;
  195. }
  196. ShopSProxy.ReqGetVipGiftBag(vipLv).Coroutine();
  197. }
  198. private void OnBtnLeftClick()
  199. {
  200. if (_curSelectIndex == 0) return;
  201. _curSelectIndex = _curSelectIndex - 1;
  202. _ui.m_list.ScrollToView(_curSelectIndex, true);
  203. UpdateRedDot();
  204. }
  205. private void OnBtnRightClick()
  206. {
  207. if (_curSelectIndex == _ui.m_list.numItems - 1) return;
  208. _curSelectIndex = _curSelectIndex + 1;
  209. _ui.m_list.ScrollToView(_curSelectIndex, true);
  210. UpdateRedDot();
  211. }
  212. private void UpdateSuitView()
  213. {
  214. _curSelectIndex = _ui.m_list.GetFirstChildInView();
  215. _ui.m_list.selectedIndex = _curSelectIndex;
  216. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  217. _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 1 ? true : false;
  218. }
  219. private void UpdateRedDot()
  220. {
  221. bool leftRed = false;
  222. bool rightRed = false;
  223. VipCfg[] vipCfgs = VipCfgArray.Instance.dataArray;
  224. for (int i = 1; i < vipCfgs.Length; i++)
  225. {
  226. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfgs[i].id);
  227. bool red = !isGet && RoleDataManager.vipLv >= vipCfgs[i].id;
  228. if (red && _curSelectIndex > i - 1)
  229. {
  230. leftRed = true;
  231. break;
  232. }
  233. if (red && _curSelectIndex + 1 < i)
  234. {
  235. rightRed = true;
  236. break;
  237. }
  238. }
  239. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv > 0 && _curSelectIndex > RoleDataManager.vipLv - 1) { leftRed = true; }
  240. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv > 0 && _curSelectIndex + 1 < RoleDataManager.vipLv) { rightRed = true; }
  241. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, leftRed);
  242. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, rightRed);
  243. }
  244. }
  245. }