mirror of
https://github.com/OMGeeky/ATCS.git
synced 2025-12-26 23:57:25 +01:00
Dialogue sketches can be saved. Bug fixes in sketch export.
This commit is contained in:
@@ -99,7 +99,7 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return parent.getProject();
|
||||
return parent == null ? null : parent.getProject();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,11 +25,10 @@ import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||
public class WriterModeData extends GameDataElement {
|
||||
private static final long serialVersionUID = -7062544089063979696L;
|
||||
|
||||
//Available from state init.
|
||||
public File jsonFile;
|
||||
|
||||
public Image npcIcon;
|
||||
public String sketchName;
|
||||
// public String sketchName;
|
||||
|
||||
|
||||
public List<String> rootsId = new ArrayList<String>();
|
||||
@@ -37,7 +36,7 @@ public class WriterModeData extends GameDataElement {
|
||||
public WriterDialogue begin;
|
||||
public Map<String, WriterDialogue> nodesById = new LinkedHashMap<String, WriterDialogue>();
|
||||
|
||||
public Map<String, WriterDialogue> dialogueThreads = new LinkedHashMap<String, WriterDialogue>();
|
||||
//public Map<String, WriterDialogue> dialogueThreads = new LinkedHashMap<String, WriterDialogue>();
|
||||
public Map<String, Integer> threadsNextIndex = new LinkedHashMap<String, Integer>();
|
||||
|
||||
|
||||
@@ -45,10 +44,11 @@ public class WriterModeData extends GameDataElement {
|
||||
this.id = id_prefix;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public WriterModeData(WriterModeDataSet parent, @SuppressWarnings("rawtypes") Map jsonObj) {
|
||||
this.parent = parent;
|
||||
this.begin = new WriterDialogue(jsonObj);
|
||||
this.id = begin.id_prefix;
|
||||
this.jsonFile = parent.writerFile;
|
||||
this.parse(jsonObj);
|
||||
this.state = State.parsed;
|
||||
}
|
||||
|
||||
@@ -67,8 +67,6 @@ public class WriterModeData extends GameDataElement {
|
||||
public String text;
|
||||
|
||||
public abstract String getTitle();
|
||||
@SuppressWarnings("rawtypes")
|
||||
public abstract Map toJson();
|
||||
|
||||
}
|
||||
|
||||
@@ -78,6 +76,7 @@ public class WriterModeData extends GameDataElement {
|
||||
public int index;
|
||||
public List<WriterReply> replies = new ArrayList<WriterReply>();
|
||||
public List<WriterReply> parents = new ArrayList<WriterReply>();
|
||||
public String dialogue_id;
|
||||
public Dialogue dialogue;
|
||||
|
||||
public WriterDialogue() {}
|
||||
@@ -98,37 +97,49 @@ public class WriterModeData extends GameDataElement {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Map toJson() {
|
||||
public void toJson(List<WriterDialogue> visited, List<Map> jsonData) {
|
||||
if (visited.contains(this)) return;
|
||||
visited.add(this);
|
||||
Map dialogueJson = new LinkedHashMap();
|
||||
jsonData.add(dialogueJson);
|
||||
dialogueJson.put("id", id);
|
||||
dialogueJson.put("id_prefix", id_prefix);
|
||||
dialogueJson.put("index", index);
|
||||
dialogueJson.put("text", text);
|
||||
if (dialogue != null) {
|
||||
dialogueJson.put("dialogue", dialogue.id);
|
||||
} else if (dialogue_id != null) {
|
||||
dialogueJson.put("dialogue", dialogue_id);
|
||||
}
|
||||
dialogueJson.put("special", isSpecial());
|
||||
dialogueJson.put("begin", begin == this);
|
||||
if (!replies.isEmpty()) {
|
||||
List repliesJson = new ArrayList();
|
||||
for (WriterReply reply : replies) {
|
||||
repliesJson.add(reply.toJson());
|
||||
repliesJson.add(reply.toJson(visited, jsonData));
|
||||
}
|
||||
dialogueJson.put("replies", repliesJson);
|
||||
}
|
||||
return dialogueJson;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public WriterDialogue(Map json) {
|
||||
this.id = (String) json.get("id");
|
||||
this.index = Integer.parseInt((String) json.get("index"));
|
||||
this.index = ((Number)json.get("index")).intValue();
|
||||
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.dialogue_id = (String) json.get("dialogue");
|
||||
if (json.get("begin") != null && ((Boolean)json.get("begin"))) begin = this;
|
||||
if (json.get("replies") != null) {
|
||||
List repliesJson = (List) json.get("replies");
|
||||
for (Object rJson : repliesJson) {
|
||||
if (((Map)rJson).get("special") != null && (Boolean)((Map)rJson).get("special")) {
|
||||
//TODO Check different cases. But there are none currently.
|
||||
this.replies.add(new EmptyReply(this, ((Map)rJson)));
|
||||
} else {
|
||||
this.replies.add(new WriterReply(this, (Map)rJson));
|
||||
}
|
||||
}
|
||||
this.replies.add(new WriterReply(this, (Map)rJson));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +153,7 @@ public class WriterModeData extends GameDataElement {
|
||||
dialogue.id = getID();
|
||||
dialogue.state = GameDataElement.State.parsed;
|
||||
} else {
|
||||
dialogue.state = GameDataElement.State.modified;
|
||||
if (hasChanged()) dialogue.state = GameDataElement.State.modified;
|
||||
}
|
||||
visited.put(this, dialogue);
|
||||
dialogue.message = this.text;
|
||||
@@ -228,13 +239,13 @@ public class WriterModeData extends GameDataElement {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Map toJson() {
|
||||
public Map toJson(List<WriterDialogue> visited, List<Map> jsonData) {
|
||||
Map replyJson = new LinkedHashMap();
|
||||
replyJson.put("text", text);
|
||||
replyJson.put("special", isSpecial());
|
||||
if (next_dialogue != null) {
|
||||
replyJson.put("next_dialogue_id", next_dialogue.id);
|
||||
replyJson.put("next_dialogue_id", next_dialogue.getID());
|
||||
next_dialogue.toJson(visited, jsonData);
|
||||
}
|
||||
return replyJson;
|
||||
}
|
||||
@@ -364,9 +375,14 @@ public class WriterModeData extends GameDataElement {
|
||||
return events;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Map toJson() {
|
||||
return begin.toJson();
|
||||
List<Map> jsonData = new ArrayList<Map>();
|
||||
begin.toJson(new ArrayList<WriterModeData.WriterDialogue>(), jsonData);
|
||||
Map jsonObj = new LinkedHashMap();
|
||||
jsonObj.put("id", id);
|
||||
jsonObj.put("dialogues", jsonData);
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -412,18 +428,18 @@ public class WriterModeData extends GameDataElement {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
nodesById.put(dialogue.getID(), dialogue);
|
||||
}
|
||||
}
|
||||
this.state = State.parsed;
|
||||
@@ -440,8 +456,12 @@ public class WriterModeData extends GameDataElement {
|
||||
if (this.state == State.init) {
|
||||
//Not parsed yet.
|
||||
this.parse();
|
||||
} else if (this.state == State.parsed) {
|
||||
}
|
||||
if (this.state == State.parsed) {
|
||||
for (WriterDialogue dialogue : nodesById.values()) {
|
||||
if (dialogue.dialogue_id != null) {
|
||||
dialogue.dialogue = getProject().getDialogue(dialogue.dialogue_id);
|
||||
}
|
||||
if (dialogue.replies == null) continue;
|
||||
for (WriterReply reply : dialogue.replies) {
|
||||
if (reply.next_dialogue_id != null) {
|
||||
@@ -457,7 +477,8 @@ public class WriterModeData extends GameDataElement {
|
||||
roots.add(nodesById.get(rootId));
|
||||
}
|
||||
|
||||
} else if (this.state == State.linked) {
|
||||
}
|
||||
if (this.state == State.linked) {
|
||||
//Already linked.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,6 +253,7 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
|
||||
}
|
||||
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;
|
||||
writerModeDataList.add(node);
|
||||
if (node.jsonFile == null) node.jsonFile = this.writerFile;
|
||||
node.parent = this;
|
||||
if (higherEmptyParent != null) higherEmptyParent.notifyCreated();
|
||||
else node.notifyCreated();
|
||||
|
||||
@@ -4,11 +4,14 @@ import java.awt.BorderLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -54,6 +57,8 @@ import prefuse.visual.EdgeItem;
|
||||
import prefuse.visual.VisualItem;
|
||||
import prefuse.visual.expression.InGroupPredicate;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
|
||||
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
|
||||
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData.EmptyReply;
|
||||
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData.SpecialDialogue;
|
||||
@@ -62,6 +67,7 @@ import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData.WriterN
|
||||
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData.WriterReply;
|
||||
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||
import com.gpl.rpg.atcontentstudio.ui.Editor;
|
||||
import com.jidesoft.swing.JideBoxLayout;
|
||||
|
||||
public class WriterModeEditor extends Editor {
|
||||
|
||||
@@ -80,8 +86,42 @@ public class WriterModeEditor extends Editor {
|
||||
view = new WriterGraphView();
|
||||
view.setLocation(0, 0);
|
||||
setLayout(new BorderLayout());
|
||||
add(createButtonPane(), BorderLayout.NORTH);
|
||||
add(view, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
|
||||
public JPanel createButtonPane() {
|
||||
JPanel pane = new JPanel();
|
||||
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.LINE_AXIS));
|
||||
JButton save = new JButton("Save sketch");
|
||||
JButton export = new JButton("Export sketch to game data");
|
||||
save.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
data.save();
|
||||
}
|
||||
});
|
||||
export.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Collection<Dialogue> exported = data.toDialogue();
|
||||
data.getProject().createElements(new ArrayList<JSONElement>(exported));
|
||||
}
|
||||
});
|
||||
pane.add(save, JideBoxLayout.FIX);
|
||||
pane.add(export, JideBoxLayout.FIX);
|
||||
pane.add(new JPanel(), JideBoxLayout.VARY);
|
||||
return pane;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void disposeOverlay() {
|
||||
if (overlay != null) view.remove(overlay);
|
||||
|
||||
Reference in New Issue
Block a user