RechargeStoreView.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using UI.RechargeStore;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. namespace GFGGame
  6. {
  7. public class RechargeStoreView : BaseWindow
  8. {
  9. private UI_RechargeStoreUI _ui;
  10. private ValueBarController _valueBarController;
  11. private List<GiftBagCfg> _giftCfgs;
  12. public override void Dispose()
  13. {
  14. _valueBarController.Dispose();
  15. _valueBarController = null;
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. }
  20. _ui = null;
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_RechargeStoreUI.PACKAGE_NAME;
  27. _ui = UI_RechargeStoreUI.Create();
  28. this.viewCom = _ui.target;
  29. isfullScreen = true;
  30. _valueBarController = new ValueBarController(_ui.m_valueBar);
  31. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  32. _ui.m_list.itemRenderer = ListItemRenderer;
  33. _ui.m_listGift.itemRenderer = ListGiftItemRenderer;
  34. _ui.m_listExchange.itemRenderer = ListExchangeItemRenderer;
  35. _ui.m_comTab.m_c1.onChanged.Add(OnComTabChange);
  36. _ui.m_c1.onChanged.Add(OnTabChange);
  37. EventAgent.AddEventListener(ConstMessage.BUY_GIFT_SUCCESS, UpdateGiftBagList);
  38. EventAgent.AddEventListener(ConstMessage.BUY_RECHARGE_SUCCESS, () =>
  39. {
  40. _ui.m_list.numItems = RechargeCfgArray.Instance.dataArray.Length;
  41. });
  42. EventAgent.AddEventListener(ConstMessage.BUY_EXCHANGE_SUCCESS, () =>
  43. {
  44. _ui.m_listExchange.numItems = ShopExchangeCfgArray.Instance.dataArray.Length;
  45. });
  46. }
  47. protected override void OnShown()
  48. {
  49. base.OnShown();
  50. _valueBarController.OnShown();
  51. _ui.m_list.numItems = RechargeCfgArray.Instance.dataArray.Length;
  52. }
  53. protected override void OnHide()
  54. {
  55. base.OnHide();
  56. _valueBarController.OnHide();
  57. }
  58. private void OnClickBtnBack()
  59. {
  60. this.Hide();
  61. }
  62. private void OnComTabChange()
  63. {
  64. _ui.m_c1.selectedIndex = _ui.m_comTab.m_c1.selectedIndex;
  65. _ui.m_list.numItems = RechargeCfgArray.Instance.dataArray.Length;
  66. _ui.m_listExchange.numItems = ShopExchangeCfgArray.Instance.dataArray.Length;
  67. UpdateGiftBagList();
  68. }
  69. private void OnTabChange()
  70. {
  71. _ui.m_list.ScrollToView(0);
  72. _ui.m_listGift.ScrollToView(0);
  73. _ui.m_listExchange.ScrollToView(0);
  74. }
  75. private void UpdateGiftBagList()
  76. {
  77. _giftCfgs = RechargeDataManager.Instance.GetGiftBagCfgs();
  78. _ui.m_listGift.numItems = _giftCfgs.Count;
  79. }
  80. private void ListItemRenderer(int index, GObject obj)
  81. {
  82. RechargeCfg itemData = RechargeCfgArray.Instance.dataArray[index];
  83. UI_StoreListItem item = UI_StoreListItem.Proxy(obj);
  84. item.m_btnBuy.m_c1.selectedIndex = 1;
  85. item.m_btnBuy.m_txtTitle.text = itemData.price.ToString();
  86. if (item.m_btnBuy.target.data == null)
  87. {
  88. item.m_btnBuy.target.onClick.Add(() =>
  89. {
  90. RechargeSProxy.ReqRecharge(itemData.id).Coroutine();
  91. });
  92. }
  93. item.m_btnBuy.target.data = index;
  94. item.m_txtName.text = string.Format("{0}{1}", itemData.itemNum, itemData.name);
  95. item.m_txtDesc.text = string.Format("首充赠送+{0}{1}", itemData.itemNum, itemData.name);
  96. item.m_imgDouble.visible = RechargeDataManager.Instance.GetRechargeBuyNumById(itemData.id) <= itemData.doubleTimes;
  97. item.m_txtDesc.visible = RechargeDataManager.Instance.GetRechargeBuyNumById(itemData.id) <= itemData.doubleTimes; ;
  98. item.m_icon.url = "ui://RechargeStore/sc_zizhuan_" + itemData.id;
  99. UI_StoreListItem.ProxyEnd();
  100. }
  101. private void ListGiftItemRenderer(int index, GObject obj)
  102. {
  103. UI_ListGiftItem item = UI_ListGiftItem.Proxy(obj);
  104. GiftBagCfg cfg = _giftCfgs[index];
  105. item.m_txtName.text = cfg.name;
  106. item.m_icon.url = string.Format("ui://RechargeStore/{0}", cfg.res);
  107. item.m_txtDesc.SetVar("count", cfg.desc);
  108. item.m_grpDiscount.visible = cfg.desc != "";
  109. item.m_txtRefreshTime.text = RechargeDataManager.Instance.GetRefreshTime(cfg.id);
  110. item.m_grpRefreshTime.visible = RechargeDataManager.Instance.GetRefreshTime(cfg.id) != "";
  111. item.m_c2.selectedIndex = RechargeDataManager.Instance.GetGiftStateById(cfg.id) ? 0 : 1;
  112. if (cfg.lockType == LockType.STORY_LV)
  113. {
  114. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(cfg.storyLevelId);
  115. item.m_txtLock.text = string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.chapterId), storyLevelCfg.order);
  116. }
  117. else if (cfg.lockType == LockType.ROLE_LV)
  118. {
  119. item.m_txtLock.text = string.Format("角色达到{0}级解锁", cfg.lv);
  120. }
  121. int buyNum = RechargeDataManager.Instance.GetGiftBuyNumById(cfg.id);
  122. item.m_txtLimit.text = string.Format("每{0}限购({1}/{2})", RechargeDataManager.Instance.refreshType[cfg.refreshType], StringUtil.GetColorText(buyNum.ToString(), "#DA8870"), cfg.maxBuyNum);
  123. // UI_Button14 btn = UI_Button14.Proxy(item.m_btnBuy);
  124. item.m_c1.selectedIndex = cfg.maxBuyNum == 0 || buyNum < cfg.maxBuyNum ? 0 : 1;
  125. if (item.m_c1.selectedIndex == 0)
  126. {
  127. item.m_txtOriginalPrice.text = cfg.originalPrice.ToString();
  128. if (cfg.price > 0 && cfg.costType != CostType.FREE)
  129. {
  130. item.m_grpOriginalPrice.visible = cfg.originalPrice > 0;
  131. item.m_grpIcon.visible = true;
  132. item.m_txtPrice.text = cfg.price.ToString();
  133. if (cfg.costType == CostType.RMB)
  134. {
  135. item.m_loaIcon.visible = false;
  136. item.m_txtIcon.visible = true;
  137. item.m_txtIcon.text = "¥";
  138. }
  139. else
  140. {
  141. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.costId);
  142. item.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(itemCfg.res);
  143. item.m_loaIcon.visible = true;
  144. item.m_txtIcon.visible = false;
  145. }
  146. }
  147. else
  148. {
  149. item.m_grpIcon.visible = false;
  150. item.m_grpOriginalPrice.visible = false;
  151. item.m_txtPrice.text = "免费";
  152. }
  153. }
  154. if (item.target.data == null)
  155. {
  156. item.target.onClick.Add(OnBtnBuyClick);
  157. }
  158. item.target.data = cfg.id;
  159. UI_ListGiftItem.ProxyEnd();
  160. }
  161. private void OnBtnBuyClick(EventContext context)
  162. {
  163. GObject btn = context.sender as GObject;
  164. ViewManager.Show<GiftBagBuyView>(btn.data);
  165. }
  166. private void ListExchangeItemRenderer(int index, GObject obj)
  167. {
  168. ShopExchangeCfg cfg = ShopExchangeCfgArray.Instance.dataArray[index];
  169. UI_StoreListItem item = UI_StoreListItem.Proxy(obj);
  170. item.m_btnBuy.m_c1.selectedIndex = 0;
  171. item.m_btnBuy.m_txtTitle.text = cfg.costNum.ToString();
  172. if (item.m_btnBuy.target.data == null)
  173. {
  174. item.m_btnBuy.target.onClick.Add(() =>
  175. {
  176. ViewManager.Show<ItemExchangeView>(cfg.id);
  177. });
  178. }
  179. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.itemId);
  180. item.m_btnBuy.target.data = cfg.id;
  181. item.m_btnBuy.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costId).res);
  182. item.m_txtName.text = itemCfg.name;
  183. item.m_txtDesc.text = string.Format("剩余:{0}", cfg.maxLimit - RechargeDataManager.Instance.GetExchangeBuyNumById(cfg.id));
  184. if (cfg.maxLimit == 0) item.m_txtDesc.text = "剩余:不限";
  185. item.m_imgDouble.visible = false;
  186. item.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  187. UI_StoreListItem.ProxyEnd();
  188. }
  189. }
  190. }