ShopViewManager.cs 8.2 KB

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