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