RewardView.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. EventAgent.DispatchEvent(ConstMessage.REWARDVIEW_CLOTHER);
  126. GetSuitItemController.TryShow(0);
  127. }
  128. private void RenderListRewardItem(int index, GObject obj)
  129. {
  130. // obj.data = _listItemDatas[index];
  131. UI_ComItem item = UI_ComItem.Proxy(obj);
  132. string name = "";
  133. string iconRes = "";
  134. string ext = "png";
  135. int rarity = 0;
  136. int id = 0;
  137. bool isSuit = false;
  138. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  139. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  140. if (suitCfg != null)
  141. {
  142. name = suitCfg.name;
  143. iconRes = suitCfg.res;
  144. rarity = suitCfg.rarity;
  145. id = suitCfg.id;
  146. isSuit = true;
  147. }
  148. else
  149. {
  150. name = itemCfg.name;
  151. ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  152. iconRes = itemCfg.res;
  153. id = itemCfg.id;
  154. isSuit = false;
  155. //if (itemCfg.itemType == ConstItemType.DRESS_UP)
  156. rarity = itemCfg.rarity;
  157. }
  158. item.m_txtName.text = name;
  159. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("{0}", _listItemDatas[index].num);
  160. item.m_txtCount.text = string.Format("{0}", _listItemDatas[index].num);
  161. item.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  162. if (rarity > 0)
  163. {
  164. item.m_QualityType.selectedIndex = rarity - 1;
  165. }
  166. else
  167. {
  168. item.m_QualityType.selectedIndex = 0;
  169. }
  170. RarityIconController.UpdateRarityIcon(item.m_loaRarity, id, false, isSuit);
  171. item.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  172. //特效("ui_ck", "ui_ck_zl");
  173. int childIndex = _ui.m_comList.m_listReward.ItemIndexToChildIndex(index);
  174. if (_effects.Count <= childIndex)
  175. {
  176. EffectUI _effectUI = EffectUIPool.CreateEffectUI(item.m_holderReware, "ui_hd", "GXHD_WuPin",120);
  177. _effects.Add(_effectUI);
  178. }
  179. if (item.target.data == null)
  180. {
  181. item.target.onClick.Add(OnClickListReward);
  182. }
  183. item.target.data = _listItemDatas[index];
  184. UI_ComItem.ProxyEnd();
  185. }
  186. private void OnClickListReward(EventContext context)
  187. {
  188. if (this.ShowTips)
  189. {
  190. ItemData data = (context.sender as GObject).data as ItemData;
  191. GoodsItemTipsController.ShowItemTips(data.id);
  192. }
  193. }
  194. private bool _showTips = true;
  195. /// <summary>
  196. /// 是否展示物品详情,默认展示
  197. /// </summary>
  198. private bool ShowTips
  199. {
  200. get { return _showTips; }
  201. set { _showTips = value; }
  202. }
  203. }
  204. }