RewardView.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderTitle, "ui_hd", "GXHD_Text");
  86. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderBgCom, "ui_hd", "TC_Quad_ALL");
  87. }
  88. else if (counTime == 2)
  89. {
  90. _ui.m_comList.m_listReward.numItems = _listItemDatas.Count;
  91. _ui.m_comList.m_listReward.ResizeToFit();
  92. if (_ui.m_comList.m_listReward.height > maxHeight)
  93. {
  94. _ui.m_comList.m_listReward.height = maxHeight;
  95. }
  96. }
  97. else if (counTime == 3)
  98. {
  99. _ui.m_downTipsText.visible = true;
  100. Timers.inst.Remove(OnTimerUpdate);
  101. }
  102. }
  103. protected override void OnHide()
  104. {
  105. EffectUIPool.Recycle(_effectUI1);
  106. _effectUI1 = null;
  107. EffectUIPool.Recycle(_effectUI2);
  108. _effectUI2 = null;
  109. Timers.inst.Remove(OnTimerUpdate);
  110. Timers.inst.Remove(OnTimerClick);
  111. _ui.m_mask.touchable = true;
  112. for (int i = 0; i < _effects.Count; i++)
  113. {
  114. if (_effects[i] != null)
  115. {
  116. EffectUIPool.Recycle(_effects[i]);
  117. _effects[i] = null;
  118. }
  119. }
  120. _effects.Clear();
  121. if (onSuccess != null)
  122. {
  123. onSuccess();
  124. }
  125. base.OnHide();
  126. //_effects.Clear();
  127. EventAgent.DispatchEvent(ConstMessage.REWARDVIEW_CLOTHER);
  128. GetSuitItemController.TryShow(0);
  129. }
  130. private void RenderListRewardItem(int index, GObject obj)
  131. {
  132. // obj.data = _listItemDatas[index];
  133. UI_ComItem item = UI_ComItem.Proxy(obj);
  134. string name = "";
  135. string iconRes = "";
  136. string ext = "png";
  137. int rarity = 0;
  138. int id = 0;
  139. bool isSuit = false;
  140. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_listItemDatas[index].id);
  141. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_listItemDatas[index].id);
  142. if (suitCfg != null)
  143. {
  144. name = suitCfg.Name;
  145. iconRes = suitCfg.Res;
  146. rarity = suitCfg.Rarity;
  147. id = suitCfg.Id;
  148. isSuit = true;
  149. }
  150. else
  151. {
  152. name = itemCfg.Name;
  153. ext = ItemUtil.GetItemResExt(itemCfg.ItemType, itemCfg.SubType, true);
  154. iconRes = itemCfg.Res;
  155. id = itemCfg.Id;
  156. isSuit = false;
  157. //if (itemCfg.itemType == ConstItemType.DRESS_UP)
  158. rarity = itemCfg.Rarity;
  159. }
  160. item.m_txtName.text = name;
  161. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("{0}", _listItemDatas[index].num);
  162. item.m_txtCount.text = string.Format("{0}", _listItemDatas[index].num);
  163. item.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  164. if (rarity > 0)
  165. {
  166. item.m_QualityType.selectedIndex = rarity - 1;
  167. }
  168. else
  169. {
  170. item.m_QualityType.selectedIndex = 0;
  171. }
  172. RarityIconController.UpdateRarityIcon(item.m_loaRarity, id, false, isSuit);
  173. item.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  174. //特效("ui_ck", "ui_ck_zl");
  175. int childIndex = _ui.m_comList.m_listReward.ItemIndexToChildIndex(index);
  176. if (_effects.Count <= childIndex)
  177. {
  178. EffectUI _effectUI = EffectUIPool.CreateEffectUI(item.m_holderReware, "ui_hd", "GXHD_WuPin", 120);
  179. _effects.Add(_effectUI);
  180. }
  181. if (item.target.data == null)
  182. {
  183. item.target.onClick.Add(OnClickListReward);
  184. }
  185. item.target.data = _listItemDatas[index];
  186. UI_ComItem.ProxyEnd();
  187. }
  188. private void OnClickListReward(EventContext context)
  189. {
  190. if (this.ShowTips)
  191. {
  192. ItemData data = (context.sender as GObject).data as ItemData;
  193. GoodsItemTipsController.ShowItemTips(data.id);
  194. }
  195. }
  196. private bool _showTips = true;
  197. /// <summary>
  198. /// 是否展示物品详情,默认展示
  199. /// </summary>
  200. private bool ShowTips
  201. {
  202. get { return _showTips; }
  203. set { _showTips = value; }
  204. }
  205. }
  206. }