ItemExchangeView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using System;
  2. using System.Threading.Tasks;
  3. using cfg.GfgCfg;
  4. using ET;
  5. using FairyGUI;
  6. using UI.CommonGame;
  7. namespace GFGGame
  8. {
  9. public class ItemExchangeView : BaseWindow
  10. {
  11. private UI_ItemExchangeUI _ui;
  12. private ShopCfg _shopCfg;
  13. private int _goodIds;
  14. private long _buyCount = 0;
  15. private long _maxCanBuy = 0;
  16. public override void Dispose()
  17. {
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. }
  22. _ui = null;
  23. base.Dispose();
  24. }
  25. protected override void OnHide()
  26. {
  27. base.OnHide();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. packageName = UI_ItemExchangeUI.PACKAGE_NAME;
  33. _ui = UI_ItemExchangeUI.Create();
  34. this.viewCom = _ui.target;
  35. this.viewCom.Center();
  36. this.modal = true;
  37. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  38. _ui.m_btnAdd.target.onClick.Add(OnBtnPlusClick);
  39. _ui.m_btnMinus.target.onClick.Add(OnBtnMinusClick);
  40. _ui.m_btnMax.target.onClick.Add(OnBtnAllClick);
  41. _ui.m_btnConfirm.onClick.Add(OnBtnExchangeClick);
  42. _ui.m_btnCancle.onClick.Add(Hide);
  43. _ui.m_comBg.m_btnClose.onClick.Add(Hide);
  44. _ui.m_comScaleList.m_listItem.itemRenderer = ListItemRenderer;
  45. _ui.m_listTag.itemRenderer = RenderListTagItem;
  46. }
  47. protected override void OnShown()
  48. {
  49. base.OnShown();
  50. _goodIds = (int)this.viewData;
  51. _shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(_goodIds);
  52. _buyCount = 1;
  53. if (_shopCfg.CostTypeReal == CostType.RMB)
  54. {
  55. _maxCanBuy = 1;
  56. }
  57. else
  58. {
  59. long itemCount = ItemDataManager.GetItemNum(_shopCfg.CostIdReal);
  60. long curMoneyCanBuy = itemCount / _shopCfg.Price;
  61. if (_shopCfg.Menu1 == ConstStoreTabId.STORE_ARENA)
  62. {
  63. itemCount = ItemDataManager.GetItemNum(ConstItemID.ARENA_CUR_COST);
  64. long itemCountOther = ItemDataManager.GetItemNum(ConstItemID.ARENA_PAST_COST);
  65. curMoneyCanBuy = (itemCount + itemCountOther) / _shopCfg.Price;
  66. }
  67. if (_shopCfg.MaxBuyNum == 0)
  68. {
  69. _maxCanBuy = Math.Min(curMoneyCanBuy, GameConst.MAX_COUNT_TO_BUY_ITEMS);
  70. }
  71. else
  72. {
  73. int lastBuyCount = _shopCfg.MaxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(_shopCfg.Id);//剩余购买次数
  74. _maxCanBuy = Math.Min(curMoneyCanBuy, lastBuyCount);
  75. }
  76. }
  77. _maxCanBuy = Math.Max(1, _maxCanBuy);
  78. _ui.m_txtExchangeCount.visible = true;
  79. _ui.m_comCost.target.visible = true;
  80. UpdateStaticView();
  81. UpdateView();
  82. }
  83. private void UpdateStaticView()
  84. {
  85. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_shopCfg.ItemId);
  86. _ui.m_comBg.m_txtTitle.text = _shopCfg.ItemName;
  87. _ui.m_txtDesc.text = string.IsNullOrEmpty(itemCfg.Desc) ? "暂无描述" : itemCfg.Desc;
  88. _ui.m_txtOwned.SetVar("count", ItemDataManager.GetItemNum(_shopCfg.ItemId).ToString()).FlushVars();
  89. _ui.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  90. _ui.m_loaRarity.visible = false;
  91. _ui.m_listTag.visible = false;
  92. _ui.m_grpScore.visible = false;
  93. _ui.m_txtType.visible = false;
  94. if (ItemUtilCS.IsDressUpItem(_shopCfg.ItemId))
  95. {
  96. _ui.m_loaRarity.visible = true;
  97. RarityIconController.UpdateRarityIcon(_ui.m_loaRarity, _shopCfg.ItemId, false);
  98. _ui.m_grpScore.visible = true;
  99. _ui.m_txtGong.text = "" + itemCfg.Score1;
  100. _ui.m_txtShang.text = "" + itemCfg.Score2;
  101. _ui.m_txtJue.text = "" + itemCfg.Score3;
  102. _ui.m_txtZhi.text = "" + itemCfg.Score4;
  103. _ui.m_listTag.visible = true;
  104. _ui.m_listTag.numItems = itemCfg.Tags.Count;
  105. _ui.m_txtType.visible = true;
  106. _ui.m_txtType.text = CommonDataManager.Tables.TblItemTypeCfg.GetOrDefault(itemCfg.SubType).Name;
  107. }
  108. _ui.m_comScaleList.m_listItem.numItems = itemCfg.Items.Count;
  109. _ui.m_comScaleList.m_listItem.visible = itemCfg.Items.Count > 0;
  110. _ui.m_grpComScaleList.visible = itemCfg.Items.Count > 0;
  111. bool isUnLock = ShopDataManager.Instance.GetShopGoodsStateById(_shopCfg.Id);
  112. _ui.m_grpBtn.visible = isUnLock;
  113. _ui.m_grpLock.visible = !isUnLock;
  114. if (!isUnLock)
  115. {
  116. _ui.m_txtLock.text = ShopDataManager.Instance.GetShopGoodsStateTips(_shopCfg.Id);
  117. }
  118. }
  119. private void RenderListTagItem(int index, GObject obj)
  120. {
  121. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_shopCfg.ItemId);
  122. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  123. ItemUtil.UpdateTag(item.m_comTag.target, itemCfg.Tags[index].Name);
  124. item.m_txtTagScore.text = itemCfg.Tags[index].Val.ToString();
  125. UI_ListTagItem.ProxyEnd();
  126. }
  127. private void ListItemRenderer(int index, GObject obj)
  128. {
  129. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_shopCfg.ItemId);
  130. ItemData itemData = ItemUtil.createItemData(itemCfg.Items[index].ToGfgGameItemParam());
  131. if (obj.data == null)
  132. {
  133. obj.data = new ItemView(obj as GComponent);
  134. }
  135. (obj.data as ItemView).SetData(itemData);
  136. (obj.data as ItemView).ChangeTxtCountStyle();
  137. }
  138. private void UpdateView()
  139. {
  140. _ui.m_txtExchangeCount.text = string.Format("{0}", _shopCfg.ItemNum * _buyCount);
  141. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_shopCfg.ItemId);
  142. _ui.m_txtCostCount.text = _buyCount.ToString();
  143. _ui.m_btnMinus.m_c1.selectedIndex = _buyCount == 1 ? 1 : 0;
  144. _ui.m_btnMinus.target.touchable = _buyCount == 1 ? false : true;
  145. // int hasCount = ItemDataManager.GetItemNum(cfg.itemId);
  146. _ui.m_btnAdd.m_c1.selectedIndex = _shopCfg.CostTypeReal == CostType.RMB || _buyCount == _maxCanBuy ? 1 : 0;
  147. _ui.m_btnAdd.target.touchable = _shopCfg.CostTypeReal == CostType.RMB || _buyCount == _maxCanBuy ? false : true;
  148. _ui.m_btnMax.m_c1.selectedIndex = _shopCfg.CostTypeReal == CostType.RMB || _buyCount == _maxCanBuy ? 1 : 0;
  149. _ui.m_btnMax.target.touchable = _shopCfg.CostTypeReal == CostType.RMB || _buyCount == _maxCanBuy ? false : true;
  150. _ui.m_txtShow.text = "选择购买数量";
  151. _ui.m_txtTips.text = string.Format("确定购买{0}个【{1}】?", _buyCount, _shopCfg.ItemName);
  152. if (_shopCfg.CostTypeReal == CostType.RMB)
  153. {
  154. _ui.m_comCost.target.visible = false;
  155. _ui.m_txtRmbCost.visible = true;
  156. _ui.m_txtRmbCost.text = string.Format("¥ {0}", _shopCfg.Price);
  157. // _ui.m_txtRmbCost.SetVar("value", _shopCfg.price.ToString()).FlushVars();
  158. }
  159. else
  160. {
  161. _ui.m_comCost.target.visible = true;
  162. _ui.m_txtRmbCost.visible = false;
  163. if(_shopCfg.Menu1 == 5)
  164. {
  165. ItemCfg costItemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_shopCfg.Menu2 == 0 || _shopCfg.Menu2 == ArenaDataManager.Instance.SeasonId ? _shopCfg.CostIdReal : _shopCfg.OldSeasonCostId);
  166. ItemUtil.UpdateItemNeedNum(_ui.m_comCost.target, costItemCfg.Id, (int)_buyCount * _shopCfg.Price);
  167. }
  168. else
  169. {
  170. ItemUtil.UpdateItemNeedNum(_ui.m_comCost.target, _shopCfg.CostIdReal, (int)_buyCount * _shopCfg.Price);
  171. }
  172. }
  173. }
  174. private void OnBtnPlusClick()
  175. {
  176. _buyCount++;
  177. _buyCount = Math.Min(_buyCount, _maxCanBuy);
  178. UpdateView();
  179. }
  180. private void OnBtnMinusClick()
  181. {
  182. // if (_buyCount == 1)
  183. // {
  184. // PromptController.Instance.ShowFloatTextPrompt("已经是最小数量了");
  185. // return;
  186. // }
  187. _buyCount--;
  188. _buyCount = Math.Max(1, _buyCount);
  189. UpdateView();
  190. }
  191. private void OnBtnAllClick()
  192. {
  193. _buyCount = Math.Max(1, _maxCanBuy);
  194. UpdateView();
  195. }
  196. private void OnBtnExchangeClick()
  197. {
  198. ShopCfg cfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(_goodIds);
  199. if (cfg.CostTypeReal != CostType.RMB)
  200. {
  201. int costId = cfg.CostIdReal;
  202. if (cfg.Menu1 == ConstStoreTabId.STORE_ARENA && cfg.Menu2 != ArenaDataManager.Instance.SeasonId && cfg.Menu2 != ConstStoreSubId.STORE_ARENA_ITEM)
  203. {
  204. costId = cfg.OldSeasonCostId;
  205. }
  206. if (costId == ConstItemID.ARENA_PAST_COST && ItemDataManager.GetItemNum(costId) < cfg.Price
  207. && ItemDataManager.GetItemNum(costId) + ItemDataManager.GetItemNum(ConstItemID.ARENA_CUR_COST) >= cfg.Price)
  208. {
  209. string oldSeasonName = CommonDataManager.Tables.TblItemCfg.GetOrDefault(ConstItemID.ARENA_PAST_COST).Name;
  210. string curSeasonName = CommonDataManager.Tables.TblItemCfg.GetOrDefault(ConstItemID.ARENA_CUR_COST).Name;
  211. string strTips = string.Format("{0}不足,是否确定将{1}1:1转化为花签够买该商品?", oldSeasonName, curSeasonName);
  212. AlertUI.Show(strTips, "")
  213. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  214. {
  215. ReqBuyGoodsAsync(_goodIds);
  216. });
  217. return;
  218. }
  219. else if (ItemDataManager.GetItemNum(costId) < cfg.Price)
  220. {
  221. PromptController.Instance.ShowFloatTextPrompt("道具不足");
  222. return;
  223. }
  224. }
  225. ReqBuyGoodsAsync(_goodIds);
  226. }
  227. private async void ReqBuyGoodsAsync(int _goodIds)
  228. {
  229. bool result = await ShopSProxy.ReqShopBuy(_goodIds, _buyCount);
  230. if (result)
  231. {
  232. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  233. this.Hide();
  234. }
  235. }
  236. }
  237. }