RechargeStoreView.cs 9.5 KB

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