RewardView.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 const int maxHeight = 1030;
  16. private EffectUI _effectUI1;
  17. private EffectUI _effectUI2;
  18. private int counTime = 0; //定时器计数
  19. public override void Dispose()
  20. {
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. _ui = UI_RewardUI.Create();
  32. this.viewCom = _ui.target;
  33. //this.viewCom.Center();
  34. //this.modal = true;
  35. //viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  36. isfullScreen = true;
  37. _ui.m_comList.m_listReward.itemRenderer = RenderListRewardItem;
  38. _ui.m_mask.onClick.Add(this.Hide);
  39. }
  40. protected override void OnShown()
  41. {
  42. base.OnShown();
  43. if ((this.viewData as object[]).Length > 0)
  44. {
  45. _listItemDatas = (this.viewData as object[])[0] as List<ItemData>;
  46. onSuccess = (this.viewData as object[])[1] as Action;
  47. }
  48. else
  49. {
  50. _listItemDatas = this.viewData as List<ItemData>;
  51. }
  52. List<ItemData> suitPart = new List<ItemData>(); ;
  53. for (int i = _listItemDatas.Count - 1; i >= 0; i--)
  54. {
  55. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[i].id);
  56. if (suitCfg != null)
  57. {
  58. for (int j = 0; j < suitCfg.partsArr.Length; j++)
  59. {
  60. suitPart.Add(ItemUtil.createItemData(suitCfg.partsArr[j], _listItemDatas[i].num));
  61. }
  62. _listItemDatas.RemoveAt(i);
  63. }
  64. }
  65. _listItemDatas.AddRange(suitPart);
  66. //_ui.m_listReward.SetVirtual(); //有虚拟列表的时候,没有办法居中显示列表
  67. _ui.m_downTipsText.visible = false;
  68. _ui.m_comList.m_listReward.numItems = 0;
  69. counTime = 0;
  70. Timers.inst.Add(0.1f, 3, OnTimerUpdate, 1);
  71. }
  72. private void OnTimerUpdate(object param)
  73. {
  74. counTime += 1;
  75. if (counTime == 1)
  76. {
  77. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderTitle, "ui_hd", "GXHD_Text");
  78. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderBgCom, "ui_hd", "TC_Quad_ALL");
  79. }
  80. else if (counTime == 2)
  81. {
  82. _ui.m_comList.m_listReward.numItems = _listItemDatas.Count;
  83. _ui.m_comList.m_listReward.ResizeToFit();
  84. if (_ui.m_comList.m_listReward.height > maxHeight)
  85. {
  86. _ui.m_comList.m_listReward.height = maxHeight;
  87. }
  88. }
  89. else if (counTime == 3)
  90. {
  91. _ui.m_downTipsText.visible = true;
  92. Timers.inst.Remove(OnTimerUpdate);
  93. }
  94. }
  95. protected override void OnHide()
  96. {
  97. EffectUIPool.Recycle(_effectUI1);
  98. _effectUI1 = null;
  99. EffectUIPool.Recycle(_effectUI2);
  100. _effectUI2 = null;
  101. Timers.inst.Remove(OnTimerUpdate);
  102. for (int i = 0; i < _effects.Count; i++)
  103. {
  104. if (_effects[i] != null)
  105. {
  106. EffectUIPool.Recycle(_effects[i]);
  107. _effects[i] = null;
  108. }
  109. }
  110. _effects.Clear();
  111. if (onSuccess != null)
  112. {
  113. onSuccess();
  114. }
  115. base.OnHide();
  116. //_effects.Clear();
  117. GetSuitItemController.TryShow(0);
  118. }
  119. private void RenderListRewardItem(int index, GObject obj)
  120. {
  121. // obj.data = _listItemDatas[index];
  122. UI_ComItem item = UI_ComItem.Proxy(obj);
  123. string name = "";
  124. string iconRes = "";
  125. string ext = "png";
  126. int rarity = 0;
  127. int id = 0;
  128. bool isSuit = false;
  129. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  130. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  131. if (suitCfg != null)
  132. {
  133. name = suitCfg.name;
  134. iconRes = suitCfg.res;
  135. rarity = suitCfg.rarity;
  136. id = suitCfg.id;
  137. isSuit = true;
  138. }
  139. else
  140. {
  141. name = itemCfg.name;
  142. ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  143. iconRes = itemCfg.res;
  144. id = itemCfg.id;
  145. isSuit = false;
  146. //if (itemCfg.itemType == ConstItemType.DRESS_UP)
  147. rarity = itemCfg.rarity;
  148. }
  149. item.m_txtName.text = name;
  150. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("{0}", _listItemDatas[index].num);
  151. item.m_txtCount.text = string.Format("{0}", _listItemDatas[index].num);
  152. item.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  153. if (rarity > 0)
  154. {
  155. item.m_QualityType.selectedIndex = rarity - 1;
  156. }
  157. else
  158. {
  159. item.m_QualityType.selectedIndex = 0;
  160. }
  161. RarityIconController.UpdateRarityIcon(item.m_loaRarity, id, false, isSuit);
  162. item.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  163. //特效("ui_ck", "ui_ck_zl");
  164. int childIndex = _ui.m_comList.m_listReward.ItemIndexToChildIndex(index);
  165. if (_effects.Count <= childIndex)
  166. {
  167. EffectUI _effectUI = EffectUIPool.CreateEffectUI(item.m_holderReware, "ui_hd", "GXHD_WuPin",120);
  168. _effects.Add(_effectUI);
  169. }
  170. if (item.target.data == null)
  171. {
  172. item.target.onClick.Add(OnClickListReward);
  173. }
  174. item.target.data = _listItemDatas[index];
  175. UI_ComItem.ProxyEnd();
  176. }
  177. private void OnClickListReward(EventContext context)
  178. {
  179. if (this.ShowTips)
  180. {
  181. ItemData data = (context.sender as GObject).data as ItemData;
  182. GoodsItemTipsController.ShowItemTips(data.id);
  183. }
  184. }
  185. private bool _showTips = true;
  186. /// <summary>
  187. /// 是否展示物品详情,默认展示
  188. /// </summary>
  189. private bool ShowTips
  190. {
  191. get { return _showTips; }
  192. set { _showTips = value; }
  193. }
  194. }
  195. }