MatchingCompetitionRewardView.cs 8.6 KB

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