消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
6.5 KiB

1 week ago
import { _decorator, Component, director, isValid, Label, Node } from 'cc';
import { GBundle, GPath, UIID } from '../game/ConfigRes';
import { GEvent } from '../../mx/module/event/GEvent';
import MTools from '../../mx/tools/MTools';
import { ConstNumType } from '../game/ConfigProjectData';
import { ItemNumType, StatisticsType } from '../game/GameData';
import { sdkConfig } from '../sdk/sdkConfig';
const { ccclass, property } = _decorator;
@ccclass('BaseInfo')
export class BaseInfo extends Component {
ui_head: Node
lb_combatPower: Label
ui_vigour: Node
ui_vigourRed: Node
lb_vigour: Label
timeLab: Label
ui_money: Node
lb_money: Label
ui_diamond: Node
lb_diamond: Label
ui_skipAd: Node
lb_skipAd: Label
maxVigour: number = 30
protected onLoad(): void {
this.ui_head = this.node.getChildByName("ui_head")
this.lb_combatPower = this.ui_head.getChildByName("lb_combatPower").getComponent(Label)
this.ui_vigour = this.node.getChildByName("ui_vigour")
this.lb_vigour = this.ui_vigour.getChildByName("lb_vigour").getComponent(Label)
this.ui_vigourRed = this.ui_vigour.getChildByName("红点")
this.timeLab = this.ui_vigour.getChildByName("timeLab").getComponent(Label)
this.ui_money = this.node.getChildByName("ui_money")
this.lb_money = this.ui_money.getChildByName("lb_money").getComponent(Label)
this.ui_diamond = this.node.getChildByName("ui_diamond")
this.lb_diamond = this.ui_diamond.getChildByName("lb_diamond").getComponent(Label)
this.ui_skipAd = this.node.getChildByName("ui_skipAd")
this.lb_skipAd = this.ui_skipAd.getChildByName("lb_skipAd").getComponent(Label)
}
protected onEnable(): void {
//监听UpdateItemNum
GEvent.Ins.on(GEvent.UpdateItemNum, this.updateItemNum, this)
//this.ui_head.on(Node.EventType.TOUCH_END, this.clickHead, this)
this.ui_vigour.on(Node.EventType.TOUCH_END, this.clickVigour, this)
this.ui_money.on(Node.EventType.TOUCH_END, this.clickMoney, this)
this.ui_diamond.on(Node.EventType.TOUCH_END, this.clickDiamond, this)
this.ui_skipAd.on(Node.EventType.TOUCH_END, this.clickSkipAd, this)
GEvent.Ins.on(GEvent.UpdateCombatPower, this.updateCombatPower, this);
GEvent.Ins.on(GEvent.UpdateVigour, this.updateVigour, this);
GEvent.Ins.on(GEvent.UpdateMoney, this.updateMoney, this);
GEvent.Ins.on(GEvent.UpdateDiamond, this.updateDiamond, this);
GEvent.Ins.on(GEvent.UpdateRole, this.updateHead, this);
// let roleName = gg.task.checkTaskIsUnlock(1102) ? "男主后期" : "男主";
// this.head.children[0].getOrAddComponent(SpriteLoad).setSprite(GPath.Home(roleName), GBundle.Home);
this.ui_skipAd.active = sdkConfig.isIAPVersion;
// if (this.ui_skipAd.active) {
// this.ui_diamond.x = -120;
// this.ui_diamond.y = -50;
// } else {
// this.ui_diamond.x = 240;
// this.ui_diamond.y = 0;
// }
this.updateItemNum();
}
protected update(dt: number): void {
if (director.getTotalFrames() % 60 == 0) {
let maxVigour = gg.data.table.getConst(ConstNumType.VigourAutoAddLimit);
let curentVigour = gg.data.getItemNum(ItemNumType.vigour);
this.timeLab.node.active = curentVigour < maxVigour;
if (this.timeLab.node.active) {
let time = gg.data.project.getAddVigourTime();
let string = MTools.formatTimeString(time, "mm:ss");
this.timeLab.string = string;
}
}
}
protected onDisable(): void {
//移除UpdateItemNum监听
GEvent.Ins.off(GEvent.UpdateItemNum, this.updateItemNum, this)
if (isValid(this.ui_head) && isValid(this.ui_vigour) && isValid(this.ui_money) && isValid(this.ui_diamond)) {
this.ui_head.off(Node.EventType.TOUCH_END, this.clickHead, this)
this.ui_vigour.off(Node.EventType.TOUCH_END, this.clickVigour, this)
this.ui_money.off(Node.EventType.TOUCH_END, this.clickMoney, this)
this.ui_diamond.off(Node.EventType.TOUCH_END, this.clickDiamond, this)
this.ui_skipAd.off(Node.EventType.TOUCH_END, this.clickSkipAd, this)
}
GEvent.Ins.off(GEvent.UpdateCombatPower, this.updateCombatPower, this);
GEvent.Ins.off(GEvent.UpdateVigour, this.updateVigour, this);
GEvent.Ins.off(GEvent.UpdateMoney, this.updateMoney, this);
GEvent.Ins.off(GEvent.UpdateDiamond, this.updateDiamond, this);
GEvent.Ins.off(GEvent.UpdateRole, this.updateHead, this);
}
protected start(): void {
this.updateCombatPower()
this.updateVigour()
this.updateMoney()
this.updateDiamond()
this.updateHead()
}
clickHead() {
gg.ui.openPanel(UIID.Settings);
}
clickVigour() {
gg.ui.openPanel(UIID.buyPower);
}
clickMoney() {
gg.game.gotoPageById(UIID.Shop);
}
clickDiamond() {
gg.game.gotoPageById(UIID.Shop);
}
clickSkipAd() {
gg.ui.openPanel(UIID.PopMonthCard);
}
updateHead(){
let isMan = gg.data.doc.roleId == 1
if(isMan){
this.ui_head.getChildByName("man").active = true
this.ui_head.getChildByName("woman").active = false
}else{
this.ui_head.getChildByName("man").active = false
this.ui_head.getChildByName("woman").active = true
}
}
/**更新战力 */
updateCombatPower() {
let num = gg.data.getCurPower()
this.lb_combatPower.string = MTools.formatChineseUnit({ num: num })
}
/**更新体力 */
updateVigour() {
let num = gg.data.getVigour()
this.lb_vigour.string = MTools.formatChineseUnit({ num: num }) + '/' + this.maxVigour//MTools.formatChineseUnit({ num: num })
}
/**更新金钱 */
updateMoney() {
let num = gg.data.getMoney()
this.lb_money.string = MTools.formatChineseUnit({ num: num })
}
/**更新钻石 */
updateDiamond() {
let num = gg.data.getDiamond()
this.lb_diamond.string = MTools.formatChineseUnit({ num: num })
}
/**更新免广券 */
updateSkipAd() {
let num = gg.data.getItemNum(ItemNumType.skipAd)
this.lb_skipAd.string = MTools.formatChineseUnit({ num: num })
}
updateItemNum() {
//更新所有道具数量
this.updateVigour()
this.updateMoney()
this.updateDiamond()
this.updateSkipAd()
}
}