RewardView.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.CommonGame;
  4. using FairyGUI;
  5. using System.Collections.Generic;
  6. using System;
  7. namespace GFGGame
  8. {
  9. public class RewardView : BaseWindow
  10. {
  11. private UI_RewardUI _ui;
  12. private List<ItemData> _listItemDatas;
  13. private Action onSuccess = null;
  14. private List<GMovieClip> _effects = new List<GMovieClip>();
  15. // private List<GoWrapper> _wrappers = new List<GoWrapper>();
  16. private const int maxHeight = 1030;
  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. _ui.m_comListReward.m_listReward.SetVirtual();
  34. _ui.m_comListReward.m_listReward.itemRenderer = RenderListRewardItem;
  35. // _ui.m_comListReward.m_listReward.onClickItem.Add(OnClickListReward);
  36. _ui.m_loaBg.onClick.Add(this.Hide);
  37. }
  38. protected override void OnShown()
  39. {
  40. base.OnShown();
  41. if ((this.viewData as object[]).Length > 0)
  42. {
  43. _listItemDatas = (this.viewData as object[])[0] as List<ItemData>;
  44. onSuccess = (this.viewData as object[])[1] as Action;
  45. }
  46. else
  47. {
  48. _listItemDatas = this.viewData as List<ItemData>;
  49. }
  50. List<ItemData> suitPart = new List<ItemData>(); ;
  51. for (int i = _listItemDatas.Count - 1; i >= 0; i--)
  52. {
  53. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[i].id);
  54. if (suitCfg != null)
  55. {
  56. for (int j = 0; j < suitCfg.partsArr.Length; j++)
  57. {
  58. suitPart.Add(ItemUtil.createItemData(suitCfg.partsArr[j], _listItemDatas[i].num));
  59. }
  60. _listItemDatas.RemoveAt(i);
  61. }
  62. }
  63. _listItemDatas.AddRange(suitPart);
  64. _ui.m_comListReward.m_listReward.numItems = _listItemDatas.Count;
  65. _ui.m_comListReward.m_listReward.ResizeToFit();
  66. if (_ui.m_comListReward.m_listReward.height > maxHeight)
  67. {
  68. _ui.m_comListReward.m_listReward.height = maxHeight;
  69. }
  70. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gxhd_bjbj");
  71. }
  72. protected override void OnHide()
  73. {
  74. if (onSuccess != null)
  75. {
  76. onSuccess();
  77. }
  78. base.OnHide();
  79. _effects.Clear();
  80. GetSuitItemController.TryShow(0);
  81. }
  82. private void RenderListRewardItem(int index, GObject obj)
  83. {
  84. // obj.data = _listItemDatas[index];
  85. UI_ListRewardItem item = UI_ListRewardItem.Proxy(obj);
  86. string name = "";
  87. string iconRes = "";
  88. string ext = "png";
  89. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  90. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  91. if (suitCfg != null)
  92. {
  93. name = suitCfg.name;
  94. iconRes = suitCfg.res;
  95. }
  96. else
  97. {
  98. name = itemCfg.name;
  99. ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType, true);
  100. iconRes = itemCfg.res;
  101. }
  102. item.m_comRewardItem.m_txtName.text = name;
  103. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("x{0}", _listItemDatas[index].num);
  104. item.m_comRewardItem.m_txtCount.text = string.Format("x{0}", _listItemDatas[index].num);
  105. item.m_comRewardItem.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  106. item.m_comRewardItem.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  107. //string resPath = ResPathUtil.GetViewEffectPath("ui_ck", "ui_ck_zl");
  108. int childIndex = _ui.m_comListReward.m_listReward.ItemIndexToChildIndex(index);
  109. if (_effects.Count <= childIndex)
  110. {
  111. _effects.Add(item.m_effect);
  112. item.m_effect.SetPlaySettings(0, -1, 1, -1);
  113. }
  114. if (item.m_comRewardItem.target.data == null)
  115. {
  116. item.m_comRewardItem.target.onClick.Add(OnClickListReward);
  117. }
  118. item.m_comRewardItem.target.data = _listItemDatas[index];
  119. UI_ListRewardItem.ProxyEnd();
  120. }
  121. private void OnClickListReward(EventContext context)
  122. {
  123. if (this.ShowTips)
  124. {
  125. ItemData data = (context.sender as GObject).data as ItemData;
  126. GoodsItemTipsController.ShowItemTips(data.id);
  127. }
  128. }
  129. private bool _showTips = true;
  130. /// <summary>
  131. /// 是否展示物品详情,默认展示
  132. /// </summary>
  133. private bool ShowTips
  134. {
  135. get { return _showTips; }
  136. set { _showTips = value; }
  137. }
  138. }
  139. }