RewardView.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.CommonGame;
  4. using FairyGUI;
  5. using System.Collections.Generic;
  6. using System;
  7. using cfg.GfgCfg;
  8. namespace GFGGame
  9. {
  10. public class RewardView : BaseWindow
  11. {
  12. private UI_RewardUI _ui;
  13. private List<ItemData> _listItemDatas;
  14. private Action onSuccess = null;
  15. private List<EffectUI> _effects = new List<EffectUI>();
  16. private const int maxHeight = 1030;
  17. private EffectUI _effectUI1;
  18. private EffectUI _effectUI2;
  19. private int counTime = 0; //定时器计数
  20. public override void Dispose()
  21. {
  22. if (_ui != null)
  23. {
  24. _ui.Dispose();
  25. _ui = null;
  26. }
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. _ui = UI_RewardUI.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. ;
  56. for (int i = _listItemDatas.Count - 1; i >= 0; i--)
  57. {
  58. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_listItemDatas[i].id);
  59. if (suitCfg != null)
  60. {
  61. for (int j = 0; j < suitCfg.Parts.Count; j++)
  62. {
  63. suitPart.Add(ItemUtil.createItemData(suitCfg.Parts[j], _listItemDatas[i].num));
  64. }
  65. _listItemDatas.RemoveAt(i);
  66. }
  67. }
  68. _listItemDatas.AddRange(suitPart);
  69. //_ui.m_listReward.SetVirtual(); //有虚拟列表的时候,没有办法居中显示列表
  70. _ui.m_downTipsText.visible = false;
  71. _ui.m_comList.m_listReward.numItems = 0;
  72. counTime = 0;
  73. Timers.inst.Add(0.1f, 3, OnTimerUpdate, 1);
  74. Timers.inst.Add(0.5f, 1, OnTimerClick);
  75. }
  76. private void OnTimerClick(object param)
  77. {
  78. _ui.m_mask.touchable = true;
  79. }
  80. private void OnTimerUpdate(object param)
  81. {
  82. counTime += 1;
  83. if (counTime == 1)
  84. {
  85. EffectUIPool.CreateEffectUI(_ui.m_holderTitle, "ui_hd", "GXHD_Text",
  86. onComplete: (effect) =>
  87. {
  88. if (effect != null)
  89. {
  90. _effectUI1 = effect;
  91. }
  92. });
  93. EffectUIPool.CreateEffectUI(_ui.m_holderBgCom, "ui_hd", "TC_Quad_ALL",
  94. onComplete: (effect) =>
  95. {
  96. if (effect != null)
  97. {
  98. _effectUI2 = effect;
  99. }
  100. });
  101. }
  102. else if (counTime == 2)
  103. {
  104. _ui.m_comList.m_listReward.numItems = _listItemDatas.Count;
  105. _ui.m_comList.m_listReward.ResizeToFit();
  106. if (_ui.m_comList.m_listReward.height > maxHeight)
  107. {
  108. _ui.m_comList.m_listReward.height = maxHeight;
  109. }
  110. }
  111. else if (counTime == 3)
  112. {
  113. _ui.m_downTipsText.visible = true;
  114. Timers.inst.Remove(OnTimerUpdate);
  115. }
  116. }
  117. protected override void OnHide()
  118. {
  119. EffectUIPool.Recycle(_effectUI1);
  120. _effectUI1 = null;
  121. EffectUIPool.Recycle(_effectUI2);
  122. _effectUI2 = null;
  123. Timers.inst.Remove(OnTimerUpdate);
  124. Timers.inst.Remove(OnTimerClick);
  125. _ui.m_mask.touchable = true;
  126. for (int i = 0; i < _effects.Count; i++)
  127. {
  128. if (_effects[i] != null)
  129. {
  130. EffectUIPool.Recycle(_effects[i]);
  131. _effects[i] = null;
  132. }
  133. }
  134. _effects.Clear();
  135. if (onSuccess != null)
  136. {
  137. onSuccess();
  138. }
  139. base.OnHide();
  140. //_effects.Clear();
  141. EventAgent.DispatchEvent(ConstMessage.REWARDVIEW_CLOTHER);
  142. GetSuitItemController.TryShow(0);
  143. }
  144. private void RenderListRewardItem(int index, GObject obj)
  145. {
  146. // obj.data = _listItemDatas[index];
  147. UI_ComItem item = UI_ComItem.Proxy(obj);
  148. string name = "";
  149. string iconRes = "";
  150. string ext = "png";
  151. int rarity = 0;
  152. int id = 0;
  153. bool isSuit = false;
  154. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_listItemDatas[index].id);
  155. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_listItemDatas[index].id);
  156. if (suitCfg != null)
  157. {
  158. name = suitCfg.Name;
  159. iconRes = suitCfg.Res;
  160. rarity = suitCfg.Rarity;
  161. id = suitCfg.Id;
  162. isSuit = true;
  163. }
  164. else
  165. {
  166. name = itemCfg.Name;
  167. ext = ItemUtil.GetItemResExt(itemCfg.ItemType, itemCfg.SubType, true);
  168. iconRes = itemCfg.Res;
  169. id = itemCfg.Id;
  170. isSuit = false;
  171. //if (itemCfg.itemType == ConstItemType.DRESS_UP)
  172. rarity = itemCfg.Rarity;
  173. }
  174. item.m_txtName.text = name;
  175. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("{0}", _listItemDatas[index].num);
  176. item.m_txtCount.text = string.Format("{0}", _listItemDatas[index].num);
  177. item.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  178. if (rarity > 0)
  179. {
  180. item.m_QualityType.selectedIndex = rarity - 1;
  181. }
  182. else
  183. {
  184. item.m_QualityType.selectedIndex = 0;
  185. }
  186. RarityIconController.UpdateRarityIcon(item.m_loaRarity, id, false, isSuit);
  187. item.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  188. //特效("ui_ck", "ui_ck_zl");
  189. int childIndex = _ui.m_comList.m_listReward.ItemIndexToChildIndex(index);
  190. if (_effects.Count <= childIndex)
  191. {
  192. EffectUIPool.CreateEffectUI(item.m_holderReware, "ui_hd", "GXHD_WuPin", 120,
  193. onComplete: (effect) =>
  194. {
  195. if (effect != null)
  196. {
  197. _effects.Add(effect);
  198. }
  199. });
  200. }
  201. if (item.target.data == null)
  202. {
  203. item.target.onClick.Add(OnClickListReward);
  204. }
  205. item.target.data = _listItemDatas[index];
  206. UI_ComItem.ProxyEnd();
  207. }
  208. private void OnClickListReward(EventContext context)
  209. {
  210. if (this.ShowTips)
  211. {
  212. ItemData data = (context.sender as GObject).data as ItemData;
  213. GoodsItemTipsController.ShowItemTips(data.id);
  214. }
  215. }
  216. private bool _showTips = true;
  217. /// <summary>
  218. /// 是否展示物品详情,默认展示
  219. /// </summary>
  220. private bool ShowTips
  221. {
  222. get { return _showTips; }
  223. set { _showTips = value; }
  224. }
  225. }
  226. }