SamsaraGame/assets/Script/panel/ColoringRole.js

262 lines
8.5 KiB
JavaScript
Raw Permalink Normal View History

2025-04-24 17:03:28 +08:00
import LiveEntity from "../ts/core/LiveEntity";
import GameModel from "../ts/core/GameModel";
import WeaponUtil from "../ts/weapon/WeaponUtil";
import ShapeUtil from "../ts/shape/ShapeUtil";
let GameRes = require('../game/GameRes');
cc.Class({
extends: LiveEntity,
properties: {
shadowNode: cc.Node,
weaponNode: cc.Node
},
onLoad() {
this._super();
this.resid = 0;
this.run_type = 0;
this.netInfo = {};
this.animationNode = this.node.getChildByName('frame');
this.animationMaskNode = this.animationNode.getChildByName('maskframe');
this.nameImgTitleNode = this.node.getChildByName('imgTitle');
//this.name_list = ['stand_1', 'stand_3', 'attack_1', 'attack_3', 'run_1', 'run_3', 'magic_1', 'magic_3'];
},
start() {
this.setInfo(GameModel.player);
console.log("coloringRoleStart")
},
/*
* 播放下一個動作
* @param next +1 -1
*/
playNextAction(next) {
let node_ani = this.animationNode.getComponent(cc.Animation);
let cur_name = node_ani.currentClip.name;
//let index = this.name_list.indexOf(cur_name);
//index = (index+next+this.name_list.length)%this.name_list.length;
//if (index >= 0 && index < this.name_list.length) {
this.loadResThenPlay('stand_1');
let temp = GameModel.conf_res_anchor[this.resid];
if (temp) {
let anchorY = temp.anchorY;
let anchorX = temp.anchorX;
this.animationNode.anchorY = anchorY;
this.animationMaskNode.anchorY = anchorY;
this.shadowNode.anchorY = anchorY;
this.weaponNode.anchorY = anchorY;
this.animationNode.anchorX = anchorX;
this.animationMaskNode.anchorX = anchorX;
this.shadowNode.anchorX = anchorX;
this.weaponNode.anchorX = anchorX;
}
ShapeUtil.playshadowAni(this.shadowNode, this.resid, 1, 'stand', this);
WeaponUtil.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.animationNode, this, this.resid, 'stand', 1, 2);
//}
},
showColorMask(color1, color2) {
console.log("面板調試顏色1:", color1.r,color1.g,color1.b)
console.log("面板調試顏色2:", color2.r,color2.g,color2.b)
if (color1.r == 0 && color1.g == 0 && color1.b == 0 && color2.r == 0 && color2.g == 0 && color2.b == 0) {
this.unshowColorMask();
} else {
this.animationMaskNodeShow = true;
this.animationMaskNode.active = true;
}
// let node_ani = this.animationNode.getComponent(cc.Animation);
// if (node_ani.currentClip) {
// this.loadResThenPlay(node_ani.currentClip.name);
// }
//else {
let temp = GameModel.conf_res_anchor[this.resid];
if (temp) {
let anchorY = temp.anchorY;
let anchorX = temp.anchorX;
this.animationNode.anchorY = anchorY;
this.animationMaskNode.anchorY = anchorY;
this.shadowNode.anchorY = anchorY;
this.weaponNode.anchorY = anchorY;
this.animationNode.anchorX = anchorX;
this.animationMaskNode.anchorX = anchorX;
this.shadowNode.anchorX = anchorX;
this.weaponNode.anchorX = anchorX;
}
this.loadResThenPlay('stand_1');
ShapeUtil.playshadowAni(this.shadowNode, this.resid, 1, 'stand', this);
WeaponUtil.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.animationNode, this, this.resid, 'stand', 1, 2);
//}
this.scheduleOnce(() => {
let logic = this.animationMaskNode.getComponent('role_color');
if (color1.r != 0 || color1.g != 0 || color1.b != 0) {
let t = Math.floor(color1.r) * 1000000 + Math.floor(color1.g) * 1000 + Math.floor(color1.b);
logic.dH1 = t;
} else {
logic.dH1 = 0;
}
if (color2.r != 0 || color2.g != 0 || color2.b != 0) {
let t = Math.floor(color2.r) * 1000000 + Math.floor(color2.g) * 1000 + Math.floor(color2.b);
logic.dH2 = t;
} else {
logic.dH2 = 0;
}
}, 0);
},
unshowColorMask() {
this.animationMaskNodeShow = false;
this.animationMaskNode.active = false;
},
setInfo(objinfo, loadGame) {
this.netInfo = objinfo;
this.resAtlas = GameRes.getRoleRes(objinfo.resid);
this.resid = objinfo.resid;
this.loadResThenPlay('stand_1');
let temp = GameModel.conf_res_anchor[this.resid];
if (temp) {
let anchorY = temp.anchorY;
let anchorX = temp.anchorX;
this.animationNode.anchorY = anchorY;
this.animationMaskNode.anchorY = anchorY;
this.shadowNode.anchorY = anchorY;
this.weaponNode.anchorY = anchorY;
this.animationNode.anchorX = anchorX;
this.animationMaskNode.anchorX = anchorX;
this.shadowNode.anchorX = anchorX;
this.weaponNode.anchorX = anchorX;
}
ShapeUtil.playshadowAni(this.shadowNode, this.resid, 1, 'stand', this);
WeaponUtil.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.animationNode, this, this.resid, 'stand', 1, 2);
// CPubFunction.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.animationNode, this, this.resid, 'stand', 1);
let nID = GameModel.conf_map[objinfo.mapid].mapid;
let mapinfo = GameModel.conf_map_list[nID];
this.gridInfoArr = mapinfo.mapInfo;
if (GameModel.conf_res_anchor[this.resid]) {
this.animationNode.anchorY = GameModel.conf_res_anchor[this.resid].anchorY;
this.animationMaskNode.anchorY = this.animationNode.anchorY;
}
if (this.animationNode && this.animationNode.getComponent(cc.Animation)) {
let clips = this.animationNode.getComponent(cc.Animation).getClips();
for (const clip of clips) {
this.animationNode.getComponent(cc.Animation).removeClip(clip, true);
}
}
},
changeWeapon(weapon) {
this.netInfo.weapon = weapon;
},
loadResThenPlay (name) {
let index = 0;
let url=`shap/${this.resid}/${name}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if(error){
cc.warn(`$警告:加載資源${url}失敗!`);
return;
}
++ index;
if (index == 2) {
this.playAnimation(name);
}
});
cc.loader.loadRes(`shape_mask/${this.resid}/${name}`, cc.SpriteAtlas, (err, atlas) => {
++ index;
if (index == 2) {
this.playAnimation(name);
}
});
},
playAnimation(name) {
if (!this.animationNode.active) {
return;
}
let clips = this.animationNode.getComponent(cc.Animation).getClips();
for (const clip of clips) {
if (clip.name == name) {
this.animationNode.getComponent(cc.Animation).play(name);
this.playMaskAnimation(name);
this.scheduleOnce(() => {
//let preScaleX = this.animationNode.scaleX;
//this.animationNode.scaleX = preScaleX > 0 ? 500 / this.animationNode.width : -500 / this.animationNode.width;
//this.animationNode.scaleY = 500 / this.animationNode.height;
/* this.animationMaskNode.scaleX = this.animationNode.scaleX;
this.animationMaskNode.scaleY = this.animationNode.scaleY; */
this.animationMaskNode.anchorY = this.animationNode.anchorY;
}, 0);
return;
}
}
let url = `shap/${this.resid}/${name}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載資源${url}失敗!`);
return;
}
if (!this.animationNode) return;
let curFrames = atlas.getSpriteFrames();
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 15);
curClip.name = name;
curClip.wrapMode = cc.WrapMode.Loop;
let nodeAni = this.animationNode.getComponent(cc.Animation);
nodeAni.addClip(curClip);
nodeAni.play(name);
this.playMaskAnimation(name);
this.scheduleOnce(() => {
//let preScaleX = this.animationNode.scaleX;
//this.animationNode.scaleX = preScaleX > 0 ? 500 / this.animationNode.width : -500 / this.animationNode.width;
//this.animationNode.scaleY = 500 / this.animationNode.height;
/* this.animationMaskNode.scaleX = this.animationNode.scaleX;
this.animationMaskNode.scaleY = this.animationNode.scaleY; */
this.animationMaskNode.anchorY = this.animationNode.anchorY;
}, 0);
});
},
playMaskAnimation (name) {
if (!this.animationMaskNode.active) {
return;
}
let clips = this.animationMaskNode.getComponent(cc.Animation).getClips();
for (const clip of clips) {
if (clip.name == name) {
this.animationMaskNode.getComponent(cc.Animation).play(name);
return;
}
}
let url=`shape_mask/${this.resid}/${name}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if(error){
cc.warn(`$警告:加載資源${url}失敗!`);
return;
}
if (!this.animationMaskNode) return;
let curFrames = atlas.getSpriteFrames();
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 15);
curClip.name = name;
curClip.wrapMode = cc.WrapMode.Loop;
let nodeAni = this.animationMaskNode.getComponent(cc.Animation);
nodeAni.addClip(curClip);
nodeAni.play(name);
});
},
OnClick() {
cc.log('OnClick');
},
});