SDK mat def editor : proof checks on node naming

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10454 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 12 years ago
parent 67d5628721
commit 845b14c4f0
  1. 143
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java
  2. 1
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/TechniqueBlock.java
  3. 33
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/navigator/node/ShaderNodeNode.java
  4. 4
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/navigator/node/TechniqueNode.java
  5. 2
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/navigator/node/properties/DefaultProperty.java

@ -49,7 +49,7 @@ import javax.swing.border.TitledBorder;
* @author Nehon * @author Nehon
*/ */
public class Diagram extends JPanel implements MouseListener, MouseMotionListener, ComponentListener { public class Diagram extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
protected Dot draggedFrom; protected Dot draggedFrom;
protected Dot draggedTo; protected Dot draggedTo;
protected Selectable selectedItem; protected Selectable selectedItem;
@ -59,21 +59,21 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
private MyMenu contextMenu = new MyMenu("Add"); private MyMenu contextMenu = new MyMenu("Add");
private MatDefEditorlElement parent; private MatDefEditorlElement parent;
private String currentTechniqueName; private String currentTechniqueName;
public Diagram() { public Diagram() {
addMouseListener(this); addMouseListener(this);
addMouseMotionListener(this); addMouseMotionListener(this);
createPopupMenu(); createPopupMenu();
} }
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
} }
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
for (OutBusPanel outBusPanel : outBuses) { for (OutBusPanel outBusPanel : outBuses) {
Point p = SwingUtilities.convertPoint(this, e.getX(), e.getY(), outBusPanel); Point p = SwingUtilities.convertPoint(this, e.getX(), e.getY(), outBusPanel);
if (outBusPanel.contains(p)) { if (outBusPanel.contains(p)) {
@ -84,7 +84,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
} }
} }
for (Connection connection : connections) { for (Connection connection : connections) {
MouseEvent me = SwingUtilities.convertMouseEvent(this, e, connection); MouseEvent me = SwingUtilities.convertMouseEvent(this, e, connection);
connection.select(me); connection.select(me);
@ -92,18 +92,18 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
return; return;
} }
} }
selectedItem = null; selectedItem = null;
repaint(); repaint();
} }
public void refreshPreviews(Material mat) { public void refreshPreviews(Material mat) {
for (OutBusPanel outBusPanel : outBuses) { for (OutBusPanel outBusPanel : outBuses) {
outBusPanel.updatePreview(mat); outBusPanel.updatePreview(mat);
} }
} }
Point clickLoc = new Point(0, 0); Point clickLoc = new Point(0, 0);
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
if (draggedFrom != null && draggedFrom.getNode() instanceof OutBusPanel) { if (draggedFrom != null && draggedFrom.getNode() instanceof OutBusPanel) {
@ -119,13 +119,13 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
contextMenu.show(this, e.getX(), e.getY()); contextMenu.show(this, e.getX(), e.getY());
clickLoc.setLocation(e.getX(), e.getY()); clickLoc.setLocation(e.getX(), e.getY());
} }
} }
public MatDefEditorlElement getEditorParent() { public MatDefEditorlElement getEditorParent() {
return parent; return parent;
} }
public void addConnection(Connection conn) { public void addConnection(Connection conn) {
connections.add(conn); connections.add(conn);
add(conn); add(conn);
@ -134,11 +134,11 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
repaint(); repaint();
} }
public void notifyMappingCreation(Connection conn) { public void notifyMappingCreation(Connection conn) {
parent.makeMapping(conn); parent.makeMapping(conn);
} }
public void addNode(NodePanel node) { public void addNode(NodePanel node) {
add(node); add(node);
node.setTechName(currentTechniqueName); node.setTechName(currentTechniqueName);
@ -147,7 +147,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
setComponentZOrder(node, 0); setComponentZOrder(node, 0);
node.addComponentListener(this); node.addComponentListener(this);
} }
public void addOutBus(OutBusPanel bus) { public void addOutBus(OutBusPanel bus) {
outBuses.add(bus); outBuses.add(bus);
bus.setDiagram(this); bus.setDiagram(this);
@ -157,15 +157,15 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
bus.componentResized(new ComponentEvent(this, ActionEvent.ACTION_PERFORMED)); bus.componentResized(new ComponentEvent(this, ActionEvent.ACTION_PERFORMED));
bus.revalidate(); bus.revalidate();
} }
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
} }
@Override @Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
} }
protected void removeSelectedConnection() { protected void removeSelectedConnection() {
if (selectedItem instanceof Connection) { if (selectedItem instanceof Connection) {
Connection selectedConnection = (Connection) selectedItem; Connection selectedConnection = (Connection) selectedItem;
@ -174,11 +174,26 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
parent.notifyRemoveConnection(selectedConnection); parent.notifyRemoveConnection(selectedConnection);
} }
} }
private String fixNodeName(String name) {
return fixNodeName(name, 0);
}
private String fixNodeName(String name, int count) {
for (NodePanel nodePanel : nodes) {
if ((name + (count == 0 ? "" : count)).equals(nodePanel.getName())) {
return fixNodeName(name, count + 1);
}
}
return name + (count == 0 ? "" : count);
}
public void addNodesFromDefs(List<ShaderNodeDefinition> defList, String path, Point clickPosition) { public void addNodesFromDefs(List<ShaderNodeDefinition> defList, String path, Point clickPosition) {
int i = 0; int i = 0;
for (ShaderNodeDefinition def : defList) { for (ShaderNodeDefinition def : defList) {
ShaderNodeBlock sn = new ShaderNodeBlock(def, path); ShaderNodeBlock sn = new ShaderNodeBlock(def, path);
sn.setName(fixNodeName(sn.getName()));
NodePanel np = new NodePanel(sn, def); NodePanel np = new NodePanel(sn, def);
addNode(np); addNode(np);
np.setLocation(clickPosition.x + i * 150, clickPosition.y); np.setLocation(clickPosition.x + i * 150, clickPosition.y);
@ -189,7 +204,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
repaint(); repaint();
} }
public void addMatParam(String type, String name, Point point) { public void addMatParam(String type, String name, Point point) {
String fixedType = type; String fixedType = type;
if (type.equals("Color")) { if (type.equals("Color")) {
@ -203,9 +218,9 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
repaint(); repaint();
getEditorParent().notifyAddMapParam(type, name); getEditorParent().notifyAddMapParam(type, name);
} }
public void addWorldParam(UniformBinding binding, Point point) { public void addWorldParam(UniformBinding binding, Point point) {
ShaderNodeVariable param = new ShaderNodeVariable(binding.getGlslType(), binding.name()); ShaderNodeVariable param = new ShaderNodeVariable(binding.getGlslType(), binding.name());
NodePanel np = new NodePanel(param, NodePanel.NodeType.WorldParam); NodePanel np = new NodePanel(param, NodePanel.NodeType.WorldParam);
addNode(np); addNode(np);
@ -214,16 +229,16 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
repaint(); repaint();
getEditorParent().notifyAddWorldParam(binding.name()); getEditorParent().notifyAddWorldParam(binding.name());
} }
public void addAttribute(String name, String type, Point point) { public void addAttribute(String name, String type, Point point) {
ShaderNodeVariable param = new ShaderNodeVariable(type, "Attr", name); ShaderNodeVariable param = new ShaderNodeVariable(type, "Attr", name);
NodePanel np = new NodePanel(param, NodePanel.NodeType.Attribute); NodePanel np = new NodePanel(param, NodePanel.NodeType.Attribute);
addNode(np); addNode(np);
np.setLocation(point.x, point.y); np.setLocation(point.x, point.y);
np.revalidate(); np.revalidate();
repaint(); repaint();
} }
protected void removeSelectedNode() { protected void removeSelectedNode() {
if (selectedItem instanceof NodePanel) { if (selectedItem instanceof NodePanel) {
int result = JOptionPane.showConfirmDialog(null, "Delete this node and all its mappings?", "Delete Shader Node", JOptionPane.OK_CANCEL_OPTION); int result = JOptionPane.showConfirmDialog(null, "Delete this node and all its mappings?", "Delete Shader Node", JOptionPane.OK_CANCEL_OPTION);
@ -239,7 +254,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
remove(conn); remove(conn);
} }
} }
remove(selectedNode); remove(selectedNode);
selectedItem = null; selectedItem = null;
repaint(); repaint();
@ -247,7 +262,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
} }
} }
@Override @Override
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
if (draggedFrom == null) { if (draggedFrom == null) {
@ -258,7 +273,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
} }
} }
protected void draggingDot(MouseEvent e) { protected void draggingDot(MouseEvent e) {
for (OutBusPanel outBusPanel : outBuses) { for (OutBusPanel outBusPanel : outBuses) {
Point p = SwingUtilities.convertPoint(this, e.getX(), e.getY(), outBusPanel); Point p = SwingUtilities.convertPoint(this, e.getX(), e.getY(), outBusPanel);
@ -271,18 +286,18 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
} }
} }
public Connection connect(Dot start, Dot end) { public Connection connect(Dot start, Dot end) {
Connection conn = new Connection(start, end); Connection conn = new Connection(start, end);
start.connect(conn); start.connect(conn);
end.connect(conn); end.connect(conn);
addConnection(conn); addConnection(conn);
return conn; return conn;
} }
public NodePanel getNodePanel(String key) { public NodePanel getNodePanel(String key) {
for (NodePanel nodePanel : nodes) { for (NodePanel nodePanel : nodes) {
if (nodePanel.getKey().equals(key)) { if (nodePanel.getKey().equals(key)) {
@ -291,7 +306,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
return null; return null;
} }
public OutBusPanel getOutBusPanel(String key) { public OutBusPanel getOutBusPanel(String key) {
for (OutBusPanel out : outBuses) { for (OutBusPanel out : outBuses) {
if (out.getKey().equals(key)) { if (out.getKey().equals(key)) {
@ -333,19 +348,19 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
* @return * @return
*/ */
public Selectable select(String key) { public Selectable select(String key) {
for (NodePanel nodePanel : nodes) { for (NodePanel nodePanel : nodes) {
if (nodePanel.getKey().equals(key)) { if (nodePanel.getKey().equals(key)) {
return doSelect(nodePanel); return doSelect(nodePanel);
} }
} }
for (Connection connection : connections) { for (Connection connection : connections) {
if (connection.getKey().equals(key)) { if (connection.getKey().equals(key)) {
return doSelect(connection); return doSelect(connection);
} }
} }
for (OutBusPanel outBusPanel : outBuses) { for (OutBusPanel outBusPanel : outBuses) {
if (outBusPanel.getKey().equals(key)) { if (outBusPanel.getKey().equals(key)) {
return doSelect(outBusPanel); return doSelect(outBusPanel);
@ -353,18 +368,18 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
return doSelect(null); return doSelect(null);
} }
@Override @Override
public void mouseMoved(MouseEvent e) { public void mouseMoved(MouseEvent e) {
dispatchToOutBuses(e); dispatchToOutBuses(e);
} }
private JMenuItem createMenuItem(String text, Icon icon) { private JMenuItem createMenuItem(String text, Icon icon) {
JMenuItem item = new JMenuItem(text, icon); JMenuItem item = new JMenuItem(text, icon);
item.setFont(new Font("Tahoma", 1, 10)); // NOI18N item.setFont(new Font("Tahoma", 1, 10)); // NOI18N
return item; return item;
} }
private void createPopupMenu() { private void createPopupMenu() {
contextMenu.setFont(new Font("Tahoma", 1, 10)); // NOI18N contextMenu.setFont(new Font("Tahoma", 1, 10)); // NOI18N
contextMenu.setOpaque(true); contextMenu.setOpaque(true);
@ -372,12 +387,12 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
TitledBorder labelBorder = BorderFactory.createTitledBorder( TitledBorder labelBorder = BorderFactory.createTitledBorder(
titleUnderline, contextMenu.getLabel(), titleUnderline, contextMenu.getLabel(),
TitledBorder.LEADING, TitledBorder.ABOVE_TOP, contextMenu.getFont(), Color.BLACK); TitledBorder.LEADING, TitledBorder.ABOVE_TOP, contextMenu.getFont(), Color.BLACK);
contextMenu.setBorder(BorderFactory.createLineBorder(Color.BLACK)); contextMenu.setBorder(BorderFactory.createLineBorder(Color.BLACK));
contextMenu.setBorder(BorderFactory.createCompoundBorder(contextMenu.getBorder(), contextMenu.setBorder(BorderFactory.createCompoundBorder(contextMenu.getBorder(),
labelBorder)); labelBorder));
JMenuItem nodeItem = createMenuItem("Node", Icons.node); JMenuItem nodeItem = createMenuItem("Node", Icons.node);
nodeItem.addActionListener(new ActionListener() { nodeItem.addActionListener(new ActionListener() {
@Override @Override
@ -387,7 +402,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
d.setVisible(true); d.setVisible(true);
} }
}); });
contextMenu.add(nodeItem); contextMenu.add(nodeItem);
contextMenu.add(createSeparator()); contextMenu.add(createSeparator());
JMenuItem matParamItem = createMenuItem("Material Parameter", Icons.mat); JMenuItem matParamItem = createMenuItem("Material Parameter", Icons.mat);
@ -400,7 +415,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
}); });
contextMenu.add(matParamItem); contextMenu.add(matParamItem);
JMenuItem worldParamItem = createMenuItem("World Parameter", Icons.world); JMenuItem worldParamItem = createMenuItem("World Parameter", Icons.world);
worldParamItem.addActionListener(new ActionListener() { worldParamItem.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -428,19 +443,19 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
OutBusPanel p2 = new OutBusPanel("color" + (outBuses.size() - 1), Shader.ShaderType.Fragment); OutBusPanel p2 = new OutBusPanel("color" + (outBuses.size() - 1), Shader.ShaderType.Fragment);
p2.setBounds(0, 350 + 50 * (outBuses.size() - 1), p2.getWidth(), p2.getHeight()); p2.setBounds(0, 350 + 50 * (outBuses.size() - 1), p2.getWidth(), p2.getHeight());
addOutBus(p2); addOutBus(p2);
} }
}); });
} }
private JSeparator createSeparator() { private JSeparator createSeparator() {
JSeparator jsep = new JSeparator(JSeparator.HORIZONTAL); JSeparator jsep = new JSeparator(JSeparator.HORIZONTAL);
jsep.setBackground(Color.BLACK); jsep.setBackground(Color.BLACK);
return jsep; return jsep;
} }
private void dispatchToOutBuses(MouseEvent e) { private void dispatchToOutBuses(MouseEvent e) {
for (OutBusPanel outBusPanel : outBuses) { for (OutBusPanel outBusPanel : outBuses) {
Point p = SwingUtilities.convertPoint(this, e.getX(), e.getY(), outBusPanel); Point p = SwingUtilities.convertPoint(this, e.getX(), e.getY(), outBusPanel);
@ -453,20 +468,20 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
} }
} }
private void removeConnection(Connection selectedConnection) { private void removeConnection(Connection selectedConnection) {
connections.remove(selectedConnection); connections.remove(selectedConnection);
selectedConnection.end.disconnect(); selectedConnection.end.disconnect();
selectedConnection.start.disconnect(); selectedConnection.start.disconnect();
remove(selectedConnection); remove(selectedConnection);
} }
private class MyMenu extends JPopupMenu { private class MyMenu extends JPopupMenu {
public MyMenu(String label) { public MyMenu(String label) {
super(label); super(label);
} }
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
//Color c1 = new Color(100, 100, 100, 255); //Color c1 = new Color(100, 100, 100, 255);
@ -475,11 +490,11 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
} }
} }
public void fixSize() { public void fixSize() {
int maxWidth = minWidth; int maxWidth = minWidth;
int maxHeight = minHeight; int maxHeight = minHeight;
for (NodePanel nodePanel : nodes) { for (NodePanel nodePanel : nodes) {
int w = nodePanel.getLocation().x + nodePanel.getWidth() + 150; int w = nodePanel.getLocation().x + nodePanel.getWidth() + 150;
if (w > maxWidth) { if (w > maxWidth) {
@ -501,30 +516,30 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
int minWidth = 0; int minWidth = 0;
int minHeight = 0; int minHeight = 0;
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
minWidth = e.getComponent().getWidth() - 2; minWidth = e.getComponent().getWidth() - 2;
minHeight = e.getComponent().getHeight() - 2; minHeight = e.getComponent().getHeight() - 2;
fixSize(); fixSize();
} }
public void componentMoved(ComponentEvent e) { public void componentMoved(ComponentEvent e) {
} }
public void componentShown(ComponentEvent e) { public void componentShown(ComponentEvent e) {
} }
public void componentHidden(ComponentEvent e) { public void componentHidden(ComponentEvent e) {
} }
public void setParent(MatDefEditorlElement parent) { public void setParent(MatDefEditorlElement parent) {
this.parent = parent; this.parent = parent;
} }
public void setCurrentTechniqueName(String currentTechniqueName) { public void setCurrentTechniqueName(String currentTechniqueName) {
this.currentTechniqueName = currentTechniqueName; this.currentTechniqueName = currentTechniqueName;
} }
public String getCurrentTechniqueName() { public String getCurrentTechniqueName() {
return currentTechniqueName; return currentTechniqueName;
} }

@ -7,7 +7,6 @@ package com.jme3.gde.materialdefinition.fileStructure;
import com.jme3.gde.materialdefinition.fileStructure.leaves.FragmentShaderFileBlock; import com.jme3.gde.materialdefinition.fileStructure.leaves.FragmentShaderFileBlock;
import com.jme3.gde.materialdefinition.fileStructure.leaves.InputMappingBlock; import com.jme3.gde.materialdefinition.fileStructure.leaves.InputMappingBlock;
import com.jme3.gde.materialdefinition.fileStructure.leaves.LightModeBlock; import com.jme3.gde.materialdefinition.fileStructure.leaves.LightModeBlock;
import com.jme3.gde.materialdefinition.fileStructure.leaves.MatParamBlock;
import com.jme3.gde.materialdefinition.fileStructure.leaves.ShaderFileBlock; import com.jme3.gde.materialdefinition.fileStructure.leaves.ShaderFileBlock;
import com.jme3.gde.materialdefinition.fileStructure.leaves.UnsupportedStatement; import com.jme3.gde.materialdefinition.fileStructure.leaves.UnsupportedStatement;
import com.jme3.gde.materialdefinition.fileStructure.leaves.VertexShaderFileBlock; import com.jme3.gde.materialdefinition.fileStructure.leaves.VertexShaderFileBlock;

@ -7,7 +7,9 @@ package com.jme3.gde.materialdefinition.navigator.node;
import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.materialdefinition.MatDefDataObject; import com.jme3.gde.materialdefinition.MatDefDataObject;
import com.jme3.gde.materialdefinition.editor.Selectable; import com.jme3.gde.materialdefinition.editor.Selectable;
import com.jme3.gde.materialdefinition.fileStructure.MatDefBlock;
import com.jme3.gde.materialdefinition.fileStructure.ShaderNodeBlock; import com.jme3.gde.materialdefinition.fileStructure.ShaderNodeBlock;
import com.jme3.gde.materialdefinition.fileStructure.TechniqueBlock;
import com.jme3.gde.materialdefinition.fileStructure.leaves.MappingBlock; import com.jme3.gde.materialdefinition.fileStructure.leaves.MappingBlock;
import com.jme3.gde.materialdefinition.icons.Icons; import com.jme3.gde.materialdefinition.icons.Icons;
import com.jme3.gde.materialdefinition.navigator.node.properties.DefaultProperty; import com.jme3.gde.materialdefinition.navigator.node.properties.DefaultProperty;
@ -17,6 +19,7 @@ import com.jme3.shader.ShaderNodeDefinition;
import java.awt.Image; import java.awt.Image;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.openide.nodes.Children; import org.openide.nodes.Children;
@ -33,10 +36,9 @@ import org.openide.util.WeakListeners;
public class ShaderNodeNode extends AbstractMatDefNode implements Selectable, PropertyChangeListener { public class ShaderNodeNode extends AbstractMatDefNode implements Selectable, PropertyChangeListener {
ShaderNodeBlock shaderNode; ShaderNodeBlock shaderNode;
ShaderNodeDefinition def; ShaderNodeDefinition def;
String key = ""; String key = "";
public ShaderNodeNode(final Lookup lookup, final ShaderNodeBlock shaderNode) { public ShaderNodeNode(final Lookup lookup, final ShaderNodeBlock shaderNode) {
// super(Children.create(new ChildFactory<MappingBlock>() { // super(Children.create(new ChildFactory<MappingBlock>() {
// @Override // @Override
@ -55,7 +57,7 @@ public class ShaderNodeNode extends AbstractMatDefNode implements Selectable, Pr
// return new MappingNode(lookup, key); // return new MappingNode(lookup, key);
// } // }
// }, true), lookup); // }, true), lookup);
super(new MappingNodeChildren(lookup, shaderNode), lookup); super(new MappingNodeChildren(lookup, shaderNode), lookup);
this.shaderNode = shaderNode; this.shaderNode = shaderNode;
setName(shaderNode.getName()); setName(shaderNode.getName());
key = makeKey(); key = makeKey();
@ -78,7 +80,17 @@ public class ShaderNodeNode extends AbstractMatDefNode implements Selectable, Pr
set.setDisplayName(shaderNode.getName() + " ShaderNode"); set.setDisplayName(shaderNode.getName() + " ShaderNode");
set.setShortDescription(def.getDocumentation()); set.setShortDescription(def.getDocumentation());
try { try {
set.put(new DefaultProperty<String>(shaderNode, String.class, "Name", "getName", "setName")); set.put(new DefaultProperty<String>(shaderNode, String.class, "Name", "getName", "setName") {
@Override
public void setValue(String val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
val = fixNodeName(val);
//glsl variable can't start with a number
if(val.matches("^\\d.*")){
return;
}
super.setValue(val);
}
});
set.put(new DefaultProperty<String>(shaderNode, String.class, "Condition", "getCondition", "setCondition")); set.put(new DefaultProperty<String>(shaderNode, String.class, "Condition", "getCondition", "setCondition"));
} catch (NoSuchMethodException ex) { } catch (NoSuchMethodException ex) {
@ -91,8 +103,21 @@ public class ShaderNodeNode extends AbstractMatDefNode implements Selectable, Pr
sheet.put(set); sheet.put(set);
return sheet; return sheet;
}
private String fixNodeName(String name) {
TechniqueBlock tech = ((TechniqueNode) this.getParentNode()).getDef();
List<ShaderNodeBlock> list = tech.getShaderNodes();
return fixNodeName(list, name, 0);
}
private String fixNodeName(List<ShaderNodeBlock> nodes, String name, int count) {
for (ShaderNodeBlock nodePanel : nodes) {
if ((name + (count == 0 ? "" : count)).equals(nodePanel.getName())) {
return fixNodeName(nodes, name, count + 1);
}
}
return name + (count == 0 ? "" : count);
} }
@Override @Override

@ -56,6 +56,10 @@ public class TechniqueNode extends AbstractMatDefNode implements Selectable, Pro
} }
protected TechniqueBlock getDef() {
return def;
}
@Override @Override
public Image getIcon(int type) { public Image getIcon(int type) {
return Icons.tech.getImage(); return Icons.tech.getImage();

@ -28,5 +28,5 @@ public class DefaultProperty<T> extends PropertySupport.Reflection<T> {
@Override @Override
public boolean canWrite() { public boolean canWrite() {
return !readOnly; return !readOnly;
} }
} }

Loading…
Cancel
Save