Commit 0c086d72 authored by liujiaxin's avatar liujiaxin

11

parent 8a51c964
...@@ -30,7 +30,10 @@ ...@@ -30,7 +30,10 @@
], ],
"styles": [ "styles": [
"./node_modules/ng-zorro-antd/ng-zorro-antd.min.css", "./node_modules/ng-zorro-antd/ng-zorro-antd.min.css",
"src/styles.css" "./node_modules/font-awesome/css/font-awesome.css",
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/animate.css/animate.min.css",
"src/styles.scss"
], ],
"scripts": [] "scripts": []
}, },
......
...@@ -24,6 +24,7 @@ import {AudioRecorderComponent} from './common/audio-recorder/audio-recorder.com ...@@ -24,6 +24,7 @@ import {AudioRecorderComponent} from './common/audio-recorder/audio-recorder.com
import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome'; import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { fas } from '@fortawesome/free-solid-svg-icons'; import { fas } from '@fortawesome/free-solid-svg-icons';
import { far } from '@fortawesome/free-regular-svg-icons'; import { far } from '@fortawesome/free-regular-svg-icons';
import { BrLineBreakerPipe } from './pipes/br-line-breaker.pipe';
registerLocaleData(zh); registerLocaleData(zh);
...@@ -36,6 +37,7 @@ registerLocaleData(zh); ...@@ -36,6 +37,7 @@ registerLocaleData(zh);
AudioRecorderComponent, AudioRecorderComponent,
UploadImageWithPreviewComponent, UploadImageWithPreviewComponent,
BackgroundImagePipe, BackgroundImagePipe,
BrLineBreakerPipe,
ResourcePipe, ResourcePipe,
TimePipe, TimePipe,
UploadVideoComponent, UploadVideoComponent,
......
@import '../style/common_mixin.css';
.model-content {
width: 100%;
height: 100%;
}
<div class="courseware-container d-flex">
<div class="model-content"> <div class="col-8">
<div style="position: absolute; left: 200px; top: 100px; width: 800px;">
<input type="text" nz-input [(ngModel)]="item.text" (blur)="save()">
<app-upload-image-with-preview <app-upload-image-with-preview
[picUrl]="item.pic_url" [picUrl]="item.contentObj.pic_id"
(imageUploaded)="onImageUploadSuccess($event, 'pic_url')" (imageUploaded)="onImageUploadSuccess($event)"
></app-upload-image-with-preview> ></app-upload-image-with-preview>
</div>
<div class="flex-fill" style="flex-direction: column;">
<app-audio-recorder <app-audio-recorder
[audioUrl]="item.audio_url" [audioUrl]="item.contentObj.audio_id"
(audioUploaded)="onAudioUploadSuccess($event, 'audio_url')" (audioUploaded)="onAudioUploadSuccess($event)"
></app-audio-recorder> ></app-audio-recorder>
<app-custom-hot-zone></app-custom-hot-zone> <nz-divider></nz-divider>
<app-upload-video></app-upload-video> <h4>Text</h4>
<app-lesson-title-config></app-lesson-title-config> <div class="flex-fill">
<textarea rows="4"
placeholder="add text"
nz-input
[(ngModel)]="inputText"
(blur)="saveText()"></textarea>
</div>
<nz-divider></nz-divider>
<h4>Thinking</h4>
<div class="flex-fill">
<textarea rows="4"
placeholder="add thinking question"
nz-input
[(ngModel)]="question"
(blur)="saveText()"></textarea>
</div>
</div> </div>
</div> </div>
\ No newline at end of file
//@import '../../../src/styles.css';
.d-flex{
display: flex;
}
.p-img {
width: 100%;
min-height: 35rem;
border: 1px solid gray;
background-color: #ddd;
background-repeat: no-repeat;
background-position: center;
background-size: contain
}
...@@ -5,28 +5,39 @@ import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, Ap ...@@ -5,28 +5,39 @@ import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, Ap
@Component({ @Component({
selector: 'app-form', selector: 'app-form',
templateUrl: './form.component.html', templateUrl: './form.component.html',
styleUrls: ['./form.component.css'] styleUrls: ['./form.component.scss']
}) })
export class FormComponent implements OnInit, OnChanges, OnDestroy { export class FormComponent implements OnInit, OnChanges, OnDestroy {
inputText = '';
question = '';
// 储存数据用 // 储存数据用
saveKey = "test_0011"; saveKey = 'ww_audio_image';
// 储存对象 // 储存对象
item; item;
audio = new Audio();
isPlaying = false;
constructor(private appRef: ApplicationRef,private changeDetectorRef: ChangeDetectorRef) { constructor(private appRef: ApplicationRef,
private changeDetectorRef: ChangeDetectorRef) {
} }
ngOnInit() { ngOnInit() {
this.item = {}; this.item = {
contentObj: {
text: 'aaaaaaa',
question: 'sdfsdfsdf',
pic_id: null,
audio_id: null
}
};
// 获取存储的数据 // 获取存储的数据
(<any> window).courseware.getData((data) => { (window as any).courseware.getData((data) => {
console.log(123123, data)
if (data) { if (data) {
this.item = data; this.item = data;
} }
...@@ -42,40 +53,52 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -42,40 +53,52 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
ngOnChanges() { ngOnChanges() {
this.inputText = this.item.contentObj.text || '';
this.question = this.item.contentObj.question || '';
} }
ngOnDestroy() { ngOnDestroy() {
this.audio.pause();
this.audio = null;
} }
init() { init() {
this.audio.onplay = () => {
this.onPlay();
};
this.audio.onpause = () => {
this.onPause();
};
this.inputText = this.item.contentObj.text || '';
this.question = this.item.contentObj.question || '';
}
onPlay() {
this.isPlaying = true;
}
onPause() {
this.isPlaying = false;
}
onClickImg() {
this.audio.play();
} }
/**
* 储存图片数据
* @param e
*/
onImageUploadSuccess(e, key) {
this.item[key] = e.url;
this.save();
}
/**
* 储存音频数据
* @param e
*/
onAudioUploadSuccess(e, key) {
this.item[key] = e.url; onImageUploadSuccess(e) {
this.item.contentObj.pic_id = e.url;
this.save(); this.save();
} }
onAudioUploadSuccess(e) {
this.item.contentObj.audio_id = e.url;
this.save();
}
/** /**
* 储存数据 * 储存数据
*/ */
...@@ -83,6 +106,11 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -83,6 +106,11 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
(<any> window).courseware.setData(this.item, null, this.saveKey); (<any> window).courseware.setData(this.item, null, this.saveKey);
this.refresh(); this.refresh();
} }
saveText() {
this.item.contentObj.text = this.inputText.trim();
this.item.contentObj.question = this.question.trim();
this.save();
}
/** /**
* 刷新 渲染页面 * 刷新 渲染页面
......
import {Pipe, PipeTransform} from '@angular/core'; import {Pipe, PipeTransform} from '@angular/core';
// import {ElectronUtil} from '../util/ElectronUtil';
declare const APP_PATH; declare const APP_PATH;
// const isInElectron = localStorage.getItem('electron'); const isInElectron = localStorage.getItem('electron');
@Pipe({ @Pipe({
name: 'backgroundImage' name: 'backgroundImage'
...@@ -10,10 +9,7 @@ declare const APP_PATH; ...@@ -10,10 +9,7 @@ declare const APP_PATH;
export class BackgroundImagePipe implements PipeTransform { export class BackgroundImagePipe implements PipeTransform {
transform(value: any, coursewareSid?: string) { transform(value: any, coursewareSid?: string) {
// const ret = value ? `url(${value})` : ''; return value > 0 ? `url(/api/media-resource/${value}/file)` : '';
const ret = value ? `url(${value})` : '';
return ret;
// let ret = value > 0 ? `url(/api/media-resource/${value}/file)` : '';
// if (isInElectron && ElectronUtil.hasCached(coursewareSid, value)) { // if (isInElectron && ElectronUtil.hasCached(coursewareSid, value)) {
// ret = `url(file://${APP_PATH}/courseware_cache/${coursewareSid}/${value})`; // ret = `url(file://${APP_PATH}/courseware_cache/${coursewareSid}/${value})`;
// } // }
......
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'brLineBreaker'
})
export class BrLineBreakerPipe implements PipeTransform {
transform(value: any, args?: any): any {
return value ? value.replace(/\n/g, '<br />') : '';
}
}
...@@ -2,25 +2,17 @@ import {Pipe, PipeTransform} from '@angular/core'; ...@@ -2,25 +2,17 @@ import {Pipe, PipeTransform} from '@angular/core';
// import {ElectronUtil} from '../util/ElectronUtil'; // import {ElectronUtil} from '../util/ElectronUtil';
declare const APP_PATH; declare const APP_PATH;
// const isInElectron = localStorage.getItem('electron'); const isInElectron = localStorage.getItem('electron');
@Pipe({ @Pipe({
name: 'resource' name: 'resource'
}) })
export class ResourcePipe implements PipeTransform { export class ResourcePipe implements PipeTransform {
transform(pic_url: any, coursewareSid?: string): string { transform(value: any, coursewareSid?: string): string {
// return pic_url; return value ? `/api/media-resource/${value}/file` : '';
if (pic_url && typeof pic_url === 'object') { // if (isInElectron && ElectronUtil.hasCached(coursewareSid, value)) {
return pic_url; // ret = `file://${APP_PATH}/courseware_cache/${coursewareSid}/${value}`;
}
// console.log('resource', pic_url)
return `${pic_url}?t=${Math.random()}`;
// let ret = value ? `/api/resource/${value}/file` : '';
// let ret = res_id ? `/resource/audio/${res_id}` : '';
// if (isInElectron && ElectronUtil.hasCached(coursewareSid, res_id)) {
// ret = `file://${APP_PATH}/courseware_cache/${coursewareSid}/${res_id}`;
// } // }
// return ret; // return ret;
} }
......
.game-container {
width: 100%;
height: 100%;
background: #ffffff;
background-size: cover;
}
#canvas {
}
@font-face
{
font-family: 'BRLNSDB';
src: url("../../assets/font/BRLNSDB.TTF") ;
}
<div class="game-container" #wrap> <div class="player-preview-content">
<canvas id="canvas" #canvas></canvas> <div
#pic
class="p-courseware-image-audio"
(click)="playAudio($event);"
[style.background-image]="data?.contentObj.pic_id ? 'url('+ data?.contentObj.pic_id +')' : 'url(assets/common/pic-not-upload.jpg)'"
>
</div>
<div class="text" #text
[innerHTML]="data.contentObj.text | brLineBreaker">
</div>
<div class="p-question-btn" [class.show-question]="showQuestion" *ngIf="data?.contentObj?.question"
(click)="toggleQuestionBox()">
<i class="anticon anticon-star"></i>
Thinking
</div>
<div class="p-question-box" [@show-question] *ngIf="showQuestion">
<div class="i-title">
Thinking
</div>
<div class="i-content"
[innerHTML]="data?.contentObj?.question | brLineBreaker"
>
</div>
</div>
</div> </div>
@import '../../app/style/123common_mixin.scss';
.player-preview-content {
width: 100%;
height: 100%;
background-color: white;
}
.p-courseware-image-audio {
width: 100%;
height: 100vh;
margin: 0 auto;
position: relative;
text-align: center;
@include k-img-bg();
}
.text {
font-family: 'ChalkboardSE-Regular';
display: block;
word-break: break-word;
word-spacing: 1px;
line-height: 1.15;
word-wrap: break-word;
white-space: normal;
width: 100%;
padding: 0 5rem;
position: relative;
letter-spacing: 1px;
font-size: 2rem;
}
.p-question-btn {
border: 1px solid #555;
position: absolute;
right: 3rem;
top: 60vh;
background-color: white;
padding: 0.1rem 1rem;
border-radius: 1rem;
text-shadow: 0 0 1px #555;
cursor: pointer;
@include k-no-select();
}
$blue: #1890ff;
.show-question {
color: $blue;
box-shadow: inset 0 0 10px #1890ff;
text-shadow: none;
border-color: #1890ff;
}
.p-question-box {
position: absolute;
width: 50vh;
right: 25vh;
top: 25vh;
background-color: white;
border: 1.5px solid $blue;
border-radius: 1rem;
overflow: hidden;
.i-title {
padding: 0.2rem 1rem;
font-size: 1rem;
color: white;
background-color: $blue;
text-align: center;
}
.i-content {
padding: 1rem;
word-break: break-word;
color: #555;
font-family: "ChalkboardSE-Regular", "Helvetica Neue", Helvetica, Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 21vh;
font-size: 1.4rem;
@include k-no-select();
}
}
import {Component, ElementRef, ViewChild, OnInit, Input, OnDestroy, HostListener} from '@angular/core'; import { Component, ElementRef, ViewChild, OnInit, Input, OnDestroy, HostListener, OnChanges, AfterViewInit } from '@angular/core';
import * as _ from 'lodash';
import { import {
Label, Label,
MySprite, tweenChange, MySprite, tweenChange,
...@@ -11,6 +11,7 @@ import {Subject} from 'rxjs'; ...@@ -11,6 +11,7 @@ import {Subject} from 'rxjs';
import {debounceTime} from 'rxjs/operators'; import {debounceTime} from 'rxjs/operators';
import TWEEN from '@tweenjs/tween.js'; import TWEEN from '@tweenjs/tween.js';
import { animate, state, style, transition, trigger } from '@angular/animations';
...@@ -18,662 +19,107 @@ import TWEEN from '@tweenjs/tween.js'; ...@@ -18,662 +19,107 @@ import TWEEN from '@tweenjs/tween.js';
@Component({ @Component({
selector: 'app-play', selector: 'app-play',
templateUrl: './play.component.html', templateUrl: './play.component.html',
styleUrls: ['./play.component.css'] styleUrls: ['./play.component.scss'],
animations: [
trigger('show-question', [
state('in', style({opacity: '0', top: '60vh', right: '3rem'})),
transition(':enter', [
style({opacity: '0', top: '40vh', right: '3rem'}),
animate('0.5s ease-in-out', style({opacity: '1', top: '25vh', right: '25vh'}))
]),
transition(':leave', [
style({opacity: '1', top: '25vh', right: '25vh'}),
animate('0.5s ease-in-out', style({opacity: '0', top: '40vh', right: '3rem'}))
]),
])
],
}) })
export class PlayComponent implements OnInit, OnDestroy { export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit {
@ViewChild('canvas', {static: true }) canvas: ElementRef;
@ViewChild('wrap', {static: true }) wrap: ElementRef;
// 数据 // 数据
data; data;
saveKey = 'ww_audio_image';
ctx;
canvasWidth = 1280; // canvas实际宽度
canvasHeight = 720; // canvas实际高度
canvasBaseW = 1280; // canvas 资源预设宽度
canvasBaseH = 720; // canvas 资源预设高度
mx; // 点击x坐标
my; // 点击y坐标
// 资源
rawImages = new Map(res);
rawAudios = new Map(resAudio);
images = new Map();
animationId: any;
winResizeEventStream = new Subject();
audioObj = {}; isPlaying = false;
audio = new Audio();
renderArr; fntSizeRect: any;
mapScale = 1; @ViewChild('pic')
domPic: ElementRef;
canvasLeft; @ViewChild('text')
canvasTop; domText: ElementRef;
saveKey = 'test_0011';
btnLeft;
btnRight;
pic1;
pic2;
canTouch = true;
curPic;
@HostListener('window:resize', ['$event'])
onResize(event) {
this.winResizeEventStream.next();
}
@Input() sid;
showQuestion: boolean;
ngOnInit() { ngOnInit() {
this.data = {}; this.data = {};
// 获取数据 // 获取数据
const getData = (<any> window).courseware.getData; const getData = ( window as any).courseware.getData;
getData((data) => { getData((data) => {
if (data && typeof data === 'object') {
if (data && typeof data == 'object') { console.log(3333, data);
this.data = data; this.data = data;
console.log(4444, data);
this.audio.pause();
this.audio.currentTime = 0;
this.isPlaying = false;
if (this.data.contentObj && this.data.contentObj.audio_id ) {
this.audio.src = this.data.contentObj.audio_id;
this.audio.load();
}
this.showQuestion = false;
} }
// console.log('data:' , data);
// 初始化 各事件监听
this.initListener();
// 若无数据 则为预览模式 需要填充一些默认数据用来显示
this.initDefaultData();
// 初始化 音频资源
this.initAudio();
// 初始化 图片资源
this.initImg();
// 开始预加载资源
this.load();
}, this.saveKey); }, this.saveKey);
this.audio.onended = () => {
this.isPlaying = false;
};
} }
ngOnDestroy() { ngOnDestroy() {
window['curCtx'] = null; this.audio.pause();
window.cancelAnimationFrame(this.animationId); this.audio = null;
}
load() {
// 预加载资源
this.loadResources().then(() => {
window["air"].hideAirClassLoading(this.saveKey, this.data);
this.init();
this.update();
});
} }
ngOnChanges(data) {
init() {
this.initCtx();
this.initData();
this.initView();
} }
initCtx() { ngAfterViewInit() {
this.canvasWidth = this.wrap.nativeElement.clientWidth; this.calcPicHeight();
this.canvasHeight = this.wrap.nativeElement.clientHeight;
this.canvas.nativeElement.width = this.wrap.nativeElement.clientWidth;
this.canvas.nativeElement.height = this.wrap.nativeElement.clientHeight;
this.ctx = this.canvas.nativeElement.getContext('2d');
this.canvas.nativeElement.width = this.canvasWidth;
this.canvas.nativeElement.height = this.canvasHeight;
window['curCtx'] = this.ctx;
} }
@HostListener('window:resize', ['$event'])
onResize(event) {
this.calcPicHeight();
updateItem(item) {
if (item) {
item.update();
}
} }
updateArr(arr) { calcPicHeight() {
if (!arr) { // Ken 2018-08-23 17:46 宁波Amy: 固定字号大小
return; const textHeight = this.domText.nativeElement.clientHeight;
} const delta = _.isEmpty(this.data.contentObj.text) ? 0 : 40;
for (let i = 0; i < arr.length; i++) { this.domPic.nativeElement.style.height = `calc(100% - ${textHeight + delta}px)`;
arr[i].update(this);
}
} }
playAudio(ev) {
ev.preventDefault();
if (this.data.contentObj && this.data.contentObj.audio_id) {
if (this.isPlaying) {
this.audio.pause();
initListener() { this.isPlaying = false;
} else {
this.winResizeEventStream this.audio.play();
.pipe(debounceTime(500)) this.isPlaying = true;
.subscribe(data => {
this.renderAfterResize();
});
// ---------------------------------------------
const setParentOffset = () => {
const rect = this.canvas.nativeElement.getBoundingClientRect();
this.canvasLeft = rect.left;
this.canvasTop = rect.top;
};
const setMxMyByTouch = (event) => {
if (event.touches.length <= 0) {
return;
}
if (this.canvasLeft == null) {
setParentOffset();
}
this.mx = event.touches[0].pageX - this.canvasLeft;
this.my = event.touches[0].pageY - this.canvasTop;
};
const setMxMyByMouse = (event) => {
this.mx = event.offsetX;
this.my = event.offsetY;
};
// ---------------------------------------------
let firstTouch = true;
const touchDownFunc = (e) => {
if (firstTouch) {
firstTouch = false;
removeMouseListener();
} }
setMxMyByTouch(e);
this.mapDown(e);
};
const touchMoveFunc = (e) => {
setMxMyByTouch(e);
this.mapMove(e);
};
const touchUpFunc = (e) => {
setMxMyByTouch(e);
this.mapUp(e);
};
const mouseDownFunc = (e) => {
if (firstTouch) {
firstTouch = false;
removeTouchListener();
}
setMxMyByMouse(e);
this.mapDown(e);
};
const mouseMoveFunc = (e) => {
setMxMyByMouse(e);
this.mapMove(e);
};
const mouseUpFunc = (e) => {
setMxMyByMouse(e);
this.mapUp(e);
};
const element = this.canvas.nativeElement;
const addTouchListener = () => {
element.addEventListener('touchstart', touchDownFunc);
element.addEventListener('touchmove', touchMoveFunc);
element.addEventListener('touchend', touchUpFunc);
element.addEventListener('touchcancel', touchUpFunc);
};
const removeTouchListener = () => {
element.removeEventListener('touchstart', touchDownFunc);
element.removeEventListener('touchmove', touchMoveFunc);
element.removeEventListener('touchend', touchUpFunc);
element.removeEventListener('touchcancel', touchUpFunc);
};
const addMouseListener = () => {
element.addEventListener('mousedown', mouseDownFunc);
element.addEventListener('mousemove', mouseMoveFunc);
element.addEventListener('mouseup', mouseUpFunc);
};
const removeMouseListener = () => {
element.removeEventListener('mousedown', mouseDownFunc);
element.removeEventListener('mousemove', mouseMoveFunc);
element.removeEventListener('mouseup', mouseUpFunc);
};
addMouseListener();
addTouchListener();
}
playAudio(key, now = false, callback = null) {
const audio = this.audioObj[key];
if (audio) {
if (now) {
audio.pause();
audio.currentTime = 0;
}
if (callback) {
audio.onended = () => {
callback();
};
}
audio.play();
} }
} }
toggleQuestionBox() {
this.showQuestion = !this.showQuestion;
loadResources() {
const pr = [];
this.rawImages.forEach((value, key) => {// 预加载图片
const p = this.preload(value)
.then(img => {
this.images.set(key, img);
})
.catch(err => console.log(err));
pr.push(p);
});
this.rawAudios.forEach((value, key) => {// 预加载音频
const a = this.preloadAudio(value)
.then(() => {
// this.images.set(key, img);
})
.catch(err => console.log(err));
pr.push(a);
});
return Promise.all(pr);
}
preload(url) {
return new Promise((resolve, reject) => {
const img = new Image();
// img.crossOrigin = "anonymous";
img.onload = () => resolve(img);
img.onerror = reject;
img.src = url;
});
} }
preloadAudio(url) {
return new Promise((resolve, reject) => {
const audio = new Audio();
audio.oncanplay = (a) => {
resolve();
};
audio.onerror = () => {
reject();
};
audio.src = url;
audio.load();
});
}
renderAfterResize() {
this.canvasWidth = this.wrap.nativeElement.clientWidth;
this.canvasHeight = this.wrap.nativeElement.clientHeight;
this.init();
}
checkClickTarget(target) {
const rect = target.getBoundingBox();
if (this.checkPointInRect(this.mx, this.my, rect)) {
return true;
}
return false;
}
getWorlRect(target) {
let rect = target.getBoundingBox();
if (target.parent) {
const pRect = this.getWorlRect(target.parent);
rect.x += pRect.x;
rect.y += pRect.y;
}
return rect;
}
checkPointInRect(x, y, rect) {
if (x >= rect.x && x <= rect.x + rect.width) {
if (y >= rect.y && y <= rect.y + rect.height) {
return true;
}
}
return false;
}
addUrlToAudioObj(key, url = null, vlomue = 1, loop = false, callback = null) {
const audioObj = this.audioObj;
if (url == null) {
url = key;
}
this.rawAudios.set(key, url);
const audio = new Audio();
audio.src = url;
audio.load();
audio.loop = loop;
audio.volume = vlomue;
audioObj[key] = audio;
if (callback) {
audio.onended = () => {
callback();
};
}
}
addUrlToImages(url) {
this.rawImages.set(url, url);
}
// ======================================================编写区域==========================================================================
/**
* 添加默认数据 便于无数据时的展示
*/
initDefaultData() {
if (!this.data.pic_url) {
this.data.pic_url = 'assets/play/default/pic.jpg';
this.data.pic_url_2 = 'assets/play/default/pic.jpg';
}
}
/**
* 添加预加载图片
*/
initImg() {
this.addUrlToImages(this.data.pic_url);
this.addUrlToImages(this.data.pic_url_2);
}
/**
* 添加预加载音频
*/
initAudio() {
// 音频资源
this.addUrlToAudioObj(this.data.audio_url);
this.addUrlToAudioObj(this.data.audio_url_2);
// 音效
this.addUrlToAudioObj('click', this.rawAudios.get('click'), 0.3);
}
/**
* 初始化数据
*/
initData() {
const sx = this.canvasWidth / this.canvasBaseW;
const sy = this.canvasHeight / this.canvasBaseH;
const s = Math.min(sx, sy);
this.mapScale = s;
// this.mapScale = sx;
// this.mapScale = sy;
this.renderArr = [];
}
/**
* 初始化试图
*/
initView() {
this.initPic();
this.initBottomPart();
}
initBottomPart() {
const btnLeft = new MySprite();
btnLeft.init(this.images.get('btn_left'));
btnLeft.x = this.canvasWidth - 150 * this.mapScale;
btnLeft.y = this.canvasHeight - 100 * this.mapScale;
btnLeft.setScaleXY(this.mapScale);
this.renderArr.push(btnLeft);
this.btnLeft = btnLeft;
const btnRight = new MySprite();
btnRight.init(this.images.get('btn_right'));
btnRight.x = this.canvasWidth - 50 * this.mapScale;
btnRight.y = this.canvasHeight - 100 * this.mapScale;
btnRight.setScaleXY(this.mapScale);
this.renderArr.push(btnRight);
this.btnRight = btnRight;
}
initPic() {
const maxW = this.canvasWidth * 0.7;
const pic1 = new MySprite();
pic1.init(this.images.get(this.data.pic_url));
pic1.x = this.canvasWidth / 2;
pic1.y = this.canvasHeight / 2;
pic1.setScaleXY(maxW / pic1.width);
this.renderArr.push(pic1);
this.pic1 = pic1;
const label1 = new Label();
label1.text = this.data.text;
label1.textAlign = 'center';
label1.fontSize = 50;
label1.fontName = 'BRLNSDB';
label1.fontColor = '#ffffff';
pic1.addChild(label1);
const pic2 = new MySprite();
pic2.init(this.images.get(this.data.pic_url_2));
pic2.x = this.canvasWidth / 2 + this.canvasWidth;
pic2.y = this.canvasHeight / 2;
pic2.setScaleXY(maxW / pic2.width);
this.renderArr.push(pic2);
this.pic2 = pic2;
this.curPic = pic1;
}
btnLeftClicked() {
this.lastPage();
}
btnRightClicked() {
this.nextPage();
}
lastPage() {
if (this.curPic == this.pic1) {
return;
}
this.canTouch = false;
const moveLen = this.canvasWidth;
tweenChange(this.pic1, {x: this.pic1.x + moveLen}, 1);
tweenChange(this.pic2, {x: this.pic2.x + moveLen}, 1, () => {
this.canTouch = true;
this.curPic = this.pic1;
});
}
nextPage() {
if (this.curPic == this.pic2) {
return;
}
this.canTouch = false;
const moveLen = this.canvasWidth;
tweenChange(this.pic1, {x: this.pic1.x - moveLen}, 1);
tweenChange(this.pic2, {x: this.pic2.x - moveLen}, 1, () => {
this.canTouch = true;
this.curPic = this.pic2;
});
}
pic1Clicked() {
this.playAudio(this.data.audio_url);
}
pic2Clicked() {
this.playAudio(this.data.audio_url_2);
}
mapDown(event) {
if (!this.canTouch) {
return;
}
if ( this.checkClickTarget(this.btnLeft) ) {
this.btnLeftClicked();
return;
}
if ( this.checkClickTarget(this.btnRight) ) {
this.btnRightClicked();
return;
}
if ( this.checkClickTarget(this.pic1) ) {
this.pic1Clicked();
return;
}
if ( this.checkClickTarget(this.pic2) ) {
this.pic2Clicked();
return;
}
}
mapMove(event) {
}
mapUp(event) {
}
update() {
// ----------------------------------------------------------
this.animationId = window.requestAnimationFrame(this.update.bind(this));
// 清除画布内容
this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
// tween 更新动画
TWEEN.update();
// ----------------------------------------------------------
this.updateArr(this.renderArr);
}
} }
@mixin hide-overflow-text {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
@mixin k-no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@mixin k-img-bg {
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
...@@ -3,6 +3,8 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; ...@@ -3,6 +3,8 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module'; import { AppModule } from './app/app.module';
import { environment } from './environments/environment'; import { environment } from './environments/environment';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
if (environment.production) { if (environment.production) {
enableProdMode(); enableProdMode();
......
/* You can add global styles to this file, and also import other style files */
/* You can add global styles to this file, and also import other style files */
@mixin hide-overflow-text {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
@mixin k-no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@mixin k-img-bg {
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
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