CardGuideView.cs 6.3 KB

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