StoreMonthView.cs 9.0 KB

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