RewardView.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 const int maxHeight = 1030;
  16. private int counTime = 0; //定时器计数
  17. public override void Dispose()
  18. {
  19. if (_ui != null)
  20. {
  21. _ui.Dispose();
  22. _ui = null;
  23. }
  24. base.Dispose();
  25. }
  26. protected override void OnInit()
  27. {
  28. base.OnInit();
  29. _ui = UI_RewardUI.Create();
  30. this.viewCom = _ui.target;
  31. //this.viewCom.Center();
  32. //this.modal = true;
  33. //viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  34. isfullScreen = true;
  35. _ui.m_comList.m_listReward.itemRenderer = RenderListRewardItem;
  36. _ui.m_mask.onClick.Add(this.Hide);
  37. }
  38. protected override void OnShown()
  39. {
  40. base.OnShown();
  41. _ui.m_mask.touchable = false;
  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 = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_listItemDatas[i].id);
  55. if (suitCfg != null)
  56. {
  57. for (int j = 0; j < suitCfg.Parts.Count; j++)
  58. {
  59. suitPart.Add(ItemUtil.createItemData(suitCfg.Parts[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_comList.m_listReward.numItems = 0;
  68. counTime = 0;
  69. Timers.inst.Add(0.1f, 3, OnTimerUpdate, 1);
  70. Timers.inst.Add(0.5f, 1, OnTimerClick);
  71. }
  72. private void OnTimerClick(object param)
  73. {
  74. _ui.m_mask.touchable = true;
  75. }
  76. private void OnTimerUpdate(object param)
  77. {
  78. counTime += 1;
  79. _ui.m_downTipsText.visible = true;
  80. _ui.m_comList.m_listReward.numItems = _listItemDatas.Count;
  81. _ui.m_comList.m_listReward.ResizeToFit();
  82. if (_ui.m_comList.m_listReward.height > maxHeight)
  83. {
  84. _ui.m_comList.m_listReward.height = maxHeight;
  85. }
  86. }
  87. protected override void OnHide()
  88. {
  89. // EffectUIPool.Recycle(_effectUI1);
  90. // _effectUI1 = null;
  91. // EffectUIPool.Recycle(_effectUI2);
  92. // _effectUI2 = null;
  93. Timers.inst.Remove(OnTimerUpdate);
  94. Timers.inst.Remove(OnTimerClick);
  95. _ui.m_mask.touchable = true;
  96. // for (int i = 0; i < _effects.Count; i++)
  97. // {
  98. // if (_effects[i] != null)
  99. // {
  100. // EffectUIPool.Recycle(_effects[i]);
  101. // _effects[i] = null;
  102. // }
  103. // }
  104. // _effects.Clear();
  105. if (onSuccess != null)
  106. {
  107. onSuccess();
  108. }
  109. base.OnHide();
  110. //_effects.Clear();
  111. EventAgent.DispatchEvent(ConstMessage.REWARDVIEW_CLOTHER);
  112. GetSuitItemController.TryShow(0);
  113. }
  114. private void RenderListRewardItem(int index, GObject obj)
  115. {
  116. // obj.data = _listItemDatas[index];
  117. UI_ComItem item = UI_ComItem.Proxy(obj);
  118. string name = "";
  119. string iconRes = "";
  120. string ext = "png";
  121. int rarity = 0;
  122. int id = 0;
  123. bool isSuit = false;
  124. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_listItemDatas[index].id);
  125. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_listItemDatas[index].id);
  126. if (suitCfg != null)
  127. {
  128. name = suitCfg.Name;
  129. iconRes = suitCfg.Res;
  130. rarity = suitCfg.Rarity;
  131. id = suitCfg.Id;
  132. isSuit = true;
  133. }
  134. else
  135. {
  136. name = itemCfg.Name;
  137. ext = ItemUtil.GetItemResExt(itemCfg.ItemType, itemCfg.SubType, true);
  138. iconRes = itemCfg.Res;
  139. id = itemCfg.Id;
  140. isSuit = false;
  141. //if (itemCfg.itemType == ConstItemType.DRESS_UP)
  142. rarity = itemCfg.Rarity;
  143. }
  144. item.m_txtName.text = name;
  145. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("{0}", _listItemDatas[index].num);
  146. item.m_txtCount.text = string.Format("{0}", _listItemDatas[index].num);
  147. item.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  148. if (rarity > 0)
  149. {
  150. item.m_QualityType.selectedIndex = rarity - 1;
  151. }
  152. else
  153. {
  154. item.m_QualityType.selectedIndex = 0;
  155. }
  156. RarityIconController.UpdateRarityIcon(item.m_loaRarity, id, false, isSuit);
  157. item.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  158. //特效("ui_ck", "ui_ck_zl");
  159. //int childIndex = _ui.m_comList.m_listReward.ItemIndexToChildIndex(index);
  160. // if (_effects.Count <= childIndex)
  161. // {
  162. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(item.m_holderReware, "ui_hd", "GXHD_WuPin",120);
  163. // _effects.Add(_effectUI);
  164. // }
  165. if (item.target.data == null)
  166. {
  167. item.target.onClick.Add(OnClickListReward);
  168. }
  169. item.target.data = _listItemDatas[index];
  170. UI_ComItem.ProxyEnd();
  171. }
  172. private void OnClickListReward(EventContext context)
  173. {
  174. if (this.ShowTips)
  175. {
  176. ItemData data = (context.sender as GObject).data as ItemData;
  177. GoodsItemTipsController.ShowItemTips(data.id);
  178. }
  179. }
  180. private bool _showTips = true;
  181. /// <summary>
  182. /// 是否展示物品详情,默认展示
  183. /// </summary>
  184. private bool ShowTips
  185. {
  186. get { return _showTips; }
  187. set { _showTips = value; }
  188. }
  189. }
  190. }