MatchingCompetitionRewardView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. if(ActivityDataManager.Instance.StartDropId != ActivityDataManager.Instance.TipsDropId)
  129. {
  130. PromptController.Instance.ShowFloatTextPrompt("特殊奖励已改变!");
  131. ActivityDataManager.Instance.StartDropId = ActivityDataManager.Instance.TipsDropId;
  132. }
  133. }
  134. private void RenderListRewardItem(int index, GObject obj)
  135. {
  136. // obj.data = _listItemDatas[index];
  137. UI.CommonGame.UI_ComItem item = UI.CommonGame.UI_ComItem.Proxy(obj);
  138. string name = "";
  139. string iconRes = "";
  140. string ext = "png";
  141. int rarity = 0;
  142. int id = 0;
  143. bool isSuit = false;
  144. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  145. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  146. if (suitCfg != null)
  147. {
  148. name = suitCfg.name;
  149. iconRes = suitCfg.res;
  150. rarity = suitCfg.rarity;
  151. id = suitCfg.id;
  152. isSuit = true;
  153. }
  154. else
  155. {
  156. name = itemCfg.name;
  157. ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  158. iconRes = itemCfg.res;
  159. id = itemCfg.id;
  160. isSuit = false;
  161. //if (itemCfg.itemType == ConstItemType.DRESS_UP)
  162. rarity = itemCfg.rarity;
  163. }
  164. item.m_txtName.text = name;
  165. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("{0}", _listItemDatas[index].num);
  166. item.m_txtCount.text = string.Format("{0}", _listItemDatas[index].num);
  167. item.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  168. if (rarity > 0)
  169. {
  170. item.m_QualityType.selectedIndex = rarity - 1;
  171. }
  172. else
  173. {
  174. item.m_QualityType.selectedIndex = 0;
  175. }
  176. RarityIconController.UpdateRarityIcon(item.m_loaRarity, id, false, isSuit);
  177. item.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  178. //特效("ui_ck", "ui_ck_zl");
  179. int childIndex = _ui.m_comList.m_listReward.ItemIndexToChildIndex(index);
  180. if (_effects.Count <= childIndex)
  181. {
  182. EffectUI _effectUI = EffectUIPool.CreateEffectUI(item.m_holderReware, "ui_hd", "GXHD_WuPin", 120);
  183. _effects.Add(_effectUI);
  184. }
  185. if (item.target.data == null)
  186. {
  187. item.target.onClick.Add(OnClickListReward);
  188. }
  189. item.target.data = _listItemDatas[index];
  190. UI.CommonGame.UI_ComItem.ProxyEnd();
  191. }
  192. private void OnClickListReward(EventContext context)
  193. {
  194. if (this.ShowTips)
  195. {
  196. ItemData data = (context.sender as GObject).data as ItemData;
  197. GoodsItemTipsController.ShowItemTips(data.id);
  198. }
  199. }
  200. private bool _showTips = true;
  201. /// <summary>
  202. /// 是否展示物品详情,默认展示
  203. /// </summary>
  204. private bool ShowTips
  205. {
  206. get { return _showTips; }
  207. set { _showTips = value; }
  208. }
  209. }
  210. }