mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
视图和示例菜单改造完成。
This commit is contained in:
parent
867497b6f5
commit
a665140f8c
@ -75,6 +75,8 @@ import PlayEvent from './menu/play/PlayEvent';
|
||||
|
||||
import VRModeEvent from './menu/view/VRModeEvent';
|
||||
|
||||
import ExampleEvent from './menu/example/ExampleEvent';
|
||||
|
||||
/**
|
||||
* 事件执行器
|
||||
*/
|
||||
@ -158,6 +160,8 @@ function EventDispatcher(app) {
|
||||
new PlayEvent(this.app),
|
||||
|
||||
new VRModeEvent(this.app),
|
||||
|
||||
new ExampleEvent(this.app),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
51
src/event/menu/example/ExampleEvent.js
Normal file
51
src/event/menu/example/ExampleEvent.js
Normal file
@ -0,0 +1,51 @@
|
||||
import MenuEvent from '../MenuEvent';
|
||||
|
||||
/**
|
||||
* 示例事件
|
||||
* @param {*} app
|
||||
*/
|
||||
function ExampleEvent(app) {
|
||||
MenuEvent.call(this, app);
|
||||
this.isPlaying = false;
|
||||
}
|
||||
|
||||
ExampleEvent.prototype = Object.create(MenuEvent.prototype);
|
||||
ExampleEvent.prototype.constructor = ExampleEvent;
|
||||
|
||||
ExampleEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('mArkanoid.' + this.id, function () {
|
||||
_this.onExample('arkanoid.app.json');
|
||||
});
|
||||
this.app.on('mCamera.' + this.id, function () {
|
||||
_this.onExample('camera.app.json');
|
||||
});
|
||||
this.app.on('mParticles.' + this.id, function () {
|
||||
_this.onExample('particles.app.json');
|
||||
});
|
||||
this.app.on('mPong.' + this.id, function () {
|
||||
_this.onExample('pong.app.json');
|
||||
});
|
||||
};
|
||||
|
||||
ExampleEvent.prototype.stop = function () {
|
||||
this.app.on('mArkanoid.' + this.id, null);
|
||||
this.app.on('mCamera.' + this.id, null);
|
||||
this.app.on('mParticles.' + this.id, null);
|
||||
this.app.on('mPong.' + this.id, null);
|
||||
};
|
||||
|
||||
ExampleEvent.prototype.onExample = function (name) {
|
||||
var editor = this.app.editor;
|
||||
|
||||
if (confirm('任何未保存数据将丢失。确定吗?')) {
|
||||
var loader = new THREE.FileLoader();
|
||||
|
||||
loader.load('examples/' + name, function (text) {
|
||||
editor.clear();
|
||||
editor.fromJSON(JSON.parse(text));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default ExampleEvent;
|
||||
@ -1,65 +0,0 @@
|
||||
import UI from '../ui/UI';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function ExampleMenu(editor) {
|
||||
|
||||
var container = new UI.Panel();
|
||||
container.setClass('menu');
|
||||
|
||||
var title = new UI.Panel();
|
||||
title.setClass('title');
|
||||
title.setTextContent('示例');
|
||||
container.add(title);
|
||||
|
||||
var options = new UI.Panel();
|
||||
options.setClass('options');
|
||||
container.add(options);
|
||||
|
||||
// Examples
|
||||
|
||||
var items = [
|
||||
{ title: '打砖块', file: 'arkanoid.app.json' },
|
||||
{ title: '相机', file: 'camera.app.json' },
|
||||
{ title: '粒子', file: 'particles.app.json' },
|
||||
{ title: '乒乓球', file: 'pong.app.json' }
|
||||
];
|
||||
|
||||
var loader = new THREE.FileLoader();
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
|
||||
(function (i) {
|
||||
|
||||
var item = items[i];
|
||||
|
||||
var option = new UI.Row();
|
||||
option.setClass('option');
|
||||
option.setTextContent(item.title);
|
||||
option.onClick(function () {
|
||||
|
||||
if (confirm('任何未保存数据将丢失。确定吗?')) {
|
||||
|
||||
loader.load('examples/' + item.file, function (text) {
|
||||
|
||||
editor.clear();
|
||||
editor.fromJSON(JSON.parse(text));
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
options.add(option);
|
||||
|
||||
})(i)
|
||||
|
||||
}
|
||||
|
||||
return container;
|
||||
|
||||
};
|
||||
|
||||
export default ExampleMenu;
|
||||
@ -1,46 +0,0 @@
|
||||
import UI from '../ui/UI';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function ViewMenu(editor) {
|
||||
|
||||
this.app = editor.app;
|
||||
|
||||
var container = new UI.Panel();
|
||||
container.setClass('menu');
|
||||
|
||||
var title = new UI.Panel();
|
||||
title.setClass('title');
|
||||
title.setTextContent('视图');
|
||||
container.add(title);
|
||||
|
||||
var options = new UI.Panel();
|
||||
options.setClass('options');
|
||||
container.add(options);
|
||||
|
||||
// VR mode
|
||||
var _this = this;
|
||||
|
||||
var option = new UI.Row();
|
||||
option.setClass('option');
|
||||
option.setTextContent('VR模式');
|
||||
option.onClick(function () {
|
||||
|
||||
if (_this.app.renderer.vr.enabled) {
|
||||
_this.app.call('enterVR', _this);
|
||||
} else {
|
||||
|
||||
alert('WebVR不可用');
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
options.add(option);
|
||||
|
||||
return container;
|
||||
|
||||
};
|
||||
|
||||
export default ViewMenu;
|
||||
@ -1,5 +1 @@
|
||||
export { default as ExampleMenu } from './ExampleMenu';
|
||||
export { default as HelpMenu } from './HelpMenu';
|
||||
export { default as StatusMenu } from './StatusMenu';
|
||||
export { default as ViewMenu } from './ViewMenu';
|
||||
export { default as Menubar } from './Menubar';
|
||||
Loading…
x
Reference in New Issue
Block a user