StoreMonthView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using UI.Store;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. using ET;
  6. using System;
  7. using cfg.GfgCfg;
  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 = CommonDataManager.Tables.TblShopCfg.GetGroup1ByMenu1AndMenu2(ConstStoreTabId.STORE_MONTH_CARD, menu2);
  92. _shopCfgs = ShopDataManager.Instance.RemoveNotOpenCfg(_shopCfgs);
  93. _shopCfgs = ShopDataManager.Instance.SortShopGoodsCfgs(_shopCfgs);
  94. _ui.m_storeMonthList.m_list.numItems = _shopCfgs.Count;
  95. MonthlyCardPrivilegeCfg privilegeCfg = CommonDataManager.Tables.TblMonthlyCardPrivilegeCfg.GetOrDefault(MonthCardPrivilegeType.Privilege1);
  96. string iconUrl = "";
  97. bool isGot = false;
  98. long endTime = 0;
  99. int privilegeCount = 0;
  100. MonthlyCardCfg monthCfg = null;
  101. switch (menu2)
  102. {
  103. case ConstStoreSubId.STORE_MONTH_GOLD_CARD:
  104. iconUrl = "ui://Store/hongbao_card_icon";
  105. monthCfg = CommonDataManager.Tables.TblMonthlyCardCfg.GetOrDefault(MonthCardType.Gold);
  106. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardGoldEndTime);
  107. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardGoldReward) > 0;
  108. for (int i = 0; i < CommonDataManager.Tables.TblMonthlyCardPrivilegeCfg.DataList.Count; i++)
  109. {
  110. if (CommonDataManager.Tables.TblMonthlyCardPrivilegeCfg.DataList[i].Value1[0] > 0)
  111. {
  112. privilegeCount++;
  113. }
  114. }
  115. _ui.m_txtDesc.SetVar("value", "红包卡").FlushVars();
  116. _ui.m_txtMoneyCount.text = privilegeCfg.Value1[0].ToString();
  117. _ui.m_txtDailyMoneyCount.text = privilegeCfg.Value1[1].ToString();
  118. _ui.m_btnBlackReward.visible = false;
  119. _ui.m_btnRule.data = 300010;
  120. break;
  121. case ConstStoreSubId.STORE_MONTH_BLACK_CARD:
  122. iconUrl = "ui://Store/fuqi_card_icon";
  123. monthCfg = CommonDataManager.Tables.TblMonthlyCardCfg.GetOrDefault(MonthCardType.BlackGold);
  124. endTime = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardBlackGoldEndTime);
  125. isGot = GameGlobal.myNumericComponent.GetAsInt(NumericType.MonthCardBlackGoldReward) > 0;
  126. for (int i = 0; i < CommonDataManager.Tables.TblMonthlyCardPrivilegeCfg.DataList.Count; i++)
  127. {
  128. if (CommonDataManager.Tables.TblMonthlyCardPrivilegeCfg.DataList[i].Value2[0] > 0)
  129. {
  130. privilegeCount++;
  131. }
  132. }
  133. _ui.m_txtDesc.SetVar("value", "福气卡").FlushVars();
  134. _ui.m_txtMoneyCount.text = privilegeCfg.Value2[0].ToString();
  135. _ui.m_txtDailyMoneyCount.text = privilegeCfg.Value2[1].ToString();
  136. _ui.m_btnBlackReward.visible = true;
  137. _ui.m_btnRule.data = 300011;
  138. break;
  139. }
  140. long day = TimeUtil.FormattingTime11(TimeHelper.ServerNow(), endTime);
  141. _ui.m_txtTime.SetVar("value", day.ToString()).FlushVars();
  142. _ui.m_txtTime.visible = endTime > TimeHelper.ServerNow();
  143. _ui.m_loaCard.url = iconUrl;
  144. ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(monthCfg.ShopId);
  145. if (shopCfg.OnceShopId > 0)
  146. {
  147. //如果配置了首次购买物品,使用特殊id购买
  148. if (ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.OnceShopId) <= 0)
  149. {
  150. shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(shopCfg.OnceShopId);
  151. }
  152. }
  153. _ui.m_btnBuy.m_txtOriginalPrice.text = shopCfg.OriginalPrice.ToString();
  154. _ui.m_btnBuy.m_grpOriginalPrice.visible = shopCfg.Price < shopCfg.OriginalPrice;
  155. int price = shopCfg.Price;
  156. _ui.m_btnBuy.m_txtPrice.text = price.ToString();
  157. _ui.m_btnBuy.target.data = shopCfg.Id;
  158. _ui.m_txtTips.SetVar("value", (price * 10).ToString()).FlushVars();
  159. _ui.m_txtTips.SetVar("day", monthCfg.LimitDays.ToString()).FlushVars();
  160. _ui.m_loaMoney.url = ResPathUtil.GetCommonGameResPath(CommonDataManager.Tables.TblItemCfg.GetOrDefault(privilegeCfg.Params1[0]).Res);
  161. _ui.m_loaDailyMoney.url = ResPathUtil.GetCommonGameResPath(CommonDataManager.Tables.TblItemCfg.GetOrDefault(privilegeCfg.Params1[1]).Res);
  162. _ui.m_txtPrivilegeCount.text = privilegeCount.ToString();
  163. _ui.m_txtTPrivilege.SetVar("value", privilegeCount.ToString()).FlushVars();
  164. _ui.m_btnGet.enabled = endTime > TimeHelper.ServerNow() && !isGot;
  165. _ui.m_btnGet.text = isGot ? "已领取" : "领取";
  166. _ui.m_btnGet.data = monthCfg.Type; ;
  167. }
  168. private void OnBtnBuyCardClick(EventContext context)
  169. {
  170. GObject obj = context.sender as GObject;
  171. int goodsId = (int)obj.data;
  172. ShopSProxy.ReqShopBuy(goodsId).Coroutine();
  173. }
  174. private async void OnBtnGetClick(EventContext context)
  175. {
  176. GObject obj = context.sender as GObject;
  177. int goodsId = (int)obj.data;
  178. bool result = await ShopSProxy.ReqGetMonthCardReward(goodsId);
  179. if (result)
  180. {
  181. UpdateView();
  182. }
  183. }
  184. private void ListItemRenderer(int index, GObject obj)
  185. {
  186. ShopCfg shopCfg = _shopCfgs[index];
  187. ShopViewManager.Instance.UptadeItem(obj, shopCfg);
  188. }
  189. private async void OnClickBtnBuy(EventContext context)
  190. {
  191. GObject obj = context.sender as GObject;
  192. int index = (int)obj.data;
  193. ShopCfg itemData = _shopCfgs[index];
  194. if (!AntiAddictionController.CheckAntiAddictionRecharge(itemData.Price))
  195. {
  196. bool result = await ShopSProxy.ReqShopBuy(itemData.Id, 1);
  197. if (result)
  198. {
  199. UpdateView();
  200. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  201. }
  202. }
  203. }
  204. private void UpdateRedDot()
  205. {
  206. RedDotController.Instance.SetComRedDot(_ui.m_btnGet, menu2 == ConstStoreSubId.STORE_MONTH_GOLD_CARD && RedDotDataManager.Instance.GetGoldCardRewardRed() || menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardRewardRed());
  207. RedDotController.Instance.SetComRedDot(_ui.m_btnBlackReward, menu2 == ConstStoreSubId.STORE_MONTH_BLACK_CARD && RedDotDataManager.Instance.GetBlackCardClothingRed(), "", -10, 5);
  208. }
  209. private void AddEffect()
  210. {
  211. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderfEff, "ui_Small_parts", "store_monthlycard");
  212. }
  213. private bool CheckIsBuyMonthCard()
  214. {
  215. long endTime1 = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardGoldEndTime);
  216. long endTime2 = GameGlobal.myNumericComponent.GetAsLong(NumericType.MonthCardBlackGoldEndTime);
  217. if (endTime1 > TimeHelper.ServerNow() || endTime2 > TimeHelper.ServerNow())
  218. {
  219. return true;
  220. }
  221. return false;
  222. }
  223. private void CheckGuide(object param)
  224. {
  225. if (GuideDataManager.IsGuideFinish(ConstGuideId.SHEZHI_ZHUJIEMBG) <= 0 && CheckIsBuyMonthCard())
  226. {
  227. UpdateCheckGuide(null);
  228. }
  229. else
  230. {
  231. Timers.inst.Remove(CheckGuide);
  232. }
  233. }
  234. protected void UpdateCheckGuide(object param)
  235. {
  236. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  237. GuideController.TryGuide(_ui.m_guideBackBtn, ConstGuideId.SHEZHI_ZHUJIEMBG, 1, "去开启背景更换特权");
  238. }
  239. }
  240. }