123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using System;
- using ET;
- using FairyGUI;
- using UI.CommonGame;
- namespace GFGGame
- {
- public class ItemExchangeView : BaseWindow
- {
- private UI_ItemExchangeUI _ui;
- private ShopCfg _shopCfg;
- private int _goodIds;
- private long _buyCount = 0;
- private long _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_ItemExchangeUI.PACKAGE_NAME;
- _ui = UI_ItemExchangeUI.Create();
- this.viewCom = _ui.target;
- this.viewCom.Center();
- this.modal = true;
- viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
- _ui.m_btnAdd.target.onClick.Add(OnBtnPlusClick);
- _ui.m_btnMinus.target.onClick.Add(OnBtnMinusClick);
- _ui.m_btnMax.target.onClick.Add(OnBtnAllClick);
- _ui.m_btnConfirm.onClick.Add(OnBtnExchangeClick);
- _ui.m_btnCancle.onClick.Add(this.Hide);
- _ui.m_listItem.itemRenderer = ListItemRenderer;
- }
- protected override void OnShown()
- {
- base.OnShown();
- _goodIds = (int)this.viewData;
- _shopCfg = ShopCfgArray.Instance.GetCfg(_goodIds);
- _buyCount = 1;
- if (_shopCfg.costType == CostType.RMB)
- {
- _maxCanBuy = 1;
- }
- else
- {
- long curMoneyCanBuy = ItemDataManager.GetItemNum(_shopCfg.costId) / _shopCfg.price;
- if (_shopCfg.maxBuyNum == 0)
- {
- _maxCanBuy = Math.Min(curMoneyCanBuy, GameConst.MAX_COUNT_TO_BUY_ITEMS);
- }
- else
- {
- int lastBuyCount = _shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(_shopCfg.id);//剩余购买次数
- _maxCanBuy = Math.Min(curMoneyCanBuy, lastBuyCount);
- }
- }
- _maxCanBuy = Math.Max(1, _maxCanBuy);
- _ui.m_txtExchangeCount.visible = true;
- _ui.m_comCost.target.visible = true;
- UpdateStaticView();
- UpdateView();
- }
- private void UpdateStaticView()
- {
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_shopCfg.itemId);
- _ui.m_txtName.text = itemCfg.name;
- _ui.m_txtDesc.text = string.IsNullOrEmpty(itemCfg.desc) ? "暂无描述" : itemCfg.desc;
- _ui.m_txtOwned.SetVar("count", ItemDataManager.GetItemNum(_shopCfg.itemId).ToString()).FlushVars();
- _ui.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
- _ui.m_loaRarity.visible = false;
- if (ItemUtilCS.IsDressUpItem(_shopCfg.itemId))
- {
- _ui.m_loaRarity.visible = true;
- RarityIconController.UpdateRarityIcon(_ui.m_loaRarity, _shopCfg.itemId, false);
- }
- _ui.m_listItem.numItems = itemCfg.itemsArr.Length;
- _ui.m_listItem.visible = itemCfg.itemsArr.Length > 0;
- }
- private void ListItemRenderer(int index, GObject obj)
- {
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_shopCfg.itemId);
- ItemData itemData = ItemUtil.createItemData(itemCfg.itemsArr[index]);
- if (obj.data == null)
- {
- obj.data = new ItemView(obj as GComponent);
- }
- (obj.data as ItemView).SetData(itemData);
- (obj.data as ItemView).ChangeTxtCountStyle();
- }
- private void UpdateView()
- {
- _ui.m_txtExchangeCount.text = string.Format("x{0}", _shopCfg.itemNum * _buyCount);
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_shopCfg.itemId);
- _ui.m_txtCostCount.text = _buyCount.ToString();
- _ui.m_btnMinus.m_c1.selectedIndex = _buyCount == 1 ? 1 : 0;
- _ui.m_btnMinus.target.touchable = _buyCount == 1 ? false : true;
- // int hasCount = ItemDataManager.GetItemNum(cfg.itemId);
- _ui.m_btnAdd.m_c1.selectedIndex = _shopCfg.costType == CostType.RMB || _buyCount == _maxCanBuy ? 1 : 0;
- _ui.m_btnAdd.target.touchable = _shopCfg.costType == CostType.RMB || _buyCount == _maxCanBuy ? false : true;
- _ui.m_btnMax.m_c1.selectedIndex = _shopCfg.costType == CostType.RMB || _buyCount == _maxCanBuy ? 1 : 0;
- _ui.m_btnMax.target.touchable = _shopCfg.costType == CostType.RMB || _buyCount == _maxCanBuy ? false : true;
- _ui.m_txtShow.text = "选择购买数量";
- _ui.m_txtTips.text = string.Format("确定购买{0}个{1}?", _buyCount, itemCfg.name);
- if (_shopCfg.costType == CostType.RMB)
- {
- _ui.m_comCost.target.visible = false;
- _ui.m_txtRmbCost.visible = true;
- _ui.m_txtRmbCost.text = string.Format("¥ {0}", _shopCfg.price);
- // _ui.m_txtRmbCost.SetVar("value", _shopCfg.price.ToString()).FlushVars();
- }
- else
- {
- _ui.m_comCost.target.visible = true;
- _ui.m_txtRmbCost.visible = false;
- ItemUtil.UpdateItemNeedNum(_ui.m_comCost.target, _shopCfg.costId, (int)_buyCount * _shopCfg.price);
- }
- }
- private void OnBtnPlusClick()
- {
- _buyCount++;
- _buyCount = Math.Min(_buyCount, _maxCanBuy);
- UpdateView();
- }
- private void OnBtnMinusClick()
- {
- // if (_buyCount == 1)
- // {
- // PromptController.Instance.ShowFloatTextPrompt("已经是最小数量了");
- // return;
- // }
- _buyCount--;
- _buyCount = Math.Max(1, _buyCount);
- UpdateView();
- }
- private void OnBtnAllClick()
- {
- _buyCount = Math.Max(1, _maxCanBuy);
- UpdateView();
- }
- private async void OnBtnExchangeClick()
- {
- ShopCfg cfg = ShopCfgArray.Instance.GetCfg(_goodIds);
- if (cfg.costType != CostType.RMB && ItemDataManager.GetItemNum(cfg.costId) < cfg.price)
- {
- PromptController.Instance.ShowFloatTextPrompt("道具不足");
- return;
- }
- bool result = await ShopSProxy.ReqShopBuy(_goodIds, _buyCount);
- if (result)
- {
- LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
- this.Hide();
- }
- }
- }
- }
|