StoreMonthView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. _ui.m_guideBackBtn.onClick.Add(OnClickBtnBack);
  48. AddEffect();
  49. }
  50. protected override void AddEventListener()
  51. {
  52. base.AddEventListener();
  53. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  54. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  55. }
  56. protected override void OnShown()
  57. {
  58. base.OnShown();
  59. _valueBarController.OnShown();
  60. UpdateView();
  61. UpdateRedDot();
  62. //Timers.inst.AddUpdate(CheckGuide);
  63. }
  64. protected override void OnHide()
  65. {
  66. base.OnHide();
  67. ShopViewManager.Instance.ClearItemEff();
  68. _valueBarController.OnHide();
  69. //Timers.inst.Remove(CheckGuide);
  70. }
  71. protected override void RemoveEventListener()
  72. {
  73. base.RemoveEventListener();
  74. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateView);
  75. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  76. }
  77. private void OnClickBtnBack()
  78. {
  79. this.Hide();
  80. ViewManager.GoBackFrom(typeof(StoreView).FullName);
  81. }
  82. private void OnBtnBlackRewardClick()
  83. {
  84. ViewManager.Show<StoreBlackCardRewardView>();
  85. }
  86. private void UpdateView()
  87. {
  88. menu2 = (int)this.viewData;
  89. ShopViewManager.Instance.ClearItemEff();
  90. _shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_MONTH_CARD, menu2);
  91. _shopCfgs = ShopDataManager.Instance.RemoveNotOpenCfg(_shopCfgs);
  92. _shopCfgs = ShopDataManager.Instance.SortShopGoodsCfgs(_shopCfgs);
  93. _ui.m_storeMonthList.m_list.numItems = _shopCfgs.Count;
  94. MonthlyCardPrivilegeCfg privilegeCfg = MonthlyCardPrivilegeCfgArray.Instance.GetCfg(MonthCardPrivilegeType.Privilege1);
  95. string iconUrl = "";
  96. bool isGot = false;
  97. long endTime = 0;
  98. int privilegeCount = 0;
  99. MonthlyCardCfg monthCfg = null;
  100. switch (menu2)
  101. {
  102. case ConstStoreSubId.STORE_MONTH_GOLD_CARD:
  103. iconUrl = "ui://Store/hongbao_card_icon";
  104. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.Gold);
  105. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardGoldEndTime);
  106. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardGoldReward) > 0;
  107. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  108. {
  109. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value1Arr[0] > 0)
  110. {
  111. privilegeCount++;
  112. }
  113. }
  114. _ui.m_txtDesc.SetVar("value", "红包卡").FlushVars();
  115. _ui.m_txtMoneyCount.text = privilegeCfg.value1Arr[0].ToString();
  116. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value1Arr[1].ToString();
  117. _ui.m_btnBlackReward.visible = false;
  118. _ui.m_btnRule.data = 300010;
  119. break;
  120. case ConstStoreSubId.STORE_MONTH_BLACK_CARD:
  121. iconUrl = "ui://Store/fuqi_card_icon";
  122. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.BlackGold);
  123. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardBlackGoldEndTime);
  124. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldReward) > 0;
  125. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  126. {
  127. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value2Arr[0] > 0)
  128. {
  129. privilegeCount++;
  130. }
  131. }
  132. _ui.m_txtDesc.SetVar("value", "福气卡").FlushVars();
  133. _ui.m_txtMoneyCount.text = privilegeCfg.value2Arr[0].ToString();
  134. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value2Arr[1].ToString();
  135. _ui.m_btnBlackReward.visible = true;
  136. _ui.m_btnRule.data = 300011;
  137. break;
  138. }
  139. long day = TimeUtil.FormattingTime11(TimeHelper.ServerNow(), endTime);
  140. _ui.m_txtTime.SetVar("value", day.ToString()).FlushVars();
  141. _ui.m_txtTime.visible = endTime > TimeHelper.ServerNow();
  142. _ui.m_loaCard.url = iconUrl;
  143. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(monthCfg.shopId);
  144. if (shopCfg.onceShopId > 0)
  145. {
  146. //如果配置了首次购买物品,使用特殊id购买
  147. if (ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.onceShopId) <= 0)
  148. {
  149. shopCfg = ShopCfgArray.Instance.GetCfg(shopCfg.onceShopId);
  150. }
  151. }
  152. _ui.m_btnBuy.m_txtOriginalPrice.text = shopCfg.originalPrice.ToString();
  153. _ui.m_btnBuy.m_grpOriginalPrice.visible = shopCfg.Price < shopCfg.originalPrice;
  154. int price = shopCfg.Price;
  155. _ui.m_btnBuy.m_txtPrice.text = price.ToString();
  156. _ui.m_btnBuy.target.data = shopCfg.id;
  157. _ui.m_txtTips.SetVar("value", (price * 10).ToString()).FlushVars();
  158. _ui.m_txtTips.SetVar("day", monthCfg.limitDays.ToString()).FlushVars();
  159. _ui.m_loaMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  160. _ui.m_loaDailyMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[1]).res);
  161. _ui.m_txtPrivilegeCount.text = privilegeCount.ToString();
  162. _ui.m_txtTPrivilege.SetVar("value", privilegeCount.ToString()).FlushVars();
  163. _ui.m_btnGet.enabled = endTime > TimeHelper.ServerNow() && !isGot;
  164. _ui.m_btnGet.text = isGot ? "已领取" : "领取";
  165. _ui.m_btnGet.data = monthCfg.type; ;
  166. }
  167. private void OnBtnBuyCardClick(EventContext context)
  168. {
  169. GObject obj = context.sender as GObject;
  170. int goodsId = (int)obj.data;
  171. ShopSProxy.ReqShopBuy(goodsId).Coroutine();
  172. }
  173. private async void OnBtnGetClick(EventContext context)
  174. {
  175. GObject obj = context.sender as GObject;
  176. int goodsId = (int)obj.data;
  177. bool result = await ShopSProxy.ReqGetMonthCardReward(goodsId);
  178. if (result)
  179. {
  180. UpdateView();
  181. }
  182. }
  183. private void ListItemRenderer(int index, GObject obj)
  184. {
  185. ShopCfg shopCfg = _shopCfgs[index];
  186. ShopViewManager.Instance.UptadeItem(obj, shopCfg);
  187. }
  188. private async void OnClickBtnBuy(EventContext context)
  189. {
  190. GObject obj = context.sender as GObject;
  191. int index = (int)obj.data;
  192. ShopCfg itemData = _shopCfgs[index];
  193. if (!AntiAddictionController.CheckAntiAddictionRecharge(itemData.Price))
  194. {
  195. bool result = await ShopSProxy.ReqShopBuy(itemData.id, 1);
  196. if (result)
  197. {
  198. UpdateView();
  199. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  200. }
  201. }
  202. }
  203. private void UpdateRedDot()
  204. {
  205. RedDotController.Instance.SetComRedDot(_ui.m_btnGet, menu2 == ConstStoreSubId.STORE_MONTH_GOLD_CARD && RedDotDataManager.Instance.GetGoldCardRewardRed() || menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardRewardRed());
  206. RedDotController.Instance.SetComRedDot(_ui.m_btnBlackReward, menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardClothingRed(), "", -10, 5);
  207. }
  208. private void AddEffect()
  209. {
  210. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderfEff, "ui_Small_parts", "store_monthlycard");
  211. }
  212. private bool CheckIsBuyMonthCard()
  213. {
  214. long endTime1 = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardGoldEndTime);
  215. long endTime2 = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardBlackGoldEndTime);
  216. if (endTime1 > TimeHelper.ServerNow() || endTime2 > TimeHelper.ServerNow())
  217. {
  218. return true;
  219. }
  220. return false;
  221. }
  222. private void CheckGuide(object param)
  223. {
  224. if (GuideDataManager.IsGuideFinish(ConstGuideId.SHEZHI_ZHUJIEMBG) <= 0 && CheckIsBuyMonthCard())
  225. {
  226. UpdateCheckGuide(null);
  227. }
  228. else
  229. {
  230. Timers.inst.Remove(CheckGuide);
  231. }
  232. }
  233. protected void UpdateCheckGuide(object param)
  234. {
  235. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  236. GuideController.TryGuide(_ui.m_guideBackBtn, ConstGuideId.SHEZHI_ZHUJIEMBG, 1, "去开启背景更换特权");
  237. }
  238. }
  239. }