// 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 EventName, { PopName } from "../EventName/EventName"; import { ButtonLock } from "../GameLogic/Sofa"; import HTTPS, { NetGet } from "../Template/HTTPS"; import MyComponent from "../Template/MyComponent"; import CollectManger, { CollectDetailsType } from "./CollectManger"; import PopManger from "./PopManger"; const { ccclass, property } = cc._decorator; @ccclass export default class Collectitem extends MyComponent { MyType: CollectDetailsType = null; select: cc.Node = null; sp: cc.Node = null; isGray = false; onLoad(): void { this.sp = this.node.getChildByName("mask").getChildByName("sp") this.select = this.node.getChildByName("select") this.regEvent(EventName.CollectSelect, this.SetSelect, this) } start(): void { let t = this.sp.getComponent(cc.Sprite) let t1 = this.select.getComponent(cc.Sprite) // 成功加载后的处理 cc.assetManager.loadRemote(this.MyType.Picture, (err, res: cc.Texture2D) => { if (!err) { t.spriteFrame = new cc.SpriteFrame(res); if (this.MyType.IsHold == 1) { // @ts-ignore t.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null)) // @ts-ignore t1.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null)) this.isGray = false } else { // @ts-ignore t.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null)) // @ts-ignore t1.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null)) this.isGray = true } if (this.MyType.IsWear == 1) { this.node.parent.children.forEach(e => { e.getChildByName('select').active = false }) this.select.active = true } } }) } SetSelect(id) { if (id == this.MyType.Id) { this.node.parent.children.forEach(e => { e.getChildByName('select').active = false }) this.select.active = true } } @ButtonLock(0.1, null) ClickMe() { PopManger.getInstance().Pop(PopName.DressUp, { animation: true, Data: { MyType: this.MyType, Sp: this.sp.getComponent(cc.Sprite).spriteFrame }, }) } }