CardDetailView.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 UI_CardDetailUI _ui;
  12. private const int listRoleCount = 5;
  13. private int _mainScore = 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 AddEventListener()
  45. {
  46. base.AddEventListener();
  47. EventAgent.AddEventListener(ConstMessage.CARD_FILTER, UpdateCardList);
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  53. CardSProxy.GetCardInfos().Coroutine();
  54. int listRoleSelect = this.viewData != null ? (int)this.viewData : 0;
  55. _ui.m_listRole.selectedIndex = listRoleSelect;
  56. _ui.m_listRole.numItems = listRoleCount;
  57. this.UpdateCardList();
  58. Timers.inst.AddUpdate(CheckGuide);
  59. }
  60. protected override void OnHide()
  61. {
  62. base.OnHide();
  63. this.Clear();
  64. Timers.inst.Remove(CheckGuide);
  65. }
  66. protected override void RemoveEventListener()
  67. {
  68. base.RemoveEventListener();
  69. EventAgent.RemoveEventListener(ConstMessage.CARD_FILTER, UpdateCardList);
  70. }
  71. private void UpdateCardList()
  72. {
  73. List<CardData> cardList = CardDataManager.GetCardListByRarity(_ui.m_listRole.selectedIndex);
  74. if (CardDataManager.isFilter == true)
  75. {
  76. //筛选
  77. cardList = CardDataManager.FilterCardList(cardList);
  78. }
  79. _ui.m_listCard.data = cardList;
  80. _ui.m_listCard.numItems = cardList.Count;
  81. _ui.m_txtTips.visible = _ui.m_listCard.numItems == 0 ? true : false;
  82. }
  83. private void RenderListCardItem(int index, GObject obj)
  84. {
  85. UI_ListCardItem listItem = UI_ListCardItem.Proxy(obj);
  86. CardData data = (_ui.m_listCard.data as List<CardData>)[index];//CardDataManager.GetCardList(_ui.m_listRole.selectedIndex)[index];
  87. listItem.target.data = data;
  88. listItem.m_comCard.m_loaCard.url = ResPathUtil.GetCardSmallPath(data.resources[data.resIndex]);
  89. RarityIconController.UpdateRarityIcon(listItem.m_loaRarity, data.itemCfg.id, false);// ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + data.itemCfg.rarity);
  90. listItem.m_loaMainScore.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (data.itemCfg.mainScore));
  91. listItem.m_loaBorder.url = "ui://Card/kp_kuang_" + data.itemCfg.rarity;//ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + data.itemCfg.rarity);
  92. listItem.m_txtLv.text = data.lv + "级";
  93. listItem.m_txtName.text = data.itemCfg.name;
  94. UI_ComStar comStar = UI_ComStar.Proxy(listItem.m_comStar);
  95. comStar.m_c1.selectedIndex = data.star;
  96. UI_ComStar.ProxyEnd();
  97. UI_ListCardItem.ProxyEnd();
  98. }
  99. private void OnClickListCardItem(EventContext context)
  100. {
  101. ViewManager.Show(ViewName.CARD_FOSTER_VIEW, (context.data as GObject).data, new object[] { ViewName.CARD_DETAIL_VIEW, _ui.m_listRole.selectedIndex });
  102. // this.Clear();
  103. }
  104. private void RenderListRoleItem(int index, GObject obj)
  105. {
  106. obj.data = index == 0 ? 0 : index;
  107. }
  108. private void OnClickListRoleItem(EventContext context)
  109. {
  110. int index = (int)(context.data as GObject).data;
  111. this.UpdateCardList();
  112. }
  113. /*******************************************************监听函数**************************************************/
  114. private void OnclickBtnFilter()
  115. {
  116. ViewManager.Show(ViewName.CARD_FILTER_VIEW, null, new object[] { ViewName.CARD_DETAIL_VIEW, _ui.m_listRole.selectedIndex });
  117. }
  118. private void OnClickBtnBack()
  119. {
  120. ViewManager.GoBackFrom(ViewName.CARD_DETAIL_VIEW);
  121. }
  122. private void OnClickBtnHome()
  123. {
  124. GameController.GoBackToMainView();
  125. }
  126. private void Clear()
  127. {
  128. // this._selectType = 0;
  129. CardDataManager._selectList.Clear();
  130. _ui.m_listRole.selectedIndex = 0;
  131. _ui.m_listCard.selectedIndex = 0;
  132. }
  133. private void CheckGuide(object param)
  134. {
  135. if (GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_LV) <= 0)
  136. {
  137. UpdateToCheckGuide(null);
  138. }
  139. else
  140. {
  141. Timers.inst.Remove(CheckGuide);
  142. }
  143. }
  144. protected override void UpdateToCheckGuide(object param)
  145. {
  146. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  147. GuideController.TryGuide(_ui.m_listCard, ConstGuideId.UP_CARD_LV, 3, "选择可升级的词牌。", 0, true, 0, 0, 0, true, true);
  148. }
  149. }
  150. }