Commit fda2e532 authored by Tt's avatar Tt

处理完成

parent d38b7c43
...@@ -5325,9 +5325,6 @@ ...@@ -5325,9 +5325,6 @@
"ProgressBar": { "ProgressBar": {
"__id__": 115 "__id__": 115
}, },
"videoPlayer": {
"__id__": 14
},
"currentTimeLabel": { "currentTimeLabel": {
"__id__": 129 "__id__": 129
}, },
......
...@@ -18,7 +18,7 @@ export default class dg29_museum_game extends cc.Component { ...@@ -18,7 +18,7 @@ export default class dg29_museum_game extends cc.Component {
this.initData(); this.initData();
this.initView(); this.initView();
this.initEvent(); this.initEvent();
this.initVideoPlayer(); // this.initVideoPlayer();
this.initGame(); this.initGame();
} }
...@@ -262,6 +262,10 @@ export default class dg29_museum_game extends cc.Component { ...@@ -262,6 +262,10 @@ export default class dg29_museum_game extends cc.Component {
} }
onTouchNext() { onTouchNext() {
console.log('next') console.log('next')
if(this.gameEnd){
this.onTouchExit();
return
}
if (this.recording) return; if (this.recording) return;
if (!this.nextQuestion) { if (!this.nextQuestion) {
pg.view.find(this, 'layout_game/layout_record/img_question').active = false; pg.view.find(this, 'layout_game/layout_record/img_question').active = false;
...@@ -286,7 +290,7 @@ export default class dg29_museum_game extends cc.Component { ...@@ -286,7 +290,7 @@ export default class dg29_museum_game extends cc.Component {
//-----------------------------------------Video------------------------------ //-----------------------------------------Video------------------------------
@property(cc.Node) barTag: cc.Node = null; @property(cc.Node) barTag: cc.Node = null;
@property(cc.Node) ProgressBar: cc.Node = null; @property(cc.Node) ProgressBar: cc.Node = null;
@property(cc.VideoPlayer) videoPlayer: cc.VideoPlayer = null; // @property(cc.VideoPlayer) videoPlayer: cc.VideoPlayer = null;
@property(cc.Label) currentTimeLabel: cc.Label = null; @property(cc.Label) currentTimeLabel: cc.Label = null;
...@@ -311,61 +315,61 @@ export default class dg29_museum_game extends cc.Component { ...@@ -311,61 +315,61 @@ export default class dg29_museum_game extends cc.Component {
} }
@property(cc.Node) video_canvas: cc.Node = null; @property(cc.Node) video_canvas: cc.Node = null;
hideVideoPlayer() { // hideVideoPlayer() {
if (!this.node) return; // if (!this.node) return;
if (!this.videoPlayer) return; // if (!this.videoPlayer) return;
if (!this.layout_video) return; // if (!this.layout_video) return;
this.layout_video.active = true; // this.layout_video.active = true;
this.videoPlayer.stayOnBottom = true; // this.videoPlayer.stayOnBottom = true;
this.videoPlayer.node.x = 0; // this.videoPlayer.node.x = 0;
this.videoPlayer.node.y = 0; // this.videoPlayer.node.y = 0;
this.videoPlayer.node.width = 100; // this.videoPlayer.node.width = 100;
this.videoPlayer.node.height = 100; // this.videoPlayer.node.height = 100;
} // }
showVideoPlayer() { // showVideoPlayer() {
if (!this.node) return; // if (!this.node) return;
if (!this.videoPlayer) return; // if (!this.videoPlayer) return;
if (!this.layout_video) return; // if (!this.layout_video) return;
this.hideUI(); // this.hideUI();
this.scheduleOnce(() => { // this.scheduleOnce(() => {
this.layout_video.active = true; // this.layout_video.active = true;
this.videoPlayer.stayOnBottom = true; // this.videoPlayer.stayOnBottom = true;
this.videoPlayer.node.x = this.video_canvas.x; // this.videoPlayer.node.x = this.video_canvas.x;
this.videoPlayer.node.y = this.video_canvas.y; // this.videoPlayer.node.y = this.video_canvas.y;
this.videoPlayer.node.width = this.video_canvas.width; // this.videoPlayer.node.width = this.video_canvas.width;
this.videoPlayer.node.height = this.video_canvas.height; // this.videoPlayer.node.height = this.video_canvas.height;
if (!this._isReadyToPlay) { // if (!this._isReadyToPlay) {
//首次播放 // //首次播放
this._isReadyToPlay = false; // this._isReadyToPlay = false;
// this.videoPlayer.remoteURL = this.data.video; // // this.videoPlayer.remoteURL = this.data.video;
pg.view.touchOn(this.playButton, this.play, this); // pg.view.touchOn(this.playButton, this.play, this);
pg.view.touchOn(this.pauseButton, this.pause, this); // pg.view.touchOn(this.pauseButton, this.pause, this);
} // }
//重复播放 // //重复播放
this.videoPlayer.currentTime = 0; // this.videoPlayer.currentTime = 0;
this._isPlayComplated = false; // this._isPlayComplated = false;
this.play(); // this.play();
this.scheduleOnce(() => { // this.scheduleOnce(() => {
if (!this.node) return; // if (!this.node) return;
if (!this.videoPlayer) return; // if (!this.videoPlayer) return;
if (!this.layout_video) return; // if (!this.layout_video) return;
this.videoPlayer.stayOnBottom = false; // this.videoPlayer.stayOnBottom = false;
this.videoControls.active = false; // this.videoControls.active = false;
}, 3); // }, 3);
}, 0.1) // }, 0.1)
} // }
private timeCtrl: TimeCtrl; private timeCtrl: TimeCtrl;
showVideo() { showVideo() {
return new Promise(async (reslove) => { return new Promise(async (reslove) => {
this.hideUI(); this.hideUI();
pg.event.emit("play_video") pg.event.emit("play_video")
if (1) return; // if (1) return;
this.showVideoPlayer(); // this.showVideoPlayer();
this.timeCtrl = pg.time.delayCtrl() this.timeCtrl = pg.time.delayCtrl()
this.timeCtrl.fillTime(99999); this.timeCtrl.fillTime(99999);
await this.timeCtrl.wait(); await this.timeCtrl.wait();
...@@ -374,155 +378,155 @@ export default class dg29_museum_game extends cc.Component { ...@@ -374,155 +378,155 @@ export default class dg29_museum_game extends cc.Component {
} }
hideVideo() { hideVideo() {
this.timeCtrl.reset(); this.timeCtrl.reset();
this.videoPlayer.node.x = -10000; // this.videoPlayer.node.x = -10000;
this.videoPlayer.node.y = -10000; // this.videoPlayer.node.y = -10000;
this.layout_video.active = false; this.layout_video.active = false;
this.showUI(); this.showUI();
} }
initVideoUrl() { // initVideoUrl() {
this.prepared = true; // this.prepared = true;
this.touchlayer.on(cc.Node.EventType.TOUCH_START, this.tryPlayVideo, this) // this.touchlayer.on(cc.Node.EventType.TOUCH_START, this.tryPlayVideo, this)
this.touchlayer._touchListener.setSwallowTouches(false) // this.touchlayer._touchListener.setSwallowTouches(false)
this.videoPlayer.node.active = true; // this.videoPlayer.node.active = true;
this.videoPlayer.remoteURL = this.data.video; // this.videoPlayer.remoteURL = this.data.video;
this.videoPlayer.resourceType = cc.VideoPlayer.ResourceType.REMOTE; // this.videoPlayer.resourceType = cc.VideoPlayer.ResourceType.REMOTE;
} // }
private prepared: boolean; // private prepared: boolean;
tryPlayVideo() { // tryPlayVideo() {
cc.log("touch layer--") // cc.log("touch layer--")
if (this.prepared) { // if (this.prepared) {
this.prepared = false; // this.prepared = false;
this.videoPlayer.volume = 0; // this.videoPlayer.volume = 0;
this.videoPlayer.play(); // this.videoPlayer.play();
this.scheduleOnce(() => { // this.scheduleOnce(() => {
this.videoPlayer.volume = 1; // this.videoPlayer.volume = 1;
this.videoPlayer.pause(); // this.videoPlayer.pause();
}, 1) // }, 1)
} // }
} // }
initVideoPlayer() { // initVideoPlayer() {
if (1) return; // if (1) return;
this.initVideoUrl(); // this.initVideoUrl();
this.videoPlayer.node.x = -10000; // this.videoPlayer.node.x = -10000;
this.videoPlayer.node.y = -10000; // this.videoPlayer.node.y = -10000;
this.layout_video.active = false; // this.layout_video.active = false;
// this.videoPlayer.node.on('ready-to-play', () => { // // this.videoPlayer.node.on('ready-to-play', () => {
// console.log('ready-to-play'); // // console.log('ready-to-play');
// this._isReadyToPlay = true; // // this._isReadyToPlay = true;
// this._isPlayComplated = false; // // this._isPlayComplated = false;
// this.videoPlayer.currentTime = 0; // // this.videoPlayer.currentTime = 0;
// }); // // });
// this.videoPlayer.node.on('meta-loaded', () => { // // this.videoPlayer.node.on('meta-loaded', () => {
// console.log('meta-loaded'); // // console.log('meta-loaded');
// }); // // });
// this.videoPlayer.node.on('clicked', () => { // // this.videoPlayer.node.on('clicked', () => {
// if (!this.node) return; // // if (!this.node) return;
// if (!this.videoPlayer) return; // // if (!this.videoPlayer) return;
// if (!this.layout_video) return; // // if (!this.layout_video) return;
// this.videoPlayer.stayOnBottom = true; // // this.videoPlayer.stayOnBottom = true;
// this.videoControls.active = true; // // this.videoControls.active = true;
// if (this.time1) { // // if (this.time1) {
// clearTimeout(this.time1); // // clearTimeout(this.time1);
// } // // }
// this.time1 = setTimeout(() => { // // this.time1 = setTimeout(() => {
// if (!this.node) return; // // if (!this.node) return;
// if (!this.videoPlayer) return; // // if (!this.videoPlayer) return;
// if (!this.layout_video) return; // // if (!this.layout_video) return;
// this.videoPlayer.stayOnBottom = false; // // this.videoPlayer.stayOnBottom = false;
// this.videoControls.active = false; // // this.videoControls.active = false;
// }, 6000); // // }, 6000);
// }); // // });
// this.videoPlayer.node.on('touchstart', () => { // // this.videoPlayer.node.on('touchstart', () => {
// if (!this.node) return; // // if (!this.node) return;
// if (!this.videoPlayer) return; // // if (!this.videoPlayer) return;
// if (!this.layout_video) return; // // if (!this.layout_video) return;
// this.videoPlayer.stayOnBottom = true; // // this.videoPlayer.stayOnBottom = true;
// this.videoControls.active = true; // // this.videoControls.active = true;
// if (this.time1) { // // if (this.time1) {
// clearTimeout(this.time1); // // clearTimeout(this.time1);
// } // // }
// this.time1 = setTimeout(() => { // // this.time1 = setTimeout(() => {
// if (!this.node) return; // // if (!this.node) return;
// if (!this.videoPlayer) return; // // if (!this.videoPlayer) return;
// if (!this.layout_video) return; // // if (!this.layout_video) return;
// this.videoPlayer.stayOnBottom = false; // // this.videoPlayer.stayOnBottom = false;
// this.videoControls.active = false; // // this.videoControls.active = false;
// }, 6000); // // }, 6000);
// }); // // });
// this.videoPlayer.node.on('playing', () => { // // this.videoPlayer.node.on('playing', () => {
// this.playButton.active = false; // // this.playButton.active = false;
// this.pauseButton.active = true; // // this.pauseButton.active = true;
// }); // // });
// this.videoPlayer.node.on('paused', () => { // // this.videoPlayer.node.on('paused', () => {
// console.log('paused'); // // console.log('paused');
// this.playButton.active = true; // // this.playButton.active = true;
// this.pauseButton.active = false; // // this.pauseButton.active = false;
// }); // // });
// this.videoPlayer.node.on('stopped', () => { // // this.videoPlayer.node.on('stopped', () => {
// console.log('stopped'); // // console.log('stopped');
// this.playButton.active = true; // // this.playButton.active = true;
// this.pauseButton.active = false; // // this.pauseButton.active = false;
// }); // // });
// this.videoPlayer.node.on('completed', async () => { // // this.videoPlayer.node.on('completed', async () => {
// console.log('completed'); // // console.log('completed');
// this._isPlayComplated = true; // // this._isPlayComplated = true;
// this.playButton.active = false; // // this.playButton.active = false;
// this.pauseButton.active = false; // // this.pauseButton.active = false;
// // 循环播放下一个 // // // 循环播放下一个
// this.hideVideo(); // // this.hideVideo();
// }); // // });
// cc.view.setResizeCallback((params) => { // // cc.view.setResizeCallback((params) => {
// console.log('Resize', params); // // console.log('Resize', params);
// this.initdDrag() // // this.initdDrag()
// }); // // });
// this.initdDrag(); // // this.initdDrag();
} // }
initdDrag() { // initdDrag() {
const maxX = this.ProgressBar.width; // const maxX = this.ProgressBar.width;
const minX = 0; // const minX = 0;
this.barTag.off(cc.Node.EventType.TOUCH_START); // this.barTag.off(cc.Node.EventType.TOUCH_START);
this.barTag.on(cc.Node.EventType.TOUCH_START, (e) => { // this.barTag.on(cc.Node.EventType.TOUCH_START, (e) => {
if (!this._isReadyToPlay) { // if (!this._isReadyToPlay) {
return; // return;
} // }
console.log("TOUCH_START"); // console.log("TOUCH_START");
}); // });
this.barTag.off(cc.Node.EventType.TOUCH_MOVE); // this.barTag.off(cc.Node.EventType.TOUCH_MOVE);
this.barTag.on(cc.Node.EventType.TOUCH_MOVE, (e) => { // this.barTag.on(cc.Node.EventType.TOUCH_MOVE, (e) => {
if (!this._isReadyToPlay) { // if (!this._isReadyToPlay) {
return; // return;
} // }
const worldPos = e.getLocation(); // const worldPos = e.getLocation();
const localPos = this.barTag.parent.convertToNodeSpaceAR(worldPos); // const localPos = this.barTag.parent.convertToNodeSpaceAR(worldPos);
let newX = localPos.x; // let newX = localPos.x;
newX = Math.min(maxX, Math.max(newX, minX)); // newX = Math.min(maxX, Math.max(newX, minX));
this.barTag.x = newX; // this.barTag.x = newX;
const percent = newX / maxX; // const percent = newX / maxX;
const dur = this.videoPlayer.getDuration(); // const dur = this.videoPlayer.getDuration();
this.currentTimeLabel.string = this.formatTime(percent * dur); // this.currentTimeLabel.string = this.formatTime(percent * dur);
this.videoPlayer.currentTime = percent * dur; // this.videoPlayer.currentTime = percent * dur;
}); // });
this.barTag.off(cc.Node.EventType.TOUCH_END); // this.barTag.off(cc.Node.EventType.TOUCH_END);
this.barTag.on(cc.Node.EventType.TOUCH_END, (e) => { // this.barTag.on(cc.Node.EventType.TOUCH_END, (e) => {
if (!this._isReadyToPlay) { // if (!this._isReadyToPlay) {
return; // return;
} // }
console.log("TOUCH_ENDED"); // console.log("TOUCH_ENDED");
this.updateBarByPos(this.barTag.x); // this.updateBarByPos(this.barTag.x);
}); // });
this.barTag.off(cc.Node.EventType.MOUSE_UP); // this.barTag.off(cc.Node.EventType.MOUSE_UP);
this.barTag.on(cc.Node.EventType.MOUSE_UP, (e) => { // this.barTag.on(cc.Node.EventType.MOUSE_UP, (e) => {
if (!this._isReadyToPlay) { // if (!this._isReadyToPlay) {
return; // return;
} // }
console.log("MOUSE_UP"); // console.log("MOUSE_UP");
this.updateBarByPos(this.barTag.x); // this.updateBarByPos(this.barTag.x);
}); // });
} // }
playVideoEnd() { playVideoEnd() {
this.hideVideo(); this.hideVideo();
...@@ -552,7 +556,7 @@ export default class dg29_museum_game extends cc.Component { ...@@ -552,7 +556,7 @@ export default class dg29_museum_game extends cc.Component {
} }
else if (event === cc.VideoPlayer.EventType.COMPLETED) { else if (event === cc.VideoPlayer.EventType.COMPLETED) {
this._isPlayComplated = true; // this._isPlayComplated = true;
this.playButton.active = false; this.playButton.active = false;
this.pauseButton.active = false; this.pauseButton.active = false;
// 循环播放下一个 // 循环播放下一个
...@@ -580,108 +584,108 @@ export default class dg29_museum_game extends cc.Component { ...@@ -580,108 +584,108 @@ export default class dg29_museum_game extends cc.Component {
} }
} }
updateBarByPos(newX) { // updateBarByPos(newX) {
const maxX = this.ProgressBar.width; // const maxX = this.ProgressBar.width;
const minX = 0; // const minX = 0;
let percent = newX / maxX; // let percent = newX / maxX;
if (percent > 1) { // if (percent > 1) {
percent = 1 // percent = 1
} // }
const dur = this.videoPlayer.getDuration(); // const dur = this.videoPlayer.getDuration();
this.videoPlayer.currentTime = percent * dur // this.videoPlayer.currentTime = percent * dur
} // }
private _isPlayComplated: boolean // private _isPlayComplated: boolean
updateBarByTime(ct) { // updateBarByTime(ct) {
if (this._isPlayComplated) { // if (this._isPlayComplated) {
return; // return;
} // }
this.currentTimeLabel.string = this.formatTime(ct); // this.currentTimeLabel.string = this.formatTime(ct);
const dur = this.videoPlayer.getDuration(); // const dur = this.videoPlayer.getDuration();
let percent = ct / dur; // let percent = ct / dur;
if (percent > 1) { // if (percent > 1) {
percent = 1 // percent = 1
} // }
this.ProgressBar.getComponent(cc.ProgressBar).progress = percent; // this.ProgressBar.getComponent(cc.ProgressBar).progress = percent;
const maxX = this.ProgressBar.width; // const maxX = this.ProgressBar.width;
const minX = 0; // const minX = 0;
let newX = percent * maxX; // let newX = percent * maxX;
newX = Math.min(maxX, Math.max(newX, minX)); // newX = Math.min(maxX, Math.max(newX, minX));
this.barTag.x = newX; // this.barTag.x = newX;
} // }
formatTime(time) { // formatTime(time) {
if (time === undefined) { // if (time === undefined) {
return ''; // return '';
} // }
let hh = "" + Math.floor(time / 60 / 60); // let hh = "" + Math.floor(time / 60 / 60);
if (Number(hh) > 0) { // if (Number(hh) > 0) {
hh = `${hh.toString().padStart(2, '0')}:`; // hh = `${hh.toString().padStart(2, '0')}:`;
} else { // } else {
hh = ''; // hh = '';
} // }
const mm = Math.floor(time / 60).toString().padStart(2, '0'); // const mm = Math.floor(time / 60).toString().padStart(2, '0');
const ss = Math.round(time % 60).toString().padStart(2, '0'); // const ss = Math.round(time % 60).toString().padStart(2, '0');
return `${hh}${mm}:${ss}`; // return `${hh}${mm}:${ss}`;
} // }
play() { // play() {
if (!this._isReadyToPlay) return; // if (!this._isReadyToPlay) return;
this.videoPlayer.play(); // this.videoPlayer.play();
} // }
pause() { // pause() {
this.videoPlayer.pause(); // this.videoPlayer.pause();
} // }
forward() { // forward() {
} // }
backward() { // backward() {
} // }
replay() { // replay() {
this._isPlayComplated = false; // this._isPlayComplated = false;
this.videoPlayer.currentTime = 0; // this.videoPlayer.currentTime = 0;
this.videoPlayer.play(); // this.videoPlayer.play();
} // }
private time1: any; // private time1: any;
private isVideoFull: boolean;//false, // private isVideoFull: boolean;//false,
private tempPos: any; // private tempPos: any;
fullScreen() { // fullScreen() {
// setTimeout(() => { // // setTimeout(() => {
// // IOS下视频的全屏适配比例有问题,所以做一个计算 // // // IOS下视频的全屏适配比例有问题,所以做一个计算
// this.videoPlayer.node.width = Math.min(this.node.width, this.node.height * 16 / 9); // // this.videoPlayer.node.width = Math.min(this.node.width, this.node.height * 16 / 9);
// }, 100); // // }, 100);
} // }
updateVideo() { // updateVideo() {
if (!this._isReadyToPlay) { // if (!this._isReadyToPlay) {
return; // return;
} // }
if (this.videoPlayer) { // if (this.videoPlayer) {
const ct = this.videoPlayer.currentTime; // const ct = this.videoPlayer.currentTime;
if (ct) { // if (ct) {
this.updateBarByTime(ct); // this.updateBarByTime(ct);
} // }
if (this.videoPlayer.isPlaying()) { // if (this.videoPlayer.isPlaying()) {
if (this.playButton.active) { // if (this.playButton.active) {
this.playButton.active = false; // this.playButton.active = false;
} // }
if (!this.pauseButton.active) { // if (!this.pauseButton.active) {
this.pauseButton.active = true; // this.pauseButton.active = true;
} // }
} else { // } else {
if (!this.playButton.active) { // if (!this.playButton.active) {
this.playButton.active = true; // this.playButton.active = true;
} // }
if (this.pauseButton.active) { // if (this.pauseButton.active) {
this.pauseButton.active = false; // this.pauseButton.active = false;
} // }
} // }
} // }
} // }
//----------------------------------------VideoEND------------------------- //----------------------------------------VideoEND-------------------------
showData(data) { showData(data) {
...@@ -708,7 +712,7 @@ export default class dg29_museum_game extends cc.Component { ...@@ -708,7 +712,7 @@ export default class dg29_museum_game extends cc.Component {
private waitTime: number; private waitTime: number;
update(dt) { update(dt) {
this.showTimeUpdate(); this.showTimeUpdate();
this.updateVideo(); // this.updateVideo();
if (!this.waitTime) this.waitTime = 8; if (!this.waitTime) this.waitTime = 8;
this.waitTime -= dt; this.waitTime -= dt;
if (this.waitTime < 0) { if (this.waitTime < 0) {
...@@ -724,7 +728,7 @@ export default class dg29_museum_game extends cc.Component { ...@@ -724,7 +728,7 @@ export default class dg29_museum_game extends cc.Component {
pg.view.find(this, 'layout_xiaodi/btn_go').active = true; pg.view.find(this, 'layout_xiaodi/btn_go').active = true;
}, 0.5) }, 0.5)
} }
pg.view.touchOn(pg.view.find(this, 'layout_xiaodi/btn_go'), this.onTouchExit, this); // pg.view.touchOn(pg.view.find(this, 'layout_xiaodi/btn_go'), this.onTouchExit, this);
pg.view.setString(pg.view.find(this, 'layout_xiaodi/btn_go/text'), this.data.npcAudioText) pg.view.setString(pg.view.find(this, 'layout_xiaodi/btn_go/text'), this.data.npcAudioText)
pg.view.find(this, 'layout_xiaodi').active = true; pg.view.find(this, 'layout_xiaodi').active = true;
pg.view.find(this, 'layout_xiaodi').getComponent(dg_xiaodi).playOver(this.data.npcAudioEnd) pg.view.find(this, 'layout_xiaodi').getComponent(dg_xiaodi).playOver(this.data.npcAudioEnd)
...@@ -734,7 +738,9 @@ export default class dg29_museum_game extends cc.Component { ...@@ -734,7 +738,9 @@ export default class dg29_museum_game extends cc.Component {
pg.view.find(this, 'layout_xiaodi').active = false; pg.view.find(this, 'layout_xiaodi').active = false;
pg.view.find(this, 'layout_xiaodi').getComponent(dg_xiaodi).playOverEnd() pg.view.find(this, 'layout_xiaodi').getComponent(dg_xiaodi).playOverEnd()
} }
private gameEnd : boolean;
private gameOver() { private gameOver() {
this.gameEnd = true;
this.rich_content.active = false; this.rich_content.active = false;
// 按钮显示未下一题的显示内容 // 按钮显示未下一题的显示内容
this.showXiaodi(); this.showXiaodi();
......
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