CardGuideView.cs 6.7 KB

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