From e781292fba535723beb3fd9c631f297a258d3cd3 Mon Sep 17 00:00:00 2001 From: Waverunner Date: Fri, 17 Oct 2014 15:16:39 -0400 Subject: [PATCH] Refactored conversation node to use inheritance --- .../csc/conversationeditor/Compiler.java | 62 ++-- .../ConversationConnectProvider.java | 27 +- .../ConversationWidget.java | 18 +- .../EditorTopComponent.java | 8 +- .../actions/NewConvEnd.java | 6 +- .../actions/NewConvOption.java | 6 +- .../actions/NewConvResponse.java | 6 +- .../actions/OpenConversation.java | 4 +- .../actions/SaveConversation.java | 4 +- .../actions/TrashConvNode.java | 6 +- .../conversationeditor/nodes/BeginNode.java | 23 ++ .../nodes/ConversationNode.java | 267 ++++++------------ .../csc/conversationeditor/nodes/EndNode.java | 23 ++ .../conversationeditor/nodes/OptionNode.java | 104 +++++++ .../nodes/ResponseNode.java | 23 ++ .../{ => nodes/imgs}/conversation_begin.png | Bin .../{ => nodes/imgs}/conversation_end.png | Bin .../{ => nodes/imgs}/conversation_option.png | Bin .../imgs}/conversation_response.png | Bin .../{ => scene}/SceneSaver.java | 39 +-- .../{ => scene}/SceneView.java | 7 +- 21 files changed, 354 insertions(+), 279 deletions(-) create mode 100644 ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/BeginNode.java create mode 100644 ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/EndNode.java create mode 100644 ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/OptionNode.java create mode 100644 ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/ResponseNode.java rename ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/{ => nodes/imgs}/conversation_begin.png (100%) rename ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/{ => nodes/imgs}/conversation_end.png (100%) rename ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/{ => nodes/imgs}/conversation_option.png (100%) rename ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/{ => nodes/imgs}/conversation_response.png (100%) rename ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/{ => scene}/SceneSaver.java (88%) rename ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/{ => scene}/SceneView.java (95%) diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/Compiler.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/Compiler.java index 0eb8024..5b6ee6b 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/Compiler.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/Compiler.java @@ -1,8 +1,8 @@ package com.projectswg.tools.csc.conversationeditor; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; -import com.projectswg.tools.csc.conversationeditor.EditorTopComponent; -import com.projectswg.tools.csc.conversationeditor.SceneView; +import com.projectswg.tools.csc.conversationeditor.nodes.OptionNode; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -48,7 +48,7 @@ public class Compiler { LinkedHashMap> conversationLinks = scene.getConversationLinks(); for (Map.Entry> entry : conversationLinks.entrySet()) { - if (entry.getKey().isStartNode()) { + if (entry.getKey().getType().equals(ConversationNode.BEGIN)) { createOptionsAndHandler(bw, entry.getKey(), entry.getValue(), 1, conversationLinks); break; } @@ -82,28 +82,42 @@ public class Compiler { int count = handleNum + 1; for (ConversationNode selectedOption : options) { - bw.write(indent4 + (options.indexOf(selectedOption) > 0 ? "elif" : "if") + " selection == " + options.indexOf(selectedOption) + ":\n"); - if (conversationLinks.containsKey(selectedOption)) { - if (comments) bw.write(indent8 + "# " + (selectedOption.getDisplayText().equals("") ? selectedOption.getStf() : selectedOption.getDisplayText()) + "\n"); + if (!(selectedOption instanceof OptionNode)) + continue; + + OptionNode option = (OptionNode) selectedOption; + + bw.write(indent4 + (options.indexOf(option) > 0 ? "elif" : "if") + " selection == " + options.indexOf(option) + ":\n"); + if (conversationLinks.containsKey(option)) { + + if (comments) bw.write(indent8 + "# " + (option.getDisplayText().equals("") ? option.getStf() : option.getDisplayText()) + "\n"); + for (ConversationNode handleNode : conversationLinks.get(selectedOption)) { - if (!handleNode.isOption() && !handleNode.isEndNode()) { - if (conversationLinks.get(handleNode) == null) { - bw.write(indent8 + "# NULL Error printing out handle for " + handleNode.getStf()); - } else { - createOptions(bw, conversationLinks.get(handleNode), count++, indent8); - bw.write(indent8 + "core.conversationService.sendConversationMessage(actor, npc, OutOfBand.ProsePackage('@conversation/" - + handleNode.getStf() + "')\n"); - handleFuncs.put(handleNode, conversationLinks.get(handleNode)); // Put these nodes in list so we can create the handlers later. - } - } else if (handleNode.isEndNode()) { - if (handleNode.getStf().contains(":")) { - String[] split = handleNode.getStf().split(":"); - bw.write(indent8 + "core.conversationService.sendStopConversation(actor, npc, 'conversation/" + split[0] + "', '" + split[1] + "')\n"); - } else { - bw.write(indent8 + "# Couldn't write end response because of bad format!"); - } + switch(handleNode.getType()) { + + case ConversationNode.RESPONSE: + if (conversationLinks.get(handleNode) == null) { + bw.write(indent8 + "# NULL Error printing out handle for " + handleNode.getStf()); + } else { + createOptions(bw, conversationLinks.get(handleNode), count++, indent8); + bw.write(indent8 + "core.conversationService.sendConversationMessage(actor, npc, OutOfBand.ProsePackage('@conversation/" + + handleNode.getStf() + "')\n"); + handleFuncs.put(handleNode, conversationLinks.get(handleNode)); // Put these nodes in list so we can create the handlers later. + } + break; + + case ConversationNode.END: + if (handleNode.getStf().contains(":")) { + String[] split = handleNode.getStf().split(":"); + bw.write(indent8 + "core.conversationService.sendStopConversation(actor, npc, 'conversation/" + split[0] + "', '" + split[1] + "')\n"); + } else { + bw.write(indent8 + "# Couldn't write end response because of bad format!"); + } + break; + } } + } bw.write(indent8 + "return\n"); bw.newLine(); @@ -129,7 +143,7 @@ public class Compiler { if (options.size() > 1) { for (ConversationNode option : options) { bw.write(indent4 + "options.add(ConversationOption(OutOfBand.ProsePackage('@conversation/" + option.getStf() +"'), " - + String.valueOf(option.getOptionId()) + ")\n"); + + String.valueOf(((OptionNode)option).getNumber()) + ")\n"); } } else { for (ConversationNode option : options) { @@ -151,7 +165,7 @@ public class Compiler { if (options.size() > 1) { ArrayList orderedOptions = new ArrayList<>(); for (ConversationNode unOrdered : options) { - orderedOptions.add(unOrdered.getOptionId(), unOrdered); + orderedOptions.add(((OptionNode)unOrdered).getNumber(), unOrdered); } for (ConversationNode option : orderedOptions) { bw.write(space + "options.add(ConversationOption(OutOfBand.ProsePackage('@conversation/" + option.getStf() +"'), " + options.indexOf(option) + ")\n"); diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationConnectProvider.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationConnectProvider.java index 3812198..939de78 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationConnectProvider.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationConnectProvider.java @@ -1,6 +1,8 @@ package com.projectswg.tools.csc.conversationeditor; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; +import com.projectswg.tools.csc.conversationeditor.nodes.EndNode; import java.awt.Point; import javax.swing.JOptionPane; import org.netbeans.api.visual.action.ConnectProvider; @@ -42,34 +44,17 @@ public class ConversationConnectProvider implements ConnectProvider { @Override public void createConnection(Widget source, Widget target) { if (source instanceof ConversationWidget && target instanceof ConversationWidget) { - if (((ConversationWidget)source).getAttachedNode().isEndNode()) { + if (((ConversationWidget)source).getAttachedNode() instanceof EndNode) { JOptionPane.showMessageDialog(null, "Cannot attach end conversation node to responses/options!", "Conversation Script Creator", JOptionPane.INFORMATION_MESSAGE); return; } ConversationNode cSource = ((ConversationWidget) source).getAttachedNode(); ConversationNode cTarget = ((ConversationWidget) target).getAttachedNode(); - if (cSource.isOption()) { - if (cTarget.isOption()) - return; - - else if (cTarget.isStartNode()) - return; - - } else if (cSource.isStartNode()) { - if (cTarget.isEndNode()) - return; - } else if (cSource.isEndNode()) { + // TODO: messages for each linking type + if (!cSource.doesLink(cTarget)) return; - - } else { // Response nodes - if (cTarget.isEndNode()) - return; - - else if (cTarget.isStartNode()) - return; - } - + /* This won't work for preventing linking to same node 2x's. Need to find another way :( if (scene.getConnectionLayer().getChildren().size() > 0) { for (Widget widget : scene.getConnectionLayer().getChildren()) { diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationWidget.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationWidget.java index b2326b3..aa75d94 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationWidget.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationWidget.java @@ -1,5 +1,6 @@ package com.projectswg.tools.csc.conversationeditor; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; import java.awt.Point; import java.beans.PropertyVetoException; @@ -21,25 +22,14 @@ public class ConversationWidget extends IconNodeWidget implements LookupListener private final ExplorerManager mgr; private boolean selected; - public ConversationWidget(SceneView scene, final ExplorerManager mgr, final ConversationNode node, boolean endConversation) { + public ConversationWidget(SceneView scene, final ExplorerManager mgr, final ConversationNode node) { super(scene.getScene()); this.attachedNode = node; this.mgr = mgr; - if (node.isEndNode()) { - setLabel(node.getStf()); - setImage(ImageUtilities.loadImage("com/projectswg/tools/csc/conversationeditor/conversation_end.png")); - } else { - setLabel(node.getStf()); - - if (node.isStartNode()) { - setImage(ImageUtilities.loadImage("com/projectswg/tools/csc/conversationeditor/conversation_begin.png")); - } else { - setImage(node.isOption() ? ImageUtilities.loadImage("com/projectswg/tools/csc/conversationeditor/conversation_option.png") - : ImageUtilities.loadImage("com/projectswg/tools/csc/conversationeditor/conversation_response.png")); - } - } + setLabel(node.getStf()); + setImage(ImageUtilities.loadImage(node.getImageStr())); // Alignment/pos/ori getLabelWidget().setAlignment(LabelWidget.Alignment.CENTER); diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/EditorTopComponent.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/EditorTopComponent.java index 3e77289..1eb772b 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/EditorTopComponent.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/EditorTopComponent.java @@ -1,7 +1,9 @@ package com.projectswg.tools.csc.conversationeditor; -import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import com.projectswg.tools.csc.conversationeditor.actions.OpenConversation; +import com.projectswg.tools.csc.conversationeditor.nodes.BeginNode; +import com.projectswg.tools.csc.conversationeditor.nodes.EndNode; import java.io.File; import javax.swing.JOptionPane; import org.netbeans.api.settings.ConvertAsProperties; @@ -122,7 +124,7 @@ public final class EditorTopComponent extends TopComponent implements ExplorerMa } public void blankSlate() { - scene.addNode(new ConversationNode("Begin Conversation", false, 0, false, true, 0)); - scene.addNode(new ConversationNode("End Conversation", false, 1, true, false, 0)); + scene.addNode(new BeginNode("sdafsdf", 0)); + scene.addNode(new EndNode("asdfasdfsaf", 1)); } } diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvEnd.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvEnd.java index dc2de9a..1e44c97 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvEnd.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvEnd.java @@ -5,9 +5,9 @@ */ package com.projectswg.tools.csc.conversationeditor.actions; -import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; import com.projectswg.tools.csc.conversationeditor.EditorTopComponent; -import com.projectswg.tools.csc.conversationeditor.SceneView; +import com.projectswg.tools.csc.conversationeditor.nodes.EndNode; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import org.openide.awt.ActionID; @@ -45,7 +45,7 @@ public final class NewConvEnd implements ActionListener { return; int id = scene.getNextId(); - scene.addNode(new ConversationNode("New End Conversation " + String.valueOf(id), false, id, true, false, 0)); + scene.addNode(new EndNode("New End Conversation " + String.valueOf(id), id)); scene.validate(); } diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvOption.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvOption.java index cf603e2..50a20b1 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvOption.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvOption.java @@ -1,8 +1,8 @@ package com.projectswg.tools.csc.conversationeditor.actions; -import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; import com.projectswg.tools.csc.conversationeditor.EditorTopComponent; -import com.projectswg.tools.csc.conversationeditor.SceneView; +import com.projectswg.tools.csc.conversationeditor.nodes.OptionNode; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import org.openide.awt.ActionID; @@ -40,7 +40,7 @@ public final class NewConvOption implements ActionListener { return; int id = scene.getNextId(); - scene.addNode(new ConversationNode("New Conversation Option " + String.valueOf(id), true, id, false, false, 0)); + scene.addNode(new OptionNode("New Conversation Option " + String.valueOf(id), id)); scene.validate(); } diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvResponse.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvResponse.java index 4e4a54c..9da8fad 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvResponse.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/NewConvResponse.java @@ -5,9 +5,9 @@ */ package com.projectswg.tools.csc.conversationeditor.actions; -import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; import com.projectswg.tools.csc.conversationeditor.EditorTopComponent; -import com.projectswg.tools.csc.conversationeditor.SceneView; +import com.projectswg.tools.csc.conversationeditor.nodes.ResponseNode; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import org.openide.awt.ActionID; @@ -45,7 +45,7 @@ public final class NewConvResponse implements ActionListener { return; int id = scene.getNextId(); - scene.addNode(new ConversationNode("New Conversation Response " + String.valueOf(id), false, id, false, false, 0)); + scene.addNode(new ResponseNode("New Conversation Response " + String.valueOf(id), id)); scene.validate(); } } diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/OpenConversation.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/OpenConversation.java index f401a06..79bbe01 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/OpenConversation.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/OpenConversation.java @@ -1,8 +1,8 @@ package com.projectswg.tools.csc.conversationeditor.actions; import com.projectswg.tools.csc.conversationeditor.EditorTopComponent; -import com.projectswg.tools.csc.conversationeditor.SceneSaver; -import com.projectswg.tools.csc.conversationeditor.SceneView; +import com.projectswg.tools.csc.conversationeditor.scene.SceneSaver; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import com.projectswg.tools.csc.conversationeditor.wizard.CompileWizardAction; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/SaveConversation.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/SaveConversation.java index 26d2450..df70ecb 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/SaveConversation.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/SaveConversation.java @@ -6,8 +6,8 @@ package com.projectswg.tools.csc.conversationeditor.actions; import com.projectswg.tools.csc.conversationeditor.EditorTopComponent; -import com.projectswg.tools.csc.conversationeditor.SceneSaver; -import com.projectswg.tools.csc.conversationeditor.SceneView; +import com.projectswg.tools.csc.conversationeditor.scene.SceneSaver; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/TrashConvNode.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/TrashConvNode.java index f100c8d..41aa2ce 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/TrashConvNode.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/actions/TrashConvNode.java @@ -5,16 +5,14 @@ */ package com.projectswg.tools.csc.conversationeditor.actions; -import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; import com.projectswg.tools.csc.conversationeditor.ConversationWidget; import com.projectswg.tools.csc.conversationeditor.EditorTopComponent; -import com.projectswg.tools.csc.conversationeditor.SceneView; +import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; +import com.projectswg.tools.csc.conversationeditor.scene.SceneView; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; -import java.util.Map; import javax.swing.SwingUtilities; import org.netbeans.api.visual.widget.ConnectionWidget; import org.netbeans.api.visual.widget.Widget; diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/BeginNode.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/BeginNode.java new file mode 100644 index 0000000..0d1d95d --- /dev/null +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/BeginNode.java @@ -0,0 +1,23 @@ +package com.projectswg.tools.csc.conversationeditor.nodes; + +public class BeginNode extends ConversationNode { + + public BeginNode(String stf, int id) { + super(getImgDirectory() + "conversation_begin.png", ConversationNode.BEGIN, stf, id); + } + + @Override + public boolean doesLink(ConversationNode target) { + switch (target.getType()) { + case ConversationNode.OPTION: + return true; + case ConversationNode.RESPONSE: + return false; + case ConversationNode.END: + return false; + case ConversationNode.BEGIN: + return false; + } + return true; + } +} diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/ConversationNode.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/ConversationNode.java index a2dfd24..9ba6444 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/ConversationNode.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/ConversationNode.java @@ -1,6 +1,7 @@ package com.projectswg.tools.csc.conversationeditor.nodes; import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.PropertySupport; @@ -8,169 +9,121 @@ import org.openide.nodes.Sheet; import org.openide.util.Lookup; public class ConversationNode extends AbstractNode implements Lookup.Provider { - private int id; - private int optionId; - private String displayText; + + private final int id; private String stf; - private boolean option; private boolean locked; - private boolean compiled; - private boolean endNode; - private boolean startNode; - public ConversationNode(String stf, boolean isOption, int id, boolean isEndNode, boolean isStartNode, int optionId) { + private final Sheet sheet; + private final String imageStr; + private final String type; + + public static final String OPTION = "Option"; + public static final String RESPONSE = "Response"; + public static final String END = "End"; + public static final String BEGIN = "Begin"; + + HashMap specificAttrs = new HashMap<>(); + + public ConversationNode(String imageStr, String type, String stf, int id) { super(Children.LEAF); - this.stf = stf; - this.option = isOption; - this.displayText = ""; - this.endNode = isEndNode; - this.startNode = isStartNode; - this.optionId = optionId; this.id = id; - - // Properties Window - if (!isStartNode) - setDisplayName("Conversation " + ((isOption) ? "Option " + String.valueOf(id) : ((isEndNode) ? "End" : "Response " + String.valueOf(id)))); - else - setDisplayName("Begin Conversation Node"); - - setShortDescription("Properties for this Conversation Node"); - } - - public String getStf() { - return stf; - } - - public void setStf(String stf) { - firePropertyChange("stf", this.stf, stf); this.stf = stf; - } + this.imageStr = imageStr; + this.sheet = super.createSheet(); + + Sheet.Set properties = Sheet.createPropertiesSet(); - public String getDisplayText() { - return displayText; - } - - public void setDisplayText(String displayText) { - firePropertyChange("display", this.displayText, displayText); - this.displayText = displayText; + properties.setDisplayName("General"); + properties.setShortDescription("Basic properties for all conversation nodes."); + + properties.put(new IdProperty(this)); + properties.put(new StfProperty(this)); + properties.put(new LockedProperty(this)); + + sheet.put(properties); + + this.type = type; + + this.setDisplayName(stf); } - public boolean isOption() { - return option; - } - - public void setOption(boolean option) { - this.option = option; - } - - public boolean isLocked() { - return locked; - } - - public void setLocked(boolean locked) { - this.locked = locked; - } - - public int getId() { + public final int getId() { return id; } - public void setId(int id) { - this.id = id; + public final String getStf() { + return stf; } - public boolean isCompiled() { - return compiled; - } - - public void setCompiled(boolean compiled) { - this.compiled = compiled; + public final void setStf(String stf) { + this.stf = stf; } - public boolean isEndNode() { - return endNode; + public final boolean isLocked() { + return locked; + } + + public final void setLocked(boolean isLocked) { + this.locked = isLocked; + } + + public final String getImageStr() { + return imageStr; + } + + public final String getType() { + return type; + } + + public final void addNodeProperties(Sheet.Set properties) { + sheet.put(properties); } - public void setEndNode(boolean endNode) { - this.endNode = endNode; - } - - public boolean isStartNode() { - return this.startNode; - } - - public void setStartNode(boolean startNode) { - this.startNode = startNode; - } - - public int getOptionId() { - return this.optionId; - } - - public void setOptionId(int optionId) { - this.optionId = optionId; + public boolean doesLink(ConversationNode target) { + return true; } @Override - protected Sheet createSheet() { - Sheet sheet = super.createSheet(); - Sheet.Set set = Sheet.createPropertiesSet(); - - set.put(new IdProperty(this)); - set.put(new StfProperty(this)); - set.put(new DisplayProperty(this)); - if (!endNode) { - set.put(new TypeProperty(this)); - - if (option) { - set.put(new OptionIdProperty(this)); - } - } - set.put(new LockedProperty(this)); - - sheet.put(set); + protected final Sheet createSheet() { return sheet; } + + public final static String getImgDirectory() { + return "com/projectswg/tools/csc/conversationeditor/nodes/imgs/"; + } + + public final Object addSpecificAttribute(String name, Object value) { + return specificAttrs.put(name, value); + } + + public HashMap getAttributes() { + return specificAttrs; + } } -class OptionIdProperty extends PropertySupport.ReadWrite { - - private final ConversationNode node; - - public OptionIdProperty(ConversationNode node) { - super("optionId", Integer.class, "Option ID", "ID used for displaying the order of this option in relation to the response (what option should show first in" - + "list of options)"); - this.node = node; - } - - @Override - public Integer getValue() throws IllegalAccessException, InvocationTargetException { - return node.getOptionId(); - } - - @Override - public void setValue(Integer val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - node.setOptionId(val); - } - -} - -class IdProperty extends PropertySupport.ReadOnly { +final class LockedProperty extends PropertySupport.ReadWrite { private final ConversationNode node; - public IdProperty(ConversationNode node) { - super("id", Integer.class, "Id", "Conversation Node Id"); + public LockedProperty(ConversationNode node) { + super("locked", Boolean.class, "Locked", "Determines if this node can be moved."); this.node = node; } @Override - public Integer getValue() throws IllegalAccessException, InvocationTargetException { - return node.getId(); + public Boolean getValue() throws IllegalAccessException, InvocationTargetException { + return node.isLocked(); + } + + @Override + public void setValue(Boolean val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + node.setLocked(val); } } -class StfProperty extends PropertySupport.ReadWrite { + +final class StfProperty extends PropertySupport.ReadWrite { private final ConversationNode node; @@ -191,62 +144,16 @@ class StfProperty extends PropertySupport.ReadWrite { } } -class TypeProperty extends PropertySupport.ReadOnly { - +final class IdProperty extends PropertySupport.ReadOnly { private final ConversationNode node; - - public TypeProperty(ConversationNode node) { - super("option", Boolean.class, "Option", "The conversation node is a response or a option"); - this.node = node; - } - - @Override - public Boolean getValue() throws IllegalAccessException, InvocationTargetException { - return node.isOption(); - } - - @Override - public void setValue(Boolean val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - node.setOption(val); - } -} -class DisplayProperty extends PropertySupport.ReadWrite { - private final ConversationNode node; - - public DisplayProperty(ConversationNode node) { - super ("display", String.class, "Text", "Optional text. This won't affect anything and can be left blank.\n" + - "You can use this for entering the value of a key from the coresponding STF for quick reference."); + public IdProperty(ConversationNode node) { + super("id", Integer.class, "Id", "Conversation Node Id"); this.node = node; } @Override - public String getValue() throws IllegalAccessException, InvocationTargetException { - return node.getDisplayText(); - } - - @Override - public void setValue(String val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - node.setDisplayText(val); - } -} - -class LockedProperty extends PropertySupport.ReadWrite { - private final ConversationNode node; - - public LockedProperty(ConversationNode node) { - super("locked", Boolean.class, "Locked", "Determines if this node can be moved."); - this.node = node; - } - - @Override - public Boolean getValue() throws IllegalAccessException, InvocationTargetException { - return node.isLocked(); - } - - @Override - public void setValue(Boolean val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - node.setLocked(val); - } - + public Integer getValue() throws IllegalAccessException, InvocationTargetException { + return node.getId(); + } } diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/EndNode.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/EndNode.java new file mode 100644 index 0000000..0cf6de0 --- /dev/null +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/EndNode.java @@ -0,0 +1,23 @@ +package com.projectswg.tools.csc.conversationeditor.nodes; + +public class EndNode extends ConversationNode { + + public EndNode(String stf, int id) { + super(getImgDirectory() + "conversation_end.png", ConversationNode.END, stf, id); + } + + @Override + public boolean doesLink(ConversationNode target) { + switch (target.getType()) { + case ConversationNode.OPTION: + return true; + case ConversationNode.RESPONSE: + return false; + case ConversationNode.END: + return false; + case ConversationNode.BEGIN: + return false; + } + return true; + } +} diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/OptionNode.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/OptionNode.java new file mode 100644 index 0000000..f1eb8c9 --- /dev/null +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/OptionNode.java @@ -0,0 +1,104 @@ +package com.projectswg.tools.csc.conversationeditor.nodes; + +import java.lang.reflect.InvocationTargetException; +import org.openide.nodes.PropertySupport; +import org.openide.nodes.Sheet; + +public class OptionNode extends ConversationNode { + + private int number; + private String displayText = ""; + + public OptionNode(String stf, int id, int optionNumber) { + super(getImgDirectory() + "conversation_option.png", ConversationNode.OPTION, stf, id); + + Sheet.Set properties = Sheet.createPropertiesSet(); + + properties.setName("optionNode"); // Name must be set or properties will not show properly + properties.setDisplayName("Conversation Option"); + properties.setShortDescription("Properties specific to Option Node"); + + properties.put(new OptionIdProperty(this)); + properties.put(new DisplayTextProperty(this)); + + addNodeProperties(properties); + + this.number = optionNumber; + } + + public OptionNode(String stf, int id) { + this(stf, id, 0); + } + + public void setNumber(int num) { + this.number = num; + } + + public int getNumber() { + return number; + } + + public void setDisplayText(String txt) { + this.displayText = txt; + } + + public String getDisplayText() { + return displayText; + } + + @Override + public boolean doesLink(ConversationNode target) { + switch (target.getType()) { + case ConversationNode.OPTION: + return false; + case ConversationNode.RESPONSE: + return true; + case ConversationNode.END: + return true; + case ConversationNode.BEGIN: + return false; + } + return true; + } +} + +class OptionIdProperty extends PropertySupport.ReadWrite { + + private final OptionNode node; + + public OptionIdProperty(OptionNode node) { + super("optionId", Integer.class, "Option ID", "ID used for displaying the order of this option in relation to the response (what option should show first in" + + "list of options)"); + this.node = node; + } + + @Override + public Integer getValue() throws IllegalAccessException, InvocationTargetException { + return node.getNumber(); + } + + @Override + public void setValue(Integer val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + node.setNumber(val); + } +} + +class DisplayTextProperty extends PropertySupport.ReadWrite { + + private final OptionNode node; + + public DisplayTextProperty(OptionNode node) { + super("displayTxt", String.class, "Display Text", "Text displayed in comment for this node at compile time"); + this.node = node; + } + + @Override + public String getValue() throws IllegalAccessException, InvocationTargetException { + return node.getDisplayText(); + } + + @Override + public void setValue(String val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + node.setDisplayText(val); + } +} diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/ResponseNode.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/ResponseNode.java new file mode 100644 index 0000000..13e126e --- /dev/null +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/ResponseNode.java @@ -0,0 +1,23 @@ +package com.projectswg.tools.csc.conversationeditor.nodes; + +public class ResponseNode extends ConversationNode { + + public ResponseNode(String stf, int id) { + super(getImgDirectory() + "conversation_response.png", ConversationNode.RESPONSE, stf, id); + } + + @Override + public boolean doesLink(ConversationNode target) { + switch (target.getType()) { + case ConversationNode.OPTION: + return true; + case ConversationNode.RESPONSE: + return false; + case ConversationNode.END: + return false; + case ConversationNode.BEGIN: + return false; + } + return true; + } +} diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/conversation_begin.png b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/imgs/conversation_begin.png similarity index 100% rename from ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/conversation_begin.png rename to ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/imgs/conversation_begin.png diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/conversation_end.png b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/imgs/conversation_end.png similarity index 100% rename from ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/conversation_end.png rename to ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/imgs/conversation_end.png diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/conversation_option.png b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/imgs/conversation_option.png similarity index 100% rename from ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/conversation_option.png rename to ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/imgs/conversation_option.png diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/conversation_response.png b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/imgs/conversation_response.png similarity index 100% rename from ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/conversation_response.png rename to ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/nodes/imgs/conversation_response.png diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/SceneSaver.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/scene/SceneSaver.java similarity index 88% rename from ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/SceneSaver.java rename to ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/scene/SceneSaver.java index 49eff7a..05b21aa 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/SceneSaver.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/scene/SceneSaver.java @@ -1,6 +1,11 @@ -package com.projectswg.tools.csc.conversationeditor; +package com.projectswg.tools.csc.conversationeditor.scene; +import com.projectswg.tools.csc.conversationeditor.ConversationWidget; +import com.projectswg.tools.csc.conversationeditor.nodes.BeginNode; import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; +import com.projectswg.tools.csc.conversationeditor.nodes.EndNode; +import com.projectswg.tools.csc.conversationeditor.nodes.OptionNode; +import com.projectswg.tools.csc.conversationeditor.nodes.ResponseNode; import java.awt.Point; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -33,6 +38,7 @@ public class SceneSaver { private static final String LOCKED = "locked"; private static final String STF = "stf"; private static final String OPTION_ID = "optionId"; + private static final String TEXT = "txt"; private static final String VERSION_VALUE_1 = "1.0"; // NOI18N @@ -60,14 +66,7 @@ public class SceneSaver { if (location != null) { Node dataXMLNode = file.createElement(NODE_NODE); - if (node.isOption()) - setAttribute(file, dataXMLNode, TYPE, "option"); - else if (!node.isEndNode() && !node.isStartNode()) - setAttribute(file, dataXMLNode, TYPE, "response"); - else if (node.isEndNode()) - setAttribute(file, dataXMLNode, TYPE, "end"); - else - setAttribute(file, dataXMLNode, TYPE, "begin"); + setAttribute(file, dataXMLNode, TYPE, node.getType()); setAttribute(file, dataXMLNode, TARGETS, getTargets(conversationLinks, node)); @@ -76,7 +75,10 @@ public class SceneSaver { setAttribute(file, dataXMLNode, Y_NODE, Integer.toString(location.y)); setAttribute(file, dataXMLNode, LOCKED, Boolean.toString(node.isLocked())); setAttribute(file, dataXMLNode, STF, node.getStf()); - setAttribute(file, dataXMLNode, OPTION_ID, Integer.toString(node.getOptionId())); + + for (HashMap.Entry entry : node.getAttributes().entrySet()) { + setAttribute(file, dataXMLNode, entry.getKey(), entry.getValue().toString()); + } sceneXMLNode.appendChild(dataXMLNode); } @@ -135,21 +137,22 @@ public class SceneSaver { String targets = getAttributeValue(node, TARGETS); String stf = getAttributeValue(node, STF); String type = getAttributeValue(node, TYPE); + String txt = getAttributeValue(node, TEXT); ConversationWidget widget = null; // ConversationNode(String stf, boolean isOption, int id, boolean isEndNode, boolean isStartNode, int optionId) switch (type) { - case "option": - widget = (ConversationWidget) scene.addNode(new ConversationNode(stf, true, nodeID, false, false, optionId)); + case ConversationNode.OPTION: + widget = (ConversationWidget) scene.addNode(new OptionNode(stf, nodeID, optionId)); break; - case "response": - widget = (ConversationWidget) scene.addNode(new ConversationNode(stf, false, nodeID, false, false, optionId)); + case ConversationNode.RESPONSE: + widget = (ConversationWidget) scene.addNode(new ResponseNode(stf, nodeID)); break; - case "begin": - widget = (ConversationWidget) scene.addNode(new ConversationNode(stf, false, nodeID, false, true, optionId)); + case ConversationNode.BEGIN: + widget = (ConversationWidget) scene.addNode(new BeginNode(stf, nodeID)); break; - case "end": - widget = (ConversationWidget) scene.addNode(new ConversationNode(stf, false, nodeID, true, false, optionId)); + case ConversationNode.END: + widget = (ConversationWidget) scene.addNode(new EndNode(stf, nodeID)); break; } diff --git a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/SceneView.java b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/scene/SceneView.java similarity index 95% rename from ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/SceneView.java rename to ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/scene/SceneView.java index de9de49..4b7a0c1 100644 --- a/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/SceneView.java +++ b/ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/scene/SceneView.java @@ -1,5 +1,8 @@ -package com.projectswg.tools.csc.conversationeditor; +package com.projectswg.tools.csc.conversationeditor.scene; +import com.projectswg.tools.csc.conversationeditor.ConversationLookFeel; +import com.projectswg.tools.csc.conversationeditor.ConversationWidget; +import com.projectswg.tools.csc.conversationeditor.EditorTopComponent; import com.projectswg.tools.csc.conversationeditor.nodes.ConversationNode; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -49,7 +52,7 @@ public class SceneView extends GraphScene{ @Override protected Widget attachNodeWidget(ConversationNode n) { - final ConversationWidget widget = new ConversationWidget(this, mgr, n, n.isEndNode()); + final ConversationWidget widget = new ConversationWidget(this, mgr, n); widget.getActions().addAction(createObjectHoverAction()); n.addPropertyChangeListener(new PropertyChangeListener() {