Commit bb13d393 authored by liujiangnan's avatar liujiangnan

feat: 功能实现

parent 6610f190
......@@ -78,10 +78,10 @@
"_active": true,
"_components": [
{
"__id__": 417
"__id__": 418
},
{
"__id__": 418
"__id__": 419
}
],
"_prefab": null,
......@@ -244,14 +244,14 @@
],
"_active": true,
"_components": [
{
"__id__": 414
},
{
"__id__": 415
},
{
"__id__": 416
},
{
"__id__": 417
}
],
"_prefab": null,
......@@ -323,7 +323,7 @@
"_active": true,
"_components": [
{
"__id__": 413
"__id__": 414
}
],
"_prefab": null,
......@@ -17313,6 +17313,9 @@
},
{
"__id__": 412
},
{
"__id__": 413
}
],
"_prefab": null,
......@@ -17437,6 +17440,76 @@
"customAttributeStrArr": [],
"_id": "92na9emSxEq4sJX4n2jZ6/"
},
{
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 409
},
"_enabled": true,
"_normalMaterial": null,
"_grayMaterial": null,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$transition": 0,
"transition": 0,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"_N$hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_N$normalSprite": null,
"_N$pressedSprite": null,
"pressedSprite": null,
"_N$hoverSprite": null,
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 409
},
"_id": "e3wAmPzt9BlYvBCfveIBBT"
},
{
"__type__": "8d79deWXmhBy7QSSjlRnsfL",
"_name": "",
......
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import Attributes from "../script/Attributes";
import {callNetworkApiGet} from "../script/util";
import { callNetworkApiGet, callNetworkApiPost, jumpToCourseWare, buttonOnClick, jumpToBundle } from "../script/util";
// @ts-ignore
import { assign, createMachine, interpret, actions, forwardTo, matchesState } from "../script/xstate";
const { pure, send, raise, sendParent } = actions;
......@@ -13,7 +13,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Node)
loading: cc.Node = null;
@property(cc.Node)
UnitView: cc.Node = null;
@property(cc.PageView)
......@@ -26,9 +26,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
tws: any[] = [];
gameMachineService: any = null;
LoadingCount: number = 1;
_mapScaleMin: number = 1;
_mapScaleMax: number = 1;
_cocosScale: number = 1;
_mapScaleMin: number = 1;
_mapScaleMax: number = 1;
_cocosScale: number = 1;
ROOT_PID: number = null;
MACHINE_INITED: boolean = false;
mute: boolean = true;
......@@ -36,54 +36,60 @@ export default class SceneComponent extends MyCocosSceneComponent {
UnitPageViewBgNode: cc.Node = null;
rootAttrTree: Attributes = null;
kidInfo: any;
onLoad(){
async onLoadEnd() {
this.tws = [];
this.LoadingCount = 0;
this.initSize();
cc.debug.setDisplayStats(false);
}
initialized() {
if(this.gameMachineService) {
this.gameMachineService.start();
const middleLayer = cc.find('middleLayer');
if (middleLayer) {
this.kidInfo = await middleLayer.getComponent('middleLayer').getUserInfo();
}
}
initSize() {
// 注意cc.winSize只有在适配后(修改fitHeight/fitWidth后)才能获取到正确的值,因此使用cc.getFrameSize()来获取初始的屏幕大小
let screen_size = cc.view.getFrameSize().width / cc.view.getFrameSize().height
let design_size = cc.Canvas.instance.designResolution.width / cc.Canvas.instance.designResolution.height
let f = screen_size >= design_size
cc.Canvas.instance.fitHeight = f
cc.Canvas.instance.fitWidth = !f
const frameSize = cc.view.getFrameSize();
this._frameSize = frameSize;
this._designSize = cc.view.getDesignResolutionSize();
let sx = cc.winSize.width / frameSize.width;
let sy = cc.winSize.height / frameSize.height;
this._cocosScale = Math.min(sx, sy);
sx = frameSize.width / this._designSize.width;
sy = frameSize.height / this._designSize.height;
this._mapScaleMin = Math.min(sx, sy) * this._cocosScale;
this._mapScaleMax = Math.max(sx, sy) * this._cocosScale;
}
start() {
this.rootAttrTree = this.getComponent('Attributes');
this.initBg();
this.initUnitViewPager();
this.createFiniteStateMachines();
const BackViewButtons = this.rootAttrTree.querySelectorAll('.back-view');
BackViewButtons.forEach(b => {
b.on(cc.Node.EventType.TOUCH_START, function () {
// TODO 返回上一层
}, this, true);
buttonOnClick(b, ()=> {
jumpToBundle("NJ_MoTianLun");
});
});
this.initialized();
}
initialized() {
if (this.gameMachineService) {
this.gameMachineService.start();
}
}
initSize() {
// 注意cc.winSize只有在适配后(修改fitHeight/fitWidth后)才能获取到正确的值,因此使用cc.getFrameSize()来获取初始的屏幕大小
let screen_size = cc.view.getFrameSize().width / cc.view.getFrameSize().height
let design_size = cc.Canvas.instance.designResolution.width / cc.Canvas.instance.designResolution.height
let f = screen_size >= design_size
cc.Canvas.instance.fitHeight = f
cc.Canvas.instance.fitWidth = !f
const frameSize = cc.view.getFrameSize();
this._frameSize = frameSize;
this._designSize = cc.view.getDesignResolutionSize();
let sx = cc.winSize.width / frameSize.width;
let sy = cc.winSize.height / frameSize.height;
this._cocosScale = Math.min(sx, sy);
sx = frameSize.width / this._designSize.width;
sy = frameSize.height / this._designSize.height;
this._mapScaleMin = Math.min(sx, sy) * this._cocosScale;
this._mapScaleMax = Math.max(sx, sy) * this._cocosScale;
}
initUnitViewPager() {
const pages = this.UnitViewPager.getPages();
let pIndex = pages.length - 1;
......@@ -97,12 +103,28 @@ export default class SceneComponent extends MyCocosSceneComponent {
lessonButtons.forEach((n) => {
n.off(cc.Node.EventType.TOUCH_END);
n.on(cc.Node.EventType.TOUCH_END, function (e) {
const na:Attributes = e.currentTarget.getComponent('Attributes');
const dataIndex = na.attrMap['index'];
console.log('-----------------');
console.log(e.currentTarget);
console.log('-----------------');
// TODO 打开课件
const b = e.currentTarget;
const lock = cc.find('icon_key', b);
const syllabusId = b.data_id;
const forderId = b.data_pid;
if (!syllabusId) {
this.showTips("未解锁 [101]");
return;
}
if (lock.active) {
this.showTips("未解锁");
return;
}
const middleLayer = cc.find('middleLayer');
if (middleLayer) {
middleLayer.getComponent('middleLayer').setData('NJ_MonkyTree_Son', {
forderId,
syllabusId,
});
}
jumpToCourseWare(syllabusId);
}, this, true)
});
}
......@@ -110,8 +132,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
moveUnitViewBackground() {
//获取滚动视图相对于左上角原点的当前滚动偏移
let scrollOffset: cc.Vec2 = this.UnitViewPager.getScrollOffset();
this.UnitsListNode.y = (scrollOffset.y * 8/9 ) + 600;
this.UnitPageViewBgNode.y = (scrollOffset.y * .81 ) + 600;
this.UnitsListNode.y = (scrollOffset.y * 8 / 9) + 600;
this.UnitPageViewBgNode.y = (scrollOffset.y * .81) + 600;
}
initBg() {
this.rootAttrTree.querySelectorAll('.page-holder').forEach(p => {
......@@ -123,12 +145,27 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
}
showTips(tips) {
const middleLayer = cc.find('middleLayer');
if (!middleLayer) {
console.log(tips);
return;
}
middleLayer.getComponent('middleLayer').showTips(tips);
}
playBgMusic(audio) {
cc.audioEngine.stopMusic();
cc.audioEngine.playMusic(audio, true);
}
createFiniteStateMachines() {
let pid = 21228; // 本地测试用
const middleLayer = cc.find('middleLayer');
if(middleLayer) {
pid = middleLayer.getComponent('middleLayer').getData('NJ_MonkyTree');
}
const operationState = {
id: 'operation',
initial: 'UnitView',
......@@ -146,18 +183,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
const lessonsBtn = this.rootAttrTree.querySelectorAll('.lesson-button');
lessonsBtn.forEach(b => {
const attr: Attributes = b.getComponent('Attributes');
const lock = cc.find('icon_key', b);
const lock = cc.find('icon_key', b);
lock.active = true;
const titleNode = attr.querySelector('.title');
titleNode.getComponent(cc.RichText).string = `<outline align=top
width=4></outline>`;
});
callNetworkApiGet('/api/syllabus/v1/tree', {pid: 21228}, (resp: any) => {
callNetworkApiGet('/api/syllabus/v1/tree', { pid }, (resp: any) => {
resp = JSON.parse(resp);
if (resp.msg == 'success') {
let { rows } = resp;
const list = rows.reduce((result, next)=> {
const list = rows.reduce((result, next) => {
const { children } = next;
// has_courseware true 是文件夹
let childrenList = children.filter(r => r.has_courseware)
......@@ -169,28 +207,31 @@ export default class SceneComponent extends MyCocosSceneComponent {
}, []);
// rows = rows.filter(r => !r.has_courseware)
console.log('UnitView', list);
lessonsBtn.forEach(b => {
const attr: Attributes = b.getComponent('Attributes');
const index = attr.attrMap['index'];
const lesson = list[index];
const lock = cc.find('icon_key', b);
lock.active = true;
const lock = cc.find('icon_key', b);
if (index === 0) {
lock.active = false;
} else {
lock.active = true;
}
const titleNode = attr.querySelector('.title');
// titleNode.getComponent(cc.RichText).string = `<outline align=top
// width=4></outline>`;
if (!lesson) {
return;
}
// TODO 解锁逻辑
lock.active = false;
b.attr({'data_id': lesson.id});
const {parent} = b;
const pa = parent.getComponent('Attributes');
const {outline} = pa.attrMap;
titleNode.getComponent(cc.RichText).string = `<outline align=top color=${outline}
width=4>${lesson.name}</outline>`;
b.attr({ 'data_id': lesson.id });
b.attr({ 'data_pid': lesson.pid });
if (this.kidInfo && this.kidInfo.unlock_syllabuses?.includes(lesson.id)) {
lock.active = false;
const { parent } = b;
const pa = parent.getComponent('Attributes');
const { outline } = pa.attrMap;
titleNode.getComponent(cc.RichText).string = `<outline align=top color=${outline}
width=4>${lesson.name}</outline>`;
}
});
ctx.UnitViewData = list;
......@@ -215,7 +256,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.gameMachineService = interpret(operationMachine).onTransition((state) => {
console.log(1, state);
});
}
setStateContextData({ rows, buttonsKey }) {
const buttons = buttonsKey;
......
......@@ -87,7 +87,7 @@ export class MyCocosSceneComponent extends cc.Component {
preload() {
const preloadArr = this._imageResList.concat(this._audioResList).concat(this._animaResList);
cc.assetManager.loadAny(preloadArr, null, null, (err, data) => {
cc.assetManager.loadAny(preloadArr, null, null, async (err, data) => {
if (window && window["air"]) {
// window["air"].onCourseInScreen = (next) => {
......@@ -95,7 +95,7 @@ export class MyCocosSceneComponent extends cc.Component {
// this.onLoadEnd();
// next();
// };
this.onLoadEnd();
await this.onLoadEnd();
window["air"].hideAirClassLoading();
} else {
this.onLoadEnd();
......
export const defaultData = {
"pic_url": "http://staging-teach.cdn.ireadabc.com/ed94332a503c31e0908bd4c6923a2665.png",
"pic_url_2": "http://staging-teach.cdn.ireadabc.com/5fb60317ade0195d35ad8034d5370a7f.png",
"text": "This is a test label.",
"audio_url": "http://staging-teach.cdn.ireadabc.com/f47f1d7b5c160fe1c59500d180346240.mp3"
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "8b6718a7-4616-4fef-aa42-bd17ddde91fc",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ 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