StoreChargeAddUpView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. _ui.m_comVipLv.m_loaIcon.url = ResPathUtil.GetIconPath("tb_hyjf", "png");
  80. ShopViewManager.Instance.UpdateVipProgressCom(_ui.m_comVipLv.target);
  81. UpdateRedDot();
  82. }
  83. protected override void OnHide()
  84. {
  85. base.OnHide();
  86. _valueBarController.OnHide();
  87. }
  88. protected override void RemoveEventListener()
  89. {
  90. base.RemoveEventListener();
  91. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  92. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  93. }
  94. private void RefreshList()
  95. {
  96. _ui.m_list.numItems = VipCfgArray.Instance.dataArray.Length - 1;
  97. }
  98. private void ListItemRenderer(int index, GObject obj)
  99. {
  100. VipCfg lastVipCfg = VipCfgArray.Instance.dataArray[index];
  101. VipCfg vipCfg = VipCfgArray.Instance.dataArray[index + 1];
  102. UI_ListVipItem item = UI_ListVipItem.Proxy(obj);
  103. string name = SuitCfgArray.Instance.GetCfg(vipCfg.suitId).name;
  104. item.m_txtName0.text = name.Length > 0 ? name.Substring(0, 1) : "";
  105. item.m_txtName1.text = name.Length > 1 ? name.Substring(1, 1) : "";
  106. item.m_txtName2.text = name.Length > 2 ? name.Substring(2, 1) : "";
  107. item.m_txtName3.text = name.Length > 3 ? name.Substring(3, 1) : "";
  108. item.m_txtName4.text = name.Length > 4 ? name.Substring(4) : "";
  109. item.m_txtGiftBag.SetVar("value", vipCfg.id.ToString()).FlushVars();
  110. if (item.m_listGiftBag.data == null)
  111. {
  112. item.m_listGiftBag.itemRenderer = ListRewardItemRender;
  113. item.m_listGiftBag.onClickItem.Add(OnListItemClick);
  114. }
  115. item.m_listGiftBag.data = lastVipCfg.bonusOnceArr;
  116. item.m_listGiftBag.numItems = lastVipCfg.bonusOnceArr.Length;
  117. if (item.m_holder.data == null)
  118. {
  119. DressUpObjUI dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  120. item.m_holder.data = dressUpObjUI;
  121. _dressUpObjUIs.Add(dressUpObjUI);
  122. }
  123. _dressUpObjUI = item.m_holder.data as DressUpObjUI;
  124. _dressUpObjUI.ResetSceneObj(80, true, true, null, false);
  125. _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.suitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  126. _dressUpObjUI.UpdateWrapper(item.m_holder);
  127. if (item.m_btnShow.data == null)
  128. {
  129. item.m_btnShow.onClick.Add(OnBtnShowClick);
  130. }
  131. item.m_btnShow.data = vipCfg.suitId;
  132. if (item.m_btnGetGiftBag.data == null)
  133. {
  134. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  135. }
  136. item.m_btnGetGiftBag.data = vipCfg.id;
  137. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  138. item.m_btnGetGiftBag.grayed = isGet || vipCfg.id > RoleDataManager.vipLv;
  139. RedDotController.Instance.SetComRedDot(item.m_btnGetGiftBag, !isGet && RoleDataManager.vipLv >= vipCfg.id);
  140. if (item.m_btnWeek.data == null)
  141. {
  142. item.m_btnWeek.onClick.Add(OnBtnWeekClick);
  143. }
  144. item.m_btnWeek.data = vipCfg.id;
  145. bool canGet = GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv == vipCfg.id;
  146. item.m_btnWeek.grayed = !canGet;
  147. RedDotController.Instance.SetComRedDot(item.m_btnWeek, canGet, "", -28, -3);
  148. UI_ListVipItem.ProxyEnd();
  149. }
  150. private void ListRewardItemRender(int index, GObject obj)
  151. {
  152. int[][] rewards = (int[][])obj.parent.data;
  153. UI_ComItem item = UI_ComItem.Proxy(obj);
  154. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  155. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  156. item.m_txtCount.text = itemData.num.ToString();
  157. item.target.data = itemCfg;
  158. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  159. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  160. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  161. UI_ComItem.ProxyEnd();
  162. }
  163. private void OnBtnShowClick(EventContext context)
  164. {
  165. GObject obj = context.sender as GObject;
  166. int suitId = (int)obj.data;
  167. int _suitTypeId = 0;
  168. for (int i = 0; i < SuitGuideMenuCfgArray.Instance.dataArray.Length; i++)
  169. {
  170. string[] suitIds = SuitGuideMenuCfgArray.Instance.dataArray[i].suitIds.Split(';');
  171. if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
  172. {
  173. _suitTypeId = SuitGuideMenuCfgArray.Instance.dataArray[i].id;
  174. break;
  175. }
  176. }
  177. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  178. }
  179. private void OnBtnWeekClick(EventContext context)
  180. {
  181. GObject obj = context.sender as GObject;
  182. int vipLv = (int)obj.data;
  183. ViewManager.Show<WeekGiftView>(vipLv);
  184. }
  185. private void OnBtnGetGiftBagClick(EventContext context)
  186. {
  187. GObject obj = context.sender as GObject;
  188. int vipLv = (int)obj.data;
  189. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipLv);
  190. if (isGet)
  191. {
  192. PromptController.Instance.ShowFloatTextPrompt("会员等级礼包已领取");
  193. return;
  194. }
  195. if (RoleDataManager.vipLv < vipLv)
  196. {
  197. PromptController.Instance.ShowFloatTextPrompt("会员等级不足");
  198. return;
  199. }
  200. ShopSProxy.ReqGetVipGiftBag(vipLv).Coroutine();
  201. }
  202. private void OnBtnLeftClick()
  203. {
  204. if (_curSelectIndex == 0) return;
  205. _curSelectIndex = _curSelectIndex - 1;
  206. _ui.m_list.ScrollToView(_curSelectIndex, true);
  207. UpdateRedDot();
  208. }
  209. private void OnBtnRightClick()
  210. {
  211. if (_curSelectIndex == _ui.m_list.numItems - 1) return;
  212. _curSelectIndex = _curSelectIndex + 1;
  213. _ui.m_list.ScrollToView(_curSelectIndex, true);
  214. UpdateRedDot();
  215. }
  216. private void UpdateSuitView()
  217. {
  218. _curSelectIndex = _ui.m_list.GetFirstChildInView();
  219. _ui.m_list.selectedIndex = _curSelectIndex;
  220. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  221. _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 1 ? true : false;
  222. }
  223. private void UpdateRedDot()
  224. {
  225. bool leftRed = false;
  226. bool rightRed = false;
  227. VipCfg[] vipCfgs = VipCfgArray.Instance.dataArray;
  228. for (int i = 1; i < vipCfgs.Length; i++)
  229. {
  230. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfgs[i].id);
  231. bool red = !isGet && RoleDataManager.vipLv >= vipCfgs[i].id;
  232. if (red && _curSelectIndex > i - 1)
  233. {
  234. leftRed = true;
  235. break;
  236. }
  237. if (red && _curSelectIndex + 1 < i)
  238. {
  239. rightRed = true;
  240. break;
  241. }
  242. }
  243. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv > 0 && _curSelectIndex > RoleDataManager.vipLv - 1) { leftRed = true; }
  244. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv > 0 && _curSelectIndex + 1 < RoleDataManager.vipLv) { rightRed = true; }
  245. RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, leftRed);
  246. RedDotController.Instance.SetComRedDot(_ui.m_btnRight, rightRed);
  247. }
  248. private void OnListItemClick(EventContext context)
  249. {
  250. GComponent comItem = (context.data as GComponent);
  251. ItemCfg itemCfg = comItem.data as ItemCfg;
  252. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  253. }
  254. }
  255. }