StoreMonthView.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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_btnBuy.target.onClick.Add(OnBtnBuyCardClick);
  39. _ui.m_btnGet.onClick.Add(OnBtnGetClick);
  40. }
  41. protected override void AddEventListener()
  42. {
  43. base.AddEventListener();
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. _valueBarController.OnShown();
  49. UpdateView();
  50. }
  51. protected override void OnHide()
  52. {
  53. base.OnHide();
  54. _valueBarController.OnHide();
  55. }
  56. protected override void RemoveEventListener()
  57. {
  58. base.RemoveEventListener();
  59. }
  60. private void UpdateView()
  61. {
  62. int menu2 = (int)this.viewData;
  63. _shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_MONTH_CARD, menu2);
  64. _ui.m_list.numItems = _shopCfgs.Count;
  65. MonthlyCardPrivilegeCfg privilegeCfg = MonthlyCardPrivilegeCfgArray.Instance.GetCfg(MonthCardPrivilegeType.Privilege1);
  66. string iconUrl = "";
  67. bool isFirstBuy = false;
  68. bool isGot = false;
  69. long endTime = 0;
  70. int privilegeCount = 0;
  71. MonthlyCardCfg monthCfg = null;
  72. switch (menu2)
  73. {
  74. case ConstStoreSubId.STORE_MONTH_GLOAD_CARD:
  75. iconUrl = "ui://Store/MonthCard_Icon";
  76. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.Gold);
  77. isFirstBuy = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardGoldFirstBuy) <= 0;
  78. endTime = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardGoldEndTime);
  79. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardGoldReward) > 0;
  80. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  81. {
  82. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value1Arr[0] > 0)
  83. {
  84. privilegeCount++;
  85. }
  86. }
  87. _ui.m_txtMoneyCount.text = privilegeCfg.value1Arr[0].ToString();
  88. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value1Arr[1].ToString();
  89. break;
  90. case ConstStoreSubId.STORE_MONTH_BLACK_CARD:
  91. iconUrl = "ui://Store/MonthCard_Icon";
  92. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.BlackGold);
  93. isFirstBuy = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldFirstBuy) <= 0;
  94. endTime = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldEndTime);
  95. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldReward) > 0;
  96. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  97. {
  98. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value2Arr[0] > 0)
  99. {
  100. privilegeCount++;
  101. }
  102. }
  103. _ui.m_txtMoneyCount.text = privilegeCfg.value2Arr[0].ToString();
  104. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value2Arr[1].ToString();
  105. break;
  106. }
  107. long day = TimeUtil.FormattingTime11(TimeHelper.ServerNow(), endTime);
  108. _ui.m_txtTime.SetVar("value", day.ToString()).FlushVars();
  109. _ui.m_txtTime.visible = endTime > TimeHelper.ServerNow();
  110. _ui.m_loaCard.url = iconUrl;
  111. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(monthCfg.shopId);
  112. _ui.m_btnBuy.m_txtOriginalPrice.text = shopCfg.price.ToString();
  113. _ui.m_btnBuy.m_grpOriginalPrice.visible = isFirstBuy && shopCfg.oncePrice < shopCfg.price;
  114. int price = isFirstBuy ? shopCfg.oncePrice : shopCfg.price;
  115. _ui.m_btnBuy.m_txtPrice.text = price.ToString();
  116. _ui.m_btnBuy.target.data = "";
  117. _ui.m_txtTips.SetVar("value", (price * 10).ToString()).FlushVars();
  118. _ui.m_txtTips.SetVar("day", monthCfg.limitDays.ToString()).FlushVars();
  119. _ui.m_loaMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  120. _ui.m_loaDailyMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  121. _ui.m_txtPrivilegeCount.text = privilegeCount.ToString();
  122. _ui.m_btnGet.enabled = endTime > TimeHelper.ServerNow() && !isGot;
  123. _ui.m_btnGet.text = isGot ? "已领取" : "领取";
  124. _ui.m_btnGet.data = monthCfg.type; ;
  125. }
  126. private void OnBtnBuyCardClick(EventContext context)
  127. {
  128. GObject obj = context.sender as GObject;
  129. int goodsId = (int)obj.data;
  130. ShopSProxy.ReqShopBuy(goodsId).Coroutine();
  131. }
  132. private async void OnBtnGetClick(EventContext context)
  133. {
  134. GObject obj = context.sender as GObject;
  135. int goodsId = (int)obj.data;
  136. bool result = await ShopSProxy.ReqGetMonthCardReward(goodsId);
  137. if (result)
  138. {
  139. UpdateView();
  140. }
  141. }
  142. private void ListItemRenderer(int index, GObject obj)
  143. {
  144. ShopCfg shopCfg = _shopCfgs[index];
  145. ShopViewManager.Instance.UptadeItem(obj, shopCfg);
  146. }
  147. private void OnClickBtnBuy(EventContext context)
  148. {
  149. GObject obj = context.sender as GObject;
  150. int index = (int)obj.data;
  151. ShopCfg itemData = _shopCfgs[index];
  152. if (!AntiAddictionController.CheckAntiAddictionRecharge(itemData.price))
  153. {
  154. ShopSProxy.ReqShopBuy(itemData.id, 1).Coroutine();
  155. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  156. }
  157. }
  158. }
  159. }