Files
drone/assets/script/drone/SingleDroneIfnoManager.ts
T
2023-05-19 17:13:53 +08:00

53 lines
1.7 KiB
TypeScript

import { Drone_Event } from "../define/Event";
import BaseComp from "../external/BaseComp";
import { CommonModel } from "./CommonModel";
const { ccclass, property } = cc._decorator;
@ccclass
export default class SingleDroneIfnoManager extends BaseComp {
@property(cc.Label)
idLabel: cc.Label = null
@property(cc.Label)
percetnLabel: cc.Label = null
@property(cc.Label)
locationNLabel: cc.Label = null
@property(cc.Label)
locationELabel: cc.Label = null
@property(cc.Sprite)
powerBarSprite: cc.Sprite = null
@property(cc.Color)
barColor: Array<cc.Color> = []
onEnable(): void {
super.onEnable()
this.on(Drone_Event.DRONE_CLICK, this.setSingleInfo.bind(this))
}
onDisable(): void {
this.off(Drone_Event.DRONE_CLICK)
super.onDisable()
}
setSingleInfo(id: string) {
console.log('setSingleInfo::id = ',id)
let detail = CommonModel.inst.droneDetail.find(data => data.id === id)
if (detail) {
const { droneName } = CommonModel.inst.droneInfo.find(data => data.id === id)
const { bettery, locationE, locationN } = detail
this.idLabel.string = droneName
this.percetnLabel.string = `${bettery}`
this.locationNLabel.string = locationN
this.locationELabel.string = locationE
this.powerBarSprite.fillRange = bettery / 100
if(bettery >= 80) {
this.powerBarSprite.node.color = this.barColor[2]
} else if(bettery <= 30) {
this.powerBarSprite.node.color = this.barColor[0]
} else {
this.powerBarSprite.node.color = this.barColor[1]
}
}
}
}