StoreChargeAddUpView.cs 12 KB

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