StoreChargeAddUpView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. item.m_txtWeekGiftBag.SetVar("value", vipCfg.id.ToString()).FlushVars();
  116. if (item.m_listWeekGiftBag.data == null)
  117. {
  118. item.m_listWeekGiftBag.itemRenderer = ListRewardItemRender;
  119. }
  120. item.m_listWeekGiftBag.data = vipCfg.bonusWeekArr;
  121. item.m_listWeekGiftBag.numItems = vipCfg.bonusWeekArr.Length;
  122. if (item.m_holder.data == null)
  123. {
  124. DressUpObjUI dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  125. item.m_holder.data = dressUpObjUI;
  126. _dressUpObjUIs.Add(dressUpObjUI);
  127. }
  128. _dressUpObjUI = item.m_holder.data as DressUpObjUI;
  129. _dressUpObjUI.ResetSceneObj(80, false, true, null, false);
  130. _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.suitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  131. _dressUpObjUI.UpdateWrapper(item.m_holder);
  132. if (item.m_btnShow.data == null)
  133. {
  134. item.m_btnShow.onClick.Add(OnBtnShowClick);
  135. }
  136. item.m_btnShow.data = vipCfg.suitId;
  137. if (item.m_btnGetGiftBag.data == null)
  138. {
  139. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  140. }
  141. item.m_btnGetGiftBag.data = vipCfg.id;
  142. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  143. item.m_btnGetGiftBag.grayed = isGet || vipCfg.id > RoleDataManager.vipLv;
  144. RedDotController.Instance.SetComRedDot(item.m_btnGetGiftBag, !isGet && RoleDataManager.vipLv >= vipCfg.id);
  145. if (item.m_btnGetWeekGiftBag.data == null)
  146. {
  147. item.m_btnGetWeekGiftBag.onClick.Add(OnBtnGetWeekGiftBagClick);
  148. }
  149. item.m_btnGetWeekGiftBag.data = vipCfg.id;
  150. bool canGet = GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv == vipCfg.id;
  151. item.m_btnGetWeekGiftBag.grayed = !canGet;
  152. RedDotController.Instance.SetComRedDot(item.m_btnGetWeekGiftBag, canGet);
  153. UI_ListVipItem.ProxyEnd();
  154. }
  155. private void ListRewardItemRender(int index, GObject obj)
  156. {
  157. int[][] rewards = (int[][])obj.parent.data;
  158. if (obj.data == null)
  159. {
  160. obj.data = new ItemView(obj as GComponent);
  161. }
  162. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  163. (obj.data as ItemView).SetData(itemData);
  164. (obj.data as ItemView).ChangeTxtCountStyle();
  165. }
  166. private void OnBtnShowClick(EventContext context)
  167. {
  168. GObject obj = context.sender as GObject;
  169. int suitId = (int)obj.data;
  170. int _suitTypeId = 0;
  171. for (int i = 0; i < SuitGuideMenuCfgArray.Instance.dataArray.Length; i++)
  172. {
  173. string[] suitIds = SuitGuideMenuCfgArray.Instance.dataArray[i].suitIds.Split(';');
  174. if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
  175. {
  176. _suitTypeId = SuitGuideMenuCfgArray.Instance.dataArray[i].id;
  177. break;
  178. }
  179. }
  180. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  181. }
  182. private void OnBtnGetGiftBagClick(EventContext context)
  183. {
  184. GObject obj = context.sender as GObject;
  185. int vipLv = (int)obj.data;
  186. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipLv);
  187. if (isGet)
  188. {
  189. PromptController.Instance.ShowFloatTextPrompt("会员等级礼包已领取");
  190. return;
  191. }
  192. if (RoleDataManager.vipLv < vipLv)
  193. {
  194. PromptController.Instance.ShowFloatTextPrompt("会员等级不足");
  195. return;
  196. }
  197. ShopSProxy.ReqGetVipGiftBag(vipLv).Coroutine();
  198. }
  199. private void OnBtnGetWeekGiftBagClick(EventContext context)
  200. {
  201. GObject obj = context.sender as GObject;
  202. int vipLv = (int)obj.data;
  203. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 1)
  204. {
  205. PromptController.Instance.ShowFloatTextPrompt("会员每周礼包已领取");
  206. return;
  207. }
  208. if (RoleDataManager.vipLv < vipLv)
  209. {
  210. PromptController.Instance.ShowFloatTextPrompt("会员等级不足");
  211. return;
  212. }
  213. AlertUI.Show("提升VIP等级能领取更高级的礼包,是否继续领取当前等级的VIP礼包?", "(该礼包每周只能领取1次)")
  214. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  215. {
  216. ShopSProxy.ReqGetVipWeekGiftBag(vipLv).Coroutine();
  217. });
  218. }
  219. private void OnBtnLeftClick()
  220. {
  221. if (_curSelectIndex == 0) return;
  222. _curSelectIndex = _curSelectIndex - 1;
  223. _ui.m_list.ScrollToView(_curSelectIndex, true);
  224. UpdateRedDot();
  225. }
  226. private void OnBtnRightClick()
  227. {
  228. if (_curSelectIndex == _ui.m_list.numItems - 1) return;
  229. _curSelectIndex = _curSelectIndex + 1;
  230. _ui.m_list.ScrollToView(_curSelectIndex, true);
  231. UpdateRedDot();
  232. }
  233. private void UpdateSuitView()
  234. {
  235. _curSelectIndex = _ui.m_list.GetFirstChildInView();
  236. _ui.m_list.selectedIndex = _curSelectIndex;
  237. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  238. _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 1 ? true : false;
  239. }
  240. private void UpdateRedDot()
  241. {
  242. bool leftRed = false;
  243. bool rightRed = false;
  244. VipCfg[] vipCfgs = VipCfgArray.Instance.dataArray;
  245. for (int i = 1; i < vipCfgs.Length; i++)
  246. {
  247. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfgs[i].id);
  248. bool red = !isGet && RoleDataManager.vipLv >= vipCfgs[i].id;
  249. if (red && _curSelectIndex > i - 1)
  250. {
  251. leftRed = true;
  252. break;
  253. }
  254. if (red && _curSelectIndex + 1 < i)
  255. {
  256. rightRed = true;
  257. break;
  258. }
  259. }
  260. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv > 0 && _curSelectIndex > RoleDataManager.vipLv - 1) { leftRed = true; }
  261. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv > 0 && _curSelectIndex + 1 < RoleDataManager.vipLv) { rightRed = true; }
  262. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, leftRed);
  263. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, rightRed);
  264. }
  265. }
  266. }