CardGuideView.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using FairyGUI;
  4. using UI.CommonGame;
  5. using UI.FieldGuide;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. /// <summary>
  10. /// 词牌图鉴界面
  11. /// </summary>
  12. public class CardGuideView: BaseWindow
  13. {
  14. private UI_CardGuideUI _ui;
  15. private List<int> _cardList;
  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. isReturnView = true;
  34. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("quanping_moren_bg");
  35. _cardList = new List<int>();
  36. _ui.m_listCard.itemRenderer = RenderCardListItem;
  37. _ui.m_listCard.onClickItem.Add(OnClickListCardItem);
  38. _ui.m_listRole.onClickItem.Add(OnClickRoleListItem);
  39. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  40. _ui.m_listRole.selectedIndex = 0;
  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 (backRefresh)
  61. {
  62. ResetSelectedItem();
  63. _ui.m_listCard.scrollPane.ScrollTop();
  64. _ui.m_In.Play();
  65. }
  66. }
  67. protected override void OnHide()
  68. {
  69. base.OnHide();
  70. }
  71. private void RenderCardListItem(int index, GObject obj)
  72. {
  73. UI_ListCardItem listItem = UI_ListCardItem.Proxy(obj);
  74. CardData data = CardDataManager.GetCardDataById(_cardList[index]);
  75. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cardList[index]);
  76. listItem.m_showType.selectedIndex = 1;
  77. // Have card
  78. if (data != null)
  79. {
  80. data.index = index;
  81. data.pageIndex = _ui.m_listRole.selectedIndex;
  82. listItem.m_unlockMask.visible = false;
  83. listItem.m_comCard.m_loaCard.url = ResPathUtil.GetCardIconPath(data.resources[data.resIndex]);
  84. int starLevelDodge = data.star / 5;
  85. listItem.m_txtLv.visible = false;
  86. for (int i = 0; i < 4; i++)
  87. {
  88. UI_ComDodgeStar dodgeStar = UI_ComDodgeStar.Proxy(listItem.target.GetChild("dodgeStar" + i));
  89. dodgeStar.m_lightType.selectedIndex = (starLevelDodge > i) ? 1 : 0;
  90. UI_ComDodgeStar.ProxyEnd();
  91. }
  92. listItem.target.data = data;
  93. }
  94. else
  95. {
  96. listItem.m_comCard.m_loaCard.url = ResPathUtil.GetCardIconPath(itemCfg.res);
  97. listItem.m_unlockMask.visible = true;
  98. listItem.target.data = null;
  99. }
  100. RarityIconController.UpdateRarityIcon(listItem.m_loaRarity, itemCfg.id, false);// ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + data.itemCfg.rarity);
  101. listItem.m_loaMainScore.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (itemCfg.mainScore));
  102. listItem.m_loaBorder.url = "ui://CommonGame/kp_kuang_" + itemCfg.rarity;//ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + data.itemCfg.rarity);
  103. listItem.m_txtName.text = itemCfg.name;
  104. UI_ListCardItem.ProxyEnd();
  105. }
  106. private void OnClickListCardItem(EventContext context)
  107. {
  108. object data = (context.data as GObject).data;
  109. int index = _ui.m_listCard.GetChildIndex(context.data as GObject);
  110. if (data == null)
  111. {
  112. object[] goBackDatas = ViewManager.GetGoBackDatas(typeof(CardGuideView).Name);
  113. object[] sourceDatas = new object[] { _cardList[index], goBackDatas, 1 };
  114. GoodsItemTipsController.ShowItemTips(_cardList[index], sourceDatas, false);
  115. }
  116. else
  117. {
  118. CardData cardData = CardDataManager.GetCardDataById(_cardList[index]);
  119. cardData.fromUIType = typeof(CardGuideView).FullName;
  120. ViewManager.Show<CardFosterView>(cardData, false, false);
  121. }
  122. }
  123. private void OnClickRoleListItem(EventContext eventContext)
  124. {
  125. if (_ui.m_listRole.selectedIndex == _lastClickIndex)
  126. {
  127. return;
  128. }
  129. _lastClickIndex = _ui.m_listRole.selectedIndex;
  130. UpdateCardList();
  131. _ui.m_listCard.scrollPane.ScrollTop();
  132. _ui.m_Refresh.Play();
  133. // 顶部选择菜单按钮的选中动画
  134. GObject gObject = eventContext.data as GObject;
  135. UI_Button21 button = UI_Button21.Proxy(gObject);
  136. button.m_fadeIn.Play();
  137. UI_Button21.ProxyEnd();
  138. }
  139. private void UpdateCardList()
  140. {
  141. UpdateCardStatusView();
  142. _cardList = CardDataManager.GetAllCardIdListByRoleType(_ui.m_listRole.selectedIndex);
  143. _ui.m_listCard.numItems = _cardList.Count;
  144. }
  145. private void UpdateCardStatusView()
  146. {
  147. CardDataManager.GetTotalProgress(out int haveCount, out int totalCount, _ui.m_listRole.selectedIndex);
  148. _ui.m_progress.target.max = totalCount;
  149. _ui.m_progress.target.value = haveCount;
  150. _ui.m_progress.m_title1.SetVar("value", haveCount.ToString()).SetVar("max", totalCount.ToString()).FlushVars();
  151. _ui.m_progress.m_rate.SetVar("rate", FieldGuideView.ProgressCalculate(haveCount, totalCount).ToString()).FlushVars();
  152. }
  153. private void OnClickBtnBack()
  154. {
  155. Hide();
  156. }
  157. private void ResetSelectedItem()
  158. {
  159. _ui.m_listRole.selectedIndex = 0;
  160. _lastClickIndex = 0;
  161. }
  162. }
  163. }