StoreChargeAddUpView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 UnityEngine;
  9. namespace GFGGame
  10. {
  11. public class StoreChargeAddUpView : BaseWindow
  12. {
  13. private UI_StoreChargeAddUpUI _ui;
  14. private ValueBarController _valueBarController;
  15. private List<ShopCfg> _shopCfgs;
  16. private DressUpObjUI _dressUpObjUI;
  17. private List<DressUpObjUI> _dressUpObjUIs = new List<DressUpObjUI>();
  18. private int _curSelectIndex = 0;
  19. //按钮锁定一段时间,防止点太快
  20. private float _leftRightBtnLockEndTime = 0;
  21. public override void Dispose()
  22. {
  23. if (_valueBarController != null)
  24. {
  25. _valueBarController.Dispose();
  26. _valueBarController = null;
  27. }
  28. if (_dressUpObjUI != null)
  29. {
  30. _dressUpObjUI.Dispose();
  31. _dressUpObjUI = null;
  32. }
  33. for (int i = 0; i < _dressUpObjUIs.Count; i++)
  34. {
  35. if (_dressUpObjUIs[i] != null)
  36. {
  37. _dressUpObjUIs[i].Dispose();
  38. _dressUpObjUIs[i] = null;
  39. }
  40. }
  41. if (_ui != null)
  42. {
  43. _ui.Dispose();
  44. }
  45. _ui = null;
  46. base.Dispose();
  47. }
  48. protected override void OnInit()
  49. {
  50. base.OnInit();
  51. packageName = UI_StoreChargeAddUpUI.PACKAGE_NAME;
  52. _ui = UI_StoreChargeAddUpUI.Create();
  53. this.viewCom = _ui.target;
  54. isfullScreen = true;
  55. this.clickBlankToClose = false;
  56. this.bringToFontOnClick = false;
  57. _dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  58. _valueBarController = new ValueBarController(_ui.m_valueBar);
  59. _ui.m_list.itemRenderer = ListItemRenderer;
  60. _ui.m_list.SetVirtual();
  61. _ui.m_list.scrollPane.onScrollEnd.Add(UpdateSuitView);
  62. _ui.m_list.scrollPane.decelerationRate = 0.8f;
  63. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  64. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  65. }
  66. protected override void AddEventListener()
  67. {
  68. base.AddEventListener();
  69. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  70. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  71. }
  72. protected override void OnShown()
  73. {
  74. base.OnShown();
  75. _valueBarController.OnShown();
  76. RefreshList();
  77. _curSelectIndex = Math.Max(0, RoleDataManager.vipLv - 1);
  78. _ui.m_list.selectedIndex = _curSelectIndex;
  79. _ui.m_list.ScrollToView(_curSelectIndex);
  80. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  81. _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 1 ? true : false;
  82. _ui.m_comVipLv.m_loaIcon.url = ResPathUtil.GetIconPath("tb_hyjf", "png");
  83. ShopViewManager.Instance.UpdateVipProgressCom(_ui.m_comVipLv.target);
  84. UpdateRedDot();
  85. }
  86. protected override void OnHide()
  87. {
  88. base.OnHide();
  89. _valueBarController.OnHide();
  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. //这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
  100. _ui.m_list.numItems = VipCfgArray.Instance.dataArray.Length;
  101. }
  102. private void ListItemRenderer(int index, GObject obj)
  103. {
  104. //索引修复,这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
  105. index--;
  106. if (index < 0) index = 0;
  107. VipCfg lastVipCfg = VipCfgArray.Instance.dataArray[index];
  108. VipCfg vipCfg = VipCfgArray.Instance.dataArray[index + 1];
  109. UI_ListVipItem item = UI_ListVipItem.Proxy(obj);
  110. string name = SuitCfgArray.Instance.GetCfg(vipCfg.suitId).name;
  111. item.m_txtName0.text = name.Length > 0 ? name.Substring(0, 1) : "";
  112. item.m_txtName1.text = name.Length > 1 ? name.Substring(1, 1) : "";
  113. item.m_txtName2.text = name.Length > 2 ? name.Substring(2, 1) : "";
  114. item.m_txtName3.text = name.Length > 3 ? name.Substring(3, 1) : "";
  115. item.m_txtName4.text = name.Length > 4 ? name.Substring(4) : "";
  116. item.m_txtGiftBag.SetVar("value", vipCfg.id.ToString()).FlushVars();
  117. if (item.m_listGiftBag.data == null)
  118. {
  119. item.m_listGiftBag.itemRenderer = ListRewardItemRender;
  120. item.m_listGiftBag.onClickItem.Add(OnListItemClick);
  121. }
  122. item.m_listGiftBag.data = lastVipCfg.bonusOnceArr;
  123. item.m_listGiftBag.numItems = lastVipCfg.bonusOnceArr.Length;
  124. if (item.m_holder.data == null)
  125. {
  126. DressUpObjUI dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  127. item.m_holder.data = dressUpObjUI;
  128. _dressUpObjUIs.Add(dressUpObjUI);
  129. }
  130. _dressUpObjUI = item.m_holder.data as DressUpObjUI;
  131. _dressUpObjUI.ResetSceneObj(80, true, true, null, false);
  132. _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.suitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  133. _dressUpObjUI.UpdateWrapper(item.m_holder);
  134. if (item.m_btnShow.data == null)
  135. {
  136. item.m_btnShow.onClick.Add(OnBtnShowClick);
  137. }
  138. item.m_btnShow.data = vipCfg.suitId;
  139. if (item.m_btnGetGiftBag.data == null)
  140. {
  141. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  142. }
  143. item.m_btnGetGiftBag.data = vipCfg.id;
  144. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  145. item.m_btnGetGiftBag.grayed = isGet || vipCfg.id > RoleDataManager.vipLv;
  146. RedDotController.Instance.SetComRedDot(item.m_btnGetGiftBag, !isGet && RoleDataManager.vipLv >= vipCfg.id);
  147. if (item.m_btnWeek.data == null)
  148. {
  149. item.m_btnWeek.onClick.Add(OnBtnWeekClick);
  150. }
  151. item.m_btnWeek.data = vipCfg.id;
  152. bool isWeekGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus), vipCfg.id);
  153. bool canGet = !isWeekGet && vipCfg.id <=RoleDataManager.vipLv;
  154. item.m_btnWeek.grayed = !canGet;
  155. RedDotController.Instance.SetComRedDot(item.m_btnWeek, canGet, "", -28, -3);
  156. UI_ListVipItem.ProxyEnd();
  157. }
  158. private void ListRewardItemRender(int index, GObject obj)
  159. {
  160. int[][] rewards = (int[][])obj.parent.data;
  161. UI_ComItem item = UI_ComItem.Proxy(obj);
  162. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  163. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  164. item.m_txtCount.text = itemData.num.ToString();
  165. item.target.data = itemCfg;
  166. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  167. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  168. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  169. UI_ComItem.ProxyEnd();
  170. }
  171. private void OnBtnShowClick(EventContext context)
  172. {
  173. GObject obj = context.sender as GObject;
  174. int suitId = (int)obj.data;
  175. int _suitTypeId = 0;
  176. for (int i = 0; i < SuitGuideMenuCfgArray.Instance.dataArray.Length; i++)
  177. {
  178. string[] suitIds = SuitGuideMenuCfgArray.Instance.dataArray[i].suitIds.Split(';');
  179. if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
  180. {
  181. _suitTypeId = SuitGuideMenuCfgArray.Instance.dataArray[i].id;
  182. break;
  183. }
  184. }
  185. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  186. }
  187. private void OnBtnWeekClick(EventContext context)
  188. {
  189. GObject obj = context.sender as GObject;
  190. int vipLv = (int)obj.data;
  191. ViewManager.Show<WeekGiftView>(vipLv);
  192. }
  193. private void OnBtnGetGiftBagClick(EventContext context)
  194. {
  195. GObject obj = context.sender as GObject;
  196. int vipLv = (int)obj.data;
  197. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipLv);
  198. if (isGet)
  199. {
  200. PromptController.Instance.ShowFloatTextPrompt("会员等级礼包已领取");
  201. return;
  202. }
  203. if (RoleDataManager.vipLv < vipLv)
  204. {
  205. PromptController.Instance.ShowFloatTextPrompt("会员等级不足");
  206. return;
  207. }
  208. ShopSProxy.ReqGetVipGiftBag(vipLv).Coroutine();
  209. }
  210. private void OnBtnLeftClick()
  211. {
  212. //LogUtil.LogDev($"OnBtnLeftClick _curSelectIndex {_curSelectIndex}");
  213. if (_leftRightBtnLockEndTime > Time.time) return;
  214. if (_curSelectIndex == 0) return;
  215. _curSelectIndex = _curSelectIndex - 1;
  216. //索引修复,这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
  217. _curSelectIndex = Mathf.Min(_curSelectIndex, _ui.m_list.numItems - 3);
  218. _ui.m_list.ScrollToView(_curSelectIndex, true, true);
  219. _leftRightBtnLockEndTime = Time.time + 0.2f;
  220. }
  221. private void OnBtnRightClick()
  222. {
  223. //LogUtil.LogDev($"OnBtnRightClick _curSelectIndex {_curSelectIndex}");
  224. if (_leftRightBtnLockEndTime > Time.time) return;
  225. if (_curSelectIndex == _ui.m_list.numItems - 1) return;
  226. _curSelectIndex = _curSelectIndex + 1;
  227. _ui.m_list.ScrollToView(_curSelectIndex, true, true);
  228. _leftRightBtnLockEndTime = Time.time + 0.2f;
  229. }
  230. private void UpdateSuitView()
  231. {
  232. _curSelectIndex = _ui.m_list.GetFirstChildInView();
  233. //LogUtil.LogDev($"UpdateSuitView _curSelectIndex {_curSelectIndex}");
  234. _ui.m_list.selectedIndex = _curSelectIndex;
  235. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  236. //索引修复,这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
  237. _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 2 ? true : false;
  238. UpdateRedDot();
  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. }
  253. if (red && _curSelectIndex + 1 < i)
  254. {
  255. rightRed = true;
  256. }
  257. }
  258. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv > 0 && _curSelectIndex > RoleDataManager.vipLv - 1) { leftRed = true; }
  259. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv > 0 && _curSelectIndex + 1 < RoleDataManager.vipLv) { rightRed = true; }
  260. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, leftRed);
  261. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, rightRed);
  262. }
  263. private void OnListItemClick(EventContext context)
  264. {
  265. GComponent comItem = (context.data as GComponent);
  266. ItemCfg itemCfg = comItem.data as ItemCfg;
  267. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  268. }
  269. }
  270. }