SamsaraGame/assets/Script/panel/SchemePropertyPanel.js

198 lines
6.6 KiB
JavaScript
Raw Permalink Normal View History

2025-04-24 17:03:28 +08:00
import GameModel from "../ts/core/GameModel";
import {EAttrTypeL1,EAttrTypeL2} from "../ts/core/EEnum";
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
cc.Class({
extends: cc.Component,
properties: {
propertyNode: cc.Node,
addPointNode: cc.Node,
},
onLoad() {
this.currentBtn = null;
this.timecnt = 0;
this.maxtiemcnt = 30;
},
loadInfo(data){
this.resetBtnStatus();
this.loadGameData(data);
},
loadGameData(data) {
this.attr1 = {};
this.addpoint = {};
this.qianneng = 0;
this.schemeId = 0;
this.schemeId = data.schemeId;
this.activate = data.activate;
this.addpoint = data.content.attribute.addPoint;
this.addpointT = SKDataUtil.clone(this.addpoint);
this.attr1 = GameModel.player.gameData.attr1;
this.qianneng = data.content.attribute.qianNeng;
this.qiannengT = this.qianneng;
this.showInfo();
},
showInfo() {
cc.find('blood/gengu', this.propertyNode).getComponent(cc.Label).string = Number(GameModel.player.gameData.level) + Number(this.addpoint[EAttrTypeL2.BONE]);// + Number(this.addpoint[EAttrTypeL2.BONE]));
cc.find('blood/genguadd', this.propertyNode).getComponent(cc.Label).string = '(' + (Number(GameModel.player.gameData.level)) + '+' + this.addpoint[EAttrTypeL2.BONE] + ')';// + Number(this.addpoint[EAttrTypeL2.BONE])) + '+0)';
cc.find('skill/lingxing', this.propertyNode).getComponent(cc.Label).string = Number(GameModel.player.gameData.level) + Number(this.addpoint[EAttrTypeL2.SPIRIT]);// + Number(this.addpoint[EAttrTypeL2.SPIRIT]));
cc.find('skill/lingxingadd', this.propertyNode).getComponent(cc.Label).string = '(' + (Number(GameModel.player.gameData.level)) + '+' + this.addpoint[EAttrTypeL2.SPIRIT] + ')';// + Number(this.addpoint[EAttrTypeL2.SPIRIT])) + '+0)';
cc.find('attack/liliang', this.propertyNode).getComponent(cc.Label).string = Number(GameModel.player.gameData.level) + Number(this.addpoint[EAttrTypeL2.STRENGTH]);// + Number(this.addpoint[EAttrTypeL2.STRENGTH]));
cc.find('attack/liliangadd', this.propertyNode).getComponent(cc.Label).string = '(' + (Number(GameModel.player.gameData.level)) + '+' + this.addpoint[EAttrTypeL2.STRENGTH] + ')';// + Number(this.addpoint[EAttrTypeL2.STRENGTH])) + '+0)';
cc.find('speed/minjie', this.propertyNode).getComponent(cc.Label).string = Number(GameModel.player.gameData.level) + Number(this.addpoint[EAttrTypeL2.DEXTERITY]);// + Number(this.addpoint[EAttrTypeL2.DEXTERITY]));
cc.find('speed/minjieadd', this.propertyNode).getComponent(cc.Label).string = '(' + (Number(GameModel.player.gameData.level)) + '+' + this.addpoint[EAttrTypeL2.DEXTERITY] + ')';// + Number(this.addpoint[EAttrTypeL2.DEXTERITY])) + '+0)';
cc.find('qianneng/qianneng', this.propertyNode).getComponent(cc.Label).string = this.qianneng;
cc.find('QixueNode/point/point', this.addPointNode).getComponent(cc.Label).string = this.addpoint[EAttrTypeL2.BONE];
cc.find('FaliNode/point/point', this.addPointNode).getComponent(cc.Label).string = this.addpoint[EAttrTypeL2.SPIRIT];
cc.find('GongjiNode/point/point', this.addPointNode).getComponent(cc.Label).string = this.addpoint[EAttrTypeL2.STRENGTH];
cc.find('SuduNode/point/point', this.addPointNode).getComponent(cc.Label).string = this.addpoint[EAttrTypeL2.DEXTERITY];
cc.find('qianNeng/qianneng', this.addPointNode).getComponent(cc.Label).string = this.qianneng;
this.initBtn(cc.find('FaliNode/point/addBtn', this.addPointNode), 101, 0);
this.initBtn(cc.find('FaliNode/point/subBtn', this.addPointNode), 101, 1);
this.initBtn(cc.find('GongjiNode/point/addBtn', this.addPointNode), 102, 0);
this.initBtn(cc.find('GongjiNode/point/subBtn', this.addPointNode), 102, 1);
this.initBtn(cc.find('QixueNode/point/addBtn', this.addPointNode), 100, 0);
this.initBtn(cc.find('QixueNode/point/subBtn', this.addPointNode), 100, 1);
this.initBtn(cc.find('SuduNode/point/addBtn', this.addPointNode), 103, 0);
this.initBtn(cc.find('SuduNode/point/subBtn', this.addPointNode), 103, 1);
this.initPropertBtn();
},
initBtn(btn, data, type) {
btn.datainfo = data;
btn.opertype = type;
btn.on(cc.Node.EventType.TOUCH_START, this.propertyBtnClick.bind(this));
btn.on(cc.Node.EventType.TOUCH_CANCEL, this.propertyBtnClick.bind(this));
btn.on(cc.Node.EventType.TOUCH_END, this.propertyBtnClick.bind(this));
},
propertyBtnClick(e) {
if (e.type == cc.Node.EventType.TOUCH_START) {
this.maxtiemcnt = 30;
this.timecnt = 0;
this.currentBtn = e.target;
}
else if (e.type == cc.Node.EventType.TOUCH_END || e.type == cc.Node.EventType.TOUCH_CANCEL) {
this.timecnt = this.maxtiemcnt;
this.update();
this.currentBtn = null;
}
},
update() {
if (this.currentBtn == null) {
return;
}
this.timecnt++;
if (this.timecnt >= this.maxtiemcnt) {
if (this.maxtiemcnt > 4) {
this.maxtiemcnt -= 2;
}
this.timecnt = 0;
if (this.currentBtn.opertype == 0) {
this.propertyAddPoint(this.currentBtn.datainfo);
}
else if (this.currentBtn.opertype == 1) {
this.propertySubPoint(this.currentBtn.datainfo);
}
}
},
onClickedBtnAddPoint(e, d) {
this.propertyNode.active = false;
this.addPointNode.active = true;
},
onClickedBtnBack(e, d) {
this.propertyNode.active = true;
this.addPointNode.active = false;
this.addpoint = SKDataUtil.clone(this.addpointT);
this.qianneng = this.qiannengT;
this.showInfo();
},
propertyAddPoint(d) {
if (this.qianneng <= 0) {
this.currentBtn = null;
return;
}
this.addpoint[d]++;
this.qianneng--;
this.showInfo();
},
initPropertBtn() {
this.setPropertBtnInfo('QixueNode', EAttrTypeL1.BONE);
this.setPropertBtnInfo('FaliNode', EAttrTypeL1.SPIRIT);
this.setPropertBtnInfo('GongjiNode', EAttrTypeL1.STRENGTH);
this.setPropertBtnInfo('SuduNode', EAttrTypeL1.DEXTERITY);
},
setPropertBtnInfo(name, type) {
if (this.qianneng <= 0) {
cc.find(`${name}/point/addBtn`, this.addPointNode).active = false;
} else {
cc.find(`${name}/point/addBtn`, this.addPointNode).active = true;
}
if (this.addpoint[type] > 0) {
cc.find(`${name}/point/subBtn`, this.addPointNode).active = true;
} else {
cc.find(`${name}/point/subBtn`, this.addPointNode).active = false;
}
},
resetBtnStatus(){
this.propertyNode.active = true;
this.addPointNode.active = false;
},
propertySubPoint(d) {
if (this.addpoint[d] <= 0) {
this.currentBtn = null;
return;
}
this.addpoint[d]--;
this.qianneng++;
this.showInfo();
},
porpertySure(e, d) {
GameModel.send('c2s_scheme_addCustomPoint', {
roleId: GameModel.player.roleid,
addPoint: JSON.stringify(this.addpoint),
qianNeng: this.qianneng,
schemeId: this.schemeId
});
this.propertyNode.active = true;
this.addPointNode.active = false;
},
});