Commit b5dadd1e authored by Chen Jiping's avatar Chen Jiping

feat:增加配置界面

parent 9f3a2900
......@@ -128,5 +128,8 @@
}
}
},
"defaultProject": "ng-template-generator"
}
"defaultProject": "ng-template-generator",
"cli": {
"analytics": "6538edac-ec62-413b-aeca-1ff86f787ac0"
}
}
\ No newline at end of file
import { Obj } from "./ObjBean";
export class ExercisesBean{
answerIndex;
answer : AnswerBean;
}
export function getDefaultExercises(){
let exercises = new ExercisesBean();
exercises.answer = new AnswerBean();
return exercises;
}
export class LetterBean extends Obj{
backgroud:String;
isFill = '0';
}
export function getDefaultLetter(){
let letter = new LetterBean();
return letter;
}
export class AnswerBean extends Obj{
letterArr = [];
}
\ No newline at end of file
export class Obj{
/**音频材料 */
audioUrl: String;
/**图片材料 */
picUrl:String;
val : String;
}
\ No newline at end of file
import { Obj } from "./ObjBean";
export class TitleBean extends Obj{
part1 : String;
part2: String;
}
export function getDefaultTile(){
let title = new TitleBean();
title.part1 = "C";
title.part2 = "Read and point";
return title;
}
\ No newline at end of file
<div class="model-content">
<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
[picUrl]="item.pic_url"
(imageUploaded)="onImageUploadSuccess($event, 'pic_url')"
></app-upload-image-with-preview>
<app-audio-recorder
[audioUrl]="item.audio_url"
(audioUploaded)="onAudioUploadSuccess($event, 'audio_url')"
></app-audio-recorder>
<app-custom-hot-zone></app-custom-hot-zone>
<app-upload-video></app-upload-video>
<app-lesson-title-config></app-lesson-title-config>
<div nz-row>
<div nz-col nzOffset='4'>
<h1 nz-title>课程练习内容编辑</h1>
</div>
</div>
<div nz-row>
</div>
\ No newline at end of file
<div nz-col [nzSpan]="15" nzOffset="3">
<nz-divider nzText="课程名称" nzOrientation="left"></nz-divider>
<nz-form-item>
<nz-form-label [nzSpan]="3" nzFor="part1">标题1</nz-form-label>
<nz-form-control [nzSpan]="6">
<nz-input-group nzAddOnBefore="Part">
<input type="text" id="part1" nz-input [(ngModel)]="item.title.part1" (blur)="save()">
</nz-input-group>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="3" nzFor="part2">标题2</nz-form-label>
<nz-form-control [nzSpan]="6">
<input nz-input type="text" id="part2" [(ngModel)]="item.title.part2" (blur)="save()">
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="3" nzFor="audioUrl">发音</nz-form-label>
<nz-form-control [nzSpan]="6">
<app-audio-recorder [audioUrl]="item.title.audioUrl" id="audioUrl"
(audioUploaded)="onAudioUploadSuccess($event, item.title, 'audioUrl')">
</app-audio-recorder>
</nz-form-control>
</nz-form-item>
<nz-divider nzText="听力材料" nzOrientation="left"></nz-divider>
<nz-form-item>
<nz-form-control [nzSpan]="6" nzOffset="3">
<app-audio-recorder id="item.audioUrl" [audioUrl]="item.audioUrl"
(audioUploaded)="onAudioUploadSuccess($event, item, 'audioUrl')">
</app-audio-recorder>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="3" nzFor="backgroudColor">主色调色号</nz-form-label>
<nz-form-control [nzSpan]="6">
<input nz-input type="text" nz-input placeholder="十六进制,如#000000" maxlength="7" id="backgroudColor"
[(ngModel)]="item.backgroudColor" (blur)="save()">
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="3">字母背景颜色</nz-form-label>
<nz-form-control [nzSpan]="6">
<div [ngStyle]="{'background':item.backgroudColor,'width':'100px','height':'30px','border':'1px solid #CCC'}">
</div>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="3">序号背景颜色</nz-form-label>
<nz-form-control [nzSpan]="6">
<div
[ngStyle]="{'background':item.backgroudColor,'width':'100px','height':'30px','border':'1px solid #CCC','opacity':'0.7'}">
</div>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="3">区块背景颜色</nz-form-label>
<nz-form-control [nzSpan]="6">
<div
[ngStyle]="{'background':item.backgroudColor,'width':'100px','height':'30px','border':'1px solid #CCC','opacity':'0.1'}">
</div>
</nz-form-control>
</nz-form-item>
<nz-divider nzText="字母" nzOrientation="left"></nz-divider>
<nz-form-item>
<nz-form-label [nzSpan]="6" nzFor="exercises">操作</nz-form-label>
<nz-form-control [nzSpan]="6">
<button nz-button nzType="dashed" [disabled]="item.letterArr.length == 3 ? true : false" class="add-btn"
id="add-btn" (click)="addLetterItem(item)">
<i nz-icon nzType="plus-circle" nzTheme="outline"></i>添加
</button>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-control [nzOffset]="2" [nzSpan]="24">
<nz-table #lettersTable nzBordered [nzData]="item.letterArr" [nzShowPagination]=false>
<thead>
<tr>
<th>序号</th>
<th>字母组合</th>
<th>音频</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of lettersTable.data;let j = index">
<td>{{ j+1 }}</td>
<td><input type="text" nz-input placeholder="max length is 4" [(ngModel)]="row.val" (blur)="save()"
maxlength="4"></td>
<td>
<app-audio-recorder [audioUrl]="row.audioUrl"
(audioUploaded)="onAudioUploadSuccess($event, row, 'audioUrl')">
</app-audio-recorder>
</td>
<td>
<a (click)="delLetter(item, j)">delete</a>
</td>
</tr>
</tbody>
</nz-table>
</nz-form-control>
</nz-form-item>
</div>
</div>
<div nz-row>
<div *ngFor="let zone of item.zoneArr; let i = index" style="padding: 0.5vw;">
<div nz-col [nzSpan]="20" nzOffset="2">
<nz-card nzTitle="练习题区域-{{i + 1}}" [nzActions]="[actionAdd]">
<div>
<div *ngFor="let data of zone.exercisesArr;let j = index">
<div nz-col [nzSpan]="12">
<nz-card nzTitle="单词-{{j+1}}" [nzExtra]="extraTemplate" [nzHoverable]="true">
<nz-form-item>
<nz-form-label [nzSpan]="6" nzFor="answerIndex">答案顺序</nz-form-label>
<nz-form-control [nzSpan]="6">
<nz-input-number [nzMin]="1" [nzMax]='8' [(ngModel)]="data.answerIndex" (ngModelChange)="saveIndex(data)"></nz-input-number>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="6" nzFor="{{j}}.indexAudioUrl">顺序音频</nz-form-label>
<nz-form-control [nzSpan]="6">
<app-audio-recorder id="{{j}}.indexAudioUrl" [audioUrl]="data.indexAudioUrl"
(audioUploaded)="onAudioUploadSuccess($event, data, 'indexAudioUrl')">
</app-audio-recorder>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="6">音频</nz-form-label>
<nz-form-control [nzSpan]="12">
<app-audio-recorder [audioUrl]="data.answer.audioUrl"
(audioUploaded)="onAudioUploadSuccess($event, data.answer, 'audioUrl')">
</app-audio-recorder>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="6">单词拆分</nz-form-label>
<nz-form-control [nzSpan]="12">
<button nz-button nzType="dashed" class="add-btn" id="add-btn"
(click)="addLetterItem(data.answer)">
<i nz-icon nzType="plus-circle" nzTheme="outline"></i>添加
</button>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="6">单词预览</nz-form-label>
<nz-form-control [nzSpan]="12">
<span nz-text>
<label *ngFor="let letter of data.answer.letterArr;let j = index"
[ngStyle]="{'color':letter.isFill=='1'?'#c8161d':'#000000','font-size':'40px'}">{{letter.val}}</label>
</span>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-control [nzOffset]="2" [nzSpan]="20">
<nz-table #lettersTable nzBordered nzTitle="按照单词填空需要进行拆分填写" [nzData]="data.answer.letterArr"
[nzShowPagination]=false>
<thead>
<tr>
<th>序号</th>
<th>字母组合</th>
<th>是否着色</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of lettersTable.data;let j = index">
<td>{{ j+1 }}</td>
<td><input type="text" nz-input placeholder="请录入字母(组合)" [(ngModel)]="row.val"
(blur)="save()">
</td>
<td>
<nz-radio-group [(ngModel)]="row.isFill" (ngModelChange)="save()">
<label nz-radio nzValue="1"></label>
<label nz-radio nzValue="0"></label>
</nz-radio-group>
</td>
<td>
<a (click)="delLetter(data.answer,j)">delete</a>
</td>
</tr>
</tbody>
</nz-table>
</nz-form-control>
</nz-form-item>
</nz-card>
<ng-template #extraTemplate>
<button style="margin: 10px;" nz-button nzType="danger" (click)="delExercisesItem(zone, j)">
<span>删除</span>
</button>
</ng-template>
</div>
</div>
</div>
<ng-template #actionAdd>
<button nz-button nzType="dashed" [disabled]="zone.exercisesArr.length == 3 ? true : false"
class="add-btn" id="add-btn" (click)="addExercisesItem(zone)">
<i nz-icon nzType="plus-circle" nzTheme="outline"></i>添加
</button>
</ng-template>
</nz-card>
</div>
</div>
</div>
</div>
\ No newline at end of file
import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ChangeDetectorRef} from '@angular/core';
import { Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ChangeDetectorRef } from '@angular/core';
import { AnswerBean, getDefaultExercises, getDefaultLetter } from '../bean/Exercises';
import { getDefaultTile } from '../bean/TitleBean';
import { NzMessageService } from 'ng-zorro-antd/message'
@Component({
......@@ -10,12 +12,12 @@ import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, Ap
export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 储存数据用
saveKey = "test_0011";
saveKey = "YM5-3";
// 储存对象
item;
constructor(private appRef: ApplicationRef,private changeDetectorRef: ChangeDetectorRef) {
constructor(private appRef: ApplicationRef, private changeDetectorRef: ChangeDetectorRef, private message: NzMessageService) {
}
......@@ -24,8 +26,16 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.item = {};
this.item.title = getDefaultTile();
this.item.letterArr = [];
/**练习题区域 */
this.item.zoneArr = [];
// 获取存储的数据
(<any> window).courseware.getData((data) => {
(<any>window).courseware.getData((data) => {
if (data) {
this.item = data;
......@@ -51,36 +61,153 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
init() {
if (!this.item.backgroudColor) {
this.item.backgroudColor = "#ab82b8";
}
if (!this.item.title) {
this.item.title = getDefaultTile();
}
if (!this.item.letterArr) {
this.item.letterArr = [];
}
if (!this.item.zoneArr) {
this.item.zoneArr = [];
}
for (let i = this.item.zoneArr.length; i < 3; ++i) {
let zone = {
exercisesArr: []
};
this.item.zoneArr.push(zone);
}
for (let i = 0; i < this.item.zoneArr.length; ++i) {
let zone = this.item.zoneArr[i];
if (!zone) {
zone = {
exercisesArr: []
};
this.item.zoneArr[i] = zone;
}
for (let j = 0; j < zone.exercisesArr.length; ++j) {
if (!zone.exercisesArr[j]) {
zone.exercisesArr[j] = getDefaultExercises();
}
if (!zone.exercisesArr[j].answer) {
zone.exercisesArr[j].answer = new AnswerBean();
}
}
}
}
/**
* 储存图片数据
* @param e
*/
onImageUploadSuccess(e, key) {
* 储存图片数据
* @param e
*/
onImageUploadSuccess(e, item, key) {
this.item[key] = e.url;
this.save();
item[key] = e.url;
this.save();
}
/**
* 储存音频数据
* @param e
*/
onAudioUploadSuccess(e, key) {
onAudioUploadSuccess(e, item, key) {
item[key] = e.url;
this.save();
}
addLetterItem(item) {
let letter = getDefaultLetter();
item.letterArr.push(letter);
item.letterArr = [...item.letterArr];
this.item[key] = e.url;
this.save();
}
delLetter(item, index) {
if (index !== -1) {
item.letterArr.splice(index, 1);
item.letterArr = [...item.letterArr];
this.save();
}
}
addExercisesItem(item) {
let exercises = getDefaultExercises();
item.exercisesArr.push(exercises);
this.save();
}
delExercisesItem(item, index) {
if (index !== -1) {
item.exercisesArr.splice(index, 1);
item.exercisesArr = [...item.exercisesArr];
this.save();
}
}
saveIndex(item) {
console.log(item);
let canSave = true;
for (let i = 0; i < this.item.zoneArr.length; ++i) {
let zone = this.item.zoneArr[i];
for (let j = 0; j < zone.exercisesArr.length; ++j) {
let exercises = zone.exercisesArr[j];
if (item == exercises) {
continue;
}
else if (exercises.answerIndex == item.answerIndex) {
canSave = false;
break;
}
}
}
console.log(canSave);
if (canSave) {
this.save();
}
else {
let id = this.message.error('已经存在相同的顺序号', { nzDuration: 0 }).messageId;
setTimeout(() => {
this.message.remove(id);
}, 2500);
}
}
/**
* 储存数据
*/
save() {
(<any> window).courseware.setData(this.item, null, this.saveKey);
(<any>window).courseware.setData(this.item, null, this.saveKey);
this.refresh();
}
......
/**
*
* @param audio 音频
* @param now true-重新开始播放,flase-继续播放
* @param callback
*/
export function playAudio(audio, now = false, callback = null) {
if (audio) {
if (now) {
audio.pause();
audio.currentTime = 0;
}
if (callback) {
audio.onended = () => {
callback();
};
}
audio.play();
}
}
/**
* 暂停播放音频
* @param audio 音频
* @param reset 暂停是否重置:true-是,false-否
* @param callback
*/
export function pauseAudio(audio, reset = false, callback = null) {
if (audio) {
if (reset) {
audio.currentTime = 0;
}
audio.pause();
if (callback) {
callback();
}
}
}
\ No newline at end of file
import { Label, Label2, LabelText, MySprite, ShapeCircle, ShapeRect } from "./Unit";
export class Exercises {
data;
images;
indexBgColor;
index: number;
bg: ShapeRect;
answer1: ShapeRect;
answer2: ShapeRect;
scaleX = 1;
scaleY = 1;
answered: Boolean = false;
rightPic: MySprite;
init(images, indexBgColor, data, scaleX = 1, scaleY = 1) {
this.images = images;
this.data = data;
this.scaleX = scaleX;
this.scaleY = scaleY;
this.indexBgColor = indexBgColor;
this.initBg();
this.initIndex();
this.initAnswer();
}
initBg() {
let height = 48 * this.scaleY;
let width = 580 * this.scaleX;
const bg = new ShapeRect();
bg.setSize(width, height);
bg.alpha = 0;
this.bg = bg;
}
initIndex(){
let indexBg = new ShapeCircle();
indexBg.setRadius(23 * this.scaleX);
indexBg.fillColor = this.indexBgColor;
indexBg.x = indexBg.width / 2;
indexBg.y = this.bg.height / 2;
indexBg.alpha = 0.7;
this.bg.addChild(indexBg);
let index = new Label();
index.text = this.index + "";
index.textAlign = 'center';
index.fontSize = 36;
index.fontName = "TCB";
index.fontColor = "#ffffff";
index.setScaleXY(this.scaleX);
index.refreshSize();
index.x = 0;
index.y = 0;
indexBg.addChild(index);
}
initAnswer(){
let startX = 46 * this.scaleX + 7 * this.scaleX;
let answer1 = this.getAnswerView(this.data.answer1);
answer1.x = startX;
this.answer1 = answer1;
let answer2 = this.getAnswerView(this.data.answer2);
answer2.x = startX + 253 * this.scaleX;
this.answer2 = answer2;
const rightPic = new MySprite();
rightPic.init(this.images.get('circle'));
rightPic.setScaleXY(this.scaleX);
rightPic.alpha = 0;
rightPic.y = this.bg.height / 2;
this.rightPic = rightPic;
if(this.data.answerIndex == '1'){
rightPic.x = answer1.x + answer1.width / 2;
}
else if(this.data.answerIndex == '2'){
rightPic.x = answer2.x + answer2.width / 2;
}
this.bg.addChild(rightPic);
}
getAnswerView(answerData){
const getLabelText = (letter) => {
const text = new LabelText();
text.val = letter.val;
if (letter.isFill == '1') {
text.fontColor = "#c8161d";
}
else {
text.fontColor = "#000000";
}
text.underLine = false;
return text;
}
let labelTextArr = [];
for (let i = 0; i < answerData.letterArr.length; ++i) {
var letter = answerData.letterArr[i];
let label = getLabelText(letter);
labelTextArr.push(label);
}
const answer = new Label2();
answer.textArr = labelTextArr;
answer.fontSize = 48;
answer.fontName = "MMB";
answer.setScaleXY(this.scaleX);
answer.refreshSize();
const answerBg = new ShapeRect();
answerBg.alpha = 0;
answerBg.setSize(answer.getBoundingBox().width, answer.getBoundingBox().height);
answerBg.y = (this.bg.height - answerBg.height) / 2;
answer.y = answerBg.height / 2;
answer.x = 0;
answerBg.addChild(answer);
this.bg.addChild(answerBg);
return answerBg;
}
checkAnswer(answerIndex) {
if(this.data.answerIndex == answerIndex){
this.rightPic.alpha = 1;
this.answered = true;
return true;
}
return false;
}
}
\ No newline at end of file
import { Label, ShapeCircle } from "./Unit";
export class Letter{
data;
images;
bgColor;
scaleX = 1;
scaleY = 1;
bg : ShapeCircle;
init(images, data, bgColor, scaleX = 1, scaleY = 1) {
this.images = images;
this.data = data;
this.bgColor = bgColor;
this.scaleX = scaleX;
this.scaleY = scaleY;
this.initBg();
this.initView();
}
initBg(){
let radius = 52 * this.scaleX;
let bg = new ShapeCircle();
bg.setRadius(radius);
bg.fillColor = this.bgColor;
this.bg = bg;
}
initView(){
const letter = new Label();
letter.text = this.data.val;
letter.textAlign = 'center';
letter.fontSize = 64;
letter.fontName = "BRLNSDB";
letter.fontColor = "#ffffff";
letter.setScaleXY(this.scaleX);
letter.refreshSize();
letter.x = 0;
letter.y = 0;
this.bg.addChild(letter);
}
}
\ No newline at end of file
import {
Label,
MySprite, ShapeRectNew,
ShapeCircle,
tweenChange,
ShapeRect
} from './Unit';
import {
playAudio,
pauseAudio
} from './AudioUtil';
export class Listening {
audio;
images;
bg;
btnPlay;
btnStop;
playing = false;
constructor(audio, images) {
this.audio = audio;
this.images = images;
}
init(scaleX = 1, scaleY = 1) {
const bg = new ShapeRect();
const btnPlay = new MySprite();
btnPlay.init(this.images.get('play'));
btnPlay.scaleX = scaleX;
btnPlay.scaleY = scaleY;
btnPlay.x = btnPlay.getBoundingBox().width / 2
btnPlay.y = btnPlay.getBoundingBox().height / 2
this.btnPlay = btnPlay;
bg.addChild(btnPlay);
const btnStop = new MySprite();
btnStop.init(this.images.get('stop'));
btnStop.x = btnPlay.x;
btnStop.y = btnPlay.y;
btnStop.alpha = 0;
btnStop.scaleX = scaleX;
btnStop.scaleY = scaleY;
this.btnStop = btnStop;
bg.addChild(btnStop);
bg.setSize(btnPlay.getBoundingBox().width, btnPlay.getBoundingBox().height);
bg.alpha = 0;
this.bg = bg;
}
play(callback = null){
console.log('playing:', this.playing);
if(!this.playing){
this.playAudio(callback);
return this.audio;
}
else{
this.pauseAudio(callback);
}
return null;
}
reset(){
this.btnPlay.alpha = 1;
this.btnStop.alpha = 0;
this.playing = false;
}
playAudio(callback = null){
this.btnPlay.alpha = 0;
this.btnStop.alpha = 1;
playAudio(this.audio, false, callback);
this.playing = true;
return this.audio;
}
pauseAudio(callback = null){
this.btnPlay.alpha = 1;
this.btnStop.alpha = 0;
this.playing = false;
pauseAudio(this.audio, false, callback)
}
}
\ No newline at end of file
import {
Label,
MySprite, ShapeRect,
} from './Unit';
import {
playAudio,
pauseAudio
} from './AudioUtil';
export class Title {
titleBg: ShapeRect;
audio;
images;
titleData;
constructor(titleData, images) {
this.titleData = titleData;
this.images = images;
}
init(mapScaleX = 1, mapScaleY = 1) {
let titleBg = new ShapeRect();
//初始化标题1背景
const titePart1Bg = new ShapeRect();
titePart1Bg.fillColor="#567790";
let pWidth = 117 * mapScaleX;
let pHeight = 65 * mapScaleY;
titePart1Bg.setSize(pWidth, pHeight);
titePart1Bg.setShadow(4,4,0, 'rgba(0, 0, 0, 0.2)');
titePart1Bg.x = 0;
titleBg.addChild(titePart1Bg);
//标题1内容
const part1 = new Label();
part1.text = this.titleData.part1;
part1.textAlign = 'left';
part1.fontSize = 48;
part1.fontName = "BRLNSDB";
part1.fontColor = "#ffffff";
part1.setScaleXY(mapScaleX);
part1.refreshSize();
part1.x = pWidth - part1.getBoundingBox().width - 13 * mapScaleX;
part1.y = 5 * mapScaleY + part1.getBoundingBox().height / 2;
titleBg.addChild(part1);
//标题2内容
const part2 = new Label();
part2.text = this.titleData.part2;
part2.fontSize = 36;
part2.fontName = "FuturaStd";
part2.fontColor = "#000000";
part2.setScaleXY(mapScaleX);
part2.refreshSize();
part2.x = titePart1Bg.getBoundingBox().width + 11 * mapScaleX;
part2.y = 16 * mapScaleY + part2.getBoundingBox().height / 2;
let height = Math.max(titePart1Bg.getBoundingBox().height, part2.getBoundingBox().height);
let width = titePart1Bg.getBoundingBox().width + part2.getBoundingBox().width + 11 * mapScaleX;
titePart1Bg.y = (height - pHeight)/2;
titleBg.setSize(width, height);
titleBg.alpha = 0;
titleBg.addChild(part2);
this.titleBg = titleBg;
}
getTitleBg(){
return this.titleBg;
}
setAudio(audio){
this.audio = audio;
}
playAudio(callback = null){
playAudio(this.audio, true, callback);
return this.audio;
}
pasueAudio(callback){
pauseAudio(this.audio, true, callback)
}
}
......@@ -709,6 +709,231 @@ export class Label extends MySprite {
}
export class LabelText {
private _val: string;
private _fontColor = "#000000";
private _underLine: boolean = false;
private _visiable = true;
set val(val) {
this._val = val;
}
get val() {
return this._val;
}
set fontColor(fontColor) {
this._fontColor = fontColor;
}
get fontColor() {
return this._fontColor;
}
set underLine(underLine) {
this._underLine = underLine;
}
get underLine() {
return this._underLine;
}
set visiable(visiable){
this._visiable = visiable;
}
get visiable(){
return this._visiable;
}
}
export class Label2 extends MySprite {
textArr: Array<LabelText> = [];
fontName = 'Verdana';
textAlign = 'left';
fontSize = 40;
fontColor = '#000000';
fontWeight = 900;
_maxWidth;
outline = 0;
outlineColor = '#ffffff';
_outlineFlag = false;
_outLineWidth;
_outLineColor;
underLineWidth: number;
underLineColor = "#000000";
constructor(ctx = null) {
super(ctx);
this.init();
}
refreshSize() {
this.ctx.save();
this.ctx.font = `${this.fontSize}px ${this.fontName}`;
this.ctx.textAlign = this.textAlign;
this.ctx.textBaseline = 'middle';
this.ctx.fontWeight = this.fontWeight;
let text = "";
let count = 0;
for (let i = 0; i < this.textArr.length; ++i) {
if(this.textArr[i].underLine){
count ++;
continue;
}
text += this.textArr[i].val;
}
if(count > 0){
this._width = this.ctx.measureText(text).width + 36 * count + 4 * (count - 1);
}
else{
this._width = this.ctx.measureText(text).width;
}
this._height = this.fontSize;
this.refreshAnchorOff();
this.ctx.restore();
}
setMaxSize(w) {
this._maxWidth = w;
this.refreshSize();
if (this.width >= w) {
this.scaleX *= w / this.width;
this.scaleY *= w / this.width;
}
}
show(callBack = null) {
this.visible = true;
if (this.alpha >= 1) {
return;
}
const tween = new TWEEN.Tween(this)
.to({ alpha: 1 }, 800)
// .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
.onComplete(() => {
if (callBack) {
callBack();
}
})
.start(); // Start the tween immediately.
}
setOutline(width = 5, color = '#ffffff') {
this._outlineFlag = true;
this._outLineWidth = width;
this._outLineColor = color;
}
drawText() {
if (!this.textArr) { return; }
this.ctx.font = `${this.fontSize}px ${this.fontName}`;
this.ctx.textAlign = this.textAlign;
this.ctx.textBaseline = 'middle';
this.ctx.fontWeight = this.fontWeight;
var startX = 0;
for (let i = 0; i < this.textArr.length; ++i) {
var text = this.textArr[i];
let width = this.ctx.measureText(text.val).width;
let tempStartX = startX;
let dW = 0;
if (text.underLine && this.underLineWidth > 0) {
this.ctx.save();
this.ctx.lineWidth = this.underLineWidth;
this.ctx.strokeStyle = this.underLineColor;
let lineY = this.fontSize / 2;
this.ctx.moveTo(tempStartX, lineY);
this.ctx.lineTo(tempStartX + 36, lineY);
this.ctx.stroke();
this.ctx.restore();
tempStartX += (36 - width) / 2;
dW = 36 ;
if(this.textArr[i + 1] && this.textArr[i + 1].underLine){
dW += 4 ;
}
}
else{
dW = width;
}
if (this._outlineFlag) {
this.ctx.lineWidth = this._outLineWidth;
this.ctx.strokeStyle = this._outLineColor;
this.ctx.strokeText(text.val, tempStartX, 0);
}
if (this.outline > 0) {
this.ctx.lineWidth = this.outline;
this.ctx.strokeStyle = this.outlineColor;
this.ctx.strokeText(text.val, tempStartX, 0);
}
this.ctx.fillStyle = text.fontColor ? text.fontColor : this.fontColor;
if(text.visiable){
this.ctx.fillText(text.val, tempStartX, 0);
}
startX += dW;
}
}
drawSelf() {
super.drawSelf();
this.drawText();
}
}
export class RichTextOld extends Label {
textArr = [];
......
......@@ -17,3 +17,20 @@
src: url("../../assets/font/BRLNSDB.TTF") ;
}
@font-face
{
font-family: 'FuturaStd';
src: url("../../assets/font/FuturaStd-Medium.otf") ;
}
@font-face
{
font-family: 'TCB';
src: url("../../assets/font/TCB.TTF") ;
}
@font-face
{
font-family: 'MMB';
src: url("../../assets/font/MMTextBook-Bold.otf") ;
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ import {Component, ElementRef, ViewChild, OnInit, Input, OnDestroy, HostListener
import {
Label,
MySprite, tweenChange,
MySprite, ShapeRectNew, tweenChange,
} from './Unit';
import {res, resAudio} from './resources';
......@@ -11,6 +11,11 @@ import {Subject} from 'rxjs';
import {debounceTime} from 'rxjs/operators';
import TWEEN from '@tweenjs/tween.js';
import { Title } from './Title';
import { getDefaultTile } from '../bean/TitleBean';
import { Listening } from './Listening';
import { Letter } from './Letter';
import { Exercises } from './Exercises.spreat';
......@@ -57,17 +62,21 @@ export class PlayComponent implements OnInit, OnDestroy {
canvasLeft;
canvasTop;
saveKey = 'test_0011';
saveKey = 'YM5-3';
btnLeft;
btnRight;
pic1;
pic2;
canTouch = true;
curPic;
/**标题*/
title: Title;
listening : Listening;
curAudio;
letterArr : Array<Letter>;
exercisesArr: Array<Exercises> = [];
@HostListener('window:resize', ['$event'])
onResize(event) {
......@@ -297,6 +306,8 @@ export class PlayComponent implements OnInit, OnDestroy {
}
audio.play();
}
return audio;
}
......@@ -341,7 +352,7 @@ export class PlayComponent implements OnInit, OnDestroy {
return new Promise((resolve, reject) => {
const audio = new Audio();
audio.oncanplay = (a) => {
resolve();
resolve(a);
};
audio.onerror = () => {
reject();
......@@ -443,9 +454,21 @@ export class PlayComponent implements OnInit, OnDestroy {
*/
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';
if (!this.data.title) {
this.data.title = getDefaultTile();
}
if(!this.data.backgroudColor){
this.data.backgroudColor = "#B5C75F";
}
if(!this.data.letterArr){
this.data.letterArr = [];
}
if(!this.data.exercisesArr){
this.data.exercisesArr = [];
}
}
......@@ -455,8 +478,7 @@ export class PlayComponent implements OnInit, OnDestroy {
*/
initImg() {
this.addUrlToImages(this.data.pic_url);
this.addUrlToImages(this.data.pic_url_2);
}
......@@ -465,13 +487,46 @@ export class PlayComponent implements OnInit, OnDestroy {
*/
initAudio() {
// 音频资源
this.addUrlToAudioObj(this.data.audio_url);
this.addUrlToAudioObj(this.data.audio_url_2);
// 音效
this.addUrlToAudioObj('click', this.rawAudios.get('click'), 0.3);
this.addUrlToAudioObj('right', this.rawAudios.get('right'));
//标题发音
if (this.data.title.audioUrl) {
this.addUrlToAudioObj('titleAudio', this.data.title.audioUrl);
}
//听力材料
if (this.data.audioUrl) {
this.addUrlToAudioObj('listenAudio', this.data.audioUrl);
}
for(let i = 0; i < this.data.letterArr.length; ++ i){
let letter = this.data.letterArr[i];
if(letter.audioUrl){
this.addUrlToAudioObj(letter.audioUrl);
}
}
//练习题音效
for (let i = 0; i < this.data.exercisesArr.length; ++i) {
let exercises = this.data.exercisesArr[i];
if (exercises.answer1 && exercises.answer1.audioUrl) {
this.addUrlToAudioObj('exercises_' + i, exercises.answer1.audioUrl);
}
if (exercises.answer2 && exercises.answer2.audioUrl) {
this.addUrlToAudioObj('exercises_2_' + i, exercises.answer2.audioUrl);
}
}
}
......@@ -486,14 +541,18 @@ export class PlayComponent implements OnInit, OnDestroy {
const s = Math.min(sx, sy);
this.mapScale = s;
// this.mapScale = sx;
// this.mapScale = sy;
this.renderArr = [];
if (this.curAudio) {
this.curAudio.pause();
}
this.curAudio = null;
this.letterArr = [];
this.exercisesArr = [];
}
......@@ -504,158 +563,196 @@ export class PlayComponent implements OnInit, OnDestroy {
initView() {
this.initPic();
this.initTitle();
this.initBottomPart();
this.initLetter();
this.initExercises();
}
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;
const listening = new Listening(this.audioObj['listenAudio'], this.images);
listening.init(this.mapScale, this.mapScale);
btnLeft.setScaleXY(this.mapScale);
listening.bg.x = this.canvasWidth - listening.bg.width - 10 * this.mapScale;
listening.bg.y = this.canvasHeight - listening.bg.height - 8 * this.mapScale;
this.listening = listening;
this.renderArr.push(btnLeft);
this.btnLeft = btnLeft;
this.renderArr.push(listening.bg);
}
initTitle() {
const title = new Title(this.data.title, this.images);
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);
title.init(this.mapScale, this.mapScale);
title.audio = this.audioObj['titleAudio'];
this.title = title;
this.renderArr.push(btnRight);
title.titleBg.y = 0;
title.titleBg.x = 0;
this.btnRight = btnRight;
this.renderArr.push(title.titleBg);
}
initPic() {
const maxW = this.canvasWidth * 0.7;
initLetter(){
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);
let letterArr = this.data.letterArr;
this.renderArr.push(pic1);
this.pic1 = pic1;
let dW = (47 + 104) * this.mapScale;
let tW = (letterArr.length - 1) * dW;
const label1 = new Label();
label1.text = this.data.text;
label1.textAlign = 'center';
label1.fontSize = 50;
label1.fontName = 'BRLNSDB';
label1.fontColor = '#ffffff';
let startX = (this.canvasWidth - tW) / 2;
pic1.addChild(label1);
let y = this.canvasHeight / 2 - 218 * this.mapScale;
for(let i = 0; i < letterArr.length; ++ i){
let letter = new Letter();
letter.init(this.images, letterArr[i], this.data.backgroudColor, this.mapScale, this.mapScale);
letter.bg.x = startX + dW * i;
letter.bg.y = y;
this.renderArr.push(letter.bg);
this.letterArr.push(letter);
}
}
initExercises(){
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);
let w = 1200 * this.mapScale;
this.renderArr.push(pic2);
this.pic2 = pic2;
let h = 364 * this.mapScale;
this.curPic = pic1;
}
let r = 69 * this.mapScale;
const bg = new ShapeRectNew();
bg.setSize(w, h, r);
bg.fillColor = this.data.backgroudColor;
bg.x = (this.canvasWidth - w) / 2;
bg.y = this.canvasHeight / 2 - 119 * this.mapScale;
bg.alpha = 0.1;
btnLeftClicked() {
this.renderArr.push(bg);
this.lastPage();
}
var dW = 582 * this.mapScale;
var dH = 105 * this.mapScale;
let rows = Math.ceil(this.data.exercisesArr.length / 2);
let cols = 2;
btnRightClicked() {
let startX = (this.canvasWidth - (cols - 1) * dW) / 2;;
this.nextPage();
let startY = bg.y + 51 * this.mapScale;
let tempY = startY;
for(let i = 0; i < this.data.exercisesArr.length; ++i){
let item = this.data.exercisesArr[i];
console.log(i);
let exercises = new Exercises();
exercises.index = i + 1;
exercises.init(this.images, this.data.backgroudColor, item, this.mapScale, this.mapScale);
this.renderArr.push(exercises.bg);
this.exercisesArr.push(exercises);
exercises.bg.x = startX - exercises.bg.width / 2;
exercises.bg.y = startY;
//换行
if ((i + 1) % rows != 0) {
startY += dH;
}
else {
startX += dW;
startY = tempY;
}
}
}
lastPage() {
if (this.curPic == this.pic1) {
mapDown(event) {
if (!this.canTouch) {
return;
}
this.canTouch = false;
if (this.curAudio) {
if (this.curAudio != this.listening.audio) {
this.curAudio.pause();
}
}
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;
});
}
if (this.checkClickTarget(this.listening.bg)) {
nextPage() {
this.curAudio = this.listening.play(() => {
this.listening.reset();
});
if (this.curPic == this.pic2) {
return;
}
this.canTouch = false;
if (this.curAudio) {
if (this.curAudio == this.listening.audio) {
this.listening.pauseAudio();
}
else {
this.curAudio.pause();
}
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);
}
if (this.checkClickTarget(this.title.titleBg)) {
this.curAudio = this.title.playAudio();
return;
}
pic2Clicked() {
this.playAudio(this.data.audio_url_2);
}
for(let i = 0; i < this.letterArr.length; ++ i){
let letter = this.letterArr[i];
if(this.checkClickTarget(letter.bg)){
this.curAudio = this.playAudio(letter.data.audioUrl, true);
break;
}
}
let clicked = false;
for (let i = 0; i < this.exercisesArr.length; ++i) {
let exercises = this.exercisesArr[i];
if (this.checkClickTarget(exercises.answer1)) {
clicked = true;
mapDown(event) {
this.clickExercises(exercises, i, '1');
if (!this.canTouch) {
return;
}
break;
}
if ( this.checkClickTarget(this.btnLeft) ) {
this.btnLeftClicked();
return;
}
if (this.checkClickTarget(exercises.answer2)) {
if ( this.checkClickTarget(this.btnRight) ) {
this.btnRightClicked();
return;
}
clicked = true;
if ( this.checkClickTarget(this.pic1) ) {
this.pic1Clicked();
return;
this.clickExercises(exercises, i, '2');
break;
}
}
if ( this.checkClickTarget(this.pic2) ) {
this.pic2Clicked();
if (clicked) {
return;
}
}
mapMove(event) {
......@@ -685,6 +782,41 @@ export class PlayComponent implements OnInit, OnDestroy {
}
clickExercises(exercises: Exercises, index: number, answerIndex: String) {
const play = () => {
let key;
if (answerIndex == '1') {
key = 'exercises_' + index;
}
else if (answerIndex == '2') {
key = 'exercises_2_' + index;
}
const audio = this.audioObj[key];
this.curAudio = audio;
this.playAudio(key, true);
}
if (exercises.answered) {
play();
}
else {
if (exercises.checkAnswer(answerIndex)) {
this.playAudio('right', true, () => {
play();
});
}
else {
play();
}
}
}
}
const res = [
// ['bg', "assets/play/bg.jpg"],
['btn_left', "assets/play/btn_left.png"],
['btn_right', "assets/play/btn_right.png"],
// ['text_bg', "assets/play/text_bg.png"],
['play', "assets/play/play.png"],
['stop', "assets/play/stop.png"],
['circle', "assets/play/circle.png"],
];
......@@ -12,7 +10,7 @@ const res = [
const resAudio = [
['click', "assets/play/music/click.mp3"],
['right', "assets/play/music/right.mp3"],
];
export {res, resAudio};
This source diff could not be displayed because it is too large. You can view the blob instead.
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