StoreChargeAddUpView.cs 11 KB

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