Skip to content

Commit 828da64

Browse files
authored
Merge pull request #599 from tonihele/bugfix/material-editor-fixes
Material editor fixes
2 parents 20875e2 + 45a0083 commit 828da64

File tree

3 files changed

+54
-43
lines changed

3 files changed

+54
-43
lines changed

jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ public class EditableMaterialFile {
5959
private final List<String> matDefEntries = new ArrayList<>();
6060
private final ProjectAssetManager manager;
6161
private FileSystem fs;
62-
public static final String[] variableTypes = new String[]{"Int", "Boolean", "Float", "Vector2", "Vector3", "Vector4", "Color", "Texture2D", "Texture3D", "TextureArray", "TextureBuffer", "TextureCubeMap"};
62+
63+
// Note that these are tested with startsWith, so the ordering matters (i.e. FloatArray & Float)
64+
public static final String[] variableTypes = new String[]{
65+
"IntArray", "Int", "Boolean", "FloatArray", "Float", "Vector2Array",
66+
"Vector3Array", "Vector4Array", "Vector2", "Vector3", "Vector4",
67+
"Color", "Texture2D", "Texture3D", "TextureArray", "TextureBuffer",
68+
"TextureCubeMap"};
6369

6470
public EditableMaterialFile(FileObject material, ProjectAssetManager manager) {
6571
this.material = material;
@@ -188,24 +194,26 @@ private void initMatDef() {
188194
matDef = manager.getAssetFolder().getFileObject(getMatDefName());
189195

190196
//try to read from classpath if not in assets folder and store in a virtual filesystem folder
191-
if (matDef == null || !matDef.isValid()) {
192-
try {
193-
fs = FileUtil.createMemoryFileSystem();
194-
matDef = fs.getRoot().createData(name, "j3md");
195-
try ( OutputStream out = matDef.getOutputStream()) {
196-
InputStream in = manager.getResourceAsStream(getMatDefName());
197-
if (in != null) {
198-
int input = in.read();
199-
while (input != -1) {
200-
out.write(input);
201-
input = in.read();
202-
}
203-
in.close();
197+
if (matDef != null && matDef.isValid()) {
198+
return;
199+
}
200+
201+
try {
202+
fs = FileUtil.createMemoryFileSystem();
203+
matDef = fs.getRoot().createData(name, "j3md");
204+
try ( OutputStream out = matDef.getOutputStream()) {
205+
InputStream in = manager.getResourceAsStream(getMatDefName());
206+
if (in != null) {
207+
int input = in.read();
208+
while (input != -1) {
209+
out.write(input);
210+
input = in.read();
204211
}
212+
in.close();
205213
}
206-
} catch (IOException ex) {
207-
Exceptions.printStackTrace(ex);
208214
}
215+
} catch (IOException ex) {
216+
Exceptions.printStackTrace(ex);
209217
}
210218
}
211219

@@ -255,6 +263,8 @@ private void checkWithMatDef() {
255263
materialParameters.put(prop.getName(), prop);
256264
}
257265
prop.setType(string);
266+
267+
break;
258268
}
259269
}
260270
}

jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.form

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,6 @@
354354
<ResourceString bundle="com/jme3/gde/materials/multiview/Bundle.properties" key="MaterialEditorTopComponent.jTextField1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
355355
</Property>
356356
</Properties>
357-
<Events>
358-
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextField1ActionPerformed"/>
359-
</Events>
360357
</Component>
361358
</SubComponents>
362359
</Container>

jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,32 @@ public void componentHidden(ComponentEvent e) {
127127
materialPreviewWidget1.showMaterial(manager, materialFileName);
128128

129129
relativeMaterialFileName = manager.getRelativeAssetPath(materialFileName);
130+
131+
jTextField1.getDocument().addDocumentListener(new DocumentListener() {
132+
@Override
133+
public void insertUpdate(DocumentEvent e) {
134+
updateName();
135+
}
136+
137+
@Override
138+
public void removeUpdate(DocumentEvent e) {
139+
updateName();
140+
}
141+
142+
@Override
143+
public void changedUpdate(DocumentEvent e) {
144+
updateName();
145+
}
146+
147+
private void updateName() {
148+
if (materialFile != null) {
149+
materialFile.setName(jTextField1.getText());
150+
String string = materialFile.getUpdatedContent();
151+
jTextArea1.setText(string);
152+
}
153+
}
154+
155+
});
130156
}
131157

132158
/** This method is called from within the constructor to
@@ -266,11 +292,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
266292
jToolBar3.add(jPanel1);
267293

268294
jTextField1.setText(org.openide.util.NbBundle.getMessage(MaterialEditorTopComponent.class, "MaterialEditorTopComponent.jTextField1.text")); // NOI18N
269-
jTextField1.addActionListener(new java.awt.event.ActionListener() {
270-
public void actionPerformed(java.awt.event.ActionEvent evt) {
271-
jTextField1ActionPerformed(evt);
272-
}
273-
});
274295
jToolBar3.add(jTextField1);
275296

276297
jCheckBox1.setSelected(true);
@@ -360,14 +381,6 @@ private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
360381
saveImmediate = jCheckBox1.isSelected();
361382
}//GEN-LAST:event_jCheckBox1ActionPerformed
362383

363-
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
364-
if (materialFile != null) {
365-
materialFile.setName(jTextField1.getText());
366-
String string = materialFile.getUpdatedContent();
367-
jTextArea1.setText(string);
368-
}
369-
}//GEN-LAST:event_jTextField1ActionPerformed
370-
371384
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
372385
if (materialFile != null) {
373386
updateProperties = true;
@@ -587,19 +600,10 @@ public void setMatDefList(final String[] matDefs, String selected) {
587600
jComboBox1.addItem("");
588601
List<String> matDefList = Arrays.asList(matDefs);
589602
Collections.sort(matDefList);
590-
String[] sortedMatDefs = matDefList.toArray(String[]::new);
591-
for (String string : sortedMatDefs) {
592-
jComboBox1.addItem(string);
603+
for (String matDef : matDefList) {
604+
jComboBox1.addItem(matDef);
593605
}
594606

595-
// jComboBox1.addItem("Common/MatDefs/Light/Lighting.j3md");
596-
// jComboBox1.addItem("Common/MatDefs/Misc/Unshaded.j3md");
597-
// jComboBox1.addItem("Common/MatDefs/Misc/Particle.j3md");
598-
// jComboBox1.addItem("Common/MatDefs/Misc/Sky.j3md");
599-
// jComboBox1.addItem("Common/MatDefs/Gui/Gui.j3md");
600-
// jComboBox1.addItem("Common/MatDefs/Terrain/TerrainLighting.j3md");
601-
// jComboBox1.addItem("Common/MatDefs/Terrain/Terrain.j3md");
602-
// jComboBox1.addItem("Common/MatDefs/Misc/ShowNormals.j3md");
603607
jComboBox1.setSelectedItem(selected);
604608
materialFile = prop;
605609
}

0 commit comments

Comments
 (0)