RewardView.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. base.Dispose();
  20. }
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. _ui = UI_RewardUI.Create();
  25. this.viewCom = _ui.target;
  26. this.viewCom.Center();
  27. this.modal = true;
  28. _ui.m_comListReward.m_listReward.SetVirtual();
  29. _ui.m_comListReward.m_listReward.itemRenderer = RenderListRewardItem;
  30. // _ui.m_comListReward.m_listReward.onClickItem.Add(OnClickListReward);
  31. _ui.m_bg.onClick.Add(this.Hide);
  32. }
  33. protected override void OnShown()
  34. {
  35. base.OnShown();
  36. if ((this.viewData as object[]).Length > 0)
  37. {
  38. _listItemDatas = (this.viewData as object[])[0] as List<ItemData>;
  39. onSuccess = (this.viewData as object[])[1] as Action;
  40. }
  41. else
  42. {
  43. _listItemDatas = this.viewData as List<ItemData>;
  44. }
  45. _ui.m_comListReward.m_listReward.numItems = _listItemDatas.Count;
  46. _ui.m_comListReward.m_listReward.ResizeToFit();
  47. if (_ui.m_comListReward.m_listReward.height > maxHeight)
  48. {
  49. _ui.m_comListReward.m_listReward.height = maxHeight;
  50. }
  51. }
  52. protected override void OnHide()
  53. {
  54. if (onSuccess != null)
  55. {
  56. onSuccess();
  57. }
  58. base.OnHide();
  59. _effects.Clear();
  60. }
  61. private void RenderListRewardItem(int index, GObject obj)
  62. {
  63. // obj.data = _listItemDatas[index];
  64. UI_ListRewardItem item = UI_ListRewardItem.Proxy(obj);
  65. string name = "";
  66. string iconRes = "";
  67. string ext = "png";
  68. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  69. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listItemDatas[index].id);
  70. if (suitCfg != null)
  71. {
  72. name = suitCfg.name;
  73. iconRes = suitCfg.res;
  74. }
  75. else
  76. {
  77. name = itemCfg.name;
  78. ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
  79. iconRes = itemCfg.res;
  80. }
  81. item.m_comRewardItem.m_txtName.text = name;
  82. // item.m_txtCount.text = _listItemDatas[index].num==1?"": string.Format("x{0}", _listItemDatas[index].num);
  83. item.m_comRewardItem.m_txtCount.text = string.Format("x{0}", _listItemDatas[index].num);
  84. item.m_comRewardItem.m_loaIcon.url = ResPathUtil.GetIconPath(iconRes, ext);
  85. item.m_comRewardItem.m_imgOnceBonus.visible = _listItemDatas[index].isOnceBonus;
  86. string resPath = ResPathUtil.GetViewEffectPath("ui_ck", "ui_ck_zl");
  87. int childIndex = _ui.m_comListReward.m_listReward.ItemIndexToChildIndex(index);
  88. if (_effects.Count <= childIndex)
  89. {
  90. _effects.Add(item.m_effect);
  91. item.m_effect.SetPlaySettings(0, -1, 1, -1);
  92. }
  93. if (item.m_comRewardItem.target.data == null)
  94. {
  95. item.m_comRewardItem.target.onClick.Add(OnClickListReward);
  96. }
  97. item.m_comRewardItem.target.data = _listItemDatas[index];
  98. }
  99. private void OnClickListReward(EventContext context)
  100. {
  101. if (this.ShowTips)
  102. {
  103. ItemData data = (context.sender as GObject).data as ItemData;
  104. GoodsItemTipsController.ShowItemTips(data.id);
  105. }
  106. }
  107. private bool _showTips = true;
  108. /// <summary>
  109. /// 是否展示物品详情,默认展示
  110. /// </summary>
  111. private bool ShowTips
  112. {
  113. get { return _showTips; }
  114. set { _showTips = value; }
  115. }
  116. }
  117. }