StoreChargeAddUpView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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.ToGfgGameItemParam();
  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. // 改为异步加载场景对象
  133. _dressUpObjUI.ResetSceneObjAsync(80, true, true, null, false, (go) =>
  134. {
  135. if (go != null)
  136. {
  137. _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.SuitId, true,
  138. new int[] { ConstDressUpItemType.BEI_JING },
  139. false, false);
  140. _dressUpObjUI.UpdateWrapper(item.m_holder);
  141. }
  142. });
  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. item.m_btnGetGiftBag.grayed = isGet || vipCfg.Id > RoleDataManager.vipLv;
  155. RedDotController.Instance.SetComRedDot(item.m_btnGetGiftBag, !isGet && RoleDataManager.vipLv >= vipCfg.Id);
  156. if (item.m_btnWeek.data == null)
  157. {
  158. item.m_btnWeek.onClick.Add(OnBtnWeekClick);
  159. }
  160. item.m_btnWeek.data = vipCfg.Id;
  161. bool isWeekGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus),
  162. vipCfg.Id);
  163. bool canGet = !isWeekGet && vipCfg.Id <= RoleDataManager.vipLv;
  164. item.m_btnWeek.grayed = !canGet;
  165. RedDotController.Instance.SetComRedDot(item.m_btnWeek, canGet, "", -28, -3);
  166. UI_ListVipItem.ProxyEnd();
  167. }
  168. private void ListRewardItemRender(int index, GObject obj)
  169. {
  170. var rewards = (List<ItemParamProto>)obj.parent.data;
  171. UI_ComItem item = UI_ComItem.Proxy(obj);
  172. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  173. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemData.id);
  174. item.m_txtCount.text = itemData.num.ToString();
  175. item.target.data = itemCfg;
  176. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  177. item.m_QualityType.selectedIndex = itemCfg.Rarity - 1;
  178. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.Id, false);
  179. UI_ComItem.ProxyEnd();
  180. }
  181. private void OnBtnShowClick(EventContext context)
  182. {
  183. GObject obj = context.sender as GObject;
  184. int suitId = (int)obj.data;
  185. int _suitTypeId = 0;
  186. for (int i = 0; i < CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList.Count; i++)
  187. {
  188. string[] suitIds = CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList[i].SuitIds.ToArray();
  189. if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
  190. {
  191. _suitTypeId = CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList[i].Id;
  192. break;
  193. }
  194. }
  195. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  196. }
  197. private void OnBtnWeekClick(EventContext context)
  198. {
  199. GObject obj = context.sender as GObject;
  200. int vipLv = (int)obj.data;
  201. ViewManager.Show<WeekGiftView>(vipLv);
  202. }
  203. private void OnBtnGetGiftBagClick(EventContext context)
  204. {
  205. GObject obj = context.sender as GObject;
  206. int vipLv = (int)obj.data;
  207. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipLv);
  208. if (isGet)
  209. {
  210. PromptController.Instance.ShowFloatTextPrompt("会员等级礼包已领取");
  211. return;
  212. }
  213. if (RoleDataManager.vipLv < vipLv)
  214. {
  215. PromptController.Instance.ShowFloatTextPrompt("会员等级不足");
  216. return;
  217. }
  218. ShopSProxy.ReqGetVipGiftBag(vipLv).Coroutine();
  219. }
  220. private void OnBtnLeftClick()
  221. {
  222. //LogUtil.LogDev($"OnBtnLeftClick _curSelectIndex {_curSelectIndex}");
  223. if (_leftRightBtnLockEndTime > Time.time) return;
  224. if (_curSelectIndex == 0) return;
  225. _curSelectIndex = _curSelectIndex - 1;
  226. //索引修复,这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
  227. _curSelectIndex = Mathf.Min(_curSelectIndex, _ui.m_list.numItems - 3);
  228. _ui.m_list.ScrollToView(_curSelectIndex, true, true);
  229. _leftRightBtnLockEndTime = Time.time + 0.2f;
  230. }
  231. private void OnBtnRightClick()
  232. {
  233. //LogUtil.LogDev($"OnBtnRightClick _curSelectIndex {_curSelectIndex}");
  234. if (_leftRightBtnLockEndTime > Time.time) return;
  235. if (_curSelectIndex == _ui.m_list.numItems - 1) return;
  236. _curSelectIndex = _curSelectIndex + 1;
  237. _ui.m_list.ScrollToView(_curSelectIndex, true, true);
  238. _leftRightBtnLockEndTime = Time.time + 0.2f;
  239. }
  240. private void UpdateSuitView()
  241. {
  242. _curSelectIndex = _ui.m_list.GetFirstChildInView();
  243. //LogUtil.LogDev($"UpdateSuitView _curSelectIndex {_curSelectIndex}");
  244. _ui.m_list.selectedIndex = _curSelectIndex;
  245. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  246. //索引修复,这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
  247. _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 2 ? true : false;
  248. UpdateRedDot();
  249. }
  250. private void UpdateRedDot()
  251. {
  252. bool leftRed = false;
  253. bool rightRed = false;
  254. List<VipCfg> vipCfgs = CommonDataManager.Tables.TblVipCfg.DataList;
  255. for (int i = 1; i < vipCfgs.Count; i++)
  256. {
  257. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus),
  258. vipCfgs[i].Id);
  259. bool red = !isGet && RoleDataManager.vipLv >= vipCfgs[i].Id;
  260. if (red && _curSelectIndex > i - 1)
  261. {
  262. leftRed = true;
  263. }
  264. if (red && _curSelectIndex + 1 < i)
  265. {
  266. rightRed = true;
  267. }
  268. }
  269. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 &&
  270. RoleDataManager.vipLv > 0 && _curSelectIndex > RoleDataManager.vipLv - 1)
  271. {
  272. leftRed = true;
  273. }
  274. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 &&
  275. RoleDataManager.vipLv > 0 && _curSelectIndex + 1 < RoleDataManager.vipLv)
  276. {
  277. rightRed = true;
  278. }
  279. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, leftRed);
  280. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, rightRed);
  281. }
  282. private void OnListItemClick(EventContext context)
  283. {
  284. GComponent comItem = (context.data as GComponent);
  285. ItemCfg itemCfg = comItem.data as ItemCfg;
  286. GoodsItemTipsController.ShowItemTips(itemCfg.Id);
  287. }
  288. }
  289. }