OSDN Git Service

three.jsをThirdPartyに追加
[webglgame/webgl_framework.git] / webglFramework / Thirdparty / three.js-master / editor / js / Sidebar.History.js
1 /**
2  * @author dforrer / https://github.com/dforrer
3  * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
4  */
5
6 Sidebar.History = function ( editor ) {
7
8         var signals = editor.signals;
9
10         var config = editor.config;
11
12         var history = editor.history;
13
14         var container = new UI.Panel();
15
16         container.add( new UI.Text( 'HISTORY' ) );
17
18         //
19
20         var persistent = new UI.THREE.Boolean( config.getKey( 'settings/history' ), 'persistent' );
21         persistent.setPosition( 'absolute' ).setRight( '8px' );
22         persistent.onChange( function () {
23
24                 var value = this.getValue();
25
26                 config.setKey( 'settings/history', value );
27
28                 if ( value ) {
29
30                         alert( 'The history will be preserved across sessions.\nThis can have an impact on performance when working with textures.' );
31
32                         var lastUndoCmd = history.undos[ history.undos.length - 1 ];
33                         var lastUndoId = ( lastUndoCmd !== undefined ) ? lastUndoCmd.id : 0;
34                         editor.history.enableSerialization( lastUndoId );
35
36                 } else {
37
38                         signals.historyChanged.dispatch();
39
40                 }
41
42         } );
43         container.add( persistent );
44
45         container.add( new UI.Break(), new UI.Break() );
46
47         var ignoreObjectSelectedSignal = false;
48
49         var outliner = new UI.Outliner( editor );
50         outliner.onChange( function () {
51
52                 ignoreObjectSelectedSignal = true;
53
54                 editor.history.goToState( parseInt( outliner.getValue() ) );
55
56                 ignoreObjectSelectedSignal = false;
57
58         } );
59         container.add( outliner );
60
61         //
62
63         var refreshUI = function () {
64
65                 var options = [];
66                 var enumerator = 1;
67
68                 function buildOption( object ) {
69
70                         var option = document.createElement( 'div' );
71                         option.value = object.id;
72
73                         return option;
74
75                 }
76
77                 ( function addObjects( objects ) {
78
79                         for ( var i = 0, l = objects.length; i < l; i ++ ) {
80
81                                 var object = objects[ i ];
82
83                                 var option = buildOption( object );
84                                 option.innerHTML = '&nbsp;' + object.name;
85
86                                 options.push( option );
87
88                         }
89
90                 } )( history.undos );
91
92
93                 ( function addObjects( objects, pad ) {
94
95                         for ( var i = objects.length - 1; i >= 0; i -- ) {
96
97                                 var object = objects[ i ];
98
99                                 var option = buildOption( object );
100                                 option.innerHTML = '&nbsp;' + object.name;
101                                 option.style.opacity = 0.3;
102
103                                 options.push( option );
104
105                         }
106
107                 } )( history.redos, '&nbsp;' );
108
109                 outliner.setOptions( options );
110
111         };
112
113         refreshUI();
114
115         // events
116
117         signals.editorCleared.add( refreshUI );
118
119         signals.historyChanged.add( refreshUI );
120         signals.historyChanged.add( function ( cmd ) {
121
122                 outliner.setValue( cmd !== undefined ? cmd.id : null );
123
124         } );
125
126
127         return container;
128
129 };