Commit 1ef63a75 authored by 范雪寒's avatar 范雪寒

style: format

parent 2a872c7e
...@@ -15,7 +15,7 @@ cc.Class({ ...@@ -15,7 +15,7 @@ cc.Class({
// }, // },
btnGroup: { btnGroup: {
default: null, default: null,
type: cc.Node type: cc.Node
}, },
actionButton: { actionButton: {
default: null, default: null,
...@@ -38,17 +38,17 @@ cc.Class({ ...@@ -38,17 +38,17 @@ cc.Class({
// }, // },
}, },
setCurrentMode(val) { setCurrentMode(val) {
if(this.__currentMode__ === val) { if (this.__currentMode__ === val) {
return; return;
} }
this.__currentMode__ = val; this.__currentMode__ = val;
this.lrc.setPlayInteractivateMode(val); this.lrc.setPlayInteractivateMode(val);
// this.lrc.stopAndResetHighLight(); // this.lrc.stopAndResetHighLight();
// this.setPlayButtonStatus(this.BUTTON_STATUS.IDLE); // this.setPlayButtonStatus(this.BUTTON_STATUS.IDLE);
}, },
getCurrentMode() { getCurrentMode() {
return this.__currentMode__; return this.__currentMode__;
}, },
getScaleValue(value) { getScaleValue(value) {
// return value / base; // return value / base;
...@@ -56,12 +56,12 @@ cc.Class({ ...@@ -56,12 +56,12 @@ cc.Class({
}, },
convertBoundingCoordinate(node, targetRect, resize) { convertBoundingCoordinate(node, targetRect, resize) {
const baseOn = node.parent; // targetRect.parent ? targetRect.parent : this.node;//cc.find('Canvas');//targetRect.parent;// cc.find('Canvas'); const baseOn = node.parent; // targetRect.parent ? targetRect.parent : this.node;//cc.find('Canvas');//targetRect.parent;// cc.find('Canvas');
const worldPos = baseOn.convertToWorldSpaceAR(cc.v2(targetRect.x , targetRect.y)); const worldPos = baseOn.convertToWorldSpaceAR(cc.v2(targetRect.x, targetRect.y));
const localPos = node._parent.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y)); const localPos = node._parent.convertToNodeSpaceAR(cc.v2(worldPos.x, worldPos.y));
const worldPos2 = baseOn.convertToWorldSpaceAR(cc.v2(targetRect.x + targetRect.width , targetRect.y + targetRect.height)); const worldPos2 = baseOn.convertToWorldSpaceAR(cc.v2(targetRect.x + targetRect.width, targetRect.y + targetRect.height));
const localPos2 = node._parent.convertToNodeSpaceAR(cc.v2(worldPos2.x, worldPos2.y)); const localPos2 = node._parent.convertToNodeSpaceAR(cc.v2(worldPos2.x, worldPos2.y));
// this.actionButton.node.x = localPos.x; // this.actionButton.node.x = localPos.x;
// localPos.x + targetNode.width // localPos.x + targetNode.width
if (resize) { if (resize) {
...@@ -69,43 +69,43 @@ cc.Class({ ...@@ -69,43 +69,43 @@ cc.Class({
node.height = targetRect.height node.height = targetRect.height
node.scale = (localPos2.x - localPos.x) / node.width node.scale = (localPos2.x - localPos.x) / node.width
} }
// node.width = (localPos2.x - localPos.x) // node.width = (localPos2.x - localPos.x)
// node.height = (localPos2.y - localPos.y) // node.height = (localPos2.y - localPos.y)
node.y = (localPos2.y + localPos.y) / 2; node.y = (localPos2.y + localPos.y) / 2;
node.x = (localPos2.x + localPos.x) / 2; node.x = (localPos2.x + localPos.x) / 2;
const {x, y, width, height} = node; const { x, y, width, height } = node;
console.log(2, {x, y, width, height} ) console.log(2, { x, y, width, height })
}, },
setNodeScale() { setNodeScale() {
const {width: dw, height: dh} = cc.view.getDesignResolutionSize(); const { width: dw, height: dh } = cc.view.getDesignResolutionSize();
const {width: fw, height: fh} = cc.view.getFrameSize(); const { width: fw, height: fh } = cc.view.getFrameSize();
const gameScale = Math.min(dw / fw, dh / fh); const gameScale = Math.min(dw / fw, dh / fh);
let sx = fw / dw; let sx = fw / dw;
let sy = fh / dh; let sy = fh / dh;
const mapS = Math.min(sx, sy); const mapS = Math.min(sx, sy);
let subNum = 720 - 640; let subNum = 720 - 640;
sx = fw * gameScale / 1280; sx = fw * gameScale / 1280;
sy = (fh * gameScale - subNum * mapS * gameScale) / 640; sy = (fh * gameScale - subNum * mapS * gameScale) / 640;
this.node.scale = Math.min(sx, sy) this.node.scale = Math.min(sx, sy)
}, },
getOffsetY() { getOffsetY() {
const {width: dw, height: dh} = cc.view.getDesignResolutionSize(); const { width: dw, height: dh } = cc.view.getDesignResolutionSize();
const {width: fw, height: fh} = cc.view.getFrameSize(); const { width: fw, height: fh } = cc.view.getFrameSize();
const gameScale = Math.min(dw / fw, dh / fh); const gameScale = Math.min(dw / fw, dh / fh);
const cw = this.node.width; const cw = this.node.width;
const ch = this.node.height; const ch = this.node.height;
return fh / 2 * gameScale - ch / 2 * this.node.scaleY ; return fh / 2 * gameScale - ch / 2 * this.node.scaleY;
}, },
setToRectArea(node, conf, resize) { setToRectArea(node, conf, resize) {
// const {width: dw, height: dh} = cc.view.getDesignResolutionSize(); // const {width: dw, height: dh} = cc.view.getDesignResolutionSize();
...@@ -115,21 +115,21 @@ cc.Class({ ...@@ -115,21 +115,21 @@ cc.Class({
// const gameScale = dh / fh; // const gameScale = dh / fh;
// console.log(3333, conf.rect) // console.log(3333, conf.rect)
let width = this.getScaleValue(conf.rect.width) let width = this.getScaleValue(conf.rect.width)
let height = this.getScaleValue(conf.rect.height ) let height = this.getScaleValue(conf.rect.height)
let x = this.getScaleValue(conf.rect.x ) let x = this.getScaleValue(conf.rect.x)
// + conf.rect.width - conf.rect.width * node.anchorX // + conf.rect.width - conf.rect.width * node.anchorX
- cw / 2; - cw / 2;
let y = this.getScaleValue(-conf.rect.y ) let y = this.getScaleValue(-conf.rect.y)
// - conf.rect.height * node.anchorY // - conf.rect.height * node.anchorY
+this.getScaleValue(-conf.rect.height ) + this.getScaleValue(-conf.rect.height)
+ ch / 2; + ch / 2;
// let x = this.getScaleValue(conf.rect.x, conf.mapScale) // let x = this.getScaleValue(conf.rect.x, conf.mapScale)
// + conf.rect.width - conf.rect.width //* node.anchorX // + conf.rect.width - conf.rect.width //* node.anchorX
// - dw / 2; // - dw / 2;
// let y = this.getScaleValue(-conf.rect.y, conf.mapScale) // let y = this.getScaleValue(-conf.rect.y, conf.mapScale)
// - conf.rect.height// * node.anchorY // - conf.rect.height// * node.anchorY
// + dh / 2; // + dh / 2;
// console.log(4444,{ // console.log(4444,{
// x, y, width, height // x, y, width, height
// }); // });
...@@ -139,18 +139,18 @@ cc.Class({ ...@@ -139,18 +139,18 @@ cc.Class({
// rectNode.anchorY = 0; // rectNode.anchorY = 0;
// this.node.addChild(rectNode); // this.node.addChild(rectNode);
// const ctx = rectNode.addComponent(cc.Graphics); // const ctx = rectNode.addComponent(cc.Graphics);
// // 红色矩形 // // 红色矩形
// ctx.lineWidth = 4; // ctx.lineWidth = 4;
// ctx.strokeColor = cc.Color.RED; // ctx.strokeColor = cc.Color.RED;
// ctx.fillColor = cc.Color.WHITE.setA(100); // ctx.fillColor = cc.Color.WHITE.setA(100);
// ctx.rect(0, 0, rectNode.width, rectNode.height); // ctx.rect(0, 0, rectNode.width, rectNode.height);
// ctx.stroke(); // ctx.stroke();
// ctx.fill() // ctx.fill()
// rectNode.width = width // rectNode.width = width
// rectNode.height = height // rectNode.height = height
// rectNode.x = x // rectNode.x = x
// rectNode.y = y; // rectNode.y = y;
this.convertBoundingCoordinate(node, { this.convertBoundingCoordinate(node, {
x, y, width, height x, y, width, height
}, resize) }, resize)
...@@ -162,7 +162,7 @@ cc.Class({ ...@@ -162,7 +162,7 @@ cc.Class({
// // width * sh = width * gameScale * height // // width * sh = width * gameScale * height
// width *= gameScale ; // width *= gameScale ;
// height *= gameScale ; // height *= gameScale ;
// bh * actionArea.width / bw // bh * actionArea.width / bw
...@@ -180,13 +180,13 @@ cc.Class({ ...@@ -180,13 +180,13 @@ cc.Class({
// return {x, y, width, height} // return {x, y, width, height}
}, },
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
onLoad () { onLoad() {
// this.setNodeScale(); // this.setNodeScale();
// const ctx = rectNode.addComponent(cc.Graphics); // const ctx = rectNode.addComponent(cc.Graphics);
// const {width: dw, height: dh} = cc.view.getDesignResolutionSize(); // const {width: dw, height: dh} = cc.view.getDesignResolutionSize();
// const cw = 1280; // const cw = 1280;
// const ch = 640; // const ch = 640;
...@@ -208,9 +208,9 @@ cc.Class({ ...@@ -208,9 +208,9 @@ cc.Class({
this.modeNameMap = {}; this.modeNameMap = {};
this.btnGroup.children.forEach(button => { this.btnGroup.children.forEach(button => {
this.modeNameMap[button.name] = button; this.modeNameMap[button.name] = button;
}); });
this.lrc =this.node.getChildByName('karaoke').getComponent('karaoke') this.lrc = this.node.getChildByName('karaoke').getComponent('karaoke')
// this.setCurrentMode(this.lrc.PLAY_MODE.MODE1); // this.setCurrentMode(this.lrc.PLAY_MODE.MODE1);
this.setPlayButtonStatus(this.BUTTON_STATUS.IDLE); this.setPlayButtonStatus(this.BUTTON_STATUS.IDLE);
...@@ -222,28 +222,28 @@ cc.Class({ ...@@ -222,28 +222,28 @@ cc.Class({
cc.director.on('GAME_RESOURCE_LOADED_sb_karaoke_cocos', () => { cc.director.on('GAME_RESOURCE_LOADED_sb_karaoke_cocos', () => {
this.lrc.initialize(); this.lrc.initialize();
this.setCurrentMode(this.lrc.PLAY_MODE.MODE1); this.setCurrentMode(this.lrc.PLAY_MODE.MODE1);
this.buttonGroupChange(this.modeNameMap[this.getCurrentMode()]) this.buttonGroupChange(this.modeNameMap[this.getCurrentMode()])
// this.lrc.node.zIndex = 99999 // this.lrc.node.zIndex = 99999
}); });
cc.director.on('GAME_DATA_FETCHED_sb_karaoke_cocos', (data) => { cc.director.on('GAME_DATA_FETCHED_sb_karaoke_cocos', (data) => {
const {width: dw, height: dh} = cc.view.getDesignResolutionSize(); const { width: dw, height: dh } = cc.view.getDesignResolutionSize();
const {width: fw, height: fh} = cc.view.getFrameSize(); const { width: fw, height: fh } = cc.view.getFrameSize();
this._gameScale = Math.min(dw / fw, dh / fh); this._gameScale = Math.min(dw / fw, dh / fh);
let sx = fw / dw; let sx = fw / dw;
let sy = fh / dh; let sy = fh / dh;
const mapS = Math.min(sx, sy); const mapS = Math.min(sx, sy);
let subNum = 720 - 640; let subNum = 720 - 640;
sx = fw * this._gameScale / 1280; sx = fw * this._gameScale / 1280;
sy = (fh * this._gameScale - subNum * mapS * this._gameScale) / 640; sy = (fh * this._gameScale - subNum * mapS * this._gameScale) / 640;
this.rootNodeScale = Math.min(sx, sy); this.rootNodeScale = Math.min(sx, sy);
this.node.scale = this.rootNodeScale; this.node.scale = this.rootNodeScale;
const rate = (this.rootNodeScale * 1280) / data.bgItem.rect.width; const rate = (this.rootNodeScale * 1280) / data.bgItem.rect.width;
this.itemScale = rate / this.rootNodeScale; this.itemScale = rate / this.rootNodeScale;
...@@ -264,8 +264,8 @@ cc.Class({ ...@@ -264,8 +264,8 @@ cc.Class({
return +item.gIdx === 3; return +item.gIdx === 3;
}); });
if (lrcRect) { if (lrcRect) {
this.setToRectArea(this.lrc.node, lrcRect, true); this.setToRectArea(this.lrc.node, lrcRect, true);
// this.lrc.node.x = lrcArea.x; // this.lrc.node.x = lrcArea.x;
...@@ -274,17 +274,17 @@ cc.Class({ ...@@ -274,17 +274,17 @@ cc.Class({
// this.lrc.node.height = lrcArea.height; // this.lrc.node.height = lrcArea.height;
// this.lrc.node.anchorX = 0; // this.lrc.node.anchorX = 0;
// this.lrc.node.anchorY = 1; // this.lrc.node.anchorY = 1;
if (this.lrc.node) { if (this.lrc.node) {
this.lrc.node.zIndex = 99999; this.lrc.node.zIndex = 99999;
} else { } else {
console.log("!this.lrc.node") console.log("!this.lrc.node")
} }
} else { } else {
this.lrc.node.active = false; this.lrc.node.active = false;
} }
if(modeGroupRect){ if (modeGroupRect) {
this.setToRectArea(this.btnGroup, modeGroupRect); this.setToRectArea(this.btnGroup, modeGroupRect);
// this.btnGroup.x = modeArea.x; // this.btnGroup.x = modeArea.x;
// this.btnGroup.y = modeArea.y; // this.btnGroup.y = modeArea.y;
...@@ -294,7 +294,7 @@ cc.Class({ ...@@ -294,7 +294,7 @@ cc.Class({
// this.btnGroup.anchorY = 1; // this.btnGroup.anchorY = 1;
this.btnGroup.children.forEach(b => { this.btnGroup.children.forEach(b => {
b.getComponent(cc.Widget).enable = false; b.getComponent(cc.Widget).enable = false;
b.getComponent(cc.Widget).enable = true; b.getComponent(cc.Widget).enable = true;
}) })
if (this.btnGroup) { if (this.btnGroup) {
...@@ -316,7 +316,7 @@ cc.Class({ ...@@ -316,7 +316,7 @@ cc.Class({
// const { width: bw, height: bh } = this.actionButton.node; // const { width: bw, height: bh } = this.actionButton.node;
// this.actionButton.node.width = actionArea.width; // this.actionButton.node.width = actionArea.width;
// this.actionButton.node.height = bh * actionArea.width / bw ; //actionArea.height; // this.actionButton.node.height = bh * actionArea.width / bw ; //actionArea.height;
if (this.actionButton.node) { if (this.actionButton.node) {
this.actionButton.node.zIndex = 99999; this.actionButton.node.zIndex = 99999;
...@@ -326,22 +326,22 @@ cc.Class({ ...@@ -326,22 +326,22 @@ cc.Class({
} else { } else {
this.actionButton.node.active = false; this.actionButton.node.active = false;
} }
// this.lrc.node.width = area.rect.width; // this.lrc.node.width = area.rect.width;
// this.lrc.node.height = area.rect.height; // this.lrc.node.height = area.rect.height;
if (data.lrcData && data.lrcData.audio_url) { if (data.lrcData && data.lrcData.audio_url) {
data.lrcData.audio_url = data.lrcData.audio_url.toLocaleLowerCase() data.lrcData.audio_url = data.lrcData.audio_url.toLocaleLowerCase()
} }
if (data.accompany_audio_url) { if (data.accompany_audio_url) {
data.accompany_audio_url = data.accompany_audio_url.toLocaleLowerCase() data.accompany_audio_url = data.accompany_audio_url.toLocaleLowerCase()
} }
this.node.y = this.getOffsetY(); this.node.y = this.getOffsetY();
...@@ -357,23 +357,23 @@ cc.Class({ ...@@ -357,23 +357,23 @@ cc.Class({
// window.dispatchEvent(new CustomEvent('resize'), true) // window.dispatchEvent(new CustomEvent('resize'), true)
// window.dispatchEvent(new cc.Event.EventCustom('resize', true)) // window.dispatchEvent(new cc.Event.EventCustom('resize', true))
}, this); }, this);
cc.director.on('GAME_VIEW_DISPLAYED', function() { cc.director.on('GAME_VIEW_DISPLAYED', function () {
// this.karaoke.prepare(); // this.karaoke.prepare();
}, this); }, this);
window.gg =this window.gg = this
this.btnGroup.children.forEach(button => { this.btnGroup.children.forEach(button => {
button.actionStatus = this.BUTTON_STATUS.IDLE; button.actionStatus = this.BUTTON_STATUS.IDLE;
button.on(cc.Node.EventType.TOUCH_START, function(event) { button.on(cc.Node.EventType.TOUCH_START, function (event) {
const btn = event.currentTarget; const btn = event.currentTarget;
window.bb = btn; window.bb = btn;
this.buttonGroupChange(btn) this.buttonGroupChange(btn)
// cc.log("This is a callback after the trigger event", event); // cc.log("This is a callback after the trigger event", event);
}, this) }, this)
}); });
; ;
}, },
setPlayButtonStatus(sts){ setPlayButtonStatus(sts) {
// this.lastButtonStateCache = this.BUTTON_STATUS.ACTIVE // this.lastButtonStateCache = this.BUTTON_STATUS.ACTIVE
if (this.actionButton.node.buttonStatus === sts) { if (this.actionButton.node.buttonStatus === sts) {
return return
...@@ -390,11 +390,11 @@ cc.Class({ ...@@ -390,11 +390,11 @@ cc.Class({
} }
// console.log(1, curMode, sts); // console.log(1, curMode, sts);
}, },
toggleActionButtonStatus(){ toggleActionButtonStatus() {
let sts = this.BUTTON_STATUS.ACTIVE; let sts = this.BUTTON_STATUS.ACTIVE;
if(this.actionButton.node.buttonStatus == sts) { if (this.actionButton.node.buttonStatus == sts) {
sts = this.BUTTON_STATUS.IDLE; sts = this.BUTTON_STATUS.IDLE;
} }
// this.setPlayButtonStatus(sts); // this.setPlayButtonStatus(sts);
...@@ -423,16 +423,16 @@ cc.Class({ ...@@ -423,16 +423,16 @@ cc.Class({
// cc.tween(button.node).to(dur, {scale: 1}).start(); // cc.tween(button.node).to(dur, {scale: 1}).start();
} else { } else {
btn.actionStatus = this.BUTTON_STATUS.ACTIVE; btn.actionStatus = this.BUTTON_STATUS.ACTIVE;
cc.tween(button).to(dur, {scale: 1.2}).start() cc.tween(button).to(dur, { scale: 1.2 }).start()
this.changeBtnActive(button, true); this.changeBtnActive(button, true);
} }
return; return;
} }
button.actionStatus = this.BUTTON_STATUS.IDLE button.actionStatus = this.BUTTON_STATUS.IDLE
cc.tween(button).to(dur, {scale: 1}).start() cc.tween(button).to(dur, { scale: 1 }).start()
this.changeBtnActive(button, false); this.changeBtnActive(button, false);
}) })
}, },
changeBtnActive(btn, isActive) { changeBtnActive(btn, isActive) {
...@@ -441,23 +441,22 @@ cc.Class({ ...@@ -441,23 +441,22 @@ cc.Class({
}, },
// onButtonClick(event, index) { // onButtonClick(event, index) {
// window.ttb = event.currentTarget; // window.ttb = event.currentTarget;
// console.log(event, index) // console.log(event, index)
// }, // },
start () { start() {
}, },
update (dt) { update(dt) {
if (this.lrc) { if (this.lrc) {
// const sts = this.lrc.getCurrentAudioState(); // const sts = this.lrc.getCurrentAudioState();
const sts = this.lrc.isCurrentAudioSourcePlaying(); const sts = this.lrc.isCurrentAudioSourcePlaying();
if (sts /*sts === cc.audioEngine.AudioState.PLAYING*/ ) { if (sts /*sts === cc.audioEngine.AudioState.PLAYING*/) {
this.setPlayButtonStatus(this.BUTTON_STATUS.ACTIVE); this.setPlayButtonStatus(this.BUTTON_STATUS.ACTIVE);
// this.lastButtonStateCache = this.BUTTON_STATUS.ACTIVE // this.lastButtonStateCache = this.BUTTON_STATUS.ACTIVE
} else { } else {
this.setPlayButtonStatus(this.BUTTON_STATUS.IDLE); this.setPlayButtonStatus(this.BUTTON_STATUS.IDLE);
// this.lastButtonStateCache = this.BUTTON_STATUS.IDLE // this.lastButtonStateCache = this.BUTTON_STATUS.IDLE
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment