// 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 { ButtonLock } from "../GameLogic/Sofa"; import HTTPS, { NetGet } from "../Template/HTTPS"; import HonorManger, { HonorWallDetailsType } from "./HonorManger"; const { ccclass, property } = cc._decorator; @ccclass export default class HonorWallitem extends cc.Component { MyType: HonorWallDetailsType = null; sp: cc.Node = null; select: cc.Node = null; labelNode: cc.Node = null; isGray = false; onLoad(): void { this.sp = this.node.getChildByName("sp") this.select = this.node.getChildByName("select") this.labelNode = this.node.getChildByName("Label") } 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 (HonorManger.getInstance().HonorMList.includes(this.MyType.Id)) { // @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 } let spLabel = this.labelNode.getComponent(cc.Label) spLabel.string = this.MyType.Name if (this.MyType.IsWear == 1) { this.ClickMe() } } }) } @ButtonLock(0.1, null) ClickMe() { //hide all this.node.parent.children.forEach(e => { e.getChildByName('select').active = false }) //show this.select.active = true //show // 创建一个自定义事件 let event = new cc.Event.EventCustom('ClickItem', true); // true 表示事件可冒泡 event.setUserData({ MyType: this.MyType, Gray: this.isGray, sp: this.sp.getComponent(cc.Sprite) }); // 传递自定义数据 this.node.dispatchEvent(event); // 派发事件 if (this.MyType.IsHold == 1) { HTTPS.Instance.get(NetGet.UserWearHonor + this.MyType.Id).then((resp) => { }) } } }