StoreMonthView.cs 9.3 KB

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