import { all_ItemConfig } from '../../game/gameConfig'; import { uimanger } from '../UIManger'; const { ccclass, property } = cc._decorator; @ccclass export class guns_single extends cc.Component { @property(cc.Label) label: cc.Label = null; @property(cc.Node) imgNode: cc.Node = null; @property(cc.Prefab) infoPage: cc.Prefab = null; @property(cc.ProgressBar) limitBar:cc.ProgressBar = null; @property(cc.Label) cegget:cc.Label = null; @property(cc.Node) wantedNode:cc.Node = null private curData = {}; private guninfo = {}; showWanted(){ this.wantedNode.active = true } init(data) { if (data == 0) { this.node.active = false; return; } var limit = data.ceg_uplimit var get = data.today_get_gold var lefttime = data.unlock_lefttime if(data.lock_type==3){ this.showWanted() this.wantedNode.getComponentInChildren(cc.Label).string = this.formatSeconds(lefttime) this.schedule(function () { this.wantedNode.getComponentInChildren(cc.Label).string = this.formatSeconds(lefttime) lefttime-=1 }, 1); }else{ this.wantedNode.active = false } if(this.limitBar)this.limitBar.progress =(limit-get)/limit if(this.cegget)this.cegget.string = `${limit-data.today_get_gold}/${data.ceg_uplimit}` this.node.active = true; this.curData = data; const imgConfigs = all_ItemConfig[data.gun_id]; this.label.string = imgConfigs.name; this.setItemImg(this.imgNode, imgConfigs.icon); // console.log(imgConfigs) this.guninfo = { name: imgConfigs.icon, weapon_id: parseInt(data.gun_id), weapon_lv: parseInt(data.fun_lv), weapon_uniid: data.gun_uniid, ammo: 30, volume: 30 } // console.log(`gungungun---${JSON.stringify(this.guninfo)}`) this.node.name = JSON.stringify(this.guninfo); } showInfo() { uimanger.showUI(this.infoPage, this.curData); } setItemImg(imgNode: cc.Node, itemId: number) { cc.loader.loadRes(`icons/${itemId}`, cc.SpriteFrame, (err, res) => { imgNode.getComponent(cc.Sprite).spriteFrame = res; }); // this.node.name = JSON.stringify(this.guninfo); } removeClickEvent() { this.getComponent(cc.Button).clickEvents.length = 0; } formatSeconds(value) { let result = parseInt(value); let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600); let m = Math.floor((result / 60) % 60) < 10 ? '0' + Math.floor((result / 60) % 60) : Math.floor((result / 60) % 60); let s = Math.floor(result % 60) < 10 ? '0' + Math.floor(result % 60) : Math.floor(result % 60); let res = ''; res += `${h}:`; res += `${m}:`; res += `${s}`; return res; } }