123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- 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<ItemData> _listItemDatas;
- private Action onSuccess = null;
- private List<GMovieClip> _effects = new List<GMovieClip>();
- // private List<GoWrapper> _wrappers = new List<GoWrapper>();
- private const int maxHeight = 1030;
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- 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_loaBg.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<ItemData>;
- onSuccess = (this.viewData as object[])[1] as Action;
- }
- else
- {
- _listItemDatas = this.viewData as List<ItemData>;
- }
- List<ItemData> suitPart = new List<ItemData>(); ;
- for (int i = _listItemDatas.Count - 1; i >= 0; i--)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[i].id);
- if (suitCfg != null)
- {
- for (int j = 0; j < suitCfg.partsArr.Length; j++)
- {
- suitPart.Add(ItemUtil.createItemData(suitCfg.partsArr[j], _listItemDatas[i].num));
- }
- _listItemDatas.RemoveAt(i);
- }
- }
- _listItemDatas.AddRange(suitPart);
- _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;
- }
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gxhd_bjbj");
- }
- 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, true);
- 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];
- UI_ListRewardItem.ProxyEnd();
- }
- 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;
- /// <summary>
- /// 是否展示物品详情,默认展示
- /// </summary>
- private bool ShowTips
- {
- get { return _showTips; }
- set { _showTips = value; }
- }
- }
- }
|