using System; using System.Collections.Generic; using ET; using FairyGUI; using UI.Bag; using UnityEngine; using UI.CommonGame; namespace GFGGame { public class BagExchangeView : BaseWindow { private UI.Bag.UI_ItemExchangeUI _ui; private int _itemId; private long _count; private List _itemList = new List(); // private LongPressGesture _longPressAdd; // private LongPressGesture _longPressMinus; public override void Dispose() { base.Dispose(); if (_ui != null) { _ui.Dispose(); _ui = null; } } protected override void OnInit() { base.OnInit(); packageName = UI.Bag.UI_ItemExchangeUI.PACKAGE_NAME; _ui = UI.Bag.UI_ItemExchangeUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; _ui.m_btnAdd.onClick.Add(OnBtnAddClick); _ui.m_btnMinus.target.onClick.Add(OnBtnMinusClick); _ui.m_btnMax.target.onClick.Add(OnBtnMaxClick); _ui.m_btnConfirm.onClick.Add(OnBtnConfirmClick); _ui.m_btnCancle.onClick.Add(OnBtnCancleClick); _ui.m_listItem.itemRenderer = ListItemRenderer; _ui.m_comBg.GetChild("btnClose").asCom.onClick.Add(Hide); } protected override void AddEventListener() { base.AddEventListener(); } protected override void OnShown() { base.OnShown(); _itemId = (int)this.viewData; _count = 1; UpdateView(); UpdateUseView(); } protected override void OnHide() { base.OnHide(); } protected override void RemoveEventListener() { base.RemoveEventListener(); // EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateList); } private void UpdateView() { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId); _ui.m_comBg.GetChild("txtTitle").asTextField.text = itemCfg.name; _ui.m_txtOwned.SetVar("count", "" + ItemDataManager.GetItemNum(itemCfg.id)).FlushVars(); _ui.m_txtDesc.text = string.IsNullOrEmpty(itemCfg.desc) ? "暂无描述" : itemCfg.desc; _ui.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg); _ui.m_txtRmbCost.visible = false; UpdateThItemList(itemCfg); _ui.m_listItem.numItems = _itemList.Count; //itemCfg.itemsArr.Length; _ui.m_listItem.visible = itemCfg.itemType == ConstItemType.USEABLE && itemCfg.subType != ConstItemSubType.USEABLE_AUTO; } private void UpdateThItemList(ItemCfg itemCfg) { _itemList.Clear(); //普通物品 foreach (var t in itemCfg.itemsArr) { var itemId = t[0]; var itemNum = t.Length > 1 ? t[1] : 1; _itemList.Add(new[] { itemId, itemNum }); } if (itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_RANDOM) { if (itemCfg.param2Arr.Length > 0) { //特殊物品 不存在的套装部件id List noExistSuitItemIds = new List(); foreach (var suitId in itemCfg.param2Arr) { noExistSuitItemIds.Clear(); SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId); foreach (var suitItemId in suitCfg.partsArr) { if (!ItemUtil.CheckItemEnough(suitItemId, 1)) { noExistSuitItemIds.Add(suitItemId); } } foreach (var noExistSuitItemId in noExistSuitItemIds) { _itemList.Add(new[] { noExistSuitItemId, 1 }); } } } } //保底物品 if (itemCfg.param1Arr.Length > 0) { foreach (var t in itemCfg.param1Arr) { var itemId = t[0]; var itemNum = t.Length > 1 ? t[1] : 1; _itemList.Add(new[] { itemId, itemNum }); } } } private void UpdateUseView() { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId); _ui.m_txtCostCount.text = _count.ToString(); _ui.m_btnMinus.m_c1.selectedIndex = _count == 1 ? 1 : 0; _ui.m_btnMinus.target.touchable = _count == 1 ? false : true; long hasCount = ItemDataManager.GetItemNum(_itemId); _ui.m_btnAdd.GetController("c1").selectedIndex = _count == hasCount ? 1 : 0; _ui.m_btnAdd.touchable = _count == hasCount ? false : true; _ui.m_btnMax.m_c1.selectedIndex = _count == hasCount ? 1 : 0; _ui.m_btnMax.target.touchable = _count == hasCount ? false : true; _ui.m_txtExchangeCount.text = string.Format("{0}", hasCount); _ui.m_txtShow.text = "选择使用数量"; _ui.m_txtTips.text = string.Format("是否使用{0}个{1}?", _count, itemCfg.name); } private void ListItemRenderer(int index, GObject obj) { //ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId); ItemData itemData = ItemUtil.createItemData(_itemList[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 OnBtnAddClick() { _count++; long hasCount = ItemDataManager.GetItemNum(_itemId); _count = Math.Min(hasCount, _count); UpdateUseView(); } private void OnBtnMinusClick() { _count--; _count = Math.Max(1, _count); UpdateUseView(); } private void OnBtnMaxClick() { _count = ItemDataManager.GetItemNum(_itemId); UpdateUseView(); } private void OnBtnConfirmClick() { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId); if (itemCfg.itemType == ConstItemType.USEABLE && itemCfg.subType == ConstItemSubType.USEABLE_GIFT_BAG_RANDOM) { ItemProxy.ReqUseRandomItem(_itemId, _count).Coroutine(); } else { ItemProxy.ReqUseItem(_itemId, _count).Coroutine(); } this.Hide(); } private void OnBtnCancleClick() { this.Hide(); } } }