CardDetailView.cs 5.0 KB

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