Menubar.Examples.js 1.4 KB

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