StoreMonthView.cs 11 KB

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