StoryCardChoose.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using FairyGUI;
  5. using UI.CommonGame;
  6. using UI.Main;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. public class StoryCardChoose : BaseWindow
  11. {
  12. private UI_StoryCardChooseUI _ui;
  13. private List<CardData> cardList = new List<CardData>();
  14. private static int _scoreType;
  15. private int _selectedIndex = 0;
  16. private int _cardId = 0; //记录打开界面时的竞技场卡牌id
  17. private int _skillId = 0;
  18. private List<GameObject> _effects = new List<GameObject>();
  19. private List<GoWrapper> _wrappers = new List<GoWrapper>();
  20. private GameObject gameObject0;
  21. private GoWrapper wrapper0;
  22. private GComponent _comSelected;
  23. public override void Dispose()
  24. {
  25. base.Dispose();
  26. if (_comSelected != null)
  27. {
  28. _comSelected.RemoveFromParent();
  29. _comSelected.Dispose();
  30. }
  31. for (int i = 0; i < _effects.Count; i++)
  32. {
  33. SceneController.DestroyObjectFromView(_effects[i], _wrappers[i]);
  34. }
  35. if (_ui != null)
  36. {
  37. _ui.Dispose();
  38. _ui = null;
  39. }
  40. }
  41. protected override void OnInit()
  42. {
  43. base.OnInit();
  44. packageName = UI_StoryCardChooseUI.PACKAGE_NAME;
  45. _ui = UI_StoryCardChooseUI.Create();
  46. this.viewCom = _ui.target;
  47. this.viewCom.Center();
  48. this.modal = true;
  49. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  50. _ui.m_listCard.SetVirtual();
  51. _ui.m_listCard.itemRenderer = RenderListCardItem;
  52. _ui.m_listCard.onClickItem.Add(OnListCardItemClick);
  53. _ui.m_listSkill.itemRenderer = RenderListSkillItem;
  54. _ui.m_btnCancel.onClick.Add(OnBtnCancelClick);
  55. _ui.m_btnConfirm.onClick.Add(OnBtnComfirmClick);
  56. _ui.m_btnUpCard.onClick.Add(OnBtnUpCardClikc);
  57. _comSelected = UIPackage.CreateObject(UI_MainUI.PACKAGE_NAME, "ComCardSelect").asCom;
  58. // string resPath = ResPathUtil.GetViewEffectPath("ui_fight_new", "kp_Select");
  59. // SceneController.AddObjectToView(gameObject0, null, _comSelected.GetChild("holder").asGraph, resPath, out gameObject0, out wrapper0);
  60. }
  61. protected override void OnShown()
  62. {
  63. base.OnShown();
  64. _scoreType = (int)viewData;
  65. ArenaDataManager dataManager = ArenaDataManager.Instance;
  66. //其他主题带的cardIds
  67. var otherThemeCardIds = new HashSet<int>();
  68. for (int i = 0; i < dataManager.DressupList.Count; i++)
  69. {
  70. if (dataManager.SelectThemeIndex == i)
  71. {
  72. continue;
  73. }
  74. otherThemeCardIds.Add(dataManager.DressupList[i].cardId);
  75. }
  76. cardList = CardDataManager.GetCardListByRarity(0);
  77. //去掉已经在其他主题装配的cardList
  78. cardList = cardList.Where(a => !otherThemeCardIds.Contains(a.id)).ToList();
  79. float dressListAllAcore =
  80. FightDataManager.Instance.GetDressListAllScore(MyDressUpHelper.dressUpObj.itemList, _scoreType);
  81. cardList = FightDataManager.Instance.SortCardList(cardList, dressListAllAcore, _scoreType);
  82. _ui.m_listCard.numItems = cardList.Count;
  83. _ui.m_listCard.selectedIndex = 0;
  84. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  85. {
  86. _cardId = dataManager.DressupList[dataManager.SelectThemeIndex].cardId;
  87. }
  88. OnCardSelected(cardList[0].id);
  89. UpdateView(0);
  90. Timers.inst.AddUpdate(CheckGuide);
  91. }
  92. private void UpdateView(int index)
  93. {
  94. // CardData cardData = cardList[index];
  95. _ui.m_loaScore.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + _scoreType);
  96. int cardId = cardList[index].id;
  97. _ui.m_txtName.text = "";
  98. PassivitySkillCfg cfg = ScoreSystemData.Instance.GetShowSkillCfg(cardId);
  99. if (cfg == null) return;
  100. _ui.m_txtName.text = cardList[index].itemCfg.name;
  101. List<PassivitySkillCfg> skillCfgs = PassivitySkillCfgArray.Instance.GetCfgsBycardId(cardId);
  102. _ui.m_listSkill.data = skillCfgs;
  103. _ui.m_listSkill.numItems = skillCfgs.Count;
  104. _ui.m_comSkillTips.target.visible = false;
  105. _selectedIndex = index;
  106. int childIndex = _ui.m_listCard.ItemIndexToChildIndex(index);
  107. _ui.m_listCard.GetChildAt(childIndex).asCom.AddChild(_comSelected);
  108. }
  109. private void RenderListSkillItem(int index, GObject obj)
  110. {
  111. List<PassivitySkillCfg> skillCfgs = obj.parent.data as List<PassivitySkillCfg>;
  112. UI_ListCardSkillItem item = UI_ListCardSkillItem.Proxy(obj);
  113. item.m_loaSkill.url = ResPathUtil.GetCardSkillPath(skillCfgs[index].res);
  114. item.m_txtLv.text = SkillDataManager.Instance
  115. .GetCardSkillLv(skillCfgs[index].cardId, skillCfgs[index].skillId).ToString();
  116. if (item.target.data == null)
  117. {
  118. item.target.onClick.Add(OnSkillItemClick);
  119. }
  120. item.target.data = index; // skillCfgs[index];
  121. UI_ListCardSkillItem.ProxyEnd();
  122. }
  123. private void OnSkillItemClick(EventContext context)
  124. {
  125. GObject gObject = context.sender as GObject;
  126. int index = (int)gObject.data;
  127. List<PassivitySkillCfg> skillCfgs =
  128. PassivitySkillCfgArray.Instance.GetCfgsBycardId(cardList[_selectedIndex].id);
  129. PassivitySkillCfg skillCfg = skillCfgs[index];
  130. _ui.m_comSkillTips.target.visible = _skillId != skillCfg.skillId;
  131. Vector2 posInA = _ui.m_listSkill.GetChildAt(index).asCom.position;
  132. Vector2 posInB = _ui.m_listSkill.TransformPoint(posInA, _ui.target);
  133. _ui.m_comSkillTips.target.SetPosition(posInB.x, posInB.y + 110, 0);
  134. _ui.m_comSkillTips.m_txtName.text = skillCfg.name;
  135. int skillLv = SkillDataManager.Instance.GetCardSkillLv(skillCfg.cardId, skillCfg.skillId);
  136. PassivitySkillLvlCfg skillLvlCfg =
  137. PassivitySkillLvlCfgArray.Instance.GetCfgByskilllvlAndskillId(skillLv, skillCfg.skillId);
  138. _ui.m_comSkillTips.m_txtSkillTips.text = skillLvlCfg.describe;
  139. _skillId = skillCfg.skillId;
  140. }
  141. private void RenderListCardItem(int index, GObject obj)
  142. {
  143. CardData cardData = cardList[index];
  144. UI_ListCardItem item = UI_ListCardItem.Proxy(obj); // obj as GButton;
  145. item.m_txtName.text = cardData.itemCfg.name;
  146. item.m_comCardMask.m_loaCard.asLoader.url =
  147. ResPathUtil.GetCardIconPath(cardData.resources[cardData.resIndex]);
  148. item.m_txtLv.text = string.Format("{0}级", cardData.lv);
  149. // item.m_loaRarity.url = ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + cardData.itemCfg.rarity);
  150. RarityIconController.UpdateRarityIcon(item.m_loaRarity, cardData.itemCfg.id,
  151. false); // ResPathUtil.GetCommonGameResPath("kp_sxing_x_" + data.itemCfg.rarity);
  152. item.m_loaMainScore.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (cardData.itemCfg.mainScore));
  153. item.m_loaBorder.url = "ui://CommonGame/kp_kuang_" + cardData.itemCfg.rarity;
  154. // UI_ComStar comStar = UI_ComStar.Proxy(item.m_comStar);
  155. item.m_txtStarLv.text = cardData.star.ToString();
  156. // comStar.m_c1.selectedIndex = cardData.star;
  157. if (_effects.Count <= index)
  158. {
  159. string resPath = ResPathUtil.GetViewEffectPath("ui_fight_new", "kp_Select");
  160. GameObject gameObject0;
  161. GoWrapper wrapper0;
  162. // SceneController.AddObjectToView(null, null, item.m_comEff.m_holder, resPath, out gameObject0, out wrapper0);
  163. // _effects.Add(gameObject0);
  164. // _wrappers.Add(wrapper0);
  165. }
  166. UI_ListCardItem.ProxyEnd();
  167. // UI_ComStar.ProxyEnd();
  168. }
  169. private void OnListCardItemClick(EventContext context)
  170. {
  171. UpdateView(_ui.m_listCard.selectedIndex);
  172. OnCardSelected(cardList[_ui.m_listCard.selectedIndex].id);
  173. }
  174. private void OnCardSelected(int cardId)
  175. {
  176. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  177. {
  178. ArenaDataManager dataManager = ArenaDataManager.Instance;
  179. dataManager.DressupList[dataManager.SelectThemeIndex].cardId = cardId;
  180. dataManager.SetMineFightAttr(dataManager.DressupList[dataManager.SelectThemeIndex],
  181. dataManager.SelectThemeIndex);
  182. EventAgent.DispatchEvent(ConstMessage.CARD_SELECTED);
  183. }
  184. }
  185. private void OnBtnUpCardClikc()
  186. {
  187. ViewManager.Show<CardFosterView>(cardList[_ui.m_listCard.selectedIndex],
  188. new object[] { typeof(StoryCardChoose).FullName, _scoreType });
  189. this.Hide();
  190. }
  191. private void OnBtnComfirmClick()
  192. {
  193. int cardId = cardList[_ui.m_listCard.selectedIndex].id;
  194. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  195. {
  196. ArenaDataManager dataManager = ArenaDataManager.Instance;
  197. ArenaSproxy.ReqChangeArenaDressup(dataManager.SelectThemeIndex, cardId,
  198. MyDressUpHelper.dressUpObj.itemList).Coroutine();
  199. if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
  200. {
  201. ViewManager.GoBackFrom(typeof(ArenaDressUpFightView).FullName);
  202. }
  203. }
  204. else
  205. {
  206. List<PassivitySkillCfg> cfgs = PassivitySkillCfgArray.Instance.GetCfgsBycardId(cardId);
  207. InstanceZonesDataManager.currentCardId = cfgs.Count > 0 ? cardId : -1;
  208. EventAgent.DispatchEvent(ConstMessage.CARD_CHOOSE);
  209. }
  210. this.Hide();
  211. }
  212. private void OnBtnCancelClick()
  213. {
  214. OnCardSelected(_cardId);
  215. this.Hide();
  216. }
  217. protected override void OnHide()
  218. {
  219. base.OnHide();
  220. _skillId = 0;
  221. _ui.m_listCard.ScrollToView(0);
  222. Timers.inst.Remove(CheckGuide);
  223. }
  224. private void CheckGuide(object param)
  225. {
  226. if (GuideDataManager.IsGuideFinish(ConstGuideId.SKILL_CARD_FIGHT) <= 0)
  227. {
  228. UpdateToCheckGuide(null);
  229. }
  230. else
  231. {
  232. Timers.inst.Remove(CheckGuide);
  233. }
  234. }
  235. protected override void UpdateToCheckGuide(object param)
  236. {
  237. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  238. GuideController.TryGuide(null, ConstGuideId.SKILL_CARD_FIGHT, 1, "词牌可以辅助战斗,增加过关概率哦。", -1, true,
  239. _ui.m_btnCancel.y + _ui.m_btnCancel.height);
  240. GuideController.TryGuide(_ui.m_listCard, ConstGuideId.SKILL_CARD_FIGHT, 2, "选择一张合适的词牌,增加过关战斗力。", 0);
  241. GuideController.TryCompleteGuide(ConstGuideId.SKILL_CARD_FIGHT, 2);
  242. }
  243. }
  244. }