Commit 8acdd228 authored by Lwd's avatar Lwd

aaaa

parent e9e05281
<div class="p-image-children-editor">
<h5 style="margin-left: 2.5%;"> preview: </h5>
<h5 style="margin-left: 2.5%;"> preview: </h5>
<div class="preview-box" #wrap>
<canvas id="canvas" #canvas></canvas>
</div>
<div class="preview-box" #wrap>
<canvas id="canvas" #canvas></canvas>
</div>
<div nz-row nzType="flex" nzAlign="middle">
<div nz-col nzSpan="5" nzOffset="1">
<div nz-row nzType="flex" nzAlign="middle">
<div nz-col nzSpan="5" nzOffset="1">
<h5> add background: </h5>
<h5> add background: </h5>
<div class="bg-box">
<app-upload-image-with-preview
[picUrl]="bgItem?.url"
(imageUploaded)="onBackgroundUploadSuccess($event)">
</app-upload-image-with-preview>
</div>
</div>
<div class="bg-box">
<app-upload-image-with-preview [picUrl]="bgItem?.url"
(imageUploaded)="onBackgroundUploadSuccess($event)">
</app-upload-image-with-preview>
</div>
</div>
<div nz-col nzSpan="5" nzOffset="1" class="img-box"
*ngFor="let it of hotZoneArr; let i = index">
<div nz-col nzSpan="5" nzOffset="1" class="img-box" *ngFor="let it of hotZoneArr; let i = index">
<div
style="margin: auto; padding: 5px; margin-top: 30px; width:90%; border: 2px dashed #ddd; border-radius: 10px">
<span style="margin-left: 40%;"> item-{{i + 1}}
</span>
<button style="float: right;" nz-button nzType="danger" nzSize="small" (click)="deleteBtnClick(i)">
X
</button>
<div
style="margin: auto; padding: 5px; margin-top: 30px; width:90%; border: 2px dashed #ddd; border-radius: 10px">
<span style="margin-left: 40%;"> item-{{i + 1}}
</span>
<button style="float: right;" nz-button nzType="danger" nzSize="small" (click)="deleteBtnClick(i)">
X
</button>
<nz-divider style="margin-top: 10px;"></nz-divider>
<nz-divider style="margin-top: 10px;"></nz-divider>
<div style="margin-top: -20px; margin-bottom: 5px">
<nz-radio-group [ngModel]="it.itemType" (ngModelChange)="radioChange($event, it)">
<label *ngIf="isHasRect" nz-radio nzValue="rect">矩形</label>
<label *ngIf="isHasPic" nz-radio nzValue="pic">图片</label>
<label *ngIf="isHasText" nz-radio nzValue="text">文本</label>
</nz-radio-group>
</div>
<div style="margin-top: -20px; margin-bottom: 5px">
<nz-radio-group [ngModel]="it.itemType" (ngModelChange)="radioChange($event, it)">
<label *ngIf="isHasRect" nz-radio nzValue="rect">矩形</label>
<label *ngIf="isHasPic" nz-radio nzValue="pic">图片</label>
<label *ngIf="isHasText" nz-radio nzValue="text">文本</label>
</nz-radio-group>
</div>
<div *ngIf="it.itemType == 'pic'">
<app-upload-image-with-preview
[picUrl]="it?.pic_url"
(imageUploaded)="onItemImgUploadSuccess($event, it)">
</app-upload-image-with-preview>
</div>
<div *ngIf="it.itemType == 'pic'">
<app-upload-image-with-preview [picUrl]="it?.pic_url"
(imageUploaded)="onItemImgUploadSuccess($event, it)">
</app-upload-image-with-preview>
</div>
<div *ngIf="it.itemType == 'text'">
<input type="text" nz-input [(ngModel)]="it.text" (blur)="saveText(it)">
</div>
<div *ngIf="it.itemType == 'text'">
<input type="text" nz-input [(ngModel)]="it.text" (blur)="saveText(it)">
</div>
<div style="width: 100%; margin-top: 5px;">
<app-audio-recorder
[audioUrl]="it.audio_url"
(audioUploaded)="onItemAudioUploadSuccess($event, it)"
></app-audio-recorder>
</div>
<div style="width: 100%; margin-top: 5px;">
<app-audio-recorder [audioUrl]="it.audio_url"
(audioUploaded)="onItemAudioUploadSuccess($event, it)"></app-audio-recorder>
</div>
</div>
</div>
</div>
</div>
<div nz-col nzSpan="5" nzOffset="1">
<div nz-col nzSpan="5" nzOffset="1">
<div class="bg-box">
<button nz-button nzType="dashed" (click)="addBtnClick()"
class="add-btn">
<i nz-icon nzType="plus-circle" nzTheme="outline"></i>
<!--Add Image-->
Add hot zone
</button>
</div>
<div class="bg-box">
<button nz-button nzType="dashed" (click)="addBtnClick()" class="add-btn">
<i nz-icon nzType="plus-circle" nzTheme="outline"></i>
<!--Add Image-->
Add hot zone
</button>
</div>
</div>
</div>
</div>
</div>
<nz-divider></nz-divider>
<nz-divider></nz-divider>
<div class="save-box">
<div class="save-box">
<button class="save-btn" nz-button nzType="primary" [nzSize]="'large'" nzShape="round"
(click)="saveClick()" >
<i nz-icon nzType="save"></i>
Save
</button>
<button class="save-btn" nz-button nzType="primary" [nzSize]="'large'" nzShape="round" (click)="saveClick()">
<i nz-icon nzType="save"></i>
Save
</button>
</div>
</div>
</div>
<label style="opacity: 0; position: absolute; top: 0px; font-family: 'BRLNSR_1'">1</label>
<label style="opacity: 0; position: absolute; top: 0px; font-family: 'BRLNSR_1'">1</label>
\ No newline at end of file
import {ApplicationRef, Component, EventEmitter, Input, OnChanges, OnDestroy, Output} from '@angular/core';
import { ApplicationRef, Component, EventEmitter, Input, OnChanges, OnDestroy, Output } from '@angular/core';
import { NzMessageService, UploadXHRArgs, UploadFile } from 'ng-zorro-antd';
@Component({
selector: 'app-upload-dragon-bone',
templateUrl: './upload-dragon-bone.component.html',
styleUrls: ['./upload-dragon-bone.component.scss']
selector: 'app-upload-dragon-bone',
templateUrl: './upload-dragon-bone.component.html',
styleUrls: ['./upload-dragon-bone.component.scss']
})
export class UploadDragonBoneComponent implements OnDestroy, OnChanges {
uploading = false;
progress = 0;
@Input()
btnName = '配置龙骨动画';
@Input()
animaNames = [];
@Input()
skeJsonData = {};
@Input()
texJsonData = {};
@Input()
texPngData = {};
@Output()
save = new EventEmitter();
@Output()
refreshEmitter = new EventEmitter();
// @Input()
// picUrl;
// @Input()
// canDelete = false;
// @Output()
// imageUploaded = new EventEmitter();
// @Output()
// imageUploadFailure = new EventEmitter();
// @Output()
// delete = new EventEmitter();
// @Input()
// picItem = null;
// @Input()
// iconSize = 2;
// @Input()
// TIP = 'Click here to upload image';
// @Input()
// disableUpload = false;
uploadUrl;
uploadData;
animaPanelVisible = false;
isSkeJsonLoading = false;
isTexJsonLoading = false;
isTexPngLoading = false;
constructor(private appRef: ApplicationRef, private nzMessageService: NzMessageService) {
this.uploadUrl = (<any> window).courseware.uploadUrl();
this.uploadData = (<any> window).courseware.uploadData();
window['air'].getUploadCallback = (url, data) => {
this.uploadUrl = url;
this.uploadData = data;
};
}
ngOnChanges() {
}
setAnimaBtnClick() {
this.animaPanelVisible = true;
this.refresh();
}
animaPanelCancel() {
this.animaPanelVisible = false;
this.refresh();
}
animaPanelOk() {
this.sendItemDragonBoneData();
this.animaPanelVisible = false;
this.refresh();
}
sendItemDragonBoneData() {
const data = {};
data['skeJsonData'] = this.skeJsonData;
data['texJsonData'] = this.texJsonData;
data['texPngData'] = this.texPngData;
this.save.emit(data);
}
skeJsonHandleChange(e) {
console.log('e: ', e);
switch (e.type) {
case 'start':
this.isSkeJsonLoading = true;
break;
case 'success':
this.skeJsonData['url'] = e.file.response.url;
this.skeJsonData['name'] = e.file.name;
this.nzMessageService.success('上传成功');
this.isSkeJsonLoading = false;
break;
case 'progress':
break;
}
}
texJsonHandleChange(e) {
console.log('e: ', e);
switch (e.type) {
case 'start':
this.isTexJsonLoading = true;
break;
case 'success':
this.texJsonData['url'] = e.file.response.url;
this.texJsonData['name'] = e.file.name;
this.nzMessageService.success('上传成功');
this.isTexJsonLoading = false;
break;
case 'progress':
break;
}
}
texPngHandleChange(e) {
console.log('e: ', e);
switch (e.type) {
case 'start':
this.isTexPngLoading = true;
break;
case 'success':
this.texPngData['url'] = e.file.response.url;
this.texPngData['name'] = e.file.name;
this.nzMessageService.success('上传成功');
this.isTexPngLoading = false;
break;
case 'progress':
break;
}
}
/**
* 刷新 渲染页面
*/
refresh() {
// this.refreshEmitter.emit();
setTimeout(() => {
this.appRef.tick();
}, 1);
}
closePanel() {
console.log(' in closePanel ');
this.refresh();
}
ngOnDestroy() {
}
uploading = false;
progress = 0;
@Input()
btnName = '配置龙骨动画';
@Input()
animaNames = [];
@Input()
skeJsonData = {};
@Input()
texJsonData = {};
@Input()
texPngData = {};
@Output()
save = new EventEmitter();
@Output()
refreshEmitter = new EventEmitter();
// @Input()
// picUrl;
// @Input()
// canDelete = false;
// @Output()
// imageUploaded = new EventEmitter();
// @Output()
// imageUploadFailure = new EventEmitter();
// @Output()
// delete = new EventEmitter();
// @Input()
// picItem = null;
// @Input()
// iconSize = 2;
// @Input()
// TIP = 'Click here to upload image';
// @Input()
// disableUpload = false;
uploadUrl;
uploadData;
animaPanelVisible = false;
isSkeJsonLoading = false;
isTexJsonLoading = false;
isTexPngLoading = false;
constructor(private appRef: ApplicationRef, private nzMessageService: NzMessageService) {
this.uploadUrl = (<any>window).courseware.uploadUrl();
this.uploadData = (<any>window).courseware.uploadData();
window['air'].getUploadCallback = (url, data) => {
this.uploadUrl = url;
this.uploadData = data;
};
}
ngOnChanges() {
}
setAnimaBtnClick() {
this.animaPanelVisible = true;
this.refresh();
}
animaPanelCancel() {
this.animaPanelVisible = false;
this.refresh();
}
animaPanelOk() {
this.sendItemDragonBoneData();
this.animaPanelVisible = false;
this.refresh();
}
sendItemDragonBoneData() {
const data = {};
data['skeJsonData'] = this.skeJsonData;
data['texJsonData'] = this.texJsonData;
data['texPngData'] = this.texPngData;
this.save.emit(data);
}
skeJsonHandleChange(e) {
console.log('e: ', e);
switch (e.type) {
case 'start':
this.isSkeJsonLoading = true;
break;
case 'success':
this.skeJsonData['url'] = e.file.response.url;
this.skeJsonData['name'] = e.file.name;
this.nzMessageService.success('上传成功');
this.isSkeJsonLoading = false;
break;
case 'progress':
break;
}
}
texJsonHandleChange(e) {
console.log('e: ', e);
switch (e.type) {
case 'start':
this.isTexJsonLoading = true;
break;
case 'success':
this.texJsonData['url'] = e.file.response.url;
this.texJsonData['name'] = e.file.name;
this.nzMessageService.success('上传成功');
this.isTexJsonLoading = false;
break;
case 'progress':
break;
}
}
texPngHandleChange(e) {
console.log('e: ', e);
switch (e.type) {
case 'start':
this.isTexPngLoading = true;
break;
case 'success':
this.texPngData['url'] = e.file.response.url;
this.texPngData['name'] = e.file.name;
this.nzMessageService.success('上传成功');
this.isTexPngLoading = false;
break;
case 'progress':
break;
}
}
/**
* 刷新 渲染页面
*/
refresh() {
// this.refreshEmitter.emit();
setTimeout(() => {
this.appRef.tick();
}, 1);
}
closePanel() {
console.log(' in closePanel ');
this.refresh();
}
ngOnDestroy() {
}
}
......@@ -4,6 +4,13 @@
<input type="text" nz-input [(ngModel)]="item.contentObj.title" (blur)="saveItem()">
</div>
<div class="section-content;text-align:center">
<div style="display: inline-block; margin-bottom: 10px">
<app-audio-recorder [audioUrl]="item.contentObj.audio_url"
(audioUploaded)="onAudioUploadSuccessByItem($event, item.contentObj)">
</app-audio-recorder>
</div>
</div>
<div *ngFor="let it of pageArr; let i = index" style="padding: 0.5vw; width: 20%;">
<div class="border" style="display: flex; align-items: center;">
......@@ -64,12 +71,60 @@
<!--公共部分-->
<div class="item-box" style="width: 35% ;padding-left: 100px">
<div style="width: 100%;">
<app-upload-image-with-preview style="width: 100%" [picUrl]="it['groupPic']"
<div style="float: left; text-align: right; margin-right: 10px; margin-left: 10px;">
<span>显示选项</span><span> :</span>
</div>
<div style="float: left;width: 100%;">
<nz-radio-group [(ngModel)]="it['type']" (ngModelChange)="handleQuestionTypeChange($event)">
<label nz-radio [nzValue]="'Image'">背景图片</label>
<label nz-radio [nzValue]="'Spine'">骨骼动画</label>
</nz-radio-group>
</div>
<div style="float: left;width: 100%;">
<div *ngIf="it['type']=='Image'">
<app-upload-image-with-preview style="width: 100%;" [picUrl]="it['groupPic']"
(imageUploaded)="onImageUploadSuccessByItem($event, it, 'image_url')">
</app-upload-image-with-preview>
</div>
<div *ngIf="it['type']=='Spine' ">
<div style="display: flex 1;margin-bottom: 10px;margin-left: 10px;">
<span>上传 ske_json 文件</span><span> : </span>
<nz-upload nzAccept=".json" [nzAction]="uploadUrl" [nzData]="uploadData"
[nzShowUploadList]="false" (nzChange)="handleChange($event, it,'ske_json')">
<button nz-button><i nz-icon nzType="upload"></i>Upload</button>
</nz-upload>
<span style="margin-left: 10px;">{{it["ske_json_name"]}}</span>
</div>
<div style="display: flex 1;margin-bottom: 10px;margin-left: 10px;">
<span>上传 tex_json 文件</span><span> : </span>
<nz-upload nzAccept=".json" [nzAction]="uploadUrl" [nzData]="uploadData"
[nzShowUploadList]="false" (nzChange)="handleChange($event, it,'tex_json')">
<button nz-button><i nz-icon nzType="upload"></i>Upload</button>
</nz-upload>
<span style="margin-left: 10px;">{{ it["tex_json_name"] }}</span>
</div>
<div style="display: flex 1;margin-bottom: 10px;margin-left: 10px;">
<span>上传 tex_png 文件</span><span> : </span>
<nz-upload nzAccept=".png" [nzAction]="uploadUrl" [nzData]="uploadData"
[nzShowUploadList]="false" (nzChange)="handleChange($event, it,'tex_png')">
<button nz-button><i nz-icon nzType="upload"></i>Upload</button>
</nz-upload>
<span style="margin-left: 10px;">{{ it["tex_png_name"] }}</span>
</div>
</div>
</div>
<!-- <app-upload-image-with-preview style="width: 100%" [picUrl]="it['groupPic']"
(imageUploaded)="onImageUploadSuccessByItem($event, it)">
</app-upload-image-with-preview>
</app-upload-image-with-preview> -->
</div>
<input style=" width: 100%; margin-bottom: 0.5vw" type="text" nz-input placeholder="点击输入文本内容"
[(ngModel)]="it.groupLabel" (blur)="saveItem()">
<app-audio-recorder style="margin-top: 0.5vw" [audioUrl]="it['group_audio_url']"
(audioUploaded)="onAudioUploadSuccessByItem($event, it, 'group')">
</app-audio-recorder>
</div>
<div class="item-box" style="width:35%; padding-left: 100px">
......
......@@ -9,6 +9,7 @@ import {
ApplicationRef,
ChangeDetectorRef
} from '@angular/core';
import { NzMessageService, UploadXHRArgs, UploadFile } from 'ng-zorro-antd';
......@@ -19,6 +20,9 @@ import {
})
export class FormComponent implements OnInit, OnChanges, OnDestroy {
pageArr = [];//页数据
fileList
uploadUrl
uploadData
_item: any;
KEY = 'hw_004';
......@@ -43,10 +47,13 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
update = new EventEmitter();
constructor(private appRef: ApplicationRef,
public changeDetectorRef: ChangeDetectorRef) {
constructor(private appRef: ApplicationRef, private changeDetectorRef: ChangeDetectorRef) {
this.uploadUrl = (<any>window).courseware.uploadUrl();
this.uploadData = (<any>window).courseware.uploadData();
window['air'].getUploadCallback = (url, data) => {
this.uploadUrl = url;
this.uploadData = data;
};
}
......@@ -55,6 +62,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.item = {};
this.item.contentObj = {};
const getData = (<any>window).courseware.getData;
getData((data) => {
......@@ -99,6 +107,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
console.log('item:', this.item);
}
getDefaultPicArr() {
const arr = [];
// for (let i = 0; i < 4; i ++) {
......@@ -170,6 +179,38 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.save();
}
uploadSuccess(file, item, key) {
console.log(item);
item[key] = file.response.url;
item[key + '_name'] = file.name;
this.save();
}
handleChange(info: { type: string, file: UploadFile, event: any }, item, key) {
console.log('info:', info);
switch (info.type) {
case 'success':
this.uploadSuccess(info.file, item, key);
break;
}
}
handleQuestionTypeChange(key) {
if (key == 'Spine') {
this.fileList = [
{
uid: '-1',
name: this.item['ske_json'],
status: 'done',
url: this.item['ske_json']
}
]
} else if (key == 'Image') {
}
this.saveItem()
this.changeDetectorRef.detectChanges();
this.changeDetectorRef.markForCheck();
}
//添加页面
addPage() {
const data = {
......@@ -189,6 +230,13 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
b_audio_url: '',
groupLabel: '',
groupPic: '',
group_audio_url: '',
type: '',
ske_json: '',
tex_json: '',
tex_png: '',
// uploadData: '',
// uploadUrl: '',
};
this.pageArr[i].pageInfo.push(data);
console.log(this.pageArr);
......@@ -222,6 +270,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
const getData = (<any>window).courseware.getData;
getData((data) => {
console.log('data:', data);
// console.log('string:', JSON.stringify(data));
}, this.KEY);
}
......
This diff is collapsed.
{
"ver": "1.1.0",
"uuid": "61fcc759-2eb5-4e50-a2f3-0cc3393881d8",
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
......@@ -114,6 +114,13 @@ var game = cc.Class({
}
this.resultNode.active = false;
//重置游戏数据游戏数据
g.data_mgr.resGameData();
g.data_mgr.addPreloadImage();
g.data_mgr.addPreloadAudio();
g.data_mgr.addPreloadAnima();
//初始化界面
this.UpdataUi();
......@@ -123,6 +130,8 @@ var game = cc.Class({
//游戏开始
g.game.inst.gameStart();
//清除线
this.clearLine();
},
......@@ -162,6 +171,15 @@ var game = cc.Class({
});
},
//播放标题音效
playAudioTitle: function () {
//获得播放路径
var path = g.data_mgr.data.contentObj.audio_url;
g.res_mgr.playAudioByUrl(path, (url) => {
g.snd_mgr.playEffect(url);
});
},
//添加项
addItem: function (listInfo, content, item, i) {
if (listInfo.length <= i) {
......@@ -190,7 +208,12 @@ var game = cc.Class({
for (var i = 0; i < conten.childrenCount; i++) {
var item = conten.children[i]
if (item.state == 1 || item.state == 3) {
// if (state == 2) {
var com = item.getComponent("item");
//设置状态为可答题
com.setBtnState(item.state);
continue;
// }
} else {
var com = item.getComponent("item");
//设置状态为可答题
......@@ -199,7 +222,7 @@ var game = cc.Class({
}
},
ShowLine: function (sx, sy, ex, ey) {
ShowLine: function (sx, sy, ex, ey, cb) {
var b = 0;
var a = 0;
var k = ex == sx ? 0 : (ey - sy) / (ex - sx);
......@@ -220,7 +243,7 @@ var game = cc.Class({
if (difnode) {
this.scheduleOnce(function () {
this.DrawLine(sx, sy, difx, dify);
this.ShowLine(difx, dify, ex, ey);
this.ShowLine(difx, dify, ex, ey, cb);
}.bind(this), 0.01);
}
else {
......@@ -232,6 +255,7 @@ var game = cc.Class({
//显示弹窗
var Info = g.data_mgr.getResultInfo(g.data_mgr.nowNode.typeId);
g.game.inst.showResult(Info);
cb && cb();
}
},
......
......@@ -2,144 +2,147 @@
* item
*/
cc.Class({
extends: cc.Component,
extends: cc.Component,
properties: {
Picture: {
default: null,
type: cc.Node,
displayName: "图片"
},
nodeState: {
default: [],
type: cc.Node,
displayName: "节点状态"
},
spt_error: {
default: null,
type: cc.Node,
displayName: "失败"
},
spt_chick: {
default: null,
type: cc.Node,
displayName: "小鸡"
}
},
properties: {
Picture: {
default: null,
type: cc.Node,
displayName: "图片"
},
nodeState: {
default: [],
type: cc.Node,
displayName: "节点状态"
},
spt_error: {
default: null,
type: cc.Node,
displayName: "失败"
},
spt_chick: {
default: null,
type: cc.Node,
displayName: "小鸡"
}
},
//更新界面ui
updateUI: function (Info) {
//当前数据
this.itemInfo = Info;
//初始化数据
this.InitData();
//设置图片
this.setPicture(Info.url);
},
//更新界面ui
updateUI: function (Info) {
//当前数据
this.itemInfo = Info;
//初始化数据
this.InitData();
//设置图片
this.setPicture(Info.url);
},
//初始化信息
InitData: function () {
//设置按钮状态
this.setBtnState(0);
if (this.itemInfo.positionId == 2) {
this.setBtnState(2);
}
},
//初始化信息
InitData: function () {
//设置按钮状态
this.setBtnState(0);
if (this.itemInfo.positionId == 2) {
this.setBtnState(2);
}
},
//设置图片
setPicture: function (url) {
//图片资源
g.res_mgr.getSpriteFrimeByUrl(url, function (list) {
this.Picture.getComponent(cc.Sprite).spriteFrame = list;
this.Picture.active = true;
}.bind(this));
},
//设置图片
setPicture: function (url) {
//图片资源
g.res_mgr.getSpriteFrimeByUrl(url, function (list) {
this.Picture.getComponent(cc.Sprite).spriteFrame = list;
this.Picture.active = true;
}.bind(this));
},
//设置按钮状态
setBtnOpen: function (b) {
this.node.getComponent(cc.Button).enabled = b;
},
//设置按钮状态
setBtnOpen: function (b) {
this.node.getComponent(cc.Button).enabled = b;
},
//设置按钮状态0可点击 1已答对 2答错 3连线完成
setBtnState: function (num) {
this.nodeState[num].active = true;
switch (~~num) {
case 0:
this.nodeState[0].active = true;
this.nodeState[1].active = false;
this.nodeState[2].active = false;
this.node.state = 0;
this.setBtnOpen(true);
break;
case 1:
this.nodeState[1].active = true;
this.nodeState[2].active = false;
this.node.state = 1;
this.setBtnOpen(false);
break;
case 2:
this.nodeState[1].active = false;
this.nodeState[2].active = true;
this.node.state = 2;
this.setBtnOpen(false);
break;
case 3:
this.nodeState[0].active = true;
this.nodeState[1].active = false;
this.nodeState[2].active = false;
this.node.state = 3;
this.setBtnOpen(false);
break;
}
},
//
onBtnGet: function () {
//如果节点的Id等于当前数据的id的话
if (this.itemInfo.typeId == g.data_mgr.playId && this.itemInfo.positionId == g.data_mgr.playType) {
//播放答对音效
g.speaker.inst.play_good();
this.setBtnState(1);
//如果是上面答对的话
if (this.itemInfo.positionId == 1) {
//执行播放下排的音乐
g.data_mgr.playType = 2;
g.game.inst.PlayAudio();
//设置按钮状态0可点击 1已答对 2答错 3连线完成
setBtnState: function (num) {
//this.nodeState[num].active = true;
switch (~~num) {
case 0:
this.nodeState[0].active = true;
this.nodeState[1].active = false;
this.nodeState[2].active = false;
this.node.state = 0;
this.setBtnOpen(true);
break;
case 1:
this.nodeState[1].active = true;
this.nodeState[2].active = false;
this.node.state = 1;
this.setBtnOpen(false);
break;
case 2:
this.nodeState[1].active = false;
this.nodeState[2].active = true;
this.node.state = 2;
this.setBtnOpen(false);
break;
case 3:
this.nodeState[0].active = true;
this.nodeState[1].active = false;
this.nodeState[2].active = false;
this.node.state = 3;
this.setBtnOpen(false);
break;
}
},
//
onBtnGet: function () {
//如果节点的Id等于当前数据的id的话
if (this.itemInfo.typeId == g.data_mgr.playId && this.itemInfo.positionId == g.data_mgr.playType) {
//播放答对音效
g.speaker.inst.play_good();
this.setBtnState(1);
//如果是上面答对的话
if (this.itemInfo.positionId == 1) {
//执行播放下排的音乐
g.data_mgr.playType = 2;
g.game.inst.PlayAudio();
//设置状态
g.game.inst.allLightDark(1, 2);
g.game.inst.allLightDark(2, 0);
//设置状态
g.game.inst.allLightDark(1, 2);
g.game.inst.allLightDark(2, 0);
//把这个答对的节点保存起来
g.data_mgr.itemInfo = this.spt_chick;
}
//如果答对的是下排的话
if (this.itemInfo.positionId == 2) {
//连线
var posStart = g.data_mgr.itemInfo.parent.convertToWorldSpaceAR(g.data_mgr.itemInfo.position);
var posEnd = this.spt_chick.parent.convertToWorldSpaceAR(this.spt_chick.position);
g.data_mgr.nowNode = this.itemInfo;
g.game.inst.ShowLine(posStart.x - 640, posStart.y - 360, posEnd.x - 640, posEnd.y - 360);
// //显示弹窗
// var Info = g.data_mgr.getResultInfo(this.itemInfo.typeId);
// g.game.inst.showResult(Info);
//把这个答对的节点保存起来
g.data_mgr.itemInfo = this;
}
//如果答对的是下排的话
if (this.itemInfo.positionId == 2) {
//连线
var posStart = g.data_mgr.itemInfo.spt_chick.parent.convertToWorldSpaceAR(g.data_mgr.itemInfo.spt_chick.position);
var posEnd = this.spt_chick.parent.convertToWorldSpaceAR(this.spt_chick.position);
g.data_mgr.nowNode = this.itemInfo;
g.game.inst.ShowLine(posStart.x - 640, posStart.y - 360, posEnd.x - 640, posEnd.y - 360, () => {
g.data_mgr.itemInfo.setBtnState(3);
this.setBtnState(3);
});
// //显示弹窗
// var Info = g.data_mgr.getResultInfo(this.itemInfo.typeId);
// g.game.inst.showResult(Info);
//弹窗关闭
// //移除当前播放的音乐
// const index = this.pageArr.indexOf(data);
// if (index !== -1) {
// this.pageArr.splice(index, 1);
// }
}
}
else {
this.spt_error.active = true;
//播放失败音效
g.speaker.inst.play_error();
this.setBtnState(2);
cc.tween(this.spt_error)
.to(0.2, { scale: 1.1 })
.to(0.5, { scale: 0 })
.start()
}
},
//弹窗关闭
// //移除当前播放的音乐
// const index = this.pageArr.indexOf(data);
// if (index !== -1) {
// this.pageArr.splice(index, 1);
// }
}
}
else {
this.spt_error.active = true;
//播放失败音效
g.speaker.inst.play_error();
this.setBtnState(2);
cc.tween(this.spt_error)
.to(0.2, { scale: 1.1 })
.to(0.5, { scale: 0 })
.start()
}
},
});
/**
* result
*/
const Color_texts = ['#BE1AC1', '#24C11A', '#1A1DC1', '#9F5307'];
var result = cc.Class({
extends: cc.Component,
......@@ -29,6 +31,16 @@ var result = cc.Class({
default: null,
type: cc.Animation,
displayName: "撒花特效"
},
Armature: {
default: null,
type: dragonBones.ArmatureDisplay,
displayName: "动画"
},
layoutText: {
default: null,
type: cc.Node,
displayName: "文字布局"
}
},
......@@ -39,13 +51,24 @@ var result = cc.Class({
//更新界面ui
updateUI: function (Info) {
this.Picture.active = false;
this.Armature.node.active = false;
if (Info) {
//当前数据
this.itemInfo = Info;
//设置图片
this.setPicture(Info.groupPic);
//设置图片
this.setTips(Info.groupLabel);
//显示图片
if (Info.type == "Image") {
//设置图片
this.setPicture(Info.groupPic);
}
//显示骨骼动画
if (Info.type == "Spine") {
g.res_mgr.loadSpine(this.Armature, Info);
}
this.initRichText(Info.groupLabel);
this.wellDone.active = false;
this.frame_tips.active = true;
this.eff_sahua.node.active = false;
......@@ -61,9 +84,9 @@ var result = cc.Class({
}
},
//设置标签
setTips: function (num) {
this.lb_tips.string = num;
// 初始化文本
initRichText(text) {
this.lb_tips.string = text;
},
//设置图片
......@@ -75,6 +98,51 @@ var result = cc.Class({
}.bind(this));
},
//播放龙骨动画
playSpine() {
this.Armature.playAnimation(g.data_mgr.dragonName, 1);
},
stopSpine() {
this.Armature.dragonAtlasAsset = null;
this.Armature.dragonAsset = null;
this.Armature.armatureName = '';
this.scheduleOnce(() => {
g.res_mgr.loadSpine(this.Armature, this.Info);
})
},
playAudio() {
cc.assetManager.loadRemote(this.itemInfo.group_audio_url, null, (err, clip) => {
this.audioID = cc.audioEngine.play(clip, false, 1);
this.audioDuration = cc.audioEngine.getDuration(this.audioID);
this.textDuration = this.audioDuration / this.layoutText.childrenCount;
this.textIndex = 0;
this.schedule(this.chengeTextColor, this.textDuration, this.layoutText.childrenCount, 0.01)
});
},
stopAudio() {
cc.audioEngine.stop(this.audioID);
this.unschedule(this.chengeTextColor);
this.isPlaying = false;
this.stopSpine();
},
chengeTextColor() {
if (!this.layoutText.children[this.textIndex] || this.textIndex == this.layoutText.childrenCount) {
this.isPlaying = false;
this.unschedule(this.chengeTextColor);
}
this.layoutText.children[this.textIndex] && (this.layoutText.children[this.textIndex].color = new cc.Color().fromHEX(Color_texts[3]));
this.layoutText.children[this.textIndex - 1] && (this.layoutText.children[this.textIndex - 1].color = new cc.Color().fromHEX(Color_texts[3]));
this.textIndex++;
},
clearTextColor() {
for (let i = 0; i < this.layoutText.children.length; i++) {
this.layoutText.children[i].color = new cc.Color().fromHEX(Color_texts[3]);
}
},
//点击关闭
onBtnClose: function () {
this.node.active = false;
......
......@@ -53,13 +53,47 @@ g.res_mgr = {
if (audio_url) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
cb && cb(audioClip);
// const audioId = cc.audioEngine.play(audioClip, false, 0.8);
// if (cb) {
// cc.audioEngine.setFinishCallback(audioId, () => {
// cb();
// });
// }
});
}
},
//加载龙骨
loadSpine(animationDisplay, Info) {
if (Info.type == 'Image') {
return;
}
cc.assetManager.loadAny([{ url: Info.tex_json, ext: '.txt' }, { url: Info.ske_json, ext: '.txt' }], (error, assets) => {
if (error) {
console.log(error)
}
else {
cc.assetManager.loadRemote(Info.tex_png, (error, texture) => {
if (error) {
console.log(error)
}
else {
var atlas = new dragonBones.DragonBonesAtlasAsset();
atlas._uuid = Info.tex_json;
atlas.atlasJson = assets[0];
atlas.texture = texture;
var asset = new dragonBones.DragonBonesAsset();
asset._uuid = Info.ske_json;
asset.dragonBonesJson = assets[1];
animationDisplay.dragonAtlasAsset = atlas;
animationDisplay.dragonAsset = asset;
let data = asset._dragonBonesJsonData.armature[0];
if (!data) {
return;
}
animationDisplay.armatureName = data.name;
g.data_mgr.dragonName = data.animation[0].name;
animationDisplay.node.active = true;
}
});
}
});
},
}
\ No newline at end of file
// 声音管理器
g.snd_mgr = {
bgmId: -1, // 背景音乐的音频ID
effIds: [], // 音效的音频ID列表(由cc.audioEngine保证音频ID不重复)
bgmVol: 1, // 背景音乐音量
neweffId: null, //保存上一个音效ID
effVol: 1, // 音效音量
pausebgVol: 1,
pauseeffVol: 1,
sndNativeUrls: {},
newsnd: null,
init: function () {
var local_storage = g.local_storage;
var music_vol = local_storage.getMusicVolume();
var effect_vol = local_storage.getEffectsVolume();
music_vol != undefined && music_vol + "" != "" && this.setMusicVolume(music_vol);
effect_vol != undefined && effect_vol + "" != "" && this.setEffectsVolume(effect_vol);
},
delAudId: function (id) {
if (id == this.bgmId) {
this.bgmId = -1;
return;
}
for (var i = 0; i < this.effIds.length; ++i) {
if (this.effIds[i] == id) {
this.effIds.splice(i, 1);
return;
}
}
},
playMusic: function (snd, _loop, finishCB) {
if (!snd) return;
this.newsnd = snd;
var loop = _loop ? false : true; // 除非指定为false,否则默认为true
// if (g.configs.platform == "vo") {
// this.bgmId = cc.audioEngine.play(snd, loop);
// return;
// }
this.bgmId = cc.audioEngine.playMusic(snd, loop);
// 播放完成回调
if (finishCB) {
cc.audioEngine.setFinishCallback(this.bgmId, function () {
finishCB();
});
}
bgmId: -1, // 背景音乐的音频ID
effIds: [], // 音效的音频ID列表(由cc.audioEngine保证音频ID不重复)
bgmVol: 1, // 背景音乐音量
neweffId: null, //保存上一个音效ID
effVol: 1, // 音效音量
pausebgVol: 1,
pauseeffVol: 1,
sndNativeUrls: {},
newsnd: null,
init: function () {
var local_storage = g.local_storage;
var music_vol = local_storage.getMusicVolume();
var effect_vol = local_storage.getEffectsVolume();
music_vol != undefined && music_vol + "" != "" && this.setMusicVolume(music_vol);
effect_vol != undefined && effect_vol + "" != "" && this.setEffectsVolume(effect_vol);
},
delAudId: function (id) {
if (id == this.bgmId) {
this.bgmId = -1;
return;
}
for (var i = 0; i < this.effIds.length; ++i) {
if (this.effIds[i] == id) {
this.effIds.splice(i, 1);
return;
}
}
},
playMusic: function (snd, _loop, finishCB) {
if (!snd) return;
this.newsnd = snd;
var loop = _loop ? false : true; // 除非指定为false,否则默认为true
// if (g.configs.platform == "vo") {
// this.bgmId = cc.audioEngine.play(snd, loop);
// return;
// }
this.bgmId = cc.audioEngine.playMusic(snd, loop);
// 播放完成回调
if (finishCB) {
cc.audioEngine.setFinishCallback(this.bgmId, function () {
finishCB();
});
}
},
playEffect: function (snd, finishCB) {
if (!snd || this.effVol == 0) return;
var id = cc.audioEngine.playEffect(snd, false); // 音效限定不能重复播放
this.playaudioEffect(id, finishCB);
},
//播放音效
playaudioEffect: function (id, finishCB) {
var self = this;
this.neweffId = id;
this.effIds.push(id);
// 播放完记得删ID
cc.audioEngine.setFinishCallback(id, function () {
self.delAudId(id);
finishCB && finishCB();
});
},
pauseVolume: function () {
cc.audioEngine.stopAll();
},
resumeVolume: function () {
if (this.newsnd != null) {
cc.audioEngine.playMusic(this.newsnd)
}
},
setMusicVolume: function (percent) {
this.bgmVol = percent;
cc.audioEngine.setMusicVolume(~~percent);
},
setEffectsVolume: function (percent) {
this.effVol = percent;
cc.audioEngine.setEffectsVolume(~~percent);
cc.audioEngine.setMusicVolume(~~this.bgmVol);
},
},
playEffect: function (snd, finishCB) {
if (!snd || this.effVol == 0) return;
var id = cc.audioEngine.playEffect(snd, false); // 音效限定不能重复播放
this.playaudioEffect(id, finishCB);
},
//播放音效
playaudioEffect: function (id, finishCB) {
var self = this;
this.neweffId = id;
this.effIds.push(id);
// 播放完记得删ID
cc.audioEngine.setFinishCallback(id, function () {
self.delAudId(id);
finishCB && finishCB();
});
},
pauseVolume: function () {
cc.audioEngine.stopAll();
},
resumeVolume: function () {
if (this.newsnd != null) {
cc.audioEngine.playMusic(this.newsnd)
}
},
setMusicVolume: function (percent) {
this.bgmVol = percent;
cc.audioEngine.setMusicVolume(~~percent);
},
setEffectsVolume: function (percent) {
this.effVol = percent;
cc.audioEngine.setEffectsVolume(~~percent);
cc.audioEngine.setMusicVolume(~~this.bgmVol);
},
};
\ No newline at end of file
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