| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- using System;
- using System.Threading.Tasks;
- using cfg.GfgCfg;
- 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 = CommonDataManager.Tables.TblShopCfg.GetOrDefault(_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 = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_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.Tags.Count;
- _ui.m_txtType.visible = true;
- _ui.m_txtType.text = CommonDataManager.Tables.TblItemTypeCfg.GetOrDefault(itemCfg.SubType).Name;
- }
- _ui.m_comScaleList.m_listItem.numItems = itemCfg.Items.Count;
- _ui.m_comScaleList.m_listItem.visible = itemCfg.Items.Count > 0;
- _ui.m_grpComScaleList.visible = itemCfg.Items.Count > 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 = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_shopCfg.ItemId);
- UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
- ItemUtil.UpdateTag(item.m_comTag.target, itemCfg.Tags[index].Name);
- item.m_txtTagScore.text = itemCfg.Tags[index].Val.ToString();
- UI_ListTagItem.ProxyEnd();
- }
- private void ListItemRenderer(int index, GObject obj)
- {
- ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_shopCfg.ItemId);
- ItemData itemData = ItemUtil.createItemData(itemCfg.Items[index].ToGfgGameItemParam());
- 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 = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_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;
- if(_shopCfg.Menu1 == 5)
- {
- ItemCfg costItemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_shopCfg.Menu2 == 0 || _shopCfg.Menu2 == ArenaDataManager.Instance.SeasonId ? _shopCfg.CostIdReal : _shopCfg.OldSeasonCostId);
- ItemUtil.UpdateItemNeedNum(_ui.m_comCost.target, costItemCfg.Id, (int)_buyCount * _shopCfg.Price);
- }
- else
- {
- 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 = CommonDataManager.Tables.TblShopCfg.GetOrDefault(_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 = CommonDataManager.Tables.TblItemCfg.GetOrDefault(ConstItemID.ARENA_PAST_COST).Name;
- string curSeasonName = CommonDataManager.Tables.TblItemCfg.GetOrDefault(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();
- }
- }
- }
- }
|