StoreMonthView.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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/MonthCard_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_txtMoneyCount.text = privilegeCfg.value1Arr[0].ToString();
  100. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value1Arr[1].ToString();
  101. _ui.m_btnBlackReward.visible = false;
  102. _ui.m_btnRule.data = 300010;
  103. break;
  104. case ConstStoreSubId.STORE_MONTH_BLACK_CARD:
  105. iconUrl = "ui://Store/MonthCard_Icon";
  106. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.BlackGold);
  107. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardBlackGoldEndTime);
  108. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldReward) > 0;
  109. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  110. {
  111. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value2Arr[0] > 0)
  112. {
  113. privilegeCount++;
  114. }
  115. }
  116. _ui.m_txtMoneyCount.text = privilegeCfg.value2Arr[0].ToString();
  117. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value2Arr[1].ToString();
  118. _ui.m_btnBlackReward.visible = true;
  119. _ui.m_btnRule.data = 300011;
  120. break;
  121. }
  122. long day = TimeUtil.FormattingTime11(TimeHelper.ServerNow(), endTime);
  123. _ui.m_txtTime.SetVar("value", day.ToString()).FlushVars();
  124. _ui.m_txtTime.visible = endTime > TimeHelper.ServerNow();
  125. _ui.m_loaCard.url = iconUrl;
  126. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(monthCfg.shopId);
  127. if(shopCfg.onceShopId > 0)
  128. {
  129. //如果配置了首次购买物品,使用特殊物品购买
  130. if(ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.onceShopId) <= 0)
  131. {
  132. shopCfg = ShopCfgArray.Instance.GetCfg(shopCfg.onceShopId);
  133. }
  134. }
  135. _ui.m_btnBuy.m_txtOriginalPrice.text = shopCfg.originalPrice.ToString();
  136. _ui.m_btnBuy.m_grpOriginalPrice.visible = shopCfg.price < shopCfg.originalPrice;
  137. int price = shopCfg.price;
  138. _ui.m_btnBuy.m_txtPrice.text = price.ToString();
  139. _ui.m_btnBuy.target.data = shopCfg.id;
  140. _ui.m_txtTips.SetVar("value", (price * 10).ToString()).FlushVars();
  141. _ui.m_txtTips.SetVar("day", monthCfg.limitDays.ToString()).FlushVars();
  142. _ui.m_loaMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  143. _ui.m_loaDailyMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  144. _ui.m_txtPrivilegeCount.text = privilegeCount.ToString();
  145. _ui.m_txtTPrivilege.SetVar("value", privilegeCount.ToString()).FlushVars();
  146. _ui.m_btnGet.enabled = endTime > TimeHelper.ServerNow() && !isGot;
  147. _ui.m_btnGet.text = isGot ? "已领取" : "领取";
  148. _ui.m_btnGet.data = monthCfg.type; ;
  149. }
  150. private void OnBtnBuyCardClick(EventContext context)
  151. {
  152. GObject obj = context.sender as GObject;
  153. int goodsId = (int)obj.data;
  154. ShopSProxy.ReqShopBuy(goodsId).Coroutine();
  155. }
  156. private async void OnBtnGetClick(EventContext context)
  157. {
  158. GObject obj = context.sender as GObject;
  159. int goodsId = (int)obj.data;
  160. bool result = await ShopSProxy.ReqGetMonthCardReward(goodsId);
  161. if (result)
  162. {
  163. UpdateView();
  164. }
  165. }
  166. private void ListItemRenderer(int index, GObject obj)
  167. {
  168. ShopCfg shopCfg = _shopCfgs[index];
  169. ShopViewManager.Instance.UptadeItem(obj, shopCfg);
  170. }
  171. private async void OnClickBtnBuy(EventContext context)
  172. {
  173. GObject obj = context.sender as GObject;
  174. int index = (int)obj.data;
  175. ShopCfg itemData = _shopCfgs[index];
  176. if (!AntiAddictionController.CheckAntiAddictionRecharge(itemData.price))
  177. {
  178. bool result = await ShopSProxy.ReqShopBuy(itemData.id, 1);
  179. if (result)
  180. {
  181. UpdateView();
  182. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  183. }
  184. }
  185. }
  186. private void UpdateRedDot()
  187. {
  188. RedDotController.Instance.SetComRedDot(_ui.m_btnGet, menu2 == ConstStoreSubId.STORE_MONTH_GOLD_CARD && RedDotDataManager.Instance.GetGoldCardRewardRed() || menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardRewardRed());
  189. RedDotController.Instance.SetComRedDot(_ui.m_btnBlackReward, menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardClothingRed(), "", -10, 5);
  190. }
  191. }
  192. }