CardGuideView.cs 6.7 KB

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