StoreMonthView.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 StoreMonthView : BaseWindow
  10. {
  11. private UI_StoreMonthUI _ui;
  12. private ValueBarController _valueBarController;
  13. private List<ShopCfg> _shopCfgs;
  14. private int menu2;
  15. public override void Dispose()
  16. {
  17. if (_valueBarController != null)
  18. {
  19. _valueBarController.Dispose();
  20. _valueBarController = null;
  21. }
  22. if (_ui != null)
  23. {
  24. _ui.Dispose();
  25. }
  26. _ui = null;
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. packageName = UI_StoreMonthUI.PACKAGE_NAME;
  33. _ui = UI_StoreMonthUI.Create();
  34. this.viewCom = _ui.target;
  35. isfullScreen = true;
  36. this.clickBlankToClose = false;
  37. _valueBarController = new ValueBarController(_ui.m_valueBar);
  38. _ui.m_list.itemRenderer = ListItemRenderer;
  39. _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  40. _ui.m_btnBuy.target.onClick.Add(OnBtnBuyCardClick);
  41. _ui.m_btnGet.onClick.Add(OnBtnGetClick);
  42. _ui.m_btnBlackReward.onClick.Add(OnBtnBlackRewardClick);
  43. }
  44. protected override void AddEventListener()
  45. {
  46. base.AddEventListener();
  47. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  48. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  49. }
  50. protected override void OnShown()
  51. {
  52. base.OnShown();
  53. _valueBarController.OnShown();
  54. UpdateView();
  55. UpdateRedDot();
  56. }
  57. protected override void OnHide()
  58. {
  59. base.OnHide();
  60. _valueBarController.OnHide();
  61. }
  62. protected override void RemoveEventListener()
  63. {
  64. base.RemoveEventListener();
  65. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateView);
  66. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  67. }
  68. private void OnBtnBlackRewardClick()
  69. {
  70. ViewManager.Show<StoreBlackCardRewardView>();
  71. }
  72. private void UpdateView()
  73. {
  74. menu2 = (int)this.viewData;
  75. _shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_MONTH_CARD, menu2);
  76. _shopCfgs = ShopDataManager.Instance.RemoveNotOpenCfg(_shopCfgs);
  77. _shopCfgs = ShopDataManager.Instance.SortShopGoodsCfgs(_shopCfgs);
  78. _ui.m_list.numItems = _shopCfgs.Count;
  79. MonthlyCardPrivilegeCfg privilegeCfg = MonthlyCardPrivilegeCfgArray.Instance.GetCfg(MonthCardPrivilegeType.Privilege1);
  80. string iconUrl = "";
  81. bool isGot = false;
  82. long endTime = 0;
  83. int privilegeCount = 0;
  84. MonthlyCardCfg monthCfg = null;
  85. switch (menu2)
  86. {
  87. case ConstStoreSubId.STORE_MONTH_GOLD_CARD:
  88. iconUrl = "ui://Store/card_lingxicard_icon";
  89. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.Gold);
  90. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardGoldEndTime);
  91. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardGoldReward) > 0;
  92. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  93. {
  94. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value1Arr[0] > 0)
  95. {
  96. privilegeCount++;
  97. }
  98. }
  99. _ui.m_txtDesc.SetVar("value", "灵犀卡").FlushVars();
  100. _ui.m_txtMoneyCount.text = privilegeCfg.value1Arr[0].ToString();
  101. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value1Arr[1].ToString();
  102. _ui.m_btnBlackReward.visible = false;
  103. _ui.m_btnRule.data = 300010;
  104. break;
  105. case ConstStoreSubId.STORE_MONTH_BLACK_CARD:
  106. iconUrl = "ui://Store/card_xuanjicard_icon";
  107. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.BlackGold);
  108. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardBlackGoldEndTime);
  109. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldReward) > 0;
  110. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  111. {
  112. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value2Arr[0] > 0)
  113. {
  114. privilegeCount++;
  115. }
  116. }
  117. _ui.m_txtDesc.SetVar("value", "璇玑卡").FlushVars();
  118. _ui.m_txtMoneyCount.text = privilegeCfg.value2Arr[0].ToString();
  119. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value2Arr[1].ToString();
  120. _ui.m_btnBlackReward.visible = true;
  121. _ui.m_btnRule.data = 300011;
  122. break;
  123. }
  124. long day = TimeUtil.FormattingTime11(TimeHelper.ServerNow(), endTime);
  125. _ui.m_txtTime.SetVar("value", day.ToString()).FlushVars();
  126. _ui.m_txtTime.visible = endTime > TimeHelper.ServerNow();
  127. _ui.m_loaCard.url = iconUrl;
  128. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(monthCfg.shopId);
  129. if (shopCfg.onceShopId > 0)
  130. {
  131. //如果配置了首次购买物品,使用特殊id购买
  132. if (ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.onceShopId) <= 0)
  133. {
  134. shopCfg = ShopCfgArray.Instance.GetCfg(shopCfg.onceShopId);
  135. }
  136. }
  137. _ui.m_btnBuy.m_txtOriginalPrice.text = shopCfg.originalPrice.ToString();
  138. _ui.m_btnBuy.m_grpOriginalPrice.visible = shopCfg.price < shopCfg.originalPrice;
  139. int price = shopCfg.price;
  140. _ui.m_btnBuy.m_txtPrice.text = price.ToString();
  141. _ui.m_btnBuy.target.data = shopCfg.id;
  142. _ui.m_txtTips.SetVar("value", (price * 10).ToString()).FlushVars();
  143. _ui.m_txtTips.SetVar("day", monthCfg.limitDays.ToString()).FlushVars();
  144. _ui.m_loaMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  145. _ui.m_loaDailyMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  146. _ui.m_txtPrivilegeCount.text = privilegeCount.ToString();
  147. _ui.m_txtTPrivilege.SetVar("value", privilegeCount.ToString()).FlushVars();
  148. _ui.m_btnGet.enabled = endTime > TimeHelper.ServerNow() && !isGot;
  149. _ui.m_btnGet.text = isGot ? "已领取" : "领取";
  150. _ui.m_btnGet.data = monthCfg.type; ;
  151. }
  152. private void OnBtnBuyCardClick(EventContext context)
  153. {
  154. GObject obj = context.sender as GObject;
  155. int goodsId = (int)obj.data;
  156. ShopSProxy.ReqShopBuy(goodsId).Coroutine();
  157. }
  158. private async void OnBtnGetClick(EventContext context)
  159. {
  160. GObject obj = context.sender as GObject;
  161. int goodsId = (int)obj.data;
  162. bool result = await ShopSProxy.ReqGetMonthCardReward(goodsId);
  163. if (result)
  164. {
  165. UpdateView();
  166. }
  167. }
  168. private void ListItemRenderer(int index, GObject obj)
  169. {
  170. ShopCfg shopCfg = _shopCfgs[index];
  171. ShopViewManager.Instance.UptadeItem(obj, shopCfg);
  172. }
  173. private async void OnClickBtnBuy(EventContext context)
  174. {
  175. GObject obj = context.sender as GObject;
  176. int index = (int)obj.data;
  177. ShopCfg itemData = _shopCfgs[index];
  178. if (!AntiAddictionController.CheckAntiAddictionRecharge(itemData.price))
  179. {
  180. bool result = await ShopSProxy.ReqShopBuy(itemData.id, 1);
  181. if (result)
  182. {
  183. UpdateView();
  184. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  185. }
  186. }
  187. }
  188. private void UpdateRedDot()
  189. {
  190. RedDotController.Instance.SetComRedDot(_ui.m_btnGet, menu2 == ConstStoreSubId.STORE_MONTH_GOLD_CARD && RedDotDataManager.Instance.GetGoldCardRewardRed() || menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardRewardRed());
  191. RedDotController.Instance.SetComRedDot(_ui.m_btnBlackReward, menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardClothingRed(), "", -10, 5);
  192. }
  193. }
  194. }