StoreChargeAddUpView.cs 13 KB

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