Temporary commit

This commit is contained in:
Zukero
2016-10-14 17:13:03 +02:00
parent c18ff9d2b4
commit 32711449b2
9 changed files with 587 additions and 81 deletions

View File

@@ -44,6 +44,7 @@ import com.gpl.rpg.atcontentstudio.model.maps.Worldmap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.saves.SavedGamesSet;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
import com.gpl.rpg.atcontentstudio.utils.FileUtils;
@@ -692,6 +693,20 @@ public class Project implements ProjectTreeNode, Serializable {
}
}
public int getWriterSketchCount() {
return createdContent.writerModeDataSet.getChildCount();
}
public WriterModeData getWriterSketch(String id) {
return createdContent.writerModeDataSet.getWriterSketch(id);
}
public WriterModeData getWriterSketch(int index) {
if (index < createdContent.writerModeDataSet.getChildCount()) {
return createdContent.writerModeDataSet.get(index);
}
return null;
}
@Override
public Project getProject() {
@@ -842,6 +857,16 @@ public class Project implements ProjectTreeNode, Serializable {
fireElementAdded(node, getNodeIndex(node));
}
public void createWriterSketch(WriterModeData node) {
node.writable = true;
createdContent.writerModeDataSet.add(node);
node.state = GameDataElement.State.created;
node.link();
fireElementAdded(node, getNodeIndex(node));
}
@Override
public GameDataSet getDataSet() {
@@ -1030,6 +1055,7 @@ public class Project implements ProjectTreeNode, Serializable {
}

View File

@@ -1,47 +1,54 @@
package com.gpl.rpg.atcontentstudio.model.tools;
import java.awt.Image;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.swing.tree.TreeNode;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.model.GameDataElement.State;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData.WriterDialogue;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class WriterModeData extends GameDataElement {
public WriterModeDataSet parent;
private static final long serialVersionUID = -7062544089063979696L;
//Available from state init.
public File jsonFile;
public Image npcIcon;
public String sketchName;
public List<String> rootsId = new LinkedList<String>();
public List<WriterDialogue> roots = new LinkedList<WriterDialogue>();
public WriterDialogue begin;
public Map<String, WriterDialogue> nodesById = new LinkedHashMap<String, WriterDialogue>();
public Map<String, WriterDialogue> dialogueThreads = new LinkedHashMap<String, WriterDialogue>();
public Map<String, Integer> threadsNextIndex = new LinkedHashMap<String, Integer>();
public WriterModeData(WriterModeDataSet parent, String id_prefix){
this.parent = parent;
this.begin = new WriterDialogue();
begin.id_prefix = id_prefix;
begin.index = getNextIndex(id_prefix);
begin.text = "";
public WriterModeData(String id_prefix){
this.id = id_prefix;
}
public WriterModeData(WriterModeDataSet parent, Map jsonObj) {
public WriterModeData(WriterModeDataSet parent, @SuppressWarnings("rawtypes") Map jsonObj) {
this.parent = parent;
this.begin = new WriterDialogue(jsonObj);
this.id = begin.id_prefix;
this.state = State.parsed;
}
@@ -60,14 +67,17 @@ public class WriterModeData extends GameDataElement {
public String text;
public abstract String getTitle();
@SuppressWarnings("rawtypes")
public abstract Map toJson();
}
public class WriterDialogue extends WriterNode {
public String id;
public String id_prefix;
public int index;
public List<WriterReply> replies = new LinkedList<WriterReply>();
public List<WriterReply> parents = new LinkedList<WriterReply>();
public WriterDialogue() {}
@@ -87,9 +97,11 @@ public class WriterModeData extends GameDataElement {
@Override
public Map toJson() {
Map dialogueJson = new HashMap();
dialogueJson.put("id", id);
dialogueJson.put("id_prefix", id_prefix);
dialogueJson.put("index", index);
dialogueJson.put("text", text);
dialogueJson.put("special", isSpecial());
if (!replies.isEmpty()) {
List repliesJson = new ArrayList();
for (WriterReply reply : replies) {
@@ -100,26 +112,55 @@ public class WriterModeData extends GameDataElement {
return dialogueJson;
}
@SuppressWarnings("rawtypes")
public WriterDialogue(Map json) {
this.id = (String) json.get("id");
this.index = Integer.parseInt((String) json.get("index"));
this.id_prefix = (String) json.get("id_prefix");
this.text = (String) json.get("text");
List repliesJson = (List) json.get("replies");
for (Object rJson : repliesJson) {
if (Boolean.parseBoolean((String)((Map)rJson).get("special"))) {
//TODO Check different cases. But there are none currently.
this.replies.add(new EmptyReply(this, ((Map)rJson)));
}
this.replies.add(new WriterReply(this, (Map)rJson));
}
}
public boolean isSpecial() {return false;}
}
public class SpecialDialogue extends WriterDialogue {}
public class SelectorDialogue extends SpecialDialogue {}
public class ShopDialogue extends SpecialDialogue {}
public class FightDialogue extends SpecialDialogue {}
public class EndDialogue extends SpecialDialogue {}
public abstract class SpecialDialogue extends WriterDialogue {
public boolean isSpecial() {return true;}
public abstract SpecialDialogue duplicate();
}
public class SelectorDialogue extends SpecialDialogue {
public SpecialDialogue duplicate() {return new SelectorDialogue();}
}
public class ShopDialogue extends SpecialDialogue {
public static final String id = "S";
public SpecialDialogue duplicate() {return new ShopDialogue();}
}
public class FightDialogue extends SpecialDialogue {
public static final String id = "F";
public SpecialDialogue duplicate() {return new FightDialogue();}
}
public class EndDialogue extends SpecialDialogue {
public static final String id = "X";
public SpecialDialogue duplicate() {return new EndDialogue();}
}
public class RemoveNPCDialogue extends SpecialDialogue {
public static final String id = "R";
public SpecialDialogue duplicate() {return new RemoveNPCDialogue();}
}
public class WriterReply extends WriterNode {
public WriterDialogue parent;
public String next_dialogue_id;
public WriterDialogue next_dialogue;
public WriterReply() {}
@@ -130,11 +171,12 @@ public class WriterModeData extends GameDataElement {
parent.replies.add(this);
}
@SuppressWarnings("rawtypes")
public WriterReply(WriterDialogue parent, Map json) {
this.parent = parent;
this.text = (String) json.get("text");
if (json.containsKey("next_dialogue")) {
next_dialogue = new WriterDialogue((Map) json.get("next_dialogue"));
if (json.containsKey("next_dialogue_id")) {
next_dialogue_id = (String) json.get("next_dialogue_id");
}
}
@@ -148,25 +190,39 @@ public class WriterModeData extends GameDataElement {
public Map toJson() {
Map replyJson = new HashMap();
replyJson.put("text", text);
replyJson.put("special", isSpecial());
if (next_dialogue != null) {
replyJson.put("next_dialogue", next_dialogue.toJson());
replyJson.put("next_dialogue_id", next_dialogue.id);
}
return replyJson;
}
public boolean isSpecial() {return false;}
}
public class SpecialReply extends WriterReply {
public boolean isSpecial() {return true;}
public SpecialReply(WriterDialogue parent) {
super(parent);
}
public SpecialReply(WriterDialogue parent, Map json) {
super(parent, json);
}
}
public class EmptyReply extends SpecialReply {
public EmptyReply(WriterDialogue parent) {
super(parent);
text="N";
}
public EmptyReply(WriterDialogue parent, Map json) {
super(parent, json);
text="N";
}
}
@@ -174,7 +230,7 @@ public class WriterModeData extends GameDataElement {
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+begin.id_prefix;
return (this.state == State.modified ? "*" : "")+id;
}
@Override
public Project getProject() {
@@ -201,15 +257,7 @@ public class WriterModeData extends GameDataElement {
public GameDataSet getDataSet() {
return null;
}
@Override
public void parse() {
// TODO
}
@Override
public void link() {
//Useless here.
}
@Override
public GameDataElement clone() {
//TODO
@@ -227,11 +275,12 @@ public class WriterModeData extends GameDataElement {
@Override
public void save() {
parent.save();
((WriterModeDataSet)this.getParent()).save(this.jsonFile);
}
@Override
public List<SaveEvent> attemptSave() {
List<SaveEvent> events = parent.attemptSave();
List<SaveEvent> events = ((WriterModeDataSet)parent).attemptSave();
if (events == null || events.isEmpty()) {
return null;
}
@@ -247,5 +296,118 @@ public class WriterModeData extends GameDataElement {
return begin.toJson();
}
@SuppressWarnings("rawtypes")
public void parse() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(jsonFile);
List gameDataElements = (List) parser.parse(reader);
for (Object obj : gameDataElements) {
Map jsonObj = (Map)obj;
String id = (String) jsonObj.get("id");
if (id != null && id.equals(this.id )) {
this.parse(jsonObj);
this.state = State.parsed;
break;
}
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("rawtypes")
public void parse(Map json) {
this.id = (String) json.get("id");
this.sketchName = (String) json.get("name");
List jsonRootsId = (List) json.get("roots_id");
if (jsonRootsId != null) {
for (Object jsonRootId : jsonRootsId) {
rootsId.add((String) jsonRootId);
}
}
List jsonDialogues = (List) json.get("dialogues");
if (jsonDialogues != null) {
for (Object jsonDialogue : jsonDialogues) {
WriterDialogue dialogue = new WriterDialogue((Map)jsonDialogue);
nodesById.put(dialogue.id, dialogue);
}
}
this.state = State.parsed;
}
@Override
public void link() {
if (this.state == State.created) {
this.begin = new WriterDialogue();
begin.id_prefix = id;
begin.index = getNextIndex(id);
begin.text = "";
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.parsed) {
for (WriterDialogue dialogue : nodesById.values()) {
if (dialogue.replies == null) continue;
for (WriterReply reply : dialogue.replies) {
if (reply.next_dialogue_id != null) {
if (isSpecial(reply.next_dialogue_id)) {
reply.next_dialogue = getSpecial(reply.next_dialogue_id);
} else {
reply.next_dialogue = nodesById.get(reply.next_dialogue_id);
}
}
}
}
for (String rootId : rootsId) {
roots.add(nodesById.get(rootId));
}
} else if (this.state == State.linked) {
//Already linked.
return;
}
this.state = State.linked;
}
public boolean isSpecial(String id) {
if (id == null) return false;
if (ShopDialogue.id.equals(id)) return true;
if (FightDialogue.id.equals(id)) return true;
if (EndDialogue.id.equals(id)) return true;
if (RemoveNPCDialogue.id.equals(id)) return true;
return false;
}
public SpecialDialogue getSpecial(String id) {
if (id == null) return null;
if (ShopDialogue.id.equals(id)) return new ShopDialogue();
if (FightDialogue.id.equals(id)) return new FightDialogue();
if (EndDialogue.id.equals(id)) return new EndDialogue();
if (RemoveNPCDialogue.id.equals(id)) return new RemoveNPCDialogue();
return null;
}
}

View File

@@ -52,7 +52,7 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
@Override
public TreeNode getChildAt(int childIndex) {
return null;
return writerModeDataList.get(childIndex);
}
@Override
@@ -155,10 +155,12 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
@SuppressWarnings("rawtypes")
public void save() {
public void save(File jsonFile) {
List<Map> dataToSave = new LinkedList<Map>();
for (WriterModeData data : writerModeDataList) {
dataToSave.add(data.toJson());
if (data.jsonFile.equals(jsonFile)) {
dataToSave.add(data.toJson());
}
}
if (dataToSave.isEmpty() && writerFile.exists()) {
if (writerFile.delete()) {
@@ -230,4 +232,30 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
}
}
public WriterModeData getWriterSketch(String id) {
for (WriterModeData sketch : writerModeDataList) {
if (id.equals(sketch.id)){
return sketch;
}
}
return null;
}
public WriterModeData get(int index) {
return writerModeDataList.get(index);
}
public void add(WriterModeData node) {
ProjectTreeNode higherEmptyParent = this;
while (higherEmptyParent != null) {
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode)higherEmptyParent.getParent()).isEmpty()) higherEmptyParent = (ProjectTreeNode)higherEmptyParent.getParent();
else break;
}
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;
writerModeDataList.add(node);
node.parent = this;
if (higherEmptyParent != null) higherEmptyParent.notifyCreated();
else node.notifyCreated();
}
}

View File

@@ -22,6 +22,7 @@ import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.saves.SavedGame;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.ActorConditionEditor;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.DialogueEditor;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.DroplistEditor;
@@ -33,6 +34,7 @@ import com.gpl.rpg.atcontentstudio.ui.map.TMXMapEditor;
import com.gpl.rpg.atcontentstudio.ui.map.WorldMapEditor;
import com.gpl.rpg.atcontentstudio.ui.saves.SavedGameEditor;
import com.gpl.rpg.atcontentstudio.ui.sprites.SpritesheetEditor;
import com.gpl.rpg.atcontentstudio.ui.tools.writermode.WriterModeEditor;
import com.jidesoft.swing.JideTabbedPane;
public class EditorsArea extends JPanel {
@@ -155,6 +157,15 @@ public class EditorsArea extends JPanel {
openEditor(new WorldMapEditor(node));
}
public void openEditor(WriterModeData node) {
if (editors.containsKey(node)) {
tabHolder.setSelectedComponent(editors.get(node));
return;
}
node.link();
openEditor(new WriterModeEditor(node));
}
public void closeEditor(ProjectTreeNode node) {
if (editors.containsKey(node)) {
closeEditor(editors.get(node));

View File

@@ -37,6 +37,7 @@ import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.saves.SavedGame;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData;
import com.jidesoft.swing.TreeSearchable;
public class ProjectsTree extends JPanel {
@@ -579,6 +580,8 @@ public class ProjectsTree extends JPanel {
ATContentStudio.frame.openEditor((TMXMap)node);
} else if (node instanceof WorldmapSegment) {
ATContentStudio.frame.openEditor((WorldmapSegment)node);
} else if (node instanceof WriterModeData) {
ATContentStudio.frame.openEditor((WriterModeData)node);
} else if (node instanceof SavedGame) {
if (konamiCodeEntered) {
ATContentStudio.frame.openEditor((SavedGame)node);

View File

@@ -34,6 +34,7 @@ import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.saves.SavedGame;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData;
public class StudioFrame extends JFrame {
@@ -212,6 +213,10 @@ public class StudioFrame extends JFrame {
editors.openEditor(node);
}
public void openEditor(WriterModeData node) {
editors.openEditor(node);
}
public void closeEditor(ProjectTreeNode node) {
editors.closeEditor(node);
}

View File

@@ -322,15 +322,22 @@ public class WorkspaceActions {
public ATCSAction testWriter = new ATCSAction("Create dialogue sketch", "Test the Writer Mode"){
public void actionPerformed(ActionEvent e) {
if (selectedNode == null || selectedNode.getProject() == null) return;
WriterModeData data = new WriterModeData(selectedNode.getProject().createdContent.writerModeDataSet, "test_");
JFrame frame = new JFrame("Writer Mode tests");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(new WriterModeEditor(data), BorderLayout.CENTER);
frame.setMinimumSize(new Dimension(250, 200));
frame.pack();
frame.setVisible(true);
new WriterSketchCreationWizard(selectedNode.getProject()).setVisible(true);
//
//
// if (selectedNode == null || selectedNode.getProject() == null) return;
// WriterModeData data = new WriterModeData(selectedNode.getProject().createdContent.writerModeDataSet, "test_");
// JFrame frame = new JFrame("Writer Mode tests");
// frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// frame.getContentPane().setLayout(new BorderLayout());
// frame.getContentPane().add(new WriterModeEditor(data), BorderLayout.CENTER);
// frame.setMinimumSize(new Dimension(250, 200));
// frame.pack();
// frame.setVisible(true);
};
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
}
};
List<ATCSAction> actions = new ArrayList<WorkspaceActions.ATCSAction>();

View File

@@ -0,0 +1,140 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.GameDataElement.State;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData;
import com.gpl.rpg.atcontentstudio.ui.JSONCreationWizard.DataType;
import com.jidesoft.swing.JideBoxLayout;
public class WriterSketchCreationWizard extends JDialog {
private WriterModeData creation = null;
final JLabel message;
final JTextField idField;
final JButton ok;
final Project proj;
public WriterSketchCreationWizard(Project proj) {
super(ATContentStudio.frame);
this.proj = proj;
JPanel pane = new JPanel();
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.PAGE_AXIS, 6));
pane.add(new JLabel("Create a new game data element."), JideBoxLayout.FIX);
message = new JLabel("Select a data type below:");
pane.add(message, JideBoxLayout.FIX);
final JPanel idPane = new JPanel();
idPane.setLayout(new BorderLayout());
JLabel idLabel = new JLabel("Dialogue ID prefix: ");
idPane.add(idLabel, BorderLayout.WEST);
idField = new JTextField("");
idField.setEditable(true);
idPane.add(idField, BorderLayout.CENTER);
pane.add(idPane, JideBoxLayout.FIX);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new JideBoxLayout(buttonPane, JideBoxLayout.LINE_AXIS, 6));
buttonPane.add(new JPanel(), JideBoxLayout.VARY);
JButton cancel = new JButton("Cancel");
buttonPane.add(cancel, JideBoxLayout.FIX);
ok = new JButton("Ok");
buttonPane.add(ok, JideBoxLayout.FIX);
pane.add(new JPanel(), JideBoxLayout.VARY);
pane.add(buttonPane, JideBoxLayout.FIX);
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
creation = new WriterModeData(idField.getText());
WriterSketchCreationWizard.this.setVisible(false);
WriterSketchCreationWizard.this.dispose();
creation.state = State.created;
WriterSketchCreationWizard.this.proj.createWriterSketch(creation);
// notifyCreated();
ATContentStudio.frame.selectInTree(creation);
ATContentStudio.frame.openEditor(creation);
}
});
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
creation = null;
WriterSketchCreationWizard.this.setVisible(false);
WriterSketchCreationWizard.this.dispose();
}
});
DocumentListener statusUpdater = new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void changedUpdate(DocumentEvent e) {
updateStatus();
}
};
idField.getDocument().addDocumentListener(statusUpdater);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(pane, BorderLayout.CENTER);
setMinimumSize(new Dimension(350,250));
updateStatus();
pack();
Dimension sdim = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wdim = getSize();
setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
}
public void updateStatus() {
boolean trouble = false;
message.setText("<html><font color=\"#00AA00\">Looks OK to me.</font></html>");
if (idField.getText() == null || idField.getText().length() <= 0) {
message.setText("<html><font color=\"#FF0000\">Internal ID must not be empty.</font></html>");
trouble = true;
} else if (proj.getWriterSketch(idField.getText()) != null) {
message.setText("<html><font color=\"#FF0000\">An item with the same ID was already created in this project.</font></html>");
trouble = true;
}
ok.setEnabled(!trouble);
message.revalidate();
message.repaint();
}
}

View File

@@ -52,17 +52,21 @@ import prefuse.render.LabelRenderer;
import prefuse.render.NullRenderer;
import prefuse.util.ColorLib;
import prefuse.util.PrefuseLib;
import prefuse.visual.DecoratorItem;
import prefuse.visual.EdgeItem;
import prefuse.visual.VisualItem;
import prefuse.visual.expression.InGroupPredicate;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData.EmptyReply;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData.SpecialDialogue;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData.WriterDialogue;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData.WriterNode;
import com.gpl.rpg.atcontentstudio.model.tools.WriterModeData.WriterReply;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.Editor;
public class WriterModeEditor extends JPanel {
public class WriterModeEditor extends Editor {
private static final long serialVersionUID = -6591631891278528494L;
@@ -157,10 +161,10 @@ public class WriterModeEditor extends JPanel {
nFill.setDefaultColor(ColorLib.gray(255));
// ColorAction nFill = new NPCPhraseColorAction(NODES, VisualItem.FILLCOLOR);
//
ColorAction eEdges = new ColorAction(EDGES, VisualItem.STROKECOLOR);
eEdges.setDefaultColor(ColorLib.gray(100));
ColorAction eArrows = new ColorAction(EDGES, VisualItem.FILLCOLOR);
eArrows.setDefaultColor(ColorLib.gray(100));
ColorAction eEdges = new ConnectedEdgeColorAction(EDGES, VisualItem.STROKECOLOR);
// eEdges.setDefaultColor(ColorLib.gray(100));
ColorAction eArrows = new ConnectedEdgeColorAction(EDGES, VisualItem.FILLCOLOR);
// eArrows.setDefaultColor(ColorLib.gray(100));
// ColorAction eEdgesLabels = new ConnectedEdgeColorAction(EDGES_LABELS, VisualItem.TEXTCOLOR);
// StrokeAction eStroke = new EdgesStrokeAction(EDGES);
@@ -291,8 +295,8 @@ public class WriterModeEditor extends JPanel {
if (reply.next_dialogue != null) {
if (cells.get(reply.next_dialogue) == null) {
Node dNode = addDialogueNode(reply.next_dialogue);
Edge e = graph.addEdge(rNode, dNode);
Node dNode = addDialogueNode(reply.next_dialogue);
Edge e = graph.addEdge(rNode, dNode);
} else {
Node dNode = cells.get(reply.next_dialogue);
Edge e = graph.addEdge(rNode, dNode);
@@ -304,6 +308,15 @@ public class WriterModeEditor extends JPanel {
return cells.get(reply);
}
public void addEdge(WriterNode source, WriterNode target) {
if (graph.getEdge(cells.get(source), cells.get(target)) != null) return;
Edge e = graph.addEdge(cells.get(source), cells.get(target));
e.setBoolean(IS_TREE_EDGE, false);
m_vis.run("colors");
m_vis.run("layout");
}
class MyLabelRenderer extends LabelRenderer {
public MyLabelRenderer(String label) {
@@ -359,14 +372,44 @@ public class WriterModeEditor extends JPanel {
}
}
class ConnectedEdgeColorAction extends ColorAction {
final int outgoing = ColorLib.rgb(255, 100, 100);
final int incoming = ColorLib.rgb(100, 255, 100);
final int none = ColorLib.gray(100);
public ConnectedEdgeColorAction(String group, String field) {
super(group, field);
}
@Override
public int getColor(VisualItem item) {
if (item instanceof DecoratorItem) {
item = ((DecoratorItem) item).getDecoratedItem();
}
if (item instanceof EdgeItem) {
if (((EdgeItem) item).getSourceItem() != null && ((EdgeItem) item).getSourceItem().isHover()) {
return outgoing;
} else if (((EdgeItem) item).getTargetItem().isHover()) {
return incoming;
}
}
return none;
}
}
class GraphInputControl extends ControlAdapter {
@Override
public void itemClicked(VisualItem item, MouseEvent e) {
if (!edgePending) {
if (edgePending) {
WriterNode target = (WriterNode) item.get(TARGET);
lockPendingEdge(target);
} else {
if (e.getClickCount() == 1) {
if (item.get(TARGET) != null) {
prevSelected = selected;
selected = (WriterModeData.WriterNode)item.get(TARGET);
selected = (WriterNode)item.get(TARGET);
}
} else if (e.getClickCount() == 2) {
if (item.get(TARGET) != null) {
@@ -374,7 +417,7 @@ public class WriterModeEditor extends JPanel {
showEditorOnSelectedAt(e.getPoint());
}
}
}
}
}
@Override
@@ -402,7 +445,11 @@ public class WriterModeEditor extends JPanel {
} else if (event.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.ALT_DOWN_MASK, true))) {
createNextDefaultNode.actionPerformed(null);
} else if (event.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK, true))) {
createContinueTalkingNode.actionPerformed(null);
if (selected instanceof WriterDialogue) {
createContinueTalkingNode.actionPerformed(null);
} else if (selected instanceof WriterReply) {
createOtherReplyNode.actionPerformed(null);
}
}
}
@@ -446,16 +493,21 @@ public class WriterModeEditor extends JPanel {
public void startPendingEdge() {
pendingEdge = graph.addEdge(cells.get(selected), nullNode);
edgePending = true;
m_vis.run("colors");
m_vis.run("layout");
revalidate();
repaint();
if (edgePending) return;
if (selected instanceof WriterDialogue ||
(selected instanceof WriterReply && ((WriterReply)selected).next_dialogue == null )) {
pendingEdge = graph.addEdge(cells.get(selected), nullNode);
edgePending = true;
m_vis.run("colors");
m_vis.run("layout");
revalidate();
repaint();
}
}
public void stopPendingEdge() {
if (!edgePending) return;
graph.removeEdge(pendingEdge);
pendingEdge = null;
edgePending = false;
@@ -465,6 +517,35 @@ public class WriterModeEditor extends JPanel {
repaint();
}
public void lockPendingEdge(WriterNode target) {
if (selected instanceof WriterReply) {
if (target instanceof WriterDialogue && ((WriterReply)selected).next_dialogue == null) {
((WriterReply)selected).next_dialogue = (WriterDialogue) target;
stopPendingEdge();
addEdge(selected, target);
}
} else if (selected instanceof WriterDialogue) {
if (target instanceof WriterReply) {
WriterReply clone = data.new WriterReply((WriterDialogue)selected);
clone.text = ((WriterReply)target).text;
if (((WriterReply)target).next_dialogue instanceof SpecialDialogue) {
clone.next_dialogue = ((SpecialDialogue)((WriterReply)target).next_dialogue).duplicate();
} else {
clone.next_dialogue = ((WriterReply)target).next_dialogue;
}
stopPendingEdge();
addReplyNode(clone);
addEdge(selected, clone);
if (clone.next_dialogue != null) addEdge(clone, clone.next_dialogue);
} else if (target instanceof WriterDialogue) {
WriterReply empty = data.new EmptyReply((WriterDialogue)selected);
empty.next_dialogue = (WriterDialogue)target;
stopPendingEdge();
addEdge(selected, target);
}
}
}
static final String disposeEditorString = "disposeEditor";
final AbstractAction disposeEditor = new AbstractAction("Dispose Editor") {
private static final long serialVersionUID = 6640035253411399809L;
@@ -483,8 +564,7 @@ public class WriterModeEditor extends JPanel {
@Override
public void actionPerformed(ActionEvent e) {
if (area == null) return;
selected.text = area.getText();
cells.get(selected).set(LABEL, selected.text);
commitAreaText();
m_vis.run("colors");
revalidate();
repaint();
@@ -503,6 +583,8 @@ public class WriterModeEditor extends JPanel {
@Override
public void actionPerformed(ActionEvent e) {
stopPendingEdge();
if (selected == null) return;
WriterNode newWrNode = null;
Node newNode = null;
if (selected instanceof WriterDialogue) {
@@ -518,15 +600,17 @@ public class WriterModeEditor extends JPanel {
newNode = addDialogueNode(((WriterDialogue)newWrNode));
}
}
Edge edge = graph.addEdge(cells.get(selected), newNode);
setSelected(newWrNode);
if (newNode!= null) {
Edge edge = graph.addEdge(cells.get(selected), newNode);
setSelected(newWrNode);
m_vis.run("colors");
m_vis.run("layout");
m_vis.run("scrollToSelectedAndEdit");
revalidate();
repaint();
m_vis.run("colors");
m_vis.run("layout");
m_vis.run("scrollToSelectedAndEdit");
revalidate();
repaint();
}
}
};
@@ -537,6 +621,7 @@ public class WriterModeEditor extends JPanel {
@Override
public void actionPerformed(ActionEvent e) {
commitAreaText();
stopPendingEdge();
createNextDefaultNode.actionPerformed(e);
}
};
@@ -549,6 +634,7 @@ public class WriterModeEditor extends JPanel {
@Override
public void actionPerformed(ActionEvent e) {
commitAreaText();
stopPendingEdge();
WriterDialogue newWrNode = null;
Node newNode = null;
if (selected instanceof WriterDialogue) {
@@ -559,14 +645,40 @@ public class WriterModeEditor extends JPanel {
newNode = addDialogueNode(newWrNode);
Edge edge = graph.addEdge(cells.get(selected), newNode);
setSelected(newWrNode);
}
m_vis.run("colors");
m_vis.run("layout");
m_vis.run("scrollToSelectedAndEdit");
m_vis.run("colors");
m_vis.run("layout");
m_vis.run("scrollToSelectedAndEdit");
revalidate();
repaint();
}
}
};
static final String createOtherReplyNodeString = "createOtherReplyNode";
final AbstractAction createOtherReplyNode = new AbstractAction("Create another reply with the same parent") {
private static final long serialVersionUID = 1658086056088672748L;
@Override
public void actionPerformed(ActionEvent e) {
commitAreaText();
stopPendingEdge();
WriterReply newWrNode = null;
Node newNode = null;
if (selected instanceof WriterReply) {
newWrNode = data.new WriterReply(((WriterReply) selected).parent);
newNode = addReplyNode(newWrNode);
Edge edge = graph.addEdge(cells.get(((WriterReply) selected).parent), newNode);
setSelected(newWrNode);
m_vis.run("colors");
m_vis.run("layout");
m_vis.run("scrollToSelectedAndEdit");
revalidate();
repaint();
}
revalidate();
repaint();
}
};
@@ -657,8 +769,14 @@ public class WriterModeEditor extends JPanel {
area.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.ALT_DOWN_MASK, true), commitAndCreateNextDefaultNodeString);
area.getActionMap().put(commitAndCreateNextDefaultNodeString, commitAndCreateNextDefaultNode);
area.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK, true), createContinueTalkingNodeString);
area.getActionMap().put(createContinueTalkingNodeString, createContinueTalkingNode);
if (selected instanceof WriterDialogue) {
area.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK, true), createContinueTalkingNodeString);
area.getActionMap().put(createContinueTalkingNodeString, createContinueTalkingNode);
} else if (selected instanceof WriterReply) {
area.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK, true), createOtherReplyNodeString);
area.getActionMap().put(createOtherReplyNodeString, createOtherReplyNode);
}
}
@@ -917,5 +1035,11 @@ public class WriterModeEditor extends JPanel {
// }
}
@Override
public void targetUpdated() {
// TODO Auto-generated method stub
}
}