using FairyGUI; using System; using UI.CommonGame; using UI.PopWindow; namespace GFGGame { public class ExchangeGoodsView : BaseWindow { private UI_ExchangeGoodsUI _ui; private int _skillId = 0; private long _nowCount = 0; //当前选择的数量 private long _maxCount = 0; //可选择的最大数量 public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_ExchangeGoodsUI.PACKAGE_NAME; _ui = UI_ExchangeGoodsUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; viewAnimationType = EnumViewAnimationType.ZOOM_CENTER; _ui.m_listConsume.itemRenderer = RenderListConsumeItem; _ui.m_btnCancel.onClick.Add(OnBtnCancelClick); _ui.m_btnUse.onClick.Add(OnBtnUseClick); _ui.m_btnReduce.onClick.Add(OnClickBtnReduce); _ui.m_btnAdd.onClick.Add(OnClickBtnAdd); _ui.m_btnAllChoose.onClick.Add(OnClickAllChoose); _ui.m_slideUpLevel.onChanged.Add(OnChangeUpLevel); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItem); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItem); } protected override void OnShown() { base.OnShown(); _skillId = (int)this.viewData; _ui.m_slideUpLevel.visible = false; ItemExchangeCfg itemCfg = ItemExchangeCfgArray.Instance.GetCfg(_skillId); getMaxCount(); _ui.m_listConsume.data = itemCfg.costId; UpdateItem(); } private void RenderListConsumeItem(int index, GObject obj) { var itemSkill = (int[][])obj.parent.data; UI_ComItem item = UI_ComItem.Proxy(obj); ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemSkill[index][0]); RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false); string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true); item.m_CountType.selectedIndex = 1; item.m_txtDecomCount.text = ItemDataManager.GetItemNum(itemCfg.id).ToString(); item.m_txtDecomHasCount.text = "/" + (itemSkill[index][1]*_nowCount).ToString(); item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext); item.m_QualityType.selectedIndex = itemCfg.rarity - 1; if (item.target.data == null) item.target.onClick.Add(() => { GoodsItemTipsController.ShowItemTips(itemSkill[index][0]); }); item.target.data = index; UI_ComItem.ProxyEnd(); } protected override void OnHide() { base.OnHide(); } private void getMaxCount() { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_skillId); foreach (var info in itemCfg.param1Arr) { long cout = ItemDataManager.GetItemNum(info[0]) / info[1]; if (_maxCount == 0 || _maxCount > cout) _maxCount = cout; } } private void OnBtnCancelClick() { ViewManager.GoBackFrom(typeof(ExchangeGoodsView).FullName); } private async void OnBtnUseClick() { //兑换物品 await ItemExchangeSProxy.ItemExchange(_skillId, _nowCount); } private void OnClickAllChoose() { _nowCount = _maxCount; ReferViewInfo(); ReferSlide(); } private void OnClickBtnAdd() { _nowCount += 1; if (_nowCount > _maxCount) _nowCount = _maxCount; ReferViewInfo(); ReferSlide(); } private void OnClickBtnReduce() { _nowCount -= 1; if (_nowCount < 0) _nowCount = 0; ReferViewInfo(); ReferSlide(); } private void OnChangeUpLevel() { float volumn = (float)_ui.m_slideUpLevel.value / 100; _nowCount = (int)(volumn * _maxCount); ReferViewInfo(); } private void ReferViewInfo() { _ui.m_txtChooseLevel.text = _nowCount.ToString(); } private void ReferSlide() { _ui.m_slideUpLevel.value = (float)_nowCount / _maxCount * 100; UpdateItem(); } private void UpdateItem() { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_skillId); UI_ComItem item = UI_ComItem.Proxy(_ui.m_itemSkill); RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false); string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true); item.m_ShowName.selectedIndex = 2; long hasNum = ItemDataManager.GetItemNum(itemCfg.id); item.m_txtCount.text = hasNum.ToString(); item.m_txtName.text = itemCfg.name; item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg.res, ext); item.m_QualityType.selectedIndex = itemCfg.rarity - 1; UI_ComItem.ProxyEnd(); _ui.m_txtHasNum.text = "已拥有:" + hasNum; _ui.m_listConsume.numItems = itemCfg.param1Arr.Length; } } }