RewardView.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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_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_listReward.numItems = 0;
  68. counTime = 0;
  69. Timers.inst.Add(0.1f, 3, OnTimerUpdate, 1);
  70. //邊框左上角特效
  71. //_effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderTitle, "ui_hd", "GXHD");
  72. }
  73. private void OnTimerUpdate(object param)
  74. {
  75. counTime += 1;
  76. if (counTime == 1)
  77. {
  78. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderTitle, "ui_hd", "GXHD");
  79. }
  80. else if (counTime == 2)
  81. {
  82. _ui.m_listReward.numItems = _listItemDatas.Count;
  83. _ui.m_listReward.ResizeToFit();
  84. if (_ui.m_listReward.height > maxHeight)
  85. {
  86. _ui.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. Timers.inst.Remove(OnTimerUpdate);
  100. for (int i = 0; i < _effects.Count; i++)
  101. {
  102. if (_effects[i] != null)
  103. {
  104. EffectUIPool.Recycle(_effects[i]);
  105. _effects[i] = null;
  106. }
  107. }
  108. _effects.Clear();
  109. if (onSuccess != null)
  110. {
  111. onSuccess();
  112. }
  113. base.OnHide();
  114. //_effects.Clear();
  115. GetSuitItemController.TryShow(0);
  116. }
  117. private void RenderListRewardItem(int index, GObject obj)
  118. {
  119. // obj.data = _listItemDatas[index];
  120. UI_ListRewardItem item = UI_ListRewardItem.Proxy(obj);
  121. string name = "";
  122. string iconRes = "";
  123. string ext = "png";
  124. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  125. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  126. if (suitCfg != null)
  127. {
  128. name = suitCfg.name;
  129. iconRes = suitCfg.res;
  130. }
  131. else
  132. {
  133. name = itemCfg.name;
  134. ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  135. iconRes = itemCfg.res;
  136. }
  137. item.m_comRewardItem.m_txtName.text = name;
  138. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("x{0}", _listItemDatas[index].num);
  139. item.m_comRewardItem.m_txtCount.text = string.Format("x{0}", _listItemDatas[index].num);
  140. item.m_comRewardItem.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  141. item.m_comRewardItem.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  142. //特效("ui_ck", "ui_ck_zl");
  143. int childIndex = _ui.m_listReward.ItemIndexToChildIndex(index);
  144. if (_effects.Count <= childIndex)
  145. {
  146. EffectUI _effectUI = EffectUIPool.CreateEffectUI(item.m_holderReware, "ui_hd", "GXHD_WuPin");
  147. _effects.Add(_effectUI);
  148. }
  149. if (item.m_comRewardItem.target.data == null)
  150. {
  151. item.m_comRewardItem.target.onClick.Add(OnClickListReward);
  152. }
  153. item.m_comRewardItem.target.data = _listItemDatas[index];
  154. UI_ListRewardItem.ProxyEnd();
  155. }
  156. private void OnClickListReward(EventContext context)
  157. {
  158. if (this.ShowTips)
  159. {
  160. ItemData data = (context.sender as GObject).data as ItemData;
  161. GoodsItemTipsController.ShowItemTips(data.id);
  162. }
  163. }
  164. private bool _showTips = true;
  165. /// <summary>
  166. /// 是否展示物品详情,默认展示
  167. /// </summary>
  168. private bool ShowTips
  169. {
  170. get { return _showTips; }
  171. set { _showTips = value; }
  172. }
  173. }
  174. }