CardDetailView.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.FieldGuide;
  4. using UI.Card;
  5. using UI.CommonGame;
  6. using System.Collections.Generic;
  7. namespace GFGGame
  8. {
  9. public class CardDetailView : BaseView
  10. {
  11. private const int listRoleCount = 5;
  12. private UI_CardDetailUI _ui;
  13. public override void Dispose()
  14. {
  15. for (int i = 0; i < _ui.m_listCard.numItems; i++)
  16. {
  17. UI_ListCardItem listItem = UI_ListCardItem.Proxy(_ui.m_listCard.GetChildAt(i));
  18. listItem.m_comCard.m_loaCard.Dispose();
  19. UI_ListCardItem.ProxyEnd();
  20. }
  21. _ui.m_loaBg.Dispose();
  22. if (_ui != null)
  23. {
  24. _ui.Dispose();
  25. }
  26. _ui = null;
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. packageName = UI_CardDetailUI.PACKAGE_NAME;
  33. _ui = UI_CardDetailUI.Create();
  34. viewCom = _ui.target;
  35. isfullScreen = true;
  36. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  37. _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  38. _ui.m_btnFilter.onClick.Add(OnclickBtnFilter);
  39. _ui.m_listCard.itemRenderer = RenderListCardItem;
  40. _ui.m_listCard.onClickItem.Add(OnClickListCardItem);
  41. _ui.m_listCard.SetVirtual();
  42. _ui.m_listRole.itemRenderer = RenderListRoleItem;
  43. _ui.m_listRole.onClickItem.Add(OnClickListRoleItem);
  44. _ui.m_listRole.selectedIndex = 0;
  45. // EventAgent.AddEventListener(ConstMessage.CARD_REFRESH, () =>
  46. // {
  47. // UpdateCardList(_ui.m_listRole.selectedIndex);
  48. // });
  49. }
  50. protected override void OnShown()
  51. {
  52. base.OnShown();
  53. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  54. CardSProxy.GetCardInfos().Coroutine();
  55. int listRoleSelect = this.viewData != null ? (int)this.viewData : 0;
  56. _ui.m_listRole.selectedIndex = listRoleSelect;
  57. _ui.m_listRole.numItems = listRoleCount;
  58. this.UpdateCardList((int)_ui.m_listRole.GetChildAt(_ui.m_listRole.selectedIndex).data);
  59. Timers.inst.AddUpdate(CheckGuide);
  60. }
  61. private void UpdateCardList(int mainScore = 0)
  62. {
  63. List<CardData> cardList = CardDataManager.GetCardListByRarity(mainScore);
  64. if (CardDataManager._selectList.Keys.Count > 0)
  65. {
  66. //筛选
  67. cardList = CardDataManager.FilterCardList(cardList, CardDataManager._selectList as Dictionary<int, Dictionary<int, int>>);
  68. }
  69. _ui.m_listCard.data = cardList;
  70. _ui.m_listCard.numItems = cardList.Count;
  71. _ui.m_txtTips.visible = _ui.m_listCard.numItems == 0 ? true : false;
  72. }
  73. private void RenderListCardItem(int index, GObject obj)
  74. {
  75. UI_ListCardItem listItem = UI_ListCardItem.Proxy(obj);
  76. CardData data = (_ui.m_listCard.data as List<CardData>)[index];//CardDataManager.GetCardList(_ui.m_listRole.selectedIndex)[index];
  77. listItem.target.data = data;
  78. listItem.m_comCard.m_loaCard.url = ResPathUtil.GetCardSmallPath(data.resources[data.resIndex]);
  79. RarityIconController.UpdateRarityIcon(listItem.m_loaRarity, data.itemCfg.id, false);// ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + data.itemCfg.rarity);
  80. listItem.m_loaMainScore.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (data.itemCfg.mainScore));
  81. listItem.m_loaBorder.url = "ui://Card/kp_kuang_" + data.itemCfg.rarity;//ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + data.itemCfg.rarity);
  82. listItem.m_txtLv.text = "Lv.\n" + data.lv;
  83. listItem.m_txtName.text = data.itemCfg.name;
  84. UI_ComStar comStar = UI_ComStar.Proxy(listItem.m_comStar);
  85. comStar.m_c1.selectedIndex = data.star;
  86. UI_ComStar.ProxyEnd();
  87. UI_ListCardItem.ProxyEnd();
  88. }
  89. private void OnClickListCardItem(EventContext context)
  90. {
  91. ViewManager.Show(ViewName.CARD_FOSTER_VIEW, (context.data as GObject).data, new object[] { ViewName.CARD_DETAIL_VIEW, _ui.m_listRole.selectedIndex });
  92. // this.Clear();
  93. }
  94. private void RenderListRoleItem(int index, GObject obj)
  95. {
  96. obj.data = index == 0 ? 0 : index;
  97. }
  98. private void OnClickListRoleItem(EventContext context)
  99. {
  100. int index = (int)(context.data as GObject).data;
  101. this.UpdateCardList(index);
  102. }
  103. /*******************************************************监听函数**************************************************/
  104. private void OnclickBtnFilter()
  105. {
  106. ViewManager.Show(ViewName.CARD_FILTER_VIEW, null, new object[] { ViewName.CARD_DETAIL_VIEW, _ui.m_listRole.selectedIndex });
  107. }
  108. private void OnClickBtnBack()
  109. {
  110. ViewManager.GoBackFrom(ViewName.CARD_DETAIL_VIEW);
  111. }
  112. private void OnClickBtnHome()
  113. {
  114. GameController.GoBackToMainView();
  115. }
  116. private void Clear()
  117. {
  118. // this._selectType = 0;
  119. CardDataManager._selectList.Clear();
  120. _ui.m_listRole.selectedIndex = 0;
  121. _ui.m_listCard.selectedIndex = 0;
  122. }
  123. protected override void OnHide()
  124. {
  125. base.OnHide();
  126. this.Clear();
  127. Timers.inst.Remove(CheckGuide);
  128. }
  129. private void CheckGuide(object param)
  130. {
  131. if (GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_LV) <= 0)
  132. {
  133. UpdateToCheckGuide(null);
  134. }
  135. else
  136. {
  137. Timers.inst.Remove(CheckGuide);
  138. }
  139. }
  140. protected override void UpdateToCheckGuide(object param)
  141. {
  142. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  143. GuideController.TryGuide(_ui.m_listCard, ConstGuideId.UP_CARD_LV, 3, "选择可升级的词牌", 0, true, 0, 0, 0, true, true);
  144. }
  145. }
  146. }