StoreMonthView.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 isFirstBuy = false;
  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/MonthCard_Icon";
  90. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.Gold);
  91. isFirstBuy = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardGoldFirstBuy) <= 0;
  92. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardGoldEndTime);
  93. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardGoldReward) > 0;
  94. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  95. {
  96. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value1Arr[0] > 0)
  97. {
  98. privilegeCount++;
  99. }
  100. }
  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/MonthCard_Icon";
  108. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.BlackGold);
  109. isFirstBuy = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldFirstBuy) <= 0;
  110. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardBlackGoldEndTime);
  111. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldReward) > 0;
  112. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  113. {
  114. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value2Arr[0] > 0)
  115. {
  116. privilegeCount++;
  117. }
  118. }
  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. _ui.m_btnBuy.m_txtOriginalPrice.text = shopCfg.price.ToString();
  131. _ui.m_btnBuy.m_grpOriginalPrice.visible = isFirstBuy && shopCfg.oncePrice < shopCfg.price;
  132. int price = isFirstBuy ? shopCfg.oncePrice : shopCfg.price;
  133. _ui.m_btnBuy.m_txtPrice.text = price.ToString();
  134. _ui.m_btnBuy.target.data = monthCfg.shopId;
  135. _ui.m_txtTips.SetVar("value", (price * 10).ToString()).FlushVars();
  136. _ui.m_txtTips.SetVar("day", monthCfg.limitDays.ToString()).FlushVars();
  137. _ui.m_loaMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  138. _ui.m_loaDailyMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  139. _ui.m_txtPrivilegeCount.text = privilegeCount.ToString();
  140. _ui.m_txtTPrivilege.SetVar("value", privilegeCount.ToString()).FlushVars();
  141. _ui.m_btnGet.enabled = endTime > TimeHelper.ServerNow() && !isGot;
  142. _ui.m_btnGet.text = isGot ? "已领取" : "领取";
  143. _ui.m_btnGet.data = monthCfg.type; ;
  144. }
  145. private void OnBtnBuyCardClick(EventContext context)
  146. {
  147. GObject obj = context.sender as GObject;
  148. int goodsId = (int)obj.data;
  149. ShopSProxy.ReqShopBuy(goodsId).Coroutine();
  150. }
  151. private async void OnBtnGetClick(EventContext context)
  152. {
  153. GObject obj = context.sender as GObject;
  154. int goodsId = (int)obj.data;
  155. bool result = await ShopSProxy.ReqGetMonthCardReward(goodsId);
  156. if (result)
  157. {
  158. UpdateView();
  159. }
  160. }
  161. private void ListItemRenderer(int index, GObject obj)
  162. {
  163. ShopCfg shopCfg = _shopCfgs[index];
  164. ShopViewManager.Instance.UptadeItem(obj, shopCfg);
  165. }
  166. private async void OnClickBtnBuy(EventContext context)
  167. {
  168. GObject obj = context.sender as GObject;
  169. int index = (int)obj.data;
  170. ShopCfg itemData = _shopCfgs[index];
  171. if (!AntiAddictionController.CheckAntiAddictionRecharge(itemData.price))
  172. {
  173. bool result = await ShopSProxy.ReqShopBuy(itemData.id, 1);
  174. if (result)
  175. {
  176. UpdateView();
  177. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  178. }
  179. }
  180. }
  181. private void UpdateRedDot()
  182. {
  183. RedDotController.Instance.SetComRedDot(_ui.m_btnGet, menu2 == ConstStoreSubId.STORE_MONTH_GOLD_CARD && RedDotDataManager.Instance.GetGoldCardRewardRed() || menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardRewardRed());
  184. RedDotController.Instance.SetComRedDot(_ui.m_btnBlackReward, menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardClothingRed(), "", -10, 5);
  185. }
  186. }
  187. }