RewardView.cs 7.4 KB

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