CardGuideView.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using FairyGUI;
  4. using UI.FieldGuide;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. /// <summary>
  9. /// 词牌图鉴界面
  10. /// </summary>
  11. public class CardGuideView: BaseWindow
  12. {
  13. private UI_CardGuideUI _ui;
  14. private List<int> _cardList;
  15. public override void Dispose()
  16. {
  17. if(_ui != null)
  18. {
  19. _ui.Dispose();
  20. _ui = null;
  21. }
  22. base.Dispose();
  23. }
  24. protected override void OnInit()
  25. {
  26. base.OnInit();
  27. packageName = UI_CardGuideUI.PACKAGE_NAME;
  28. _ui = UI_CardGuideUI.Create();
  29. this.viewCom = _ui.target;
  30. isfullScreen = true;
  31. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("quanping_moren_bg");
  32. _cardList = new List<int>();
  33. _ui.m_listCard.itemRenderer = RenderCardListItem;
  34. _ui.m_listCard.onClickItem.Add(OnClickListCardItem);
  35. _ui.m_listRole.onClickItem.Add(OnClickRoleListItem);
  36. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  37. _ui.m_listRole.selectedIndex = 0;
  38. }
  39. protected override void AddEventListener()
  40. {
  41. base.AddEventListener();
  42. EventAgent.AddEventListener(ConstMessage.CARD_FILTER, UpdateCardList);
  43. EventAgent.AddEventListener(ConstMessage.CARD_INFO, UpdateCardList);
  44. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateCardList);
  45. }
  46. protected override void RemoveEventListener()
  47. {
  48. base.RemoveEventListener();
  49. EventAgent.RemoveEventListener(ConstMessage.CARD_FILTER, UpdateCardList);
  50. EventAgent.RemoveEventListener(ConstMessage.CARD_INFO, UpdateCardList);
  51. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateCardList);
  52. }
  53. protected override void OnShown()
  54. {
  55. base.OnShown();
  56. UpdateCardList();
  57. }
  58. protected override void OnHide()
  59. {
  60. base.OnHide();
  61. _ui.m_listRole.selectedIndex = 0;
  62. _ui.m_listRole.scrollPane.ScrollTop();
  63. }
  64. private void RenderCardListItem(int index, GObject obj)
  65. {
  66. CardData data = CardDataManager.GetCardDataById(_cardList[index]);
  67. UI_ListCardGuideItem listItem = UI_ListCardGuideItem.Proxy(obj);
  68. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cardList[index]);
  69. // Have
  70. if (data != null)
  71. {
  72. listItem.m_unlockMask.visible = false;
  73. listItem.m_comCard.m_loaCard.url = ResPathUtil.GetCardIconPath(data.resources[data.resIndex]);
  74. int starLevelDodge = data.star / 5;
  75. for (int i = 0; i < 4; i++)
  76. {
  77. UI_CardGuideComDodgeStar dodgeStar = UI_CardGuideComDodgeStar.Proxy(listItem.target.GetChild("dodgeStar" + i));
  78. dodgeStar.m_lightType.selectedIndex = (starLevelDodge > i) ? 1 : 0;
  79. UI_CardGuideComDodgeStar.ProxyEnd();
  80. }
  81. listItem.target.data = data;
  82. }
  83. else
  84. {
  85. listItem.m_comCard.m_loaCard.url = ResPathUtil.GetCardIconPath(itemCfg.res);
  86. listItem.m_unlockMask.visible = true;
  87. listItem.target.data = null;
  88. }
  89. RarityIconController.UpdateRarityIcon(listItem.m_loaRarity, itemCfg.id, false);// ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + data.itemCfg.rarity);
  90. listItem.m_loaMainScore.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (itemCfg.mainScore));
  91. listItem.m_loaBorder.url = "ui://CommonGame/kp_kuang_" + itemCfg.rarity;//ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + data.itemCfg.rarity);
  92. listItem.m_txtName.text = itemCfg.name;
  93. UI_ListCardGuideItem.ProxyEnd();
  94. }
  95. private void OnClickListCardItem(EventContext context)
  96. {
  97. object data = (context.data as GObject).data;
  98. int index = _ui.m_listCard.GetChildIndex(context.data as GObject);
  99. if(data == null)
  100. {
  101. object[] goBackDatas = ViewManager.GetGoBackDatas(typeof(CardGuideView).Name);
  102. object[] sourceDatas = new object[] { _cardList[index], goBackDatas, 1 };
  103. GoodsItemTipsController.ShowItemTips(_cardList[index], sourceDatas, false);
  104. }
  105. else
  106. {
  107. ViewManager.Show<CardFosterView>(new object[] { _cardList[index], typeof(CardGuideView).FullName}, new object[] { typeof(CardGuideView).FullName, _ui.m_listRole.selectedIndex });
  108. Hide();
  109. }
  110. }
  111. private void OnClickRoleListItem(EventContext eventContext)
  112. {
  113. UpdateCardList();
  114. _ui.m_listCard.scrollPane.ScrollTop();
  115. }
  116. private void UpdateCardList()
  117. {
  118. UpdateCardStatusView();
  119. _cardList = CardDataManager.GetAllCardIdListByRoleType(_ui.m_listRole.selectedIndex);
  120. _ui.m_listCard.numItems = _cardList.Count;
  121. }
  122. private void UpdateCardStatusView()
  123. {
  124. CardDataManager.GetTotalProgress(out int haveCount, out int totalCount, _ui.m_listRole.selectedIndex);
  125. _ui.m_progress.target.max = totalCount;
  126. _ui.m_progress.target.value = haveCount;
  127. _ui.m_progress.m_title1.SetVar("value", haveCount.ToString()).SetVar("max", totalCount.ToString()).FlushVars();
  128. _ui.m_progress.m_rate.SetVar("rate", FieldGuideView.ProgressCalculate(haveCount, totalCount).ToString()).FlushVars();
  129. }
  130. private void OnClickBtnBack()
  131. {
  132. ViewManager.GoBackFrom(typeof(CardGuideView).FullName);
  133. }
  134. }
  135. }