Menubar.Examples.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. import * as THREE from '../../build/three.module.js';
  5. import { UIPanel, UIRow } from './libs/ui.js';
  6. var MenubarExamples = function ( editor ) {
  7. var strings = editor.strings;
  8. var container = new UIPanel();
  9. container.setClass( 'menu' );
  10. var title = new UIPanel();
  11. title.setClass( 'title' );
  12. title.setTextContent( strings.getKey( 'menubar/examples' ) );
  13. container.add( title );
  14. var options = new UIPanel();
  15. options.setClass( 'options' );
  16. container.add( options );
  17. // Examples
  18. var items = [
  19. { title: 'menubar/examples/Arkanoid', file: 'arkanoid.app.json' },
  20. { title: 'menubar/examples/Camera', file: 'camera.app.json' },
  21. { title: 'menubar/examples/Particles', file: 'particles.app.json' },
  22. { title: 'menubar/examples/Pong', file: 'pong.app.json' },
  23. { title: 'menubar/examples/Shaders', file: 'shaders.app.json' }
  24. ];
  25. var loader = new THREE.FileLoader();
  26. for ( var i = 0; i < items.length; i ++ ) {
  27. ( function ( i ) {
  28. var item = items[ i ];
  29. var option = new UIRow();
  30. option.setClass( 'option' );
  31. option.setTextContent( strings.getKey( item.title ) );
  32. option.onClick( function () {
  33. if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
  34. loader.load( 'examples/' + item.file, function ( text ) {
  35. editor.clear();
  36. editor.fromJSON( JSON.parse( text ) );
  37. } );
  38. }
  39. } );
  40. options.add( option );
  41. } )( i );
  42. }
  43. return container;
  44. };
  45. export { MenubarExamples };