CardDetailView.cs 5.8 KB

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