// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import { ItemName, PopName } from "../EventName/EventName"; import HTTPS, { NetGet } from "../Template/HTTPS"; import PopComponet from "../Template/PopComponet"; import HonorManger, { HonorWallDetailsType } from "./HonorManger"; import HonorWallitem from "./HonorWallitem"; import PopManger from "./PopManger"; import Privacy from "./Privacy"; const { ccclass, property } = cc._decorator; @ccclass export default class HonorWall extends PopComponet { @property(cc.Node) Itemparent: cc.Node = null @property(cc.Label) progressLabel: cc.Label = null onLoad() { this.node.on('ClickItem', this.ClickItem, this) } onDestroy(): void { this.node.off('ClickItem', this.ClickItem, this) } ClickItem(event) { // 处理事件 let data = event.getUserData(); // 获取自定义数据 let Title = this.node.getChildByName("Title") let Bg = Title.getChildByName("Bg") let Sp = Title.getChildByName("Sp") let Name = Title.getChildByName("Name") let Detail = Title.getChildByName("Detail") Bg.active = true Sp.active = true Name.active = true Detail.active = true; Name.getComponent(cc.Label).string = (data.MyType).Name Detail.getComponent(cc.Label).string = (data.MyType).Description Sp.getComponent(cc.Sprite).spriteFrame = (data.sp).spriteFrame if ((data.Gray)) { // @ts-ignore Sp.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null)) Bg.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null)) } else { // @ts-ignore Sp.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null)) Bg.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null)) } } start() { this.init() } init() { this.initDisPlay() this.initIconItem() } initDisPlay() { let HonorDataAll = [ ...HonorManger.getInstance().HonorWallDetails_Shangban, ...HonorManger.getInstance().HonorWallDetails_ChiDao, ...HonorManger.getInstance().HonorWallDetails_Qita]; let d = HonorDataAll.filter(e => { return HonorManger.getInstance().SelectHonorM == e.Id }) let Title = this.node.getChildByName("Title") let Bg = Title.getChildByName("Bg") let Sp = Title.getChildByName("Sp") let Name = Title.getChildByName("Name") let Detail = Title.getChildByName("Detail") //如果有值 if (HonorManger.getInstance().SelectHonorM > 0) { Bg.active = true Sp.active = true Name.active = true Detail.active = true Name.getComponent(cc.Label).string = d[0].Name Detail.getComponent(cc.Label).string = d[0].Description } else { Bg.active = false Sp.active = false Name.active = false Detail.active = false } } initIconItem() { let HonorDataAll = [ ...HonorManger.getInstance().HonorWallDetails_Shangban, ...HonorManger.getInstance().HonorWallDetails_ChiDao, ...HonorManger.getInstance().HonorWallDetails_Qita]; this.progressLabel.string = `已获得 ${HonorManger.getInstance().HonorMList.length}/${HonorDataAll.length}`; for (let j = 0; j < HonorDataAll.length; j++) { const element = HonorDataAll[j]; PopManger.getInstance().LoadAssets(ItemName.HonorItem).then((Prefab) => { let subPrefab = cc.instantiate(Prefab) subPrefab.getComponent(HonorWallitem).MyType = element subPrefab.parent = this.Itemparent }).catch((error) => { // 加载失败的处理 }); } } ClickDelete() { this.node.destroy() } }