ShopViewManager.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.Store;
  6. namespace GFGGame
  7. {
  8. public class ShopViewManager : SingletonBase<ShopViewManager>
  9. {
  10. public void BuyItem(int itemId, int itemCount, int buyType, ShopCfg shopCfg)
  11. {
  12. BuyItemConteoller.Show(itemId, itemCount, buyType, () =>
  13. {
  14. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.FU_ZHUANG_DIAN, 2);
  15. GetSuitItemController.TryShow(0);
  16. }, true, false, GameConst.MAX_COUNT_TO_BUY_ITEMS);
  17. }
  18. //更行vip进度
  19. public void UpdateVipProgressCom(GObject obj)
  20. {
  21. UI_ComVipLv com = UI_ComVipLv.Proxy(obj);
  22. com.m_txtLv.text = RoleDataManager.vipLv.ToString();
  23. int level = RoleDataManager.vipLv;
  24. ET.Log.Debug("vipLv:" + level);
  25. ET.Log.Debug("vipExp:" + RoleDataManager.vipExp);
  26. VipCfg vipCfg = VipCfgArray.Instance.GetCfg(RoleDataManager.vipLv);
  27. if (vipCfg == null) return;
  28. VipCfg nextVipCfg = VipCfgArray.Instance.GetCfg(RoleDataManager.vipLv + 1);
  29. com.m_grpTips.visible = nextVipCfg != null;
  30. if (com.m_btnRule.data == null)
  31. {
  32. com.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  33. com.m_btnRule.data = 300009;
  34. }
  35. if (nextVipCfg != null)
  36. {
  37. com.m_proExp.target.max = vipCfg.num;
  38. com.m_proExp.target.value = RoleDataManager.vipExp;
  39. com.m_proExp.m_txttitle.SetVar("value", com.m_proExp.target.value.ToString()).FlushVars();
  40. com.m_proExp.m_txttitle.SetVar("max", com.m_proExp.target.max.ToString()).FlushVars();
  41. com.m_txtTips.SetVar("exp", (vipCfg.num - RoleDataManager.vipExp).ToString()).FlushVars();
  42. com.m_txtTips.SetVar("vipLv", (nextVipCfg.id).ToString()).FlushVars();
  43. }
  44. else
  45. {
  46. com.m_proExp.target.max = vipCfg.num;
  47. com.m_proExp.target.value = RoleDataManager.vipExp;
  48. com.m_proExp.m_txttitle.SetVar("value", com.m_proExp.target.value.ToString()).FlushVars();
  49. com.m_proExp.m_txttitle.SetVar("max", "MAX").FlushVars();
  50. }
  51. UI_ComVipLv.ProxyEnd();
  52. }
  53. private List<EffectUI> _effectUIs = new List<EffectUI>();
  54. //清除商品item的特效
  55. public void ClearItemEff()
  56. {
  57. for (int i = 0; i < _effectUIs.Count; i++)
  58. {
  59. EffectUIPool.Recycle(_effectUIs[i]);
  60. _effectUIs[i] = null;
  61. }
  62. _effectUIs.Clear();
  63. }
  64. //更新商品item
  65. public void UptadeItem(GObject obj, ShopCfg shopCfg)
  66. {
  67. UI_ListShopItem item = UI_ListShopItem.Proxy(obj);
  68. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  69. try
  70. {
  71. item.m_txtName.text = shopCfg.itemName;
  72. item.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  73. }
  74. catch (Exception e)
  75. {
  76. Console.WriteLine(e);
  77. throw;
  78. }
  79. item.m_grpDiscount.visible = shopCfg.Price < shopCfg.originalPrice;
  80. if (item.m_grpDiscount.visible)
  81. {
  82. EffectUI _effectUI = EffectUIPool.CreateEffectUI(item.m_holderfEff, "ui_Small_parts", "store_Value");
  83. _effectUIs.Add(_effectUI);
  84. item.m_holderfEff.visible = shopCfg.Price < shopCfg.originalPrice;
  85. }
  86. item.m_txtDesc.text = shopCfg.Price <= 0 ? "" : ShopDataManager.Instance.GetShopGoodsDiscount(shopCfg.id).ToString();
  87. item.m_txtEndTime.SetVar("value", ShopDataManager.Instance.GetEndTime(shopCfg.id)).FlushVars();
  88. item.m_txtEndTime.visible = shopCfg.endTime != "";
  89. item.m_c2.selectedIndex = ShopDataManager.Instance.GetShopGoodsStateById(shopCfg.id) ? 1 : 0;
  90. item.m_txtLock.text = ShopDataManager.Instance.GetShopGoodsStateTips(shopCfg.id);
  91. int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  92. item.m_txtLimit.visible = shopCfg.maxBuyNum > 0;
  93. item.m_txtLimit.text = string.Format("{0}({1}/{2})", ShopDataManager.Instance.refreshType[shopCfg.refreshType], StringUtil.GetColorText(buyNum.ToString(), "#5A3E16"), shopCfg.maxBuyNum);
  94. item.m_c1.selectedIndex = shopCfg.maxBuyNum == 0 || buyNum < shopCfg.maxBuyNum ? 0 : 1;
  95. if (item.m_c1.selectedIndex == 0)//可购买
  96. {
  97. item.m_btnBuy.m_txtOriginalPrice.text = NumberUtil.ChangeNumberUnit(shopCfg.originalPrice);
  98. if (shopCfg.Price > 0 && shopCfg.CostTypeReal != CostType.FREE)//不免费
  99. {
  100. item.m_btnBuy.m_grpOriginalPrice.visible = shopCfg.originalPrice > 0 && shopCfg.originalPrice != shopCfg.Price;
  101. item.m_btnBuy.m_loaIcon.visible = true;
  102. item.m_btnBuy.m_txtPrice.text = NumberUtil.ChangeNumberUnit(shopCfg.Price);// cfg.price.ToString();
  103. if (shopCfg.CostTypeReal == CostType.RMB)//人民币
  104. {
  105. item.m_btnBuy.m_loaIcon.visible = false;
  106. item.m_btnBuy.m_txtIcon.visible = true;
  107. item.m_btnBuy.m_txtIcon.text = "¥";
  108. }
  109. else//道具
  110. {
  111. ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.CostIdReal);
  112. item.m_btnBuy.m_loaIcon.url = ResPathUtil.GetIconPath(costItemCfg);
  113. item.m_btnBuy.m_loaIcon.visible = true;
  114. item.m_btnBuy.m_txtIcon.visible = false;
  115. }
  116. }
  117. else
  118. {
  119. item.m_btnBuy.m_txtIcon.text = "";
  120. item.m_btnBuy.m_loaIcon.visible = false;
  121. item.m_btnBuy.m_grpOriginalPrice.visible = false;
  122. item.m_btnBuy.m_txtPrice.text = "免费";
  123. }
  124. }
  125. if (item.target.data == null)
  126. {
  127. item.target.onClick.Add(OnBtnBugItem);
  128. }
  129. item.target.data = shopCfg;
  130. bool isRed = item.m_c1.selectedIndex == 0 && item.m_c2.selectedIndex == 0 && shopCfg.Price == 0;
  131. RedDotController.Instance.SetComRedDot(item.target, isRed, "", -6, 100);
  132. UI_ListShopItem.ProxyEnd();
  133. }
  134. public void OnBtnBugItem(EventContext context)
  135. {
  136. ShopCfg cfg = (context.sender as GObject).data as ShopCfg;
  137. bool isSellOut = cfg.maxBuyNum > 0 && cfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(cfg.id) <= 0;
  138. if (isSellOut)
  139. {
  140. PromptController.Instance.ShowFloatTextPrompt("已售罄");
  141. return;
  142. }
  143. // if (!ShopDataManager.Instance.GetShopGoodsStateById(cfg.id))
  144. // {
  145. // PromptController.Instance.ShowFloatTextPrompt(ShopDataManager.Instance.GetShopGoodsStateTips(cfg.id));
  146. // return;
  147. // }
  148. if (cfg.CostTypeReal == CostType.FREE)
  149. {
  150. ShopSProxy.ReqShopBuy(cfg.id, 1).Coroutine();
  151. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  152. }
  153. else
  154. {
  155. ViewManager.Show<ItemExchangeView>(cfg.id);
  156. }
  157. }
  158. }
  159. }