165 lines
4.6 KiB
TypeScript
165 lines
4.6 KiB
TypeScript
import { all_ItemConfig } from '../../game/gameConfig';
|
|
import { UIUpdateWeapon } from '../Academy/UIUpdateWeapon';
|
|
import { UIBase } from '../UIBase';
|
|
import { uimanger } from '../UIManger';
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class guns_info extends UIBase {
|
|
@property(cc.Node) title: cc.Node = null;
|
|
@property(cc.Node) imgNode: cc.Node = null;
|
|
|
|
@property(cc.ScrollView) scrollView: cc.ScrollView = null;
|
|
@property(cc.Node) arrow_up: cc.Node = null;
|
|
@property(cc.Node) arrow_down: cc.Node = null;
|
|
|
|
// gun info
|
|
@property(cc.Label) lab_hp: cc.Label = null;
|
|
@property(cc.Label) lab_returnBlood: cc.Label = null;
|
|
@property(cc.Label) lab_attack: cc.Label = null;
|
|
@property(cc.Label) lab_defence: cc.Label = null;
|
|
@property(cc.Label) lab_speed: cc.Label = null;
|
|
@property(cc.Label) lab_range: cc.Label = null;
|
|
@property(cc.Label) lab_rateoffire: cc.Label = null;
|
|
@property(cc.Label) lab_clip: cc.Label = null;
|
|
@property(cc.Label) lab_vision: cc.Label = null;
|
|
@property(cc.Label) lab_reload: cc.Label = null;
|
|
@property(cc.Label) lab_naijiu: cc.Label = null;
|
|
|
|
@property(cc.Label) lab_lucky: cc.Label = null;
|
|
@property(cc.Label) lab_successrate: cc.Label = null;
|
|
|
|
@property(cc.ProgressBar) limitBar: cc.ProgressBar = null;
|
|
|
|
@property(cc.Label) cegget: cc.Label = null;
|
|
@property(cc.Node) wantedNode: cc.Node = null;
|
|
|
|
@property(cc.ProgressBar) pveBar: cc.ProgressBar = null;
|
|
@property(cc.Label) pveget: cc.Label = null;
|
|
|
|
showWanted() {
|
|
this.wantedNode.active = true;
|
|
}
|
|
|
|
protected update(dt: number): void {
|
|
if (this.scrollView.getScrollOffset().y <= 0) {
|
|
this.arrow_down.active = true;
|
|
this.arrow_up.active = false;
|
|
} else {
|
|
this.arrow_up.active = true;
|
|
this.arrow_down.active = false;
|
|
}
|
|
}
|
|
|
|
init(data) {
|
|
const infoMap = new Map([
|
|
['1', this.lab_hp],
|
|
['2', this.lab_returnBlood],
|
|
['3', this.lab_attack],
|
|
['4', this.lab_defence],
|
|
['5', this.lab_speed],
|
|
['6', this.lab_range],
|
|
['9', this.lab_rateoffire],
|
|
['10', this.lab_clip],
|
|
['13', this.lab_vision],
|
|
['14', this.lab_reload],
|
|
['34', this.lab_lucky],
|
|
['35', this.lab_successrate],
|
|
['37', this.lab_naijiu],
|
|
]);
|
|
|
|
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;
|
|
}
|
|
|
|
const imgConfigs = all_ItemConfig[data.gun_id];
|
|
this.title.getComponent(cc.Label).string = imgConfigs.name;
|
|
this.setItemImg(this.imgNode, imgConfigs.icon);
|
|
// info
|
|
data.attr.forEach((element) => {
|
|
if (element.type == 2) {
|
|
infoMap.get(`${element.attr_id}`).string = `${element.val}%`;
|
|
} else {
|
|
infoMap.get(`${element.attr_id}`).string = `${element.val}`;
|
|
}
|
|
});
|
|
|
|
infoMap.forEach((element) => {
|
|
if (element.string === '000') {
|
|
element.string = 'Locked';
|
|
element.node.color = cc.Color.GRAY;
|
|
}
|
|
});
|
|
|
|
//
|
|
var limit = data.ceg_uplimit;
|
|
var get = data.today_get_gold;
|
|
|
|
this.limitBar.progress = (limit - get) / limit;
|
|
this.cegget.string = `${limit - data.today_get_gold}/${
|
|
data.ceg_uplimit
|
|
}`;
|
|
//
|
|
//pve
|
|
var pveuplimit = data.pve_ceg_uplimit;
|
|
var pveget = data.today_pve_get_ceg;
|
|
if (this.pveBar)
|
|
this.pveBar.progress = (pveuplimit - pveget) / pveuplimit;
|
|
if (this.pveget)
|
|
this.pveget.string = `${pveuplimit - pveget}/${pveuplimit}`;
|
|
//
|
|
}
|
|
|
|
onClickAdvance() {
|
|
const data = {};
|
|
data['current'] = 'advance';
|
|
uimanger.showUI(UIUpdateWeapon.prefabPath, data);
|
|
}
|
|
|
|
onClickUpgrade() {
|
|
uimanger.showUI(UIUpdateWeapon.prefabPath, {});
|
|
}
|
|
|
|
onClose() {
|
|
this.node.destroy();
|
|
}
|
|
setItemImg(imgNode: cc.Node, itemId: number) {
|
|
cc.loader.loadRes(`icons/${itemId}`, cc.SpriteFrame, (err, res) => {
|
|
imgNode.getComponent(cc.Sprite).spriteFrame = res;
|
|
});
|
|
}
|
|
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;
|
|
}
|
|
}
|