StoreMonthView.cs 9.4 KB

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