Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sb_karaoke_cocos
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
sb_karaoke_cocos
Commits
1ef63a75
Commit
1ef63a75
authored
Feb 07, 2022
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style: format
parent
2a872c7e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
94 deletions
+93
-94
adapter_sb_karaoke_cocos.js
...os/components/karaoke/scripts/adapter_sb_karaoke_cocos.js
+93
-94
No files found.
assets/sb_karaoke_cocos/components/karaoke/scripts/adapter_sb_karaoke_cocos.js
View file @
1ef63a75
...
...
@@ -15,7 +15,7 @@ cc.Class({
// },
btnGroup
:
{
default
:
null
,
type
:
cc
.
Node
type
:
cc
.
Node
},
actionButton
:
{
default
:
null
,
...
...
@@ -38,17 +38,17 @@ cc.Class({
// },
},
setCurrentMode
(
val
)
{
if
(
this
.
__currentMode__
===
val
)
{
if
(
this
.
__currentMode__
===
val
)
{
return
;
}
this
.
__currentMode__
=
val
;
this
.
__currentMode__
=
val
;
this
.
lrc
.
setPlayInteractivateMode
(
val
);
// this.lrc.stopAndResetHighLight();
// this.setPlayButtonStatus(this.BUTTON_STATUS.IDLE);
},
getCurrentMode
()
{
return
this
.
__currentMode__
;
return
this
.
__currentMode__
;
},
getScaleValue
(
value
)
{
// return value / base;
...
...
@@ -56,12 +56,12 @@ cc.Class({
},
convertBoundingCoordinate
(
node
,
targetRect
,
resize
)
{
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
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
));
// this.actionButton.node.x = localPos.x;
// localPos.x + targetNode.width
if
(
resize
)
{
...
...
@@ -69,43 +69,43 @@ cc.Class({
node
.
height
=
targetRect
.
height
node
.
scale
=
(
localPos2
.
x
-
localPos
.
x
)
/
node
.
width
}
// node.width = (localPos2.x - localPos.x)
// node.height = (localPos2.y - localPos.y)
node
.
y
=
(
localPos2
.
y
+
localPos
.
y
)
/
2
;
node
.
x
=
(
localPos2
.
x
+
localPos
.
x
)
/
2
;
const
{
x
,
y
,
width
,
height
}
=
node
;
console
.
log
(
2
,
{
x
,
y
,
width
,
height
}
)
node
.
y
=
(
localPos2
.
y
+
localPos
.
y
)
/
2
;
node
.
x
=
(
localPos2
.
x
+
localPos
.
x
)
/
2
;
const
{
x
,
y
,
width
,
height
}
=
node
;
console
.
log
(
2
,
{
x
,
y
,
width
,
height
}
)
},
setNodeScale
()
{
const
{
width
:
dw
,
height
:
dh
}
=
cc
.
view
.
getDesignResolutionSize
();
const
{
width
:
fw
,
height
:
fh
}
=
cc
.
view
.
getFrameSize
();
const
{
width
:
dw
,
height
:
dh
}
=
cc
.
view
.
getDesignResolutionSize
();
const
{
width
:
fw
,
height
:
fh
}
=
cc
.
view
.
getFrameSize
();
const
gameScale
=
Math
.
min
(
dw
/
fw
,
dh
/
fh
);
let
sx
=
fw
/
dw
;
let
sy
=
fh
/
dh
;
const
mapS
=
Math
.
min
(
sx
,
sy
);
let
subNum
=
720
-
640
;
sx
=
fw
*
gameScale
/
1280
;
sy
=
(
fh
*
gameScale
-
subNum
*
mapS
*
gameScale
)
/
640
;
this
.
node
.
scale
=
Math
.
min
(
sx
,
sy
)
},
getOffsetY
()
{
const
{
width
:
dw
,
height
:
dh
}
=
cc
.
view
.
getDesignResolutionSize
();
const
{
width
:
fw
,
height
:
fh
}
=
cc
.
view
.
getFrameSize
();
const
{
width
:
dw
,
height
:
dh
}
=
cc
.
view
.
getDesignResolutionSize
();
const
{
width
:
fw
,
height
:
fh
}
=
cc
.
view
.
getFrameSize
();
const
gameScale
=
Math
.
min
(
dw
/
fw
,
dh
/
fh
);
const
cw
=
this
.
node
.
width
;
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
)
{
// const {width: dw, height: dh} = cc.view.getDesignResolutionSize();
...
...
@@ -115,21 +115,21 @@ cc.Class({
// const gameScale = dh / fh;
// console.log(3333, conf.rect)
let
width
=
this
.
getScaleValue
(
conf
.
rect
.
width
)
let
height
=
this
.
getScaleValue
(
conf
.
rect
.
height
)
let
x
=
this
.
getScaleValue
(
conf
.
rect
.
x
)
// + conf.rect.width - conf.rect.width * node.anchorX
-
cw
/
2
;
let
y
=
this
.
getScaleValue
(
-
conf
.
rect
.
y
)
// - conf.rect.height * node.anchorY
+
this
.
getScaleValue
(
-
conf
.
rect
.
height
)
+
ch
/
2
;
let
height
=
this
.
getScaleValue
(
conf
.
rect
.
height
)
let
x
=
this
.
getScaleValue
(
conf
.
rect
.
x
)
// + conf.rect.width - conf.rect.width * node.anchorX
-
cw
/
2
;
let
y
=
this
.
getScaleValue
(
-
conf
.
rect
.
y
)
// - conf.rect.height * node.anchorY
+
this
.
getScaleValue
(
-
conf
.
rect
.
height
)
+
ch
/
2
;
// let x = this.getScaleValue(conf.rect.x, conf.mapScale)
// + conf.rect.width - conf.rect.width //* node.anchorX
// - dw / 2;
// + conf.rect.width - conf.rect.width //* node.anchorX
// - dw / 2;
// let y = this.getScaleValue(-conf.rect.y, conf.mapScale)
// - conf.rect.height// * node.anchorY
// + dh / 2;
// - conf.rect.height// * node.anchorY
// + dh / 2;
// console.log(4444,{
// x, y, width, height
// });
...
...
@@ -139,18 +139,18 @@ cc.Class({
// rectNode.anchorY = 0;
// this.node.addChild(rectNode);
// const ctx = rectNode.addComponent(cc.Graphics);
// // 红色矩形
// ctx.lineWidth = 4;
// ctx.strokeColor = cc.Color.RED;
// ctx.fillColor = cc.Color.WHITE.setA(100);
// // 红色矩形
// ctx.lineWidth = 4;
// ctx.strokeColor = cc.Color.RED;
// ctx.fillColor = cc.Color.WHITE.setA(100);
// ctx.rect(0, 0, rectNode.width, rectNode.height);
// ctx.stroke();
// ctx.fill()
// ctx.stroke();
// ctx.fill()
// rectNode.width = width
// rectNode.height = height
// rectNode.x = x
// rectNode.height = height
// rectNode.x = x
// rectNode.y = y;
this
.
convertBoundingCoordinate
(
node
,
{
x
,
y
,
width
,
height
},
resize
)
...
...
@@ -162,7 +162,7 @@ cc.Class({
// // width * sh = width * gameScale * height
// width *= gameScale ;
// height *= gameScale ;
// bh * actionArea.width / bw
...
...
@@ -180,13 +180,13 @@ cc.Class({
// return {x, y, width, height}
},
// LIFE-CYCLE CALLBACKS:
onLoad
()
{
onLoad
()
{
// this.setNodeScale();
// const ctx = rectNode.addComponent(cc.Graphics);
// const ctx = rectNode.addComponent(cc.Graphics);
// const {width: dw, height: dh} = cc.view.getDesignResolutionSize();
// const cw = 1280;
// const ch = 640;
...
...
@@ -208,9 +208,9 @@ cc.Class({
this
.
modeNameMap
=
{};
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
.
setPlayButtonStatus
(
this
.
BUTTON_STATUS
.
IDLE
);
...
...
@@ -222,28 +222,28 @@ cc.Class({
cc
.
director
.
on
(
'
GAME_RESOURCE_LOADED_sb_karaoke_cocos
'
,
()
=>
{
this
.
lrc
.
initialize
();
this
.
setCurrentMode
(
this
.
lrc
.
PLAY_MODE
.
MODE1
);
this
.
buttonGroupChange
(
this
.
modeNameMap
[
this
.
getCurrentMode
()])
this
.
setCurrentMode
(
this
.
lrc
.
PLAY_MODE
.
MODE1
);
this
.
buttonGroupChange
(
this
.
modeNameMap
[
this
.
getCurrentMode
()])
// this.lrc.node.zIndex = 99999
});
cc
.
director
.
on
(
'
GAME_DATA_FETCHED_sb_karaoke_cocos
'
,
(
data
)
=>
{
const
{
width
:
dw
,
height
:
dh
}
=
cc
.
view
.
getDesignResolutionSize
();
const
{
width
:
fw
,
height
:
fh
}
=
cc
.
view
.
getFrameSize
();
const
{
width
:
dw
,
height
:
dh
}
=
cc
.
view
.
getDesignResolutionSize
();
const
{
width
:
fw
,
height
:
fh
}
=
cc
.
view
.
getFrameSize
();
this
.
_gameScale
=
Math
.
min
(
dw
/
fw
,
dh
/
fh
);
let
sx
=
fw
/
dw
;
let
sy
=
fh
/
dh
;
const
mapS
=
Math
.
min
(
sx
,
sy
);
let
subNum
=
720
-
640
;
sx
=
fw
*
this
.
_gameScale
/
1280
;
sy
=
(
fh
*
this
.
_gameScale
-
subNum
*
mapS
*
this
.
_gameScale
)
/
640
;
this
.
rootNodeScale
=
Math
.
min
(
sx
,
sy
);
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
;
...
...
@@ -264,8 +264,8 @@ cc.Class({
return
+
item
.
gIdx
===
3
;
});
if
(
lrcRect
)
{
this
.
setToRectArea
(
this
.
lrc
.
node
,
lrcRect
,
true
);
// this.lrc.node.x = lrcArea.x;
...
...
@@ -274,17 +274,17 @@ cc.Class({
// this.lrc.node.height = lrcArea.height;
// this.lrc.node.anchorX = 0;
// this.lrc.node.anchorY = 1;
if
(
this
.
lrc
.
node
)
{
this
.
lrc
.
node
.
zIndex
=
99999
;
}
else
{
console
.
log
(
"
!this.lrc.node
"
)
}
}
else
{
this
.
lrc
.
node
.
active
=
false
;
}
if
(
modeGroupRect
)
{
if
(
modeGroupRect
)
{
this
.
setToRectArea
(
this
.
btnGroup
,
modeGroupRect
);
// this.btnGroup.x = modeArea.x;
// this.btnGroup.y = modeArea.y;
...
...
@@ -294,7 +294,7 @@ cc.Class({
// this.btnGroup.anchorY = 1;
this
.
btnGroup
.
children
.
forEach
(
b
=>
{
b
.
getComponent
(
cc
.
Widget
).
enable
=
false
;
b
.
getComponent
(
cc
.
Widget
).
enable
=
true
;
b
.
getComponent
(
cc
.
Widget
).
enable
=
true
;
})
if
(
this
.
btnGroup
)
{
...
...
@@ -316,7 +316,7 @@ cc.Class({
// const { width: bw, height: bh } = this.actionButton.node;
// this.actionButton.node.width = actionArea.width;
// this.actionButton.node.height = bh * actionArea.width / bw ; //actionArea.height;
if
(
this
.
actionButton
.
node
)
{
this
.
actionButton
.
node
.
zIndex
=
99999
;
...
...
@@ -326,22 +326,22 @@ cc.Class({
}
else
{
this
.
actionButton
.
node
.
active
=
false
;
}
// this.lrc.node.width = area.rect.width;
// this.lrc.node.height = area.rect.height;
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
)
{
data
.
accompany_audio_url
=
data
.
accompany_audio_url
.
toLocaleLowerCase
()
data
.
accompany_audio_url
=
data
.
accompany_audio_url
.
toLocaleLowerCase
()
}
this
.
node
.
y
=
this
.
getOffsetY
();
...
...
@@ -357,23 +357,23 @@ cc.Class({
// window.dispatchEvent(new CustomEvent('resize'), true)
// window.dispatchEvent(new cc.Event.EventCustom('resize', true))
},
this
);
cc
.
director
.
on
(
'
GAME_VIEW_DISPLAYED
'
,
function
()
{
cc
.
director
.
on
(
'
GAME_VIEW_DISPLAYED
'
,
function
()
{
// this.karaoke.prepare();
},
this
);
window
.
gg
=
this
window
.
gg
=
this
this
.
btnGroup
.
children
.
forEach
(
button
=>
{
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
;
window
.
bb
=
btn
;
this
.
buttonGroupChange
(
btn
)
this
.
buttonGroupChange
(
btn
)
// cc.log("This is a callback after the trigger event", event);
},
this
)
},
this
)
});
;
},
setPlayButtonStatus
(
sts
){
setPlayButtonStatus
(
sts
)
{
// this.lastButtonStateCache = this.BUTTON_STATUS.ACTIVE
if
(
this
.
actionButton
.
node
.
buttonStatus
===
sts
)
{
return
...
...
@@ -390,11 +390,11 @@ cc.Class({
}
// console.log(1, curMode, sts);
},
toggleActionButtonStatus
(){
toggleActionButtonStatus
()
{
let
sts
=
this
.
BUTTON_STATUS
.
ACTIVE
;
if
(
this
.
actionButton
.
node
.
buttonStatus
==
sts
)
{
if
(
this
.
actionButton
.
node
.
buttonStatus
==
sts
)
{
sts
=
this
.
BUTTON_STATUS
.
IDLE
;
}
// this.setPlayButtonStatus(sts);
...
...
@@ -423,16 +423,16 @@ cc.Class({
// cc.tween(button.node).to(dur, {scale: 1}).start();
}
else
{
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
);
}
return
;
}
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
);
})
},
changeBtnActive
(
btn
,
isActive
)
{
...
...
@@ -441,23 +441,22 @@ cc.Class({
},
// onButtonClick(event, index) {
// window.ttb = event.currentTarget;
// console.log(event, index)
// },
start
()
{
start
()
{
},
update
(
dt
)
{
update
(
dt
)
{
if
(
this
.
lrc
)
{
// const sts = this.lrc.getCurrentAudioState();
const
sts
=
this
.
lrc
.
isCurrentAudioSourcePlaying
();
if
(
sts
/*sts === cc.audioEngine.AudioState.PLAYING*/
)
{
this
.
setPlayButtonStatus
(
this
.
BUTTON_STATUS
.
ACTIVE
);
if
(
sts
/*sts === cc.audioEngine.AudioState.PLAYING*/
)
{
this
.
setPlayButtonStatus
(
this
.
BUTTON_STATUS
.
ACTIVE
);
// this.lastButtonStateCache = this.BUTTON_STATUS.ACTIVE
}
else
{
this
.
setPlayButtonStatus
(
this
.
BUTTON_STATUS
.
IDLE
);
this
.
setPlayButtonStatus
(
this
.
BUTTON_STATUS
.
IDLE
);
// this.lastButtonStateCache = this.BUTTON_STATUS.IDLE
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment