StoreChargeAddUpView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using UI.Store;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. using ET;
  6. using System;
  7. namespace GFGGame
  8. {
  9. public class StoreChargeAddUpView : BaseWindow
  10. {
  11. private UI_StoreChargeAddUpUI _ui;
  12. private ValueBarController _valueBarController;
  13. private List<ShopCfg> _shopCfgs;
  14. private DressUpObjUI _dressUpObjUI;
  15. private List<DressUpObjUI> _dressUpObjUIs = new List<DressUpObjUI>();
  16. private int _curSelectIndex = 0;
  17. public override void Dispose()
  18. {
  19. if (_valueBarController != null)
  20. {
  21. _valueBarController.Dispose();
  22. _valueBarController = null;
  23. }
  24. if (_dressUpObjUI != null)
  25. {
  26. _dressUpObjUI.Dispose();
  27. _dressUpObjUI = null;
  28. }
  29. for (int i = 0; i < _dressUpObjUIs.Count; i++)
  30. {
  31. if (_dressUpObjUIs[i] != null)
  32. {
  33. _dressUpObjUIs[i].Dispose();
  34. _dressUpObjUIs[i] = null;
  35. }
  36. }
  37. if (_ui != null)
  38. {
  39. _ui.Dispose();
  40. }
  41. _ui = null;
  42. base.Dispose();
  43. }
  44. protected override void OnInit()
  45. {
  46. base.OnInit();
  47. packageName = UI_StoreChargeAddUpUI.PACKAGE_NAME;
  48. _ui = UI_StoreChargeAddUpUI.Create();
  49. this.viewCom = _ui.target;
  50. isfullScreen = true;
  51. this.clickBlankToClose = false;
  52. this.bringToFontOnClick = false;
  53. _dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  54. _valueBarController = new ValueBarController(_ui.m_valueBar);
  55. _ui.m_list.itemRenderer = ListItemRenderer;
  56. _ui.m_list.SetVirtual();
  57. _ui.m_list.scrollPane.onScrollEnd.Add(UpdateSuitView);
  58. _ui.m_list.scrollPane.decelerationRate = 0.8f;
  59. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  60. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  61. }
  62. protected override void AddEventListener()
  63. {
  64. base.AddEventListener();
  65. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  66. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  67. }
  68. protected override void OnShown()
  69. {
  70. base.OnShown();
  71. _valueBarController.OnShown();
  72. RefreshList();
  73. _curSelectIndex = Math.Max(0, RoleDataManager.vipLv - 1);
  74. _ui.m_list.selectedIndex = _curSelectIndex;
  75. _ui.m_list.ScrollToView(_curSelectIndex);
  76. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  77. _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 1 ? true : false;
  78. ShopViewManager.Instance.UpdateVipProgressCom(_ui.m_comVipLv.target);
  79. UpdateRedDot();
  80. }
  81. protected override void OnHide()
  82. {
  83. base.OnHide();
  84. _valueBarController.OnHide();
  85. }
  86. protected override void RemoveEventListener()
  87. {
  88. base.RemoveEventListener();
  89. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  90. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  91. }
  92. private void RefreshList()
  93. {
  94. _ui.m_list.numItems = VipCfgArray.Instance.dataArray.Length - 1;
  95. }
  96. private void ListItemRenderer(int index, GObject obj)
  97. {
  98. VipCfg lastVipCfg = VipCfgArray.Instance.dataArray[index];
  99. VipCfg vipCfg = VipCfgArray.Instance.dataArray[index + 1];
  100. UI_ListVipItem item = UI_ListVipItem.Proxy(obj);
  101. string name = SuitCfgArray.Instance.GetCfg(vipCfg.suitId).name;
  102. item.m_txtName0.text = name.Length > 0 ? name.Substring(0, 1) : "";
  103. item.m_txtName1.text = name.Length > 1 ? name.Substring(1, 1) : "";
  104. item.m_txtName2.text = name.Length > 2 ? name.Substring(2, 1) : "";
  105. item.m_txtName3.text = name.Length > 3 ? name.Substring(3, 1) : "";
  106. item.m_txtName4.text = name.Length > 4 ? name.Substring(4) : "";
  107. item.m_txtGiftBag.SetVar("value", vipCfg.id.ToString()).FlushVars();
  108. if (item.m_listGiftBag.data == null)
  109. {
  110. item.m_listGiftBag.itemRenderer = ListRewardItemRender;
  111. }
  112. item.m_listGiftBag.data = lastVipCfg.bonusOnceArr;
  113. item.m_listGiftBag.numItems = lastVipCfg.bonusOnceArr.Length;
  114. item.m_txtWeekGiftBag.SetVar("value", vipCfg.id.ToString()).FlushVars();
  115. if (item.m_listWeekGiftBag.data == null)
  116. {
  117. item.m_listWeekGiftBag.itemRenderer = ListRewardItemRender;
  118. }
  119. item.m_listWeekGiftBag.data = vipCfg.bonusWeekArr;
  120. item.m_listWeekGiftBag.numItems = vipCfg.bonusWeekArr.Length;
  121. if (item.m_holder.data == null)
  122. {
  123. DressUpObjUI dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  124. item.m_holder.data = dressUpObjUI;
  125. _dressUpObjUIs.Add(dressUpObjUI);
  126. }
  127. _dressUpObjUI = item.m_holder.data as DressUpObjUI;
  128. _dressUpObjUI.ResetSceneObj(80, false, true, null, false);
  129. _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.suitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  130. _dressUpObjUI.UpdateWrapper(item.m_holder);
  131. if (item.m_btnShow.data == null)
  132. {
  133. item.m_btnShow.onClick.Add(OnBtnShowClick);
  134. }
  135. item.m_btnShow.data = vipCfg.suitId;
  136. if (item.m_btnGetGiftBag.data == null)
  137. {
  138. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  139. }
  140. item.m_btnGetGiftBag.data = vipCfg.id;
  141. bool isGet = MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  142. item.m_btnGetGiftBag.grayed = isGet || vipCfg.id > RoleDataManager.vipLv;
  143. RedDotController.Instance.SetComRedDot(item.m_btnGetGiftBag, !isGet && RoleDataManager.vipLv >= vipCfg.id);
  144. if (item.m_btnGetWeekGiftBag.data == null)
  145. {
  146. item.m_btnGetWeekGiftBag.onClick.Add(OnBtnGetWeekGiftBagClick);
  147. }
  148. item.m_btnGetWeekGiftBag.data = vipCfg.id;
  149. bool canGet = GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 && RoleDataManager.vipLv == vipCfg.id;
  150. item.m_btnGetWeekGiftBag.grayed = !canGet;
  151. RedDotController.Instance.SetComRedDot(item.m_btnGetWeekGiftBag, canGet);
  152. UI_ListVipItem.ProxyEnd();
  153. }
  154. private void ListRewardItemRender(int index, GObject obj)
  155. {
  156. int[][] rewards = (int[][])obj.parent.data;
  157. if (obj.data == null)
  158. {
  159. obj.data = new ItemView(obj as GComponent);
  160. }
  161. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  162. (obj.data as ItemView).SetData(itemData);
  163. (obj.data as ItemView).ChangeTxtCountStyle();
  164. }
  165. private void OnBtnShowClick(EventContext context)
  166. {
  167. GObject obj = context.sender as GObject;
  168. int suitId = (int)obj.data;
  169. int _suitTypeId = 0;
  170. for (int i = 0; i < SuitGuideMenuCfgArray.Instance.dataArray.Length; i++)
  171. {
  172. string[] suitIds = SuitGuideMenuCfgArray.Instance.dataArray[i].suitIds.Split(';');
  173. if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
  174. {
  175. _suitTypeId = SuitGuideMenuCfgArray.Instance.dataArray[i].id;
  176. break;
  177. }
  178. }
  179. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  180. }
  181. private void OnBtnGetGiftBagClick(EventContext context)
  182. {
  183. GObject obj = context.sender as GObject;
  184. int vipLv = (int)obj.data;
  185. bool isGet = MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipLv);
  186. if (isGet)
  187. {
  188. PromptController.Instance.ShowFloatTextPrompt("会员等级礼包已领取");
  189. return;
  190. }
  191. if (RoleDataManager.vipLv < vipLv)
  192. {
  193. PromptController.Instance.ShowFloatTextPrompt("会员等级不足");
  194. return;
  195. }
  196. ShopSProxy.ReqGetVipGiftBag(vipLv).Coroutine();
  197. }
  198. private void OnBtnGetWeekGiftBagClick(EventContext context)
  199. {
  200. GObject obj = context.sender as GObject;
  201. int vipLv = (int)obj.data;
  202. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 1)
  203. {
  204. PromptController.Instance.ShowFloatTextPrompt("会员每周礼包已领取");
  205. return;
  206. }
  207. if (RoleDataManager.vipLv < vipLv)
  208. {
  209. PromptController.Instance.ShowFloatTextPrompt("会员等级不足");
  210. return;
  211. }
  212. AlertUI.Show("提升VIP等级能领取更高级的礼包,是否继续领取当前等级的VIP礼包?", "(该礼包每周只能领取1次)")
  213. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  214. {
  215. ShopSProxy.ReqGetVipWeekGiftBag(vipLv).Coroutine();
  216. });
  217. }
  218. private void OnBtnLeftClick()
  219. {
  220. if (_curSelectIndex == 0) return;
  221. _curSelectIndex = _curSelectIndex - 1;
  222. _ui.m_list.ScrollToView(_curSelectIndex, true);
  223. UpdateRedDot();
  224. }
  225. private void OnBtnRightClick()
  226. {
  227. if (_curSelectIndex == _ui.m_list.numItems - 1) return;
  228. _curSelectIndex = _curSelectIndex + 1;
  229. _ui.m_list.ScrollToView(_curSelectIndex, true);
  230. UpdateRedDot();
  231. }
  232. private void UpdateSuitView()
  233. {
  234. _curSelectIndex = _ui.m_list.GetFirstChildInView();
  235. _ui.m_list.selectedIndex = _curSelectIndex;
  236. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  237. _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 1 ? true : false;
  238. }
  239. private void UpdateRedDot()
  240. {
  241. bool leftRed = false;
  242. bool rightRed = false;
  243. VipCfg[] vipCfgs = VipCfgArray.Instance.dataArray;
  244. for (int i = 1; i < vipCfgs.Length; i++)
  245. {
  246. bool isGet = MathHelper.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfgs[i].id);
  247. bool red = !isGet && RoleDataManager.vipLv >= vipCfgs[i].id;
  248. if (red && _curSelectIndex > i - 1)
  249. {
  250. leftRed = true;
  251. break;
  252. }
  253. if (red && _curSelectIndex + 1 < i)
  254. {
  255. rightRed = true;
  256. break;
  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. }
  265. }