RewardView.cs 6.8 KB

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