Commit 14802b2f authored by Li MingZhe's avatar Li MingZhe

feat: 增加动画图片类型 背景乐

parent dad6427b
This diff is collapsed.
...@@ -55,4 +55,4 @@ ...@@ -55,4 +55,4 @@
"tslint": "~5.18.0", "tslint": "~5.18.0",
"typescript": "~3.7.5" "typescript": "~3.7.5"
} }
} }
\ No newline at end of file
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
<ng-template #truthyTemplate > <ng-template #truthyTemplate >
<div class="btn-delete" (click)="onBtnDeleteAudio()"> <div class="btn-delete" (click)="onBtnDeleteAudio()">
<fa-icon icon="close"></fa-icon> <!-- <fa-icon icon="close"></fa-icon> -->
<i nz-icon nzType="close" nzTheme="outline"></i>
</div> </div>
</ng-template> </ng-template>
......
...@@ -26,7 +26,7 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -26,7 +26,7 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
uploadData; uploadData;
@Input() @Input()
needRemove = false; needRemove = true;
@Input() @Input()
audioItem: any = null; audioItem: any = null;
...@@ -157,6 +157,7 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -157,6 +157,7 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
onBtnDeleteAudio() { onBtnDeleteAudio() {
this.audioUrl = null; this.audioUrl = null;
this.audioUploaded.emit({});
this.audioRemoved.emit(); this.audioRemoved.emit();
} }
......
...@@ -21,5 +21,13 @@ ...@@ -21,5 +21,13 @@
</nz-select> </nz-select>
</div> </div>
<div style="display: flex; align-items: center; margin-top: 20px;">
<h4> 背景乐添加: </h4>
<app-audio-recorder
style="margin-left: 20px"
[audioUrl]="item.bg_audio_url"
(audioUploaded)="onAudioUploadSuccess($event, 'bg_audio_url', item)">
</app-audio-recorder>
</div>
</div> </div>
...@@ -31,11 +31,17 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -31,11 +31,17 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
text: true, text: true,
audio: true, audio: true,
}, },
// { {
// name: '动画', name: '图片',
// rect: true, pic: true,
// anima: true audio: true,
// } },
{
name: '动画',
rect: true,
anima: true,
audio: true,
}
] ]
......
This diff is collapsed.
...@@ -301,8 +301,8 @@ cc.Class({ ...@@ -301,8 +301,8 @@ cc.Class({
item.addComponent(cc.Button); item.addComponent(cc.Button);
item.on('click', () => { item.on('click', () => {
if (item.audioClip) { if (item.audioClip) {
cc.audioEngine.stopAll(); cc.audioEngine.stopAllEffects();
cc.audioEngine.play(item.audioClip, false, 0.5); cc.audioEngine.playEffect(item.audioClip, false, 0.5);
} }
}); });
}, },
......
...@@ -89,7 +89,7 @@ cc.Class({ ...@@ -89,7 +89,7 @@ cc.Class({
getDefaultData() { getDefaultData() {
const dataJson = '{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/cea0606b09735d7346dc57626f0a0a9b.png","rect":{"x":205.28,"y":0,"width":844.44,"height":475}},"hotZoneItemArr":[{"id":"1597805601321","index":0,"pic_url":"http://staging-teach.cdn.ireadabc.com/ddf2a304102c90bd2ed1cadf27f8feb7.png","text":"arrow","audio_url":"http://staging-teach.cdn.ireadabc.com/1961d807c944e6551af02c7b57e117f3.mp3","itemType":"rect","fontScale":0.98046875,"imgScale":4.139756944444445,"mapScale":0.98046875,"skeJsonData":{"url":"http://staging-teach.cdn.ireadabc.com/ab66b9d704187f60fd8a61c981435b8e.json","name":"finish2_ske.json"},"texJsonData":{"url":"http://staging-teach.cdn.ireadabc.com/a4b74d67df855493b394c7df9625ba24.json","name":"finish2_tex.json"},"texPngData":{"url":"http://staging-teach.cdn.ireadabc.com/e485027385bab93761a5d1749166ba83.png","name":"finish2_tex.png"},"gIdx":"0","fontSize":50,"fontName":"BRLNSR_1","ontColor":"#8f3758","rect":{"x":75.22,"y":135.5,"width":200,"height":200}},{"id":"1597805655229","index":1,"pic_url":"http://staging-teach.cdn.ireadabc.com/18f2a029e02d679da8d42746daea228f.png","text":"home","audio_url":"http://staging-teach.cdn.ireadabc.com/0128a59057e63c4c6b4b96556d077a98.mp3","itemType":"rect","fontScale":0.98046875,"imgScale":3.72578125,"mapScale":0.98046875,"skeJsonData":{"url":"http://staging-teach.cdn.ireadabc.com/bd825dcceea298d1146be8067ae3d17f.json","name":"finish1_ske.json"},"texJsonData":{"url":"http://staging-teach.cdn.ireadabc.com/246f8991b729fa3e5a7f4802de828efa.json","name":"finish1_tex.json"},"texPngData":{"url":"http://staging-teach.cdn.ireadabc.com/5a0c5af3e952acd0ac83a6e5c6f03ff1.png","name":"finish1_tex.png"},"gIdx":"0","fontSize":50,"fontName":"BRLNSR_1","ontColor":"#8f3758","rect":{"x":661.72,"y":69,"width":77,"height":77}}],"picArr":[{"pic_url":"http://staging-teach.cdn.ireadabc.com/29cdcc64c0898a1ec63f89b8b2fdd0e6.png","audio_url":"http://staging-teach.cdn.ireadabc.com/f51e3fedc88aa69a99f6ef579f7de047.mp3","text":"arrow"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/18f2a029e02d679da8d42746daea228f.png","audio_url":"http://staging-teach.cdn.ireadabc.com/fbe2f23b9eb191a9330f99800e0d54d5.mp3","text":"home"}]}' const dataJson = '{"bgColorId":0,"bgColor":"#f9bd03","bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/539e2f58cb1817f852d9c09ec1ac7c8b.png","rect":{"x":265.18,"y":0,"width":776.65,"height":500}},"hotZoneItemArr":[{"id":"1611197962070","index":0,"pic_url":"http://staging-teach.cdn.ireadabc.com/8ce25a36313edb9dfa3de77ba85cb6b9.png","text":"aaa","audio_url":"http://staging-teach.cdn.ireadabc.com/cd8daa8b4d8ff707b3a3680e80bc4761.mp3","itemType":"rect","fontScale":1.02109375,"imgScale":0.7029268568840579,"mapScale":1.02109375,"skeJsonData":{"url":"http://staging-teach.cdn.ireadabc.com/3db1a0ed6b7e33d5f9f284e1a5980349.json","name":"Ubbie_ske.json"},"texJsonData":{"url":"http://staging-teach.cdn.ireadabc.com/4232e00c9b1d272e650e51dbb785e498.json","name":"Ubbie_tex.json"},"texPngData":{"url":"http://staging-teach.cdn.ireadabc.com/2e56dbe3134380952a725eacceb86359.png","name":"Ubbie_tex.png"},"gIdx":"0","rect":{"x":-1.68,"y":-1,"width":200,"height":200}},{"id":"1611197966644","index":1,"pic_url":"http://staging-teach.cdn.ireadabc.com/c8abf7383d65bcbdba8f390785cece60.png","audio_url":"http://staging-teach.cdn.ireadabc.com/1961d807c944e6551af02c7b57e117f3.mp3","itemType":"pic","fontScale":1.02109375,"imgScale":0.2536231884057971,"mapScale":1.02109375,"gIdx":"1","rect":{"x":7.32,"y":424,"width":70,"height":70}},{"id":"1611197971104","index":2,"audio_url":"http://staging-teach.cdn.ireadabc.com/694a80e21cefd6e53880d61e684e1c94.mp3","itemType":"rect","fontScale":1.02109375,"imgScale":1,"mapScale":1.02109375,"skeJsonData":{"url":"http://staging-teach.cdn.ireadabc.com/7efceac56cc9a61b107a11457390d3c6.json","name":"finish1_ske.json"},"texJsonData":{"url":"http://staging-teach.cdn.ireadabc.com/d6e8db4fb385127de9e3cd9d8a9530f7.json","name":"finish1_tex.json"},"texPngData":{"url":"http://staging-teach.cdn.ireadabc.com/96f5c7a9ac9f433c9c870c38b0811a38.png","name":"finish1_tex.png"},"gIdx":"2","rect":{"x":575.32,"y":303,"width":200,"height":200}}],"bg_audio_url":"http://staging-teach.cdn.ireadabc.com/3fa65d5f667a2ef9059d3dfc5df74a4d.mp3"}'
const data1 = JSON.parse(dataJson); const data1 = JSON.parse(dataJson);
return data1; return data1;
...@@ -164,9 +164,18 @@ cc.Class({ ...@@ -164,9 +164,18 @@ cc.Class({
}, },
addPreloadImage() { addPreloadImage() {
if (this.data.bgItem) { if (this.data.bgItem) {
this._imageResList.push({url: this.data.bgItem.url}); this._imageResList.push({ url: this.data.bgItem.url });
}
if (!this.data.hotZoneItemArr) {
return;
} }
this.data.hotZoneItemArr.forEach((item) => {
if (item.pic_url) {
this._imageResList.push({ url: item.pic_url });
}
})
}, },
...@@ -178,6 +187,8 @@ cc.Class({ ...@@ -178,6 +187,8 @@ cc.Class({
this.data.hotZoneItemArr.forEach((item) => { this.data.hotZoneItemArr.forEach((item) => {
this._audioResList.push({url: item.audio_url}); this._audioResList.push({url: item.audio_url});
}) })
this._audioResList.push({url: this.bg_audio_url});
}, },
addPreloadAnima() { addPreloadAnima() {
...@@ -185,14 +196,12 @@ cc.Class({ ...@@ -185,14 +196,12 @@ cc.Class({
return; return;
} }
this.data.hotZoneItemArr.forEach((item) => { this.data.hotZoneItemArr.forEach((item) => {
// if (item.gIdx == '0') { if (item.skeJsonData) {
// this._animaResList.push({url: item.skeJsonData.url}); this._animaResList.push({ url: item.skeJsonData.url || '' });
// this._animaResList.push({url: item.texJsonData.url}); this._animaResList.push({ url: item.texJsonData.url || ''});
// this._animaResList.push({url: item.texPngData.url}); this._animaResList.push({ url: item.texPngData.url || ''});
// } }
}) })
}, },
loadEnd() { loadEnd() {
...@@ -205,6 +214,15 @@ cc.Class({ ...@@ -205,6 +214,15 @@ cc.Class({
this.initBottomPart(); this.initBottomPart();
this.initCircle(); this.initCircle();
this.initListener(); this.initListener();
this.initMusic();
},
initMusic() {
cc.assetManager.loadRemote(this.data.bg_audio_url, (err, clip) => {
cc.audioEngine.setMusicVolume(0.3);
const audioID = cc.audioEngine.playMusic(clip, true);
});
}, },
_cocosScale: null, _cocosScale: null,
...@@ -343,12 +361,13 @@ cc.Class({ ...@@ -343,12 +361,13 @@ cc.Class({
bgBottom.y = -frameSize.height / 2 * this._cocosScale - 15 * bgBottom.scaleY; bgBottom.y = -frameSize.height / 2 * this._cocosScale - 15 * bgBottom.scaleY;
this.data.hotZoneItemArr.forEach((item) => { this.data.hotZoneItemArr.forEach((item) => {
// if (item.gIdx == '0') { if (item.gIdx == '0') {
// this.setOneAnima(item); this.setOneCircle(item);
// } else if (item.gIdx == '1') { } else if (item.gIdx == '1') {
// this.setOnePic(item); this.setOnePic(item);
// } } else if (item.gIdx == '2') {
this.setOneCircle(item); this.setOneAnima(item);
}
}); });
}); });
...@@ -364,7 +383,14 @@ cc.Class({ ...@@ -364,7 +383,14 @@ cc.Class({
const bgBottom = cc.find('Canvas/bgBottom'); const bgBottom = cc.find('Canvas/bgBottom');
const script = bgBottom.getComponent('bgBottom'); const script = bgBottom.getComponent('bgBottom');
script.setItemData(this.data.hotZoneItemArr);
const picArr = [];
this.data.hotZoneItemArr.forEach((item) => {
if (item.gIdx == '0') {
picArr.push(item);
}
});
script.setItemData(picArr);
}, },
...@@ -467,8 +493,8 @@ cc.Class({ ...@@ -467,8 +493,8 @@ cc.Class({
console.log('clicked'); console.log('clicked');
if (animaNode.audioClip) { if (animaNode.audioClip) {
cc.audioEngine.stopAll(); cc.audioEngine.stopAllEffects();
cc.audioEngine.play(animaNode.audioClip, false, 0.8); cc.audioEngine.playEffect(animaNode.audioClip, false, 0.8);
} }
if (animationNames.length > 0) { if (animationNames.length > 0) {
...@@ -504,10 +530,30 @@ cc.Class({ ...@@ -504,10 +530,30 @@ cc.Class({
picNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale; picNode.y = this.hotZoneBg.height / 2 - data.rect.height * scale - data.rect.y * scale;
picNode.anchorX = picNode.anchorY = 0; picNode.anchorX = picNode.anchorY = 0;
if (data.audio_url) {
this.addPicAudio(picNode);
}
}); });
}, },
addPicAudio(picNode) {
const data = picNode.data;
cc.assetManager.loadRemote(data.audio_url, (err, audioClip) => {
picNode.audioClip = audioClip;
});
picNode.addComponent(cc.Button);
picNode.on('click', () => {
if (picNode.audioClip) {
cc.audioEngine.stopAllEffects();
cc.audioEngine.playEffect(picNode.audioClip, false, 0.8);
}
});
},
setOneCircle(data) { setOneCircle(data) {
const rate = (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width; const rate = (this.hotZoneBg.scale * this.hotZoneBg.width) / this.data.bgItem.rect.width;
...@@ -605,8 +651,8 @@ cc.Class({ ...@@ -605,8 +651,8 @@ cc.Class({
console.log('clicked'); console.log('clicked');
if (animaNode.audioClip) { if (animaNode.audioClip) {
cc.audioEngine.stopAll(); cc.audioEngine.stopAllEffects();
cc.audioEngine.play(animaNode.audioClip, false, 0.8); cc.audioEngine.playEffect(animaNode.audioClip, false, 0.8);
} }
if (animationNames.length > 0) { if (animationNames.length > 0) {
...@@ -637,7 +683,7 @@ cc.Class({ ...@@ -637,7 +683,7 @@ cc.Class({
node.data.animaNode.showAnima(); node.data.animaNode.showAnima();
// if (node.data.audioClip) { // if (node.data.audioClip) {
// cc.audioEngine.stopAll(); // cc.audioEngine.stopAll();
// cc.audioEngine.play(node.data.audioClip, false, 0.8); // cc.audioEngine.playEffect(node.data.audioClip, false, 0.8);
// } // }
this.hideCircle(); this.hideCircle();
return; return;
......
...@@ -24,6 +24,7 @@ cc.Class({ ...@@ -24,6 +24,7 @@ cc.Class({
_maxPage: null, _maxPage: null,
_lineMaxCount: null, _lineMaxCount: null,
_disW: null, _disW: null,
_maxW: null,
onLoad: function onLoad() { onLoad: function onLoad() {
this._canTouch = true; this._canTouch = true;
this._isTop = false; this._isTop = false;
...@@ -34,8 +35,8 @@ cc.Class({ ...@@ -34,8 +35,8 @@ cc.Class({
this._pageIndex = 0; this._pageIndex = 0;
this._maxPage = 0; this._maxPage = 0;
this._disW = 5; this._disW = 5;
var maxW = 1280 - 90; this._maxW = 1280 - 90;
this._lineMaxCount = Math.floor(maxW / (this._disW + this._itemLen)); this._lineMaxCount = Math.floor(this._maxW / (this._disW + this._itemLen));
}, },
start: function start() { start: function start() {
this._initListener(); this._initListener();
...@@ -109,7 +110,7 @@ cc.Class({ ...@@ -109,7 +110,7 @@ cc.Class({
return; return;
} }
if (_this2._pageIndex >= _this2._maxPage) { if (_this2._pageIndex >= _this2._maxPage - 1) {
return; return;
} }
...@@ -144,7 +145,7 @@ cc.Class({ ...@@ -144,7 +145,7 @@ cc.Class({
this._pageUpBtn.opacity = 255; this._pageUpBtn.opacity = 255;
} }
if (this._pageIndex == this._maxPage) { if (this._pageIndex == this._maxPage - 1) {
this._pageDownBtn.opacity = 100; this._pageDownBtn.opacity = 100;
} else { } else {
this._pageDownBtn.opacity = 255; this._pageDownBtn.opacity = 255;
...@@ -182,12 +183,37 @@ cc.Class({ ...@@ -182,12 +183,37 @@ cc.Class({
return; return;
} }
this._dataArr = dataArr; this._dataArr = dataArr; // this._maxPage = Math.ceil(dataArr.length / this._lineMaxCount) - 1;
this._maxPage = Math.ceil(dataArr.length / this._lineMaxCount) - 1;
this._initPageArr();
this._pageIndex = 0; this._pageIndex = 0;
this._refreshPage(); this._refreshPage();
}, },
_pageArr: null,
_initPageArr: function _initPageArr() {
var tmpArr = [];
this._pageArr = [tmpArr];
var curLen = this._disW;
for (var i = 0; i < this._dataArr.length; i++) {
var item = this._addOneItem(this._dataArr[i]);
curLen += item.width + this._disW;
if (curLen > this._maxW) {
tmpArr = [item];
this._pageArr.push(tmpArr);
} else {
tmpArr.push(item);
}
}
this._maxPage = this._pageArr.length;
console.log('this._maxPage: ', this._maxPage);
},
_itemLen: null, _itemLen: null,
_addOneItem: function _addOneItem(data) { _addOneItem: function _addOneItem(data) {
var item = new cc.Node(); var item = new cc.Node();
...@@ -203,6 +229,7 @@ cc.Class({ ...@@ -203,6 +229,7 @@ cc.Class({
this._addItemAudio(item, data.audio_url); this._addItemAudio(item, data.audio_url);
item.data = data;
return item; return item;
}, },
_addItemPic: function _addItemPic(item, url) { _addItemPic: function _addItemPic(item, url) {
...@@ -246,6 +273,12 @@ cc.Class({ ...@@ -246,6 +273,12 @@ cc.Class({
} }
label.font = this._labelFont; label.font = this._labelFont;
label._forceUpdateRenderData(true);
if (labelNode.width > this._itemLen) {
item.width = labelNode.width;
}
}, },
_addItemAudio: function _addItemAudio(item, url) { _addItemAudio: function _addItemAudio(item, url) {
var _this4 = this; var _this4 = this;
...@@ -264,8 +297,8 @@ cc.Class({ ...@@ -264,8 +297,8 @@ cc.Class({
item.addComponent(cc.Button); item.addComponent(cc.Button);
item.on('click', function () { item.on('click', function () {
if (item.audioClip) { if (item.audioClip) {
cc.audioEngine.stopAll(); cc.audioEngine.stopAllEffects();
cc.audioEngine.play(item.audioClip, false, 0.5); cc.audioEngine.playEffect(item.audioClip, false, 0.5);
} }
}); });
}, },
...@@ -276,20 +309,36 @@ cc.Class({ ...@@ -276,20 +309,36 @@ cc.Class({
var dataArr = this._dataArr; var dataArr = this._dataArr;
var disW = this._disW; var disW = this._disW;
var startIndex = this._pageIndex * this._lineMaxCount; var startIndex = this._pageIndex * this._lineMaxCount; // const showArr = dataArr.slice(startIndex, startIndex + this._lineMaxCount);
var showArr = dataArr.slice(startIndex, startIndex + this._lineMaxCount);
var baseX = -(disW + this._itemLen) * (showArr.length - 1) / 2; var showArr = this._pageArr[this._pageIndex];
var baseX = this._getCurPageBaseX(); // const baseX = -(disW + this._itemLen) * (showArr.length - 1) / 2;
var baseY = -25; var baseY = -25;
showArr.forEach(function (data, i) { showArr.forEach(function (el, i) {
var item = _this5._addOneItem(data); var item = _this5._addOneItem(el.data);
_this5._itemLayer.addChild(item); _this5._itemLayer.addChild(item);
item.x = baseX + (disW + _this5._itemLen) * i; item.x = baseX + (disW + item.width) / 2;
item.y = baseY; item.y = baseY;
baseX = item.x + (disW + item.width) / 2;
}); });
this._setPageBtnState(); this._setPageBtnState();
},
_getCurPageBaseX: function _getCurPageBaseX() {
var arr = this._pageArr[this._pageIndex];
console.log('arr: ', arr);
var curLen = this._disW;
for (var i = 0; i < arr.length; i++) {
curLen += arr[i].width + this._disW;
}
return -curLen / 2;
} // update (dt) {}, } // update (dt) {},
}); });
......
This diff is collapsed.
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
"children": [ "children": [
"scene" "scene"
], ],
"height": 376.28125, "height": 375.984375,
"type": "panel", "type": "panel",
"width": 470 "width": 470
}, },
...@@ -55,12 +55,12 @@ ...@@ -55,12 +55,12 @@
"children": [ "children": [
"node-library" "node-library"
], ],
"height": 376.28125, "height": 375.984375,
"type": "panel", "type": "panel",
"width": 264 "width": 264
} }
], ],
"height": 376.28125, "height": 375.984375,
"type": "dock-h", "type": "dock-h",
"width": 737 "width": 737
}, },
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
"timeline", "timeline",
"game-window" "game-window"
], ],
"height": 275.734375, "height": 276,
"type": "panel", "type": "panel",
"width": 737 "width": 737
} }
......
{"version":"1.0.8","stats":{"/Users/limingzhe/Documents/workspace/pro_hw/pro_cocos/cc_mz_004/play/temp/quick-scripts/src/__qc_index__.js":"2020-12-09T05:57:51.956Z","/Users/limingzhe/Documents/workspace/pro_hw/pro_cocos/cc_mz_004/play/temp/quick-scripts/src/assets/mz_004/script/util.js":"2020-12-09T05:57:51.938Z","/Users/limingzhe/Documents/workspace/pro_hw/pro_cocos/cc_mz_004/play/temp/quick-scripts/src/assets/mz_004/prefab/bgBottom.js":"2020-12-09T05:57:51.940Z","/Users/limingzhe/Documents/workspace/pro_hw/pro_cocos/cc_mz_004/play/temp/quick-scripts/src/assets/mz_004/script/scene.js":"2020-12-09T05:57:51.936Z"}} {"version":"1.0.8","stats":{"/Users/limingzhe/Documents/workspace/pro_hw/pro_cocos/cc_mz_004/play/temp/quick-scripts/src/__qc_index__.js":"2021-01-21T02:50:42.204Z","/Users/limingzhe/Documents/workspace/pro_hw/pro_cocos/cc_mz_004/play/temp/quick-scripts/src/assets/mz_004/script/scene.js":"2021-01-21T02:50:42.185Z","/Users/limingzhe/Documents/workspace/pro_hw/pro_cocos/cc_mz_004/play/temp/quick-scripts/src/assets/mz_004/script/util.js":"2021-01-21T02:50:42.186Z","/Users/limingzhe/Documents/workspace/pro_hw/pro_cocos/cc_mz_004/play/temp/quick-scripts/src/assets/mz_004/prefab/bgBottom.js":"2021-01-21T02:50:42.187Z"}}
(function () { (function () {
var scripts = [{"deps":{"./assets/mz_004/script/util":1,"./assets/mz_004/prefab/bgBottom":2,"./assets/mz_004/script/scene":3},"path":"preview-scripts/__qc_index__.js"},{"deps":{},"path":"preview-scripts/assets/mz_004/script/util.js"},{"deps":{"../script/util":1},"path":"preview-scripts/assets/mz_004/prefab/bgBottom.js"},{"deps":{"./util":1},"path":"preview-scripts/assets/mz_004/script/scene.js"}]; var scripts = [{"deps":{"./assets/mz_004/script/util":2,"./assets/mz_004/prefab/bgBottom":3,"./assets/mz_004/script/scene":1},"path":"preview-scripts/__qc_index__.js"},{"deps":{"./util":2},"path":"preview-scripts/assets/mz_004/script/scene.js"},{"deps":{},"path":"preview-scripts/assets/mz_004/script/util.js"},{"deps":{"../script/util":2},"path":"preview-scripts/assets/mz_004/prefab/bgBottom.js"}];
var entries = ["preview-scripts/__qc_index__.js"]; var entries = ["preview-scripts/__qc_index__.js"];
var bundleScript = 'preview-scripts/__qc_bundle__.js'; var bundleScript = 'preview-scripts/__qc_bundle__.js';
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -24,6 +24,7 @@ cc.Class({ ...@@ -24,6 +24,7 @@ cc.Class({
_maxPage: null, _maxPage: null,
_lineMaxCount: null, _lineMaxCount: null,
_disW: null, _disW: null,
_maxW: null,
onLoad: function onLoad() { onLoad: function onLoad() {
this._canTouch = true; this._canTouch = true;
this._isTop = false; this._isTop = false;
...@@ -34,8 +35,8 @@ cc.Class({ ...@@ -34,8 +35,8 @@ cc.Class({
this._pageIndex = 0; this._pageIndex = 0;
this._maxPage = 0; this._maxPage = 0;
this._disW = 5; this._disW = 5;
var maxW = 1280 - 90; this._maxW = 1280 - 90;
this._lineMaxCount = Math.floor(maxW / (this._disW + this._itemLen)); this._lineMaxCount = Math.floor(this._maxW / (this._disW + this._itemLen));
}, },
start: function start() { start: function start() {
this._initListener(); this._initListener();
...@@ -109,7 +110,7 @@ cc.Class({ ...@@ -109,7 +110,7 @@ cc.Class({
return; return;
} }
if (_this2._pageIndex >= _this2._maxPage) { if (_this2._pageIndex >= _this2._maxPage - 1) {
return; return;
} }
...@@ -144,7 +145,7 @@ cc.Class({ ...@@ -144,7 +145,7 @@ cc.Class({
this._pageUpBtn.opacity = 255; this._pageUpBtn.opacity = 255;
} }
if (this._pageIndex == this._maxPage) { if (this._pageIndex == this._maxPage - 1) {
this._pageDownBtn.opacity = 100; this._pageDownBtn.opacity = 100;
} else { } else {
this._pageDownBtn.opacity = 255; this._pageDownBtn.opacity = 255;
...@@ -182,12 +183,37 @@ cc.Class({ ...@@ -182,12 +183,37 @@ cc.Class({
return; return;
} }
this._dataArr = dataArr; this._dataArr = dataArr; // this._maxPage = Math.ceil(dataArr.length / this._lineMaxCount) - 1;
this._maxPage = Math.ceil(dataArr.length / this._lineMaxCount) - 1;
this._initPageArr();
this._pageIndex = 0; this._pageIndex = 0;
this._refreshPage(); this._refreshPage();
}, },
_pageArr: null,
_initPageArr: function _initPageArr() {
var tmpArr = [];
this._pageArr = [tmpArr];
var curLen = this._disW;
for (var i = 0; i < this._dataArr.length; i++) {
var item = this._addOneItem(this._dataArr[i]);
curLen += item.width + this._disW;
if (curLen > this._maxW) {
tmpArr = [item];
this._pageArr.push(tmpArr);
} else {
tmpArr.push(item);
}
}
this._maxPage = this._pageArr.length;
console.log('this._maxPage: ', this._maxPage);
},
_itemLen: null, _itemLen: null,
_addOneItem: function _addOneItem(data) { _addOneItem: function _addOneItem(data) {
var item = new cc.Node(); var item = new cc.Node();
...@@ -203,6 +229,7 @@ cc.Class({ ...@@ -203,6 +229,7 @@ cc.Class({
this._addItemAudio(item, data.audio_url); this._addItemAudio(item, data.audio_url);
item.data = data;
return item; return item;
}, },
_addItemPic: function _addItemPic(item, url) { _addItemPic: function _addItemPic(item, url) {
...@@ -246,6 +273,12 @@ cc.Class({ ...@@ -246,6 +273,12 @@ cc.Class({
} }
label.font = this._labelFont; label.font = this._labelFont;
label._forceUpdateRenderData(true);
if (labelNode.width > this._itemLen) {
item.width = labelNode.width;
}
}, },
_addItemAudio: function _addItemAudio(item, url) { _addItemAudio: function _addItemAudio(item, url) {
var _this4 = this; var _this4 = this;
...@@ -264,8 +297,8 @@ cc.Class({ ...@@ -264,8 +297,8 @@ cc.Class({
item.addComponent(cc.Button); item.addComponent(cc.Button);
item.on('click', function () { item.on('click', function () {
if (item.audioClip) { if (item.audioClip) {
cc.audioEngine.stopAll(); cc.audioEngine.stopAllEffects();
cc.audioEngine.play(item.audioClip, false, 0.5); cc.audioEngine.playEffect(item.audioClip, false, 0.5);
} }
}); });
}, },
...@@ -276,20 +309,36 @@ cc.Class({ ...@@ -276,20 +309,36 @@ cc.Class({
var dataArr = this._dataArr; var dataArr = this._dataArr;
var disW = this._disW; var disW = this._disW;
var startIndex = this._pageIndex * this._lineMaxCount; var startIndex = this._pageIndex * this._lineMaxCount; // const showArr = dataArr.slice(startIndex, startIndex + this._lineMaxCount);
var showArr = dataArr.slice(startIndex, startIndex + this._lineMaxCount);
var baseX = -(disW + this._itemLen) * (showArr.length - 1) / 2; var showArr = this._pageArr[this._pageIndex];
var baseX = this._getCurPageBaseX(); // const baseX = -(disW + this._itemLen) * (showArr.length - 1) / 2;
var baseY = -25; var baseY = -25;
showArr.forEach(function (data, i) { showArr.forEach(function (el, i) {
var item = _this5._addOneItem(data); var item = _this5._addOneItem(el.data);
_this5._itemLayer.addChild(item); _this5._itemLayer.addChild(item);
item.x = baseX + (disW + _this5._itemLen) * i; item.x = baseX + (disW + item.width) / 2;
item.y = baseY; item.y = baseY;
baseX = item.x + (disW + item.width) / 2;
}); });
this._setPageBtnState(); this._setPageBtnState();
},
_getCurPageBaseX: function _getCurPageBaseX() {
var arr = this._pageArr[this._pageIndex];
console.log('arr: ', arr);
var curLen = this._disW;
for (var i = 0; i < arr.length; i++) {
curLen += arr[i].width + this._disW;
}
return -curLen / 2;
} // update (dt) {}, } // update (dt) {},
}); });
......
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