CardStarRewardView.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using FairyGUI;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using cfg.GfgCfg;
  5. using UI.Card;
  6. using UnityEngine;
  7. using YooAsset;
  8. namespace GFGGame
  9. {
  10. public class CardStarRewardView : BaseWindow
  11. {
  12. private UI_CardStarRewardUI _ui;
  13. private List<CardStarCfg> _cardStarRewards;
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_CardStarRewardUI.PACKAGE_NAME;
  27. _ui = UI_CardStarRewardUI.Create();
  28. this.viewCom = _ui.target;
  29. this.viewCom.Center();
  30. this.modal = true;
  31. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  32. _ui.m_listReward.itemRenderer = RenderListStarRewardItem;
  33. }
  34. protected override void AddEventListener()
  35. {
  36. base.AddEventListener();
  37. EventAgent.AddEventListener(ConstMessage.CARD_STAR_REWARD, UpdateView);
  38. }
  39. protected override void OnShown()
  40. {
  41. base.OnShown();
  42. _cardStarRewards = this.viewData as List<CardStarCfg>;
  43. UpdateView();
  44. }
  45. protected override void OnHide()
  46. {
  47. base.OnHide();
  48. }
  49. protected override void RemoveEventListener()
  50. {
  51. base.RemoveEventListener();
  52. EventAgent.RemoveEventListener(ConstMessage.CARD_STAR_REWARD, UpdateView);
  53. }
  54. private void UpdateView()
  55. {
  56. _ui.m_listReward.numItems = _cardStarRewards.Count;
  57. }
  58. private void RenderListStarRewardItem(int index, GObject obj)
  59. {
  60. UI_ListCardStarRewardItem item = UI_ListCardStarRewardItem.Proxy(obj);
  61. CardStarCfg cardStarCfg = _cardStarRewards[index];
  62. CardData cardData = CardDataManager.GetCardDataById(cardStarCfg.CardId);
  63. if (index == 0)
  64. {
  65. item.m_txtTitle.text = "激活词牌";
  66. }
  67. else
  68. {
  69. item.m_txtTitle.text =
  70. string.Format("词牌星级达到{0}星", NumberUtil.GetChiniseNumberText(cardStarCfg.StarLvl / 5));
  71. }
  72. string resPath = ResPathUtil.GetCardAnimationPath(cardData.resources[cardData.resIndex]);
  73. if (index == 1 && YooAssetsEx.CheckResExist(resPath))
  74. {
  75. item.m_txtTips.visible = true;
  76. }
  77. else
  78. {
  79. item.m_txtTips.visible = false;
  80. }
  81. item.m_c1.selectedIndex = cardData.starRewardsState.ContainsKey(cardStarCfg.StarLvl)
  82. ? cardData.starRewardsState[cardStarCfg.StarLvl]
  83. : 0;
  84. if (item.m_btnGet.data == null)
  85. {
  86. item.m_btnGet.onClick.Add(OnClickBtnGet);
  87. }
  88. item.m_btnGet.data = cardStarCfg;
  89. ItemData reward = ItemUtil.createItemData(cardStarCfg.Rewards[0].ToGfgGameItemParam());
  90. if (item.m_comItem.data == null)
  91. {
  92. item.m_comItem.data = new ItemView(item.m_comItem);
  93. }
  94. (item.m_comItem.data as ItemView).SetData(reward);
  95. UI_ListCardStarRewardItem.ProxyEnd();
  96. }
  97. private void OnClickBtnGet(EventContext context)
  98. {
  99. GObject obj = context.sender as GObject;
  100. CardStarCfg cardStarCfg = obj.data as CardStarCfg;
  101. CardSProxy.GetCardStarBonus(cardStarCfg.CardId, cardStarCfg.StarLvl).Coroutine();
  102. }
  103. }
  104. }