StoreMonthView.cs 8.0 KB

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