|
@@ -0,0 +1,136 @@
|
|
|
+using System;
|
|
|
+using FairyGUI;
|
|
|
+using UI.RechargeStore;
|
|
|
+
|
|
|
+namespace GFGGame
|
|
|
+{
|
|
|
+ public class ItemExchangeView : BaseWindow
|
|
|
+ {
|
|
|
+ private UI_ItemExchangeUI _ui;
|
|
|
+ private int _exchangeId;
|
|
|
+ private int _buyCount = 0;
|
|
|
+ private int _maxCanBuy = 0;
|
|
|
+ public override void Dispose()
|
|
|
+ {
|
|
|
+
|
|
|
+ if (_ui != null)
|
|
|
+ {
|
|
|
+ _ui.Dispose();
|
|
|
+ }
|
|
|
+ _ui = null;
|
|
|
+ base.Dispose();
|
|
|
+ }
|
|
|
+ protected override void OnHide()
|
|
|
+ {
|
|
|
+ base.OnHide();
|
|
|
+
|
|
|
+ }
|
|
|
+ protected override void OnInit()
|
|
|
+ {
|
|
|
+ base.OnInit();
|
|
|
+ packageName = UI_GiftBagBuyUI.PACKAGE_NAME;
|
|
|
+ _ui = UI_ItemExchangeUI.Create();
|
|
|
+ this.viewCom = _ui.target;
|
|
|
+ this.viewCom.Center();
|
|
|
+ this.modal = true;
|
|
|
+ viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
|
|
|
+
|
|
|
+ _ui.m_btnPlus.onClick.Add(OnBtnPlusClick);
|
|
|
+ _ui.m_btnMinus.onClick.Add(OnBtnMinusClick);
|
|
|
+ _ui.m_btnAll.onClick.Add(OnBtnAllClick);
|
|
|
+ _ui.m_btnExchange.onClick.Add(OnBtnExchangeClick);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnShown()
|
|
|
+ {
|
|
|
+ base.OnShown();
|
|
|
+
|
|
|
+ _exchangeId = (int)this.viewData;
|
|
|
+ ShopExchangeCfg cfg = ShopExchangeCfgArray.Instance.GetCfg(_exchangeId);
|
|
|
+
|
|
|
+ _buyCount = 1;
|
|
|
+ if (cfg.maxLimit == 0)
|
|
|
+ {
|
|
|
+ _maxCanBuy = GameConst.MAX_COUNT_TO_BUY_ITEMS;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _maxCanBuy = Math.Min(ItemDataManager.GetItemNum(cfg.costId) / cfg.costNum, cfg.maxLimit - RechargeDataManager.Instance.GetExchangeBuyNumById(cfg.id));
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateStaticView();
|
|
|
+ UpdateView();
|
|
|
+ }
|
|
|
+ private void UpdateStaticView()
|
|
|
+ {
|
|
|
+ ShopExchangeCfg cfg = ShopExchangeCfgArray.Instance.GetCfg(_exchangeId);
|
|
|
+ ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.itemId);
|
|
|
+ _ui.m_txtName.text = itemCfg.name;
|
|
|
+ _ui.m_txtDiscribe.text = itemCfg.desc;
|
|
|
+ _ui.m_txtHasCount.text = string.Format("已拥有:{0}", StringUtil.GetColorText(ItemDataManager.GetItemNum(cfg.itemId).ToString(), "#BC8068"));
|
|
|
+ _ui.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
|
|
|
+ _ui.m_rarity.visible = false;
|
|
|
+ if (ItemUtilCS.IsDressUpItem(cfg.itemId))
|
|
|
+ {
|
|
|
+ _ui.m_rarity.visible = true;
|
|
|
+ RarityIconController.UpdateRarityIcon(_ui.m_rarity, cfg.itemId, false);
|
|
|
+ }
|
|
|
+ _ui.m_txtLastCount.text = string.Format("剩余:{0}", cfg.maxLimit - RechargeDataManager.Instance.GetExchangeBuyNumById(cfg.id));
|
|
|
+ if (cfg.maxLimit == 0) _ui.m_txtLastCount.text = "剩余:不限";
|
|
|
+
|
|
|
+ ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(cfg.costId);
|
|
|
+ _ui.m_iconPrice.url = ResPathUtil.GetCommonGameResPath(costItemCfg.res);
|
|
|
+
|
|
|
+ }
|
|
|
+ private void UpdateView()
|
|
|
+ {
|
|
|
+
|
|
|
+ _ui.m_btnAll.enabled = _buyCount < _maxCanBuy;
|
|
|
+ _ui.m_btnPlus.enabled = _buyCount < _maxCanBuy;
|
|
|
+
|
|
|
+ ShopExchangeCfg cfg = ShopExchangeCfgArray.Instance.GetCfg(_exchangeId);
|
|
|
+ _ui.m_txtNum.text = string.Format("x{0}", cfg.num * _buyCount);
|
|
|
+ _ui.m_txtCount.text = _buyCount.ToString();
|
|
|
+ _ui.m_txtPrice.text = (_buyCount * cfg.costNum).ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void OnBtnPlusClick()
|
|
|
+ {
|
|
|
+ _buyCount++;
|
|
|
+ UpdateView();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnBtnMinusClick()
|
|
|
+ {
|
|
|
+ if (_buyCount == 1)
|
|
|
+ {
|
|
|
+ PromptController.Instance.ShowFloatTextPrompt("已经是最小数量了");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _buyCount--;
|
|
|
+ UpdateView();
|
|
|
+ }
|
|
|
+ private void OnBtnAllClick()
|
|
|
+ {
|
|
|
+ _buyCount = _maxCanBuy;
|
|
|
+ UpdateView();
|
|
|
+ }
|
|
|
+ private async void OnBtnExchangeClick()
|
|
|
+ {
|
|
|
+ ShopExchangeCfg cfg = ShopExchangeCfgArray.Instance.GetCfg(_exchangeId);
|
|
|
+ if (ItemDataManager.GetItemNum(cfg.costId) < cfg.costNum)
|
|
|
+ {
|
|
|
+ PromptController.Instance.ShowFloatTextPrompt("道具不足");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ bool result = await RechargeSProxy.ReqExchangeShopItem(_exchangeId, _buyCount);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|