StoreMonthView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. using UI.Store;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. using ET;
  6. using System;
  7. using System.Linq;
  8. namespace GFGGame
  9. {
  10. public class StoreMonthView : BaseWindow
  11. {
  12. private UI_StoreMonthUI _ui;
  13. private ValueBarController _valueBarController;
  14. private List<ShopCfg> _shopCfgs;
  15. private int menu2;
  16. private EffectUI _effectUI1;
  17. public override void Dispose()
  18. {
  19. EffectUIPool.Recycle(_effectUI1);
  20. _effectUI1 = null;
  21. if (_valueBarController != null)
  22. {
  23. _valueBarController.Dispose();
  24. _valueBarController = null;
  25. }
  26. if (_ui != null)
  27. {
  28. _ui.Dispose();
  29. }
  30. _ui = null;
  31. base.Dispose();
  32. }
  33. protected override void OnInit()
  34. {
  35. base.OnInit();
  36. packageName = UI_StoreMonthUI.PACKAGE_NAME;
  37. _ui = UI_StoreMonthUI.Create();
  38. this.viewCom = _ui.target;
  39. isfullScreen = true;
  40. this.clickBlankToClose = false;
  41. this.bringToFontOnClick = false;
  42. _valueBarController = new ValueBarController(_ui.m_valueBar);
  43. _ui.m_storeMonthList.m_list.itemRenderer = ListItemRenderer;
  44. _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  45. _ui.m_btnBuy.target.onClick.Add(OnBtnBuyCardClick);
  46. _ui.m_btnGet.onClick.Add(OnBtnGetClick);
  47. _ui.m_btnBlackReward.onClick.Add(OnBtnBlackRewardClick);
  48. _ui.m_guideBackBtn.onClick.Add(OnClickBtnBack);
  49. AddEffect();
  50. }
  51. protected override void AddEventListener()
  52. {
  53. base.AddEventListener();
  54. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  55. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  56. }
  57. protected override void OnShown()
  58. {
  59. base.OnShown();
  60. _valueBarController.OnShown();
  61. UpdateView();
  62. UpdateRedDot();
  63. //Timers.inst.AddUpdate(CheckGuide);
  64. }
  65. protected override void OnHide()
  66. {
  67. base.OnHide();
  68. ShopViewManager.Instance.ClearItemEff();
  69. _valueBarController.OnHide();
  70. //Timers.inst.Remove(CheckGuide);
  71. }
  72. protected override void RemoveEventListener()
  73. {
  74. base.RemoveEventListener();
  75. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateView);
  76. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  77. }
  78. private void OnClickBtnBack()
  79. {
  80. this.Hide();
  81. ViewManager.GoBackFrom(typeof(StoreView).FullName);
  82. }
  83. private void OnBtnBlackRewardClick()
  84. {
  85. ViewManager.Show<StoreBlackCardRewardView>();
  86. }
  87. private void UpdateView()
  88. {
  89. menu2 = (int)this.viewData;
  90. ShopViewManager.Instance.ClearItemEff();
  91. _shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_MONTH_CARD, menu2);
  92. _shopCfgs = ShopDataManager.Instance.RemoveNotOpenCfg(_shopCfgs);
  93. _shopCfgs = ShopDataManager.Instance.SortShopGoodsCfgs(_shopCfgs);
  94. var addList = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_MONTH_CARD, 2);
  95. //增加月卡商城子类型2的商品拼接, 用意是支持单个商品在红包卡, 福气卡里面销售
  96. foreach (var shopCfgItem in addList)
  97. {
  98. if (_shopCfgs.All(a => a.id != shopCfgItem.id))
  99. {
  100. _shopCfgs.Add(shopCfgItem);
  101. }
  102. }
  103. _ui.m_storeMonthList.m_list.numItems = _shopCfgs.Count;
  104. MonthlyCardPrivilegeCfg privilegeCfg = MonthlyCardPrivilegeCfgArray.Instance.GetCfg(MonthCardPrivilegeType.Privilege1);
  105. string iconUrl = "";
  106. bool isGot = false;
  107. long endTime = 0;
  108. int privilegeCount = 0;
  109. MonthlyCardCfg monthCfg = null;
  110. switch (menu2)
  111. {
  112. case ConstStoreSubId.STORE_MONTH_GOLD_CARD:
  113. iconUrl = "ui://Store/hongbao_card_icon";
  114. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.Gold);
  115. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardGoldEndTime);
  116. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardGoldReward) > 0;
  117. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  118. {
  119. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value1Arr[0] > 0)
  120. {
  121. privilegeCount++;
  122. }
  123. }
  124. _ui.m_txtDesc.SetVar("value", "红包卡").FlushVars();
  125. _ui.m_txtMoneyCount.text = privilegeCfg.value1Arr[0].ToString();
  126. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value1Arr[1].ToString();
  127. _ui.m_btnBlackReward.visible = false;
  128. _ui.m_btnRule.data = 300010;
  129. break;
  130. case ConstStoreSubId.STORE_MONTH_BLACK_CARD:
  131. iconUrl = "ui://Store/fuqi_card_icon";
  132. monthCfg = MonthlyCardCfgArray.Instance.GetCfg(MonthCardType.BlackGold);
  133. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardBlackGoldEndTime);
  134. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldReward) > 0;
  135. for (int i = 0; i < MonthlyCardPrivilegeCfgArray.Instance.dataArray.Length; i++)
  136. {
  137. if (MonthlyCardPrivilegeCfgArray.Instance.dataArray[i].value2Arr[0] > 0)
  138. {
  139. privilegeCount++;
  140. }
  141. }
  142. _ui.m_txtDesc.SetVar("value", "福气卡").FlushVars();
  143. _ui.m_txtMoneyCount.text = privilegeCfg.value2Arr[0].ToString();
  144. _ui.m_txtDailyMoneyCount.text = privilegeCfg.value2Arr[1].ToString();
  145. _ui.m_btnBlackReward.visible = true;
  146. _ui.m_btnRule.data = 300011;
  147. break;
  148. }
  149. long day = TimeUtil.FormattingTime11(TimeHelper.ServerNow(), endTime);
  150. _ui.m_txtTime.SetVar("value", day.ToString()).FlushVars();
  151. _ui.m_txtTime.visible = endTime > TimeHelper.ServerNow();
  152. _ui.m_loaCard.url = iconUrl;
  153. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(monthCfg.shopId);
  154. if (shopCfg.onceShopId > 0)
  155. {
  156. //如果配置了首次购买物品,使用特殊id购买
  157. if (ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.onceShopId) <= 0)
  158. {
  159. shopCfg = ShopCfgArray.Instance.GetCfg(shopCfg.onceShopId);
  160. }
  161. }
  162. _ui.m_btnBuy.m_txtOriginalPrice.text = shopCfg.originalPrice.ToString();
  163. _ui.m_btnBuy.m_grpOriginalPrice.visible = shopCfg.Price < shopCfg.originalPrice;
  164. int price = shopCfg.Price;
  165. _ui.m_btnBuy.m_txtPrice.text = price.ToString();
  166. _ui.m_btnBuy.target.data = shopCfg.id;
  167. _ui.m_txtTips.SetVar("value", (price * 10).ToString()).FlushVars();
  168. _ui.m_txtTips.SetVar("day", monthCfg.limitDays.ToString()).FlushVars();
  169. _ui.m_loaMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[0]).res);
  170. _ui.m_loaDailyMoney.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(privilegeCfg.paramsArr[1]).res);
  171. _ui.m_txtPrivilegeCount.text = privilegeCount.ToString();
  172. _ui.m_txtTPrivilege.SetVar("value", privilegeCount.ToString()).FlushVars();
  173. _ui.m_btnGet.enabled = endTime > TimeHelper.ServerNow() && !isGot;
  174. _ui.m_btnGet.text = isGot ? "已领取" : "领取";
  175. _ui.m_btnGet.data = monthCfg.type; ;
  176. }
  177. private void OnBtnBuyCardClick(EventContext context)
  178. {
  179. GObject obj = context.sender as GObject;
  180. int goodsId = (int)obj.data;
  181. ShopSProxy.ReqShopBuy(goodsId).Coroutine();
  182. }
  183. private async void OnBtnGetClick(EventContext context)
  184. {
  185. GObject obj = context.sender as GObject;
  186. int goodsId = (int)obj.data;
  187. bool result = await ShopSProxy.ReqGetMonthCardReward(goodsId);
  188. if (result)
  189. {
  190. UpdateView();
  191. }
  192. }
  193. private void ListItemRenderer(int index, GObject obj)
  194. {
  195. ShopCfg shopCfg = _shopCfgs[index];
  196. ShopViewManager.Instance.UptadeItem(obj, shopCfg);
  197. }
  198. private async void OnClickBtnBuy(EventContext context)
  199. {
  200. GObject obj = context.sender as GObject;
  201. int index = (int)obj.data;
  202. ShopCfg itemData = _shopCfgs[index];
  203. if (!AntiAddictionController.CheckAntiAddictionRecharge(itemData.Price))
  204. {
  205. bool result = await ShopSProxy.ReqShopBuy(itemData.id, 1);
  206. if (result)
  207. {
  208. UpdateView();
  209. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  210. }
  211. }
  212. }
  213. private void UpdateRedDot()
  214. {
  215. RedDotController.Instance.SetComRedDot(_ui.m_btnGet, menu2 == ConstStoreSubId.STORE_MONTH_GOLD_CARD && RedDotDataManager.Instance.GetGoldCardRewardRed() || menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardRewardRed());
  216. RedDotController.Instance.SetComRedDot(_ui.m_btnBlackReward, menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardClothingRed(), "", -10, 5);
  217. }
  218. private void AddEffect()
  219. {
  220. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderfEff, "ui_Small_parts", "store_monthlycard");
  221. }
  222. private bool CheckIsBuyMonthCard()
  223. {
  224. long endTime1 = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardGoldEndTime);
  225. long endTime2 = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardBlackGoldEndTime);
  226. if (endTime1 > TimeHelper.ServerNow() || endTime2 > TimeHelper.ServerNow())
  227. {
  228. return true;
  229. }
  230. return false;
  231. }
  232. private void CheckGuide(object param)
  233. {
  234. if (GuideDataManager.IsGuideFinish(ConstGuideId.SHEZHI_ZHUJIEMBG) <= 0 && CheckIsBuyMonthCard())
  235. {
  236. UpdateCheckGuide(null);
  237. }
  238. else
  239. {
  240. Timers.inst.Remove(CheckGuide);
  241. }
  242. }
  243. protected void UpdateCheckGuide(object param)
  244. {
  245. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  246. GuideController.TryGuide(_ui.m_guideBackBtn, ConstGuideId.SHEZHI_ZHUJIEMBG, 1, "去开启背景更换特权");
  247. }
  248. }
  249. }