Sidebar.Outliner.Textures.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Sidebar.Outliner.Textures = function ( signals ) {
  2. var container = new UI.Panel();
  3. container.name = "TEX";
  4. container.setPadding( '10px' );
  5. var outliner = new UI.FancySelect().setWidth( '100%' ).setHeight('170px').setColor( '#444' ).setFontSize( '12px' ).onChange( selectFromOutliner );
  6. container.add( outliner );
  7. var textures = null;
  8. function getTextures() {
  9. var options = {};
  10. for ( var i in editor.textures ) {
  11. var texture = editor.textures[ i ];
  12. if ( texture.name == '') texture.name = 'Texture' + texture.id;
  13. options[ i ] = texture.name;
  14. }
  15. outliner.setOptions( options );
  16. getSelected();
  17. }
  18. function selectFromOutliner() {
  19. var uuid = outliner.getValue();
  20. editor.select( editor.textures[uuid] );
  21. }
  22. function getSelected() {
  23. var selectedUuids = [];
  24. for ( var uuid in editor.selected ) {
  25. if ( editor.textures[uuid] ) selectedUuids.push(uuid);
  26. }
  27. // TODO: implement multiple selection
  28. outliner.setValue( selectedUuids.length ? selectedUuids[0] : null );
  29. }
  30. // events
  31. var timeout;
  32. signals.sceneChanged.add( function () {
  33. clearTimeout( timeout );
  34. timeout = setTimeout( function () {
  35. getTextures();
  36. }, 100 );
  37. } );
  38. signals.selected.add( getSelected );
  39. return container;
  40. }