RechargeStoreView.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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_c1.selectedIndex = 0;
  52. _ui.m_comTab.m_c1.selectedIndex = 0;
  53. _ui.m_list.numItems = RechargeCfgArray.Instance.dataArray.Length;
  54. _ui.m_listExchange.numItems = ShopExchangeCfgArray.Instance.dataArray.Length;
  55. UpdateGiftBagList();
  56. OnTabChange();
  57. }
  58. protected override void OnHide()
  59. {
  60. base.OnHide();
  61. _valueBarController.OnHide();
  62. }
  63. private void OnClickBtnBack()
  64. {
  65. this.Hide();
  66. }
  67. private void OnComTabChange()
  68. {
  69. _ui.m_c1.selectedIndex = _ui.m_comTab.m_c1.selectedIndex;
  70. }
  71. private void OnTabChange()
  72. {
  73. _ui.m_list.ScrollToView(0);
  74. _ui.m_listGift.ScrollToView(0);
  75. _ui.m_listExchange.ScrollToView(0);
  76. }
  77. private void UpdateGiftBagList()
  78. {
  79. _giftCfgs = RechargeDataManager.Instance.GetGiftBagCfgs();
  80. _ui.m_listGift.numItems = _giftCfgs.Count;
  81. }
  82. private void ListItemRenderer(int index, GObject obj)
  83. {
  84. RechargeCfg itemData = RechargeCfgArray.Instance.dataArray[index];
  85. UI_StoreListItem item = UI_StoreListItem.Proxy(obj);
  86. item.m_btnBuy.m_c1.selectedIndex = 1;
  87. item.m_btnBuy.m_txtTitle.text = itemData.price.ToString();
  88. if (item.m_btnBuy.target.data == null)
  89. {
  90. item.m_btnBuy.target.onClick.Add(() =>
  91. {
  92. RechargeSProxy.ReqRecharge(itemData.id).Coroutine();
  93. });
  94. }
  95. item.m_btnBuy.target.data = index;
  96. item.m_txtName.text = string.Format("{0}{1}", itemData.itemNum, itemData.name);
  97. item.m_txtDesc.text = string.Format("首充赠送+{0}{1}", itemData.itemNum, itemData.name);
  98. bool isDouble = RechargeDataManager.Instance.GetRechargeBuyNumById(itemData.id) < itemData.doubleTimes;
  99. item.m_imgDouble.visible = isDouble;
  100. item.m_txtDesc.visible = isDouble;
  101. item.m_icon.url = "ui://RechargeStore/sc_zizhuan_" + itemData.id;
  102. UI_StoreListItem.ProxyEnd();
  103. }
  104. private void ListGiftItemRenderer(int index, GObject obj)
  105. {
  106. UI_ListGiftItem item = UI_ListGiftItem.Proxy(obj);
  107. GiftBagCfg cfg = _giftCfgs[index];
  108. item.m_txtName.text = cfg.name;
  109. item.m_icon.url = string.Format("ui://RechargeStore/{0}", cfg.res);
  110. item.m_txtDesc.SetVar("count", cfg.desc).FlushVars(); ;
  111. item.m_grpDiscount.visible = cfg.desc != "";
  112. item.m_txtEndTime.text = RechargeDataManager.Instance.GetEndTime(cfg.id);
  113. item.m_grpEndTime.visible = cfg.endTime != "";
  114. item.m_c2.selectedIndex = RechargeDataManager.Instance.GetGiftStateById(cfg.id) ? 0 : 1;
  115. if (cfg.lockType == LockType.STORY_LV)
  116. {
  117. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(cfg.storyLevelId);
  118. item.m_txtLock.text = string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.chapterId), storyLevelCfg.order);
  119. }
  120. else if (cfg.lockType == LockType.ROLE_LV)
  121. {
  122. item.m_txtLock.text = string.Format("角色达到{0}级解锁", cfg.lv);
  123. }
  124. int buyNum = RechargeDataManager.Instance.GetGiftBuyNumById(cfg.id);
  125. item.m_txtLimit.text = string.Format("{0}({1}/{2})", RechargeDataManager.Instance.refreshType[cfg.refreshType], StringUtil.GetColorText(buyNum.ToString(), "#DA8870"), cfg.maxBuyNum);
  126. item.m_txtLimit.visible = cfg.maxBuyNum > 0;
  127. // if (cfg.refreshType == RefreshType.NONE) item.m_txtLimit.text = "永久限购";
  128. // UI_Button14 btn = UI_Button14.Proxy(item.m_btnBuy);
  129. item.m_c1.selectedIndex = cfg.maxBuyNum == 0 || buyNum < cfg.maxBuyNum ? 0 : 1;
  130. if (item.m_c1.selectedIndex == 0)
  131. {
  132. item.m_txtOriginalPrice.text = cfg.originalPrice.ToString();
  133. if (cfg.price > 0 && cfg.costType != CostType.FREE)
  134. {
  135. item.m_grpOriginalPrice.visible = cfg.originalPrice > 0;
  136. item.m_grpIcon.visible = true;
  137. item.m_txtPrice.text = cfg.price.ToString();
  138. if (cfg.costType == CostType.RMB)
  139. {
  140. item.m_loaIcon.visible = false;
  141. item.m_txtIcon.visible = true;
  142. item.m_txtIcon.text = "¥";
  143. }
  144. else
  145. {
  146. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.costId);
  147. item.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(itemCfg.res);
  148. item.m_loaIcon.visible = true;
  149. item.m_txtIcon.visible = false;
  150. }
  151. }
  152. else
  153. {
  154. item.m_grpIcon.visible = false;
  155. item.m_grpOriginalPrice.visible = false;
  156. item.m_txtPrice.text = "免费";
  157. }
  158. }
  159. if (item.target.data == null)
  160. {
  161. item.target.onClick.Add(OnBtnBuyClick);
  162. }
  163. item.target.data = cfg.id;
  164. UI_ListGiftItem.ProxyEnd();
  165. }
  166. private void OnBtnBuyClick(EventContext context)
  167. {
  168. GObject btn = context.sender as GObject;
  169. int giftId = (int)btn.data;
  170. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  171. if (cfg.maxBuyNum != 0 && RechargeDataManager.Instance.GetGiftBuyNumById(giftId) == cfg.maxBuyNum)
  172. {
  173. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  174. return;
  175. }
  176. ViewManager.Show<GiftBagBuyView>(btn.data);
  177. }
  178. private void ListExchangeItemRenderer(int index, GObject obj)
  179. {
  180. ShopExchangeCfg cfg = ShopExchangeCfgArray.Instance.dataArray[index];
  181. UI_StoreListItem item = UI_StoreListItem.Proxy(obj);
  182. item.m_btnBuy.m_c1.selectedIndex = 0;
  183. item.m_btnBuy.m_txtTitle.text = cfg.costNum.ToString();
  184. if (item.m_btnBuy.target.data == null)
  185. {
  186. item.m_btnBuy.target.onClick.Add(() =>
  187. {
  188. ViewManager.Show<ItemExchangeView>(cfg.id);
  189. });
  190. }
  191. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.itemId);
  192. item.m_btnBuy.target.data = cfg.id;
  193. item.m_btnBuy.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costId).res);
  194. item.m_txtName.text = itemCfg.name;
  195. item.m_txtDesc.text = string.Format("剩余:{0}", cfg.maxLimit - RechargeDataManager.Instance.GetExchangeBuyNumById(cfg.id));
  196. if (cfg.maxLimit == 0) item.m_txtDesc.text = "剩余:不限";
  197. item.m_imgDouble.visible = false;
  198. item.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  199. UI_StoreListItem.ProxyEnd();
  200. }
  201. }
  202. }