ItemExchangeView.cs 10 KB

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