1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
/**
* @author mrdoob / http://mrdoob.com/
*/
Sidebar.Script = function ( editor ) {
var strings = editor.strings;
var signals = editor.signals;
var container = new UI.Panel();
container.setDisplay( 'none' );
container.add( new UI.Text( strings.getKey( 'sidebar/script' ) ).setTextTransform( 'uppercase' ) );
container.add( new UI.Break() );
container.add( new UI.Break() );
//
var scriptsContainer = new UI.Row();
container.add( scriptsContainer );
var newScript = new UI.Button( strings.getKey( 'sidebar/script/new' ) );
newScript.onClick( function () {
var script = { name: '', source: 'function update( event ) {}' };
editor.execute( new AddScriptCommand( editor, editor.selected, script ) );
} );
container.add( newScript );
/*
var loadScript = new UI.Button( 'Load' );
loadScript.setMarginLeft( '4px' );
container.add( loadScript );
*/
//
function update() {
scriptsContainer.clear();
scriptsContainer.setDisplay( 'none' );
var object = editor.selected;
if ( object === null ) {
return;
}
var scripts = editor.scripts[ object.uuid ];
if ( scripts !== undefined && scripts.length > 0 ) {
scriptsContainer.setDisplay( 'block' );
for ( var i = 0; i < scripts.length; i ++ ) {
( function ( object, script ) {
var name = new UI.Input( script.name ).setWidth( '130px' ).setFontSize( '12px' );
name.onChange( function () {
editor.execute( new SetScriptValueCommand( editor, editor.selected, script, 'name', this.getValue() ) );
} );
scriptsContainer.add( name );
var edit = new UI.Button( strings.getKey( 'sidebar/script/edit' ) );
edit.setMarginLeft( '4px' );
edit.onClick( function () {
signals.editScript.dispatch( object, script );
} );
scriptsContainer.add( edit );
var remove = new UI.Button( strings.getKey( 'sidebar/script/remove' ) );
remove.setMarginLeft( '4px' );
remove.onClick( function () {
if ( confirm( 'Are you sure?' ) ) {
editor.execute( new RemoveScriptCommand( editor, editor.selected, script ) );
}
} );
scriptsContainer.add( remove );
scriptsContainer.add( new UI.Break() );
} )( object, scripts[ i ] )
}
}
}
// signals
signals.objectSelected.add( function ( object ) {
if ( object !== null && editor.camera !== object ) {
container.setDisplay( 'block' );
update();
} else {
container.setDisplay( 'none' );
}
} );
signals.scriptAdded.add( update );
signals.scriptRemoved.add( update );
signals.scriptChanged.add( update );
return container;
};
|