Sidebar.Script.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Sidebar.Script = function ( editor ) {
  5. var signals = editor.signals;
  6. var container = new UI.CollapsiblePanel();
  7. container.setCollapsed( editor.config.getKey( 'ui/sidebar/script/collapsed' ) );
  8. container.onCollapsedChange( function ( boolean ) {
  9. editor.config.setKey( 'ui/sidebar/script/collapsed', boolean );
  10. } );
  11. container.setDisplay( 'none' );
  12. container.addStatic( new UI.Text( 'Script' ).setTextTransform( 'uppercase' ) );
  13. container.add( new UI.Break() );
  14. //
  15. var scriptsContainer = new UI.Panel();
  16. container.add( scriptsContainer );
  17. var eventType = new UI.Select();
  18. eventType.setOptions( {
  19. 'init': 'init',
  20. 'keydown': 'keydown',
  21. 'keyup': 'keyup',
  22. 'mousedown': 'mousedown',
  23. 'mouseup': 'mouseup',
  24. 'mousemove': 'mousemove',
  25. 'update': 'update'
  26. } );
  27. container.add( eventType );
  28. var button = new UI.Button( 'Add' );
  29. button.setMarginLeft( '5px' );
  30. button.onClick( function () {
  31. var script = new UI.ScriptEditor();
  32. script.setValue( { event: eventType.getValue(), source: '' } );
  33. script.onChange( function () {
  34. signals.scriptChanged.dispatch();
  35. } );
  36. scriptsContainer.add( script );
  37. } );
  38. container.add( button );
  39. // signals
  40. signals.objectSelected.add( function ( object ) {
  41. scriptsContainer.clear();
  42. if ( object !== null ) {
  43. container.setDisplay( 'block' );
  44. var sources = editor.scripts[ object.uuid ];
  45. if ( sources !== undefined ) {
  46. for ( var i = 0; i < sources.length; i ++ ) {
  47. var script = new UI.ScriptEditor();
  48. script.setValue( sources[ i ] );
  49. script.onChange( function () {
  50. signals.scriptChanged.dispatch();
  51. } );
  52. scriptsContainer.add( script );
  53. }
  54. }
  55. } else {
  56. container.setDisplay( 'none' );
  57. }
  58. } );
  59. signals.scriptChanged.add( function () {
  60. var array = [];
  61. var object = editor.selected;
  62. for ( var i = 0; i < scriptsContainer.children.length; i ++ ) {
  63. var script = scriptsContainer.children[ i ];
  64. array.push( script.getValue() );
  65. }
  66. editor.scripts[ object.uuid ] = array;
  67. } );
  68. return container;
  69. };
粤ICP备19079148号