MatchingCompetitionRewardView.cs 7.6 KB

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