StoryCardChoose.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Collections.Generic;
  2. using FairyGUI;
  3. using UI.CommonGame;
  4. using UI.Main;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class StoryCardChoose : BaseWindow
  9. {
  10. private UI_StoryCardChooseUI _ui;
  11. private List<CardData> cardList = new List<CardData>();
  12. private static int _scoreType;
  13. public override void Dispose()
  14. {
  15. base.Dispose();
  16. }
  17. protected override void OnInit()
  18. {
  19. base.OnInit();
  20. packageName = UI_StoryCardChooseUI.PACKAGE_NAME;
  21. _ui = UI_StoryCardChooseUI.Create();
  22. this.viewCom = _ui.target;
  23. this.viewCom.Center();
  24. this.modal = true;
  25. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  26. _ui.m_listCard.SetVirtual();
  27. _ui.m_listCard.itemRenderer = RenderListCardItem;
  28. _ui.m_btnCancel.onClick.Add(OnBtnCancelClick);
  29. _ui.m_btnConfirm.onClick.Add(OnBtnComfirmClick);
  30. _ui.m_listCard.onClickItem.Add(OnListCardItemClick);
  31. }
  32. protected override void OnShown()
  33. {
  34. base.OnShown();
  35. _scoreType = (int)viewData;
  36. cardList = CardDataManager.CardDicToList(CardDataManager.GetCardDicByRarity(0));
  37. cardList = SortCardList(cardList);
  38. _ui.m_listCard.numItems = cardList.Count;
  39. _ui.m_listCard.selectedIndex = 0;
  40. UpdateView(0);
  41. GuideController.TryGuideStoryCardChoose(_ui.m_listCard);
  42. }
  43. private void UpdateView(int index)
  44. {
  45. int cardId = cardList[index].id;
  46. PassivitySkillCfg cfg = ScoreSystemData.Instance.GetShowSkillCfg(cardId);
  47. _ui.m_txtName.text = cfg == null ? "" : cfg.name;
  48. _ui.m_txtDiscribe.text = cfg == null ? "" : cfg.describe1;
  49. _ui.m_loaScore.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + _scoreType);
  50. }
  51. private void RenderListCardItem(int index, GObject obj)
  52. {
  53. GButton item = obj as GButton;
  54. item.GetChild("txtName").asTextField.text = cardList[index].itemCfg.name;
  55. item.GetChild("comCardMask").asCom.GetChild("loaCard").asLoader.url = ResPathUtil.GetCardSmallPath(cardList[index].res);
  56. item.GetChild("txtLv").asTextField.text = string.Format("Lv.\n{0}", cardList[index].lv);
  57. item.GetChild("loaRarity").asLoader.url = ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + (5 - cardList[index].itemCfg.rarity));
  58. UI_ComStar comStar = UI_ComStar.Proxy(item.GetChild("comStar").asCom);
  59. comStar.m_c1.selectedIndex = cardList[index].star;
  60. }
  61. private void OnListCardItemClick(EventContext context)
  62. {
  63. UpdateView(_ui.m_listCard.selectedIndex);
  64. GuideController.TryGuideStoryCardChooseBtnConfirm(_ui.m_btnConfirm);
  65. }
  66. private void OnBtnComfirmClick()
  67. {
  68. int cardId = cardList[_ui.m_listCard.selectedIndex].id;
  69. PassivitySkillCfg[] cfgs = PassivitySkillCfgArray.Instance.GetCfgs(cardId);
  70. StoryDataManager.currentCardId = cfgs.Length > 0 ? cardId : -1;
  71. this.Hide();
  72. EventAgent.DispatchEvent(ConstMessage.CARD_CHOOSE);
  73. GuideController.HideGuide();
  74. GuideController.TryCompleteGuide(ConstGuideId.USE_CARD_FIGHT);
  75. }
  76. private static List<CardData> SortCardList(List<CardData> arrayList)
  77. {
  78. arrayList.Sort((CardData a, CardData b) =>
  79. {
  80. int scoreA = ItemDataManager.GetItemScoreValue(a.id, _scoreType);
  81. int scoreB = ItemDataManager.GetItemScoreValue(b.id, _scoreType);
  82. if (scoreA < scoreB)
  83. {
  84. return 1;
  85. }
  86. else if (scoreA > scoreB)
  87. {
  88. return -1;
  89. }
  90. return string.Compare(a.itemCfg.res, b.itemCfg.res);
  91. });
  92. return arrayList;
  93. }
  94. private void OnBtnCancelClick()
  95. {
  96. this.Hide();
  97. }
  98. protected override void OnHide()
  99. {
  100. base.OnHide();
  101. }
  102. }
  103. }