using System.Collections; using UnityEngine; using UI.CommonGame; using FairyGUI; using System.Collections.Generic; using System; namespace GFGGame { public class RewardView : BaseWindow { private UI_RewardUI _ui; private List _listItemDatas; private Action onSuccess = null; private List _effects = new List(); // private List _wrappers = new List(); private const int maxHeight = 1030; public override void Dispose() { base.Dispose(); } protected override void OnInit() { base.OnInit(); _ui = UI_RewardUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; _ui.m_comListReward.m_listReward.SetVirtual(); _ui.m_comListReward.m_listReward.itemRenderer = RenderListRewardItem; // _ui.m_comListReward.m_listReward.onClickItem.Add(OnClickListReward); _ui.m_bg.onClick.Add(this.Hide); } protected override void OnShown() { base.OnShown(); if ((this.viewData as object[]).Length > 0) { _listItemDatas = (this.viewData as object[])[0] as List; onSuccess = (this.viewData as object[])[1] as Action; } else { _listItemDatas = this.viewData as List; } _ui.m_comListReward.m_listReward.numItems = _listItemDatas.Count; _ui.m_comListReward.m_listReward.ResizeToFit(); if (_ui.m_comListReward.m_listReward.height > maxHeight) { _ui.m_comListReward.m_listReward.height = maxHeight; } } protected override void OnHide() { if (onSuccess != null) { onSuccess(); } base.OnHide(); _effects.Clear(); GetSuitItemController.TryShow(0); } private void RenderListRewardItem(int index, GObject obj) { // obj.data = _listItemDatas[index]; UI_ListRewardItem item = UI_ListRewardItem.Proxy(obj); string name = ""; string iconRes = ""; string ext = "png"; SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[index].id); ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listItemDatas[index].id); if (suitCfg != null) { name = suitCfg.name; iconRes = suitCfg.res; } else { name = itemCfg.name; ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType); iconRes = itemCfg.res; } item.m_comRewardItem.m_txtName.text = name; // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("x{0}", _listItemDatas[index].num); item.m_comRewardItem.m_txtCount.text = string.Format("x{0}", _listItemDatas[index].num); item.m_comRewardItem.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext); item.m_comRewardItem.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus; string resPath = ResPathUtil.GetViewEffectPath("ui_ck", "ui_ck_zl"); int childIndex = _ui.m_comListReward.m_listReward.ItemIndexToChildIndex(index); if (_effects.Count <= childIndex) { _effects.Add(item.m_effect); item.m_effect.SetPlaySettings(0, -1, 1, -1); } if (item.m_comRewardItem.target.data == null) { item.m_comRewardItem.target.onClick.Add(OnClickListReward); } item.m_comRewardItem.target.data = _listItemDatas[index]; } private void OnClickListReward(EventContext context) { if (this.ShowTips) { ItemData data = (context.sender as GObject).data as ItemData; GoodsItemTipsController.ShowItemTips(data.id); } } private bool _showTips = true; /// /// 是否展示物品详情,默认展示 /// private bool ShowTips { get { return _showTips; } set { _showTips = value; } } } }