HOF.ts 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { _decorator, Component, Node, Label, Sprite, SpriteFrame, RichText } from 'cc';
  2. import { DataSystem } from '../../core/data/DataSystem';
  3. import { Http } from '../../core/net/Http';
  4. import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
  5. import List from '../../core/ui/virtualList/List';
  6. import { StringUtils } from '../../core/utils/StringUtils';
  7. import { ConfigData } from '../../data/ConfigData';
  8. import { FormationData } from '../formation/FormationData';
  9. import { UserHeroData } from '../UserHeroData';
  10. import { HOFItem } from './HOFItem';
  11. const { ccclass, property, requireComponent } = _decorator;
  12. /**
  13. * 名人堂
  14. * @author 袁浩
  15. */
  16. @ccclass('HOF')
  17. @requireComponent(Http)
  18. export class HOF extends Component {
  19. @property({ tooltip: "名人堂列表", type: List })
  20. public list: List;
  21. @property({ tooltip: "技能名称", type: Label })
  22. public skillName: Label;
  23. @property({ tooltip: "技能图标", type: Sprite })
  24. public skillSprite: Sprite;
  25. @property({ tooltip: "技能描述", type: RichText })
  26. public descLabel: RichText;
  27. private hofList: { camp: number, heros: number[] }[];
  28. /**
  29. * 当图鉴页面显示
  30. */
  31. public async onShow() {
  32. this.loadHeros();
  33. let skillID = DataSystem.getData(ConfigData).get("fetter")[5].specificSkill;
  34. let skill = DataSystem.getData(ConfigData).get("skill")[skillID];
  35. this.skillName.string = skill.name;
  36. this.descLabel.string = StringUtils.getRichText(skill.des);
  37. this.skillSprite.spriteFrame = await this.getComponent(ResourceLoader).load(`images/skill/${skill.icon}/spriteFrame`, SpriteFrame);
  38. }
  39. /**
  40. * 检查阵位的羁绊是否激活
  41. */
  42. private async checkFormationFetter() {
  43. let formationData = DataSystem.getData(FormationData);
  44. for (let i = 0; i < this.hofList.length; i++) {
  45. const specific = this.hofList[i];
  46. let isFormationActive = true;//当前阵位是否激活
  47. for (let j = 0; j < specific.heros.length; j++) {
  48. const heroID = specific.heros[j];
  49. isFormationActive = isFormationActive && formationData.has(heroID);
  50. }
  51. if (isFormationActive) {
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57. /**
  58. * 根据阵营加载英雄数据并展示到UI
  59. * @param camp 阵营
  60. */
  61. public async loadHeros() {
  62. let userHeroData = DataSystem.getData(UserHeroData);
  63. await userHeroData.pull(this.getComponent(Http));
  64. let specificGroupConfig: string = DataSystem.getData(ConfigData).get("fetter")[5].specificGroup;//羁绊组合
  65. let groupList = specificGroupConfig.split(";");
  66. let list: { camp: number, heros: number[] }[] = [];
  67. for (let i = 0; i < groupList.length; i++) {
  68. const group = groupList[i];
  69. let heroIDList = group.split(",");
  70. let specific: { camp: number, heros: number[] } = { camp: i + 1, heros: [] };
  71. for (let j = 0; j < heroIDList.length; j++) {
  72. const heroID = parseInt(heroIDList[j]);
  73. specific.heros.push(heroID);
  74. specific.camp = DataSystem.getData(ConfigData).get("general")[heroID].camp;
  75. }
  76. list.push(specific);
  77. }
  78. this.hofList = list;
  79. this.list.numItems = list.length;
  80. }
  81. /**
  82. * 当列表项渲染
  83. * @param item 项节点
  84. * @param index 项索引
  85. */
  86. public onListRender(item: Node, index: number) {
  87. item.getComponent(HOFItem).onDataChange(this.hofList[index]);
  88. }
  89. }