CardStarRewardView.cs 3.4 KB

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