MatchingCompetitionRewardView.cs 8.0 KB

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