import { _decorator, Component, Node, Label, Sprite, SpriteFrame, RichText } from 'cc'; import { DataSystem } from '../../core/data/DataSystem'; import { Http } from '../../core/net/Http'; import { ResourceLoader } from '../../core/resourceManager/ResourceLoader'; import List from '../../core/ui/virtualList/List'; import { StringUtils } from '../../core/utils/StringUtils'; import { ConfigData } from '../../data/ConfigData'; import { FormationData } from '../formation/FormationData'; import { UserHeroData } from '../UserHeroData'; import { HOFItem } from './HOFItem'; const { ccclass, property, requireComponent } = _decorator; /** * 名人堂 * @author 袁浩 */ @ccclass('HOF') @requireComponent(Http) export class HOF extends Component { @property({ tooltip: "名人堂列表", type: List }) public list: List; @property({ tooltip: "技能名称", type: Label }) public skillName: Label; @property({ tooltip: "技能图标", type: Sprite }) public skillSprite: Sprite; @property({ tooltip: "技能描述", type: RichText }) public descLabel: RichText; private hofList: { camp: number, heros: number[] }[]; /** * 当图鉴页面显示 */ public async onShow() { this.loadHeros(); let skillID = DataSystem.getData(ConfigData).get("fetter")[5].specificSkill; let skill = DataSystem.getData(ConfigData).get("skill")[skillID]; this.skillName.string = skill.name; this.descLabel.string = StringUtils.getRichText(skill.des); this.skillSprite.spriteFrame = await this.getComponent(ResourceLoader).load(`images/skill/${skill.icon}/spriteFrame`, SpriteFrame); } /** * 检查阵位的羁绊是否激活 */ private async checkFormationFetter() { let formationData = DataSystem.getData(FormationData); for (let i = 0; i < this.hofList.length; i++) { const specific = this.hofList[i]; let isFormationActive = true;//当前阵位是否激活 for (let j = 0; j < specific.heros.length; j++) { const heroID = specific.heros[j]; isFormationActive = isFormationActive && formationData.has(heroID); } if (isFormationActive) { return true; } } return false; } /** * 根据阵营加载英雄数据并展示到UI * @param camp 阵营 */ public async loadHeros() { let userHeroData = DataSystem.getData(UserHeroData); await userHeroData.pull(this.getComponent(Http)); let specificGroupConfig: string = DataSystem.getData(ConfigData).get("fetter")[5].specificGroup;//羁绊组合 let groupList = specificGroupConfig.split(";"); let list: { camp: number, heros: number[] }[] = []; for (let i = 0; i < groupList.length; i++) { const group = groupList[i]; let heroIDList = group.split(","); let specific: { camp: number, heros: number[] } = { camp: i + 1, heros: [] }; for (let j = 0; j < heroIDList.length; j++) { const heroID = parseInt(heroIDList[j]); specific.heros.push(heroID); specific.camp = DataSystem.getData(ConfigData).get("general")[heroID].camp; } list.push(specific); } this.hofList = list; this.list.numItems = list.length; } /** * 当列表项渲染 * @param item 项节点 * @param index 项索引 */ public onListRender(item: Node, index: number) { item.getComponent(HOFItem).onDataChange(this.hofList[index]); } }