diff options
author | Valerio Virgillito | 2012-07-09 12:15:26 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-07-09 12:15:26 -0700 |
commit | 1839f24e8dcbad38d1381bbcd65c17a9caa45987 (patch) | |
tree | 516a29ca99d4aae0d5228223fff438c1a3c4e0d3 /js/panels/Materials/materials-popup.reel/materials-popup.js | |
parent | aedd14b18695d031f695d27dfbd94df5614495bb (diff) | |
parent | febfdb18042d1c73ac58ee4e35c5f176428dee00 (diff) | |
download | ninja-1839f24e8dcbad38d1381bbcd65c17a9caa45987.tar.gz |
Merge pull request #346 from mqg734/MaterialsUI
UI support for preview, edit, duplicate and delete of WebGL Materials.
Diffstat (limited to 'js/panels/Materials/materials-popup.reel/materials-popup.js')
-rwxr-xr-x | js/panels/Materials/materials-popup.reel/materials-popup.js | 440 |
1 files changed, 186 insertions, 254 deletions
diff --git a/js/panels/Materials/materials-popup.reel/materials-popup.js b/js/panels/Materials/materials-popup.reel/materials-popup.js index 7c5493c6..0d0435a4 100755 --- a/js/panels/Materials/materials-popup.reel/materials-popup.js +++ b/js/panels/Materials/materials-popup.reel/materials-popup.js | |||
@@ -30,7 +30,11 @@ POSSIBILITY OF SUCH DAMAGE. | |||
30 | 30 | ||
31 | var Montage = require("montage/core/core").Montage, | 31 | var Montage = require("montage/core/core").Montage, |
32 | Component = require("montage/ui/component").Component, | 32 | Component = require("montage/ui/component").Component, |
33 | MaterialsModel = require("js/models/materials-model").MaterialsModel; | 33 | MaterialsModel = require("js/models/materials-model").MaterialsModel, |
34 | NJUtils = require("js/lib/NJUtils").NJUtils, | ||
35 | World = require("js/lib/drawing/world").World, | ||
36 | Rectangle = require("js/lib/geom/rectangle").Rectangle, | ||
37 | ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; | ||
34 | 38 | ||
35 | //////////////////////////////////////////////////////////////////////// | 39 | //////////////////////////////////////////////////////////////////////// |
36 | //Exporting as MaterialsPopup | 40 | //Exporting as MaterialsPopup |
@@ -46,11 +50,35 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
46 | serializable: true | 50 | serializable: true |
47 | }, | 51 | }, |
48 | 52 | ||
53 | saveAsButton: { | ||
54 | value: null, | ||
55 | serializable: true | ||
56 | }, | ||
57 | |||
58 | resetButton: { | ||
59 | value: null, | ||
60 | serializable: true | ||
61 | }, | ||
62 | |||
63 | materialsLibraryRef: { | ||
64 | value: null | ||
65 | }, | ||
66 | |||
49 | materialTitle: { | 67 | materialTitle: { |
50 | value: null, | 68 | value: null, |
51 | serializable: true | 69 | serializable: true |
52 | }, | 70 | }, |
53 | 71 | ||
72 | previewCanvas: { | ||
73 | value: null, | ||
74 | serializable: true | ||
75 | }, | ||
76 | |||
77 | previewShape: { | ||
78 | value: null, | ||
79 | serializable: true | ||
80 | }, | ||
81 | |||
54 | // Material Properties | 82 | // Material Properties |
55 | _materialName: { | 83 | _materialName: { |
56 | enumerable: true, | 84 | enumerable: true, |
@@ -66,11 +94,11 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
66 | switch(event._currentTarget.label) | 94 | switch(event._currentTarget.label) |
67 | { | 95 | { |
68 | case "Cancel": | 96 | case "Cancel": |
69 | console.log("Cancel material edit"); | 97 | // console.log("Cancel material edit"); |
70 | this.revertToOriginalValues(); | 98 | this.revertToOriginalValues(); |
71 | break; | 99 | break; |
72 | case "OK": | 100 | case "OK": |
73 | console.log("Committing material with the following values:"); | 101 | // console.log("Committing material with the following values:"); |
74 | for(var i=0, len=this.materialsProperties.childComponents.length; i< len; i++) | 102 | for(var i=0, len=this.materialsProperties.childComponents.length; i< len; i++) |
75 | { | 103 | { |
76 | var childControl = this.materialsProperties.childComponents[i]; | 104 | var childControl = this.materialsProperties.childComponents[i]; |
@@ -89,6 +117,12 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
89 | 117 | ||
90 | } | 118 | } |
91 | break; | 119 | break; |
120 | case "Save As...": | ||
121 | this.saveAs(); | ||
122 | break; | ||
123 | case "Reset": | ||
124 | this.reset(); | ||
125 | break; | ||
92 | } | 126 | } |
93 | 127 | ||
94 | // Notify Materials Library to close popup | 128 | // Notify Materials Library to close popup |
@@ -96,6 +130,28 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
96 | } | 130 | } |
97 | }, | 131 | }, |
98 | 132 | ||
133 | saveAs: | ||
134 | { | ||
135 | value: function() | ||
136 | { | ||
137 | // console.log("Save As..."); | ||
138 | var materialCopy = prompt("Save material as", this._materialName + "_Copy"); | ||
139 | |||
140 | if (materialCopy) | ||
141 | { | ||
142 | this.materialsLibraryRef.duplicateMaterial(materialCopy); | ||
143 | } | ||
144 | } | ||
145 | }, | ||
146 | |||
147 | reset: | ||
148 | { | ||
149 | value: function() | ||
150 | { | ||
151 | // console.log("Reset"); | ||
152 | } | ||
153 | }, | ||
154 | |||
99 | revertToOriginalValues: | 155 | revertToOriginalValues: |
100 | { | 156 | { |
101 | value: function() | 157 | value: function() |
@@ -155,15 +211,15 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
155 | { | 211 | { |
156 | value: function(event) | 212 | value: function(event) |
157 | { | 213 | { |
158 | if(typeof event.propertyValue === "object") | 214 | // if(typeof event.propertyValue === "object") |
159 | { | 215 | // { |
160 | console.log(event.propertyLabel + " changing to "); | 216 | // console.log(event.propertyLabel + " changing to "); |
161 | console.dir(event.propertyValue); | 217 | // console.dir(event.propertyValue); |
162 | } | 218 | // } |
163 | else | 219 | // else |
164 | { | 220 | // { |
165 | console.log(event.propertyLabel + " changing to " + event.propertyValue); | 221 | // console.log(event.propertyLabel + " changing to " + event.propertyValue); |
166 | } | 222 | // } |
167 | 223 | ||
168 | if (event.propertyLabel && event.propertyValue) | 224 | if (event.propertyLabel && event.propertyValue) |
169 | this.applyProperty( event.propertyLabel, event.propertyValue ); | 225 | this.applyProperty( event.propertyLabel, event.propertyValue ); |
@@ -175,15 +231,15 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
175 | value: function(theEvent) | 231 | value: function(theEvent) |
176 | { | 232 | { |
177 | var event = theEvent._event; | 233 | var event = theEvent._event; |
178 | if(typeof event.propertyValue === "object") | 234 | // if(typeof event.propertyValue === "object") |
179 | { | 235 | // { |
180 | console.log(event.propertyLabel + " changed to "); | 236 | // console.log(event.propertyLabel + " changed to "); |
181 | console.dir(event.propertyValue); | 237 | // console.dir(event.propertyValue); |
182 | } | 238 | // } |
183 | else | 239 | // else |
184 | { | 240 | // { |
185 | console.log(event.propertyLabel + " changed to " + event.propertyValue); | 241 | // console.log(event.propertyLabel + " changed to " + event.propertyValue); |
186 | } | 242 | // } |
187 | 243 | ||
188 | if (event.propertyLabel) | 244 | if (event.propertyLabel) |
189 | this.applyProperty( event.propertyLabel, event.propertyValue ); | 245 | this.applyProperty( event.propertyLabel, event.propertyValue ); |
@@ -219,9 +275,10 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
219 | this._material.setProperty( this._propNames[index], value ); | 275 | this._material.setProperty( this._propNames[index], value ); |
220 | } | 276 | } |
221 | 277 | ||
278 | var obj, matArray, matTypeArray, nMats, iMat, world; | ||
222 | if (this._useSelection) | 279 | if (this._useSelection) |
223 | { | 280 | { |
224 | console.log( "apply to selection" ); | 281 | // console.log( "apply to selection" ); |
225 | 282 | ||
226 | var selection = this.application.ninja.selectedElements; | 283 | var selection = this.application.ninja.selectedElements; |
227 | if (selection && (selection.length > 0)) | 284 | if (selection && (selection.length > 0)) |
@@ -230,25 +287,38 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
230 | for (var iObj=0; iObj<nObjs; iObj++) | 287 | for (var iObj=0; iObj<nObjs; iObj++) |
231 | { | 288 | { |
232 | var canvas = selection[iObj]; | 289 | var canvas = selection[iObj]; |
233 | var obj; | ||
234 | if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj; | 290 | if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj; |
235 | if (obj) | 291 | if (obj) |
236 | { | 292 | { |
237 | var matArray = obj._materialArray; | 293 | matArray = o |