RewardView.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.CommonGame;
  4. using FairyGUI;
  5. using System.Collections.Generic;
  6. using System;
  7. namespace GFGGame
  8. {
  9. public class RewardView : BaseWindow
  10. {
  11. private UI_RewardUI _ui;
  12. private List<ItemData> _listItemDatas;
  13. private Action onSuccess = null;
  14. private List<EffectUI> _effects = new List<EffectUI>();
  15. // private List<GoWrapper> _wrappers = new List<GoWrapper>();
  16. private const int maxHeight = 1030;
  17. private EffectUI _effectUI1;
  18. public override void Dispose()
  19. {
  20. EffectUIPool.Recycle(_effectUI1);
  21. _effectUI1 = null;
  22. for (int i = 0; i < _effects.Count; i++)
  23. {
  24. if (_effects[i] != null)
  25. {
  26. EffectUIPool.Recycle(_effects[i]);
  27. _effects[i] = null;
  28. }
  29. }
  30. _effects.Clear();
  31. if (_ui != null)
  32. {
  33. _ui.Dispose();
  34. _ui = null;
  35. }
  36. base.Dispose();
  37. }
  38. protected override void OnInit()
  39. {
  40. base.OnInit();
  41. _ui = UI_RewardUI.Create();
  42. this.viewCom = _ui.target;
  43. this.viewCom.Center();
  44. this.modal = true;
  45. _ui.m_comListReward.m_listReward.SetVirtual();
  46. _ui.m_comListReward.m_listReward.itemRenderer = RenderListRewardItem;
  47. // _ui.m_comListReward.m_listReward.onClickItem.Add(OnClickListReward);
  48. _ui.m_loaBg.onClick.Add(this.Hide);
  49. }
  50. protected override void OnShown()
  51. {
  52. base.OnShown();
  53. if ((this.viewData as object[]).Length > 0)
  54. {
  55. _listItemDatas = (this.viewData as object[])[0] as List<ItemData>;
  56. onSuccess = (this.viewData as object[])[1] as Action;
  57. }
  58. else
  59. {
  60. _listItemDatas = this.viewData as List<ItemData>;
  61. }
  62. List<ItemData> suitPart = new List<ItemData>(); ;
  63. for (int i = _listItemDatas.Count - 1; i >= 0; i--)
  64. {
  65. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[i].id);
  66. if (suitCfg != null)
  67. {
  68. for (int j = 0; j < suitCfg.partsArr.Length; j++)
  69. {
  70. suitPart.Add(ItemUtil.createItemData(suitCfg.partsArr[j], _listItemDatas[i].num));
  71. }
  72. _listItemDatas.RemoveAt(i);
  73. }
  74. }
  75. _listItemDatas.AddRange(suitPart);
  76. _ui.m_comListReward.m_listReward.numItems = _listItemDatas.Count;
  77. _ui.m_comListReward.m_listReward.ResizeToFit();
  78. if (_ui.m_comListReward.m_listReward.height > maxHeight)
  79. {
  80. _ui.m_comListReward.m_listReward.height = maxHeight;
  81. }
  82. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gxhd_bjbj");
  83. //邊框左上角特效
  84. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderTitle, "ui_hd", "GXHD");
  85. }
  86. protected override void OnHide()
  87. {
  88. if (onSuccess != null)
  89. {
  90. onSuccess();
  91. }
  92. base.OnHide();
  93. //_effects.Clear();
  94. GetSuitItemController.TryShow(0);
  95. }
  96. private void RenderListRewardItem(int index, GObject obj)
  97. {
  98. // obj.data = _listItemDatas[index];
  99. UI_ListRewardItem item = UI_ListRewardItem.Proxy(obj);
  100. string name = "";
  101. string iconRes = "";
  102. string ext = "png";
  103. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  104. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  105. if (suitCfg != null)
  106. {
  107. name = suitCfg.name;
  108. iconRes = suitCfg.res;
  109. }
  110. else
  111. {
  112. name = itemCfg.name;
  113. ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  114. iconRes = itemCfg.res;
  115. }
  116. item.m_comRewardItem.m_txtName.text = name;
  117. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("x{0}", _listItemDatas[index].num);
  118. item.m_comRewardItem.m_txtCount.text = string.Format("x{0}", _listItemDatas[index].num);
  119. item.m_comRewardItem.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  120. item.m_comRewardItem.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  121. //特效("ui_ck", "ui_ck_zl");
  122. int childIndex = _ui.m_comListReward.m_listReward.ItemIndexToChildIndex(index);
  123. if (_effects.Count <= childIndex)
  124. {
  125. //EffectUI _effectUI = EffectUIPool.CreateEffectUI(item.m_holderReware, "ui_hd", "GXHD_WuPin");
  126. //_effects.Add(_effectUI);
  127. //_effects.Add(item.m_effect);
  128. //item.m_effect.SetPlaySettings(0, -1, 1, -1);
  129. }
  130. if (item.m_comRewardItem.target.data == null)
  131. {
  132. item.m_comRewardItem.target.onClick.Add(OnClickListReward);
  133. }
  134. item.m_comRewardItem.target.data = _listItemDatas[index];
  135. UI_ListRewardItem.ProxyEnd();
  136. }
  137. private void OnClickListReward(EventContext context)
  138. {
  139. if (this.ShowTips)
  140. {
  141. ItemData data = (context.sender as GObject).data as ItemData;
  142. GoodsItemTipsController.ShowItemTips(data.id);
  143. }
  144. }
  145. private bool _showTips = true;
  146. /// <summary>
  147. /// 是否展示物品详情,默认展示
  148. /// </summary>
  149. private bool ShowTips
  150. {
  151. get { return _showTips; }
  152. set { _showTips = value; }
  153. }
  154. }
  155. }