123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- using System;
- using System.Threading.Tasks;
- 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(Hide);
- _ui.m_comBg.m_btnClose.onClick.Add(Hide);
- _ui.m_comScaleList.m_listItem.itemRenderer = ListItemRenderer;
- _ui.m_listTag.itemRenderer = RenderListTagItem;
- }
- protected override void OnShown()
- {
- base.OnShown();
- _goodIds = (int)this.viewData;
- _shopCfg = ShopCfgArray.Instance.GetCfg(_goodIds);
- _buyCount = 1;
- if (_shopCfg.CostTypeReal == CostType.RMB)
- {
- _maxCanBuy = 1;
- }
- else
- {
- long itemCount = ItemDataManager.GetItemNum(_shopCfg.CostIdReal);
- long curMoneyCanBuy = itemCount / _shopCfg.Price;
- if (_shopCfg.menu1 == ConstStoreTabId.STORE_ARENA)
- {
- itemCount = ItemDataManager.GetItemNum(ConstItemID.ARENA_CUR_COST);
- long itemCountOther = ItemDataManager.GetItemNum(ConstItemID.ARENA_PAST_COST);
- curMoneyCanBuy = (itemCount + itemCountOther) / _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_comBg.m_txtTitle.text = _shopCfg.itemName;
- _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;
- _ui.m_listTag.visible = false;
- _ui.m_grpScore.visible = false;
- _ui.m_txtType.visible = false;
- if (ItemUtilCS.IsDressUpItem(_shopCfg.itemId))
- {
- _ui.m_loaRarity.visible = true;
- RarityIconController.UpdateRarityIcon(_ui.m_loaRarity, _shopCfg.itemId, false);
- _ui.m_grpScore.visible = true;
- _ui.m_txtGong.text = "" + itemCfg.score1;
- _ui.m_txtShang.text = "" + itemCfg.score2;
- _ui.m_txtJue.text = "" + itemCfg.score3;
- _ui.m_txtZhi.text = "" + itemCfg.score4;
- _ui.m_listTag.visible = true;
- _ui.m_listTag.numItems = itemCfg.tagsArr.Length;
- _ui.m_txtType.visible = true;
- _ui.m_txtType.text = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType).name;
- }
- _ui.m_comScaleList.m_listItem.numItems = itemCfg.itemsArr.Length;
- _ui.m_comScaleList.m_listItem.visible = itemCfg.itemsArr.Length > 0;
- _ui.m_grpComScaleList.visible = itemCfg.itemsArr.Length > 0;
- bool isUnLock = ShopDataManager.Instance.GetShopGoodsStateById(_shopCfg.id);
- _ui.m_grpBtn.visible = isUnLock;
- _ui.m_grpLock.visible = !isUnLock;
- if (!isUnLock)
- {
- _ui.m_txtLock.text = ShopDataManager.Instance.GetShopGoodsStateTips(_shopCfg.id);
- }
- }
- private void RenderListTagItem(int index, GObject obj)
- {
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_shopCfg.itemId);
- UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
- ItemUtil.UpdateTag(item.m_comTag.target, itemCfg.tagsArr[index][0]);
- item.m_txtTagScore.text = itemCfg.tagsArr[index][1].ToString();
- UI_ListTagItem.ProxyEnd();
- }
- 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("{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.CostTypeReal == CostType.RMB || _buyCount == _maxCanBuy ? 1 : 0;
- _ui.m_btnAdd.target.touchable = _shopCfg.CostTypeReal == CostType.RMB || _buyCount == _maxCanBuy ? false : true;
- _ui.m_btnMax.m_c1.selectedIndex = _shopCfg.CostTypeReal == CostType.RMB || _buyCount == _maxCanBuy ? 1 : 0;
- _ui.m_btnMax.target.touchable = _shopCfg.CostTypeReal == CostType.RMB || _buyCount == _maxCanBuy ? false : true;
- _ui.m_txtShow.text = "选择购买数量";
- _ui.m_txtTips.text = string.Format("确定购买{0}个【{1}】?", _buyCount, _shopCfg.itemName);
- if (_shopCfg.CostTypeReal == 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.CostIdReal, (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 void OnBtnExchangeClick()
- {
- ShopCfg cfg = ShopCfgArray.Instance.GetCfg(_goodIds);
- if (cfg.CostTypeReal != CostType.RMB)
- {
- int costId = cfg.CostIdReal;
- if (cfg.menu1 == ConstStoreTabId.STORE_ARENA && cfg.menu2 != ArenaDataManager.Instance.SeasonId && cfg.menu2 != ConstStoreSubId.STORE_ARENA_ITEM)
- {
- costId = cfg.oldSeasonCostId;
- }
- if (costId == ConstItemID.ARENA_PAST_COST && ItemDataManager.GetItemNum(costId) < cfg.Price
- && ItemDataManager.GetItemNum(costId) + ItemDataManager.GetItemNum(ConstItemID.ARENA_CUR_COST) >= cfg.Price)
- {
- string oldSeasonName = ItemCfgArray.Instance.GetCfg(ConstItemID.ARENA_PAST_COST).name;
- string curSeasonName = ItemCfgArray.Instance.GetCfg(ConstItemID.ARENA_CUR_COST).name;
- string strTips = string.Format("{0}不足,是否确定将{1}1:1转化为花签够买该商品?", oldSeasonName, curSeasonName);
- AlertUI.Show(strTips, "")
- .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
- {
- ReqBuyGoodsAsync(_goodIds);
- });
- return;
- }
- else if (ItemDataManager.GetItemNum(costId) < cfg.Price)
- {
- PromptController.Instance.ShowFloatTextPrompt("道具不足");
- return;
- }
- }
- ReqBuyGoodsAsync(_goodIds);
- }
- private async void ReqBuyGoodsAsync(int _goodIds)
- {
- bool result = await ShopSProxy.ReqShopBuy(_goodIds, _buyCount);
- if (result)
- {
- LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
- this.Hide();
- }
- }
- }
- }
|