Merge branch 'pulls/1195352/9'

This commit is contained in:
Nut.andor
2025-08-04 20:47:18 +02:00
133 changed files with 30235 additions and 33454 deletions

14
.idea/codeStyles/Project.xml generated Normal file
View File

@@ -0,0 +1,14 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="JD_P_AT_EMPTY_LINES" value="false" />
</JavaCodeStyleSettings>
<codeStyleSettings language="JAVA">
<option name="RIGHT_MARGIN" value="200" />
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="1" />
<option name="BINARY_OPERATION_WRAP" value="5" />
<option name="SOFT_MARGINS" value="120" />
</codeStyleSettings>
</code_scheme>
</component>

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View File

@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

2
.idea/misc.xml generated
View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="temurin-11" project-jdk-type="JavaSDK" />
</project>

View File

@@ -43,7 +43,7 @@ public class MapObject implements Cloneable
{
private Properties properties = new Properties();
private ObjectGroup objectGroup;
private Rectangle bounds = new Rectangle();
private Rectangle bounds;
private String name = "Object";
private String type = "";
private String imageSource = "";

View File

@@ -57,7 +57,7 @@ public class Sprite
private String name = null;
private int id = -1;
private int flags = KEY_LOOP;
private int flags;
private float frameRate = 1.0f; //one fps
private Tile[] frames;

View File

@@ -588,7 +588,7 @@ public class TMXMapWriter
}
// Iterate while parents are the same
int shared = 0;
int shared;
int maxShared = Math.min(fromParents.size(), toParents.size());
for (shared = 0; shared < maxShared; shared++) {
String fromParent = fromParents.get(shared);

View File

@@ -1,10 +1,16 @@
package com.gpl.rpg.atcontentstudio;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import com.gpl.rpg.atcontentstudio.model.Workspace;
import com.gpl.rpg.atcontentstudio.ui.StudioFrame;
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
import com.gpl.rpg.atcontentstudio.ui.WorkspaceSelector;
import prefuse.data.expression.parser.ExpressionParser;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
@@ -14,31 +20,16 @@ import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.plaf.FontUIResource;
import prefuse.data.expression.parser.ExpressionParser;
import com.gpl.rpg.atcontentstudio.model.Workspace;
import com.gpl.rpg.atcontentstudio.ui.StudioFrame;
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
import com.gpl.rpg.atcontentstudio.ui.WorkspaceSelector;
public class ATContentStudio {
public static final String APP_NAME = "Andor's Trail Content Studio";
public static final String APP_VERSION = readVersionFromFile();
public static final String APP_VERSION = readVersionFromFile();
public static final String CHECK_UPDATE_URL = "https://andorstrail.com/static/ATCS_latest";
public static final String DOWNLOAD_URL = "https://andorstrail.com/viewtopic.php?f=6&t=4806";
@@ -57,7 +48,7 @@ public static final String APP_VERSION = readVersionFromFile();
*/
public static void main(String[] args) {
String fontScaling = System.getProperty(FONT_SCALE_ENV_VAR_NAME);
Float fontScale = null;
Float fontScale;
if (fontScaling != null) {
try {
fontScale = Float.parseFloat(fontScaling);
@@ -120,7 +111,8 @@ public static final String APP_VERSION = readVersionFromFile();
frame = new StudioFrame(APP_NAME + " " + APP_VERSION);
frame.setVisible(true);
frame.setDefaultCloseOperation(StudioFrame.DO_NOTHING_ON_CLOSE);
};
}
});
for (File f : ConfigCache.getKnownWorkspaces()) {
if (workspaceRoot.equals(f)) {
@@ -208,7 +200,7 @@ public static final String APP_VERSION = readVersionFromFile();
System.out.println("Scaling fonts to " + SCALING);
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
Map<Object, Object> newDefaults = new HashMap<Object, Object>();
for (Enumeration<Object> e = defaults.keys(); e.hasMoreElements();) {
for (Enumeration<Object> e = defaults.keys(); e.hasMoreElements(); ) {
Object key = e.nextElement();
Object value = defaults.get(key);
if (value instanceof Font) {
@@ -226,6 +218,7 @@ public static final String APP_VERSION = readVersionFromFile();
}
}
}
private static String readVersionFromFile() {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
Objects.requireNonNull(ATContentStudio.class.getResourceAsStream("/ATCS_latest"))))) {

View File

@@ -1,12 +1,12 @@
package com.gpl.rpg.atcontentstudio;
import com.gpl.rpg.atcontentstudio.io.SettingsSave;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.gpl.rpg.atcontentstudio.io.SettingsSave;
public class ConfigCache implements Serializable {
private static final long serialVersionUID = 4584324644282843961L;
@@ -18,9 +18,9 @@ public class ConfigCache implements Serializable {
static {
if (System.getenv("APPDATA") != null) {
CONFIG_CACHE_STORAGE = new File(System.getenv("APPDATA")+File.separator+ATContentStudio.APP_NAME+File.separator+"configCache" );
CONFIG_CACHE_STORAGE = new File(System.getenv("APPDATA") + File.separator + ATContentStudio.APP_NAME + File.separator + "configCache");
} else {
CONFIG_CACHE_STORAGE = new File(System.getenv("HOME")+File.separator+"."+ATContentStudio.APP_NAME+File.separator+"configCache" );
CONFIG_CACHE_STORAGE = new File(System.getenv("HOME") + File.separator + "." + ATContentStudio.APP_NAME + File.separator + "configCache");
}
CONFIG_CACHE_STORAGE.getParentFile().mkdirs();
if (CONFIG_CACHE_STORAGE.exists()) {
@@ -77,7 +77,7 @@ public class ConfigCache implements Serializable {
}
public static void putNotifViewConfig(boolean[] view) {
for (int i=instance.notifConfig.length; i<0; --i) {
for (int i = instance.notifConfig.length; i < 0; --i) {
instance.notifConfig[i] = view[i];
}
instance.save();
@@ -91,7 +91,8 @@ public class ConfigCache implements Serializable {
return instance.notifConfig;
}
public static void init() {}
public static void init() {
}
public static void clear() {
instance.knownWorkspaces.clear();

View File

@@ -8,7 +8,7 @@ public class Notification {
public static List<Notification> notifs = new ArrayList<Notification>();
private static List<NotificationListener> listeners = new CopyOnWriteArrayList<NotificationListener>();
public static boolean showS = true, showI = true, showW = true, showE = true;
public static boolean showS, showI, showW, showE;
static {
boolean[] config = ConfigCache.getNotifViewConfig();
@@ -34,7 +34,7 @@ public class Notification {
}
public String toString() {
return "["+type.toString()+"] "+text;
return "[" + type.toString() + "] " + text;
}
public static void clear() {

View File

@@ -3,6 +3,7 @@ package com.gpl.rpg.atcontentstudio;
public interface NotificationListener {
public void onNewNotification(Notification n);
public void onListCleared(int i);
}

View File

@@ -1,15 +1,9 @@
package com.gpl.rpg.atcontentstudio.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import com.gpl.rpg.atcontentstudio.Notification;
import java.io.*;
public class SettingsSave {
public static void saveInstance(Object obj, File f, String type) {
@@ -20,21 +14,21 @@ public class SettingsSave {
oos.writeObject(obj);
oos.flush();
oos.close();
Notification.addSuccess(type+" successfully saved.");
Notification.addSuccess(type + " successfully saved.");
} catch (IOException e) {
e.printStackTrace();
Notification.addError(type+" saving error: "+e.getMessage());
Notification.addError(type + " saving error: " + e.getMessage());
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
Notification.addError(type+" saving error: "+e.getMessage());
Notification.addError(type + " saving error: " + e.getMessage());
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Notification.addError(type+" saving error: "+e.getMessage());
Notification.addError(type + " saving error: " + e.getMessage());
}
}
@@ -48,27 +42,27 @@ public class SettingsSave {
ois = new ObjectInputStream(fis);
try {
result = ois.readObject();
Notification.addSuccess(type+" successfully loaded.");
Notification.addSuccess(type + " successfully loaded.");
} catch (ClassNotFoundException e) {
e.printStackTrace();
Notification.addError(type+" loading error: "+e.getMessage());
Notification.addError(type + " loading error: " + e.getMessage());
} finally {
ois.close();
}
} catch (IOException e) {
e.printStackTrace();
Notification.addError(type+" loading error: "+e.getMessage());
Notification.addError(type + " loading error: " + e.getMessage());
} finally {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
Notification.addError(type+" loading error: "+e.getMessage());
Notification.addError(type + " loading error: " + e.getMessage());
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Notification.addError(type+" loading error: "+e.getMessage());
Notification.addError(type + " loading error: " + e.getMessage());
}
return result;
}

View File

@@ -1,16 +1,15 @@
package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
public class ClosedProject implements ProjectTreeNode {
String name;
@@ -25,26 +24,32 @@ public class ClosedProject implements ProjectTreeNode {
public TreeNode getChildAt(int childIndex) {
return null;
}
@Override
public int getChildCount() {
return 0;
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public int getIndex(TreeNode node) {
return 0;
}
@Override
public boolean getAllowsChildren() {
return false;
}
@Override
public boolean isLeaf() {
return true;
}
@Override
public Enumeration<ProjectTreeNode> children() {
return null;
@@ -52,19 +57,22 @@ public class ClosedProject implements ProjectTreeNode {
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenRemoved(path);
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -72,7 +80,7 @@ public class ClosedProject implements ProjectTreeNode {
@Override
public String getDesc() {
return name+" [closed]";
return name + " [closed]";
}
@Override
@@ -85,16 +93,19 @@ public class ClosedProject implements ProjectTreeNode {
public Image getIcon() {
return getOpenIcon();
}
@Override
public Image getClosedIcon() {
//TODO Create a cool Project icon.
return DefaultIcons.getStdClosedIcon();
}
@Override
public Image getLeafIcon() {
//TODO Create a cool Project icon.
return DefaultIcons.getStdClosedIcon();
}
@Override
public Image getOpenIcon() {
//TODO Create a cool Project icon.

View File

@@ -1,17 +1,13 @@
package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarkEntry;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarkEntry;
import java.awt.*;
import java.io.Serializable;
import java.util.List;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public abstract class GameDataElement implements ProjectTreeNode, Serializable {
@@ -44,51 +40,60 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
public Enumeration<ProjectTreeNode> children() {
return null;
}
@Override
public boolean getAllowsChildren() {
return false;
}
@Override
public TreeNode getChildAt(int arg0) {
return null;
}
@Override
public int getChildCount() {
return 0;
}
@Override
public int getIndex(TreeNode arg0) {
return 0;
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public boolean isLeaf() {
return true;
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenRemoved(path);
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
}
@Override
public abstract String getDesc();
@@ -97,8 +102,8 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
}
public abstract void parse();
public abstract void link();
public abstract void link();
@Override
@@ -110,10 +115,17 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
public Image getIcon() {
return null;
}
@Override
public Image getClosedIcon() {return null;}
public Image getClosedIcon() {
return null;
}
@Override
public Image getOpenIcon() {return null;}
public Image getOpenIcon() {
return null;
}
@Override
public Image getLeafIcon() {
return getIcon();
@@ -172,6 +184,7 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
public static interface BacklinksListener {
public void backlinkAdded(GameDataElement gde);
public void backlinkRemoved(GameDataElement gde);
}
@@ -190,4 +203,35 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
public abstract List<SaveEvent> attemptSave();
/**
* Checks if the current state indicates that parsing/linking should be skipped.
*
* @return true if the operation should be skipped, false otherwise
*/
protected boolean shouldSkipParseOrLink() {
if (shouldSkipParse()) return true;
if (this.state == State.linked) {
//Already linked.
return true;
}
return false;
}
protected boolean shouldSkipParse() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return true;
}
return false;
}
/**
* Ensures the element is parsed if needed based on its current state.
*/
protected void ensureParseIfNeeded() {
if (this.state == State.init) {
//Not parsed yet.
this.parse();
}
}
}

View File

@@ -1,28 +1,5 @@
package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.tree.TreeNode;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.gpl.rpg.atcontentstudio.model.Project.ResourceSet;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
@@ -32,13 +9,27 @@ import com.gpl.rpg.atcontentstudio.model.sprites.SpriteSheetSet;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.swing.tree.TreeNode;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.awt.*;
import java.io.*;
import java.util.List;
import java.util.*;
public class GameSource implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = -1512979360971918158L;
public static final String DEFAULT_REL_PATH_FOR_GAME_RESOURCE = "res"+File.separator+"values"+File.separator+"loadresources.xml";
public static final String DEFAULT_REL_PATH_FOR_DEBUG_RESOURCE = "res"+File.separator+"values"+File.separator+"loadresources_debug.xml";
public static final String DEFAULT_REL_PATH_FOR_GAME_RESOURCE = "res" + File.separator + "values" + File.separator + "loadresources.xml";
public static final String DEFAULT_REL_PATH_FOR_DEBUG_RESOURCE = "res" + File.separator + "values" + File.separator + "loadresources_debug.xml";
public transient GameDataSet gameData;
public transient TMXMapSet gameMaps;
@@ -57,7 +48,7 @@ public class GameSource implements ProjectTreeNode, Serializable {
public File baseFolder;
public Type type;
public transient Project parent = null;
public transient Project parent;
public transient Map<String, List<String>> referencedSourceFiles = null;
@@ -105,7 +96,7 @@ public class GameSource implements ProjectTreeNode, Serializable {
}
public void readResourceList() {
File xmlFile = null;
File xmlFile;
if (parent.sourceSetToUse == ResourceSet.gameData) {
xmlFile = new File(baseFolder, DEFAULT_REL_PATH_FOR_GAME_RESOURCE);
} else if (parent.sourceSetToUse == ResourceSet.debugData) {
@@ -138,7 +129,7 @@ public class GameSource implements ProjectTreeNode, Serializable {
NodeList arrayItems = arrayNode.getElementsByTagName("item");
if (arrayItems != null) {
for (int j = 0; j < arrayItems.getLength(); j++) {
arrayContents.add(((Element)arrayItems.item(j)).getTextContent());
arrayContents.add(((Element) arrayItems.item(j)).getTextContent());
}
referencedSourceFiles.put(name, arrayContents);
}
@@ -160,40 +151,49 @@ public class GameSource implements ProjectTreeNode, Serializable {
public Enumeration<ProjectTreeNode> children() {
return v.getNonEmptyElements();
}
@Override
public boolean getAllowsChildren() {
return true;
}
@Override
public TreeNode getChildAt(int arg0) {
return v.getNonEmptyElementAt(arg0);
}
@Override
public int getChildCount() {
return v.getNonEmptySize();
}
@Override
public int getIndex(TreeNode arg0) {
return v.getNonEmptyIndexOf((ProjectTreeNode) arg0);
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public boolean isLeaf() {
return false;
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
if (path.size() == 1 && this.v.getNonEmptySize() == 1) {
@@ -203,6 +203,7 @@ public class GameSource implements ProjectTreeNode, Serializable {
parent.childrenRemoved(path);
}
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -210,14 +211,20 @@ public class GameSource implements ProjectTreeNode, Serializable {
node.notifyCreated();
}
}
@Override
public String getDesc() {
switch(type) {
case altered: return (needsSaving() ? "*" : "")+"Altered data";
case created: return (needsSaving() ? "*" : "")+"Created data";
case referenced: return (needsSaving() ? "*" : "")+"Referenced data";
case source: return (needsSaving() ? "*" : "")+"AT Source"; //The fact that it is from "source" is already mentionned by its parent.
default: return (needsSaving() ? "*" : "")+"Game data";
switch (type) {
case altered:
return (needsSaving() ? "*" : "") + "Altered data";
case created:
return (needsSaving() ? "*" : "") + "Created data";
case referenced:
return (needsSaving() ? "*" : "") + "Referenced data";
case source:
return (needsSaving() ? "*" : "") + "AT Source"; //The fact that it is from "source" is already mentionned by its parent.
default:
return (needsSaving() ? "*" : "") + "Game data";
}
}
@@ -252,18 +259,22 @@ public class GameSource implements ProjectTreeNode, Serializable {
public Image getIcon() {
return getOpenIcon();
}
@Override
public Image getClosedIcon() {
return DefaultIcons.getATClosedIcon();
}
@Override
public Image getLeafIcon() {
return DefaultIcons.getATClosedIcon();
}
@Override
public Image getOpenIcon() {
return DefaultIcons.getATOpenIcon();
}
@Override
public GameDataSet getDataSet() {
return null;

View File

@@ -1,6 +1,6 @@
package com.gpl.rpg.atcontentstudio.model;
import java.awt.Dimension;
import java.awt.*;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

View File

@@ -1,69 +1,12 @@
package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringReader;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
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 java.util.Properties;
import javax.swing.tree.TreeNode;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.json.simple.JSONArray;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import com.gpl.rpg.atcontentstudio.io.SettingsSave;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarksRoot;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
import com.gpl.rpg.atcontentstudio.model.gamedata.*;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
import com.gpl.rpg.atcontentstudio.model.maps.Worldmap;
@@ -74,6 +17,30 @@ import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
import com.gpl.rpg.atcontentstudio.utils.FileUtils;
import org.json.simple.JSONArray;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.swing.tree.TreeNode;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.awt.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.*;
public class Project implements ProjectTreeNode, Serializable {
@@ -103,7 +70,7 @@ public class Project implements ProjectTreeNode, Serializable {
public transient Workspace parent;
public Properties knownSpritesheetsProperties = null;
public Properties knownSpritesheetsProperties;
public static enum ResourceSet {
gameData,
@@ -111,7 +78,7 @@ public class Project implements ProjectTreeNode, Serializable {
allFiles
}
public ResourceSet sourceSetToUse = ResourceSet.allFiles;
public ResourceSet sourceSetToUse;
public Project(Workspace w, String name, File source, ResourceSet sourceSet) {
this.parent = w;
@@ -119,11 +86,11 @@ public class Project implements ProjectTreeNode, Serializable {
this.sourceSetToUse = sourceSet;
//CREATE PROJECT
baseFolder = new File(w.baseFolder, name+File.separator);
baseFolder = new File(w.baseFolder, name + File.separator);
try {
baseFolder.mkdir();
} catch (SecurityException e) {
Notification.addError("Eror creating project root folder: "+e.getMessage());
Notification.addError("Eror creating project root folder: " + e.getMessage());
e.printStackTrace();
}
open = true;
@@ -198,21 +165,22 @@ public class Project implements ProjectTreeNode, Serializable {
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenRemoved(path);
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -220,9 +188,10 @@ public class Project implements ProjectTreeNode, Serializable {
node.notifyCreated();
}
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+name;
return (needsSaving() ? "*" : "") + name;
}
@@ -237,10 +206,10 @@ public class Project implements ProjectTreeNode, Serializable {
public static Project fromFolder(Workspace w, File projRoot) {
Project p = null;
Project p;
File f = new File(projRoot, Project.SETTINGS_FILE);
if (!f.exists()) {
Notification.addError("Unable to find "+SETTINGS_FILE+" for project "+projRoot.getName());
Notification.addError("Unable to find " + SETTINGS_FILE + " for project " + projRoot.getName());
return null;
} else {
p = (Project) SettingsSave.loadInstance(f, "Project");
@@ -299,7 +268,7 @@ public class Project implements ProjectTreeNode, Serializable {
}
}
for (ProjectTreeNode node : baseContent.gameMaps.tmxMaps) {
((TMXMap)node).link();
((TMXMap) node).link();
}
for (ProjectTreeNode node : alteredContent.gameData.v.getNonEmptyIterable()) {
if (node instanceof GameDataCategory<?>) {
@@ -309,7 +278,7 @@ public class Project implements ProjectTreeNode, Serializable {
}
}
for (ProjectTreeNode node : alteredContent.gameMaps.tmxMaps) {
((TMXMap)node).link();
((TMXMap) node).link();
}
for (ProjectTreeNode node : createdContent.gameData.v.getNonEmptyIterable()) {
if (node instanceof GameDataCategory<?>) {
@@ -319,7 +288,7 @@ public class Project implements ProjectTreeNode, Serializable {
}
}
for (ProjectTreeNode node : createdContent.gameMaps.tmxMaps) {
((TMXMap)node).link();
((TMXMap) node).link();
}
for (WorldmapSegment node : createdContent.worldmap) {
@@ -334,7 +303,7 @@ public class Project implements ProjectTreeNode, Serializable {
}
public void save() {
SettingsSave.saveInstance(this, new File(baseFolder, Project.SETTINGS_FILE), "Project "+this.name);
SettingsSave.saveInstance(this, new File(baseFolder, Project.SETTINGS_FILE), "Project " + this.name);
}
@@ -428,7 +397,7 @@ public class Project implements ProjectTreeNode, Serializable {
public ActorCondition getActorCondition(int index) {
if (index < createdContent.gameData.actorConditions.size()) {
return createdContent.gameData.actorConditions.get(index);
} else if (index < getActorConditionCount()){
} else if (index < getActorConditionCount()) {
return getActorCondition(baseContent.gameData.actorConditions.get(index - createdContent.gameData.actorConditions.size()).id);
}
return null;
@@ -457,7 +426,7 @@ public class Project implements ProjectTreeNode, Serializable {
public Dialogue getDialogue(int index) {
if (index < createdContent.gameData.dialogues.size()) {
return createdContent.gameData.dialogues.get(index);
} else if (index < getDialogueCount()){
} else if (index < getDialogueCount()) {
return getDialogue(baseContent.gameData.dialogues.get(index - createdContent.gameData.dialogues.size()).id);
}
return null;
@@ -486,7 +455,7 @@ public class Project implements ProjectTreeNode, Serializable {
public Droplist getDroplist(int index) {
if (index < createdContent.gameData.droplists.size()) {
return createdContent.gameData.droplists.get(index);
} else if (index < getDroplistCount()){
} else if (index < getDroplistCount()) {
return getDroplist(baseContent.gameData.droplists.get(index - createdContent.gameData.droplists.size()).id);
}
return null;
@@ -515,7 +484,7 @@ public class Project implements ProjectTreeNode, Serializable {
public Item getItem(int index) {
if (index < createdContent.gameData.items.size()) {
return createdContent.gameData.items.get(index);
} else if (index < getItemCount()){
} else if (index < getItemCount()) {
return getItem(baseContent.gameData.items.get(index - createdContent.gameData.items.size()).id);
}
return null;
@@ -528,7 +497,7 @@ public class Project implements ProjectTreeNode, Serializable {
public Item getItemIncludingAltered(int index) {
if (index < createdContent.gameData.items.size()) {
return createdContent.gameData.items.get(index);
} else if (index < createdContent.gameData.items.size() + alteredContent.gameData.items.size()){
} else if (index < createdContent.gameData.items.size() + alteredContent.gameData.items.size()) {
return alteredContent.gameData.items.get(index - createdContent.gameData.items.size());
} else if (index < getItemCountIncludingAltered()) {
return baseContent.gameData.items.get(index - (createdContent.gameData.items.size() + alteredContent.gameData.items.size()));
@@ -559,7 +528,7 @@ public class Project implements ProjectTreeNode, Serializable {
public ItemCategory getItemCategory(int index) {
if (index < createdContent.gameData.itemCategories.size()) {
return createdContent.gameData.itemCategories.get(index);
} else if (index < getItemCategoryCount()){
} else if (index < getItemCategoryCount()) {
return getItemCategory(baseContent.gameData.itemCategories.get(index - createdContent.gameData.itemCategories.size()).id);
}
return null;
@@ -595,7 +564,7 @@ public class Project implements ProjectTreeNode, Serializable {
public NPC getNPC(int index) {
if (index < createdContent.gameData.npcs.size()) {
return createdContent.gameData.npcs.get(index);
} else if (index < getNPCCount()){
} else if (index < getNPCCount()) {
return getNPC(baseContent.gameData.npcs.get(index - createdContent.gameData.npcs.size()).id);
}
return null;
@@ -608,7 +577,7 @@ public class Project implements ProjectTreeNode, Serializable {
public NPC getNPCIncludingAltered(int index) {
if (index < createdContent.gameData.npcs.size()) {
return createdContent.gameData.npcs.get(index);
} else if (index < createdContent.gameData.npcs.size() + alteredContent.gameData.npcs.size()){
} else if (index < createdContent.gameData.npcs.size() + alteredContent.gameData.npcs.size()) {
return alteredContent.gameData.npcs.get(index - createdContent.gameData.npcs.size());
} else if (index < getNPCCountIncludingAltered()) {
return baseContent.gameData.npcs.get(index - (createdContent.gameData.npcs.size() + alteredContent.gameData.npcs.size()));
@@ -639,7 +608,7 @@ public class Project implements ProjectTreeNode, Serializable {
public Quest getQuest(int index) {
if (index < createdContent.gameData.quests.size()) {
return createdContent.gameData.quests.get(index);
} else if (index < getQuestCount()){
} else if (index < getQuestCount()) {
return getQuest(baseContent.gameData.quests.get(index - createdContent.gameData.quests.size()).id);
}
return null;
@@ -667,7 +636,7 @@ public class Project implements ProjectTreeNode, Serializable {
public WorldmapSegment getWorldmapSegment(int index) {
if (index < createdContent.worldmap.size()) {
return createdContent.worldmap.get(index);
} else if (index < getWorldmapSegmentCount()){
} else if (index < getWorldmapSegmentCount()) {
return getWorldmapSegment(baseContent.worldmap.get(index - createdContent.worldmap.size()).id);
}
return null;
@@ -703,7 +672,7 @@ public class Project implements ProjectTreeNode, Serializable {
public Spritesheet getSpritesheet(int index) {
if (index < createdContent.gameSprites.spritesheets.size()) {
return createdContent.gameSprites.spritesheets.get(index);
} else if (index < getSpritesheetCount()){
} else if (index < getSpritesheetCount()) {
return getSpritesheet(baseContent.gameSprites.spritesheets.get(index - createdContent.gameSprites.spritesheets.size()).id);
}
return null;
@@ -731,7 +700,7 @@ public class Project implements ProjectTreeNode, Serializable {
public TMXMap getMap(int index) {
if (index < createdContent.gameMaps.getChildCount()) {
return createdContent.gameMaps.get(index);
} else if (index < getMapCount()){
} else if (index < getMapCount()) {
return getMap(baseContent.gameMaps.get(index - createdContent.gameMaps.getChildCount()).id);
}
return null;
@@ -769,16 +738,19 @@ public class Project implements ProjectTreeNode, Serializable {
public Image getIcon() {
return getOpenIcon();
}
@Override
public Image getClosedIcon() {
//TODO Create a cool Project icon.
return DefaultIcons.getStdClosedIcon();
}
@Override
public Image getLeafIcon() {
//TODO Create a cool Project icon.
return DefaultIcons.getStdClosedIcon();
}
@Override
public Image getOpenIcon() {
//TODO Create a cool Project icon.
@@ -788,7 +760,7 @@ public class Project implements ProjectTreeNode, Serializable {
public void makeWritable(JSONElement node) {
GameSource.Type type = node.getDataType();
if (type == null) {
Notification.addError("Unable to make "+node.getDesc()+" writable. No owning GameDataSet found.");
Notification.addError("Unable to make " + node.getDesc() + " writable. No owning GameDataSet found.");
} else {
if (type == GameSource.Type.source) {
JSONElement clone = (JSONElement) node.clone();
@@ -809,17 +781,16 @@ public class Project implements ProjectTreeNode, Serializable {
clone.state = GameDataElement.State.created;
alteredContent.gameData.addElement(clone);
} else {
Notification.addError("Unable to make "+node.getDesc()+" writable. It does not originate from game source material.");
Notification.addError("Unable to make " + node.getDesc() + " writable. It does not originate from game source material.");
}
}
}
public void makeWritable(TMXMap node) {
GameSource.Type type = node.getDataType();
if (type == null) {
Notification.addError("Unable to make "+node.getDesc()+" writable. No owning GameDataSet found.");
Notification.addError("Unable to make " + node.getDesc() + " writable. No owning GameDataSet found.");
} else {
if (type == GameSource.Type.source) {
TMXMap clone = node.clone();
@@ -831,7 +802,7 @@ public class Project implements ProjectTreeNode, Serializable {
clone.state = GameDataElement.State.created;
alteredContent.gameMaps.addMap(clone);
} else {
Notification.addError("Unable to make "+node.getDesc()+" writable. It does not originate from game source material.");
Notification.addError("Unable to make " + node.getDesc() + " writable. It does not originate from game source material.");
}
}
}
@@ -839,7 +810,7 @@ public class Project implements ProjectTreeNode, Serializable {
public void makeWritable(WorldmapSegment node) {
GameSource.Type type = node.getDataType();
if (type == null) {
Notification.addError("Unable to make "+node.getDesc()+" writable. No owning GameDataSet found.");
Notification.addError("Unable to make " + node.getDesc() + " writable. No owning GameDataSet found.");
} else {
if (type == GameSource.Type.source) {
WorldmapSegment clone = node.clone();
@@ -853,13 +824,12 @@ public class Project implements ProjectTreeNode, Serializable {
clone.state = GameDataElement.State.created;
alteredContent.worldmap.addSegment(clone);
} else {
Notification.addError("Unable to make "+node.getDesc()+" writable. It does not originate from game source material.");
Notification.addError("Unable to make " + node.getDesc() + " writable. It does not originate from game source material.");
}
}
}
/**
*
* @param node. Before calling this method, make sure that no other node with the same class and id exist in either created or altered.
*/
public void createElement(JSONElement node) {
@@ -883,7 +853,6 @@ public class Project implements ProjectTreeNode, Serializable {
}
/**
*
* @param node. Before calling this method, make sure that no other node with the same class and id exist in either created or altered.
*/
public void createElements(List<? extends JSONElement> nodes) {
@@ -911,7 +880,6 @@ public class Project implements ProjectTreeNode, Serializable {
}
/**
*
* @param node. Before calling this method, make sure that no other map with the same id exist in either created or altered.
*/
public void createElement(TMXMap node) {
@@ -941,16 +909,16 @@ public class Project implements ProjectTreeNode, Serializable {
public void moveToCreated(JSONElement target) {
target.childrenRemoved(new ArrayList<ProjectTreeNode>());
((GameDataCategory<?>)target.getParent()).remove(target);
((GameDataCategory<?>) target.getParent()).remove(target);
target.state = GameDataElement.State.created;
createdContent.gameData.addElement(target);
}
public void moveToAltered(JSONElement target) {
target.childrenRemoved(new ArrayList<ProjectTreeNode>());
((GameDataCategory<?>)target.getParent()).remove(target);
((GameDataCategory<?>) target.getParent()).remove(target);
target.state = GameDataElement.State.created;
((JSONElement) target).jsonFile = new File(baseContent.gameData.getGameDataElement(((JSONElement)target).getClass(), target.id).jsonFile.getAbsolutePath());
((JSONElement) target).jsonFile = new File(baseContent.gameData.getGameDataElement(((JSONElement) target).getClass(), target.id).jsonFile.getAbsolutePath());
alteredContent.gameData.addElement((JSONElement) target);
}
@@ -975,7 +943,6 @@ public class Project implements ProjectTreeNode, Serializable {
}
public void createWriterSketch(WriterModeData node) {
node.writable = true;
createdContent.writerModeDataSet.add(node);
@@ -1060,7 +1027,8 @@ public class Project implements ProjectTreeNode, Serializable {
}
public void removeElementListener(Class<? extends GameDataElement> interestingType, ProjectElementListener listener) {
if (projectElementListeners.get(interestingType) != null) projectElementListeners.get(interestingType).remove(listener);
if (projectElementListeners.get(interestingType) != null)
projectElementListeners.get(interestingType).remove(listener);
}
public void fireElementAdded(GameDataElement element, int index) {
@@ -1080,10 +1048,10 @@ public class Project implements ProjectTreeNode, Serializable {
}
public void exportProjectAsZipPackage(final File target) {
WorkerDialog.showTaskMessage("Exporting project "+name+"...", ATContentStudio.frame, true, new Runnable() {
WorkerDialog.showTaskMessage("Exporting project " + name + "...", ATContentStudio.frame, true, new Runnable() {
@Override
public void run() {
Notification.addInfo("Exporting project \""+name+"\" as "+target.getAbsolutePath());
Notification.addInfo("Exporting project \"" + name + "\" as " + target.getAbsolutePath());
File tmpDir;
try {
@@ -1095,7 +1063,7 @@ public class Project implements ProjectTreeNode, Serializable {
e.printStackTrace();
}
Notification.addSuccess("Project \""+name+"\" exported as "+target.getAbsolutePath());
Notification.addSuccess("Project \"" + name + "\" exported as " + target.getAbsolutePath());
}
@@ -1103,10 +1071,10 @@ public class Project implements ProjectTreeNode, Serializable {
}
public void exportProjectOverGameSource(final File target) {
WorkerDialog.showTaskMessage("Exporting project "+name+"...", ATContentStudio.frame, true, new Runnable() {
WorkerDialog.showTaskMessage("Exporting project " + name + "...", ATContentStudio.frame, true, new Runnable() {
@Override
public void run() {
Notification.addInfo("Exporting project \""+name+"\" into "+target.getAbsolutePath());
Notification.addInfo("Exporting project \"" + name + "\" into " + target.getAbsolutePath());
File tmpDir;
try {
@@ -1118,7 +1086,7 @@ public class Project implements ProjectTreeNode, Serializable {
e.printStackTrace();
}
Notification.addSuccess("Project \""+name+"\" exported into "+target.getAbsolutePath());
Notification.addSuccess("Project \"" + name + "\" exported into " + target.getAbsolutePath());
}
@@ -1137,13 +1105,15 @@ public class Project implements ProjectTreeNode, Serializable {
// }
Map<Class<? extends GameDataElement>, List<String>> writtenFilesPerDataType = new LinkedHashMap<Class<? extends GameDataElement>, List<String>>();
List<String> writtenFiles;
writtenFiles = writeDataDeltaForDataType(createdContent.gameData.actorConditions, alteredContent.gameData.actorConditions, baseContent.gameData.actorConditions, ActorCondition.class, tmpJsonDataDir);
writtenFiles = writeDataDeltaForDataType(createdContent.gameData.actorConditions, alteredContent.gameData.actorConditions, baseContent.gameData.actorConditions, ActorCondition.class,
tmpJsonDataDir);
writtenFilesPerDataType.put(ActorCondition.class, writtenFiles);
writtenFiles = writeDataDeltaForDataType(createdContent.gameData.dialogues, alteredContent.gameData.dialogues, baseContent.gameData.dialogues, Dialogue.class, tmpJsonDataDir);
writtenFilesPerDataType.put(Dialogue.class, writtenFiles);
writtenFiles = writeDataDeltaForDataType(createdContent.gameData.droplists, alteredContent.gameData.droplists, baseContent.gameData.droplists, Droplist.class, tmpJsonDataDir);
writtenFilesPerDataType.put(Droplist.class, writtenFiles);
writtenFiles = writeDataDeltaForDataType(createdContent.gameData.itemCategories, alteredContent.gameData.itemCategories, baseContent.gameData.itemCategories, ItemCategory.class, tmpJsonDataDir);
writtenFiles = writeDataDeltaForDataType(createdContent.gameData.itemCategories, alteredContent.gameData.itemCategories, baseContent.gameData.itemCategories, ItemCategory.class,
tmpJsonDataDir);
writtenFilesPerDataType.put(ItemCategory.class, writtenFiles);
writtenFiles = writeDataDeltaForDataType(createdContent.gameData.items, alteredContent.gameData.items, baseContent.gameData.items, Item.class, tmpJsonDataDir);
writtenFilesPerDataType.put(Item.class, writtenFiles);
@@ -1254,7 +1224,7 @@ public class Project implements ProjectTreeNode, Serializable {
w.close();
// Notification.addSuccess("Json file "+jsonFile.getAbsolutePath()+" saved.");
} catch (IOException e) {
Notification.addError("Error while writing json file "+jsonFile.getAbsolutePath()+" : "+e.getMessage());
Notification.addError("Error while writing json file " + jsonFile.getAbsolutePath() + " : " + e.getMessage());
e.printStackTrace();
}
}
@@ -1319,19 +1289,19 @@ public class Project implements ProjectTreeNode, Serializable {
NodeList arrayItems = arrayNode.getElementsByTagName("item");
if (arrayItems != null) {
for (int j = 0; j < arrayItems.getLength(); j++) {
resName = ((Element)arrayItems.item(j)).getTextContent();
resName = ((Element) arrayItems.item(j)).getTextContent();
if (resName == null) continue;
resToFile = resName.replaceFirst("\\A"+resPrefix, "")+fileSuffix;
resToFile = resName.replaceFirst("\\A" + resPrefix, "") + fileSuffix;
writtenFiles.remove(resToFile);
}
}
if (!writtenFiles.isEmpty()) {
Comment com = doc.createComment("Added by ATCS "+ATContentStudio.APP_VERSION+" for project "+getProject().name);
Comment com = doc.createComment("Added by ATCS " + ATContentStudio.APP_VERSION + " for project " + getProject().name);
arrayNode.appendChild(com);
Collections.sort(writtenFiles);
for (String missingRes : writtenFiles) {
Element item = doc.createElement("item");
fileToRes = resPrefix+missingRes.replaceFirst(fileSuffix+"\\z", "");
fileToRes = resPrefix + missingRes.replaceFirst(fileSuffix + "\\z", "");
item.setTextContent(fileToRes);
arrayNode.appendChild(item);
}
@@ -1400,7 +1370,4 @@ public class Project implements ProjectTreeNode, Serializable {
}
}

View File

@@ -1,23 +1,26 @@
package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image;
import java.util.List;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import java.awt.*;
import java.util.List;
public interface ProjectTreeNode extends TreeNode {
public void childrenAdded(List<ProjectTreeNode> path);
public void childrenChanged(List<ProjectTreeNode> path);
public void childrenRemoved(List<ProjectTreeNode> path);
public void notifyCreated();
public String getDesc();
/**
* Unnecessary for anything not below a Project. Can return null.
*
* @return the parent Project or null.
*/
public Project getProject();
@@ -25,29 +28,31 @@ public interface ProjectTreeNode extends TreeNode {
/**
* Unnecessary for anything not below a GameDataSet. Can return null.
*
* @return the parent GameDataSet or null.
*/
public GameDataSet getDataSet();
public Image getIcon();
/**
*
* @return The icon depicting this node when it is an open folder. Can be null for leaves.
*/
public Image getOpenIcon();
/**
*
* @return The icon depicting this node when it is a closed folder. Can be null for leaves.
*/
public Image getClosedIcon();
/**
*
* @return The icon depicting this node when it is a leaf. Should return the closed one for empty folders.
*/
public Image getLeafIcon();
/**
* Unnecessary for anything not below a GameSource. Can return null.
*
* @return the parent GameSource or null.
*/
public GameSource.Type getDataType();

View File

@@ -29,7 +29,7 @@ public class SaveEvent {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof SaveEvent)) return false;
else return (((SaveEvent)obj).type == this.type) && (((SaveEvent)obj).target == this.target);
else return (((SaveEvent) obj).type == this.type) && (((SaveEvent) obj).target == this.target);
}
}

View File

@@ -1,22 +1,5 @@
package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.SettingsSave;
@@ -25,6 +8,16 @@ import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.ProjectsTree.ProjectsTreeModel;
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Files;
import java.util.List;
import java.util.*;
public class Workspace implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = 7938633033601384956L;
@@ -72,7 +65,7 @@ public class Workspace implements ProjectTreeNode, Serializable {
}
public static void setActive(File workspaceRoot) {
Workspace w = null;
Workspace w;
File f = new File(workspaceRoot, WS_SETTINGS_FILE);
if (!workspaceRoot.exists() || !f.exists()) {
w = new Workspace(workspaceRoot);
@@ -145,7 +138,7 @@ public class Workspace implements ProjectTreeNode, Serializable {
if (projectsTreeModel != null) {
while (path.size() > 1) {
projectsTreeModel.changeNode(new TreePath(path.toArray()));
path.remove(path.size()-1);
path.remove(path.size() - 1);
}
}
@@ -311,7 +304,6 @@ public class Workspace implements ProjectTreeNode, Serializable {
Notification.addError("Error while deleting closed project "
+ cp.name + ". Files may remain in the workspace.");
}
cp = null;
saveActive();
}
@@ -327,7 +319,6 @@ public class Workspace implements ProjectTreeNode, Serializable {
Notification.addError("Error while deleting project " + p.name
+ ". Files may remain in the workspace.");
}
p = null;
saveActive();
}
@@ -339,7 +330,7 @@ public class Workspace implements ProjectTreeNode, Serializable {
for (File c : f.listFiles())
b &= delete(c);
}
return b &= f.delete();
return b & f.delete();
}
@Override

View File

@@ -1,21 +1,16 @@
package com.gpl.rpg.atcontentstudio.model;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
public class WorkspaceSettings {
public static final String VERSION_KEY = "ATCS_Version";
@@ -38,7 +33,7 @@ public class WorkspaceSettings {
public static String DEFAULT_IMG_EDITOR_COMMAND = "gimp";
public Setting<String> imageEditorCommand = new PrimitiveSetting<String>("imageEditorCommand", DEFAULT_IMG_EDITOR_COMMAND);
public static String[] LANGUAGE_LIST = new String[]{null, "de", "ru", "pl", "fr", "it", "es", "nl", "uk", "ca", "sv", "pt", "pt_BR", "zh_Hant", "zh_Hans", "ja", "cs", "tr", "ko", "hu", "sl", "bg", "id", "fi", "th", "gl", "ms" ,"pa", "az", "nb"};
public static String[] LANGUAGE_LIST = new String[]{null, "de", "ru", "pl", "fr", "it", "es", "nl", "uk", "ca", "sv", "pt", "pt_BR", "zh_Hant", "zh_Hans", "ja", "cs", "tr", "ko", "hu", "sl", "bg", "id", "fi", "th", "gl", "ms", "pa", "az", "nb"};
public Setting<String> translatorLanguage = new NullDefaultPrimitiveSetting<String>("translatorLanguage");
public static Boolean DEFAULT_ALLOW_INTERNET = true;
public Setting<Boolean> useInternet = new PrimitiveSetting<Boolean>("useInternet", DEFAULT_ALLOW_INTERNET);
@@ -79,7 +74,7 @@ public class WorkspaceSettings {
}
} catch (Exception e) {
Notification.addError("Error while parsing workspace settings: "+e.getMessage());
Notification.addError("Error while parsing workspace settings: " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -126,7 +121,7 @@ public class WorkspaceSettings {
w.close();
Notification.addSuccess("Workspace settings saved.");
} catch (IOException e) {
Notification.addError("Error while saving workspace settings : "+e.getMessage());
Notification.addError("Error while saving workspace settings : " + e.getMessage());
e.printStackTrace();
}
}
@@ -160,7 +155,7 @@ public class WorkspaceSettings {
public abstract void readFromJson(@SuppressWarnings("rawtypes") Map json);
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public void saveToJson(Map json) {
if (!defaultValue.equals(value)) json.put(id, value);
}
@@ -174,9 +169,9 @@ public class WorkspaceSettings {
this.value = this.defaultValue = defaultValue;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public void readFromJson(Map json) {
if (json.get(id) != null) value = (X)json.get(id);
if (json.get(id) != null) value = (X) json.get(id);
}
@@ -188,7 +183,7 @@ public class WorkspaceSettings {
super(id, null);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void saveToJson(Map json) {
if (value != null) json.put(id, value);
@@ -202,13 +197,13 @@ public class WorkspaceSettings {
this.value = this.defaultValue = defaultValue;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void readFromJson(Map json) {
value = new ArrayList<X>();
if (json.get(id) != null) {
for (Object o : ((List)json.get(id))) {
value.add((X)o);
for (Object o : ((List) json.get(id))) {
value.add((X) o);
}
}
}
@@ -216,5 +211,4 @@ public class WorkspaceSettings {
}
}

View File

@@ -1,12 +1,5 @@
package com.gpl.rpg.atcontentstudio.model.bookmarks;
import java.awt.Image;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.Project;
@@ -15,6 +8,12 @@ import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
public class BookmarkEntry implements BookmarkNode {
public GameDataElement bookmarkedElement;
@@ -64,21 +63,22 @@ public class BookmarkEntry implements BookmarkNode {
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenRemoved(path);
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -87,13 +87,19 @@ public class BookmarkEntry implements BookmarkNode {
@Override
public String getDesc() {
if (bookmarkedElement instanceof QuestStage) {
String text = ((GameDataElement)bookmarkedElement).getDesc();
String text = ((GameDataElement) bookmarkedElement).getDesc();
if (text.length() > 60) {
text = text.substring(0, 57)+"...";
text = text.substring(0, 57) + "...";
}
return ((GameDataElement)bookmarkedElement).getDataType().toString()+"/"+((Quest)((QuestStage)bookmarkedElement).parent).id+"#"+((QuestStage)bookmarkedElement).progress+":"+text;
return ((GameDataElement) bookmarkedElement).getDataType().toString() +
"/" +
((Quest) ((QuestStage) bookmarkedElement).parent).id +
"#" +
((QuestStage) bookmarkedElement).progress +
":" +
text;
} else {
return ((GameDataElement)bookmarkedElement).getDataType().toString()+"/"+((GameDataElement)bookmarkedElement).getDesc();
return ((GameDataElement) bookmarkedElement).getDataType().toString() + "/" + ((GameDataElement) bookmarkedElement).getDesc();
}
}

View File

@@ -1,20 +1,16 @@
package com.gpl.rpg.atcontentstudio.model.bookmarks;
import java.awt.Image;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.util.List;
import java.util.*;
public class BookmarkFolder implements BookmarkNode {
List<BookmarkNode> contents = new LinkedList<BookmarkNode>();
@@ -70,13 +66,13 @@ public class BookmarkFolder implements BookmarkNode {
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenChanged(path);
}
@@ -89,6 +85,7 @@ public class BookmarkFolder implements BookmarkNode {
parent.childrenRemoved(path);
}
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());

View File

@@ -2,9 +2,10 @@ package com.gpl.rpg.atcontentstudio.model.bookmarks;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
public interface BookmarkNode extends ProjectTreeNode{
public interface BookmarkNode extends ProjectTreeNode {
public void save();
public void delete();
}

View File

@@ -1,36 +1,27 @@
package com.gpl.rpg.atcontentstudio.model.bookmarks;
import java.awt.Image;
import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.SavedSlotCollection;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
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.gamedata.*;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
public class BookmarksRoot implements BookmarkNode {
SavedSlotCollection v = new SavedSlotCollection();
public transient Project parent = null;
public transient Project parent;
BookmarkFolder ac, diag, dl, it, ic, npc, q, tmx, sp, wm;
@@ -90,11 +81,13 @@ public class BookmarksRoot implements BookmarkNode {
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
if (path.size() == 1 && this.v.getNonEmptySize() == 1) {
@@ -104,6 +97,7 @@ public class BookmarksRoot implements BookmarkNode {
parent.childrenRemoved(path);
}
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -114,7 +108,7 @@ public class BookmarksRoot implements BookmarkNode {
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+"Bookmarks";
return (needsSaving() ? "*" : "") + "Bookmarks";
}
@Override
@@ -167,11 +161,12 @@ public class BookmarksRoot implements BookmarkNode {
}
@Override
public void delete() {}
public void delete() {
}
public void addBookmark(GameDataElement target) {
BookmarkEntry node;
BookmarkFolder folder = null;
BookmarkFolder folder;
if (target instanceof ActorCondition) {
folder = ac;
} else if (target instanceof Dialogue) {
@@ -197,7 +192,8 @@ public class BookmarksRoot implements BookmarkNode {
}
ProjectTreeNode higherEmptyParent = folder;
while (higherEmptyParent != null) {
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode)higherEmptyParent.getParent()).isEmpty()) higherEmptyParent = (ProjectTreeNode)higherEmptyParent.getParent();
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode) higherEmptyParent.getParent()).isEmpty())
higherEmptyParent = (ProjectTreeNode) higherEmptyParent.getParent();
else break;
}
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;

View File

@@ -1,6 +1,12 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -9,20 +15,13 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
public class ActorCondition extends JSONElement {
private static final long serialVersionUID = -3969824899972048507L;
public static final Integer MAGNITUDE_CLEAR = -99;
public static final Integer DURATION_FOREVER = 999;;
public static final Integer DURATION_FOREVER = 999;
public static final Integer DURATION_NONE = 0;
// Available from init state
@@ -47,10 +46,7 @@ public class ActorCondition extends JSONElement {
}
public static enum VisualEffectID {
redSplash
,blueSwirl
,greenSplash
,miss
redSplash, blueSwirl, greenSplash, miss
}
public static class RoundEffect implements Cloneable {
@@ -98,7 +94,7 @@ public class ActorCondition extends JSONElement {
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+display_name+" ("+id+")";
return (needsSaving() ? "*" : "") + display_name + " (" + id + ")";
}
@SuppressWarnings("rawtypes")
@@ -109,7 +105,7 @@ public class ActorCondition extends JSONElement {
reader = new FileReader(jsonFile);
List actorConditions = (List) parser.parse(reader);
for (Object obj : actorConditions) {
Map aCondJson = (Map)obj;
Map aCondJson = (Map) obj;
ActorCondition aCond = fromJson(aCondJson);
aCond.jsonFile = jsonFile;
aCond.parent = category;
@@ -119,13 +115,13 @@ public class ActorCondition extends JSONElement {
category.add(aCond);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
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());
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());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -166,8 +162,8 @@ public class ActorCondition extends JSONElement {
this.constant_ability_effect = new AbilityEffect();
this.constant_ability_effect.increase_attack_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseAttackChance"));
if (abilityEffect.get("increaseAttackDamage") != null) {
this.constant_ability_effect.increase_damage_min = JSONElement.getInteger((Number) (((Map)abilityEffect.get("increaseAttackDamage")).get("min")));
this.constant_ability_effect.increase_damage_max = JSONElement.getInteger((Number) (((Map)abilityEffect.get("increaseAttackDamage")).get("max")));
this.constant_ability_effect.increase_damage_min = JSONElement.getInteger((Number) (((Map) abilityEffect.get("increaseAttackDamage")).get("min")));
this.constant_ability_effect.increase_damage_max = JSONElement.getInteger((Number) (((Map) abilityEffect.get("increaseAttackDamage")).get("max")));
}
this.constant_ability_effect.max_hp_boost = JSONElement.getInteger((Number) abilityEffect.get("increaseMaxHP"));
this.constant_ability_effect.max_ap_boost = JSONElement.getInteger((Number) abilityEffect.get("increaseMaxAP"));
@@ -184,38 +180,40 @@ public class ActorCondition extends JSONElement {
if (roundEffect != null) {
this.round_effect = new RoundEffect();
if (roundEffect.get("increaseCurrentHP") != null) {
this.round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("max")));
this.round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("min")));
this.round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map) roundEffect.get("increaseCurrentHP")).get("max")));
this.round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map) roundEffect.get("increaseCurrentHP")).get("min")));
}
if (roundEffect.get("increaseCurrentAP") != null) {
this.round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("max")));
this.round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("min")));
this.round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map) roundEffect.get("increaseCurrentAP")).get("max")));
this.round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map) roundEffect.get("increaseCurrentAP")).get("min")));
}
String vfx = (String) roundEffect.get("visualEffectID");
this.round_effect.visual_effect = null;
if (vfx != null) {
try {
this.round_effect.visual_effect = VisualEffectID.valueOf(vfx);
} catch(IllegalArgumentException e) {}
} catch (IllegalArgumentException e) {
}
}
}
Map fullRoundEffect = (Map) aCondJson.get("fullRoundEffect");
if (fullRoundEffect != null) {
this.full_round_effect = new RoundEffect();
if (fullRoundEffect.get("increaseCurrentHP") != null) {
this.full_round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("max")));
this.full_round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("min")));
this.full_round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map) fullRoundEffect.get("increaseCurrentHP")).get("max")));
this.full_round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map) fullRoundEffect.get("increaseCurrentHP")).get("min")));
}
if (fullRoundEffect.get("increaseCurrentAP") != null) {
this.full_round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("max")));
this.full_round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("min")));
this.full_round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map) fullRoundEffect.get("increaseCurrentAP")).get("max")));
this.full_round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map) fullRoundEffect.get("increaseCurrentAP")).get("min")));
}
String vfx = (String) fullRoundEffect.get("visualEffectID");
this.full_round_effect.visual_effect = null;
if (vfx != null) {
try {
this.full_round_effect.visual_effect = VisualEffectID.valueOf(vfx);
} catch(IllegalArgumentException e) {}
} catch (IllegalArgumentException e) {
}
}
}
this.state = State.parsed;
@@ -224,17 +222,10 @@ public class ActorCondition extends JSONElement {
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
if (this.icon_id != null) {
String spritesheetId = this.icon_id.split(":")[0];
if (getProject().getSpritesheet(spritesheetId) == null) {
@@ -295,7 +286,7 @@ public class ActorCondition extends JSONElement {
//Nothing to link to.
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Map toJson() {
Map jsonAC = new LinkedHashMap();
@@ -308,7 +299,8 @@ public class ActorCondition extends JSONElement {
if (this.stacking != null && this.stacking == 1) jsonAC.put("isStacking", this.stacking);
if (this.round_effect != null) {
Map jsonRound = new LinkedHashMap();
if (this.round_effect.visual_effect != null) jsonRound.put("visualEffectID", this.round_effect.visual_effect.toString());
if (this.round_effect.visual_effect != null)
jsonRound.put("visualEffectID", this.round_effect.visual_effect.toString());
if (this.round_effect.hp_boost_min != null || this.round_effect.hp_boost_max != null) {
Map jsonHP = new LinkedHashMap();
if (this.round_effect.hp_boost_min != null) jsonHP.put("min", this.round_effect.hp_boost_min);
@@ -329,7 +321,8 @@ public class ActorCondition extends JSONElement {
}
if (this.full_round_effect != null) {
Map jsonFullRound = new LinkedHashMap();
if (this.full_round_effect.visual_effect != null) jsonFullRound.put("visualEffectID", this.full_round_effect.visual_effect.toString());
if (this.full_round_effect.visual_effect != null)
jsonFullRound.put("visualEffectID", this.full_round_effect.visual_effect.toString());
if (this.full_round_effect.hp_boost_min != null || this.full_round_effect.hp_boost_max != null) {
Map jsonHP = new LinkedHashMap();
if (this.full_round_effect.hp_boost_min != null) jsonHP.put("min", this.full_round_effect.hp_boost_min);
@@ -350,24 +343,36 @@ public class ActorCondition extends JSONElement {
}
if (this.constant_ability_effect != null) {
Map jsonAbility = new LinkedHashMap();
if (this.constant_ability_effect.increase_attack_chance != null) jsonAbility.put("increaseAttackChance", this.constant_ability_effect.increase_attack_chance);
if (this.constant_ability_effect.increase_attack_chance != null)
jsonAbility.put("increaseAttackChance", this.constant_ability_effect.increase_attack_chance);
if (this.constant_ability_effect.increase_damage_min != null || this.constant_ability_effect.increase_damage_max != null) {
Map jsonAD = new LinkedHashMap();
if (this.constant_ability_effect.increase_damage_min != null) jsonAD.put("min", this.constant_ability_effect.increase_damage_min);
if (this.constant_ability_effect.increase_damage_min != null)
jsonAD.put("min", this.constant_ability_effect.increase_damage_min);
else jsonAD.put("min", 0);
if (this.constant_ability_effect.increase_damage_max != null) jsonAD.put("max", this.constant_ability_effect.increase_damage_max);
if (this.constant_ability_effect.increase_damage_max != null)
jsonAD.put("max", this.constant_ability_effect.increase_damage_max);
else jsonAD.put("max", 0);
jsonAbility.put("increaseAttackDamage", jsonAD);
}
if (this.constant_ability_effect.max_hp_boost != null) jsonAbility.put("increaseMaxHP", this.constant_ability_effect.max_hp_boost);
if (this.constant_ability_effect.max_ap_boost != null) jsonAbility.put("increaseMaxAP", this.constant_ability_effect.max_ap_boost);
if (this.constant_ability_effect.increase_move_cost != null) jsonAbility.put("increaseMoveCost", this.constant_ability_effect.increase_move_cost);
if (this.constant_ability_effect.increase_use_cost != null) jsonAbility.put("increaseUseItemCost", this.constant_ability_effect.increase_use_cost);
if (this.constant_ability_effect.increase_reequip_cost != null) jsonAbility.put("increaseReequipCost", this.constant_ability_effect.increase_reequip_cost);
if (this.constant_ability_effect.increase_attack_cost != null) jsonAbility.put("increaseAttackCost", this.constant_ability_effect.increase_attack_cost);
if (this.constant_ability_effect.increase_critical_skill != null) jsonAbility.put("increaseCriticalSkill", this.constant_ability_effect.increase_critical_skill);
if (this.constant_ability_effect.increase_block_chance != null) jsonAbility.put("increaseBlockChance", this.constant_ability_effect.increase_block_chance);
if (this.constant_ability_effect.increase_damage_resistance != null) jsonAbility.put("increaseDamageResistance", this.constant_ability_effect.increase_damage_resistance);
if (this.constant_ability_effect.max_hp_boost != null)
jsonAbility.put("increaseMaxHP", this.constant_ability_effect.max_hp_boost);
if (this.constant_ability_effect.max_ap_boost != null)
jsonAbility.put("increaseMaxAP", this.constant_ability_effect.max_ap_boost);
if (this.constant_ability_effect.increase_move_cost != null)
jsonAbility.put("increaseMoveCost", this.constant_ability_effect.increase_move_cost);
if (this.constant_ability_effect.increase_use_cost != null)
jsonAbility.put("increaseUseItemCost", this.constant_ability_effect.increase_use_cost);
if (this.constant_ability_effect.increase_reequip_cost != null)
jsonAbility.put("increaseReequipCost", this.constant_ability_effect.increase_reequip_cost);
if (this.constant_ability_effect.increase_attack_cost != null)
jsonAbility.put("increaseAttackCost", this.constant_ability_effect.increase_attack_cost);
if (this.constant_ability_effect.increase_critical_skill != null)
jsonAbility.put("increaseCriticalSkill", this.constant_ability_effect.increase_critical_skill);
if (this.constant_ability_effect.increase_block_chance != null)
jsonAbility.put("increaseBlockChance", this.constant_ability_effect.increase_block_chance);
if (this.constant_ability_effect.increase_damage_resistance != null)
jsonAbility.put("increaseDamageResistance", this.constant_ability_effect.increase_damage_resistance);
jsonAC.put("abilityEffect", jsonAbility);
}
return jsonAC;
@@ -375,7 +380,7 @@ public class ActorCondition extends JSONElement {
@Override
public String getProjectFilename() {
return "actorconditions_"+getProject().name+".json";
return "actorconditions_" + getProject().name + ".json";
}
}

View File

@@ -0,0 +1,384 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.Project;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public final class Common {
public static <T extends ActorConditionEffect> void actorConditionElementChanged(List<T> list, GameDataElement oldOne, GameDataElement newOne, GameDataElement backlink) {
if (list != null) {
for (T c : list) {
if (c.condition == oldOne) {
oldOne.removeBacklink(backlink);
c.condition = (ActorCondition) newOne;
if (newOne != null) newOne.addBacklink(backlink);
}
}
}
}
//region link common stuff
public static void linkConditions(List<? extends ActorConditionEffect> conditions, Project proj, GameDataElement backlink) {
if (conditions != null) {
for (ActorConditionEffect ce : conditions) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(backlink);
}
}
}
public static void linkEffects(HitEffect effect, Project proj, GameDataElement backlink) {
linkEffects((DeathEffect) effect, proj, backlink);
if (effect != null) {
linkConditions(effect.conditions_target, proj, backlink);
}
}
public static void linkEffects(DeathEffect effect, Project proj, GameDataElement backlink) {
if (effect != null) {
linkConditions(effect.conditions_source, proj, backlink);
}
}
public static void linkIcon(Project proj, String iconId, GameDataElement backlink) {
if (iconId != null) {
String spritesheetId = iconId.split(":")[0];
if (proj.getSpritesheet(spritesheetId) == null) {
Notification.addError("Error Spritesheet " + spritesheetId + ". has no backlink. (" + iconId + ")");
return;
}
proj.getSpritesheet(spritesheetId).addBacklink(backlink);
}
}
//endregion
//region write common stuff
public static void writeMinMaxToMap(Map parent, Integer min, Integer max, int defaultValue) {
if (min != null || max != null) {
if (min != null)
parent.put("min", min);
else parent.put("min", defaultValue);
if (max != null)
parent.put("max", max);
else parent.put("max", defaultValue);
}
}
public static void writeMinMaxToMap(Map parent, String key, Integer min, Integer max, int defaultValue) {
if (min != null || max != null) {
Map minMaxMap = new LinkedHashMap();
parent.put(key, minMaxMap);
writeMinMaxToMap(minMaxMap, min, max, defaultValue);
}
}
public static void writeDescriptionToMap(Map parent, String description) {
if (description != null) parent.put("description", description);
}
public static void writeIconToMap(Map parent, String icon_id) {
if (icon_id != null) parent.put("iconID", icon_id);
}
public static void writeHitReceivedEffectToMap(Map parent, HitReceivedEffect effect) {
if (effect != null) {
writeHitEffectToMap(parent, effect);
writeBasicEffectObjectToMap(effect.target, parent, "increaseAttackerCurrentHP", "increaseAttackerCurrentAP");
}
}
public static void writeHitReceivedEffectToMap(Map parent, HitReceivedEffect effect, String key) {
if (effect != null) {
Map effectJson = new LinkedHashMap();
parent.put(key, effectJson);
writeHitReceivedEffectToMap(effectJson, effect);
}
}
public static void writeHitEffectToMap(Map parent, HitEffect effect) {
if (effect != null) {
writeDeathEffectToMap(parent, effect);
writeTimedActorConditionEffectObjectToMap(effect.conditions_target, parent, "conditionsTarget");
}
}
public static void writeHitEffectToMap(Map parent, HitEffect effect, String key) {
if (effect != null) {
Map effectJson = new LinkedHashMap();
parent.put(key, effectJson);
writeHitEffectToMap(effectJson, effect);
}
}
public static void writeDeathEffectToMap(Map parent, DeathEffect effect) {
writeBasicEffectObjectToMap(effect, parent, "increaseCurrentHP", "increaseCurrentAP");
writeTimedActorConditionEffectObjectToMap(effect.conditions_source, parent, "conditionsSource");
}
public static void writeDeathEffectToMap(Map parent, DeathEffect effect, String key) {
if (effect != null) {
Map effectJson = new LinkedHashMap();
parent.put(key, effectJson);
writeDeathEffectToMap(effectJson, effect);
}
}
public static void writeBasicEffectObjectToMap(BasicEffect effect, Map parent, String keyHP, String keyAP) {
writeMinMaxToMap(parent, keyHP, effect.hp_boost_min, effect.hp_boost_max, 0);
writeMinMaxToMap(parent, keyAP, effect.ap_boost_min, effect.ap_boost_max, 0);
}
public static void writeTimedActorConditionEffectObjectToMap(List<TimedActorConditionEffect> list, Map parent, String key) {
if (list != null) {
List conditionsSourceJson = new ArrayList();
parent.put(key, conditionsSourceJson);
for (TimedActorConditionEffect condition : list) {
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
writeTimedConditionEffectToMap(condition, conditionJson);
}
}
}
public static void writeConditionEffectToMap(ActorConditionEffect condition, Map parent) {
if (condition.condition != null) {
parent.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
parent.put("condition", condition.condition_id);
}
if (condition.magnitude != null) {
parent.put("magnitude", condition.magnitude);
}
}
public static void writeTimedConditionEffectToMap(TimedActorConditionEffect condition, Map parent) {
writeConditionEffectToMap(condition, parent);
if (condition.duration != null) {
parent.put("duration", condition.duration);
}
if (condition.chance != null) {
parent.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
//endregion
public static class TimedActorConditionEffect extends ActorConditionEffect {
//Available from parsed state
public Integer duration = null;
public Double chance = null;
public TimedActorConditionEffect createClone() {
TimedActorConditionEffect cclone = new TimedActorConditionEffect();
cclone.magnitude = this.magnitude;
cclone.condition_id = this.condition_id;
cclone.condition = this.condition;
cclone.chance = this.chance;
cclone.duration = this.duration;
return cclone;
}
public boolean isInfinite() {
return duration != null && duration.equals(ActorCondition.DURATION_FOREVER);
}
public boolean isImmunity() {
return (super.isClear()) && (duration != null && duration > ActorCondition.DURATION_NONE);
}
@Override
public boolean isClear() {
return (super.isClear()) && (duration == null || duration.equals(ActorCondition.DURATION_NONE));
}
}
public static class ActorConditionEffect {
//Available from parsed state
public Integer magnitude = null;
public String condition_id = null;
//Available from linked state
public ActorCondition condition = null;
public boolean isClear() {
return magnitude == null || magnitude.equals(ActorCondition.MAGNITUDE_CLEAR);
}
}
@SuppressWarnings("rawtypes")
public static ArrayList<TimedActorConditionEffect> parseTimedConditionEffects(List conditionsSourceJson) {
ArrayList<TimedActorConditionEffect> conditions_source;
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
conditions_source = new ArrayList<>();
for (Object conditionJsonObj : conditionsSourceJson) {
Map conditionJson = (Map) conditionJsonObj;
TimedActorConditionEffect condition = new TimedActorConditionEffect();
readConditionEffect(condition, conditionJson);
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null)
condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
conditions_source.add(condition);
}
} else {
conditions_source = null;
}
return conditions_source;
}
@SuppressWarnings("rawtypes")
private static void readConditionEffect(ActorConditionEffect condition, Map conditionJson) {
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
}
@SuppressWarnings("rawtypes")
public static Common.DeathEffect parseDeathEffect(Map killEffect) {
Common.DeathEffect kill_effect = new Common.DeathEffect();
readDeathEffect(killEffect, kill_effect);
return kill_effect;
}
@SuppressWarnings("rawtypes")
public static HitEffect parseHitEffect(Map hitEffect) {
Common.HitEffect hit_effect = new Common.HitEffect();
readHitEffect(hitEffect, hit_effect);
return hit_effect;
}
@SuppressWarnings("rawtypes")
public static HitReceivedEffect parseHitReceivedEffect(Map hitReceivedEffect) {
HitReceivedEffect hit_received_effect = new Common.HitReceivedEffect();
readHitEffect(hitReceivedEffect, hit_received_effect);
if (hitReceivedEffect.get("increaseAttackerCurrentHP") != null) {
hit_received_effect.target.hp_boost_max = JSONElement.getInteger((Number) (((Map) hitReceivedEffect.get("increaseAttackerCurrentHP")).get("max")));
hit_received_effect.target.hp_boost_min = JSONElement.getInteger((Number) (((Map) hitReceivedEffect.get("increaseAttackerCurrentHP")).get("min")));
}
if (hitReceivedEffect.get("increaseAttackerCurrentAP") != null) {
hit_received_effect.target.ap_boost_max = JSONElement.getInteger((Number) (((Map) hitReceivedEffect.get("increaseAttackerCurrentAP")).get("max")));
hit_received_effect.target.ap_boost_min = JSONElement.getInteger((Number) (((Map) hitReceivedEffect.get("increaseAttackerCurrentAP")).get("min")));
}
return hit_received_effect;
}
@SuppressWarnings("rawtypes")
private static void readDeathEffect(Map killEffect, DeathEffect kill_effect) {
if (killEffect.get("increaseCurrentHP") != null) {
kill_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map) killEffect.get("increaseCurrentHP")).get("min")));
kill_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map) killEffect.get("increaseCurrentHP")).get("max")));
}
if (killEffect.get("increaseCurrentAP") != null) {
kill_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map) killEffect.get("increaseCurrentAP")).get("min")));
kill_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map) killEffect.get("increaseCurrentAP")).get("max")));
}
List conditionsSourceJson = (List) killEffect.get("conditionsSource");
kill_effect.conditions_source = parseTimedConditionEffects(conditionsSourceJson);
}
@SuppressWarnings("rawtypes")
private static void readHitEffect(Map hitEffect, HitEffect hit_effect) {
readDeathEffect(hitEffect, hit_effect);
List conditionsTargetJson = (List) hitEffect.get("conditionsTarget");
hit_effect.conditions_target = parseTimedConditionEffects(conditionsTargetJson);
}
public static class BasicEffect {
public Integer hp_boost_min = null;
public Integer hp_boost_max = null;
public Integer ap_boost_min = null;
public Integer ap_boost_max = null;
public boolean isNull() {
if (ap_boost_min != null) return false;
if (ap_boost_max != null) return false;
if (hp_boost_min != null) return false;
if (hp_boost_max != null) return false;
return true;
}
}
public static class DeathEffect extends BasicEffect {
//Available from parsed state
public List<TimedActorConditionEffect> conditions_source = null;
@Override
public boolean isNull() {
if (!super.isNull()) return false;
if (conditions_source != null) return false;
return true;
}
}
public static class HitEffect extends DeathEffect {
//Available from parsed state
public List<TimedActorConditionEffect> conditions_target = null;
@Override
public boolean isNull() {
if (!super.isNull()) return false;
if (conditions_target != null) return false;
return true;
}
}
public static class HitReceivedEffect extends Common.HitEffect {
//Available from parsed state
public BasicEffect target = new BasicEffect();
@Override
public boolean isNull() {
if (!super.isNull()) return false;
if (!target.isNull()) return false;
return true;
}
}
public static void copyDeathEffectValues(Common.DeathEffect target, Common.DeathEffect source, GameDataElement backlink) {
copyEffectValues(target, source);
if (source.conditions_source != null) {
target.conditions_source = new ArrayList<>();
for (TimedActorConditionEffect c : source.conditions_source) {
TimedActorConditionEffect cclone = c.createClone();
if (cclone.condition != null) {
cclone.condition.addBacklink(backlink);
}
target.conditions_source.add(cclone);
}
}
}
private static void copyEffectValues(BasicEffect target, BasicEffect source) {
target.ap_boost_max = source.ap_boost_max;
target.ap_boost_min = source.ap_boost_min;
target.hp_boost_max = source.hp_boost_max;
target.hp_boost_min = source.hp_boost_min;
}
public static void copyHitEffectValues(Common.HitEffect target, Common.HitEffect source, GameDataElement backlink) {
copyDeathEffectValues(target, source, backlink);
if (source.conditions_target != null) {
target.conditions_target = new ArrayList<>();
for (TimedActorConditionEffect c : source.conditions_target) {
TimedActorConditionEffect cclone = c.createClone();
if (cclone.condition != null) {
cclone.condition.addBacklink(backlink);
}
target.conditions_target.add(cclone);
}
}
}
public static void copyHitReceivedEffectValues(Common.HitReceivedEffect target, Common.HitReceivedEffect source, GameDataElement backlink) {
copyHitEffectValues(target, source, backlink);
copyEffectValues(target.target, source.target);
}
}

View File

@@ -1,19 +1,5 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
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.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
@@ -21,6 +7,16 @@ import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement.RequirementType;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.*;
public class Dialogue extends JSONElement {
@@ -95,7 +91,7 @@ public class Dialogue extends JSONElement {
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+id;
return (needsSaving() ? "*" : "") + id;
}
public static String getStaticDesc() {
@@ -110,7 +106,7 @@ public class Dialogue extends JSONElement {
reader = new FileReader(jsonFile);
List dialogues = (List) parser.parse(reader);
for (Object obj : dialogues) {
Map dialogueJson = (Map)obj;
Map dialogueJson = (Map) obj;
Dialogue dialogue = fromJson(dialogueJson);
dialogue.jsonFile = jsonFile;
dialogue.parent = category;
@@ -120,13 +116,13 @@ public class Dialogue extends JSONElement {
category.add(dialogue);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
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());
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());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -162,7 +158,7 @@ public class Dialogue extends JSONElement {
if (repliesJson != null && !repliesJson.isEmpty()) {
this.replies = new ArrayList<Dialogue.Reply>();
for (Object replyJsonObj : repliesJson) {
Map replyJson = (Map)replyJsonObj;
Map replyJson = (Map) replyJsonObj;
Reply reply = new Reply();
reply.text = (String) replyJson.get("text");
reply.next_phrase_id = (String) replyJson.get("nextPhraseID");
@@ -174,10 +170,13 @@ public class Dialogue extends JSONElement {
Requirement requirement = new Requirement();
requirement.jsonFile = this.jsonFile;
requirement.parent = this;
if (requirementJson.get("requireType") != null) requirement.type = RequirementType.valueOf((String) requirementJson.get("requireType"));
if (requirementJson.get("requireType") != null)
requirement.type = RequirementType.valueOf((String) requirementJson.get("requireType"));
requirement.required_obj_id = (String) requirementJson.get("requireID");
if (requirementJson.get("value") != null) requirement.required_value = JSONElement.getInteger(Integer.parseInt(requirementJson.get("value").toString()));
if (requirementJson.get("negate") != null) requirement.negated = (Boolean) requirementJson.get("negate");
if (requirementJson.get("value") != null)
requirement.required_value = JSONElement.getInteger(Integer.parseInt(requirementJson.get("value").toString()));
if (requirementJson.get("negate") != null)
requirement.negated = (Boolean) requirementJson.get("negate");
requirement.state = State.parsed;
reply.requirements.add(requirement);
}
@@ -189,11 +188,13 @@ public class Dialogue extends JSONElement {
if (rewardsJson != null && !rewardsJson.isEmpty()) {
this.rewards = new ArrayList<Dialogue.Reward>();
for (Object rewardJsonObj : rewardsJson) {
Map rewardJson = (Map)rewardJsonObj;
Map rewardJson = (Map) rewardJsonObj;
Reward reward = new Reward();
if (rewardJson.get("rewardType") != null) reward.type = Reward.RewardType.valueOf((String) rewardJson.get("rewardType"));
if (rewardJson.get("rewardType") != null)
reward.type = Reward.RewardType.valueOf((String) rewardJson.get("rewardType"));
if (rewardJson.get("rewardID") != null) reward.reward_obj_id = (String) rewardJson.get("rewardID");
if (rewardJson.get("value") != null) reward.reward_value = JSONElement.getInteger((Number) rewardJson.get("value"));
if (rewardJson.get("value") != null)
reward.reward_value = JSONElement.getInteger((Number) rewardJson.get("value"));
if (rewardJson.get("mapName") != null) reward.map_name = (String) rewardJson.get("mapName");
this.rewards.add(reward);
}
@@ -202,24 +203,15 @@ public class Dialogue extends JSONElement {
}
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking dialogue "+id+". No parent project found.");
Notification.addError("Error linking dialogue " + id + ". No parent project found.");
return;
}
if (this.switch_to_npc_id != null) this.switch_to_npc = proj.getNPC(this.switch_to_npc_id);
@@ -274,7 +266,7 @@ public class Dialogue extends JSONElement {
case removeQuestProgress:
reward.reward_obj = proj.getQuest(reward.reward_obj_id);
if (reward.reward_obj != null && reward.reward_value != null) {
QuestStage stage = ((Quest)reward.reward_obj).getStage(reward.reward_value);
QuestStage stage = ((Quest) reward.reward_obj).getStage(reward.reward_value);
if (stage != null) {
stage.addBacklink(this);
}
@@ -294,7 +286,6 @@ public class Dialogue extends JSONElement {
}
@Override
public Image getIcon() {
return DefaultIcons.getDialogueIcon();
@@ -398,7 +389,7 @@ public class Dialogue extends JSONElement {
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Map toJson() {
Map dialogueJson = new LinkedHashMap();
@@ -412,7 +403,7 @@ public class Dialogue extends JSONElement {
if (this.replies != null) {
List repliesJson = new ArrayList();
dialogueJson.put("replies", repliesJson);
for (Reply reply : this.replies){
for (Reply reply : this.replies) {
Map replyJson = new LinkedHashMap();
repliesJson.add(replyJson);
if (reply.text != null) replyJson.put("text", reply.text);
@@ -464,7 +455,7 @@ public class Dialogue extends JSONElement {
@Override
public String getProjectFilename() {
return "conversationlist_"+getProject().name+".json";
return "conversationlist_" + getProject().name + ".json";
}
}

View File

@@ -1,6 +1,14 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -10,15 +18,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class Droplist extends JSONElement {
@@ -46,7 +45,7 @@ public class Droplist extends JSONElement {
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+id;
return (needsSaving() ? "*" : "") + id;
}
public static String getStaticDesc() {
@@ -61,7 +60,7 @@ public class Droplist extends JSONElement {
reader = new FileReader(jsonFile);
List droplists = (List) parser.parse(reader);
for (Object obj : droplists) {
Map droplistJson = (Map)obj;
Map droplistJson = (Map) obj;
Droplist droplist = fromJson(droplistJson);
droplist.jsonFile = jsonFile;
droplist.parent = category;
@@ -71,13 +70,13 @@ public class Droplist extends JSONElement {
category.add(droplist);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
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());
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());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -111,7 +110,7 @@ public class Droplist extends JSONElement {
if (droppedItemsJson != null && !droppedItemsJson.isEmpty()) {
this.dropped_items = new ArrayList<DroppedItem>();
for (Object droppedItemJsonObj : droppedItemsJson) {
Map droppedItemJson = (Map)droppedItemJsonObj;
Map droppedItemJson = (Map) droppedItemJsonObj;
DroppedItem droppedItem = new DroppedItem();
droppedItem.item_id = (String) droppedItemJson.get("itemID");
//if (droppedItemJson.get("chance") != null) droppedItem.chance = JSONElement.parseChance(droppedItemJson.get("chance").toString());
@@ -129,20 +128,13 @@ public class Droplist extends JSONElement {
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking droplist "+id+". No parent project found.");
Notification.addError("Error linking droplist " + id + ". No parent project found.");
return;
}
if (dropped_items != null) {
@@ -155,7 +147,6 @@ public class Droplist extends JSONElement {
}
public static Image getImage() {
return DefaultIcons.getDroplistImage();
}
@@ -202,7 +193,7 @@ public class Droplist extends JSONElement {
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Map toJson() {
Map droplistJson = new LinkedHashMap();
@@ -236,7 +227,7 @@ public class Droplist extends JSONElement {
@Override
public String getProjectFilename() {
return "droplists_"+getProject().name+".json";
return "droplists_" + getProject().name + ".json";
}
}

View File

@@ -1,31 +1,17 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.tree.TreeNode;
import org.json.simple.JSONArray;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.*;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
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.ui.DefaultIcons;
import org.json.simple.JSONArray;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.io.*;
import java.util.List;
import java.util.*;
public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implements ProjectTreeNode, Serializable {
@@ -74,16 +60,19 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
public Enumeration<E> children() {
return Collections.enumeration(this);
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
if (path.size() == 1 && this.getChildCount() == 1) {
@@ -93,6 +82,7 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
parent.childrenRemoved(path);
}
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -100,9 +90,10 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
node.notifyCreated();
}
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+this.name;
return (needsSaving() ? "*" : "") + this.name;
}
@Override
@@ -119,14 +110,17 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
public Image getIcon() {
return getOpenIcon();
}
@Override
public Image getClosedIcon() {
return DefaultIcons.getJsonClosedIcon();
}
@Override
public Image getLeafIcon() {
return DefaultIcons.getJsonClosedIcon();
}
@Override
public Image getOpenIcon() {
return DefaultIcons.getJsonOpenIcon();
@@ -145,7 +139,7 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
@SuppressWarnings("rawtypes")
public void save(File jsonFile) {
if (getDataType() != GameSource.Type.created && getDataType() != GameSource.Type.altered) {
Notification.addError("Error while trying to write json file "+jsonFile.getAbsolutePath()+" : Game Source type "+getDataType().toString()+" should not be saved.");
Notification.addError("Error while trying to write json file " + jsonFile.getAbsolutePath() + " : Game Source type " + getDataType().toString() + " should not be saved.");
return;
}
List<Map> dataToSave = new ArrayList<Map>();
@@ -156,9 +150,9 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
}
if (dataToSave.isEmpty() && jsonFile.exists()) {
if (jsonFile.delete()) {
Notification.addSuccess("File "+jsonFile.getAbsolutePath()+" deleted.");
Notification.addSuccess("File " + jsonFile.getAbsolutePath() + " deleted.");
} else {
Notification.addError("Error deleting file "+jsonFile.getAbsolutePath());
Notification.addError("Error deleting file " + jsonFile.getAbsolutePath());
}
return;
@@ -177,9 +171,9 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
for (E element : this) {
element.state = GameDataElement.State.saved;
}
Notification.addSuccess("Json file "+jsonFile.getAbsolutePath()+" saved.");
Notification.addSuccess("Json file " + jsonFile.getAbsolutePath() + " saved.");
} catch (IOException e) {
Notification.addError("Error while writing json file "+jsonFile.getAbsolutePath()+" : "+e.getMessage());
Notification.addError("Error while writing json file " + jsonFile.getAbsolutePath() + " : " + e.getMessage());
e.printStackTrace();
}
@@ -226,7 +220,8 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
break;
}
}
events.add(new SaveEvent(SaveEvent.Type.alsoSave, node, true, "There are "+containedIds.get(node.id)+" elements with this ID in this category. Change the conflicting IDs before saving."));
events.add(new SaveEvent(SaveEvent.Type.alsoSave, node, true,
"There are " + containedIds.get(node.id) + " elements with this ID in this category. Change the conflicting IDs before saving."));
}
}
if (checkImpactedCategory && impactedCategory != null) {

View File

@@ -1,14 +1,5 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
@@ -18,13 +9,21 @@ import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.SavedSlotCollection;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
public class GameDataSet implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = -8558067213826970968L;
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res"+File.separator+"raw"+File.separator;
public static final String DEFAULT_REL_PATH_IN_PROJECT = "json"+File.separator;
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res" + File.separator + "raw" + File.separator;
public static final String DEFAULT_REL_PATH_IN_PROJECT = "json" + File.separator;
public static final String GAME_AC_ARRAY_NAME = "loadresource_actorconditions";
public static final String GAME_DIALOGUES_ARRAY_NAME = "loadresource_conversationlists";
@@ -82,79 +81,79 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
if (parent.type == GameSource.Type.source && (parent.parent.sourceSetToUse == ResourceSet.debugData || parent.parent.sourceSetToUse == ResourceSet.gameData)) {
String suffix = (parent.parent.sourceSetToUse == ResourceSet.debugData) ? DEBUG_SUFFIX : "";
if (parent.referencedSourceFiles.get(GAME_AC_ARRAY_NAME+suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_AC_ARRAY_NAME+suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "")+FILENAME_SUFFIX);
if (parent.referencedSourceFiles.get(GAME_AC_ARRAY_NAME + suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_AC_ARRAY_NAME + suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "") + FILENAME_SUFFIX);
if (f.exists()) {
ActorCondition.fromJson(f, actorConditions);
} else {
Notification.addWarn("Unable to locate resource "+resource+" in the game source for project "+getProject().name);
Notification.addWarn("Unable to locate resource " + resource + " in the game source for project " + getProject().name);
}
}
}
if (parent.referencedSourceFiles.get(GAME_DIALOGUES_ARRAY_NAME+suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_DIALOGUES_ARRAY_NAME+suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "")+FILENAME_SUFFIX);
if (parent.referencedSourceFiles.get(GAME_DIALOGUES_ARRAY_NAME + suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_DIALOGUES_ARRAY_NAME + suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "") + FILENAME_SUFFIX);
if (f.exists()) {
Dialogue.fromJson(f, dialogues);
} else {
Notification.addWarn("Unable to locate resource "+resource+" in the game source for project "+getProject().name);
Notification.addWarn("Unable to locate resource " + resource + " in the game source for project " + getProject().name);
}
}
}
if (parent.referencedSourceFiles.get(GAME_DROPLISTS_ARRAY_NAME+suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_DROPLISTS_ARRAY_NAME+suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "")+FILENAME_SUFFIX);
if (parent.referencedSourceFiles.get(GAME_DROPLISTS_ARRAY_NAME + suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_DROPLISTS_ARRAY_NAME + suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "") + FILENAME_SUFFIX);
if (f.exists()) {
Droplist.fromJson(f, droplists);
} else {
Notification.addWarn("Unable to locate resource "+resource+" in the game source for project "+getProject().name);
Notification.addWarn("Unable to locate resource " + resource + " in the game source for project " + getProject().name);
}
}
}
if (parent.referencedSourceFiles.get(GAME_ITEMS_ARRAY_NAME+suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_ITEMS_ARRAY_NAME+suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "")+FILENAME_SUFFIX);
if (parent.referencedSourceFiles.get(GAME_ITEMS_ARRAY_NAME + suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_ITEMS_ARRAY_NAME + suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "") + FILENAME_SUFFIX);
if (f.exists()) {
Item.fromJson(f, items);
} else {
Notification.addWarn("Unable to locate resource "+resource+" in the game source for project "+getProject().name);
Notification.addWarn("Unable to locate resource " + resource + " in the game source for project " + getProject().name);
}
}
}
if (parent.referencedSourceFiles.get(GAME_ITEMCAT_ARRAY_NAME+suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_ITEMCAT_ARRAY_NAME+suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "")+FILENAME_SUFFIX);
if (parent.referencedSourceFiles.get(GAME_ITEMCAT_ARRAY_NAME + suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_ITEMCAT_ARRAY_NAME + suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "") + FILENAME_SUFFIX);
if (f.exists()) {
ItemCategory.fromJson(f, itemCategories);
} else {
Notification.addWarn("Unable to locate resource "+resource+" in the game source for project "+getProject().name);
Notification.addWarn("Unable to locate resource " + resource + " in the game source for project " + getProject().name);
}
}
}
if (parent.referencedSourceFiles.get(GAME_NPC_ARRAY_NAME+suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_NPC_ARRAY_NAME+suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "")+FILENAME_SUFFIX);
if (parent.referencedSourceFiles.get(GAME_NPC_ARRAY_NAME + suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_NPC_ARRAY_NAME + suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "") + FILENAME_SUFFIX);
if (f.exists()) {
NPC.fromJson(f, npcs);
} else {
Notification.addWarn("Unable to locate resource "+resource+" in the game source for project "+getProject().name);
Notification.addWarn("Unable to locate resource " + resource + " in the game source for project " + getProject().name);
}
}
}
if (parent.referencedSourceFiles.get(GAME_QUESTS_ARRAY_NAME+suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_QUESTS_ARRAY_NAME+suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "")+FILENAME_SUFFIX);
if (parent.referencedSourceFiles.get(GAME_QUESTS_ARRAY_NAME + suffix) != null) {
for (String resource : parent.referencedSourceFiles.get(GAME_QUESTS_ARRAY_NAME + suffix)) {
File f = new File(baseFolder, resource.replaceAll(RESOURCE_PREFIX, "") + FILENAME_SUFFIX);
if (f.exists()) {
Quest.fromJson(f, quests);
} else {
Notification.addWarn("Unable to locate resource "+resource+" in the game source for project "+getProject().name);
Notification.addWarn("Unable to locate resource " + resource + " in the game source for project " + getProject().name);
}
}
}
@@ -184,40 +183,49 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public Enumeration<ProjectTreeNode> children() {
return v.getNonEmptyElements();
}
@Override
public boolean getAllowsChildren() {
return true;
}
@Override
public TreeNode getChildAt(int arg0) {
return v.getNonEmptyElementAt(arg0);
}
@Override
public int getChildCount() {
return v.getNonEmptySize();
}
@Override
public int getIndex(TreeNode arg0) {
return v.getNonEmptyIndexOf((ProjectTreeNode) arg0);
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public boolean isLeaf() {
return false;
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
if (path.size() == 1 && this.v.getNonEmptySize() == 1) {
@@ -227,6 +235,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
parent.childrenRemoved(path);
}
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -234,9 +243,10 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
node.notifyCreated();
}
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+"JSON data";
return (needsSaving() ? "*" : "") + "JSON data";
}
@@ -247,7 +257,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public ActorCondition getActorCondition(String id) {
if (actorConditions == null) return null;
for (ActorCondition gde : actorConditions) {
if (id.equals(gde.id)){
if (id.equals(gde.id)) {
return gde;
}
}
@@ -257,7 +267,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public Dialogue getDialogue(String id) {
if (dialogues == null) return null;
for (Dialogue gde : dialogues) {
if (id.equals(gde.id)){
if (id.equals(gde.id)) {
return gde;
}
}
@@ -267,7 +277,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public Droplist getDroplist(String id) {
if (droplists == null) return null;
for (Droplist gde : droplists) {
if (id.equals(gde.id)){
if (id.equals(gde.id)) {
return gde;
}
}
@@ -277,7 +287,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public Item getItem(String id) {
if (items == null) return null;
for (Item gde : items) {
if (id.equals(gde.id)){
if (id.equals(gde.id)) {
return gde;
}
}
@@ -287,7 +297,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public ItemCategory getItemCategory(String id) {
if (itemCategories == null) return null;
for (ItemCategory gde : itemCategories) {
if (id.equals(gde.id)){
if (id.equals(gde.id)) {
return gde;
}
}
@@ -297,7 +307,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public NPC getNPC(String id) {
if (npcs == null) return null;
for (NPC gde : npcs) {
if (id.equals(gde.id)){
if (id.equals(gde.id)) {
return gde;
}
}
@@ -307,7 +317,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public NPC getNPCIgnoreCase(String id) {
if (npcs == null) return null;
for (NPC gde : npcs) {
if (id.equalsIgnoreCase(gde.id)){
if (id.equalsIgnoreCase(gde.id)) {
return gde;
}
}
@@ -317,7 +327,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public Quest getQuest(String id) {
if (quests == null) return null;
for (Quest gde : quests) {
if (id.equals(gde.id)){
if (id.equals(gde.id)) {
return gde;
}
}
@@ -334,14 +344,17 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public Image getIcon() {
return getOpenIcon();
}
@Override
public Image getClosedIcon() {
return DefaultIcons.getJsonClosedIcon();
}
@Override
public Image getLeafIcon() {
return DefaultIcons.getJsonClosedIcon();
}
@Override
public Image getOpenIcon() {
return DefaultIcons.getJsonOpenIcon();
@@ -350,7 +363,8 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
public void addElement(JSONElement node) {
ProjectTreeNode higherEmptyParent = this;
while (higherEmptyParent != null) {
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode)higherEmptyParent.getParent()).isEmpty()) higherEmptyParent = (ProjectTreeNode)higherEmptyParent.getParent();
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode) higherEmptyParent.getParent()).isEmpty())
higherEmptyParent = (ProjectTreeNode) higherEmptyParent.getParent();
else break;
}
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;
@@ -383,7 +397,7 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
quests.add((Quest) node);
node.parent = quests;
} else {
Notification.addError("Cannot add "+node.getDesc()+". Unknown data type.");
Notification.addError("Cannot add " + node.getDesc() + ". Unknown data type.");
return;
}
if (node.jsonFile != null && parent.type == GameSource.Type.altered) {

View File

@@ -1,6 +1,13 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -10,13 +17,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import static com.gpl.rpg.atcontentstudio.model.gamedata.Common.*;
public class Item extends JSONElement {
@@ -35,45 +36,20 @@ public class Item extends JSONElement {
public String description = null;
public HitEffect hit_effect = null;
public HitReceivedEffect hit_received_effect = null;
public KillEffect kill_effect = null;
public DeathEffect kill_effect = null;
public EquipEffect equip_effect = null;
//Available from linked state
public ItemCategory category = null;
public static class KillEffect {
//Available from parsed state
public Integer hp_boost_min = null;
public Integer hp_boost_max = null;
public Integer ap_boost_min = null;
public Integer ap_boost_max = null;
public List<TimedConditionEffect> conditions_source = null;
}
//Inheritance for code compactness, not semantically correct.
public static class HitEffect extends KillEffect {
//Available from parsed state
public List<TimedConditionEffect> conditions_target = null;
}
public static class HitReceivedEffect extends HitEffect {
//Available from parsed state
public Integer hp_boost_min_target = null;
public Integer hp_boost_max_target = null;
public Integer ap_boost_min_target = null;
public Integer ap_boost_max_target = null;
}
public static class EquipEffect {
//Available from parsed state
public Integer damage_boost_min = null;
public Integer damage_boost_max = null;
public Integer max_hp_boost = null;
public Integer max_ap_boost = null;
public List<ConditionEffect> conditions = null;
public List<ActorConditionEffect> conditions = null;
public Integer increase_move_cost = null;
public Integer increase_use_item_cost = null;
public Integer increase_reequip_cost = null;
@@ -86,20 +62,6 @@ public class Item extends JSONElement {
public Integer damage_modifier = null;
}
public static class ConditionEffect {
//Available from parsed state
public Integer magnitude = null;
public String condition_id = null;
//Available from linked state
public ActorCondition condition = null;
}
public static class TimedConditionEffect extends ConditionEffect {
//Available from parsed state
public Integer duration = null;
public Double chance = null;
}
public static enum DisplayType {
ordinary,
@@ -111,7 +73,7 @@ public class Item extends JSONElement {
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+name+" ("+id+")";
return (needsSaving() ? "*" : "") + name + " (" + id + ")";
}
public static String getStaticDesc() {
@@ -126,7 +88,7 @@ public class Item extends JSONElement {
reader = new FileReader(jsonFile);
List items = (List) parser.parse(reader);
for (Object obj : items) {
Map itemJson = (Map)obj;
Map itemJson = (Map) obj;
Item item = fromJson(itemJson);
item.jsonFile = jsonFile;
item.parent = category;
@@ -136,13 +98,13 @@ public class Item extends JSONElement {
category.add(item);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
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());
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());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -168,7 +130,8 @@ public class Item extends JSONElement {
item.icon_id = (String) itemJson.get("iconID");
item.id = (String) itemJson.get("id");
item.name = (String) itemJson.get("name");
if (itemJson.get("displaytype") != null) item.display_type = DisplayType.valueOf((String) itemJson.get("displaytype"));
if (itemJson.get("displaytype") != null)
item.display_type = DisplayType.valueOf((String) itemJson.get("displaytype"));
return item;
}
@@ -187,8 +150,8 @@ public class Item extends JSONElement {
if (equipEffect != null) {
this.equip_effect = new EquipEffect();
if (equipEffect.get("increaseAttackDamage") != null) {
this.equip_effect.damage_boost_min = JSONElement.getInteger((Number) (((Map)equipEffect.get("increaseAttackDamage")).get("min")));
this.equip_effect.damage_boost_max = JSONElement.getInteger((Number) (((Map)equipEffect.get("increaseAttackDamage")).get("max")));
this.equip_effect.damage_boost_min = JSONElement.getInteger((Number) (((Map) equipEffect.get("increaseAttackDamage")).get("min")));
this.equip_effect.damage_boost_max = JSONElement.getInteger((Number) (((Map) equipEffect.get("increaseAttackDamage")).get("max")));
}
this.equip_effect.max_hp_boost = JSONElement.getInteger((Number) equipEffect.get("increaseMaxHP"));
this.equip_effect.max_ap_boost = JSONElement.getInteger((Number) equipEffect.get("increaseMaxAP"));
@@ -202,15 +165,16 @@ public class Item extends JSONElement {
this.equip_effect.increase_damage_resistance = JSONElement.getInteger((Number) equipEffect.get("increaseDamageResistance"));
//TODO correct game data, to unify format.
// this.equip_effect.critical_multiplier = JSONElement.getDouble((Number) equipEffect.get("setCriticalMultiplier"));
if (equipEffect.get("setCriticalMultiplier") != null) this.equip_effect.critical_multiplier = JSONElement.getDouble(Double.parseDouble(equipEffect.get("setCriticalMultiplier").toString()));
if (equipEffect.get("setCriticalMultiplier") != null)
this.equip_effect.critical_multiplier = JSONElement.getDouble(Double.parseDouble(equipEffect.get("setCriticalMultiplier").toString()));
this.equip_effect.damage_modifier = JSONElement.getInteger((Number) equipEffect.get("setNonWeaponDamageModifier"));
List conditionsJson = (List) equipEffect.get("addedConditions");
if (conditionsJson != null && !conditionsJson.isEmpty()) {
this.equip_effect.conditions = new ArrayList<Item.ConditionEffect>();
this.equip_effect.conditions = new ArrayList<>();
for (Object conditionJsonObj : conditionsJson) {
Map conditionJson = (Map)conditionJsonObj;
ConditionEffect condition = new ConditionEffect();
Map conditionJson = (Map) conditionJsonObj;
ActorConditionEffect condition = new ActorConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
this.equip_effect.conditions.add(condition);
@@ -221,88 +185,12 @@ public class Item extends JSONElement {
Map hitEffect = (Map) itemJson.get("hitEffect");
if (hitEffect != null) {
this.hit_effect = new HitEffect();
if (hitEffect.get("increaseCurrentHP") != null) {
this.hit_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentHP")).get("min")));
this.hit_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentHP")).get("max")));
}
if (hitEffect.get("increaseCurrentAP") != null) {
this.hit_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentAP")).get("min")));
this.hit_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentAP")).get("max")));
}
List conditionsSourceJson = (List) hitEffect.get("conditionsSource");
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
this.hit_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsSourceJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.hit_effect.conditions_source.add(condition);
}
}
List conditionsTargetJson = (List) hitEffect.get("conditionsTarget");
if (conditionsTargetJson != null && !conditionsTargetJson.isEmpty()) {
this.hit_effect.conditions_target = new ArrayList<Item.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsTargetJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.hit_effect.conditions_target.add(condition);
}
}
this.hit_effect = parseHitEffect(hitEffect);
}
Map hitReceivedEffect = (Map) itemJson.get("hitReceivedEffect");
if (hitReceivedEffect != null) {
this.hit_received_effect = new HitReceivedEffect();
if (hitReceivedEffect.get("increaseCurrentHP") != null) {
this.hit_received_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseCurrentHP")).get("min")));
this.hit_received_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseCurrentHP")).get("max")));
}
if (hitReceivedEffect.get("increaseCurrentAP") != null) {
this.hit_received_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseCurrentAP")).get("min")));
this.hit_received_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseCurrentAP")).get("max")));
}
if (hitReceivedEffect.get("increaseAttackerCurrentHP") != null) {
this.hit_received_effect.hp_boost_min_target = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseAttackerCurrentHP")).get("min")));
this.hit_received_effect.hp_boost_max_target = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseAttackerCurrentHP")).get("max")));
}
if (hitReceivedEffect.get("increaseAttackerCurrentAP") != null) {
this.hit_received_effect.ap_boost_min_target = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseAttackerCurrentAP")).get("min")));
this.hit_received_effect.ap_boost_max_target = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseAttackerCurrentAP")).get("max")));
}
List conditionsSourceJson = (List) hitReceivedEffect.get("conditionsSource");
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
this.hit_received_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsSourceJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.hit_received_effect.conditions_source.add(condition);
}
}
List conditionsTargetJson = (List) hitReceivedEffect.get("conditionsTarget");
if (conditionsTargetJson != null && !conditionsTargetJson.isEmpty()) {
this.hit_received_effect.conditions_target = new ArrayList<Item.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsTargetJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.hit_received_effect.conditions_target.add(condition);
}
}
this.hit_received_effect = parseHitReceivedEffect(hitReceivedEffect);
}
Map killEffect = (Map) itemJson.get("killEffect");
@@ -310,28 +198,7 @@ public class Item extends JSONElement {
killEffect = (Map) itemJson.get("useEffect");
}
if (killEffect != null) {
this.kill_effect = new KillEffect();
if (killEffect.get("increaseCurrentHP") != null) {
this.kill_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)killEffect.get("increaseCurrentHP")).get("min")));
this.kill_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)killEffect.get("increaseCurrentHP")).get("max")));
}
if (killEffect.get("increaseCurrentAP") != null) {
this.kill_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)killEffect.get("increaseCurrentAP")).get("min")));
this.kill_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)killEffect.get("increaseCurrentAP")).get("max")));
}
List conditionsSourceJson = (List) killEffect.get("conditionsSource");
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
this.kill_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsSourceJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.kill_effect.conditions_source.add(condition);
}
}
this.kill_effect = parseDeathEffect(killEffect);
}
this.state = State.parsed;
}
@@ -339,68 +206,30 @@ public class Item extends JSONElement {
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking item "+id+". No parent project found.");
Notification.addError("Error linking item " + id + ". No parent project found.");
return;
}
if (this.icon_id != null) {
String spritesheetId = this.icon_id.split(":")[0];
proj.getSpritesheet(spritesheetId).addBacklink(this);
}
linkIcon(proj, this.icon_id, this);
if (this.category_id != null) this.category = proj.getItemCategory(this.category_id);
if (this.category != null) this.category.addBacklink(this);
if (this.equip_effect != null && this.equip_effect.conditions != null) {
for (ConditionEffect ce : this.equip_effect.conditions) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
if (this.hit_effect != null && this.hit_effect.conditions_source != null) {
for (TimedConditionEffect ce : this.hit_effect.conditions_source) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
if (this.hit_effect != null && this.hit_effect.conditions_target != null) {
for (TimedConditionEffect ce : this.hit_effect.conditions_target) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
if (this.hit_received_effect != null && this.hit_received_effect.conditions_source != null) {
for (TimedConditionEffect ce : this.hit_received_effect.conditions_source) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
if (this.hit_received_effect != null && this.hit_received_effect.conditions_target != null) {
for (TimedConditionEffect ce : this.hit_received_effect.conditions_target) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
if (this.kill_effect != null && this.kill_effect.conditions_source != null) {
for (TimedConditionEffect ce : this.kill_effect.conditions_source) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
linkConditions(this.equip_effect.conditions, proj, this);
}
linkEffects(this.hit_effect, proj, this);
linkEffects(this.hit_received_effect, proj, this);
linkEffects(this.kill_effect, proj, this);
this.state = State.linked;
}
@Override
public Image getIcon() {
return getProject().getIcon(icon_id);
@@ -444,9 +273,9 @@ public class Item extends JSONElement {
clone.equip_effect.max_ap_boost = this.equip_effect.max_ap_boost;
clone.equip_effect.max_hp_boost = this.equip_effect.max_hp_boost;
if (this.equip_effect.conditions != null) {
clone.equip_effect.conditions = new ArrayList<Item.ConditionEffect>();
for (ConditionEffect c : this.equip_effect.conditions) {
ConditionEffect cclone = new ConditionEffect();
clone.equip_effect.conditions = new ArrayList<>();
for (ActorConditionEffect c : this.equip_effect.conditions) {
ActorConditionEffect cclone = new ActorConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
@@ -459,103 +288,15 @@ public class Item extends JSONElement {
}
if (this.hit_effect != null) {
clone.hit_effect = new HitEffect();
clone.hit_effect.ap_boost_max = this.hit_effect.ap_boost_max;
clone.hit_effect.ap_boost_min = this.hit_effect.ap_boost_min;
clone.hit_effect.hp_boost_max = this.hit_effect.hp_boost_max;
clone.hit_effect.hp_boost_min = this.hit_effect.hp_boost_min;
if (this.hit_effect.conditions_source != null) {
clone.hit_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
for (TimedConditionEffect c : this.hit_effect.conditions_source) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.hit_effect.conditions_source.add(cclone);
}
}
if (this.hit_effect.conditions_target != null) {
clone.hit_effect.conditions_target = new ArrayList<Item.TimedConditionEffect>();
for (TimedConditionEffect c : this.hit_effect.conditions_target) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.hit_effect.conditions_target.add(cclone);
}
}
copyHitEffectValues(clone.hit_effect, this.hit_effect, clone);
}
if (this.hit_received_effect != null) {
clone.hit_received_effect = new HitReceivedEffect();
clone.hit_received_effect.ap_boost_max = this.hit_received_effect.ap_boost_max;
clone.hit_received_effect.ap_boost_min = this.hit_received_effect.ap_boost_min;
clone.hit_received_effect.hp_boost_max = this.hit_received_effect.hp_boost_max;
clone.hit_received_effect.hp_boost_min = this.hit_received_effect.hp_boost_min;
clone.hit_received_effect.ap_boost_max_target = this.hit_received_effect.ap_boost_max_target;
clone.hit_received_effect.ap_boost_min_target = this.hit_received_effect.ap_boost_min_target;
clone.hit_received_effect.hp_boost_max_target = this.hit_received_effect.hp_boost_max_target;
clone.hit_received_effect.hp_boost_min_target = this.hit_received_effect.hp_boost_min_target;
if (this.hit_received_effect.conditions_source != null) {
clone.hit_received_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
for (TimedConditionEffect c : this.hit_received_effect.conditions_source) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.hit_received_effect.conditions_source.add(cclone);
}
}
if (this.hit_received_effect.conditions_target != null) {
clone.hit_received_effect.conditions_target = new ArrayList<Item.TimedConditionEffect>();
for (TimedConditionEffect c : this.hit_received_effect.conditions_target) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.hit_received_effect.conditions_target.add(cclone);
}
}
copyHitReceivedEffectValues(clone.hit_received_effect, this.hit_received_effect, clone);
}
if (this.kill_effect != null) {
clone.kill_effect = new KillEffect();
clone.kill_effect.ap_boost_max = this.kill_effect.ap_boost_max;
clone.kill_effect.ap_boost_min = this.kill_effect.ap_boost_min;
clone.kill_effect.hp_boost_max = this.kill_effect.hp_boost_max;
clone.kill_effect.hp_boost_min = this.kill_effect.hp_boost_min;
if (this.kill_effect.conditions_source != null) {
clone.kill_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
for (TimedConditionEffect c : this.kill_effect.conditions_source) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.kill_effect.conditions_source.add(cclone);
}
}
clone.kill_effect = new DeathEffect();
copyDeathEffectValues(clone.kill_effect, this.kill_effect, clone);
}
return clone;
}
@@ -567,54 +308,30 @@ public class Item extends JSONElement {
this.category = (ItemCategory) newOne;
if (newOne != null) newOne.addBacklink(this);
} else {
if (this.equip_effect != null && this.equip_effect.conditions != null) {
for (ConditionEffect c : this.equip_effect.conditions) {
if (c.condition == oldOne) {
oldOne.removeBacklink(this);
c.condition = (ActorCondition) newOne;
if (newOne != null) newOne.addBacklink(this);
if (this.equip_effect != null) {
if (this.equip_effect.conditions != null) {
actorConditionElementChanged(this.equip_effect.conditions, oldOne, newOne, this);
}
}
if (this.hit_effect != null) {
actorConditionElementChanged(this.hit_effect.conditions_source, oldOne, newOne, this);
actorConditionElementChanged(this.hit_effect.conditions_target, oldOne, newOne, this);
}
if (this.hit_effect != null && this.hit_effect.conditions_source != null) {
for (TimedConditionEffect c : this.hit_effect.conditions_source) {
if (c.condition == oldOne) {
oldOne.removeBacklink(this);
c.condition = (ActorCondition) newOne;
if (newOne != null) newOne.addBacklink(this);
}
}
}
if (this.hit_effect != null && this.hit_effect.conditions_target != null) {
for (TimedConditionEffect c : this.hit_effect.conditions_target) {
if (c.condition == oldOne) {
oldOne.removeBacklink(this);
c.condition = (ActorCondition) newOne;
if (newOne != null) newOne.addBacklink(this);
if (this.kill_effect != null) {
actorConditionElementChanged(this.kill_effect.conditions_source, oldOne, newOne, this);
}
}
}
if (this.kill_effect != null && this.kill_effect.conditions_source != null) {
for (TimedConditionEffect c : this.kill_effect.conditions_source) {
if (c.condition == oldOne) {
oldOne.removeBacklink(this);
c.condition = (ActorCondition) newOne;
if (newOne != null) newOne.addBacklink(this);
}
}
}
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Map toJson() {
Map itemJson = new LinkedHashMap();
itemJson.put("id", this.id);
if (this.icon_id != null) itemJson.put("iconID", this.icon_id);
writeIconToMap(itemJson, this.icon_id);
if (this.name != null) itemJson.put("name", this.name);
if(this.display_type != null) itemJson.put("displaytype", this.display_type.toString());
if (this.display_type != null) itemJson.put("displaytype", this.display_type.toString());
if (this.has_manual_price != null) itemJson.put("hasManualPrice", this.has_manual_price);
if (this.base_market_cost != null) itemJson.put("baseMarketCost", this.base_market_cost);
@@ -623,211 +340,68 @@ public class Item extends JSONElement {
} else if (this.category_id != null) {
itemJson.put("category", this.category_id);
}
if (this.description != null) itemJson.put("description", this.description);
writeDescriptionToMap(itemJson, this.description);
if (this.equip_effect != null) {
Map equipEffectJson = new LinkedHashMap();
itemJson.put("equipEffect", equipEffectJson);
if (this.equip_effect.damage_boost_min != null || this.equip_effect.damage_boost_max != null) {
Map damageJson = new LinkedHashMap();
equipEffectJson.put("increaseAttackDamage", damageJson);
if (this.equip_effect.damage_boost_min != null) damageJson.put("min", this.equip_effect.damage_boost_min);
else damageJson.put("min", 0);
if (this.equip_effect.damage_boost_max != null) damageJson.put("max", this.equip_effect.damage_boost_max);
else damageJson.put("max", 0);
}
if (this.equip_effect.max_hp_boost != null) equipEffectJson.put("increaseMaxHP", this.equip_effect.max_hp_boost);
if (this.equip_effect.max_ap_boost != null) equipEffectJson.put("increaseMaxAP", this.equip_effect.max_ap_boost);
if (this.equip_effect.increase_move_cost != null) equipEffectJson.put("increaseMoveCost", this.equip_effect.increase_move_cost);
if (this.equip_effect.increase_use_item_cost != null) equipEffectJson.put("increaseUseItemCost", this.equip_effect.increase_use_item_cost);
if (this.equip_effect.increase_reequip_cost != null) equipEffectJson.put("increaseReequipCost", this.equip_effect.increase_reequip_cost);
if (this.equip_effect.increase_attack_cost != null) equipEffectJson.put("increaseAttackCost", this.equip_effect.increase_attack_cost);
if (this.equip_effect.increase_attack_chance != null) equipEffectJson.put("increaseAttackChance", this.equip_effect.increase_attack_chance);
if (this.equip_effect.increase_critical_skill != null) equipEffectJson.put("increaseCriticalSkill", this.equip_effect.increase_critical_skill);
if (this.equip_effect.increase_block_chance != null) equipEffectJson.put("increaseBlockChance", this.equip_effect.increase_block_chance);
if (this.equip_effect.increase_damage_resistance != null) equipEffectJson.put("increaseDamageResistance", this.equip_effect.increase_damage_resistance);
if (this.equip_effect.critical_multiplier != null) equipEffectJson.put("setCriticalMultiplier", this.equip_effect.critical_multiplier);
if (this.equip_effect.damage_modifier != null) equipEffectJson.put("setNonWeaponDamageModifier", this.equip_effect.damage_modifier);
writeMinMaxToMap(equipEffectJson, "increaseAttackDamage", this.equip_effect.damage_boost_min, this.equip_effect.damage_boost_max, 0);
if (this.equip_effect.max_hp_boost != null)
equipEffectJson.put("increaseMaxHP", this.equip_effect.max_hp_boost);
if (this.equip_effect.max_ap_boost != null)
equipEffectJson.put("increaseMaxAP", this.equip_effect.max_ap_boost);
if (this.equip_effect.increase_move_cost != null)
equipEffectJson.put("increaseMoveCost", this.equip_effect.increase_move_cost);
if (this.equip_effect.increase_use_item_cost != null)
equipEffectJson.put("increaseUseItemCost", this.equip_effect.increase_use_item_cost);
if (this.equip_effect.increase_reequip_cost != null)
equipEffectJson.put("increaseReequipCost", this.equip_effect.increase_reequip_cost);
if (this.equip_effect.increase_attack_cost != null)
equipEffectJson.put("increaseAttackCost", this.equip_effect.increase_attack_cost);
if (this.equip_effect.increase_attack_chance != null)
equipEffectJson.put("increaseAttackChance", this.equip_effect.increase_attack_chance);
if (this.equip_effect.increase_critical_skill != null)
equipEffectJson.put("increaseCriticalSkill", this.equip_effect.increase_critical_skill);
if (this.equip_effect.increase_block_chance != null)
equipEffectJson.put("increaseBlockChance", this.equip_effect.increase_block_chance);
if (this.equip_effect.increase_damage_resistance != null)
equipEffectJson.put("increaseDamageResistance", this.equip_effect.increase_damage_resistance);
if (this.equip_effect.critical_multiplier != null)
equipEffectJson.put("setCriticalMultiplier", this.equip_effect.critical_multiplier);
if (this.equip_effect.damage_modifier != null)
equipEffectJson.put("setNonWeaponDamageModifier", this.equip_effect.damage_modifier);
if (this.equip_effect.conditions != null) {
List conditionsJson = new ArrayList();
equipEffectJson.put("addedConditions", conditionsJson);
for (ConditionEffect condition : this.equip_effect.conditions) {
for (ActorConditionEffect condition : this.equip_effect.conditions) {
Map conditionJson = new LinkedHashMap();
conditionsJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
writeConditionEffectToMap(condition, conditionJson);
}
}
}
if (this.hit_effect != null) {
Map hitEffectJson = new LinkedHashMap();
itemJson.put("hitEffect", hitEffectJson);
if (this.hit_effect.hp_boost_min != null || this.hit_effect.hp_boost_max != null) {
Map hpJson = new LinkedHashMap();
hitEffectJson.put("increaseCurrentHP", hpJson);
if (this.hit_effect.hp_boost_min != null) hpJson.put("min", this.hit_effect.hp_boost_min);
else hpJson.put("min", 0);
if (this.hit_effect.hp_boost_max != null) hpJson.put("max", this.hit_effect.hp_boost_max);
else hpJson.put("max", 0);
}
if (this.hit_effect.ap_boost_min != null || this.hit_effect.ap_boost_max != null) {
Map apJson = new LinkedHashMap();
hitEffectJson.put("increaseCurrentAP", apJson);
if (this.hit_effect.ap_boost_min != null) apJson.put("min", this.hit_effect.ap_boost_min);
else apJson.put("min", 0);
if (this.hit_effect.ap_boost_max != null) apJson.put("max", this.hit_effect.ap_boost_max);
else apJson.put("max", 0);
}
if (this.hit_effect.conditions_source != null) {
List conditionsSourceJson = new ArrayList();
hitEffectJson.put("conditionsSource", conditionsSourceJson);
for (TimedConditionEffect condition : this.hit_effect.conditions_source) {
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
if (this.hit_effect.conditions_target != null) {
List conditionsTargetJson = new ArrayList();
hitEffectJson.put("conditionsTarget", conditionsTargetJson);
for (TimedConditionEffect condition : this.hit_effect.conditions_target) {
Map conditionJson = new LinkedHashMap();
conditionsTargetJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
}
if (this.hit_received_effect != null) {
Map hitReceivedEffectJson = new LinkedHashMap();
itemJson.put("hitReceivedEffect", hitReceivedEffectJson);
if (this.hit_received_effect.hp_boost_min != null || this.hit_received_effect.hp_boost_max != null) {
Map hpJson = new LinkedHashMap();
hitReceivedEffectJson.put("increaseCurrentHP", hpJson);
if (this.hit_received_effect.hp_boost_min != null) hpJson.put("min", this.hit_received_effect.hp_boost_min);
else hpJson.put("min", 0);
if (this.hit_received_effect.hp_boost_max != null) hpJson.put("max", this.hit_received_effect.hp_boost_max);
else hpJson.put("max", 0);
}
if (this.hit_received_effect.ap_boost_min != null || this.hit_received_effect.ap_boost_max != null) {
Map apJson = new LinkedHashMap();
hitReceivedEffectJson.put("increaseCurrentAP", apJson);
if (this.hit_received_effect.ap_boost_min != null) apJson.put("min", this.hit_received_effect.ap_boost_min);
else apJson.put("min", 0);
if (this.hit_received_effect.ap_boost_max != null) apJson.put("max", this.hit_received_effect.ap_boost_max);
else apJson.put("max", 0);
}
if (this.hit_received_effect.hp_boost_min_target != null || this.hit_received_effect.hp_boost_max_target != null) {
Map hpJson = new LinkedHashMap();
hitReceivedEffectJson.put("increaseAttackerCurrentHP", hpJson);
if (this.hit_received_effect.hp_boost_min_target != null) hpJson.put("min", this.hit_received_effect.hp_boost_min_target);
else hpJson.put("min", 0);
if (this.hit_received_effect.hp_boost_max_target != null) hpJson.put("max", this.hit_received_effect.hp_boost_max_target);
else hpJson.put("max", 0);
}
if (this.hit_received_effect.ap_boost_min_target != null || this.hit_received_effect.ap_boost_max_target != null) {
Map apJson = new LinkedHashMap();
hitReceivedEffectJson.put("increaseAttackerCurrentAP", apJson);
if (this.hit_received_effect.ap_boost_min_target != null) apJson.put("min", this.hit_received_effect.ap_boost_min_target);
else apJson.put("min", 0);
if (this.hit_received_effect.ap_boost_max_target != null) apJson.put("max", this.hit_received_effect.ap_boost_max_target);
else apJson.put("max", 0);
}
if (this.hit_received_effect.conditions_source != null) {
List conditionsSourceJson = new ArrayList();
hitReceivedEffectJson.put("conditionsSource", conditionsSourceJson);
for (TimedConditionEffect condition : this.hit_received_effect.conditions_source) {
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
if (this.hit_received_effect.conditions_target != null) {
List conditionsTargetJson = new ArrayList();
hitReceivedEffectJson.put("conditionsTarget", conditionsTargetJson);
for (TimedConditionEffect condition : this.hit_received_effect.conditions_target) {
Map conditionJson = new LinkedHashMap();
conditionsTargetJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
}
if (this.kill_effect != null) {
Map killEffectJson = new LinkedHashMap();
writeHitEffectToMap(itemJson, this.hit_effect, "hitEffect");
writeHitReceivedEffectToMap(itemJson, this.hit_received_effect, "hitReceivedEffect");
String key;
if (this.category != null && this.category.action_type != null && this.category.action_type == ItemCategory.ActionType.equip) {
itemJson.put("killEffect", killEffectJson);
key = "killEffect";
} else if (this.category != null && this.category.action_type != null && this.category.action_type == ItemCategory.ActionType.use) {
itemJson.put("useEffect", killEffectJson);
}
if (this.kill_effect.hp_boost_min != null || this.kill_effect.hp_boost_max != null) {
Map hpJson = new LinkedHashMap();
killEffectJson.put("increaseCurrentHP", hpJson);
if (this.kill_effect.hp_boost_min != null) hpJson.put("min", this.kill_effect.hp_boost_min);
else hpJson.put("min", 0);
if (this.kill_effect.hp_boost_max != null) hpJson.put("max", this.kill_effect.hp_boost_max);
else hpJson.put("min", 0);
}
if (this.kill_effect.ap_boost_min != null || this.kill_effect.ap_boost_max != null) {
Map apJson = new LinkedHashMap();
killEffectJson.put("increaseCurrentAP", apJson);
if (this.kill_effect.ap_boost_min != null) apJson.put("min", this.kill_effect.ap_boost_min);
else apJson.put("min", 0);
if (this.kill_effect.ap_boost_max != null) apJson.put("max", this.kill_effect.ap_boost_max);
else apJson.put("max", 0);
}
if (this.kill_effect.conditions_source != null) {
List conditionsSourceJson = new ArrayList();
killEffectJson.put("conditionsSource", conditionsSourceJson);
for (TimedConditionEffect condition : this.kill_effect.conditions_source) {
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
key = "useEffect";
} else {
System.out.println("Could not create JSON-Map for Item: Failed to determine if the item should be used or equipped.");
key = null;
}
if (key != null) {
writeDeathEffectToMap(itemJson, this.kill_effect, key);
}
return itemJson;
}
@Override
public String getProjectFilename() {
return "itemlist_"+getProject().name+".json";
return "itemlist_" + getProject().name + ".json";
}
public Integer computePrice() {
@@ -836,7 +410,7 @@ public class Item extends JSONElement {
if (category.action_type == ItemCategory.ActionType.use) {
price += kill_effect == null ? 0 : calculateUseCost();
} else if (category.action_type == ItemCategory.ActionType.equip) {
price += equip_effect == null ? 0 : calculateEquipCost(isWeapon());;
price += equip_effect == null ? 0 : calculateEquipCost(isWeapon());
price += hit_effect == null ? 0 : calculateHitCost();
price += kill_effect == null ? 0 : calculateKillCost();
}
@@ -859,30 +433,31 @@ public class Item extends JSONElement {
public int calculateUseCost() {
final float averageHPBoost = (zeroForNull(kill_effect.hp_boost_min) + zeroForNull(kill_effect.hp_boost_max)) / 2.0f;
if (averageHPBoost == 0) return 0;
return (int) (0.1*Math.signum(averageHPBoost)*Math.pow(Math.abs(averageHPBoost), 2) + 3*averageHPBoost);
return (int) (0.1 * Math.signum(averageHPBoost) * Math.pow(Math.abs(averageHPBoost), 2) + 3 * averageHPBoost);
}
public int calculateEquipCost(boolean isWeapon) {
final int costBC = (int) (3*Math.pow(Math.max(0, zeroForNull(equip_effect.increase_block_chance)), 2.5) + 28*zeroForNull(equip_effect.increase_block_chance));
final int costAC = (int) (0.4*Math.pow(Math.max(0,zeroForNull(equip_effect.increase_attack_chance)), 2.5) - 6*Math.pow(Math.abs(Math.min(0,zeroForNull(equip_effect.increase_attack_chance))),2.7));
final int costBC = (int) (3 * Math.pow(Math.max(0, zeroForNull(equip_effect.increase_block_chance)), 2.5) + 28 * zeroForNull(equip_effect.increase_block_chance));
final int costAC = (int) (0.4 * Math.pow(Math.max(0, zeroForNull(equip_effect.increase_attack_chance)), 2.5) - 6 * Math.pow(
Math.abs(Math.min(0, zeroForNull(equip_effect.increase_attack_chance))), 2.7));
final int costAP = isWeapon ?
(int) (0.2*Math.pow(10.0f/zeroForNull(equip_effect.increase_attack_cost), 8) - 25*zeroForNull(equip_effect.increase_attack_cost))
:-3125 * zeroForNull(equip_effect.increase_attack_cost);
(int) (0.2 * Math.pow(10.0f / zeroForNull(equip_effect.increase_attack_cost), 8) - 25 * zeroForNull(equip_effect.increase_attack_cost))
: -3125 * zeroForNull(equip_effect.increase_attack_cost);
final int costDR = 1325 * zeroForNull(equip_effect.increase_damage_resistance);
final int costDMG_Min = isWeapon ?
(int) (10*Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_min)), 2.5))
:(int) (10*Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_min)), 3) + zeroForNull(equip_effect.damage_boost_min)*80);
(int) (10 * Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_min)), 2.5))
: (int) (10 * Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_min)), 3) + zeroForNull(equip_effect.damage_boost_min) * 80);
final int costDMG_Max = isWeapon ?
(int) (2*Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_max)), 2.1))
:(int) (2*Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_max)), 3) + zeroForNull(equip_effect.damage_boost_max)*20);
final int costCS = (int) (2.2*Math.pow(zeroForNull(equip_effect.increase_critical_skill), 3));
final int costCM = (int) (50*Math.pow(Math.max(0, zeroForNull(equip_effect.critical_multiplier)), 2));
(int) (2 * Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_max)), 2.1))
: (int) (2 * Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_max)), 3) + zeroForNull(equip_effect.damage_boost_max) * 20);
final int costCS = (int) (2.2 * Math.pow(zeroForNull(equip_effect.increase_critical_skill), 3));
final int costCM = (int) (50 * Math.pow(Math.max(0, zeroForNull(equip_effect.critical_multiplier)), 2));
final int costMaxHP = (int) (30*Math.pow(Math.max(0,zeroForNull(equip_effect.max_hp_boost)), 1.2) + 70*zeroForNull(equip_effect.max_hp_boost));
final int costMaxAP = (int) (50*Math.pow(Math.max(0,zeroForNull(equip_effect.max_ap_boost)), 3) + 750*zeroForNull(equip_effect.max_ap_boost));
final int costMovement = (int) (510*Math.pow(Math.max(0,-zeroForNull(equip_effect.increase_move_cost)), 2.5) - 350*zeroForNull(equip_effect.increase_move_cost));
final int costUseItem = (int)(915*Math.pow(Math.max(0,-zeroForNull(equip_effect.increase_use_item_cost)), 3) - 430*zeroForNull(equip_effect.increase_use_item_cost));
final int costReequip = (int)(450*Math.pow(Math.max(0,-zeroForNull(equip_effect.increase_reequip_cost)), 2) - 250*zeroForNull(equip_effect.increase_reequip_cost));
final int costMaxHP = (int) (30 * Math.pow(Math.max(0, zeroForNull(equip_effect.max_hp_boost)), 1.2) + 70 * zeroForNull(equip_effect.max_hp_boost));
final int costMaxAP = (int) (50 * Math.pow(Math.max(0, zeroForNull(equip_effect.max_ap_boost)), 3) + 750 * zeroForNull(equip_effect.max_ap_boost));
final int costMovement = (int) (510 * Math.pow(Math.max(0, -zeroForNull(equip_effect.increase_move_cost)), 2.5) - 350 * zeroForNull(equip_effect.increase_move_cost));
final int costUseItem = (int) (915 * Math.pow(Math.max(0, -zeroForNull(equip_effect.increase_use_item_cost)), 3) - 430 * zeroForNull(equip_effect.increase_use_item_cost));
final int costReequip = (int) (450 * Math.pow(Math.max(0, -zeroForNull(equip_effect.increase_reequip_cost)), 2) - 250 * zeroForNull(equip_effect.increase_reequip_cost));
return costBC + costAC + costAP + costDR + costDMG_Min + costDMG_Max + costCS + costCM
+ costMaxHP + costMaxAP
@@ -895,8 +470,8 @@ public class Item extends JSONElement {
final float averageAPBoost = (zeroForNull(hit_effect.ap_boost_min) + zeroForNull(hit_effect.ap_boost_max)) / 2.0f;
if (averageHPBoost == 0 && averageAPBoost == 0) return 0;
final int costBoostHP = (int)(2770*Math.pow(Math.max(0,averageHPBoost), 2.5) + 450*averageHPBoost);
final int costBoostAP = (int)(3100*Math.pow(Math.max(0,averageAPBoost), 2.5) + 300*averageAPBoost);
final int costBoostHP = (int) (2770 * Math.pow(Math.max(0, averageHPBoost), 2.5) + 450 * averageHPBoost);
final int costBoostAP = (int) (3100 * Math.pow(Math.max(0, averageAPBoost), 2.5) + 300 * averageAPBoost);
return costBoostHP + costBoostAP;
}
@@ -905,8 +480,8 @@ public class Item extends JSONElement {
final float averageAPBoost = (zeroForNull(kill_effect.ap_boost_min) + zeroForNull(kill_effect.ap_boost_max)) / 2.0f;
if (averageHPBoost == 0 && averageAPBoost == 0) return 0;
final int costBoostHP = (int)(923*Math.pow(Math.max(0,averageHPBoost), 2.5) + 450*averageHPBoost);
final int costBoostAP = (int)(1033*Math.pow(Math.max(0,averageAPBoost), 2.5) + 300*averageAPBoost);
final int costBoostHP = (int) (923 * Math.pow(Math.max(0, averageHPBoost), 2.5) + 450 * averageHPBoost);
final int costBoostAP = (int) (1033 * Math.pow(Math.max(0, averageAPBoost), 2.5) + 300 * averageAPBoost);
return costBoostHP + costBoostAP;
}
}

View File

@@ -1,6 +1,13 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -9,15 +16,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
public class ItemCategory extends JSONElement {
private static final long serialVersionUID = -348864002519568300L;
@@ -99,7 +97,7 @@ public class ItemCategory extends JSONElement {
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+name+" ("+id+")";
return (needsSaving() ? "*" : "") + name + " (" + id + ")";
}
public static String getStaticDesc() {
@@ -115,7 +113,7 @@ public class ItemCategory extends JSONElement {
reader = new FileReader(jsonFile);
List itemCategories = (List) parser.parse(reader);
for (Object obj : itemCategories) {
Map itemCatJson = (Map)obj;
Map itemCatJson = (Map) obj;
ItemCategory itemCat = fromJson(itemCatJson);
itemCat.jsonFile = jsonFile;
itemCat.parent = category;
@@ -125,13 +123,13 @@ public class ItemCategory extends JSONElement {
category.add(itemCat);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
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());
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());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -156,14 +154,16 @@ public class ItemCategory extends JSONElement {
ItemCategory itemCat = new ItemCategory();
itemCat.id = (String) itemCatJson.get("id");
itemCat.name = (String) itemCatJson.get("name");
if (itemCatJson.get("inventorySlot") != null) itemCat.slot = InventorySlot.valueOf((String) itemCatJson.get("inventorySlot"));
if (itemCatJson.get("inventorySlot") != null)
itemCat.slot = InventorySlot.valueOf((String) itemCatJson.get("inventorySlot"));
return itemCat;
}
@SuppressWarnings("rawtypes")
@Override
public void parse(Map itemCatJson) {
if (itemCatJson.get("actionType") != null) action_type = ActionType.valueOf((String) itemCatJson.get("actionType"));
if (itemCatJson.get("actionType") != null)
action_type = ActionType.valueOf((String) itemCatJson.get("actionType"));
if (itemCatJson.get("size") != null) size = Size.valueOf((String) itemCatJson.get("size"));
this.state = State.parsed;
@@ -171,17 +171,10 @@ public class ItemCategory extends JSONElement {
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
//Nothing to link to :D
this.state = State.linked;
@@ -264,7 +257,7 @@ public class ItemCategory extends JSONElement {
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Failed to load item category icon "+res);
Notification.addError("Failed to load item category icon " + res);
e.printStackTrace();
}
}
@@ -307,7 +300,7 @@ public class ItemCategory extends JSONElement {
// Nothing to link to.
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Map toJson() {
Map itemCatJson = new LinkedHashMap();
@@ -322,7 +315,7 @@ public class ItemCategory extends JSONElement {
@Override
public String getProjectFilename() {
return "itemcategories_"+getProject().name+".json";
return "itemcategories_" + getProject().name + ".json";
}

View File

@@ -1,21 +1,16 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.*;
import java.util.List;
import java.util.Map;
public abstract class JSONElement extends GameDataElement {
@@ -26,8 +21,7 @@ public abstract class JSONElement extends GameDataElement {
@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.
if (shouldSkipParse()) {
return;
}
JSONParser parser = new JSONParser();
@@ -36,32 +30,31 @@ public abstract class JSONElement extends GameDataElement {
reader = new FileReader(jsonFile);
List gameDataElements = (List) parser.parse(reader);
for (Object obj : gameDataElements) {
Map jsonObj = (Map)obj;
Map jsonObj = (Map) obj;
String id = (String) jsonObj.get("id");
try {
if (id != null && id.equals(this.id )) {
if (id != null && id.equals(this.id)) {
this.parse(jsonObj);
this.state = State.parsed;
break;
}
}
catch(Exception e){
} catch (Exception e) {
System.out.println("Error in ID: " + id);
System.out.println(e.getMessage());
}
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
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());
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());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} catch (IllegalArgumentException e) {
System.out.println(id);
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -78,6 +71,7 @@ public abstract class JSONElement extends GameDataElement {
@SuppressWarnings("rawtypes")
public abstract Map toJson();
public String toJsonString() {
StringWriter writer = new JsonPrettyWriter();
try {
@@ -99,7 +93,7 @@ public abstract class JSONElement extends GameDataElement {
public void save() {
if (this.getParent() instanceof GameDataCategory<?> && writable) {
((GameDataCategory<?>)this.getParent()).save(this.jsonFile);
((GameDataCategory<?>) this.getParent()).save(this.jsonFile);
}
}
@@ -107,7 +101,7 @@ public abstract class JSONElement extends GameDataElement {
* Returns null if save occurred (no notable events).
*/
public List<SaveEvent> attemptSave() {
List<SaveEvent> events = ((GameDataCategory<?>)this.getParent()).attemptSave(true, this.jsonFile.getName());
List<SaveEvent> events = ((GameDataCategory<?>) this.getParent()).attemptSave(true, this.jsonFile.getName());
if (events == null || events.isEmpty()) {
return null;
}
@@ -142,18 +136,20 @@ public abstract class JSONElement extends GameDataElement {
double a = 1;
try {
a = Integer.parseInt(s.substring(0, c));
} catch (NumberFormatException nfe) {}
} catch (NumberFormatException nfe) {
}
double b = 100;
try {
b = Integer.parseInt(s.substring(c+1));
} catch (NumberFormatException nfe) {}
return a/b;
b = Integer.parseInt(s.substring(c + 1));
} catch (NumberFormatException nfe) {
}
else {
return a / b;
} else {
double a = 10;
try {
a = Double.parseDouble(s);
} catch (NumberFormatException nfe) {}
} catch (NumberFormatException nfe) {
}
return a;
}
}

View File

@@ -1,22 +1,22 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
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.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static com.gpl.rpg.atcontentstudio.model.gamedata.Common.*;
public class NPC extends JSONElement {
@@ -73,43 +73,9 @@ public class NPC extends JSONElement {
wholeMap
}
public static class DeathEffect {
//Available from parsed state
public Integer hp_boost_min = null;
public Integer hp_boost_max = null;
public Integer ap_boost_min = null;
public Integer ap_boost_max = null;
public List<TimedConditionEffect> conditions_source = null;
}
public static class HitEffect extends DeathEffect {
//Available from parsed state
public List<TimedConditionEffect> conditions_target = null;
}
public static class HitReceivedEffect extends HitEffect {
//Available from parsed state
public Integer hp_boost_min_target = null;
public Integer hp_boost_max_target = null;
public Integer ap_boost_min_target = null;
public Integer ap_boost_max_target = null;
}
public static class TimedConditionEffect {
//Available from parsed state
public Integer magnitude = null;
public String condition_id = null;
public Integer duration = null;
public Double chance = null;
//Available from linked state
public ActorCondition condition = null;
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+name+" ("+id+")";
return (needsSaving() ? "*" : "") + name + " (" + id + ")";
}
public static String getStaticDesc() {
@@ -125,7 +91,7 @@ public class NPC extends JSONElement {
reader = new FileReader(jsonFile);
List npcs = (List) parser.parse(reader);
for (Object obj : npcs) {
Map npcJson = (Map)obj;
Map npcJson = (Map) obj;
NPC npc = fromJson(npcJson);
npc.jsonFile = jsonFile;
npc.parent = category;
@@ -135,13 +101,13 @@ public class NPC extends JSONElement {
category.add(npc);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
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());
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());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -179,11 +145,13 @@ public class NPC extends JSONElement {
this.max_ap = JSONElement.getInteger((Number) npcJson.get("maxAP"));
this.move_cost = JSONElement.getInteger((Number) npcJson.get("moveCost"));
this.unique = JSONElement.getInteger((Number) npcJson.get("unique"));
if (npcJson.get("monsterClass") != null) this.monster_class = MonsterClass.valueOf((String) npcJson.get("monsterClass"));
if (npcJson.get("movementAggressionType") != null) this.movement_type = MovementType.valueOf((String) npcJson.get("movementAggressionType"));
if (npcJson.get("monsterClass") != null)
this.monster_class = MonsterClass.valueOf((String) npcJson.get("monsterClass"));
if (npcJson.get("movementAggressionType") != null)
this.movement_type = MovementType.valueOf((String) npcJson.get("movementAggressionType"));
if (npcJson.get("attackDamage") != null) {
this.attack_damage_min = JSONElement.getInteger((Number) (((Map)npcJson.get("attackDamage")).get("min")));
this.attack_damage_max = JSONElement.getInteger((Number) (((Map)npcJson.get("attackDamage")).get("max")));
this.attack_damage_min = JSONElement.getInteger((Number) (((Map) npcJson.get("attackDamage")).get("min")));
this.attack_damage_max = JSONElement.getInteger((Number) (((Map) npcJson.get("attackDamage")).get("max")));
}
this.spawngroup_id = (String) npcJson.get("spawnGroup");
this.faction_id = (String) npcJson.get("faction");
@@ -194,188 +162,49 @@ public class NPC extends JSONElement {
this.critical_skill = JSONElement.getInteger((Number) npcJson.get("criticalSkill"));
//TODO correct game data, to unify format.
// this.critical_multiplier = JSONElement.getDouble((Number) npcJson.get("criticalMultiplier"));
if (npcJson.get("criticalMultiplier") != null) this.critical_multiplier = JSONElement.getDouble(Double.parseDouble(npcJson.get("criticalMultiplier").toString()));
if (npcJson.get("criticalMultiplier") != null)
this.critical_multiplier = JSONElement.getDouble(Double.parseDouble(npcJson.get("criticalMultiplier").toString()));
this.block_chance = JSONElement.getInteger((Number) npcJson.get("blockChance"));
this.damage_resistance = JSONElement.getInteger((Number) npcJson.get("damageResistance"));
Map hitEffect = (Map) npcJson.get("hitEffect");
if (hitEffect != null) {
this.hit_effect = new HitEffect();
if (hitEffect.get("increaseCurrentHP") != null) {
this.hit_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentHP")).get("max")));
this.hit_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentHP")).get("min")));
}
if (hitEffect.get("increaseCurrentAP") != null) {
this.hit_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentAP")).get("max")));
this.hit_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentAP")).get("min")));
}
List conditionsSourceJson = (List) hitEffect.get("conditionsSource");
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
this.hit_effect.conditions_source = new ArrayList<NPC.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsSourceJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.hit_effect.conditions_source.add(condition);
}
}
List conditionsTargetJson = (List) hitEffect.get("conditionsTarget");
if (conditionsTargetJson != null && !conditionsTargetJson.isEmpty()) {
this.hit_effect.conditions_target = new ArrayList<NPC.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsTargetJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.hit_effect.conditions_target.add(condition);
}
}
this.hit_effect = parseHitEffect(hitEffect);
}
Map hitReceivedEffect = (Map) npcJson.get("hitReceivedEffect");
if (hitReceivedEffect != null) {
this.hit_received_effect = new HitReceivedEffect();
if (hitReceivedEffect.get("increaseCurrentHP") != null) {
this.hit_received_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseCurrentHP")).get("max")));
this.hit_received_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseCurrentHP")).get("min")));
}
if (hitReceivedEffect.get("increaseCurrentAP") != null) {
this.hit_received_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseCurrentAP")).get("max")));
this.hit_received_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseCurrentAP")).get("min")));
}
if (hitReceivedEffect.get("increaseAttackerCurrentHP") != null) {
this.hit_received_effect.hp_boost_max_target = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseAttackerCurrentHP")).get("max")));
this.hit_received_effect.hp_boost_min_target = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseAttackerCurrentHP")).get("min")));
}
if (hitReceivedEffect.get("increaseAttackerCurrentAP") != null) {
this.hit_received_effect.ap_boost_max_target = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseAttackerCurrentAP")).get("max")));
this.hit_received_effect.ap_boost_min_target = JSONElement.getInteger((Number) (((Map)hitReceivedEffect.get("increaseAttackerCurrentAP")).get("min")));
}
List conditionsSourceJson = (List) hitReceivedEffect.get("conditionsSource");
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
this.hit_received_effect.conditions_source = new ArrayList<NPC.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsSourceJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.hit_received_effect.conditions_source.add(condition);
}
}
List conditionsTargetJson = (List) hitReceivedEffect.get("conditionsTarget");
if (conditionsTargetJson != null && !conditionsTargetJson.isEmpty()) {
this.hit_received_effect.conditions_target = new ArrayList<NPC.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsTargetJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.hit_received_effect.conditions_target.add(condition);
}
}
this.hit_received_effect = parseHitReceivedEffect(hitReceivedEffect);
}
Map deathEffect = (Map) npcJson.get("deathEffect");
if (deathEffect != null) {
this.death_effect = new HitEffect();
if (deathEffect.get("increaseCurrentHP") != null) {
this.death_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)deathEffect.get("increaseCurrentHP")).get("max")));
this.death_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)deathEffect.get("increaseCurrentHP")).get("min")));
this.death_effect = parseDeathEffect(deathEffect);
}
if (deathEffect.get("increaseCurrentAP") != null) {
this.death_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)deathEffect.get("increaseCurrentAP")).get("max")));
this.death_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)deathEffect.get("increaseCurrentAP")).get("min")));
}
List conditionsSourceJson = (List) deathEffect.get("conditionsSource");
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
this.death_effect.conditions_source = new ArrayList<NPC.TimedConditionEffect>();
for (Object conditionJsonObj : conditionsSourceJson) {
Map conditionJson = (Map)conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
this.death_effect.conditions_source.add(condition);
}
}
}
}
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking item "+id+". No parent project found.");
Notification.addError("Error linking item " + id + ". No parent project found.");
return;
}
if (this.icon_id != null) {
String spritesheetId = this.icon_id.split(":")[0];
if (proj.getSpritesheet(spritesheetId) == null) {
Notification.addError("Error Spritesheet "+id+". has no backlink.");
return;
}
proj.getSpritesheet(spritesheetId).addBacklink(this);
}
linkIcon(proj, this.icon_id, this);
if (this.dialogue_id != null) this.dialogue = proj.getDialogue(this.dialogue_id);
if (this.dialogue != null) this.dialogue.addBacklink(this);
if (this.droplist_id != null) this.droplist = proj.getDroplist(this.droplist_id);
if (this.droplist != null) this.droplist.addBacklink(this);
if (this.hit_effect != null && this.hit_effect.conditions_source != null) {
for (TimedConditionEffect ce : this.hit_effect.conditions_source) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
if (this.hit_effect != null && this.hit_effect.conditions_target != null) {
for (TimedConditionEffect ce : this.hit_effect.conditions_target) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
if (this.hit_received_effect != null && this.hit_received_effect.conditions_source != null) {
for (TimedConditionEffect ce : this.hit_received_effect.conditions_source) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
if (this.hit_received_effect != null && this.hit_received_effect.conditions_target != null) {
for (TimedConditionEffect ce : this.hit_received_effect.conditions_target) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
if (this.death_effect != null && this.death_effect.conditions_source != null) {
for (TimedConditionEffect ce : this.death_effect.conditions_source) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(this);
}
}
linkEffects(this.hit_effect, proj, this);
linkEffects(this.hit_received_effect, proj, this);
linkEffects(this.death_effect, proj, this);
this.state = State.linked;
}
@@ -417,103 +246,15 @@ public class NPC extends JSONElement {
clone.faction_id = this.faction_id;
if (this.hit_effect != null) {
clone.hit_effect = new HitEffect();
clone.hit_effect.ap_boost_max = this.hit_effect.ap_boost_max;
clone.hit_effect.ap_boost_min = this.hit_effect.ap_boost_min;
clone.hit_effect.hp_boost_max = this.hit_effect.hp_boost_max;
clone.hit_effect.hp_boost_min = this.hit_effect.hp_boost_min;
if (this.hit_effect.conditions_source != null) {
clone.hit_effect.conditions_source = new ArrayList<TimedConditionEffect>();
for (TimedConditionEffect c : this.hit_effect.conditions_source) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.hit_effect.conditions_source.add(cclone);
}
}
if (this.hit_effect.conditions_target != null) {
clone.hit_effect.conditions_target = new ArrayList<TimedConditionEffect>();
for (TimedConditionEffect c : this.hit_effect.conditions_target) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.hit_effect.conditions_target.add(cclone);
}
}
copyHitEffectValues(clone.hit_effect, this.hit_effect, clone);
}
if (this.hit_received_effect != null) {
clone.hit_received_effect = new HitReceivedEffect();
clone.hit_received_effect.ap_boost_max = this.hit_received_effect.ap_boost_max;
clone.hit_received_effect.ap_boost_min = this.hit_received_effect.ap_boost_min;
clone.hit_received_effect.hp_boost_max = this.hit_received_effect.hp_boost_max;
clone.hit_received_effect.hp_boost_min = this.hit_received_effect.hp_boost_min;
clone.hit_received_effect.ap_boost_max_target = this.hit_received_effect.ap_boost_max_target;
clone.hit_received_effect.ap_boost_min_target = this.hit_received_effect.ap_boost_min_target;
clone.hit_received_effect.hp_boost_max_target = this.hit_received_effect.hp_boost_max_target;
clone.hit_received_effect.hp_boost_min_target = this.hit_received_effect.hp_boost_min_target;
if (this.hit_received_effect.conditions_source != null) {
clone.hit_received_effect.conditions_source = new ArrayList<TimedConditionEffect>();
for (TimedConditionEffect c : this.hit_received_effect.conditions_source) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.hit_received_effect.conditions_source.add(cclone);
}
}
if (this.hit_received_effect.conditions_target != null) {
clone.hit_received_effect.conditions_target = new ArrayList<TimedConditionEffect>();
for (TimedConditionEffect c : this.hit_received_effect.conditions_target) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.hit_received_effect.conditions_target.add(cclone);
}
}
copyHitReceivedEffectValues(clone.hit_received_effect, this.hit_received_effect, clone);
}
if (this.death_effect != null) {
clone.death_effect = new DeathEffect();
clone.death_effect.ap_boost_max = this.death_effect.ap_boost_max;
clone.death_effect.ap_boost_min = this.death_effect.ap_boost_min;
clone.death_effect.hp_boost_max = this.death_effect.hp_boost_max;
clone.death_effect.hp_boost_min = this.death_effect.hp_boost_min;
if (this.death_effect.conditions_source != null) {
clone.death_effect.conditions_source = new ArrayList<TimedConditionEffect>();
for (TimedConditionEffect c : this.death_effect.conditions_source) {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = c.magnitude;
cclone.condition_id = c.condition_id;
cclone.condition = c.condition;
cclone.chance = c.chance;
cclone.duration = c.duration;
if (cclone.condition != null) {
cclone.condition.addBacklink(clone);
}
clone.death_effect.conditions_source.add(cclone);
}
}
copyDeathEffectValues(clone.death_effect, this.death_effect, clone);
}
clone.max_ap = this.max_ap;
clone.max_hp = this.max_hp;
@@ -537,49 +278,28 @@ public class NPC extends JSONElement {
this.droplist = (Droplist) newOne;
if (newOne != null) newOne.addBacklink(this);
} else {
if (this.hit_effect != null && this.hit_effect.conditions_source != null) {
for (TimedConditionEffect tce : this.hit_effect.conditions_source) {
if (tce.condition == oldOne) {
oldOne.removeBacklink(this);
tce.condition = (ActorCondition) newOne;
if (newOne != null) newOne.addBacklink(this);
}
}
}
if (this.hit_effect != null && this.hit_effect.conditions_target != null) {
for (TimedConditionEffect tce : this.hit_effect.conditions_target) {
if (tce.condition == oldOne) {
oldOne.removeBacklink(this);
tce.condition = (ActorCondition) newOne;
if (newOne != null) newOne.addBacklink(this);
}
}
if (this.hit_effect != null) {
actorConditionElementChanged(this.hit_effect.conditions_source, oldOne, newOne, this);
actorConditionElementChanged(this.hit_effect.conditions_target, oldOne, newOne, this);
}
}
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Map toJson() {
Map npcJson = new LinkedHashMap();
npcJson.put("id", this.id);
if (this.name != null) npcJson.put("name", this.name);
if (this.icon_id != null) npcJson.put("iconID", this.icon_id);
writeIconToMap(npcJson, this.icon_id);
if (this.max_hp != null) npcJson.put("maxHP", this.max_hp);
if (this.max_ap != null) npcJson.put("maxAP", this.max_ap);
if (this.move_cost != null) npcJson.put("moveCost", this.move_cost);
if (this.unique != null) npcJson.put("unique", this.unique);
if (this.monster_class != null) npcJson.put("monsterClass", this.monster_class.toString());
if (this.movement_type != null) npcJson.put("movementAggressionType", this.movement_type.toString());
if (this.attack_damage_min != null || this.attack_damage_max != null) {
Map adJson = new LinkedHashMap();
npcJson.put("attackDamage", adJson);
if (this.attack_damage_min != null) adJson.put("min", this.attack_damage_min);
else adJson.put("min", 0);
if (this.attack_damage_max != null) adJson.put("max", this.attack_damage_max);
else adJson.put("max", 0);
}
writeMinMaxToMap(npcJson, "attackDamage", this.attack_damage_min, attack_damage_max, 0);
if (this.spawngroup_id != null) npcJson.put("spawnGroup", this.spawngroup_id);
if (this.faction_id != null) npcJson.put("faction", this.faction_id);
if (this.dialogue != null) {
@@ -598,186 +318,34 @@ public class NPC extends JSONElement {
if (this.critical_multiplier != null) npcJson.put("criticalMultiplier", this.critical_multiplier);
if (this.block_chance != null) npcJson.put("blockChance", this.block_chance);
if (this.damage_resistance != null) npcJson.put("damageResistance", this.damage_resistance);
if (this.hit_effect != null) {
Map hitEffectJson = new LinkedHashMap();
npcJson.put("hitEffect", hitEffectJson);
if (this.hit_effect.hp_boost_min != null || this.hit_effect.hp_boost_max != null) {
Map hpJson = new LinkedHashMap();
hitEffectJson.put("increaseCurrentHP", hpJson);
if (this.hit_effect.hp_boost_min != null) hpJson.put("min", this.hit_effect.hp_boost_min);
else hpJson.put("min", 0);
if (this.hit_effect.hp_boost_max != null) hpJson.put("max", this.hit_effect.hp_boost_max);
else hpJson.put("max", 0);
}
if (this.hit_effect.ap_boost_min != null || this.hit_effect.ap_boost_max != null) {
Map apJson = new LinkedHashMap();
hitEffectJson.put("increaseCurrentAP", apJson);
if (this.hit_effect.ap_boost_min != null) apJson.put("min", this.hit_effect.ap_boost_min);
else apJson.put("min", 0);
if (this.hit_effect.ap_boost_max != null) apJson.put("max", this.hit_effect.ap_boost_max);
else apJson.put("max", 0);
}
if (this.hit_effect.conditions_source != null) {
List conditionsSourceJson = new ArrayList();
hitEffectJson.put("conditionsSource", conditionsSourceJson);
for (TimedConditionEffect condition : this.hit_effect.conditions_source) {
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
if (this.hit_effect.conditions_target != null) {
List conditionsTargetJson = new ArrayList();
hitEffectJson.put("conditionsTarget", conditionsTargetJson);
for (TimedConditionEffect condition : this.hit_effect.conditions_target) {
Map conditionJson = new LinkedHashMap();
conditionsTargetJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
}
if (this.hit_received_effect != null) {
Map hitReceivedEffectJson = new LinkedHashMap();
npcJson.put("hitReceivedEffect", hitReceivedEffectJson);
if (this.hit_received_effect.hp_boost_min != null || this.hit_received_effect.hp_boost_max != null) {
Map hpJson = new LinkedHashMap();
hitReceivedEffectJson.put("increaseCurrentHP", hpJson);
if (this.hit_received_effect.hp_boost_min != null) hpJson.put("min", this.hit_received_effect.hp_boost_min);
else hpJson.put("min", 0);
if (this.hit_received_effect.hp_boost_max != null) hpJson.put("max", this.hit_received_effect.hp_boost_max);
else hpJson.put("max", 0);
}
if (this.hit_received_effect.ap_boost_min != null || this.hit_received_effect.ap_boost_max != null) {
Map apJson = new LinkedHashMap();
hitReceivedEffectJson.put("increaseCurrentAP", apJson);
if (this.hit_received_effect.ap_boost_min != null) apJson.put("min", this.hit_received_effect.ap_boost_min);
else apJson.put("min", 0);
if (this.hit_received_effect.ap_boost_max != null) apJson.put("max", this.hit_received_effect.ap_boost_max);
else apJson.put("max", 0);
}
if (this.hit_received_effect.hp_boost_min_target != null || this.hit_received_effect.hp_boost_max_target != null) {
Map hpJson = new LinkedHashMap();
hitReceivedEffectJson.put("increaseAttackerCurrentHP", hpJson);
if (this.hit_received_effect.hp_boost_min_target != null) hpJson.put("min", this.hit_received_effect.hp_boost_min_target);
else hpJson.put("min", 0);
if (this.hit_received_effect.hp_boost_max_target != null) hpJson.put("max", this.hit_received_effect.hp_boost_max_target);
else hpJson.put("max", 0);
}
if (this.hit_received_effect.ap_boost_min_target != null || this.hit_received_effect.ap_boost_max_target != null) {
Map apJson = new LinkedHashMap();
hitReceivedEffectJson.put("increaseAttackerCurrentAP", apJson);
if (this.hit_received_effect.ap_boost_min_target != null) apJson.put("min", this.hit_received_effect.ap_boost_min_target);
else apJson.put("min", 0);
if (this.hit_received_effect.ap_boost_max_target != null) apJson.put("max", this.hit_received_effect.ap_boost_max_target);
else apJson.put("max", 0);
}
if (this.hit_received_effect.conditions_source != null) {
List conditionsSourceJson = new ArrayList();
hitReceivedEffectJson.put("conditionsSource", conditionsSourceJson);
for (TimedConditionEffect condition : this.hit_received_effect.conditions_source) {
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
if (this.hit_received_effect.conditions_target != null) {
List conditionsTargetJson = new ArrayList();
hitReceivedEffectJson.put("conditionsTarget", conditionsTargetJson);
for (TimedConditionEffect condition : this.hit_received_effect.conditions_target) {
Map conditionJson = new LinkedHashMap();
conditionsTargetJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
}
if (this.death_effect != null) {
Map deathEffectJson = new LinkedHashMap();
npcJson.put("deathEffect", deathEffectJson);
if (this.death_effect.hp_boost_min != null || this.death_effect.hp_boost_max != null) {
Map hpJson = new LinkedHashMap();
deathEffectJson.put("increaseCurrentHP", hpJson);
if (this.death_effect.hp_boost_min != null) hpJson.put("min", this.death_effect.hp_boost_min);
else hpJson.put("min", 0);
if (this.death_effect.hp_boost_max != null) hpJson.put("max", this.death_effect.hp_boost_max);
else hpJson.put("max", 0);
}
if (this.death_effect.ap_boost_min != null || this.death_effect.ap_boost_max != null) {
Map apJson = new LinkedHashMap();
deathEffectJson.put("increaseCurrentAP", apJson);
if (this.death_effect.ap_boost_min != null) apJson.put("min", this.death_effect.ap_boost_min);
else apJson.put("min", 0);
if (this.death_effect.ap_boost_max != null) apJson.put("max", this.death_effect.ap_boost_max);
else apJson.put("max", 0);
}
if (this.death_effect.conditions_source != null) {
List conditionsSourceJson = new ArrayList();
deathEffectJson.put("conditionsSource", conditionsSourceJson);
for (TimedConditionEffect condition : this.death_effect.conditions_source) {
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
} else if (condition.condition_id != null) {
conditionJson.put("condition", condition.condition_id);
}
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
if (condition.duration != null) conditionJson.put("duration", condition.duration);
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
}
}
}
writeHitEffectToMap(npcJson, this.hit_effect, "hitEffect");
writeHitReceivedEffectToMap(npcJson, this.hit_received_effect, "hitReceivedEffect");
writeDeathEffectToMap(npcJson, this.death_effect, "deathEffect");
return npcJson;
}
@Override
public String getProjectFilename() {
return "monsterlist_"+getProject().name+".json";
return "monsterlist_" + getProject().name + ".json";
}
public int getMonsterExperience() {
double EXP_FACTOR_DAMAGERESISTANCE = 9;
double EXP_FACTOR_SCALING = 0.7;
double attacksPerTurn = Math.floor((double)(max_ap != null ? max_ap : 10.0) / (double)(attack_cost != null ? attack_cost : 10.0));
double attacksPerTurn = Math.floor((double) (max_ap != null ? max_ap : 10.0) / (double) (attack_cost != null ? attack_cost : 10.0));
double avgDamagePotential = 0;
if (attack_damage_min != null || attack_damage_max != null) {
avgDamagePotential = ((double)(attack_damage_min != null ? attack_damage_min : 0) + (double)(attack_damage_max != null ? attack_damage_max : 0)) / 2.0;
avgDamagePotential = ((double) (attack_damage_min != null ? attack_damage_min : 0) + (double) (attack_damage_max != null ? attack_damage_max : 0)) / 2.0;
}
double avgCrit = 0;
if (critical_skill != null && critical_multiplier != null) {
avgCrit = (double)(critical_skill / 100.0) * critical_multiplier;
avgCrit = (double) (critical_skill / 100.0) * critical_multiplier;
}
double avgAttackHP = attacksPerTurn * ((double)(attack_chance != null ? attack_chance : 0) / 100.0) * avgDamagePotential * (1 + avgCrit);
double avgDefenseHP = ((max_hp != null ? max_hp : 1) * (1 + ((double)(block_chance != null ? block_chance : 0) / 100.0))) + ( EXP_FACTOR_DAMAGERESISTANCE * (damage_resistance != null ? damage_resistance : 0));
double avgAttackHP = attacksPerTurn * ((double) (attack_chance != null ? attack_chance : 0) / 100.0) * avgDamagePotential * (1 + avgCrit);
double avgDefenseHP = ((max_hp != null ? max_hp : 1) * (1 + ((double) (block_chance != null ? block_chance : 0) / 100.0))) +
(EXP_FACTOR_DAMAGERESISTANCE * (damage_resistance != null ? damage_resistance : 0));
double attackConditionBonus = 0;
if (hit_effect != null && hit_effect.conditions_target != null && hit_effect.conditions_target.size() > 0) {
attackConditionBonus = 50;
@@ -785,7 +353,7 @@ public class NPC extends JSONElement {
double experience = (((avgAttackHP * 3) + avgDefenseHP) * EXP_FACTOR_SCALING) + attackConditionBonus;
return new Double(Math.ceil(experience)).intValue();
};
}
}

View File

@@ -1,6 +1,13 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -10,14 +17,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class Quest extends JSONElement {
private static final long serialVersionUID = 2004839647483250099L;
@@ -32,7 +31,7 @@ public class Quest extends JSONElement {
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+name+" ("+id+")";
return (needsSaving() ? "*" : "") + name + " (" + id + ")";
}
public static String getStaticDesc() {
@@ -48,7 +47,7 @@ public class Quest extends JSONElement {
reader = new FileReader(jsonFile);
List quests = (List) parser.parse(reader);
for (Object obj : quests) {
Map questJson = (Map)obj;
Map questJson = (Map) obj;
Quest quest = fromJson(questJson);
quest.jsonFile = jsonFile;
quest.parent = category;
@@ -58,13 +57,13 @@ public class Quest extends JSONElement {
category.add(quest);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
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());
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());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -102,7 +101,7 @@ public class Quest extends JSONElement {
this.stages = new ArrayList<QuestStage>();
if (questStagesJson != null && !questStagesJson.isEmpty()) {
for (Object questStageJsonObj : questStagesJson) {
Map questStageJson = (Map)questStageJsonObj;
Map questStageJson = (Map) questStageJsonObj;
QuestStage questStage = new QuestStage(this);
questStage.parse(questStageJson);
this.stages.add(questStage);
@@ -113,17 +112,10 @@ public class Quest extends JSONElement {
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
for (QuestStage stage : stages) {
stage.link();
@@ -151,7 +143,7 @@ public class Quest extends JSONElement {
clone.visible_in_log = this.visible_in_log;
if (this.stages != null) {
clone.stages = new ArrayList<QuestStage>();
for (QuestStage stage : this.stages){
for (QuestStage stage : this.stages) {
clone.stages.add((QuestStage) stage.clone(clone));
}
}
@@ -163,7 +155,7 @@ public class Quest extends JSONElement {
//Nothing to link to.
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Map toJson() {
Map questJson = new LinkedHashMap();
@@ -183,7 +175,7 @@ public class Quest extends JSONElement {
@Override
public String getProjectFilename() {
return "questlist_"+getProject().name+".json";
return "questlist_" + getProject().name + ".json";
}
public QuestStage getStage(Integer stageId) {

View File

@@ -1,12 +1,12 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import java.util.LinkedHashMap;
import java.util.Map;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import java.awt.*;
import java.util.LinkedHashMap;
import java.util.Map;
public class QuestStage extends JSONElement {
private static final long serialVersionUID = 8313645819951513431L;
@@ -16,7 +16,7 @@ public class QuestStage extends JSONElement {
public Integer exp_reward = null;
public Integer finishes_quest = null;
public QuestStage(Quest parent){
public QuestStage(Quest parent) {
this.parent = parent;
}
@@ -34,14 +34,14 @@ public class QuestStage extends JSONElement {
@Override
public void parse(Map jsonObj) {
progress = JSONElement.getInteger((Number) jsonObj.get("progress"));
this.id = ((Quest)parent).id+":"+progress;
this.id = ((Quest) parent).id + ":" + progress;
log_text = (String) jsonObj.get("logText");
exp_reward = JSONElement.getInteger((Number) jsonObj.get("rewardExperience"));
finishes_quest = JSONElement.getInteger((Number) jsonObj.get("finishesQuest"));
state = State.parsed;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Map toJson() {
Map stageJson = new LinkedHashMap();
@@ -54,22 +54,15 @@ public class QuestStage extends JSONElement {
@Override
public String getDesc() {
return progress+" - "+(exp_reward != null ? "["+exp_reward+"XP]" : "")+((finishes_quest != null) && (finishes_quest == 1) ? "[END]" : "")+log_text;
return progress + " - " + (exp_reward != null ? "[" + exp_reward + "XP]" : "") + ((finishes_quest != null) && (finishes_quest == 1) ? "[END]" : "") + log_text;
}
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
//Nothing to link to :D
this.state = State.linked;
@@ -82,7 +75,7 @@ public class QuestStage extends JSONElement {
@Override
public String getProjectFilename() {
return ((Quest)parent).getProjectFilename();
return ((Quest) parent).getProjectFilename();
}
@Override

View File

@@ -1,14 +1,14 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.Project;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.Project;
public class Requirement extends JSONElement {
private static final long serialVersionUID = 7295593297142310955L;
@@ -68,70 +68,39 @@ public class Requirement extends JSONElement {
}
public enum SkillID {
weaponChance
,weaponDmg
,barter
,dodge
,barkSkin
,moreCriticals
,betterCriticals
,speed // Raises max ap
,coinfinder
,moreExp
,cleave // +10ap on kill
,eater // +1hp per kill
,fortitude // +N hp per levelup
,evasion // increase successful flee chance & reduce chance of monster attack
,regeneration // +N hp per round
,lowerExploss
,magicfinder
,resistanceMental // lowers chance to get negative active conditions by monsters (Mental like Dazed)
,resistancePhysical // lowers chance to get negative active conditions by monsters (Physical Capacity like Minor fatigue)
,resistanceBlood // lowers chance to get negative active conditions by monsters (Blood Disorder like Weak Poison)
,shadowBless
,sporeImmunity
,crit1 // lowers atk ability
,crit2 // lowers def ability ,rejuvenation // Reduces magnitudes of conditions
,rejuvenation // Reduces magnitudes of conditions
,taunt // Causes AP loss of attackers that miss
,concussion // AC loss for monsters with (AC-BC)>N
,weaponProficiencyDagger
,weaponProficiency1hsword
,weaponProficiency2hsword
,weaponProficiencyAxe
,weaponProficiencyBlunt
,weaponProficiencyUnarmed
,weaponProficiencyPole
,armorProficiencyShield
,armorProficiencyUnarmored
,armorProficiencyLight
,armorProficiencyHeavy
,fightstyleDualWield
,fightstyle2hand
,fightstyleWeaponShield
,specializationDualWield
,specialization2hand
,specializationWeaponShield
weaponChance, weaponDmg, barter, dodge, barkSkin, moreCriticals, betterCriticals, speed // Raises max ap
, coinfinder, moreExp, cleave // +10ap on kill
, eater // +1hp per kill
, fortitude // +N hp per levelup
, evasion // increase successful flee chance & reduce chance of monster attack
, regeneration // +N hp per round
, lowerExploss, magicfinder, resistanceMental // lowers chance to get negative active conditions by monsters (Mental like Dazed)
, resistancePhysical // lowers chance to get negative active conditions by monsters (Physical Capacity like Minor fatigue)
, resistanceBlood // lowers chance to get negative active conditions by monsters (Blood Disorder like Weak Poison)
, shadowBless, sporeImmunity, crit1 // lowers atk ability
, crit2 // lowers def ability ,rejuvenation // Reduces magnitudes of conditions
, rejuvenation // Reduces magnitudes of conditions
, taunt // Causes AP loss of attackers that miss
, concussion // AC loss for monsters with (AC-BC)>N
, weaponProficiencyDagger, weaponProficiency1hsword, weaponProficiency2hsword, weaponProficiencyAxe, weaponProficiencyBlunt, weaponProficiencyUnarmed, weaponProficiencyPole, armorProficiencyShield, armorProficiencyUnarmored, armorProficiencyLight, armorProficiencyHeavy, fightstyleDualWield, fightstyle2hand, fightstyleWeaponShield, specializationDualWield, specialization2hand, specializationWeaponShield
}
@Override
public String getDesc() {
String obj_id = "";
if (required_obj_id != null)
{
if (required_obj_id != null) {
obj_id = required_obj_id;
if (type != null && type == RequirementType.random){
if (type != null && type == RequirementType.random) {
obj_id = " Chance " + obj_id + (required_obj_id.contains("/") ? "" : "%");
}
else {
} else {
obj_id += ":";
}
}
return ((negated != null && negated) ? "NOT " : "")
+(type == null ? "" : type.toString()+":")
+obj_id
+(required_value == null ? "" : required_value.toString());
+ (type == null ? "" : type.toString() + ":")
+ obj_id
+ (required_value == null ? "" : required_value.toString());
}
@Override
@@ -153,20 +122,13 @@ public class Requirement extends JSONElement {
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking requirement "+getDesc()+". No parent project found.");
Notification.addError("Error linking requirement " + getDesc() + ". No parent project found.");
return;
}
switch (type) {
@@ -187,7 +149,7 @@ public class Requirement extends JSONElement {
case questProgress:
this.required_obj = proj.getQuest(required_obj_id);
if (this.required_obj != null && this.required_value != null) {
QuestStage stage = ((Quest)this.required_obj).getStage(this.required_value);
QuestStage stage = ((Quest) this.required_obj).getStage(this.required_value);
if (stage != null) {
stage.addBacklink((GameDataElement) this.parent);
}
@@ -245,6 +207,7 @@ public class Requirement extends JSONElement {
}
}
}
@Override
public String getProjectFilename() {
throw new Error("Thou shalt not reach this method.");
@@ -257,8 +220,7 @@ public class Requirement extends JSONElement {
required_value = null;
}
if(destType==RequirementType.random)
{
if (destType == RequirementType.random) {
required_obj_id = "50/100";
}

View File

@@ -1,16 +1,17 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import java.awt.*;
public class ContainerArea extends MapObject {
public Droplist droplist = null;
public ContainerArea(tiled.core.MapObject obj) {}
public ContainerArea(tiled.core.MapObject obj) {
}
@Override
public void link() {

View File

@@ -1,18 +1,18 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import java.awt.*;
public class KeyArea extends MapObject {
public String dialogue_id = null;
public String dialogue_id;
public Dialogue dialogue = null;
public Requirement requirement = null;
public boolean oldSchoolRequirement = true;
public Requirement requirement;
public boolean oldSchoolRequirement;
public KeyArea(tiled.core.MapObject obj) {
dialogue_id = obj.getProperties().getProperty("phrase");
@@ -79,7 +79,7 @@ public class KeyArea extends MapObject {
}
if (requirement != null) {
if (oldSchoolRequirement && Requirement.RequirementType.questProgress.equals(requirement.type) && (requirement.negated == null || !requirement.negated)) {
tmxObject.setName(requirement.required_obj_id+":"+((requirement.required_value == null) ? "" : Integer.toString(requirement.required_value)));
tmxObject.setName(requirement.required_obj_id + ":" + ((requirement.required_value == null) ? "" : Integer.toString(requirement.required_value)));
} else {
if (requirement.type != null) {
tmxObject.getProperties().setProperty("requireType", requirement.type.toString());
@@ -101,7 +101,8 @@ public class KeyArea extends MapObject {
public void updateNameFromRequirementChange() {
if (oldSchoolRequirement && Requirement.RequirementType.questProgress.equals(requirement.type) && (requirement.negated == null || !requirement.negated)) {
name = (requirement.negated != null && requirement.negated) ? "NOT " : "" + requirement.required_obj_id+":"+((requirement.required_value == null) ? "" : Integer.toString(requirement.required_value));
name = (requirement.negated != null && requirement.negated) ? "NOT " : "" + requirement.required_obj_id + ":" + ((requirement.required_value == null) ? "" : Integer.toString(
requirement.required_value));
} else if (oldSchoolRequirement) {
int i = 0;
String futureName = requirement.type.toString() + "#" + Integer.toString(i);

View File

@@ -1,17 +1,16 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import java.awt.*;
public class MapChange extends MapObject {
public String map_id = null;
public String map_id;
public TMXMap map = null;
public String place_id = null;
public String place_id;
public MapChange(tiled.core.MapObject obj) {
this.map_id = obj.getProperties().getProperty("map");

View File

@@ -1,10 +1,10 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import java.awt.*;
public abstract class MapObject {
public int x, y, w, h;
@@ -64,7 +64,7 @@ public abstract class MapObject {
break;
}
} else {
Notification.addWarn("Unknown map object type: "+obj.getType()+"with name "+obj.getName()+" in map "+parentMap.id);
Notification.addWarn("Unknown map object type: " + obj.getType() + "with name " + obj.getName() + " in map " + parentMap.id);
}
if (result != null) {
result.x = obj.getX();

View File

@@ -1,10 +1,10 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import java.util.ArrayList;
import java.util.List;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
public class MapObjectGroup {

View File

@@ -1,17 +1,17 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class ReplaceArea extends MapObject {
public Requirement requirement = null;
public Requirement requirement;
public boolean oldSchoolRequirement = false;
public List<ReplaceArea.Replacement> replacements = null;
@@ -66,34 +66,20 @@ public class ReplaceArea extends MapObject {
requirement.elementChanged(oldOne, newOne);
}
public ReplaceArea.Replacement addReplacement(String source, String target) {
public ReplaceArea.Replacement createReplacement(String source, String target) {
Replacement repl = new Replacement(source, target);
addReplacement(repl);
return repl;
}
public void addReplacement(ReplaceArea.Replacement repl) {
if (replacements == null) replacements = new ArrayList<ReplaceArea.Replacement>();
replacements.add(repl);
}
// public void removeReplacement(String source, String target) {
// replacedLayers.remove(source);
// }
public void removeReplacement(Replacement repl) {
replacements.remove(repl);
}
@Override
public void savePropertiesInTmxObject(tiled.core.MapObject tmxObject) {
if (replacements != null) {
for(Replacement r : replacements)
for (Replacement r : replacements)
tmxObject.getProperties().setProperty(r.sourceLayer, r.targetLayer);
}
if (requirement != null) {
if (oldSchoolRequirement && Requirement.RequirementType.questProgress.equals(requirement.type) && (requirement.negated == null || !requirement.negated)) {
tmxObject.setName(requirement.required_obj_id+":"+((requirement.required_value == null) ? "" : Integer.toString(requirement.required_value)));
tmxObject.setName(requirement.required_obj_id + ":" + ((requirement.required_value == null) ? "" : Integer.toString(requirement.required_value)));
} else {
if (requirement.type != null) {
tmxObject.getProperties().setProperty("requireType", requirement.type.toString());
@@ -116,7 +102,8 @@ public class ReplaceArea extends MapObject {
//Don't use yet !
public void updateNameFromRequirementChange() {
if (oldSchoolRequirement && Requirement.RequirementType.questProgress.equals(requirement.type) && (requirement.negated == null || !requirement.negated)) {
name = (requirement.negated != null && requirement.negated) ? "NOT " : "" + requirement.required_obj_id+":"+((requirement.required_value == null) ? "" : Integer.toString(requirement.required_value));
name = (requirement.negated != null && requirement.negated) ? "NOT " : "" + requirement.required_obj_id + ":" + ((requirement.required_value == null) ? "" : Integer.toString(
requirement.required_value));
} else if (oldSchoolRequirement) {
int i = 0;
String futureName = requirement.type.toString() + "#" + Integer.toString(i);
@@ -130,6 +117,7 @@ public class ReplaceArea extends MapObject {
public class Replacement {
public String sourceLayer, targetLayer;
public Replacement(String source, String target) {
this.sourceLayer = source;
this.targetLayer = target;

View File

@@ -1,17 +1,19 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import java.awt.*;
public class RestArea extends MapObject {
public RestArea(tiled.core.MapObject obj) {}
public RestArea(tiled.core.MapObject obj) {
}
@Override
public void link() {}
public void link() {
}
@Override
public Image getIcon() {

View File

@@ -1,11 +1,11 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import java.awt.*;
public class ScriptArea extends MapObject {
public Dialogue dialogue = null;

View File

@@ -1,11 +1,11 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import java.awt.*;
public class SignArea extends MapObject {
public Dialogue dialogue = null;

View File

@@ -1,13 +1,13 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class SpawnArea extends MapObject {
public int quantity = 1;
@@ -32,7 +32,7 @@ public class SpawnArea extends MapObject {
}
if (obj.getProperties().getProperty("spawngroup") != null) {
this.spawngroup_id = obj.getProperties().getProperty("spawngroup");
} else if (obj.getName() != null ){
} else if (obj.getName() != null) {
this.spawngroup_id = obj.getName();
}
}

View File

@@ -1,35 +1,21 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.tree.TreeNode;
import tiled.io.TMXMapReader;
import tiled.io.TMXMapWriter;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.*;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
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.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import tiled.io.TMXMapReader;
import tiled.io.TMXMapWriter;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.io.*;
import java.util.List;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
public class TMXMap extends GameDataElement {
@@ -54,7 +40,7 @@ public class TMXMap extends GameDataElement {
bluetint
}
public File tmxFile = null;
public File tmxFile;
public tiled.core.Map tmxMap = null;
public Set<Spritesheet> usedSpritesheets = null;
public List<MapObjectGroup> groups = null;
@@ -86,9 +72,9 @@ public class TMXMap extends GameDataElement {
colorFilter = ColorFilter.valueOf(((String) tmxMap.getProperties().get("colorfilter")));
}
} catch (FileNotFoundException e) {
Notification.addError("Impossible to load TMX map file "+tmxFile.getAbsolutePath());
Notification.addError("Impossible to load TMX map file " + tmxFile.getAbsolutePath());
} catch (Exception e) {
Notification.addError("Error while loading TMX map file "+tmxFile.getAbsolutePath()+": "+e.getMessage());
Notification.addError("Error while loading TMX map file " + tmxFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
}
for (tiled.core.MapLayer layer : tmxMap.getLayers()) {
@@ -137,7 +123,7 @@ public class TMXMap extends GameDataElement {
s.addBacklink(clone);
}
} catch (Exception e) {
Notification.addError("Error while cloning map "+this.id+" : "+e.getMessage());
Notification.addError("Error while cloning map " + this.id + " : " + e.getMessage());
e.printStackTrace();
}
@@ -181,28 +167,30 @@ public class TMXMap extends GameDataElement {
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenRemoved(path);
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+id;
return (needsSaving() ? "*" : "") + id;
}
@Override
@@ -214,14 +202,21 @@ public class TMXMap extends GameDataElement {
public Image getIcon() {
return DefaultIcons.getTiledIconIcon();
}
@Override
public Image getLeafIcon() {
return DefaultIcons.getTiledIconIcon();
}
@Override
public Image getClosedIcon() {return null;}
public Image getClosedIcon() {
return null;
}
@Override
public Image getOpenIcon() {return null;}
public Image getOpenIcon() {
return null;
}
@Override
public GameDataSet getDataSet() {
@@ -258,10 +253,10 @@ public class TMXMap extends GameDataElement {
if (getDataType() == GameSource.Type.source) {
writer.writeMap(tmxMap, baos, tmxFile.getAbsolutePath());
} else {
writer.writeMap(tmxMap, baos, ((TMXMapSet)this.parent).mapFolder.getAbsolutePath()+File.separator+"placeholder.tmx");
writer.writeMap(tmxMap, baos, ((TMXMapSet) this.parent).mapFolder.getAbsolutePath() + File.separator + "placeholder.tmx");
}
} catch (Exception e) {
Notification.addError("Error while converting map "+getDesc()+" to XML: "+e.getMessage());
Notification.addError("Error while converting map " + getDesc() + " to XML: " + e.getMessage());
e.printStackTrace();
}
return baos.toString();
@@ -283,9 +278,9 @@ public class TMXMap extends GameDataElement {
w.close();
this.state = State.saved;
changedOnDisk = false;
Notification.addSuccess("TMX file "+tmxFile.getAbsolutePath()+" saved.");
Notification.addSuccess("TMX file " + tmxFile.getAbsolutePath() + " saved.");
} catch (IOException e) {
Notification.addError("Error while writing TMX file "+tmxFile.getAbsolutePath()+" : "+e.getMessage());
Notification.addError("Error while writing TMX file " + tmxFile.getAbsolutePath() + " : " + e.getMessage());
e.printStackTrace();
}
}
@@ -302,12 +297,12 @@ public class TMXMap extends GameDataElement {
if (writable) {
if (tmxFile.exists()) {
if (tmxFile.delete()) {
Notification.addSuccess("TMX file "+tmxFile.getAbsolutePath()+" deleted.");
Notification.addSuccess("TMX file " + tmxFile.getAbsolutePath() + " deleted.");
} else {
Notification.addError("Error while deleting TMX file "+tmxFile.getAbsolutePath());
Notification.addError("Error while deleting TMX file " + tmxFile.getAbsolutePath());
}
}
((TMXMapSet)parent).tmxMaps.remove(this);
((TMXMapSet) parent).tmxMaps.remove(this);
//TODO clear blacklinks ?
}
}
@@ -413,22 +408,24 @@ public class TMXMap extends GameDataElement {
for (MapObjectGroup g : groups) {
for (MapObject o : g.mapObjects) {
if (o instanceof ContainerArea) {
if (((ContainerArea)o).droplist != null) ((ContainerArea)o).droplist.elementChanged(this, null);
if (((ContainerArea) o).droplist != null) ((ContainerArea) o).droplist.elementChanged(this, null);
} else if (o instanceof KeyArea) {
if (((KeyArea)o).dialogue != null) ((KeyArea)o).dialogue.elementChanged(this, null);
if (((KeyArea)o).requirement != null && ((KeyArea)o).requirement.required_obj != null) ((KeyArea)o).requirement.required_obj.elementChanged(this, null);
if (((KeyArea) o).dialogue != null) ((KeyArea) o).dialogue.elementChanged(this, null);
if (((KeyArea) o).requirement != null && ((KeyArea) o).requirement.required_obj != null)
((KeyArea) o).requirement.required_obj.elementChanged(this, null);
} else if (o instanceof MapChange) {
if (((MapChange)o).map != null) ((MapChange)o).map.elementChanged(this, null);
if (((MapChange) o).map != null) ((MapChange) o).map.elementChanged(this, null);
} else if (o instanceof ReplaceArea) {
if (((ReplaceArea)o).requirement != null && ((ReplaceArea)o).requirement.required_obj != null) ((ReplaceArea)o).requirement.required_obj.elementChanged(this, null);
if (((ReplaceArea) o).requirement != null && ((ReplaceArea) o).requirement.required_obj != null)
((ReplaceArea) o).requirement.required_obj.elementChanged(this, null);
} else if (o instanceof RestArea) {
} else if (o instanceof ScriptArea) {
if (((ScriptArea)o).dialogue != null) ((ScriptArea)o).dialogue.elementChanged(this, null);
if (((ScriptArea) o).dialogue != null) ((ScriptArea) o).dialogue.elementChanged(this, null);
} else if (o instanceof SignArea) {
if (((SignArea)o).dialogue != null) ((SignArea)o).dialogue.elementChanged(this, null);
if (((SignArea) o).dialogue != null) ((SignArea) o).dialogue.elementChanged(this, null);
} else if (o instanceof SpawnArea) {
if (((SpawnArea)o).spawnGroup != null) {
for (NPC n : ((SpawnArea)o).spawnGroup) {
if (((SpawnArea) o).spawnGroup != null) {
for (NPC n : ((SpawnArea) o).spawnGroup) {
n.elementChanged(this, null);
}
}
@@ -461,6 +458,7 @@ public class TMXMap extends GameDataElement {
public interface MapChangedOnDiskListener {
public void mapChanged();
public void mapReloaded();
}

View File

@@ -1,24 +1,5 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
@@ -29,11 +10,20 @@ import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.utils.FileUtils;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class TMXMapSet implements ProjectTreeNode {
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res"+File.separator+"xml"+File.separator;
public static final String DEFAULT_REL_PATH_IN_PROJECT = "maps"+File.separator;
public static final String DEFAULT_REL_PATH_TO_DRAWABLE = ".."+File.separator+"drawable"+File.separator;
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res" + File.separator + "xml" + File.separator;
public static final String DEFAULT_REL_PATH_IN_PROJECT = "maps" + File.separator;
public static final String DEFAULT_REL_PATH_TO_DRAWABLE = ".." + File.separator + "drawable" + File.separator;
public static final String GAME_MAPS_ARRAY_NAME = "loadresource_maps";
public static final String DEBUG_SUFFIX = "_debug";
@@ -49,27 +39,26 @@ public class TMXMapSet implements ProjectTreeNode {
this.parent = source;
if (source.type == GameSource.Type.source) {
this.mapFolder = new File(source.baseFolder, DEFAULT_REL_PATH_IN_SOURCE);
}
else if (source.type == GameSource.Type.created | source.type == GameSource.Type.altered) {
} else if (source.type == GameSource.Type.created | source.type == GameSource.Type.altered) {
this.mapFolder = new File(source.baseFolder, DEFAULT_REL_PATH_IN_PROJECT);
if (!this.mapFolder.exists()) {
this.mapFolder.mkdirs();
}
FileUtils.makeSymlink(getProject().baseContent.gameSprites.drawableFolder, new File(mapFolder.getAbsolutePath()+File.separator+DEFAULT_REL_PATH_TO_DRAWABLE));
FileUtils.makeSymlink(getProject().baseContent.gameSprites.drawableFolder, new File(mapFolder.getAbsolutePath() + File.separator + DEFAULT_REL_PATH_TO_DRAWABLE));
}
this.tmxMaps = new ArrayList<TMXMap>();
if (source.type == GameSource.Type.source && (source.parent.sourceSetToUse == ResourceSet.debugData || source.parent.sourceSetToUse == ResourceSet.gameData)) {
String suffix = (source.parent.sourceSetToUse == ResourceSet.debugData) ? DEBUG_SUFFIX : "";
if (source.referencedSourceFiles.get(GAME_MAPS_ARRAY_NAME+suffix) != null) {
for (String resource : source.referencedSourceFiles.get(GAME_MAPS_ARRAY_NAME+suffix)) {
File f = new File(mapFolder, resource.replaceAll(RESOURCE_PREFIX, "")+FILENAME_SUFFIX);
if (source.referencedSourceFiles.get(GAME_MAPS_ARRAY_NAME + suffix) != null) {
for (String resource : source.referencedSourceFiles.get(GAME_MAPS_ARRAY_NAME + suffix)) {
File f = new File(mapFolder, resource.replaceAll(RESOURCE_PREFIX, "") + FILENAME_SUFFIX);
if (f.exists()) {
TMXMap map = new TMXMap(this, f);
tmxMaps.add(map);
} else {
Notification.addWarn("Unable to locate resource "+resource+" in the game source for project "+getProject().name);
Notification.addWarn("Unable to locate resource " + resource + " in the game source for project " + getProject().name);
}
}
}
@@ -93,16 +82,18 @@ public class TMXMapSet implements ProjectTreeNode {
});
if (source.type == GameSource.Type.created | source.type == GameSource.Type.altered) {
final Path folderPath = Paths.get(mapFolder.getAbsolutePath());
Thread watcher = new Thread("Map folder watcher for "+getProject().name+"/"+source.type) {
Thread watcher = new Thread("Map folder watcher for " + getProject().name + "/" + source.type) {
public void run() {
WatchService watchService;
while(getProject().open) {
while (getProject().open) {
try {
watchService = FileSystems.getDefault().newWatchService();
/*WatchKey watchKey = */folderPath.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE);
/*WatchKey watchKey = */
folderPath.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE);
WatchKey wk;
validService: while(getProject().open) {
validService:
while (getProject().open) {
wk = watchService.poll(10, TimeUnit.SECONDS);
if (wk != null) {
for (WatchEvent<?> event : wk.pollEvents()) {
@@ -114,7 +105,7 @@ public class TMXMapSet implements ProjectTreeNode {
map.mapChangedOnDisk();
}
}
if(!wk.reset()) {
if (!wk.reset()) {
watchService.close();
break validService;
}
@@ -126,7 +117,8 @@ public class TMXMapSet implements ProjectTreeNode {
e.printStackTrace();
}
}
};
}
};
watcher.start();
}
@@ -136,40 +128,49 @@ public class TMXMapSet implements ProjectTreeNode {
public Enumeration<TMXMap> children() {
return Collections.enumeration(tmxMaps);
}
@Override
public boolean getAllowsChildren() {
return true;
}
@Override
public TreeNode getChildAt(int arg0) {
return tmxMaps.get(arg0);
}
@Override
public int getChildCount() {
return tmxMaps.size();
}
@Override
public int getIndex(TreeNode arg0) {
return tmxMaps.indexOf(arg0);
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public boolean isLeaf() {
return false;
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
if (path.size() == 1 && this.getChildCount() == 1) {
@@ -179,6 +180,7 @@ public class TMXMapSet implements ProjectTreeNode {
parent.childrenRemoved(path);
}
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -186,9 +188,10 @@ public class TMXMapSet implements ProjectTreeNode {
map.notifyCreated();
}
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+"TMX Maps";
return (needsSaving() ? "*" : "") + "TMX Maps";
}
@Override
@@ -201,14 +204,17 @@ public class TMXMapSet implements ProjectTreeNode {
public Image getIcon() {
return getOpenIcon();
}
@Override
public Image getClosedIcon() {
return DefaultIcons.getTmxClosedIcon();
}
@Override
public Image getLeafIcon() {
return DefaultIcons.getTmxClosedIcon();
}
@Override
public Image getOpenIcon() {
return DefaultIcons.getTmxOpenIcon();
@@ -232,7 +238,7 @@ public class TMXMapSet implements ProjectTreeNode {
public TMXMap getMap(String id) {
if (tmxMaps == null) return null;
for (TMXMap map : tmxMaps) {
if (id.equals(map.id)){
if (id.equals(map.id)) {
return map;
}
}
@@ -242,7 +248,8 @@ public class TMXMapSet implements ProjectTreeNode {
public void addMap(TMXMap node) {
ProjectTreeNode higherEmptyParent = this;
while (higherEmptyParent != null) {
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode)higherEmptyParent.getParent()).isEmpty()) higherEmptyParent = (ProjectTreeNode)higherEmptyParent.getParent();
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode) higherEmptyParent.getParent()).isEmpty())
higherEmptyParent = (ProjectTreeNode) higherEmptyParent.getParent();
else break;
}
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;
@@ -252,7 +259,7 @@ public class TMXMapSet implements ProjectTreeNode {
node.tmxFile = new File(this.mapFolder, node.tmxFile.getName());
} else {
//Created node.
node.tmxFile = new File(this.mapFolder, node.id+".tmx");
node.tmxFile = new File(this.mapFolder, node.id + ".tmx");
}
node.parent = this;
if (higherEmptyParent != null) higherEmptyParent.notifyCreated();

View File

@@ -1,40 +1,5 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import java.awt.Point;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.tree.TreeNode;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
@@ -42,18 +7,35 @@ import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.swing.tree.TreeNode;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.awt.*;
import java.io.*;
import java.util.List;
import java.util.*;
public class Worldmap extends ArrayList<WorldmapSegment> implements ProjectTreeNode {
private static final long serialVersionUID = 4590409256594556179L;
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res/xml/worldmap.xml";
public static final String DEFAULT_REL_PATH_IN_PROJECT = "maps"+File.separator+"worldmap.xml";
public static final String DEFAULT_REL_PATH_IN_PROJECT = "maps" + File.separator + "worldmap.xml";
public File worldmapFile;
public GameSource parent;
public Map<String, Map<String, Point>> segments = new LinkedHashMap<String, Map<String,Point>>();
public Map<String, Map<String, Point>> segments = new LinkedHashMap<String, Map<String, Point>>();
public Worldmap(GameSource gameSource) {
this.parent = gameSource;
@@ -152,13 +134,13 @@ public class Worldmap extends ArrayList<WorldmapSegment> implements ProjectTreeN
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenChanged(path);
}
@@ -174,8 +156,9 @@ public class Worldmap extends ArrayList<WorldmapSegment> implements ProjectTreeN
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+"Worldmap";
return (needsSaving() ? "*" : "") + "Worldmap";
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -190,14 +173,17 @@ public class Worldmap extends ArrayList<WorldmapSegment> implements ProjectTreeN
public Image getIcon() {
return DefaultIcons.getMapClosedIcon();
}
@Override
public Image getLeafIcon() {
return null;
}
@Override
public Image getClosedIcon() {
return DefaultIcons.getMapClosedIcon();
}
@Override
public Image getOpenIcon() {
return DefaultIcons.getMapOpenIcon();
@@ -245,7 +231,8 @@ public class Worldmap extends ArrayList<WorldmapSegment> implements ProjectTreeN
public void addSegment(WorldmapSegment node) {
ProjectTreeNode higherEmptyParent = this;
while (higherEmptyParent != null) {
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode)higherEmptyParent.getParent()).isEmpty()) higherEmptyParent = (ProjectTreeNode)higherEmptyParent.getParent();
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode) higherEmptyParent.getParent()).isEmpty())
higherEmptyParent = (ProjectTreeNode) higherEmptyParent.getParent();
else break;
}
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;

View File

@@ -1,34 +1,26 @@
package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import java.awt.Point;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
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.ui.DefaultIcons;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.awt.*;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class WorldmapSegment extends GameDataElement {
@@ -56,7 +48,7 @@ public class WorldmapSegment extends GameDataElement {
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+id;
return (needsSaving() ? "*" : "") + id;
}
@Override
@@ -99,7 +91,7 @@ public class WorldmapSegment extends GameDataElement {
@Override
public WorldmapSegment clone() {
WorldmapSegment clone = new WorldmapSegment((Worldmap)parent, id, (Element) xmlNode.cloneNode(true));
WorldmapSegment clone = new WorldmapSegment((Worldmap) parent, id, (Element) xmlNode.cloneNode(true));
return clone;
}
@@ -130,7 +122,7 @@ public class WorldmapSegment extends GameDataElement {
}
oldOne.removeBacklink(this);
if(newOne != null) newOne.addBacklink(this);
if (newOne != null) newOne.addBacklink(this);
if (modified) {
this.state = GameDataElement.State.modified;
@@ -146,7 +138,7 @@ public class WorldmapSegment extends GameDataElement {
@Override
public void save() {
((Worldmap)parent).save();
((Worldmap) parent).save();
}
public String toXml() {
@@ -232,6 +224,7 @@ public class WorldmapSegment extends GameDataElement {
public Image getIcon() {
return DefaultIcons.getUIMapIcon();
}
@Override
public Image getLeafIcon() {
return DefaultIcons.getUIMapIcon();

View File

@@ -1,14 +1,5 @@
package com.gpl.rpg.atcontentstudio.model.saves;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.andorstrainer.io.SavedGameIO;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
@@ -18,6 +9,14 @@ import com.gpl.rpg.atcontentstudio.model.SaveEvent;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
public class SavedGame extends GameDataElement {
private static final long serialVersionUID = -6443495534761084990L;
@@ -35,7 +34,7 @@ public class SavedGame extends GameDataElement {
this.parent = parent;
this.loadedSave = SavedGameIO.loadFile(savedFile);
if (this.loadedSave == null) {
throw new IOException("Unable to load save: "+savedFile.getAbsolutePath());
throw new IOException("Unable to load save: " + savedFile.getAbsolutePath());
}
}
@@ -76,28 +75,30 @@ public class SavedGame extends GameDataElement {
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenRemoved(path);
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+loadedSave.displayInfo;
return (needsSaving() ? "*" : "") + loadedSave.displayInfo;
}
@Override
@@ -109,14 +110,21 @@ public class SavedGame extends GameDataElement {
public Image getIcon() {
return DefaultIcons.getHeroIcon();
}
@Override
public Image getLeafIcon() {
return DefaultIcons.getHeroIcon();
}
@Override
public Image getClosedIcon() {return null;}
public Image getClosedIcon() {
return null;
}
@Override
public Image getOpenIcon() {return null;}
public Image getOpenIcon() {
return null;
}
@Override
public GameDataSet getDataSet() {

View File

@@ -1,16 +1,5 @@
package com.gpl.rpg.atcontentstudio.model.saves;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.Project;
@@ -18,6 +7,16 @@ import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
public class SavedGamesSet implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = -6565834239789184087L;
@@ -45,7 +44,8 @@ public class SavedGamesSet implements ProjectTreeNode, Serializable {
try {
ProjectTreeNode higherEmptyParent = this;
while (higherEmptyParent != null) {
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode)higherEmptyParent.getParent()).isEmpty()) higherEmptyParent = (ProjectTreeNode)higherEmptyParent.getParent();
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode) higherEmptyParent.getParent()).isEmpty())
higherEmptyParent = (ProjectTreeNode) higherEmptyParent.getParent();
else break;
}
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;
@@ -105,11 +105,13 @@ public class SavedGamesSet implements ProjectTreeNode, Serializable {
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
if (path.size() == 1 && this.getChildCount() == 1) {
@@ -119,6 +121,7 @@ public class SavedGamesSet implements ProjectTreeNode, Serializable {
parent.childrenRemoved(path);
}
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -126,9 +129,10 @@ public class SavedGamesSet implements ProjectTreeNode, Serializable {
s.notifyCreated();
}
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+"Saved games";
return (needsSaving() ? "*" : "") + "Saved games";
}
@Override
@@ -141,14 +145,17 @@ public class SavedGamesSet implements ProjectTreeNode, Serializable {
public Image getIcon() {
return getOpenIcon();
}
@Override
public Image getClosedIcon() {
return DefaultIcons.getSavClosedIcon();
}
@Override
public Image getLeafIcon() {
return DefaultIcons.getSavClosedIcon();
}
@Override
public Image getOpenIcon() {
return DefaultIcons.getSavOpenIcon();
@@ -159,6 +166,7 @@ public class SavedGamesSet implements ProjectTreeNode, Serializable {
public GameDataSet getDataSet() {
return null;
}
@Override
public Type getDataType() {
return null;

View File

@@ -1,14 +1,5 @@
package com.gpl.rpg.atcontentstudio.model.sprites;
import java.awt.Image;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.Project;
@@ -16,10 +7,18 @@ import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
public class SpriteSheetSet implements ProjectTreeNode {
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res"+File.separator+"drawable"+File.separator;
public static final String DEFAULT_REL_PATH_IN_PROJECT = "spritesheets"+File.separator;
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res" + File.separator + "drawable" + File.separator;
public static final String DEFAULT_REL_PATH_IN_PROJECT = "spritesheets" + File.separator;
public File drawableFolder = null;
@@ -29,7 +28,8 @@ public class SpriteSheetSet implements ProjectTreeNode {
public SpriteSheetSet(GameSource source) {
this.parent = source;
if (source.type == GameSource.Type.source) this.drawableFolder = new File(source.baseFolder, DEFAULT_REL_PATH_IN_SOURCE);
if (source.type == GameSource.Type.source)
this.drawableFolder = new File(source.baseFolder, DEFAULT_REL_PATH_IN_SOURCE);
else if (source.type == GameSource.Type.created | source.type == GameSource.Type.altered) {
this.drawableFolder = new File(source.baseFolder, DEFAULT_REL_PATH_IN_PROJECT);
if (!this.drawableFolder.exists()) {
@@ -50,40 +50,49 @@ public class SpriteSheetSet implements ProjectTreeNode {
public Enumeration<Spritesheet> children() {
return Collections.enumeration(spritesheets);
}
@Override
public boolean getAllowsChildren() {
return true;
}
@Override
public TreeNode getChildAt(int arg0) {
return spritesheets.get(arg0);
}
@Override
public int getChildCount() {
return spritesheets.size();
}
@Override
public int getIndex(TreeNode arg0) {
return spritesheets.indexOf(arg0);
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public boolean isLeaf() {
return false;
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
if (path.size() == 1 && this.getChildCount() == 1) {
@@ -93,6 +102,7 @@ public class SpriteSheetSet implements ProjectTreeNode {
parent.childrenRemoved(path);
}
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
@@ -100,9 +110,10 @@ public class SpriteSheetSet implements ProjectTreeNode {
s.notifyCreated();
}
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+"Spritesheets";
return (needsSaving() ? "*" : "") + "Spritesheets";
}
@Override
@@ -114,14 +125,17 @@ public class SpriteSheetSet implements ProjectTreeNode {
public Image getIcon() {
return getOpenIcon();
}
@Override
public Image getClosedIcon() {
return DefaultIcons.getSpriteClosedIcon();
}
@Override
public Image getLeafIcon() {
return DefaultIcons.getSpriteClosedIcon();
}
@Override
public Image getOpenIcon() {
return DefaultIcons.getSpriteOpenIcon();
@@ -145,7 +159,7 @@ public class SpriteSheetSet implements ProjectTreeNode {
public Spritesheet getSpritesheet(String id) {
if (spritesheets == null) return null;
for (Spritesheet sheet : spritesheets) {
if (id.equals(sheet.id)){
if (id.equals(sheet.id)) {
return sheet;
}
}

View File

@@ -1,19 +1,5 @@
package com.gpl.rpg.atcontentstudio.model.sprites;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
@@ -23,6 +9,15 @@ import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import javax.imageio.ImageIO;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.*;
public class Spritesheet extends GameDataElement {
private static final long serialVersionUID = -5981708088278528586L;
@@ -40,7 +35,7 @@ public class Spritesheet extends GameDataElement {
monster,
item,
actorcondition
};
}
//Lazy initialization.
public BufferedImage spritesheet = null;
@@ -52,19 +47,19 @@ public class Spritesheet extends GameDataElement {
this.id = f.getName().substring(0, f.getName().lastIndexOf("."));
this.parent = parent;
String cat = getProject().getSpritesheetsProperty("atcs.spritesheet."+this.id+".category");
String cat = getProject().getSpritesheetsProperty("atcs.spritesheet." + this.id + ".category");
if (cat != null) {
this.category = Category.valueOf(cat);
}
String sizex = getProject().getSpritesheetsProperty("atcs.spritesheet."+this.id+".sizex");
String sizex = getProject().getSpritesheetsProperty("atcs.spritesheet." + this.id + ".sizex");
if (sizex != null) {
this.spriteWidth = Integer.parseInt(sizex);
}
String sizey = getProject().getSpritesheetsProperty("atcs.spritesheet."+this.id+".sizey");
String sizey = getProject().getSpritesheetsProperty("atcs.spritesheet." + this.id + ".sizey");
if (sizey != null) {
this.spriteHeight = Integer.parseInt(sizey);
}
String anim = getProject().getSpritesheetsProperty("atcs.spritesheet."+this.id+".animate");
String anim = getProject().getSpritesheetsProperty("atcs.spritesheet." + this.id + ".animate");
if (anim != null) {
this.animated = Boolean.parseBoolean(anim);
}
@@ -74,52 +69,63 @@ public class Spritesheet extends GameDataElement {
public Enumeration<ProjectTreeNode> children() {
return null;
}
@Override
public boolean getAllowsChildren() {
return false;
}
@Override
public TreeNode getChildAt(int arg0) {
return null;
}
@Override
public int getChildCount() {
return 0;
}
@Override
public int getIndex(TreeNode arg0) {
return 0;
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public boolean isLeaf() {
return true;
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0, this);
parent.childrenRemoved(path);
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+spritesheetFile.getName();
return (needsSaving() ? "*" : "") + spritesheetFile.getName();
}
@Override
@@ -132,12 +138,12 @@ public class Spritesheet extends GameDataElement {
try {
spritesheet = ImageIO.read(spritesheetFile);
} catch (IOException e) {
Notification.addError("Error loading image "+spritesheetFile.getAbsolutePath()+" : "+e.getMessage());
Notification.addError("Error loading image " + spritesheetFile.getAbsolutePath() + " : " + e.getMessage());
e.printStackTrace();
return 0;
}
}
return (int) (Math.ceil(((double)spritesheet.getWidth()) / ((double)spriteWidth)) * Math.ceil(((double)spritesheet.getHeight()) / ((double)spriteHeight)));
return (int) (Math.ceil(((double) spritesheet.getWidth()) / ((double) spriteWidth)) * Math.ceil(((double) spritesheet.getHeight()) / ((double) spriteHeight)));
}
public BufferedImage getImage(int index) {
@@ -145,7 +151,7 @@ public class Spritesheet extends GameDataElement {
try {
spritesheet = ImageIO.read(spritesheetFile);
} catch (IOException e) {
Notification.addError("Error loading image "+spritesheetFile.getAbsolutePath()+" : "+e.getMessage());
Notification.addError("Error loading image " + spritesheetFile.getAbsolutePath() + " : " + e.getMessage());
e.printStackTrace();
return null;
}
@@ -175,7 +181,7 @@ public class Spritesheet extends GameDataElement {
}
Image result = getImage(index);
if (result == null) return null;
result = result.getScaledInstance((int)(16*ATContentStudio.SCALING), (int)(16*ATContentStudio.SCALING), Image.SCALE_SMOOTH);
result = result.getScaledInstance((int) (16 * ATContentStudio.SCALING), (int) (16 * ATContentStudio.SCALING), Image.SCALE_SMOOTH);
cache_icon.put(index, result);
return result;
}
@@ -190,14 +196,21 @@ public class Spritesheet extends GameDataElement {
public Image getIcon() {
return getIcon(0);
}
@Override
public Image getLeafIcon() {
return getIcon();
}
@Override
public Image getClosedIcon() {return null;}
public Image getClosedIcon() {
return null;
}
@Override
public Image getOpenIcon() {return null;}
public Image getOpenIcon() {
return null;
}
@Override
@@ -217,7 +230,7 @@ public class Spritesheet extends GameDataElement {
@Override
public void parse() {
if(this.state == GameDataElement.State.init){
if (this.state == GameDataElement.State.init) {
this.state = GameDataElement.State.parsed;
}
}
@@ -227,7 +240,7 @@ public class Spritesheet extends GameDataElement {
if (this.state == GameDataElement.State.init) {
this.parse();
}
if(this.state == GameDataElement.State.parsed) {
if (this.state == GameDataElement.State.parsed) {
this.state = GameDataElement.State.linked;
}
}
@@ -255,10 +268,14 @@ public class Spritesheet extends GameDataElement {
@Override
public void save() {
if (this.category != null) getProject().setSpritesheetsProperty("atcs.spritesheet."+this.id+".category", this.category.toString());
if (this.spriteWidth != 32) getProject().setSpritesheetsProperty("atcs.spritesheet."+this.id+".sizex", Integer.toString(this.spriteWidth));
if (this.spriteHeight != 32) getProject().setSpritesheetsProperty("atcs.spritesheet."+this.id+".sizey", Integer.toString(this.spriteHeight));
if (this.animated)getProject().setSpritesheetsProperty("atcs.spritesheet."+this.id+".animate", Boolean.toString(this.animated));
if (this.category != null)
getProject().setSpritesheetsProperty("atcs.spritesheet." + this.id + ".category", this.category.toString());
if (this.spriteWidth != 32)
getProject().setSpritesheetsProperty("atcs.spritesheet." + this.id + ".sizex", Integer.toString(this.spriteWidth));
if (this.spriteHeight != 32)
getProject().setSpritesheetsProperty("atcs.spritesheet." + this.id + ".sizey", Integer.toString(this.spriteHeight));
if (this.animated)
getProject().setSpritesheetsProperty("atcs.spritesheet." + this.id + ".animate", Boolean.toString(this.animated));
getProject().save();
this.state = GameDataElement.State.saved;

View File

@@ -1,11 +1,6 @@
package com.gpl.rpg.atcontentstudio.model.tools.i18n;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.LinkedList;

View File

@@ -1,41 +1,34 @@
package com.gpl.rpg.atcontentstudio.model.tools.i18n;
import java.io.File;
import java.io.FileFilter;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javax.swing.JOptionPane;
import com.gpl.rpg.atcontentstudio.model.Project;
import net.launchpad.tobal.poparser.POEntry;
import net.launchpad.tobal.poparser.POFile;
import net.launchpad.tobal.poparser.POParser;
import javax.swing.*;
import java.io.File;
import java.io.FileFilter;
import java.util.*;
/**
*
* @author Kevin
*
* <p>
* To use this, paste the following script in the beanshell console of ATCS.
* Don't forget to change the project number to suit your needs.
* <p>
* <code>
*
import com.gpl.rpg.atcontentstudio.model.Workspace;
import com.gpl.rpg.atcontentstudio.model.tools.i18n.PotGenerator;
import com.gpl.rpg.atcontentstudio.model.tools.i18n.PotComparator;
proj = Workspace.activeWorkspace.projects.get(7);
PotGenerator.generatePotFileForProject(proj);
comp = new PotComparator(proj);
comp.compare();
comp.updatePoFiles(proj);
*
*
* import com.gpl.rpg.atcontentstudio.model.Workspace;
* import com.gpl.rpg.atcontentstudio.model.tools.i18n.PotGenerator;
* import com.gpl.rpg.atcontentstudio.model.tools.i18n.PotComparator;
*
* proj = Workspace.activeWorkspace.projects.get(7);
* PotGenerator.generatePotFileForProject(proj);
* comp = new PotComparator(proj);
* comp.compare();
* comp.updatePoFiles(proj);
* </code>
*/
public class PotComparator {
@@ -53,15 +46,15 @@ public class PotComparator {
public PotComparator(Project proj) {
POParser parser = new POParser();
POFile newPot = parser.parseFile(new File(proj.alteredContent.baseFolder.getAbsolutePath()+File.separator+"english.pot"));
POFile newPot = parser.parseFile(new File(proj.alteredContent.baseFolder.getAbsolutePath() + File.separator + "english.pot"));
if (newPot == null) {
System.err.println("Cannot locate new english.pot file at "+proj.alteredContent.baseFolder.getAbsolutePath()+File.separator);
System.err.println("Cannot locate new english.pot file at " + proj.alteredContent.baseFolder.getAbsolutePath() + File.separator);
}
extractFromPoFile(newPot, stringsResourcesNew, resourcesStringsNew);
POFile oldPot = parser.parseFile(new File(proj.baseContent.baseFolder.getAbsolutePath()+File.separator+"assets"+File.separator+"translation"+File.separator+"english.pot"));
POFile oldPot = parser.parseFile(new File(proj.baseContent.baseFolder.getAbsolutePath() + File.separator + "assets" + File.separator + "translation" + File.separator + "english.pot"));
if (oldPot == null) {
System.err.println("Cannot locate old english.pot file at "+proj.baseContent.baseFolder.getAbsolutePath()+File.separator+"assets"+File.separator+"translations"+File.separator);
System.err.println("Cannot locate old english.pot file at " + proj.baseContent.baseFolder.getAbsolutePath() + File.separator + "assets" + File.separator + "translations" + File.separator);
}
extractFromPoFile(oldPot, stringsResourcesOld, resourcesStringsOld);
}
@@ -80,7 +73,7 @@ public class PotComparator {
}
if (msgid.contains("\\n")) {
msgid = msgid.replaceAll("\\\\n", "\\\\n\"\n\"");
msgid = "\"\n\""+msgid;
msgid = "\"\n\"" + msgid;
}
for (String resLine : resources) {
String[] resArray = resLine.split(" ");
@@ -107,23 +100,23 @@ public class PotComparator {
sb.append("---------------------------------------------\n");
sb.append("--- TYPO CHECK ------------------------------\n");
sb.append("---------------------------------------------\n");
sb.append("String at: "+oldRes+"\n");
sb.append("String at: " + oldRes + "\n");
if (allOldResources.size() > 1) {
sb.append("Also present at:\n");
for (String res : allOldResources) {
if (!res.equals(oldRes)) {
sb.append("- "+res+"\n");
sb.append("- " + res + "\n");
}
}
}
if (allNewResources != null) {
sb.append("Still present at: \n");
for (String res : allNewResources) {
sb.append("- "+res+"\n");
sb.append("- " + res + "\n");
}
}
sb.append("Was : \""+oldString+"\"\n");
sb.append("Now : \""+newString+"\"\n");
sb.append("Was : \"" + oldString + "\"\n");
sb.append("Now : \"" + newString + "\"\n");
System.out.println(sb.toString());
showTypoDialog(oldString, newString, sb.toString());
}
@@ -134,29 +127,30 @@ public class PotComparator {
System.out.println("---------------------------------------------");
System.out.println("--- REMOVED RESOURCE ------------------------");
System.out.println("---------------------------------------------");
System.out.println("String at: "+oldRes);
System.out.println("String at: " + oldRes);
if (allOldResources.size() > 1) {
System.out.println("And also at:");
for (String res : allOldResources) {
if (!res.equals(oldRes)) {
System.out.println("- "+res);
System.out.println("- " + res);
}
}
}
System.out.println("Was: \""+oldString+"\"");
System.out.println("Was: \"" + oldString + "\"");
if (allNewResources == null) {
System.out.println("Absent from new.");
} else {
System.out.println("Still present at: ");
for (String res : allNewResources) {
System.out.println("- "+res);
System.out.println("- " + res);
}
}
}
}
}
removedStrings: for (String oldString : stringsResourcesOld.keySet()) {
removedStrings:
for (String oldString : stringsResourcesOld.keySet()) {
if (stringsResourcesNew.get(oldString) == null) {
List<String> allOldResources = stringsResourcesOld.get(oldString);
if (allOldResources.size() >= 1) {
@@ -171,11 +165,11 @@ public class PotComparator {
System.out.println("---------------------------------------------");
System.out.println("--- REMOVED STRING --------------------------");
System.out.println("---------------------------------------------");
System.out.println("String: \""+oldString+"\"");
System.out.println("String: \"" + oldString + "\"");
if (allOldResources.size() > 0) {
System.out.println("Was at:");
for (String res : allOldResources) {
System.out.println("- "+res);
System.out.println("- " + res);
}
}
System.out.println("This string is absent from the new file, and its attached resources are missing too.");
@@ -189,7 +183,7 @@ public class PotComparator {
String review = "Review";
String outdated = "Outdated";
String none = "None";
Object[] options = new Object[] {typo, review, outdated, none};
Object[] options = new Object[]{typo, review, outdated, none};
int result = JOptionPane.showOptionDialog(null, checkReport, "Choose action", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, typo);
@@ -198,7 +192,7 @@ public class PotComparator {
return;
}
System.out.println("Decision: "+options[result]);
System.out.println("Decision: " + options[result]);
if (options[result] != none) {
msgIdToReplace.put(oldMsg, newMsg);
@@ -213,7 +207,7 @@ public class PotComparator {
public void updatePoFiles(Project proj) {
File poFolder = new File(proj.baseContent.baseFolder.getAbsolutePath()+File.separator+"assets"+File.separator+"translation");
File poFolder = new File(proj.baseContent.baseFolder.getAbsolutePath() + File.separator + "assets" + File.separator + "translation");
File[] poFiles = poFolder.listFiles(new FileFilter() {
@Override
public boolean accept(File arg0) {
@@ -261,7 +255,7 @@ public class PotComparator {
}
if (msgid.contains("\\n")) {
msgid = msgid.replaceAll("\\\\n", "\\\\n\"\n\"");
msgid = "\"\n\""+msgid;
msgid = "\"\n\"" + msgid;
}
String translation = "";
if (!msgstrs.isEmpty()) {
@@ -274,7 +268,7 @@ public class PotComparator {
}
if (translation.contains("\\n")) {
translation = translation.replaceAll("\\\\n", "\\\\n\"\n\"");
translation = "\"\n\""+translation;
translation = "\"\n\"" + translation;
}
}
translations.put(msgid, translation);
@@ -293,18 +287,18 @@ public class PotComparator {
for (String msgid : msgIdToReview) {
if (translations.containsKey(msgid)) {
String trans = translations.get(msgid);
if (trans != null && trans.length() >= 1) translations.put(msgid, "[REVIEW]"+trans);
if (trans != null && trans.length() >= 1) translations.put(msgid, "[REVIEW]" + trans);
}
}
for (String msgid : msgIdOutdated) {
if (translations.containsKey(msgid)) {
String trans = translations.get(msgid);
if (trans != null && trans.length() >= 1) translations.put(msgid, "[OUTDATED]"+trans);
if (trans != null && trans.length() >= 1) translations.put(msgid, "[OUTDATED]" + trans);
}
}
PoPotWriter.writePoFile(stringsResourcesNew, translations, new File(proj.alteredContent.baseFolder.getAbsolutePath()+File.separator+f.getName()));
PoPotWriter.writePoFile(stringsResourcesNew, translations, new File(proj.alteredContent.baseFolder.getAbsolutePath() + File.separator + f.getName()));
}
}

View File

@@ -1,23 +1,16 @@
package com.gpl.rpg.atcontentstudio.model.tools.i18n;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.*;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
public class PotGenerator {
public static void generatePotFileForProject(Project proj) {
@@ -28,15 +21,15 @@ public class PotGenerator {
for (ActorCondition ac : gsrc.gameData.actorConditions) {
pushString(stringsResources, resourcesStrings, ac.display_name, getPotContextComment(ac));
pushString(stringsResources, resourcesStrings, ac.description, getPotContextComment(ac)+":description");
pushString(stringsResources, resourcesStrings, ac.description, getPotContextComment(ac) + ":description");
}
for (Dialogue d : gsrc.gameData.dialogues ) {
for (Dialogue d : gsrc.gameData.dialogues) {
pushString(stringsResources, resourcesStrings, d.message, getPotContextComment(d));
if (d.replies == null) continue;
for (Dialogue.Reply r : d.replies) {
if (r.text != null && !r.text.equals(Dialogue.Reply.GO_NEXT_TEXT) ) {
pushString(stringsResources, resourcesStrings, r.text, getPotContextComment(d)+":"+d.replies.indexOf(r));
if (r.text != null && !r.text.equals(Dialogue.Reply.GO_NEXT_TEXT)) {
pushString(stringsResources, resourcesStrings, r.text, getPotContextComment(d) + ":" + d.replies.indexOf(r));
}
}
}
@@ -47,10 +40,10 @@ public class PotGenerator {
for (Item i : gsrc.gameData.items) {
pushString(stringsResources, resourcesStrings, i.name, getPotContextComment(i));
pushString(stringsResources, resourcesStrings, i.description, getPotContextComment(i)+":description");
pushString(stringsResources, resourcesStrings, i.description, getPotContextComment(i) + ":description");
}
for (NPC npc : gsrc.gameData.npcs ) {
for (NPC npc : gsrc.gameData.npcs) {
pushString(stringsResources, resourcesStrings, npc.name, getPotContextComment(npc));
}
@@ -58,14 +51,14 @@ public class PotGenerator {
if (q.visible_in_log != null && q.visible_in_log != 0) {
pushString(stringsResources, resourcesStrings, q.name, getPotContextComment(q));
for (QuestStage qs : q.stages) {
pushString(stringsResources, resourcesStrings, qs.log_text, getPotContextComment(q)+":"+Integer.toString(qs.progress));
pushString(stringsResources, resourcesStrings, qs.log_text, getPotContextComment(q) + ":" + Integer.toString(qs.progress));
}
}
}
for (WorldmapSegment ws : gsrc.worldmap) {
for (WorldmapSegment.NamedArea area : ws.labels.values()) {
pushString(stringsResources, resourcesStrings, area.name, gsrc.worldmap.worldmapFile.getName()+":"+ws.id+":"+area.id);
pushString(stringsResources, resourcesStrings, area.name, gsrc.worldmap.worldmapFile.getName() + ":" + ws.id + ":" + area.id);
}
}
@@ -74,7 +67,7 @@ public class PotGenerator {
}
private static void pushString (Map<String, List<String>> stringsResources, Map<String, String> resourcesStrings, String translatableString, String resourceIdentifier) {
private static void pushString(Map<String, List<String>> stringsResources, Map<String, String> resourcesStrings, String translatableString, String resourceIdentifier) {
if (translatableString == null) return;
if (translatableString.length() == 0) return;
if (translatableString.contains("\"")) {
@@ -82,7 +75,7 @@ public class PotGenerator {
}
if (translatableString.contains("\n")) {
translatableString = translatableString.replaceAll("\n", "\\\\n\"\n\"");
translatableString = "\"\n\""+translatableString;
translatableString = "\"\n\"" + translatableString;
}
resourcesStrings.put(resourceIdentifier, translatableString);
List<String> resourceIdentifiers = stringsResources.get(translatableString);
@@ -94,7 +87,7 @@ public class PotGenerator {
}
private static String getPotContextComment(JSONElement e) {
return e.jsonFile.getName()+":"+e.id;
return e.jsonFile.getName() + ":" + e.id;
}

View File

@@ -1,30 +1,7 @@
package com.gpl.rpg.atcontentstudio.model.tools.resoptimizer;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.json.simple.JSONArray;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
@@ -38,27 +15,34 @@ import com.whoischarles.util.json.Minify;
import com.whoischarles.util.json.Minify.UnterminatedCommentException;
import com.whoischarles.util.json.Minify.UnterminatedRegExpLiteralException;
import com.whoischarles.util.json.Minify.UnterminatedStringLiteralException;
import org.json.simple.JSONArray;
import tiled.core.TileSet;
import tiled.io.TMXMapWriter;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.List;
import java.util.*;
/**
*
* @author Kevin
*
* <p>
* To use this, paste the following script in the beanshell console of ATCS.
* Don't forget to change the project number to suit your needs.
* <p>
* <code>
* import com.gpl.rpg.atcontentstudio.model.tools.resoptimizer.ResourcesCompactor;
* import com.gpl.rpg.atcontentstudio.model.Workspace;
*
import com.gpl.rpg.atcontentstudio.model.tools.resoptimizer.ResourcesCompactor;
import com.gpl.rpg.atcontentstudio.model.Workspace;
proj = Workspace.activeWorkspace.projects.get(0);
new ResourcesCompactor(proj).compactData();
*
* proj = Workspace.activeWorkspace.projects.get(0);
* new ResourcesCompactor(proj).compactData();
* </code>
*/
public class ResourcesCompactor {
public static String DEFAULT_REL_PATH_IN_PROJECT = "compressed"+File.separator;
public static String DEFAULT_REL_PATH_IN_PROJECT = "compressed" + File.separator;
private Project proj;
private File baseFolder;
@@ -82,11 +66,11 @@ public class ResourcesCompactor {
public void compactData() {
compactJsonData();
for(CompressedSpritesheet cs : compressedSpritesheets) {
for (CompressedSpritesheet cs : compressedSpritesheets) {
cs.drawFile();
}
for (File preserved : preservedSpritesheets) {
FileUtils.copyFile(preserved, new File(baseFolder.getAbsolutePath()+File.separator+DEFAULT_DRAWABLE_REL_PATH+File.separator+preserved.getName()));
FileUtils.copyFile(preserved, new File(baseFolder.getAbsolutePath() + File.separator + DEFAULT_DRAWABLE_REL_PATH + File.separator + preserved.getName()));
}
compactMaps();
}
@@ -94,7 +78,7 @@ public class ResourcesCompactor {
public void compactJsonData() {
final List<File> filesCovered = new LinkedList<File>();
File folder = new File(baseFolder.getAbsolutePath()+File.separator+GameDataSet.DEFAULT_REL_PATH_IN_SOURCE);
File folder = new File(baseFolder.getAbsolutePath() + File.separator + GameDataSet.DEFAULT_REL_PATH_IN_SOURCE);
if (!folder.exists()) folder.mkdirs();
for (ActorCondition ac : proj.baseContent.gameData.actorConditions) {
@@ -195,6 +179,7 @@ public class ResourcesCompactor {
e.printStackTrace();
}
}
private void compactMaps() {
for (TMXMap map : proj.baseContent.gameMaps.tmxMaps) {
TMXMap clone = map.clone();
@@ -206,12 +191,11 @@ public class ResourcesCompactor {
compactMap(tmx, map.id);
clone.tmxMap = null;
clone.groups.clear();
clone = null;
}
}
private void compactMap(tiled.core.Map tmx, String name) {
File target = new File(baseFolder.getAbsolutePath()+File.separator+TMXMapSet.DEFAULT_REL_PATH_IN_SOURCE+File.separator+name+".tmx");
File target = new File(baseFolder.getAbsolutePath() + File.separator + TMXMapSet.DEFAULT_REL_PATH_IN_SOURCE + File.separator + name + ".tmx");
if (!target.getParentFile().exists()) target.getParentFile().mkdirs();
Map<tiled.core.Tile, SpritesheetId> localConvertions = new LinkedHashMap<tiled.core.Tile, SpritesheetId>();
@@ -251,7 +235,7 @@ public class ResourcesCompactor {
} catch (IOException e) {
e.printStackTrace();
}
ts.setName(cs.prefix+Integer.toString(cs.index));
ts.setName(cs.prefix + Integer.toString(cs.index));
//ts.setSource("../drawable/"+ts.getName()+TILESHEET_SUFFIX);
tmx.addTileset(ts);
}
@@ -334,9 +318,9 @@ public class ResourcesCompactor {
this.prefix = prefix;
this.index = index;
File folder = new File(ResourcesCompactor.this.baseFolder.getAbsolutePath()+File.separator+DEFAULT_DRAWABLE_REL_PATH);
File folder = new File(ResourcesCompactor.this.baseFolder.getAbsolutePath() + File.separator + DEFAULT_DRAWABLE_REL_PATH);
if (!folder.exists()) folder.mkdirs();
this.f = new File(folder, prefix+Integer.toString(index)+TILESHEET_SUFFIX);
this.f = new File(folder, prefix + Integer.toString(index) + TILESHEET_SUFFIX);
}
public boolean hasFreeSlot() {
@@ -347,14 +331,14 @@ public class ResourcesCompactor {
mustDraw = true;
originalSpritesId[nextFreeSlot] = spriteId;
nextFreeSlot++;
return SpritesheetId.getInstance(prefix+Integer.toString(index), nextFreeSlot - 1);
return SpritesheetId.getInstance(prefix + Integer.toString(index), nextFreeSlot - 1);
}
public void drawFile() {
if (!mustDraw) return;
BufferedImage img = new BufferedImage(TILESHEET_WIDTH_IN_SPRITES * TILE_WIDTH_IN_PIXELS, TILESHEET_HEIGHT_IN_SPRITES * TILE_HEIGHT_IN_PIXELS, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D)img.getGraphics();
Graphics2D g = (Graphics2D) img.getGraphics();
Color transparent = new Color(0, 0, 0, 0);
g.setColor(transparent);
g.fillRect(0, 0, img.getWidth(), img.getHeight());

View File

@@ -32,7 +32,7 @@ public class SpritesheetId {
}
static String toStringID(String tileset, int offset) {
return tileset+":"+Integer.toString(offset);
return tileset + ":" + Integer.toString(offset);
}
}

View File

@@ -1,6 +1,17 @@
package com.gpl.rpg.atcontentstudio.model.tools.writermode;
import java.awt.Image;
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.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -12,18 +23,6 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
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.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class WriterModeData extends GameDataElement {
private static final long serialVersionUID = -7062544089063979696L;
@@ -42,7 +41,7 @@ public class WriterModeData extends GameDataElement {
public Map<String, Integer> threadsNextIndex = new LinkedHashMap<String, Integer>();
public WriterModeData(String id_prefix){
public WriterModeData(String id_prefix) {
this.id = id_prefix;
}
@@ -63,7 +62,7 @@ public class WriterModeData extends GameDataElement {
public int getNextIndex(String id_prefix) {
Integer index = threadsNextIndex.get(id_prefix);
if (index == null) index = 0;
while (getProject().getDialogue(id_prefix+index) != null) {
while (getProject().getDialogue(id_prefix + index) != null) {
index++;
}
threadsNextIndex.put(id_prefix, index + 1);
@@ -95,7 +94,8 @@ public class WriterModeData extends GameDataElement {
public String dialogue_id;
public Dialogue dialogue;
public WriterDialogue() {}
public WriterDialogue() {
}
public WriterDialogue(Dialogue dialogue) {
this.dialogue = dialogue;
@@ -107,7 +107,7 @@ public class WriterModeData extends GameDataElement {
this.id_prefix = m.group(1);
this.index = Integer.parseInt(m.group(2));
} else {
this.id_prefix = this.id+"_";
this.id_prefix = this.id + "_";
}
nodesById.put(this.id, this);
if (dialogue.replies != null) {
@@ -129,14 +129,14 @@ public class WriterModeData extends GameDataElement {
@Override
public String getTitle() {
return "Dialogue "+getID();
return "Dialogue " + getID();
}
public String getID() {
return this.id != null ? this.id : this.id_prefix+this.index;
return this.id != null ? this.id : this.id_prefix + this.index;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public void toJson(List<WriterDialogue> visited, List<Map> jsonData) {
if (visited.contains(this)) return;
visited.add(this);
@@ -165,28 +165,30 @@ public class WriterModeData extends GameDataElement {
@SuppressWarnings("rawtypes")
public WriterDialogue(Map json) {
this.id = (String) json.get("id");
this.index = ((Number)json.get("index")).intValue();
this.index = ((Number) json.get("index")).intValue();
this.id_prefix = (String) json.get("id_prefix");
if (threadsNextIndex.get(id_prefix) == null || threadsNextIndex.get(id_prefix) <= index) {
threadsNextIndex.put(id_prefix, index+1);
threadsNextIndex.put(id_prefix, index + 1);
}
this.text = (String) json.get("text");
this.dialogue_id = (String) json.get("dialogue");
if (json.get("begin") != null && ((Boolean)json.get("begin"))) begin = this;
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")) {
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)));
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));
}
}
}
}
public boolean isSpecial() {return false;}
public boolean isSpecial() {
return false;
}
public Dialogue toDialogue(Map<WriterDialogue, Dialogue> visited, List<Dialogue> created, List<Dialogue> modified) {
@@ -241,7 +243,7 @@ public class WriterModeData extends GameDataElement {
public boolean hasChanged() {
return dialogue == null ||
text == null ? dialogue.message!=null : !text.equals(dialogue.message) ||
text == null ? dialogue.message != null : !text.equals(dialogue.message) ||
repliesHaveChanged();
}
@@ -260,35 +262,63 @@ public class WriterModeData extends GameDataElement {
public abstract class SpecialDialogue extends WriterDialogue {
public SpecialDialogue() {}
public boolean isSpecial() {return true;}
public SpecialDialogue() {
}
public boolean isSpecial() {
return true;
}
public abstract SpecialDialogue duplicate();
public SpecialDialogue(Dialogue dialogue) {
super(dialogue);
}
}
public class SelectorDialogue extends SpecialDialogue {
public SelectorDialogue() {}
public SpecialDialogue duplicate() {return new SelectorDialogue();}
public SelectorDialogue() {
}
public SpecialDialogue duplicate() {
return new SelectorDialogue();
}
public SelectorDialogue(Dialogue dialogue) {
super(dialogue);
}
}
public class ShopDialogue extends SpecialDialogue {
public static final String id = Dialogue.Reply.SHOP_PHRASE_ID;
public SpecialDialogue duplicate() {return new ShopDialogue();}
public SpecialDialogue duplicate() {
return new ShopDialogue();
}
}
public class FightDialogue extends SpecialDialogue {
public static final String id = Dialogue.Reply.FIGHT_PHRASE_ID;
public SpecialDialogue duplicate() {return new FightDialogue();}
public SpecialDialogue duplicate() {
return new FightDialogue();
}
}
public class EndDialogue extends SpecialDialogue {
public static final String id = Dialogue.Reply.EXIT_PHRASE_ID;
public SpecialDialogue duplicate() {return new EndDialogue();}
public SpecialDialogue duplicate() {
return new EndDialogue();
}
}
public class RemoveNPCDialogue extends SpecialDialogue {
public static final String id = Dialogue.Reply.REMOVE_PHRASE_ID;
public SpecialDialogue duplicate() {return new RemoveNPCDialogue();}
public SpecialDialogue duplicate() {
return new RemoveNPCDialogue();
}
}
public class WriterReply extends WriterNode {
@@ -297,7 +327,8 @@ public class WriterModeData extends GameDataElement {
public WriterDialogue next_dialogue;
public Dialogue.Reply reply;
public WriterReply() {}
public WriterReply() {
}
public WriterReply(WriterDialogue parent) {
this.parent = parent;
@@ -312,7 +343,7 @@ public class WriterModeData extends GameDataElement {
this.next_dialogue_id = reply.next_phrase_id;
if (nodesById.get(this.next_dialogue_id) != null) {
this.next_dialogue = nodesById.get(this.next_dialogue_id);
} else if (reply.next_phrase != null ){
} else if (reply.next_phrase != null) {
this.next_dialogue = new WriterDialogue(reply.next_phrase);
}
}
@@ -328,10 +359,10 @@ public class WriterModeData extends GameDataElement {
@Override
public String getTitle() {
return "Reply in "+parent.id_prefix+parent.index;
return "Reply in " + parent.id_prefix + parent.index;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public Map toJson(List<WriterDialogue> visited, List<Map> jsonData) {
Map replyJson = new LinkedHashMap();
replyJson.put("text", text);
@@ -343,7 +374,9 @@ public class WriterModeData extends GameDataElement {
return replyJson;
}
public boolean isSpecial() {return false;}
public boolean isSpecial() {
return false;
}
public Dialogue.Reply toReply(Map<WriterDialogue, Dialogue> visited, List<Dialogue> created, List<Dialogue> modified) {
if (reply == null) {
@@ -375,12 +408,13 @@ public class WriterModeData extends GameDataElement {
}
}
public class SpecialReply extends WriterReply {
public boolean isSpecial() {return true;}
public boolean isSpecial() {
return true;
}
public SpecialReply(WriterDialogue parent, Dialogue.Reply reply) {
super(parent, reply);
@@ -394,6 +428,7 @@ public class WriterModeData extends GameDataElement {
super(parent, json);
}
}
public class EmptyReply extends SpecialReply {
public EmptyReply(WriterDialogue parent, Dialogue.Reply reply) {
@@ -413,11 +448,11 @@ public class WriterModeData extends GameDataElement {
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+id;
return (needsSaving() ? "*" : "") + id;
}
@Override
public Project getProject() {
return parent.getProject();
@@ -427,18 +462,22 @@ public class WriterModeData extends GameDataElement {
public Image getIcon() {
return DefaultIcons.getDialogueIcon();
}
@Override
public Image getOpenIcon() {
return null;
}
@Override
public Image getClosedIcon() {
return null;
}
@Override
public Image getLeafIcon() {
return getIcon();
}
@Override
public GameDataSet getDataSet() {
return null;
@@ -449,11 +488,13 @@ public class WriterModeData extends GameDataElement {
//TODO
return null;
}
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
// Useless here.
}
@Override
public String getProjectFilename() {
return WriterModeDataSet.DEFAULT_REL_PATH_IN_PROJECT;
@@ -461,12 +502,12 @@ public class WriterModeData extends GameDataElement {
@Override
public void save() {
((WriterModeDataSet)this.getParent()).save(this.jsonFile);
((WriterModeDataSet) this.getParent()).save(this.jsonFile);
}
@Override
public List<SaveEvent> attemptSave() {
List<SaveEvent> events = ((WriterModeDataSet)parent).attemptSave();
List<SaveEvent> events = ((WriterModeDataSet) parent).attemptSave();
if (events == null || events.isEmpty()) {
return null;
}
@@ -477,7 +518,7 @@ public class WriterModeData extends GameDataElement {
return events;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public Map toJson() {
List<Map> jsonData = new ArrayList<Map>();
begin.toJson(new ArrayList<WriterModeData.WriterDialogue>(), jsonData);
@@ -489,32 +530,29 @@ public class WriterModeData extends GameDataElement {
@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;
}
if (shouldSkipParse()) 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;
Map jsonObj = (Map) obj;
String id = (String) jsonObj.get("id");
if (id != null && id.equals(this.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());
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());
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());
Notification.addError("Error while parsing JSON file " + jsonFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -540,7 +578,7 @@ public class WriterModeData extends GameDataElement {
List jsonDialogues = (List) json.get("dialogues");
if (jsonDialogues != null) {
for (Object jsonDialogue : jsonDialogues) {
WriterDialogue dialogue = new WriterDialogue((Map)jsonDialogue);
WriterDialogue dialogue = new WriterDialogue((Map) jsonDialogue);
nodesById.put(dialogue.getID(), dialogue);
}
}
@@ -562,8 +600,8 @@ public class WriterModeData extends GameDataElement {
}
if (this.state == State.parsed) {
for (String prefix : threadsNextIndex.keySet()) {
while (getProject().getDialogue(prefix+threadsNextIndex.get(prefix)) != null) {
threadsNextIndex.put(prefix, threadsNextIndex.get(prefix)+1);
while (getProject().getDialogue(prefix + threadsNextIndex.get(prefix)) != null) {
threadsNextIndex.put(prefix, threadsNextIndex.get(prefix) + 1);
}
}
for (WriterDialogue dialogue : nodesById.values()) {
@@ -592,11 +630,13 @@ public class WriterModeData extends GameDataElement {
score = 0;
//Arbitrary values... hopefully this gives good results.
//Same target gives good hope of preserving at least the structure.
if (dReply.next_phrase_id != null && dReply.next_phrase_id.equals(reply.next_dialogue_id)) score +=50;
if (dReply.next_phrase_id != null && dReply.next_phrase_id.equals(reply.next_dialogue_id))
score += 50;
//Same text is almost as good as an ID, but there may be duplicates due to requirements system...
if (dReply.text != null && dReply.text.equals(reply.text)) score +=40;
if (dReply.text != null && dReply.text.equals(reply.text)) score += 40;
//Same slot in the list. That's not so bad if all else fails, and could help sort duplicates with same text.
if (dialogue.dialogue.replies.indexOf(dReply) == dialogue.replies.indexOf(reply)) score +=20;
if (dialogue.dialogue.replies.indexOf(dReply) == dialogue.replies.indexOf(reply))
score += 20;
//Both have null text. It's not much, but it's something....
if (dReply.text == null && reply.text == null) score += 10;
if (score > maxScore) {
@@ -643,7 +683,7 @@ public class WriterModeData extends GameDataElement {
return null;
}
public List<Dialogue> toDialogue(){
public List<Dialogue> toDialogue() {
Map<WriterModeData.WriterDialogue, Dialogue> visited = new LinkedHashMap<WriterModeData.WriterDialogue, Dialogue>();
List<Dialogue> created = new ArrayList<Dialogue>();
List<Dialogue> modified = new ArrayList<Dialogue>();

View File

@@ -1,35 +1,20 @@
package com.gpl.rpg.atcontentstudio.model.tools.writermode;
import java.awt.Image;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import com.gpl.rpg.atcontentstudio.model.*;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
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.ui.DefaultIcons;
import javax.swing.tree.TreeNode;
import java.awt.*;
import java.io.*;
import java.util.List;
import java.util.*;
public class WriterModeDataSet implements ProjectTreeNode, Serializable {
@@ -86,19 +71,19 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this);
path.add(0, this);
parent.childrenRemoved(path);
}
@@ -109,7 +94,7 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+"Dialogue sketches";
return (needsSaving() ? "*" : "") + "Dialogue sketches";
}
@Override
@@ -163,9 +148,9 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
}
if (dataToSave.isEmpty() && writerFile.exists()) {
if (writerFile.delete()) {
Notification.addSuccess("File "+writerFile.getAbsolutePath()+" deleted.");
Notification.addSuccess("File " + writerFile.getAbsolutePath() + " deleted.");
} else {
Notification.addError("Error deleting file "+writerFile.getAbsolutePath());
Notification.addError("Error deleting file " + writerFile.getAbsolutePath());
}
return;
@@ -184,9 +169,9 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
for (WriterModeData element : writerModeDataList) {
element.state = GameDataElement.State.saved;
}
Notification.addSuccess("Json file "+writerFile.getAbsolutePath()+" saved.");
Notification.addSuccess("Json file " + writerFile.getAbsolutePath() + " saved.");
} catch (IOException e) {
Notification.addError("Error while writing json file "+writerFile.getAbsolutePath()+" : "+e.getMessage());
Notification.addError("Error while writing json file " + writerFile.getAbsolutePath() + " : " + e.getMessage());
e.printStackTrace();
}
}
@@ -210,19 +195,19 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
reader = new FileReader(writerFile);
List writerDataListJson = (List) parser.parse(reader);
for (Object obj : writerDataListJson) {
Map jsonObj = (Map)obj;
Map jsonObj = (Map) obj;
WriterModeData data = new WriterModeData(this, jsonObj);
data.writable = true;
writerModeDataList.add(data);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+writerFile.getAbsolutePath()+": "+e.getMessage());
Notification.addError("Error while parsing JSON file " + writerFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing JSON file "+writerFile.getAbsolutePath()+": "+e.getMessage());
Notification.addError("Error while parsing JSON file " + writerFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+writerFile.getAbsolutePath()+": "+e.getMessage());
Notification.addError("Error while parsing JSON file " + writerFile.getAbsolutePath() + ": " + e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
@@ -236,7 +221,7 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
public WriterModeData getWriterSketch(String id) {
for (WriterModeData sketch : writerModeDataList) {
if (id.equals(sketch.id)){
if (id.equals(sketch.id)) {
return sketch;
}
}
@@ -250,7 +235,8 @@ public class WriterModeDataSet implements ProjectTreeNode, Serializable {
public void add(WriterModeData node) {
ProjectTreeNode higherEmptyParent = this;
while (higherEmptyParent != null) {
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode)higherEmptyParent.getParent()).isEmpty()) higherEmptyParent = (ProjectTreeNode)higherEmptyParent.getParent();
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode) higherEmptyParent.getParent()).isEmpty())
higherEmptyParent = (ProjectTreeNode) higherEmptyParent.getParent();
else break;
}
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;

View File

@@ -1,26 +1,21 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Scanner;
import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.event.HyperlinkListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.jidesoft.swing.JideTabbedPane;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Scanner;
public class AboutEditor extends Editor {
private static final long serialVersionUID = 6230549148222457139L;
@@ -30,8 +25,8 @@ public class AboutEditor extends Editor {
"<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=UTF-8\\\" />" +
"</head><body>" +
"<table><tr valign=\"top\">" +
"<td><img src=\""+ATContentStudio.class.getResource("/com/gpl/rpg/atcontentstudio/img/atcs_border_banner.png")+"\"/></td>" +
"<td><font size=+1>Welcome to "+ATContentStudio.APP_NAME+" "+ATContentStudio.APP_VERSION+"</font><br/>" +
"<td><img src=\"" + ATContentStudio.class.getResource("/com/gpl/rpg/atcontentstudio/img/atcs_border_banner.png") + "\"/></td>" +
"<td><font size=+1>Welcome to " + ATContentStudio.APP_NAME + " " + ATContentStudio.APP_VERSION + "</font><br/>" +
"<br/>" +
"This is a content editor for Andor's Trail.<br/>" +
"<b>Right click on the left area or use the \"File\" menu to create a project.</b><br/>" +
@@ -55,6 +50,7 @@ public class AboutEditor extends Editor {
"Quentin Delvallet<br/>" +
"Žižkin<br/>" +
"Gonk<br/>" +
"<a href=\"https://github.com/OMGeeky\">OMGeeky</a><br/>" +
"<br/>" +
"This project uses the following libraries:<br/>" +
"<a href=\"http://code.google.com/p/json-simple/\">JSON.simple</a> by Yidong Fang & Chris Nokleberg.<br/>" +
@@ -97,30 +93,54 @@ public class AboutEditor extends Editor {
public static final AboutEditor instance = new AboutEditor();
@SuppressWarnings("resource")
private AboutEditor() {
this.name="About "+ATContentStudio.APP_NAME;
this.name = "About " + ATContentStudio.APP_NAME;
this.icon = new ImageIcon(DefaultIcons.getMainIconIcon());
this.target = new GameDataElement(){
this.target = new GameDataElement() {
private static final long serialVersionUID = -227480102288529682L;
@Override
public GameDataSet getDataSet() {return null;}
public GameDataSet getDataSet() {
return null;
}
@Override
public String getDesc() {return null;}
public String getDesc() {
return null;
}
@Override
public void parse() {}
public void parse() {
}
@Override
public void link() {}
public void link() {
}
@Override
public GameDataElement clone() {return null;}
public GameDataElement clone() {
return null;
}
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {}
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
}
@Override
public String getProjectFilename() {return null;}
public String getProjectFilename() {
return null;
}
@Override
public void save() {}
public void save() {
}
@Override
public List<SaveEvent> attemptSave() {return null;}
public List<SaveEvent> attemptSave() {
return null;
}
};
setLayout(new BorderLayout());
@@ -132,12 +152,14 @@ public class AboutEditor extends Editor {
editorTabsHolder.add("Welcome", getInfoPane(WELCOME_STRING, "text/html"));
editorTabsHolder.add("JSON.simple License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/LICENSE.JSON.simple.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("RSyntaxTextArea License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/RSyntaxTextArea.License.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("RSyntaxTextArea License",
getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/RSyntaxTextArea.License.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("JIDE Common Layer License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/LICENSE.JIDE.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("libtiled-java License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/LICENSE.libtiled.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("prefuse License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/license-prefuse.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("BeanShell License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/LICENSE.LGPLv3.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("SipHash for Java License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/LICENSE.siphash-zackehh.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("SipHash for Java License",
getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/LICENSE.siphash-zackehh.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("jsoup License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/LICENSE.jsoup.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("General PO Parser License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/LICENSE.GPLv3.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
editorTabsHolder.add("Minify.java License", getInfoPane(new Scanner(ATContentStudio.class.getResourceAsStream("/LICENSE.minify.txt"), "UTF-8").useDelimiter("\\A").next(), "text/text"));
@@ -175,6 +197,7 @@ public class AboutEditor extends Editor {
@Override
public void targetUpdated() {}
public void targetUpdated() {
}
}

View File

@@ -1,6 +1,6 @@
package com.gpl.rpg.atcontentstudio.ui;
import javax.swing.JCheckBox;
import javax.swing.*;
public class BooleanBasedCheckBox extends JCheckBox {

View File

@@ -1,17 +1,9 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.*;
public class CollapsiblePanel extends JPanel {
@@ -42,6 +34,7 @@ public class CollapsiblePanel extends JPanel {
public void componentShown(ComponentEvent e) {
updateBorderTitle();
}
@Override
public void componentHidden(ComponentEvent e) {
updateBorderTitle();
@@ -132,9 +125,9 @@ public class CollapsiblePanel extends JPanel {
protected void updateBorderTitle() {
String arrow = "";
if (getComponentCount() > 0) {
arrow = (hasInvisibleComponent()?"[+] ":"[-] ");
arrow = (hasInvisibleComponent() ? "[+] " : "[-] ");
}
border.setTitle(arrow+title);
border.setTitle(arrow + title);
repaint();
}
@@ -150,9 +143,11 @@ public class CollapsiblePanel extends JPanel {
public void collapse() {
toggleVisibility(false);
}
public void expand() {
toggleVisibility(true);
}
public void setExpanded(boolean expand) {
toggleVisibility(expand);
}

View File

@@ -1,15 +1,14 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.Image;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.Notification;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
public class DefaultIcons {
private static Map<String, Image> imageCache = new LinkedHashMap<String, Image>();
@@ -17,288 +16,714 @@ public class DefaultIcons {
private static String MAIN_ICON_RES = "/com/gpl/rpg/atcontentstudio/img/andorstrainer.png";
public static Image getMainIconImage() { return getImage(MAIN_ICON_RES); }
public static Image getMainIconIcon() { return getIcon(MAIN_ICON_RES); }
public static Image getMainIconImage() {
return getImage(MAIN_ICON_RES);
}
public static Image getMainIconIcon() {
return getIcon(MAIN_ICON_RES);
}
private static String FOLDER_STD_CLOSED_RES = "/com/gpl/rpg/atcontentstudio/img/folder_std_closed.png";
public static Image getStdClosedImage() { return getImage(FOLDER_STD_CLOSED_RES); }
public static Image getStdClosedIcon() { return getIcon(FOLDER_STD_CLOSED_RES); }
public static Image getStdClosedImage() {
return getImage(FOLDER_STD_CLOSED_RES);
}
public static Image getStdClosedIcon() {
return getIcon(FOLDER_STD_CLOSED_RES);
}
private static String FOLDER_STD_OPEN_RES = "/com/gpl/rpg/atcontentstudio/img/folder_std_open.png";
public static Image getStdOpenImage() { return getImage(FOLDER_STD_OPEN_RES); }
public static Image getStdOpenIcon() { return getIcon(FOLDER_STD_OPEN_RES); }
public static Image getStdOpenImage() {
return getImage(FOLDER_STD_OPEN_RES);
}
public static Image getStdOpenIcon() {
return getIcon(FOLDER_STD_OPEN_RES);
}
private static String FOLDER_JSON_CLOSED_RES = "/com/gpl/rpg/atcontentstudio/img/folder_json_closed.png";
public static Image getJsonClosedImage() { return getImage(FOLDER_JSON_CLOSED_RES); }
public static Image getJsonClosedIcon() { return getIcon(FOLDER_JSON_CLOSED_RES); }
public static Image getJsonClosedImage() {
return getImage(FOLDER_JSON_CLOSED_RES);
}
public static Image getJsonClosedIcon() {
return getIcon(FOLDER_JSON_CLOSED_RES);
}
private static String FOLDER_JSON_OPEN_RES = "/com/gpl/rpg/atcontentstudio/img/folder_json_open.png";
public static Image getJsonOpenImage() { return getImage(FOLDER_JSON_OPEN_RES); }
public static Image getJsonOpenIcon() { return getIcon(FOLDER_JSON_OPEN_RES); }
public static Image getJsonOpenImage() {
return getImage(FOLDER_JSON_OPEN_RES);
}
public static Image getJsonOpenIcon() {
return getIcon(FOLDER_JSON_OPEN_RES);
}
private static String FOLDER_SAV_CLOSED_RES = "/com/gpl/rpg/atcontentstudio/img/folder_sav_closed.png";
public static Image getSavClosedImage() { return getImage(FOLDER_SAV_CLOSED_RES); }
public static Image getSavClosedIcon() { return getIcon(FOLDER_SAV_CLOSED_RES); }
public static Image getSavClosedImage() {
return getImage(FOLDER_SAV_CLOSED_RES);
}
public static Image getSavClosedIcon() {
return getIcon(FOLDER_SAV_CLOSED_RES);
}
private static String FOLDER_SAV_OPEN_RES = "/com/gpl/rpg/atcontentstudio/img/folder_sav_open.png";
public static Image getSavOpenImage() { return getImage(FOLDER_SAV_OPEN_RES); }
public static Image getSavOpenIcon() { return getIcon(FOLDER_SAV_OPEN_RES); }
public static Image getSavOpenImage() {
return getImage(FOLDER_SAV_OPEN_RES);
}
public static Image getSavOpenIcon() {
return getIcon(FOLDER_SAV_OPEN_RES);
}
private static String FOLDER_SPRITE_CLOSED_RES = "/com/gpl/rpg/atcontentstudio/img/folder_sprite_closed.png";
public static Image getSpriteClosedImage() { return getImage(FOLDER_SPRITE_CLOSED_RES); }
public static Image getSpriteClosedIcon() { return getIcon(FOLDER_SPRITE_CLOSED_RES); }
public static Image getSpriteClosedImage() {
return getImage(FOLDER_SPRITE_CLOSED_RES);
}
public static Image getSpriteClosedIcon() {
return getIcon(FOLDER_SPRITE_CLOSED_RES);
}
private static String FOLDER_SPRITE_OPEN_RES = "/com/gpl/rpg/atcontentstudio/img/folder_sprite_open.png";
public static Image getSpriteOpenImage() { return getImage(FOLDER_SPRITE_OPEN_RES); }
public static Image getSpriteOpenIcon() { return getIcon(FOLDER_SPRITE_OPEN_RES); }
public static Image getSpriteOpenImage() {
return getImage(FOLDER_SPRITE_OPEN_RES);
}
public static Image getSpriteOpenIcon() {
return getIcon(FOLDER_SPRITE_OPEN_RES);
}
private static String FOLDER_TMX_CLOSED_RES = "/com/gpl/rpg/atcontentstudio/img/folder_tmx_closed.png";
public static Image getTmxClosedImage() { return getImage(FOLDER_TMX_CLOSED_RES); }
public static Image getTmxClosedIcon() { return getIcon(FOLDER_TMX_CLOSED_RES); }
public static Image getTmxClosedImage() {
return getImage(FOLDER_TMX_CLOSED_RES);
}
public static Image getTmxClosedIcon() {
return getIcon(FOLDER_TMX_CLOSED_RES);
}
private static String FOLDER_TMX_OPEN_RES = "/com/gpl/rpg/atcontentstudio/img/folder_tmx_open.png";
public static Image getTmxOpenImage() { return getImage(FOLDER_TMX_OPEN_RES); }
public static Image getTmxOpenIcon() { return getIcon(FOLDER_TMX_OPEN_RES); }
public static Image getTmxOpenImage() {
return getImage(FOLDER_TMX_OPEN_RES);
}
public static Image getTmxOpenIcon() {
return getIcon(FOLDER_TMX_OPEN_RES);
}
private static String FOLDER_MAP_CLOSED_RES = "/com/gpl/rpg/atcontentstudio/img/folder_map_closed.png";
public static Image getMapClosedImage() { return getImage(FOLDER_MAP_CLOSED_RES); }
public static Image getMapClosedIcon() { return getIcon(FOLDER_MAP_CLOSED_RES); }
public static Image getMapClosedImage() {
return getImage(FOLDER_MAP_CLOSED_RES);
}
public static Image getMapClosedIcon() {
return getIcon(FOLDER_MAP_CLOSED_RES);
}
private static String FOLDER_MAP_OPEN_RES = "/com/gpl/rpg/atcontentstudio/img/folder_map_open.png";
public static Image getMapOpenImage() { return getImage(FOLDER_MAP_OPEN_RES); }
public static Image getMapOpenIcon() { return getIcon(FOLDER_MAP_OPEN_RES); }
public static Image getMapOpenImage() {
return getImage(FOLDER_MAP_OPEN_RES);
}
public static Image getMapOpenIcon() {
return getIcon(FOLDER_MAP_OPEN_RES);
}
private static String FOLDER_AT_CLOSED_RES = "/com/gpl/rpg/atcontentstudio/img/folder_at_closed.png";
public static Image getATClosedImage() { return getImage(FOLDER_AT_CLOSED_RES); }
public static Image getATClosedIcon() { return getIcon(FOLDER_AT_CLOSED_RES); }
public static Image getATClosedImage() {
return getImage(FOLDER_AT_CLOSED_RES);
}
public static Image getATClosedIcon() {
return getIcon(FOLDER_AT_CLOSED_RES);
}
private static String FOLDER_AT_OPEN_RES = "/com/gpl/rpg/atcontentstudio/img/folder_at_open.png";
public static Image getATOpenImage() { return getImage(FOLDER_AT_OPEN_RES); }
public static Image getATOpenIcon() { return getIcon(FOLDER_AT_OPEN_RES); }
public static Image getATOpenImage() {
return getImage(FOLDER_AT_OPEN_RES);
}
public static Image getATOpenIcon() {
return getIcon(FOLDER_AT_OPEN_RES);
}
private static String FOLDER_BOOKMARK_CLOSED_RES = "/com/gpl/rpg/atcontentstudio/img/folder_bookmark_closed.png";
public static Image getBookmarkClosedImage() { return getImage(FOLDER_BOOKMARK_CLOSED_RES); }
public static Image getBookmarkClosedIcon() { return getIcon(FOLDER_BOOKMARK_CLOSED_RES); }
public static Image getBookmarkClosedImage() {
return getImage(FOLDER_BOOKMARK_CLOSED_RES);
}
public static Image getBookmarkClosedIcon() {
return getIcon(FOLDER_BOOKMARK_CLOSED_RES);
}
private static String FOLDER_BOOKMARK_OPEN_RES = "/com/gpl/rpg/atcontentstudio/img/folder_bookmark_open.png";
public static Image getBookmarkOpenImage() { return getImage(FOLDER_BOOKMARK_OPEN_RES); }
public static Image getBookmarkOpenIcon() { return getIcon(FOLDER_BOOKMARK_OPEN_RES); }
public static Image getBookmarkOpenImage() {
return getImage(FOLDER_BOOKMARK_OPEN_RES);
}
public static Image getBookmarkOpenIcon() {
return getIcon(FOLDER_BOOKMARK_OPEN_RES);
}
private static String TILED_ICON_RES = "/com/gpl/rpg/atcontentstudio/img/tiled-icon.png";
public static Image getTiledIconImage() { return getImage(TILED_ICON_RES); }
public static Image getTiledIconIcon() { return getIcon(TILED_ICON_RES); }
public static Image getTiledIconImage() {
return getImage(TILED_ICON_RES);
}
public static Image getTiledIconIcon() {
return getIcon(TILED_ICON_RES);
}
private static String UI_MAP_RES = "/com/gpl/rpg/atcontentstudio/img/ui_icon_map.png";
public static Image getUIMapImage() { return getImage(UI_MAP_RES); }
public static Image getUIMapIcon() { return getIcon(UI_MAP_RES); }
public static Image getUIMapImage() {
return getImage(UI_MAP_RES);
}
public static Image getUIMapIcon() {
return getIcon(UI_MAP_RES);
}
private static String HERO_RES = "/com/gpl/rpg/atcontentstudio/img/char_hero.png";
public static Image getHeroImage() { return getImage(HERO_RES); }
public static Image getHeroIcon() { return getIcon(HERO_RES); }
public static Image getHeroImage() {
return getImage(HERO_RES);
}
public static Image getHeroIcon() {
return getIcon(HERO_RES);
}
private static String TILE_LAYER_RES = "/com/gpl/rpg/atcontentstudio/img/tile_layer.png";
public static Image getTileLayerImage() { return getImage(TILE_LAYER_RES); }
public static Image getTileLayerIcon() { return getIcon(TILE_LAYER_RES); }
public static Image getTileLayerImage() {
return getImage(TILE_LAYER_RES);
}
public static Image getTileLayerIcon() {
return getIcon(TILE_LAYER_RES);
}
private static String OBJECT_LAYER_RES = "/com/gpl/rpg/atcontentstudio/img/object_layer.png";
public static Image getObjectLayerImage() { return getImage(OBJECT_LAYER_RES); }
public static Image getObjectLayerIcon() { return getIcon(OBJECT_LAYER_RES); }
public static Image getObjectLayerImage() {
return getImage(OBJECT_LAYER_RES);
}
public static Image getObjectLayerIcon() {
return getIcon(OBJECT_LAYER_RES);
}
private static String ACTOR_CONDITION_RES = "/com/gpl/rpg/atcontentstudio/img/actor_condition.png";
public static Image getActorConditionImage() { return getImage(ACTOR_CONDITION_RES); }
public static Image getActorConditionIcon() { return getIcon(ACTOR_CONDITION_RES); }
public static Image getActorConditionImage() {
return getImage(ACTOR_CONDITION_RES);
}
public static Image getActorConditionIcon() {
return getIcon(ACTOR_CONDITION_RES);
}
private static String ITEM_RES = "/com/gpl/rpg/atcontentstudio/img/item.png";
public static Image getItemImage() { return getImage(ITEM_RES); }
public static Image getItemIcon() { return getIcon(ITEM_RES); }
public static Image getItemImage() {
return getImage(ITEM_RES);
}
public static Image getItemIcon() {
return getIcon(ITEM_RES);
}
private static String NPC_RES = "/com/gpl/rpg/atcontentstudio/img/npc.png";
public static Image getNPCImage() { return getImage(NPC_RES); }
public static Image getNPCIcon() { return getIcon(NPC_RES); }
public static Image getNPCImage() {
return getImage(NPC_RES);
}
public static Image getNPCIcon() {
return getIcon(NPC_RES);
}
private static String BONEMEAL_RES = "/com/gpl/rpg/atcontentstudio/img/bonemeal.png";
public static Image getBonemealImage() { return getImage(BONEMEAL_RES); }
public static Image getBonemealIcon() { return getIcon(BONEMEAL_RES); }
public static Image getBonemealImage() {
return getImage(BONEMEAL_RES);
}
public static Image getBonemealIcon() {
return getIcon(BONEMEAL_RES);
}
private static String NPC_CLOSE_RES = "/com/gpl/rpg/atcontentstudio/img/npc_close.png";
public static Image getNPCCloseImage() { return getImage(NPC_CLOSE_RES); }
public static Image getNPCCloseIcon() { return getIcon(NPC_CLOSE_RES); }
public static Image getNPCCloseImage() {
return getImage(NPC_CLOSE_RES);
}
public static Image getNPCCloseIcon() {
return getIcon(NPC_CLOSE_RES);
}
private static String DIALOGUE_RES = "/com/gpl/rpg/atcontentstudio/img/dialogue.png";
public static Image getDialogueImage() { return getImage(DIALOGUE_RES); }
public static Image getDialogueIcon() { return getIcon(DIALOGUE_RES); }
public static Image getDialogueImage() {
return getImage(DIALOGUE_RES);
}
public static Image getDialogueIcon() {
return getIcon(DIALOGUE_RES);
}
private static String QUEST_RES = "/com/gpl/rpg/atcontentstudio/img/ui_icon_quest.png";
public static Image getQuestImage() { return getImage(QUEST_RES); }
public static Image getQuestIcon() { return getIcon(QUEST_RES); }
public static Image getQuestImage() {
return getImage(QUEST_RES);
}
public static Image getQuestIcon() {
return getIcon(QUEST_RES);
}
private static String DROPLIST_RES = "/com/gpl/rpg/atcontentstudio/img/ui_icon_equipment.png";
public static Image getDroplistImage() { return getImage(DROPLIST_RES); }
public static Image getDroplistIcon() { return getIcon(DROPLIST_RES); }
public static Image getDroplistImage() {
return getImage(DROPLIST_RES);
}
public static Image getDroplistIcon() {
return getIcon(DROPLIST_RES);
}
private static String COMBAT_RES = "/com/gpl/rpg/atcontentstudio/img/ui_icon_combat.png";
public static Image getCombatImage() { return getImage(COMBAT_RES); }
public static Image getCombatIcon() { return getIcon(COMBAT_RES); }
public static Image getCombatImage() {
return getImage(COMBAT_RES);
}
public static Image getCombatIcon() {
return getIcon(COMBAT_RES);
}
private static String GOLD_RES = "/com/gpl/rpg/atcontentstudio/img/ui_icon_coins.png";
public static Image getGoldImage() { return getImage(GOLD_RES); }
public static Image getGoldIcon() { return getIcon(GOLD_RES); }
public static Image getGoldImage() {
return getImage(GOLD_RES);
}
public static Image getGoldIcon() {
return getIcon(GOLD_RES);
}
private static String SKILL_RES = "/com/gpl/rpg/atcontentstudio/img/ui_icon_skill.png";
public static Image getSkillImage() { return getImage(SKILL_RES); }
public static Image getSkillIcon() { return getIcon(SKILL_RES); }
public static Image getSkillImage() {
return getImage(SKILL_RES);
}
public static Image getSkillIcon() {
return getIcon(SKILL_RES);
}
private static String IMMUNITY_RES = "/com/gpl/rpg/atcontentstudio/img/ui_icon_immunity.png";
public static Image getImmunityImage() { return getImage(IMMUNITY_RES); }
public static Image getImmunityIcon() { return getIcon(IMMUNITY_RES); }
public static Image getImmunityImage() {
return getImage(IMMUNITY_RES);
}
public static Image getImmunityIcon() {
return getIcon(IMMUNITY_RES);
}
private static String ITEM_CATEGORY_RES = "/com/gpl/rpg/atcontentstudio/img/equip_weapon.png";
public static Image getItemCategoryImage() { return getImage(ITEM_CATEGORY_RES); }
public static Image getItemCategoryIcon() { return getIcon(ITEM_CATEGORY_RES); }
public static Image getItemCategoryImage() {
return getImage(ITEM_CATEGORY_RES);
}
public static Image getItemCategoryIcon() {
return getIcon(ITEM_CATEGORY_RES);
}
private static String NULLIFY_RES = "/com/gpl/rpg/atcontentstudio/img/nullify.png";
public static Image getNullifyImage() { return getImage(NULLIFY_RES); }
public static Image getNullifyIcon() { return getIcon(NULLIFY_RES); }
public static Image getNullifyImage() {
return getImage(NULLIFY_RES);
}
public static Image getNullifyIcon() {
return getIcon(NULLIFY_RES);
}
private static String CREATE_RES = "/com/gpl/rpg/atcontentstudio/img/file_create.png";
public static Image getCreateImage() { return getImage(CREATE_RES); }
public static Image getCreateIcon() { return getIcon(CREATE_RES); }
public static Image getCreateImage() {
return getImage(CREATE_RES);
}
public static Image getCreateIcon() {
return getIcon(CREATE_RES);
}
private static String ARROW_UP_RES = "/com/gpl/rpg/atcontentstudio/img/arrow_up.png";
public static Image getArrowUpImage() { return getImage(ARROW_UP_RES); }
public static Image getArrowUpIcon() { return getIcon(ARROW_UP_RES); }
public static Image getArrowUpImage() {
return getImage(ARROW_UP_RES);
}
public static Image getArrowUpIcon() {
return getIcon(ARROW_UP_RES);
}
private static String ARROW_DOWN_RES = "/com/gpl/rpg/atcontentstudio/img/arrow_down.png";
public static Image getArrowDownImage() { return getImage(ARROW_DOWN_RES); }
public static Image getArrowDownIcon() { return getIcon(ARROW_DOWN_RES); }
public static Image getArrowDownImage() {
return getImage(ARROW_DOWN_RES);
}
public static Image getArrowDownIcon() {
return getIcon(ARROW_DOWN_RES);
}
private static String ARROW_LEFT_RES = "/com/gpl/rpg/atcontentstudio/img/arrow_left.png";
public static Image getArrowLeftImage() { return getImage(ARROW_LEFT_RES); }
public static Image getArrowLeftIcon() { return getIcon(ARROW_LEFT_RES); }
public static Image getArrowLeftImage() {
return getImage(ARROW_LEFT_RES);
}
public static Image getArrowLeftIcon() {
return getIcon(ARROW_LEFT_RES);
}
private static String ARROW_RIGHT_RES = "/com/gpl/rpg/atcontentstudio/img/arrow_right.png";
public static Image getArrowRightImage() { return getImage(ARROW_RIGHT_RES); }
public static Image getArrowRightIcon() { return getIcon(ARROW_RIGHT_RES); }
public static Image getArrowRightImage() {
return getImage(ARROW_RIGHT_RES);
}
public static Image getArrowRightIcon() {
return getIcon(ARROW_RIGHT_RES);
}
private static String CONTAINER_RES = "/com/gpl/rpg/atcontentstudio/img/container.png";
public static Image getContainerImage() { return getImage(CONTAINER_RES); }
public static Image getContainerIcon() { return getIcon(CONTAINER_RES); }
public static Image getContainerImage() {
return getImage(CONTAINER_RES);
}
public static Image getContainerIcon() {
return getIcon(CONTAINER_RES);
}
private static String KEY_RES = "/com/gpl/rpg/atcontentstudio/img/key.png";
public static Image getKeyImage() { return getImage(KEY_RES); }
public static Image getKeyIcon() { return getIcon(KEY_RES); }
public static Image getKeyImage() {
return getImage(KEY_RES);
}
public static Image getKeyIcon() {
return getIcon(KEY_RES);
}
private static String MAPCHANGE_RES = "/com/gpl/rpg/atcontentstudio/img/mapchange.png";
public static Image getMapchangeImage() { return getImage(MAPCHANGE_RES); }
public static Image getMapchangeIcon() { return getIcon(MAPCHANGE_RES); }
public static Image getMapchangeImage() {
return getImage(MAPCHANGE_RES);
}
public static Image getMapchangeIcon() {
return getIcon(MAPCHANGE_RES);
}
private static String REPLACE_RES = "/com/gpl/rpg/atcontentstudio/img/replace.png";
public static Image getReplaceImage() { return getImage(REPLACE_RES); }
public static Image getReplaceIcon() { return getIcon(REPLACE_RES); }
public static Image getReplaceImage() {
return getImage(REPLACE_RES);
}
public static Image getReplaceIcon() {
return getIcon(REPLACE_RES);
}
private static String REST_RES = "/com/gpl/rpg/atcontentstudio/img/rest.png";
public static Image getRestImage() { return getImage(REST_RES); }
public static Image getRestIcon() { return getIcon(REST_RES); }
public static Image getRestImage() {
return getImage(REST_RES);
}
public static Image getRestIcon() {
return getIcon(REST_RES);
}
private static String SCRIPT_RES = "/com/gpl/rpg/atcontentstudio/img/script.png";
public static Image getScriptImage() { return getImage(SCRIPT_RES); }
public static Image getScriptIcon() { return getIcon(SCRIPT_RES); }
public static Image getScriptImage() {
return getImage(SCRIPT_RES);
}
public static Image getScriptIcon() {
return getIcon(SCRIPT_RES);
}
private static String SIGN_RES = "/com/gpl/rpg/atcontentstudio/img/sign.png";
public static Image getSignImage() { return getImage(SIGN_RES); }
public static Image getSignIcon() { return getIcon(SIGN_RES); }
public static Image getSignImage() {
return getImage(SIGN_RES);
}
public static Image getSignIcon() {
return getIcon(SIGN_RES);
}
private static String CREATE_CONTAINER_RES = "/com/gpl/rpg/atcontentstudio/img/create_container.png";
public static Image getCreateContainerImage() { return getImage(CREATE_CONTAINER_RES); }
public static Image getCreateContainerIcon() { return getIcon(CREATE_CONTAINER_RES); }
public static Image getCreateContainerImage() {
return getImage(CREATE_CONTAINER_RES);
}
public static Image getCreateContainerIcon() {
return getIcon(CREATE_CONTAINER_RES);
}
private static String CREATE_KEY_RES = "/com/gpl/rpg/atcontentstudio/img/create_key.png";
public static Image getCreateKeyImage() { return getImage(CREATE_KEY_RES); }
public static Image getCreateKeyIcon() { return getIcon(CREATE_KEY_RES); }
public static Image getCreateKeyImage() {
return getImage(CREATE_KEY_RES);
}
public static Image getCreateKeyIcon() {
return getIcon(CREATE_KEY_RES);
}
private static String CREATE_REPLACE_RES = "/com/gpl/rpg/atcontentstudio/img/create_replace.png";
public static Image getCreateReplaceImage() { return getImage(CREATE_REPLACE_RES); }
public static Image getCreateReplaceIcon() { return getIcon(CREATE_REPLACE_RES); }
public static Image getCreateReplaceImage() {
return getImage(CREATE_REPLACE_RES);
}
public static Image getCreateReplaceIcon() {
return getIcon(CREATE_REPLACE_RES);
}
private static String CREATE_REST_RES = "/com/gpl/rpg/atcontentstudio/img/create_rest.png";
public static Image getCreateRestImage() { return getImage(CREATE_REST_RES); }
public static Image getCreateRestIcon() { return getIcon(CREATE_REST_RES); }
public static Image getCreateRestImage() {
return getImage(CREATE_REST_RES);
}
public static Image getCreateRestIcon() {
return getIcon(CREATE_REST_RES);
}
private static String CREATE_SCRIPT_RES = "/com/gpl/rpg/atcontentstudio/img/create_script.png";
public static Image getCreateScriptImage() { return getImage(CREATE_SCRIPT_RES); }
public static Image getCreateScriptIcon() { return getIcon(CREATE_SCRIPT_RES); }
public static Image getCreateScriptImage() {
return getImage(CREATE_SCRIPT_RES);
}
public static Image getCreateScriptIcon() {
return getIcon(CREATE_SCRIPT_RES);
}
private static String CREATE_SIGN_RES = "/com/gpl/rpg/atcontentstudio/img/create_sign.png";
public static Image getCreateSignImage() { return getImage(CREATE_SIGN_RES); }
public static Image getCreateSignIcon() { return getIcon(CREATE_SIGN_RES); }
public static Image getCreateSignImage() {
return getImage(CREATE_SIGN_RES);
}
public static Image getCreateSignIcon() {
return getIcon(CREATE_SIGN_RES);
}
private static String CREATE_SPAWNAREA_RES = "/com/gpl/rpg/atcontentstudio/img/create_spawnarea.png";
public static Image getCreateSpawnareaImage() { return getImage(CREATE_SPAWNAREA_RES); }
public static Image getCreateSpawnareaIcon() { return getIcon(CREATE_SPAWNAREA_RES); }
public static Image getCreateSpawnareaImage() {
return getImage(CREATE_SPAWNAREA_RES);
}
public static Image getCreateSpawnareaIcon() {
return getIcon(CREATE_SPAWNAREA_RES);
}
private static String CREATE_MAPCHANGE_RES = "/com/gpl/rpg/atcontentstudio/img/create_tiled.png";
public static Image getCreateMapchangeImage() { return getImage(CREATE_MAPCHANGE_RES); }
public static Image getCreateMapchangeIcon() { return getIcon(CREATE_MAPCHANGE_RES); }
public static Image getCreateMapchangeImage() {
return getImage(CREATE_MAPCHANGE_RES);
}
public static Image getCreateMapchangeIcon() {
return getIcon(CREATE_MAPCHANGE_RES);
}
private static String CREATE_OBJECT_GROUP_RES = "/com/gpl/rpg/atcontentstudio/img/create_object_group.png";
public static Image getCreateObjectGroupImage() { return getImage(CREATE_OBJECT_GROUP_RES); }
public static Image getCreateObjectGroupIcon() { return getIcon(CREATE_OBJECT_GROUP_RES); }
public static Image getCreateObjectGroupImage() {
return getImage(CREATE_OBJECT_GROUP_RES);
}
public static Image getCreateObjectGroupIcon() {
return getIcon(CREATE_OBJECT_GROUP_RES);
}
private static String CREATE_TILE_LAYER_RES = "/com/gpl/rpg/atcontentstudio/img/create_tile_layer.png";
public static Image getCreateTileLayerImage() { return getImage(CREATE_TILE_LAYER_RES); }
public static Image getCreateTileLayerIcon() { return getIcon(CREATE_TILE_LAYER_RES); }
public static Image getCreateTileLayerImage() {
return getImage(CREATE_TILE_LAYER_RES);
}
public static Image getCreateTileLayerIcon() {
return getIcon(CREATE_TILE_LAYER_RES);
}
private static String LABEL_RES = "/com/gpl/rpg/atcontentstudio/img/label.png";
public static Image getLabelImage() { return getImage(LABEL_RES); }
public static Image getLabelIcon() { return getIcon(LABEL_RES); }
public static Image getLabelImage() {
return getImage(LABEL_RES);
}
public static Image getLabelIcon() {
return getIcon(LABEL_RES);
}
private static String ZOOM_RES = "/com/gpl/rpg/atcontentstudio/img/zoom.png";
public static Image getZoomImage() { return getImage(ZOOM_RES); }
public static Image getZoomIcon() { return getIcon(ZOOM_RES); }
public static Image getZoomImage() {
return getImage(ZOOM_RES);
}
public static Image getZoomIcon() {
return getIcon(ZOOM_RES);
}
private static String TIMER_RES = "/com/gpl/rpg/atcontentstudio/img/timer.png";
public static Image getTimerImage() { return getImage(TIMER_RES); }
public static Image getTimerIcon() { return getIcon(TIMER_RES); }
public static Image getTimerImage() {
return getImage(TIMER_RES);
}
public static Image getTimerIcon() {
return getIcon(TIMER_RES);
}
private static String DATE_RES = "/com/gpl/rpg/atcontentstudio/img/date.png";
public static Image getDateImage() { return getImage(DATE_RES); }
public static Image getDateIcon() { return getIcon(DATE_RES); }
public static Image getDateImage() {
return getImage(DATE_RES);
}
public static Image getDateIcon() {
return getIcon(DATE_RES);
}
private static String TIME_RES = "/com/gpl/rpg/atcontentstudio/img/date.png";
public static Image getTimeImage() { return getImage(TIME_RES); }
public static Image getTimeIcon() { return getIcon(TIME_RES); }
public static Image getTimeImage() {
return getImage(TIME_RES);
}
public static Image getTimeIcon() {
return getIcon(TIME_RES);
}
private static String ALIGNMENT_RES = "/com/gpl/rpg/atcontentstudio/img/alignment.png";
public static Image getAlignmentImage() { return getImage(ALIGNMENT_RES); }
public static Image getAlignmentIcon() { return getIcon(ALIGNMENT_RES); }
public static Image getAlignmentImage() {
return getImage(ALIGNMENT_RES);
}
public static Image getAlignmentIcon() {
return getIcon(ALIGNMENT_RES);
}
private static String STATUS_RED_RES = "/com/gpl/rpg/atcontentstudio/img/status_red.png";
public static Image getStatusRedImage() { return getImage(STATUS_RED_RES); }
public static Image getStatusRedIcon() { return getIcon(STATUS_RED_RES); }
public static Image getStatusRedImage() {
return getImage(STATUS_RED_RES);
}
public static Image getStatusRedIcon() {
return getIcon(STATUS_RED_RES);
}
private static String STATUS_ORANGE_RES = "/com/gpl/rpg/atcontentstudio/img/status_orange.png";
public static Image getStatusOrangeImage() { return getImage(STATUS_ORANGE_RES); }
public static Image getStatusOrangeIcon() { return getIcon(STATUS_ORANGE_RES); }
public static Image getStatusOrangeImage() {
return getImage(STATUS_ORANGE_RES);
}
public static Image getStatusOrangeIcon() {
return getIcon(STATUS_ORANGE_RES);
}
private static String STATUS_GREEN_RES = "/com/gpl/rpg/atcontentstudio/img/status_green.png";
public static Image getStatusGreenImage() { return getImage(STATUS_GREEN_RES); }
public static Image getStatusGreenIcon() { return getIcon(STATUS_GREEN_RES); }
public static Image getStatusGreenImage() {
return getImage(STATUS_GREEN_RES);
}
public static Image getStatusGreenIcon() {
return getIcon(STATUS_GREEN_RES);
}
private static String STATUS_BLUE_RES = "/com/gpl/rpg/atcontentstudio/img/status_blue.png";
public static Image getStatusBlueImage() { return getImage(STATUS_BLUE_RES); }
public static Image getStatusBlueIcon() { return getIcon(STATUS_BLUE_RES); }
public static Image getStatusBlueImage() {
return getImage(STATUS_BLUE_RES);
}
public static Image getStatusBlueIcon() {
return getIcon(STATUS_BLUE_RES);
}
private static String STATUS_UNKNOWN_RES = "/com/gpl/rpg/atcontentstudio/img/status_unknown.png";
public static Image getStatusUnknownImage() { return getImage(STATUS_UNKNOWN_RES); }
public static Image getStatusUnknownIcon() { return getIcon(STATUS_UNKNOWN_RES); }
public static Image getStatusUnknownImage() {
return getImage(STATUS_UNKNOWN_RES);
}
public static Image getStatusUnknownIcon() {
return getIcon(STATUS_UNKNOWN_RES);
}
private static String BOOKMARK_INACTIVE = "/com/gpl/rpg/atcontentstudio/img/bookmark_inactive.png";
public static Image getBookmarkInactiveImage() { return getImage(BOOKMARK_INACTIVE); }
public static Image getBookmarkInactiveIcon() { return getIcon(BOOKMARK_INACTIVE); }
public static Image getBookmarkInactiveImage() {
return getImage(BOOKMARK_INACTIVE);
}
public static Image getBookmarkInactiveIcon() {
return getIcon(BOOKMARK_INACTIVE);
}
private static String BOOKMARK_ACTIVE = "/com/gpl/rpg/atcontentstudio/img/bookmark_active.png";
public static Image getBookmarkActiveImage() { return getImage(BOOKMARK_ACTIVE); }
public static Image getBookmarkActiveIcon() { return getIcon(BOOKMARK_ACTIVE); }
public static Image getBookmarkActiveImage() {
return getImage(BOOKMARK_ACTIVE);
}
public static Image getBookmarkActiveIcon() {
return getIcon(BOOKMARK_ACTIVE);
}
private static Image getImage(String res) {
@@ -307,7 +732,7 @@ public class DefaultIcons {
Image img = ImageIO.read(DefaultIcons.class.getResourceAsStream(res));
imageCache.put(res, img);
} catch (IOException e) {
Notification.addError("Failed to load image "+res);
Notification.addError("Failed to load image " + res);
e.printStackTrace();
}
}
@@ -316,7 +741,7 @@ public class DefaultIcons {
private static Image getIcon(String res) {
if (iconCache.get(res) == null) {
Image icon = getImage(res).getScaledInstance((int)(16*ATContentStudio.SCALING), (int)(16*ATContentStudio.SCALING), Image.SCALE_SMOOTH);
Image icon = getImage(res).getScaledInstance((int) (16 * ATContentStudio.SCALING), (int) (16 * ATContentStudio.SCALING), Image.SCALE_SMOOTH);
iconCache.put(res, icon);
}
return iconCache.get(res);

View File

@@ -1,78 +1,40 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.regex.Matcher;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JSpinner.NumberEditor;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.text.DefaultFormatter;
import javax.swing.text.JTextComponent;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
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.ProjectElementListener;
import com.gpl.rpg.atcontentstudio.model.Workspace;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
import com.gpl.rpg.atcontentstudio.model.gamedata.*;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.utils.WeblateIntegration;
import com.jidesoft.swing.ComboBoxSearchable;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import javax.swing.JSpinner.NumberEditor;
import javax.swing.event.*;
import javax.swing.text.DefaultFormatter;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.regex.Matcher;
public abstract class Editor extends JPanel implements ProjectElementListener {
private static final long serialVersionUID = 241750514033596878L;
private static final FieldUpdateListener nullListener = new FieldUpdateListener() {@Override public void valueChanged(JComponent source, Object value) {}};
private static final FieldUpdateListener nullListener = new FieldUpdateListener() {
@Override
public void valueChanged(JComponent source, Object value) {
}
};
public static final String SAVE = "Save";
public static final String DELETE = "Delete";
@@ -117,7 +79,8 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
return addTextField(pane, label, value, false, nullListener);
}
public static void addTranslationPane(JPanel pane, final JTextComponent tfComponent, final String initialValue) {if (Workspace.activeWorkspace.settings.translatorLanguage.getCurrentValue() != null) {
public static void addTranslationPane(JPanel pane, final JTextComponent tfComponent, final String initialValue) {
if (Workspace.activeWorkspace.settings.translatorLanguage.getCurrentValue() != null) {
JPanel labelPane = new JPanel();
labelPane.setLayout(new JideBoxLayout(labelPane, JideBoxLayout.LINE_AXIS, 6));
final JLabel translateLinkLabel = new JLabel(getWeblateLabelLink(initialValue));
@@ -161,7 +124,8 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
break;
}
translationStatus.setText(unit.translatedText);
};
}
}.start();
pane.add(labelPane, JideBoxLayout.FIX);
tfComponent.getDocument().addDocumentListener(new DocumentListener() {
@@ -171,12 +135,14 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
translateLinkLabel.revalidate();
translateLinkLabel.repaint();
}
@Override
public void insertUpdate(DocumentEvent e) {
translateLinkLabel.setText(getWeblateLabelLink(tfComponent.getText().replaceAll("\n", Matcher.quoteReplacement("\n"))));
translateLinkLabel.revalidate();
translateLinkLabel.repaint();
}
@Override
public void changedUpdate(DocumentEvent e) {
translateLinkLabel.setText(getWeblateLabelLink(tfComponent.getText().replaceAll("\n", Matcher.quoteReplacement("\n"))));
@@ -209,17 +175,34 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
}
public static String getWeblateLabelLink(String text) {
return "<html><a href=\""+WeblateIntegration.getWeblateLabelURI(text)+"\">Translate on weblate</a></html>";
return "<html><a href=\"" + WeblateIntegration.getWeblateLabelURI(text) + "\">Translate on weblate</a></html>";
}
public static JTextField addTextField(JPanel pane, String label, String initialValue, boolean editable, final FieldUpdateListener listener) {
final JTextField tfField = new JTextField(initialValue);
addTextComponent(pane, label, editable, listener, tfField, false, false);
tfField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(tfField, tfField.getText());
}
});
return tfField;
}
public static <T extends JTextComponent> T addTextComponent(JPanel pane, String label, boolean editable, final FieldUpdateListener listener, T tfField, boolean specialNewLinesHandling, boolean scrollable) {
JPanel tfPane = new JPanel();
tfPane.setLayout(new JideBoxLayout(tfPane, JideBoxLayout.LINE_AXIS, 6));
JLabel tfLabel = new JLabel(label);
tfPane.add(tfLabel, JideBoxLayout.FIX);
final JTextField tfField = new JTextField(initialValue);
tfField.setEditable(editable);
tfPane.add(tfField, JideBoxLayout.VARY);
JComponent component;
if (scrollable) {
component = new JScrollPane(tfField);
} else {
component = tfField;
}
tfPane.add(component, JideBoxLayout.VARY);
JButton nullify = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
tfPane.add(nullify, JideBoxLayout.FIX);
nullify.setEnabled(editable);
@@ -235,21 +218,23 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
tfField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
listener.valueChanged(tfField, tfField.getText());
String text = tfField.getText();
if (specialNewLinesHandling) text = text.replaceAll("\n", Matcher.quoteReplacement("\n"));
listener.valueChanged(tfField, text);
}
@Override
public void insertUpdate(DocumentEvent e) {
listener.valueChanged(tfField, tfField.getText());
String text = tfField.getText();
if (specialNewLinesHandling) text = text.replaceAll("\n", Matcher.quoteReplacement("\n"));
listener.valueChanged(tfField, text);
}
@Override
public void changedUpdate(DocumentEvent e) {
listener.valueChanged(tfField, tfField.getText());
}
});
tfField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(tfField, tfField.getText());
String text = tfField.getText();
if (specialNewLinesHandling) text = text.replaceAll("\n", Matcher.quoteReplacement("\n"));
listener.valueChanged(tfField, text);
}
});
return tfField;
@@ -263,50 +248,13 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
}
public static JTextArea addTextArea(JPanel pane, String label, String initialValue, boolean editable, final FieldUpdateListener listener) {
String text= initialValue == null ? "" : initialValue.replaceAll("\\n", "\n");
JPanel tfPane = new JPanel();
tfPane.setLayout(new JideBoxLayout(tfPane, JideBoxLayout.LINE_AXIS, 6));
JLabel tfLabel = new JLabel(label);
tfPane.add(tfLabel, JideBoxLayout.FIX);
String text = initialValue == null ? "" : initialValue.replaceAll("\\n", "\n");
final JTextArea tfArea = new JTextArea(text);
tfArea.setEditable(editable);
tfArea.setRows(2);
tfArea.setLineWrap(true);
tfArea.setWrapStyleWord(true);
tfPane.add(new JScrollPane(tfArea), JideBoxLayout.VARY);
JButton nullify = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
tfPane.add(nullify, JideBoxLayout.FIX);
nullify.setEnabled(editable);
pane.add(tfPane, JideBoxLayout.FIX);
nullify.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tfArea.setText("");
listener.valueChanged(tfArea, null);
}
});
tfArea.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
listener.valueChanged(tfArea, tfArea.getText().replaceAll("\n", Matcher.quoteReplacement("\n")));
}
@Override
public void insertUpdate(DocumentEvent e) {
listener.valueChanged(tfArea, tfArea.getText().replaceAll("\n", Matcher.quoteReplacement("\n")));
}
@Override
public void changedUpdate(DocumentEvent e) {
listener.valueChanged(tfArea, tfArea.getText().replaceAll("\n", Matcher.quoteReplacement("\n")));
}
});
// tfArea.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// listener.valueChanged(tfArea, tfArea.getText().replaceAll("\n", "\\n"));
// }
// });
addTextComponent(pane, label, editable, listener, tfArea, true, true);
return tfArea;
}
@@ -318,49 +266,63 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
return addIntegerField(pane, label, initialValue, 0, allowNegatives, editable, listener);
}
public static JSpinner addIntegerField(JPanel pane, String label, Integer initialValue, Integer defaultValue, boolean allowNegatives, boolean editable, final FieldUpdateListener listener) {
public static <T extends Number & Comparable<T>> JSpinner addNumberField(JPanel pane, String label, boolean editable, final FieldUpdateListener listener, T minimum, T maximum, Number stepSize, T value, T defaultValue) {
JPanel tfPane = new JPanel();
tfPane.setLayout(new JideBoxLayout(tfPane, JideBoxLayout.LINE_AXIS, 6));
JLabel tfLabel = new JLabel(label);
tfPane.add(tfLabel, JideBoxLayout.FIX);
final JSpinner spinner = new JSpinner(new SpinnerNumberModel(initialValue != null ? initialValue.intValue() : defaultValue.intValue(), allowNegatives ? Integer.MIN_VALUE : 0, Integer.MAX_VALUE, 1));
((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
if (!(((minimum == null) || (minimum.compareTo(value) <= 0)) &&
((maximum == null) || (maximum.compareTo(value) >= 0)))) {
System.err.printf("Value for number field outside of range: %s <= %s <= %s is false%n", minimum, value, maximum);
value = defaultValue;
}
final JSpinner spinner = new JSpinner(new SpinnerNumberModel(value, minimum, maximum, stepSize));
((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
spinner.setEnabled(editable);
((DefaultFormatter)((NumberEditor)spinner.getEditor()).getTextField().getFormatter()).setCommitsOnValidEdit(true);
((DefaultFormatter) ((NumberEditor) spinner.getEditor()).getTextField().getFormatter()).setCommitsOnValidEdit(true);
tfPane.add(spinner, JideBoxLayout.VARY);
JButton nullify = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
tfPane.add(nullify, JideBoxLayout.FIX);
nullify.setEnabled(editable);
pane.add(tfPane, JideBoxLayout.FIX);
spinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
listener.valueChanged(spinner, spinner.getValue());
}
});
nullify.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
spinner.addChangeListener(e -> listener.valueChanged(spinner, spinner.getValue()));
nullify.addActionListener(e -> {
spinner.setValue(0);
listener.valueChanged(spinner, null);
}
});
return spinner;
}
public static JSpinner addIntegerField(JPanel pane, String label, Integer initialValue, Integer defaultValue, boolean allowNegatives, boolean editable, final FieldUpdateListener listener) {
int value = initialValue != null ? initialValue : defaultValue;
int minimum = allowNegatives ? Integer.MIN_VALUE : 0;
int maximum = Integer.MAX_VALUE;
return addNumberField(pane, label, editable, listener, minimum, maximum, 1, value, defaultValue);
}
private static final String percent = "%";
private static final String ratio = "x/y";
public static JComponent addChanceField(JPanel pane, String label, String initialValue, String defaultValue, boolean editable, final FieldUpdateListener listener) {
int defaultChance = 1;
int defaultMaxChance = 100;
if (defaultValue != null) {
if (defaultValue.contains("/")) {
int c = defaultValue.indexOf('/');
try { defaultChance = Integer.parseInt(defaultValue.substring(0, c)); } catch (NumberFormatException nfe) {};
try { defaultMaxChance = Integer.parseInt(defaultValue.substring(c+1)); } catch (NumberFormatException nfe) {};
try {
defaultChance = Integer.parseInt(defaultValue.substring(0, c));
} catch (NumberFormatException nfe) {
}
try {
defaultMaxChance = Integer.parseInt(defaultValue.substring(c + 1));
} catch (NumberFormatException nfe) {
}
} else {
try { defaultChance = Integer.parseInt(defaultValue); } catch (NumberFormatException nfe) {};
try {
defaultChance = Integer.parseInt(defaultValue);
} catch (NumberFormatException nfe) {
}
}
}
@@ -370,13 +332,20 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
if (initialValue != null) {
if (initialValue.contains("/")) {
int c = initialValue.indexOf('/');
try { chance = Integer.parseInt(initialValue.substring(0, c)); } catch (NumberFormatException nfe) {};
try { maxChance = Integer.parseInt(initialValue.substring(c+1)); } catch (NumberFormatException nfe) {};
try {
chance = Integer.parseInt(initialValue.substring(0, c));
} catch (NumberFormatException nfe) {
}
try {
maxChance = Integer.parseInt(initialValue.substring(c + 1));
} catch (NumberFormatException nfe) {
}
} else {
try {
chance = Integer.parseInt(initialValue);
currentFormIsRatio = false;
} catch (NumberFormatException nfe) {};
} catch (NumberFormatException nfe) {
}
}
}
@@ -385,7 +354,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
JLabel tfLabel = new JLabel(label);
tfPane.add(tfLabel, JideBoxLayout.FIX);
final JComboBox<String> entryTypeBox = new JComboBox<String>(new String[] {percent, ratio});
final JComboBox<String> entryTypeBox = new JComboBox<String>(new String[]{percent, ratio});
if (currentFormIsRatio) {
entryTypeBox.setSelectedItem(ratio);
} else {
@@ -394,22 +363,26 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
entryTypeBox.setEnabled(editable);
tfPane.add(entryTypeBox, JideBoxLayout.FIX);
/////////////////////////////////////////////////////////////////////////////////////////////////// make sure "chance" is between 1 and 100. If lower than 1 get 1. If higher than 100, get chance/maxChance * 100... Then do the same with defaultChance, in case no value exist.
final SpinnerNumberModel percentModel = new SpinnerNumberModel(initialValue != null ? ((chance > 1 ? chance : 1) < 100 ? chance : (chance * 100 / maxChance)) : ((defaultChance > 1 ? defaultChance : 1) < 100 ? defaultChance : (defaultChance * 100 / defaultMaxChance)) , 1, 100, 1);
final SpinnerNumberModel percentModel = new SpinnerNumberModel(
initialValue != null ? ((chance > 1 ? chance : 1) < 100 ? chance : (chance * 100 / maxChance)) : ((defaultChance > 1 ? defaultChance : 1) < 100 ? defaultChance : (defaultChance * 100 /
defaultMaxChance)),
1, 100, 1);
final SpinnerNumberModel ratioChanceModel = new SpinnerNumberModel(initialValue != null ? chance : defaultChance, 1, Integer.MAX_VALUE, 1);
final JSpinner chanceSpinner = new JSpinner(currentFormIsRatio ? ratioChanceModel : percentModel);
if (!currentFormIsRatio) ((JSpinner.DefaultEditor)chanceSpinner.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
if (!currentFormIsRatio)
((JSpinner.DefaultEditor) chanceSpinner.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
chanceSpinner.setEnabled(editable);
((DefaultFormatter)((NumberEditor)chanceSpinner.getEditor()).getTextField().getFormatter()).setCommitsOnValidEdit(true);
((DefaultFormatter) ((NumberEditor) chanceSpinner.getEditor()).getTextField().getFormatter()).setCommitsOnValidEdit(true);
tfPane.add(chanceSpinner, JideBoxLayout.FLEXIBLE);
final JLabel ratioLabel = new JLabel("/");
tfPane.add(ratioLabel, JideBoxLayout.FIX);
final JSpinner maxChanceSpinner = new JSpinner(new SpinnerNumberModel(initialValue != null ? maxChance : defaultMaxChance, 1, Integer.MAX_VALUE, 1));
((JSpinner.DefaultEditor)maxChanceSpinner.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
((JSpinner.DefaultEditor) maxChanceSpinner.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
maxChanceSpinner.setEnabled(editable);
((DefaultFormatter)((NumberEditor)maxChanceSpinner.getEditor()).getTextField().getFormatter()).setCommitsOnValidEdit(true);
((DefaultFormatter) ((NumberEditor) maxChanceSpinner.getEditor()).getTextField().getFormatter()).setCommitsOnValidEdit(true);
tfPane.add(maxChanceSpinner, JideBoxLayout.FLEXIBLE);
if (!currentFormIsRatio) {
@@ -428,21 +401,21 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
@Override
public void actionPerformed(ActionEvent e) {
if (entryTypeBox.getSelectedItem() == percent) {
int chance = ((Integer)chanceSpinner.getValue());
int maxChance = ((Integer)maxChanceSpinner.getValue());
int chance = ((Integer) chanceSpinner.getValue());
int maxChance = ((Integer) maxChanceSpinner.getValue());
chance *= 100;
chance /= maxChance;
chance = Math.max(0, Math.min(100, chance));
chanceSpinner.setModel(percentModel);
chanceSpinner.setValue(chance);
((JSpinner.DefaultEditor)chanceSpinner.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
((JSpinner.DefaultEditor) chanceSpinner.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
ratioLabel.setVisible(false);
maxChanceSpinner.setVisible(false);
tfPane.revalidate();
tfPane.repaint();
listener.valueChanged(chanceSpinner, chanceSpinner.getValue().toString());
} else if (entryTypeBox.getSelectedItem() == ratio) {
int chance = ((Integer)chanceSpinner.getValue());
int chance = ((Integer) chanceSpinner.getValue());
chanceSpinner.setModel(ratioChanceModel);
chanceSpinner.setValue(chance);
maxChanceSpinner.setValue(100);
@@ -485,34 +458,11 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
// }
public static JSpinner addDoubleField(JPanel pane, String label, Double initialValue, boolean editable, final FieldUpdateListener listener) {
JPanel tfPane = new JPanel();
tfPane.setLayout(new JideBoxLayout(tfPane, JideBoxLayout.LINE_AXIS, 6));
JLabel tfLabel = new JLabel(label);
tfPane.add(tfLabel, JideBoxLayout.FIX);
final JSpinner spinner = new JSpinner(new SpinnerNumberModel(initialValue != null ? initialValue.doubleValue() : 0.0d, 0.0d, new Float(Float.MAX_VALUE).doubleValue(), 1.0d));
((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
spinner.setEnabled(editable);
((DefaultFormatter)((NumberEditor)spinner.getEditor()).getTextField().getFormatter()).setCommitsOnValidEdit(true);
tfPane.add(spinner, JideBoxLayout.VARY);
JButton nullify = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
tfPane.add(nullify, JideBoxLayout.FIX);
nullify.setEnabled(editable);
pane.add(tfPane, JideBoxLayout.FIX);
pane.add(tfPane, JideBoxLayout.FIX);
spinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
listener.valueChanged(spinner, spinner.getValue());
}
});
nullify.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
spinner.setValue(0.0d);
listener.valueChanged(spinner, null);
}
});
return spinner;
double minimum = 0.0d;
double defaultValue = 0.0d;
double value = initialValue != null ? initialValue : minimum;
double maximum = Float.valueOf(Float.MAX_VALUE).doubleValue();
return addNumberField(pane, label, editable, listener, minimum, maximum, 1.0d, value, defaultValue);
}
public static IntegerBasedCheckBox addIntegerBasedCheckBox(JPanel pane, String label, Integer initialValue, boolean editable) {
@@ -559,7 +509,11 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
@SuppressWarnings("rawtypes")
public static JComboBox addEnumValueBox(JPanel pane, String label, Enum[] values, Enum initialValue, boolean writable) {
return addEnumValueBox(pane, label, values, initialValue, writable, new FieldUpdateListener() {@Override public void valueChanged(JComponent source, Object value) {}});
return addEnumValueBox(pane, label, values, initialValue, writable, new FieldUpdateListener() {
@Override
public void valueChanged(JComponent source, Object value) {
}
});
}
@SuppressWarnings("rawtypes")
@@ -568,8 +522,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
comboPane.setLayout(new JideBoxLayout(comboPane, JideBoxLayout.LINE_AXIS, 6));
JLabel comboLabel = new JLabel(label);
comboPane.add(comboLabel, JideBoxLayout.FIX);
@SuppressWarnings("unchecked")
final JComboBox enumValuesCombo = new JComboBox(values);
@SuppressWarnings("unchecked") final JComboBox enumValuesCombo = new JComboBox(values);
enumValuesCombo.setEnabled(writable);
enumValuesCombo.setSelectedItem(initialValue);
comboPane.add(enumValuesCombo, JideBoxLayout.VARY);
@@ -598,120 +551,136 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
public MyComboBox addNPCBox(JPanel pane, Project proj, String label, NPC npc, boolean writable, FieldUpdateListener listener) {
final GDEComboModel<NPC> comboModel = new GDEComboModel<NPC>(proj, npc){
final GDEComboModel<NPC> comboModel = new GDEComboModel<NPC>(proj, npc) {
private static final long serialVersionUID = 2638082961277241764L;
@Override
public NPC getTypedElementAt(int index) {
return project.getNPC(index);
}
@Override
public int getSize() {
return project.getNPCCount()+1;
return project.getNPCCount() + 1;
}
};
return addGDEBox(pane, label, npc, NPC.class, comboModel, writable, listener);
}
public MyComboBox addActorConditionBox(JPanel pane, Project proj, String label, ActorCondition acond, boolean writable, FieldUpdateListener listener) {
final GDEComboModel<ActorCondition> comboModel = new GDEComboModel<ActorCondition>(proj, acond){
final GDEComboModel<ActorCondition> comboModel = new GDEComboModel<ActorCondition>(proj, acond) {
private static final long serialVersionUID = 2638082961277241764L;
@Override
public ActorCondition getTypedElementAt(int index) {
return project.getActorCondition(index);
}
@Override
public int getSize() {
return project.getActorConditionCount()+1;
return project.getActorConditionCount() + 1;
}
};
return addGDEBox(pane, label, acond, ActorCondition.class, comboModel, writable, listener);
}
public MyComboBox addItemBox(JPanel pane, Project proj, String label, Item item, boolean writable, FieldUpdateListener listener) {
final GDEComboModel<Item> comboModel = new GDEComboModel<Item>(proj, item){
final GDEComboModel<Item> comboModel = new GDEComboModel<Item>(proj, item) {
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Item getTypedElementAt(int index) {
return project.getItem(index);
}
@Override
public int getSize() {
return project.getItemCount()+1;
return project.getItemCount() + 1;
}
};
return addGDEBox(pane, label, item, Item.class, comboModel, writable, listener);
}
public MyComboBox addItemCategoryBox(JPanel pane, Project proj, String label, ItemCategory ic, boolean writable, FieldUpdateListener listener) {
final GDEComboModel<ItemCategory> comboModel = new GDEComboModel<ItemCategory>(proj, ic){
final GDEComboModel<ItemCategory> comboModel = new GDEComboModel<ItemCategory>(proj, ic) {
private static final long serialVersionUID = 2638082961277241764L;
@Override
public ItemCategory getTypedElementAt(int index) {
return project.getItemCategory(index);
}
@Override
public int getSize() {
return project.getItemCategoryCount()+1;
return project.getItemCategoryCount() + 1;
}
};
return addGDEBox(pane, label, ic, ItemCategory.class, comboModel, writable, listener);
}
public MyComboBox addQuestBox(JPanel pane, Project proj, String label, Quest quest, boolean writable, FieldUpdateListener listener) {
final GDEComboModel<Quest> comboModel = new GDEComboModel<Quest>(proj, quest){
final GDEComboModel<Quest> comboModel = new GDEComboModel<Quest>(proj, quest) {
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Quest getTypedElementAt(int index) {
return project.getQuest(index);
}
@Override
public int getSize() {
return project.getQuestCount()+1;
return project.getQuestCount() + 1;
}
};
return addGDEBox(pane, label, quest, Quest.class, comboModel, writable, listener);
}
public MyComboBox addDroplistBox(JPanel pane, Project proj, String label, Droplist droplist, boolean writable, FieldUpdateListener listener) {
final GDEComboModel<Droplist> comboModel = new GDEComboModel<Droplist>(proj, droplist){
final GDEComboModel<Droplist> comboModel = new GDEComboModel<Droplist>(proj, droplist) {
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Droplist getTypedElementAt(int index) {
return project.getDroplist(index);
}
@Override
public int getSize() {
return project.getDroplistCount()+1;
return project.getDroplistCount() + 1;
}
};
return addGDEBox(pane, label, droplist, Droplist.class, comboModel, writable, listener);
}
public MyComboBox addDialogueBox(JPanel pane, Project proj, String label, Dialogue dialogue, boolean writable, final FieldUpdateListener listener) {
final GDEComboModel<Dialogue> comboModel = new GDEComboModel<Dialogue>(proj, dialogue){
final GDEComboModel<Dialogue> comboModel = new GDEComboModel<Dialogue>(proj, dialogue) {
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Dialogue getTypedElementAt(int index) {
return project.getDialogue(index);
}
@Override
public int getSize() {
return project.getDialogueCount()+1;
return project.getDialogueCount() + 1;
}
};
return addGDEBox(pane, label, dialogue, Dialogue.class, comboModel, writable, listener);
}
public MyComboBox addMapBox(JPanel pane, Project proj, String label, TMXMap map, boolean writable, final FieldUpdateListener listener) {
final GDEComboModel<TMXMap> comboModel = new GDEComboModel<TMXMap>(proj, map){
final GDEComboModel<TMXMap> comboModel = new GDEComboModel<TMXMap>(proj, map) {
private static final long serialVersionUID = 2638082961277241764L;
@Override
public TMXMap getTypedElementAt(int index) {
return project.getMap(index);
}
@Override
public int getSize() {
return project.getMapCount()+1;
return project.getMapCount() + 1;
}
};
return addGDEBox(pane, label, map, TMXMap.class, comboModel, writable, listener);
@@ -725,11 +694,11 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
gdePane.add(gdeLabel, JideBoxLayout.FIX);
final MyComboBox gdeBox = new MyComboBox(dataClass, comboModel);
gdeBox.setRenderer(new GDERenderer(false, writable));
new ComboBoxSearchable(gdeBox){
new ComboBoxSearchable(gdeBox) {
@Override
protected String convertElementToString(Object object) {
if (object == null) return "none";
else return ((GameDataElement)object).getDesc();
else return ((GameDataElement) object).getDesc();
}
};
gdeBox.setEnabled(writable);
@@ -739,12 +708,12 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
goToGde.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GameDataElement selected = ((GameDataElement)comboModel.getSelectedItem());
GameDataElement selected = ((GameDataElement) comboModel.getSelectedItem());
if (selected != null) {
ATContentStudio.frame.openEditor(((GameDataElement)comboModel.getSelectedItem()));
ATContentStudio.frame.selectInTree((GameDataElement)comboModel.getSelectedItem());
ATContentStudio.frame.openEditor(((GameDataElement) comboModel.getSelectedItem()));
ATContentStudio.frame.selectInTree((GameDataElement) comboModel.getSelectedItem());
} else if (writable) {
JSONCreationWizard wizard = new JSONCreationWizard(((GameDataElement)target).getProject(), dataClass);
JSONCreationWizard wizard = new JSONCreationWizard(((GameDataElement) target).getProject(), dataClass);
wizard.addCreationListener(new JSONCreationWizard.CreationCompletedListener() {
@Override
@@ -764,7 +733,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
goToGde.setIcon((writable ? new ImageIcon(DefaultIcons.getCreateIcon()) : null));
goToGde.setEnabled(writable);
} else {
goToGde.setIcon(new ImageIcon(((GameDataElement)comboModel.getSelectedItem()).getIcon()));
goToGde.setIcon(new ImageIcon(((GameDataElement) comboModel.getSelectedItem()).getIcon()));
goToGde.setEnabled(true);
}
listener.valueChanged(gdeBox, gdeBox.getModel().getSelectedItem());
@@ -797,11 +766,11 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
final QuestStageComboModel comboModel = new QuestStageComboModel(proj, initial, quest);
final JComboBox<QuestStage> combo = new JComboBox<QuestStage>(comboModel);
combo.setRenderer(new GDERenderer(false, writable));
new ComboBoxSearchable(combo){
new ComboBoxSearchable(combo) {
@Override
protected String convertElementToString(Object object) {
if (object == null) return "none";
else return ((GameDataElement)object).getDesc();
else return ((GameDataElement) object).getDesc();
}
};
questSelectionBox.addActionListener(new ActionListener() {
@@ -823,7 +792,6 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
});
combo.setEnabled(writable);
gdePane.add(combo, JideBoxLayout.VARY);
@@ -833,21 +801,20 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
}
@SuppressWarnings({ "rawtypes"})
@SuppressWarnings({"rawtypes"})
public JList addBacklinksList(JPanel pane, GameDataElement gde) {
return addBacklinksList(pane, gde, "Elements linking to this one");
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public JList addBacklinksList(JPanel pane, GameDataElement gde, String title) {
final JList list = new JList(new GDEBacklinksListModel(gde));
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
ATContentStudio.frame.openEditor((GameDataElement)list.getSelectedValue());
ATContentStudio.frame.selectInTree((GameDataElement)list.getSelectedValue());
ATContentStudio.frame.openEditor((GameDataElement) list.getSelectedValue());
ATContentStudio.frame.selectInTree((GameDataElement) list.getSelectedValue());
}
}
});
@@ -855,8 +822,8 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
ATContentStudio.frame.openEditor((GameDataElement)list.getSelectedValue());
ATContentStudio.frame.selectInTree((GameDataElement)list.getSelectedValue());
ATContentStudio.frame.openEditor((GameDataElement) list.getSelectedValue());
ATContentStudio.frame.selectInTree((GameDataElement) list.getSelectedValue());
}
}
});
@@ -922,8 +889,8 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
private static final long serialVersionUID = 6819681566800482793L;
private boolean includeType = false;
private boolean writable = false;
private boolean includeType;
private boolean writable;
public GDERenderer(boolean includeType, boolean writable) {
super();
@@ -936,33 +903,33 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value == null) {
label.setText("None"+(writable ? ". Click on the button to create one." : ""));
label.setText("None" + (writable ? ". Click on the button to create one." : ""));
} else {
if (includeType && ((GameDataElement)value).getDataType() != null) {
if (includeType && ((GameDataElement) value).getDataType() != null) {
if (value instanceof QuestStage) {
String text = ((GameDataElement)value).getDesc();
String text = ((GameDataElement) value).getDesc();
if (text.length() > 60) {
text = text.substring(0, 57)+"...";
text = text.substring(0, 57) + "...";
}
label.setText(((GameDataElement)value).getDataType().toString()+"/"+((Quest)((QuestStage)value).parent).id+"#"+((QuestStage)value).progress+":"+text);
label.setText(((GameDataElement) value).getDataType().toString() + "/" + ((Quest) ((QuestStage) value).parent).id + "#" + ((QuestStage) value).progress + ":" + text);
} else {
label.setText(((GameDataElement)value).getDataType().toString()+"/"+((GameDataElement)value).getDesc());
label.setText(((GameDataElement) value).getDataType().toString() + "/" + ((GameDataElement) value).getDesc());
}
} else {
if (value instanceof QuestStage) {
String text = ((GameDataElement)value).getDesc();
String text = ((GameDataElement) value).getDesc();
if (text.length() > 60) {
text = text.substring(0, 57)+"...";
text = text.substring(0, 57) + "...";
}
label.setText(text);
} else {
label.setText(((GameDataElement)value).getDesc());
label.setText(((GameDataElement) value).getDesc());
}
}
if (((GameDataElement)value).getIcon() == null) {
Notification.addError("Unable to find icon for "+((GameDataElement)value).getDesc());
if (((GameDataElement) value).getIcon() == null) {
Notification.addError("Unable to find icon for " + ((GameDataElement) value).getDesc());
} else {
label.setIcon(new ImageIcon(((GameDataElement)value).getIcon()));
label.setIcon(new ImageIcon(((GameDataElement) value).getIcon()));
}
}
return label;
@@ -987,7 +954,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
@Override
public int getSize() {
if (currentQuest == null) return 1;
return currentQuest.stages.size()+1;
return currentQuest.stages.size() + 1;
}
@Override
@@ -1028,7 +995,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
}
public static class GDEBacklinksListModel implements ListModel<GameDataElement> {
public static class GDEBacklinksListModel implements ListenerCollectionModel<GameDataElement> {
GameDataElement source;
@@ -1040,6 +1007,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
public void backlinkRemoved(GameDataElement gde) {
fireListChanged();
}
@Override
public void backlinkAdded(GameDataElement gde) {
fireListChanged();
@@ -1048,36 +1016,17 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
}
@Override
public int getSize() {
return source.getBacklinks().size();
}
@Override
public GameDataElement getElementAt(int index) {
for (GameDataElement gde : source.getBacklinks()) {
if (index == 0) return gde;
index --;
}
return null;
public Collection<GameDataElement> getElements() {
return source.getBacklinks();
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
public List<ListDataListener> getListeners() {
return listeners;
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
}
public void fireListChanged() {
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, this.getSize()));
}
}
}
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -1095,12 +1044,12 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
@Override
public void elementAdded(GameDataElement added, int index) {
((GDEComboModel)getModel()).itemAdded(added, index);
((GDEComboModel) getModel()).itemAdded(added, index);
}
@Override
public void elementRemoved(GameDataElement removed, int index) {
((GDEComboModel)getModel()).itemRemoved(removed, index);
((GDEComboModel) getModel()).itemRemoved(removed, index);
}
@Override
@@ -1113,7 +1062,6 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
public abstract void targetUpdated();
transient Map<Class<? extends GameDataElement>, List<ProjectElementListener>> projectElementListeners = new HashMap<Class<? extends GameDataElement>, List<ProjectElementListener>>();
public void addElementListener(Class<? extends GameDataElement> interestingType, ProjectElementListener listener) {
@@ -1162,4 +1110,21 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
}
public <E extends Common.ActorConditionEffect, T extends OrderedListenerListModel<?, E>> void updateConditionEffect(ActorCondition value,
GameDataElement backlink,
E selectedHitEffectTargetCondition,
T hitTargetConditionsModel) {
if (selectedHitEffectTargetCondition.condition != null) {
selectedHitEffectTargetCondition.condition.removeBacklink(backlink);
}
selectedHitEffectTargetCondition.condition = value;
if (selectedHitEffectTargetCondition.condition != null) {
selectedHitEffectTargetCondition.condition_id = selectedHitEffectTargetCondition.condition.id;
selectedHitEffectTargetCondition.condition.addBacklink(backlink);
} else {
selectedHitEffectTargetCondition.condition_id = null;
}
hitTargetConditionsModel.itemChanged(selectedHitEffectTargetCondition);
}
}

View File

@@ -1,35 +1,13 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.swing.Action;
import javax.swing.JPanel;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.*;
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.writermode.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;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.ItemCategoryEditor;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.ItemEditor;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.NPCEditor;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.QuestEditor;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.*;
import com.gpl.rpg.atcontentstudio.ui.map.TMXMapEditor;
import com.gpl.rpg.atcontentstudio.ui.map.WorldMapEditor;
import com.gpl.rpg.atcontentstudio.ui.saves.SavedGameEditor;
@@ -37,6 +15,13 @@ import com.gpl.rpg.atcontentstudio.ui.sprites.SpritesheetEditor;
import com.gpl.rpg.atcontentstudio.ui.tools.writermode.WriterModeEditor;
import com.jidesoft.swing.JideTabbedPane;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.util.LinkedHashMap;
import java.util.Map;
public class EditorsArea extends JPanel {
private static final long serialVersionUID = 8801849846876081538L;
@@ -61,20 +46,25 @@ public class EditorsArea extends JPanel {
@Override
public void setEnabled(boolean b) {
}
@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
}
@Override
public void putValue(String key, Object value) {
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public Object getValue(String key) {
return null;
}
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
}
@@ -104,7 +94,7 @@ public class EditorsArea extends JPanel {
return;
}
if (node instanceof Quest) {
openEditor(new QuestEditor((Quest)node));
openEditor(new QuestEditor((Quest) node));
} else if (node instanceof Dialogue) {
openEditor(new DialogueEditor((Dialogue) node));
} else if (node instanceof Droplist) {

View File

@@ -1,21 +1,5 @@
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 java.io.File;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
@@ -23,6 +7,12 @@ import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
import com.gpl.rpg.atcontentstudio.model.sprites.SpriteSheetSet;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class ExportProjectWizard extends JDialog {
private static final long serialVersionUID = -8745083621008868612L;
@@ -78,8 +68,9 @@ public class ExportProjectWizard extends JDialog {
browse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser(){
JFileChooser jfc = new JFileChooser() {
private static final long serialVersionUID = -3001082967957619011L;
@Override
public boolean accept(File f) {
if (asZip.isSelected()) {
@@ -100,7 +91,7 @@ public class ExportProjectWizard extends JDialog {
if (result == JFileChooser.APPROVE_OPTION) {
File f = jfc.getSelectedFile();
if (asZip.isSelected() && !f.getAbsolutePath().substring(f.getAbsolutePath().length() - 4, f.getAbsolutePath().length()).equalsIgnoreCase(".zip")) {
f = new File(f.getAbsolutePath()+".zip");
f = new File(f.getAbsolutePath() + ".zip");
}
target.setSelectedItem(f.getAbsolutePath());
updateState();
@@ -157,12 +148,12 @@ public class ExportProjectWizard extends JDialog {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(pane, BorderLayout.CENTER);
setMinimumSize(new Dimension(500,150));
setMinimumSize(new Dimension(500, 150));
pack();
Dimension sdim = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wdim = getSize();
setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
setLocation((sdim.width - wdim.width) / 2, (sdim.height - wdim.height) / 2);
}
private void updateState() {

View File

@@ -1,6 +1,6 @@
package com.gpl.rpg.atcontentstudio.ui;
import javax.swing.JComponent;
import javax.swing.*;
public interface FieldUpdateListener {

View File

@@ -1,25 +1,16 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;
public class IdChangeImpactWizard extends JDialog {
private static final long serialVersionUID = 8532169707953315739L;
@@ -35,7 +26,7 @@ public class IdChangeImpactWizard extends JDialog {
JPanel pane = new JPanel();
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.PAGE_AXIS));
pane.add(new JLabel("Changing the id for \""+changing.getDesc()+"\" has impacts on your project:"), JideBoxLayout.FIX);
pane.add(new JLabel("Changing the id for \"" + changing.getDesc() + "\" has impacts on your project:"), JideBoxLayout.FIX);
pane.add(new JLabel("The following elements from your project will be modified:"), JideBoxLayout.FIX);
JList<GameDataElement> modifList = new JList<GameDataElement>(new Vector<GameDataElement>(toModify));
modifList.setCellRenderer(new ChangeImpactListCellRenderer());
@@ -88,9 +79,9 @@ public class IdChangeImpactWizard extends JDialog {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
GameDataElement target = ((GameDataElement)value);
GameDataElement target = ((GameDataElement) value);
label.setIcon(new ImageIcon(target.getIcon()));
label.setText(target.getDataType().toString()+"/"+target.getDesc());
label.setText(target.getDataType().toString() + "/" + target.getDesc());
}
return c;
}

View File

@@ -1,6 +1,6 @@
package com.gpl.rpg.atcontentstudio.ui;
import javax.swing.JCheckBox;
import javax.swing.*;
public class IntegerBasedCheckBox extends JCheckBox {

View File

@@ -1,12 +1,7 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import javax.swing.JComponent;
import javax.swing.*;
import java.awt.*;
public class JMovingIdler extends JComponent {
@@ -14,8 +9,8 @@ public class JMovingIdler extends JComponent {
private static final long serialVersionUID = -2980521421870322717L;
int position = 0;
boolean destroyed=false, running=false;
Thread moverThread = new Thread(){
boolean destroyed = false, running = false;
Thread moverThread = new Thread() {
public void run() {
while (!destroyed) {
boolean back = false;
@@ -33,7 +28,8 @@ public class JMovingIdler extends JComponent {
}
try {
sleep(10);
} catch (InterruptedException e) {}
} catch (InterruptedException e) {
}
JMovingIdler.this.revalidate();
JMovingIdler.this.repaint();
}
@@ -57,7 +53,8 @@ public class JMovingIdler extends JComponent {
running = false;
try {
moverThread.join();
} catch (InterruptedException e) {}
} catch (InterruptedException e) {
}
}
protected void paintComponent(Graphics g) {
@@ -67,23 +64,23 @@ public class JMovingIdler extends JComponent {
int h = this.getHeight();
g2.setColor(getBackground());
g2.fillRect(0,0,w,h);
g2.fillRect(0, 0, w, h);
int x = w * position / 100;
Paint p = new GradientPaint(x - (w/8), 0, getBackground(), x , 0, getForeground());
Paint p = new GradientPaint(x - (w / 8), 0, getBackground(), x, 0, getForeground());
g2.setPaint(p);
g2.fillRect(Math.max(0,x-(w/8)),0, Math.min(x, w), h);
g2.fillRect(Math.max(0, x - (w / 8)), 0, Math.min(x, w), h);
p = new GradientPaint(x, 0, getForeground(), x + (w/8), 0, getBackground());
p = new GradientPaint(x, 0, getForeground(), x + (w / 8), 0, getBackground());
g2.setPaint(p);
g2.fillRect(Math.max(0,x),0, Math.min(x+(w/8), w), h);
g2.fillRect(Math.max(0, x), 0, Math.min(x + (w / 8), w), h);
g2.setColor(Color.BLACK);
g2.drawLine(0,0,0,h);
g2.drawLine(0,0,w,0);
g2.drawLine(w,0,w,h);
g2.drawLine(0,h,w,h);
g2.drawLine(0, 0, 0, h);
g2.drawLine(0, 0, w, 0);
g2.drawLine(w, 0, w, h);
g2.drawLine(0, h, w, h);
}
@Override

View File

@@ -1,47 +1,27 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListDataListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameDataElement.State;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.*;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.ui.sprites.SpriteChooser;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListDataListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class JSONCreationWizard extends JDialog {
private static final long serialVersionUID = -5744628699021314026L;
@@ -86,7 +66,7 @@ public class JSONCreationWizard extends JDialog {
dataTypeCombo.setEnabled(false);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public JSONCreationWizard(final Project proj) {
super(ATContentStudio.frame);
this.proj = proj;
@@ -137,7 +117,7 @@ public class JSONCreationWizard extends JDialog {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
idPane.setVisible(true);
switch ((DataType)e.getItem()) {
switch ((DataType) e.getItem()) {
case actorCondition:
iconPane.setVisible(true);
namePane.setVisible(true);
@@ -199,7 +179,7 @@ public class JSONCreationWizard extends JDialog {
@Override
public void actionPerformed(ActionEvent e) {
Spritesheet.Category cat = null;
switch ((DataType)dataTypeCombo.getSelectedItem()) {
switch ((DataType) dataTypeCombo.getSelectedItem()) {
case actorCondition:
cat = Spritesheet.Category.actorcondition;
break;
@@ -227,15 +207,15 @@ public class JSONCreationWizard extends JDialog {
@Override
public void iconSelected(String selected) {
if (selected != null) {
switch ((DataType)dataTypeCombo.getSelectedItem()) {
switch ((DataType) dataTypeCombo.getSelectedItem()) {
case actorCondition:
((ActorCondition)creation).icon_id = selected;
((ActorCondition) creation).icon_id = selected;
break;
case item:
((Item)creation).icon_id = selected;
((Item) creation).icon_id = selected;
break;
case npc:
((NPC)creation).icon_id = selected;
((NPC) creation).icon_id = selected;
break;
case dialogue:
case droplist:
@@ -271,24 +251,24 @@ public class JSONCreationWizard extends JDialog {
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
switch ((DataType)dataTypeCombo.getSelectedItem()) {
switch ((DataType) dataTypeCombo.getSelectedItem()) {
case actorCondition:
((ActorCondition)creation).display_name = nameField.getText();
((ActorCondition) creation).display_name = nameField.getText();
break;
case item:
((Item)creation).name = nameField.getText();
((Item) creation).name = nameField.getText();
break;
case npc:
((NPC)creation).name = nameField.getText();
((NPC) creation).name = nameField.getText();
break;
case dialogue:
case droplist:
break;
case itemCategory:
((ItemCategory)creation).name = nameField.getText();
((ItemCategory) creation).name = nameField.getText();
break;
case quest:
((Quest)creation).name = nameField.getText();
((Quest) creation).name = nameField.getText();
break;
default:
return;
@@ -318,10 +298,12 @@ public class JSONCreationWizard extends JDialog {
public void removeUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void changedUpdate(DocumentEvent e) {
updateStatus();
@@ -333,7 +315,7 @@ public class JSONCreationWizard extends JDialog {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(pane, BorderLayout.CENTER);
setMinimumSize(new Dimension(350,250));
setMinimumSize(new Dimension(350, 250));
idPane.setVisible(false);
iconPane.setVisible(false);
namePane.setVisible(false);
@@ -342,7 +324,7 @@ public class JSONCreationWizard extends JDialog {
Dimension sdim = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wdim = getSize();
setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
setLocation((sdim.width - wdim.width) / 2, (sdim.height - wdim.height) / 2);
}
public void updateStatus() {
@@ -355,12 +337,12 @@ public class JSONCreationWizard extends JDialog {
message.setText("<html><font color=\"#FF0000\">Internal ID must not be empty.</font></html>");
trouble = true;
} else {
switch ((DataType)dataTypeCombo.getSelectedItem()) {
switch ((DataType) dataTypeCombo.getSelectedItem()) {
case actorCondition:
if(nameField.getText() == null || nameField.getText().length() <= 0) {
if (nameField.getText() == null || nameField.getText().length() <= 0) {
message.setText("<html><font color=\"#FF0000\">An actor condition must have a name.</font></html>");
trouble = true;
} else if (((ActorCondition)creation).icon_id == null) {
} else if (((ActorCondition) creation).icon_id == null) {
message.setText("<html><font color=\"#FF0000\">An actor condition must have an icon.</font></html>");
trouble = true;
} else if (proj.getActorCondition(idField.getText()) != null) {
@@ -376,10 +358,10 @@ public class JSONCreationWizard extends JDialog {
}
break;
case item:
if(nameField.getText() == null || nameField.getText().length() <= 0) {
if (nameField.getText() == null || nameField.getText().length() <= 0) {
message.setText("<html><font color=\"#FF0000\">An item must have a name.</font></html>");
trouble = true;
} else if (((Item)creation).icon_id == null) {
} else if (((Item) creation).icon_id == null) {
message.setText("<html><font color=\"#FF0000\">An item must have an icon.</font></html>");
trouble = true;
} else if (proj.getItem(idField.getText()) != null) {
@@ -395,10 +377,10 @@ public class JSONCreationWizard extends JDialog {
}
break;
case npc:
if(nameField.getText() == null || nameField.getText().length() <= 0) {
if (nameField.getText() == null || nameField.getText().length() <= 0) {
message.setText("<html><font color=\"#FF0000\">A NPC must have a name.</font></html>");
trouble = true;
} else if (((NPC)creation).icon_id == null) {
} else if (((NPC) creation).icon_id == null) {
message.setText("<html><font color=\"#FF0000\">A NPC must have an icon.</font></html>");
trouble = true;
} else if (proj.getNPC(idField.getText()) != null) {
@@ -440,7 +422,7 @@ public class JSONCreationWizard extends JDialog {
}
break;
case itemCategory:
if(nameField.getText() == null || nameField.getText().length() <= 0) {
if (nameField.getText() == null || nameField.getText().length() <= 0) {
message.setText("<html><font color=\"#FF0000\">An item category must have a name.</font></html>");
trouble = true;
} else if (proj.getItemCategory(idField.getText()) != null) {
@@ -456,7 +438,7 @@ public class JSONCreationWizard extends JDialog {
}
break;
case quest:
if(nameField.getText() == null || nameField.getText().length() <= 0) {
if (nameField.getText() == null || nameField.getText().length() <= 0) {
message.setText("<html><font color=\"#FF0000\">A quest must have a name.</font></html>");
trouble = true;
} else if (proj.getQuest(idField.getText()) != null) {
@@ -548,28 +530,28 @@ public class JSONCreationWizard extends JDialog {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
((JLabel)c).setText(JSONCreationWizard.dataTypeDesc((DataType) value));
switch ((DataType)value) {
((JLabel) c).setText(JSONCreationWizard.dataTypeDesc((DataType) value));
switch ((DataType) value) {
case actorCondition:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getActorConditionIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getActorConditionIcon()));
break;
case dialogue:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getDialogueIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getDialogueIcon()));
break;
case droplist:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getDroplistIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getDroplistIcon()));
break;
case item:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getItemIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getItemIcon()));
break;
case itemCategory:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getDroplistIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getDroplistIcon()));
break;
case npc:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getNPCIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getNPCIcon()));
break;
case quest:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getQuestIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getQuestIcon()));
break;
default:
break;

View File

@@ -1,9 +1,22 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.*;
import com.jidesoft.swing.JideBoxLayout;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListDataListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
@@ -13,50 +26,11 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.jidesoft.swing.JideBoxLayout;
public class JSONImportWizard extends JDialog {
private static final long serialVersionUID = 661234868711700156L;
@@ -91,7 +65,7 @@ public class JSONImportWizard extends JDialog {
JButton ok, cancel;
ActionListener okListener, cancelListener;
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public JSONImportWizard(Project proj) {
super(ATContentStudio.frame);
@@ -155,10 +129,12 @@ public class JSONImportWizard extends JDialog {
public void removeUpdate(DocumentEvent e) {
checkEnableNext();
}
@Override
public void insertUpdate(DocumentEvent e) {
checkEnableNext();
}
@Override
public void changedUpdate(DocumentEvent e) {
checkEnableNext();
@@ -168,8 +144,9 @@ public class JSONImportWizard extends JDialog {
browse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser(){
JFileChooser jfc = new JFileChooser() {
private static final long serialVersionUID = -3001082967957619011L;
@Override
public boolean accept(File f) {
if (f.isDirectory() || f.getName().endsWith(".json") || f.getName().endsWith(".JSON")) {
@@ -216,8 +193,6 @@ public class JSONImportWizard extends JDialog {
});
buttonPane = new JPanel();
buttonPane.setLayout(new JideBoxLayout(buttonPane, JideBoxLayout.LINE_AXIS, 6));
buttonPane.add(new JPanel(), JideBoxLayout.VARY);
@@ -233,12 +208,12 @@ public class JSONImportWizard extends JDialog {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(pane, BorderLayout.CENTER);
setMinimumSize(new Dimension(450,350));
setMinimumSize(new Dimension(450, 350));
pack();
Dimension sdim = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wdim = getSize();
setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
setLocation((sdim.width - wdim.width) / 2, (sdim.height - wdim.height) / 2);
}
@@ -261,7 +236,7 @@ public class JSONImportWizard extends JDialog {
ok.setEnabled(jsonPasteArea.getText() != null && jsonPasteArea.getText().length() > 0 && dataTypeCombo.getSelectedItem() != null && dataTypeCombo.getSelectedItem() != DataType.none);
ok.removeActionListener(okListener);
okListener = new ActionListener() {
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void actionPerformed(ActionEvent e) {
List<String> errors = new ArrayList<String>();
@@ -275,16 +250,16 @@ public class JSONImportWizard extends JDialog {
jsonParserOutput = new JSONParser().parse(new FileReader(new File(jsonFileName.getText())));
}
} catch (ParseException e1) {
errors.add("Invalid JSON content: "+e1.getMessage());
errors.add("Invalid JSON content: " + e1.getMessage());
} catch (FileNotFoundException e1) {
errors.add("Unable to access file: "+e1.getMessage());
errors.add("Unable to access file: " + e1.getMessage());
} catch (IOException e1) {
errors.add("Error while accessing file: "+e1.getMessage());
errors.add("Error while accessing file: " + e1.getMessage());
}
if (jsonParserOutput != null) {
List<Map> jsonObjects = null;
if (jsonParserOutput instanceof List) {
jsonObjects = (List)jsonParserOutput;
jsonObjects = (List) jsonParserOutput;
} else if (jsonParserOutput instanceof Map) {
jsonObjects = new ArrayList<Map>();
jsonObjects.add((Map) jsonParserOutput);
@@ -292,11 +267,11 @@ public class JSONImportWizard extends JDialog {
errors.add("Invalid JSON content: neither an array nor an object.");
}
if (jsonObjects != null) {
JSONElement node = null;
JSONElement existingNode = null;
JSONElement node;
JSONElement existingNode;
int i = 0;
for (Map jsonObject : jsonObjects) {
switch ((DataType)dataTypeCombo.getSelectedItem()) {
switch ((DataType) dataTypeCombo.getSelectedItem()) {
case actorCondition:
node = ActorCondition.fromJson(jsonObject);
existingNode = proj.getActorCondition(node.id);
@@ -334,18 +309,16 @@ public class JSONImportWizard extends JDialog {
created.add(node);
if (existingNode != null) {
if (existingNode.getDataType() == GameSource.Type.created) {
errors.add("An item with id "+node.id+" is already created in this project.");
errors.add("An item with id " + node.id + " is already created in this project.");
} else if (existingNode.getDataType() == GameSource.Type.altered) {
errors.add("An item with id "+node.id+" is already altered in this project.");
errors.add("An item with id " + node.id + " is already altered in this project.");
} else {
node.jsonFile = existingNode.jsonFile;
warnings.add("An item with id "+node.id+" exists in the used game source. This one will be inserted as \"altered\"");
warnings.add("An item with id " + node.id + " exists in the used game source. This one will be inserted as \"altered\"");
}
existingNode = null;
}
node = null;
} else {
warnings.add("Failed to load element #"+i);
warnings.add("Failed to load element #" + i);
}
}
}
@@ -507,7 +480,7 @@ public class JSONImportWizard extends JDialog {
private static final long serialVersionUID = 6819681566800482793L;
private boolean includeType = false;
private boolean includeType;
public GDERenderer(boolean includeType) {
super();
@@ -521,35 +494,35 @@ public class JSONImportWizard extends JDialog {
if (value == null) {
label.setText("none");
} else {
if (includeType && ((GameDataElement)value).getDataType() != null) {
label.setText(((GameDataElement)value).getDataType().toString()+"/"+((GameDataElement)value).getDesc());
if (includeType && ((GameDataElement) value).getDataType() != null) {
label.setText(((GameDataElement) value).getDataType().toString() + "/" + ((GameDataElement) value).getDesc());
} else {
label.setText(((GameDataElement)value).getDesc());
label.setText(((GameDataElement) value).getDesc());
}
switch ((DataType)dataTypeCombo.getSelectedItem()) {
switch ((DataType) dataTypeCombo.getSelectedItem()) {
case actorCondition:
label.setIcon(new ImageIcon(proj.getIcon(((ActorCondition)value).icon_id)));
label.setIcon(new ImageIcon(proj.getIcon(((ActorCondition) value).icon_id)));
break;
case item:
label.setIcon(new ImageIcon(proj.getIcon(((Item)value).icon_id)));
label.setIcon(new ImageIcon(proj.getIcon(((Item) value).icon_id)));
break;
case npc:
label.setIcon(new ImageIcon(proj.getIcon(((NPC)value).icon_id)));
label.setIcon(new ImageIcon(proj.getIcon(((NPC) value).icon_id)));
break;
case dialogue:
label.setIcon(new ImageIcon(((Dialogue)value).getIcon()));
label.setIcon(new ImageIcon(((Dialogue) value).getIcon()));
break;
case droplist:
label.setIcon(new ImageIcon(((Droplist)value).getIcon()));
label.setIcon(new ImageIcon(((Droplist) value).getIcon()));
break;
case itemCategory:
label.setIcon(new ImageIcon(((ItemCategory)value).getIcon()));
label.setIcon(new ImageIcon(((ItemCategory) value).getIcon()));
break;
case quest:
label.setIcon(new ImageIcon(((Quest)value).getIcon()));
label.setIcon(new ImageIcon(((Quest) value).getIcon()));
break;
default:
Notification.addError("Unable to find icon for "+((GameDataElement)value).getDesc());
Notification.addError("Unable to find icon for " + ((GameDataElement) value).getDesc());
}
}
return label;
@@ -559,11 +532,12 @@ public class JSONImportWizard extends JDialog {
public static class ErrorRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = -4265342800284721660L;
@Override
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
((JLabel)c).setIcon(NotificationsPane.icons.get(Notification.Type.ERROR));
((JLabel) c).setIcon(NotificationsPane.icons.get(Notification.Type.ERROR));
}
return c;
}
@@ -572,18 +546,19 @@ public class JSONImportWizard extends JDialog {
public static class WarningRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = -3836045237946111606L;
@Override
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
((JLabel)c).setIcon(NotificationsPane.icons.get(Notification.Type.WARN));
((JLabel) c).setIcon(NotificationsPane.icons.get(Notification.Type.WARN));
}
return c;
}
}
@SuppressWarnings("rawtypes")
public static class GDEListModel implements ListModel {
public static class GDEListModel implements ListenerCollectionModel {
List<? extends Object> source;
@@ -592,35 +567,15 @@ public class JSONImportWizard extends JDialog {
}
@Override
public int getSize() {
return source.size();
}
@Override
public Object getElementAt(int index) {
for (Object obj : source) {
if (index == 0) return obj;
index --;
}
return null;
public Collection getElements() {
return source;
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
}
public void fireListChanged() {
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, this.getSize()));
}
public List<ListDataListener> getListeners() {
return listeners;
}
}
@@ -671,28 +626,28 @@ public class JSONImportWizard extends JDialog {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
((JLabel)c).setText(dataTypeDesc((DataType) value));
switch ((DataType)value) {
((JLabel) c).setText(dataTypeDesc((DataType) value));
switch ((DataType) value) {
case actorCondition:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getActorConditionIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getActorConditionIcon()));
break;
case dialogue:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getDialogueIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getDialogueIcon()));
break;
case droplist:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getDroplistIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getDroplistIcon()));
break;
case item:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getItemIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getItemIcon()));
break;
case itemCategory:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getDroplistIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getDroplistIcon()));
break;
case npc:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getNPCIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getNPCIcon()));
break;
case quest:
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getQuestIcon()));
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getQuestIcon()));
break;
default:
break;

View File

@@ -0,0 +1,24 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.util.Collection;
public interface ListenerCollectionModel<E> extends ListenerListModel<E> {
public Collection<E> getElements();
@Override
default int getSize() {
Collection<E> elements = getElements();
if (elements == null) return 0;
return elements.size();
}
@Override
default E getElementAt(int index) {
for (E obj : getElements()) {
if (index == 0) return obj;
index--;
}
return null;
}
}

View File

@@ -0,0 +1,67 @@
package com.gpl.rpg.atcontentstudio.ui;
import javax.swing.*;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import java.util.List;
public interface ListenerListModel<E> extends ListModel<E> {
List<ListDataListener> getListeners();
default void notifyListeners(ChangeType event, int index0, int index1) {
notifyListeners(this, event, index0, index1);
}
default void notifyListeners(Object source, ChangeType event, int index0, int index1) {
int eventCode;
switch (event) {
case CHANGED:
eventCode = ListDataEvent.CONTENTS_CHANGED;
break;
case ADDED:
eventCode = ListDataEvent.INTERVAL_ADDED;
break;
case REMOVED:
eventCode = ListDataEvent.INTERVAL_REMOVED;
break;
default:
throw new IllegalArgumentException();
}
for (ListDataListener l : getListeners()) {
ListDataEvent e = new ListDataEvent(source, eventCode, index0, index1);
switch (event) {
case CHANGED: {
l.contentsChanged(e);
break;
}
case ADDED: {
l.intervalAdded(e);
break;
}
case REMOVED: {
l.intervalRemoved(e);
break;
}
}
}
}
default void addListDataListener(ListDataListener l) {
getListeners().add(l);
}
default void removeListDataListener(ListDataListener l) {
getListeners().remove(l);
}
default void fireListChanged() {
notifyListeners(this, ChangeType.CHANGED, 0, getSize() - 1);
}
enum ChangeType {
CHANGED,
ADDED,
REMOVED,
}
}

View File

@@ -1,27 +1,17 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.NotificationListener;
import javax.swing.*;
import javax.swing.event.ListDataListener;
import java.awt.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
@SuppressWarnings("rawtypes")
public class NotificationsPane extends JList {
@@ -43,19 +33,19 @@ public class NotificationsPane extends JList {
super();
MyListModel model = new MyListModel();
setModel(model);
setCellRenderer(new ListCellRenderer(){
setCellRenderer(new ListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JLabel label = new JLabel();
Font f = label.getFont();
label.setIcon(NotificationsPane.icons.get(((Notification)value).type));
label.setText(((Notification)value).text);
label.setIcon(NotificationsPane.icons.get(((Notification) value).type));
label.setText(((Notification) value).text);
if (isSelected) {
// label.setBackground(Color.RED);
label.setBorder(BorderFactory.createLineBorder(Color.BLUE));
// label.setForeground(Color.WHITE);
}
f = f.deriveFont(10f*ATContentStudio.SCALING);
f = f.deriveFont(10f * ATContentStudio.SCALING);
label.setFont(f);
return label;
}
@@ -64,13 +54,18 @@ public class NotificationsPane extends JList {
}
private class MyListModel implements ListModel, NotificationListener {
private class MyListModel implements ListenerListModel<Notification>, NotificationListener {
@Override
public Object getElementAt(int index) {
public Notification getElementAt(int index) {
return Notification.notifs.get(index);
}
@Override
public List<ListDataListener> getListeners() {
return listeners;
}
@Override
public int getSize() {
return Notification.notifs.size();
@@ -78,28 +73,15 @@ public class NotificationsPane extends JList {
@Override
public void onNewNotification(Notification n) {
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(NotificationsPane.this, ListDataEvent.INTERVAL_ADDED, Notification.notifs.size() - 1 , Notification.notifs.size() - 1));
}
notifyListeners(NotificationsPane.this, ChangeType.ADDED, Notification.notifs.size() - 1, Notification.notifs.size() - 1);
NotificationsPane.this.ensureIndexIsVisible(Notification.notifs.indexOf(n));
}
@Override
public void onListCleared(int i) {
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(NotificationsPane.this, ListDataEvent.INTERVAL_REMOVED, 0 , i));
}
notifyListeners(NotificationsPane.this, ChangeType.REMOVED, 0, i);
}
private List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
}
}
}

View File

@@ -0,0 +1,93 @@
package com.gpl.rpg.atcontentstudio.ui;
import javax.swing.event.ListDataListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public abstract class OrderedListenerListModel<S, E> implements ListenerCollectionModel<E> {
protected S source;
protected abstract List<E> getItems();
protected abstract void setItems(List<E> items);
public OrderedListenerListModel(S source) {
this.source = source;
}
@Override
public Collection<E> getElements() {
return getItems();
}
@Override
public E getElementAt(int index) {
if (index < 0 || index >= getSize()) return null;
return getItems().get(index);
}
public E setElementAt(int index, E value) {
if (index < 0 || index >= getSize()) return null;
return getItems().set(index, value);
}
public void addObject(E item) {
addItem(item);
}
public void addItem(E item) {
if (getItems() == null) {
setItems(new ArrayList<E>());
}
getItems().add(item);
int index = getItems().indexOf(item);
notifyListeners(ChangeType.ADDED, index, index);
}
public void removeObject(E item) {
removeItem(item);
}
public void removeItem(E item) {
int index = getItems().indexOf(item);
getItems().remove(item);
if (getSize() == 0) {
setItems(null);
}
notifyListeners(this, ChangeType.REMOVED, index, index);
}
public void moveUp(E item) {
moveUpOrDown(item, -1);
}
public void moveDown(E item) {
moveUpOrDown(item, 1);
}
private void moveUpOrDown(E item, int direction) {
int index = getItems().indexOf(item);
E exchanged = getElementAt(index + direction);
setElementAt(index, exchanged);
setElementAt(index + direction, item);
notifyListeners(this, ChangeType.CHANGED, index + direction, index);
}
public void objectChanged(E item) {
itemChanged(item);
}
public void itemChanged(E item) {
int index = getItems().indexOf(item);
notifyListeners(this, ChangeType.CHANGED, index, index);
}
private final List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
public List<ListDataListener> getListeners() {
return listeners;
}
}

View File

@@ -1,10 +1,7 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.Icon;
import javax.swing.*;
import java.awt.*;
public class OverlayIcon implements Icon {

View File

@@ -1,31 +1,5 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.ComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListDataListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.Project.ResourceSet;
@@ -34,6 +8,18 @@ import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
import com.gpl.rpg.atcontentstudio.model.sprites.SpriteSheetSet;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListDataListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class ProjectCreationWizard extends JDialog {
private static final long serialVersionUID = -2854969975146867119L;
@@ -118,10 +104,12 @@ public class ProjectCreationWizard extends JDialog {
public void removeUpdate(DocumentEvent e) {
updateOkButtonEnablement();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateOkButtonEnablement();
}
@Override
public void changedUpdate(DocumentEvent e) {
updateOkButtonEnablement();
@@ -142,8 +130,8 @@ public class ProjectCreationWizard extends JDialog {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
boolean keepTrying = true;
if (atSourceSelectionCombo.getSelectedItem() != null && ((String)atSourceSelectionCombo.getSelectedItem()).length() > 0) {
File f = new File((String)atSourceSelectionCombo.getSelectedItem());
if (atSourceSelectionCombo.getSelectedItem() != null && ((String) atSourceSelectionCombo.getSelectedItem()).length() > 0) {
File f = new File((String) atSourceSelectionCombo.getSelectedItem());
if (f.exists()) {
chooser.setCurrentDirectory(f);
keepTrying = false;
@@ -168,7 +156,7 @@ public class ProjectCreationWizard extends JDialog {
if (!Workspace.activeWorkspace.knownMapSourcesFolders.contains(atSourceFolder)) {
Workspace.activeWorkspace.knownMapSourcesFolders.add(atSourceFolder);
}
Workspace.createProject(projectNameField.getText(), atSourceFolder, (Project.ResourceSet)resourceSetToUse.getSelectedItem());
Workspace.createProject(projectNameField.getText(), atSourceFolder, (Project.ResourceSet) resourceSetToUse.getSelectedItem());
ProjectCreationWizard.this.dispose();
}
});
@@ -182,7 +170,7 @@ public class ProjectCreationWizard extends JDialog {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints c =new GridBagConstraints();
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTHWEST;
c.fill = GridBagConstraints.BOTH;
@@ -234,8 +222,6 @@ public class ProjectCreationWizard extends JDialog {
buttonPane.setLayout(new GridBagLayout());
GridBagConstraints c2 = new GridBagConstraints();
c2.fill = GridBagConstraints.HORIZONTAL;
c2.gridx = 1;
c2.weightx = 80;
c2.gridx = 1;
c2.weightx = 80;
@@ -262,7 +248,7 @@ public class ProjectCreationWizard extends JDialog {
pack();
Dimension sdim = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wdim = getSize();
setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
setLocation((sdim.width - wdim.width) / 2, (sdim.height - wdim.height) / 2);
}
@@ -272,12 +258,12 @@ public class ProjectCreationWizard extends JDialog {
this.okButton.setEnabled(false);
return;
}
if (atSourceSelectionCombo.getSelectedItem() == null || ((String)atSourceSelectionCombo.getSelectedItem()).length() <= 0) {
if (atSourceSelectionCombo.getSelectedItem() == null || ((String) atSourceSelectionCombo.getSelectedItem()).length() <= 0) {
errorLabel.setText("<html><font color=\"#FF0000\">Select an AT source root folder.</font></html>");
this.okButton.setEnabled(false);
return;
}
File projFolder = new File(Workspace.activeWorkspace.baseFolder, projectNameField.getText()+File.separator);
File projFolder = new File(Workspace.activeWorkspace.baseFolder, projectNameField.getText() + File.separator);
File sourceFolder = new File((String) atSourceSelectionCombo.getSelectedItem());
if (projFolder.exists()) {
errorLabel.setText("<html><font color=\"#FF0000\">A project with this name already exists.</font></html>");
@@ -287,7 +273,7 @@ public class ProjectCreationWizard extends JDialog {
try {
projFolder.getCanonicalPath();
} catch (IOException ioe) {
errorLabel.setText("<html><font color=\"#FF0000\">"+projectNameField.getText()+" is not a valid project name.</font></html>");
errorLabel.setText("<html><font color=\"#FF0000\">" + projectNameField.getText() + " is not a valid project name.</font></html>");
this.okButton.setEnabled(false);
return;
}

View File

@@ -1,34 +1,5 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.JTree;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import com.gpl.rpg.andorstrainer.AndorsTrainer;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
@@ -42,6 +13,21 @@ import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
import com.jidesoft.swing.TreeSearchable;
import javax.swing.*;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class ProjectsTree extends JPanel {
private static final long serialVersionUID = 6332593891796576708L;
@@ -60,10 +46,10 @@ public class ProjectsTree extends JPanel {
super();
setLayout(new BorderLayout());
projectsTree = new JTree(new ProjectsTreeModel());
new TreeSearchable(projectsTree){
new TreeSearchable(projectsTree) {
@Override
protected String convertElementToString(Object object) {
return ((ProjectTreeNode)((TreePath)object).getLastPathComponent()).getDesc();
return ((ProjectTreeNode) ((TreePath) object).getLastPathComponent()).getDesc();
}
};
add(projectsTree, BorderLayout.CENTER);
@@ -107,7 +93,7 @@ public class ProjectsTree extends JPanel {
if (e.isPopupTrigger()) {
popupActivated(e);
} else if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
TreePath path = projectsTree.getPathForLocation (e.getX(), e.getY());
TreePath path = projectsTree.getPathForLocation(e.getX(), e.getY());
projectsTree.setSelectionPath(path);
if (path != null) {
itemAction((ProjectTreeNode) path.getLastPathComponent());
@@ -567,7 +553,7 @@ public class ProjectsTree extends JPanel {
}
public void popupActivated(MouseEvent e) {
TreePath path = projectsTree.getPathForLocation (e.getX(), e.getY());
TreePath path = projectsTree.getPathForLocation(e.getX(), e.getY());
TreePath[] allSelected = projectsTree.getSelectionPaths();
boolean selectClickedItem = true;
if (allSelected != null) {
@@ -587,20 +573,20 @@ public class ProjectsTree extends JPanel {
public void itemAction(ProjectTreeNode node) {
if (node instanceof JSONElement) {
ATContentStudio.frame.openEditor((JSONElement)node);
ATContentStudio.frame.openEditor((JSONElement) node);
} else if (node instanceof Spritesheet) {
ATContentStudio.frame.openEditor((Spritesheet)node);
ATContentStudio.frame.openEditor((Spritesheet) node);
} else if (node instanceof TMXMap) {
ATContentStudio.frame.openEditor((TMXMap)node);
ATContentStudio.frame.openEditor((TMXMap) node);
} else if (node instanceof WorldmapSegment) {
ATContentStudio.frame.openEditor((WorldmapSegment)node);
ATContentStudio.frame.openEditor((WorldmapSegment) node);
} else if (node instanceof WriterModeData) {
ATContentStudio.frame.openEditor((WriterModeData)node);
ATContentStudio.frame.openEditor((WriterModeData) node);
} else if (node instanceof BookmarkEntry) {
ATContentStudio.frame.openEditor(((BookmarkEntry)node).bookmarkedElement);
ATContentStudio.frame.openEditor(((BookmarkEntry) node).bookmarkedElement);
} else if (node instanceof SavedGame) {
if (konamiCodeEntered) {
ATContentStudio.frame.openEditor((SavedGame)node);
ATContentStudio.frame.openEditor((SavedGame) node);
}
}
}
@@ -618,17 +604,17 @@ public class ProjectsTree extends JPanel {
@Override
public Object getChild(Object parent, int index) {
return ((ProjectTreeNode)parent).getChildAt(index);
return ((ProjectTreeNode) parent).getChildAt(index);
}
@Override
public int getChildCount(Object parent) {
return ((ProjectTreeNode)parent).getChildCount();
return ((ProjectTreeNode) parent).getChildCount();
}
@Override
public boolean isLeaf(Object node) {
return ((ProjectTreeNode)node).isLeaf();
return ((ProjectTreeNode) node).isLeaf();
}
@Override
@@ -638,25 +624,31 @@ public class ProjectsTree extends JPanel {
public void insertNode(TreePath node) {
for (TreeModelListener l : listeners) {
l.treeNodesInserted(new TreeModelEvent(node.getLastPathComponent(), node.getParentPath().getPath(), new int[]{((ProjectTreeNode)node.getParentPath().getLastPathComponent()).getIndex((ProjectTreeNode)node.getLastPathComponent())}, new Object[]{node.getLastPathComponent()} ));
l.treeNodesInserted(new TreeModelEvent(node.getLastPathComponent(), node.getParentPath().getPath(),
new int[]{((ProjectTreeNode) node.getParentPath().getLastPathComponent()).getIndex((ProjectTreeNode) node.getLastPathComponent())},
new Object[]{node.getLastPathComponent()}));
}
}
public void changeNode(TreePath node) {
for (TreeModelListener l : listeners) {
l.treeNodesChanged(new TreeModelEvent(node.getLastPathComponent(), node.getParentPath(), new int[]{((ProjectTreeNode)node.getParentPath().getLastPathComponent()).getIndex((ProjectTreeNode)node.getLastPathComponent())}, new Object[]{node.getLastPathComponent()} ));
l.treeNodesChanged(new TreeModelEvent(node.getLastPathComponent(), node.getParentPath(),
new int[]{((ProjectTreeNode) node.getParentPath().getLastPathComponent()).getIndex((ProjectTreeNode) node.getLastPathComponent())},
new Object[]{node.getLastPathComponent()}));
}
}
public void removeNode(TreePath node) {
for (TreeModelListener l : listeners) {
l.treeNodesRemoved(new TreeModelEvent(node.getLastPathComponent(), node.getParentPath(), new int[]{((ProjectTreeNode)node.getParentPath().getLastPathComponent()).getIndex((ProjectTreeNode)node.getLastPathComponent())}, new Object[]{node.getLastPathComponent()} ));
l.treeNodesRemoved(new TreeModelEvent(node.getLastPathComponent(), node.getParentPath(),
new int[]{((ProjectTreeNode) node.getParentPath().getLastPathComponent()).getIndex((ProjectTreeNode) node.getLastPathComponent())},
new Object[]{node.getLastPathComponent()}));
}
}
@Override
public int getIndexOfChild(Object parent, Object child) {
return ((ProjectTreeNode)parent).getIndex((ProjectTreeNode) child);
return ((ProjectTreeNode) parent).getIndex((ProjectTreeNode) child);
}
List<TreeModelListener> listeners = new CopyOnWriteArrayList<TreeModelListener>();
@@ -682,13 +674,13 @@ public class ProjectsTree extends JPanel {
Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel)c;
String text = ((ProjectTreeNode)value).getDesc();
JLabel label = (JLabel) c;
String text = ((ProjectTreeNode) value).getDesc();
if (text != null) label.setText(text);
Image img = null;
if (leaf) img = ((ProjectTreeNode)value).getLeafIcon();
else if (expanded) img = ((ProjectTreeNode)value).getOpenIcon();
else img = ((ProjectTreeNode)value).getClosedIcon();
Image img;
if (leaf) img = ((ProjectTreeNode) value).getLeafIcon();
else if (expanded) img = ((ProjectTreeNode) value).getOpenIcon();
else img = ((ProjectTreeNode) value).getClosedIcon();
if (img != null) {
label.setIcon(new ImageIcon(img));
@@ -721,7 +713,8 @@ public class ProjectsTree extends JPanel {
while (!exit && timeout > 0) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {}
} catch (InterruptedException e) {
}
timeout -= 10;
}
konamiTimeout = null;

View File

@@ -1,27 +1,5 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
@@ -29,6 +7,14 @@ import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.List;
import java.util.*;
public class SaveItemsWizard extends JDialog {
private static final long serialVersionUID = -3301878024575930527L;
@@ -43,7 +29,7 @@ public class SaveItemsWizard extends JDialog {
JList willBeSaved;
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public SaveItemsWizard(List<SaveEvent> events, GameDataElement originalRequester) {
super(ATContentStudio.frame);
this.events = events;
@@ -77,7 +63,7 @@ public class SaveItemsWizard extends JDialog {
pane.add(new JLabel(" While trying to save: "), JideBoxLayout.FIX);
JLabel origItemDesc = new JLabel();
origItemDesc.setIcon(new ImageIcon(originalRequester.getIcon()));
origItemDesc.setText(originalRequester.getDataType().toString()+"/"+originalRequester.id);
origItemDesc.setText(originalRequester.getDataType().toString() + "/" + originalRequester.id);
pane.add(origItemDesc, JideBoxLayout.FIX);
pane.add(new JLabel(" the following errors have been encountered and must be corrected before saving can occur: "), JideBoxLayout.FIX);
} else {
@@ -119,7 +105,7 @@ public class SaveItemsWizard extends JDialog {
pane.add(new JLabel(" While trying to save: "), JideBoxLayout.FIX);
JLabel origItemDesc = new JLabel();
origItemDesc.setIcon(new ImageIcon(originalRequester.getIcon()));
origItemDesc.setText(originalRequester.getDataType().toString()+"/"+originalRequester.id);
origItemDesc.setText(originalRequester.getDataType().toString() + "/" + originalRequester.id);
pane.add(origItemDesc, JideBoxLayout.FIX);
pane.add(new JLabel(" the following side-effects have been identified and must be applied to the project before saving: "), JideBoxLayout.FIX);
} else {
@@ -180,43 +166,43 @@ public class SaveItemsWizard extends JDialog {
Map<GameDataCategory<JSONElement>, Set<File>> jsonToSave = new IdentityHashMap<GameDataCategory<JSONElement>, Set<File>>();
for (SaveEvent event : movedToCreatedList) {
if (event.target instanceof JSONElement) {
if (!jsonToSave.containsKey(event.target.getParent())){
if (!jsonToSave.containsKey(event.target.getParent())) {
jsonToSave.put((GameDataCategory<JSONElement>) event.target.getParent(), new HashSet<File>());
}
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement)event.target).jsonFile);
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement) event.target).jsonFile);
event.target.getProject().moveToCreated((JSONElement) event.target);
if (!jsonToSave.containsKey(event.target.getParent())){
if (!jsonToSave.containsKey(event.target.getParent())) {
jsonToSave.put((GameDataCategory<JSONElement>) event.target.getParent(), new HashSet<File>());
}
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement)event.target).jsonFile);
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement) event.target).jsonFile);
}
//TODO movable maps, when ID is editable.
}
for (SaveEvent event : movedToAlteredList) {
if (event.target instanceof JSONElement) {
if (!jsonToSave.containsKey(event.target.getParent())){
if (!jsonToSave.containsKey(event.target.getParent())) {
jsonToSave.put((GameDataCategory<JSONElement>) event.target.getParent(), new HashSet<File>());
}
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement)event.target).jsonFile);
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement) event.target).jsonFile);
event.target.getProject().moveToAltered((JSONElement) event.target);
if (!jsonToSave.containsKey(event.target.getParent())){
if (!jsonToSave.containsKey(event.target.getParent())) {
jsonToSave.put((GameDataCategory<JSONElement>) event.target.getParent(), new HashSet<File>());
}
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement)event.target).jsonFile);
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement) event.target).jsonFile);
}
//TODO movable maps, when ID is editable.
}
for (SaveEvent event : alsoSavedList) {
if (event.target instanceof JSONElement) {
if (!jsonToSave.containsKey(event.target.getParent())){
if (!jsonToSave.containsKey(event.target.getParent())) {
jsonToSave.put((GameDataCategory<JSONElement>) event.target.getParent(), new HashSet<File>());
}
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement)event.target).jsonFile);
jsonToSave.get((GameDataCategory<JSONElement>) event.target.getParent()).add(((JSONElement) event.target).jsonFile);
}
}
@@ -261,9 +247,9 @@ public class SaveItemsWizard extends JDialog {
SaveEvent event = (SaveEvent) value;
label.setIcon(new ImageIcon(event.target.getIcon()));
if (event.error) {
label.setText(event.target.getDataType().toString()+"/"+event.target.id+": "+event.errorText);
label.setText(event.target.getDataType().toString() + "/" + event.target.id + ": " + event.errorText);
} else {
label.setText(event.target.getDataType().toString()+"/"+event.target.id);
label.setText(event.target.getDataType().toString() + "/" + event.target.id);
}
}
return c;

View File

@@ -1,30 +1,21 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import javax.swing.JPanel;
import javax.swing.JViewport;
import javax.swing.Scrollable;
import javax.swing.SwingConstants;
import javax.swing.*;
import java.awt.*;
public class ScrollablePanel extends JPanel implements Scrollable, SwingConstants {
private static final long serialVersionUID = 6498229143202972325L;
public enum ScrollableSizeHint
{
public enum ScrollableSizeHint {
NONE,
FIT,
STRETCH;
STRETCH
}
public enum IncrementType
{
public enum IncrementType {
PERCENT,
PIXELS;
PIXELS
}
private ScrollableSizeHint scrollableHeight = ScrollableSizeHint.NONE;
@@ -38,9 +29,8 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
/**
* Default constructor that uses a FlowLayout
*/
public ScrollablePanel()
{
this( new FlowLayout() );
public ScrollablePanel() {
this(new FlowLayout());
}
/**
@@ -48,9 +38,8 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
*
* @param layout the LayountManger for the panel
*/
public ScrollablePanel(LayoutManager layout)
{
super( layout );
public ScrollablePanel(LayoutManager layout) {
super(layout);
IncrementInfo block = new IncrementInfo(IncrementType.PERCENT, 100);
IncrementInfo unit = new IncrementInfo(IncrementType.PERCENT, 10);
@@ -66,8 +55,7 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
*
* @return the ScrollableSizeHint enum for the height
*/
public ScrollableSizeHint getScrollableHeight()
{
public ScrollableSizeHint getScrollableHeight() {
return scrollableHeight;
}
@@ -75,7 +63,7 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
* Set the ScrollableSizeHint enum for the height. The enum is used to
* determine the boolean value that is returned by the
* getScrollableTracksViewportHeight() method. The valid values are:
*
* <p>
* ScrollableSizeHint.NONE - return "false", which causes the height
* of the panel to be used when laying out the children
* ScrollableSizeHint.FIT - return "true", which causes the height of
@@ -85,8 +73,7 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
*
* @param scrollableHeight as represented by the ScrollableSizeHint enum.
*/
public void setScrollableHeight(ScrollableSizeHint scrollableHeight)
{
public void setScrollableHeight(ScrollableSizeHint scrollableHeight) {
this.scrollableHeight = scrollableHeight;
revalidate();
}
@@ -96,8 +83,7 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
*
* @return the ScrollableSizeHint enum for the width
*/
public ScrollableSizeHint getScrollableWidth()
{
public ScrollableSizeHint getScrollableWidth() {
return scrollableWidth;
}
@@ -105,7 +91,7 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
* Set the ScrollableSizeHint enum for the width. The enum is used to
* determine the boolean value that is returned by the
* getScrollableTracksViewportWidth() method. The valid values are:
*
* <p>
* ScrollableSizeHint.NONE - return "false", which causes the width
* of the panel to be used when laying out the children
* ScrollableSizeHint.FIT - return "true", which causes the width of
@@ -115,8 +101,7 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
*
* @param scrollableWidth as represented by the ScrollableSizeHint enum.
*/
public void setScrollableWidth(ScrollableSizeHint scrollableWidth)
{
public void setScrollableWidth(ScrollableSizeHint scrollableWidth) {
this.scrollableWidth = scrollableWidth;
revalidate();
}
@@ -126,8 +111,7 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
*
* @return the block IncrementInfo for the specified orientation
*/
public IncrementInfo getScrollableBlockIncrement(int orientation)
{
public IncrementInfo getScrollableBlockIncrement(int orientation) {
return orientation == SwingConstants.HORIZONTAL ? horizontalBlock : verticalBlock;
}
@@ -136,15 +120,14 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
*
* @param orientation specify the scrolling orientation. Must be either:
* SwingContants.HORIZONTAL or SwingContants.VERTICAL.
* @param amount a value used with the IncrementType to determine the
* scrollable amount
* @paran type specify how the amount parameter in the calculation of
* the scrollable amount. Valid values are:
* IncrementType.PERCENT - treat the amount as a % of the viewport size
* IncrementType.PIXEL - treat the amount as the scrollable amount
* @param amount a value used with the IncrementType to determine the
* scrollable amount
*/
public void setScrollableBlockIncrement(int orientation, IncrementType type, int amount)
{
public void setScrollableBlockIncrement(int orientation, IncrementType type, int amount) {
IncrementInfo info = new IncrementInfo(type, amount);
setScrollableBlockIncrement(orientation, info);
}
@@ -157,10 +140,8 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
* @param info An IncrementInfo object containing information of how to
* calculate the scrollable amount.
*/
public void setScrollableBlockIncrement(int orientation, IncrementInfo info)
{
switch(orientation)
{
public void setScrollableBlockIncrement(int orientation, IncrementInfo info) {
switch (orientation) {
case SwingConstants.HORIZONTAL:
horizontalBlock = info;
break;
@@ -177,8 +158,7 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
*
* @return the unit IncrementInfo for the specified orientation
*/
public IncrementInfo getScrollableUnitIncrement(int orientation)
{
public IncrementInfo getScrollableUnitIncrement(int orientation) {
return orientation == SwingConstants.HORIZONTAL ? horizontalUnit : verticalUnit;
}
@@ -187,15 +167,14 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
*
* @param orientation specify the scrolling orientation. Must be either:
* SwingContants.HORIZONTAL or SwingContants.VERTICAL.
* @param amount a value used with the IncrementType to determine the
* scrollable amount
* @paran type specify how the amount parameter in the calculation of
* the scrollable amount. Valid values are:
* IncrementType.PERCENT - treat the amount as a % of the viewport size
* IncrementType.PIXEL - treat the amount as the scrollable amount
* @param amount a value used with the IncrementType to determine the
* scrollable amount
*/
public void setScrollableUnitIncrement(int orientation, IncrementType type, int amount)
{
public void setScrollableUnitIncrement(int orientation, IncrementType type, int amount) {
IncrementInfo info = new IncrementInfo(type, amount);
setScrollableUnitIncrement(orientation, info);
}
@@ -208,10 +187,8 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
* @param info An IncrementInfo object containing information of how to
* calculate the scrollable amount.
*/
public void setScrollableUnitIncrement(int orientation, IncrementInfo info)
{
switch(orientation)
{
public void setScrollableUnitIncrement(int orientation, IncrementInfo info) {
switch (orientation) {
case SwingConstants.HORIZONTAL:
horizontalUnit = info;
break;
@@ -225,16 +202,13 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
//Implement Scrollable interface
public Dimension getPreferredScrollableViewportSize()
{
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
public int getScrollableUnitIncrement(
Rectangle visible, int orientation, int direction)
{
switch(orientation)
{
Rectangle visible, int orientation, int direction) {
switch (orientation) {
case SwingConstants.HORIZONTAL:
return getScrollableIncrement(horizontalUnit, visible.width);
case SwingConstants.VERTICAL:
@@ -245,10 +219,8 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
}
public int getScrollableBlockIncrement(
Rectangle visible, int orientation, int direction)
{
switch(orientation)
{
Rectangle visible, int orientation, int direction) {
switch (orientation) {
case SwingConstants.HORIZONTAL:
return getScrollableIncrement(horizontalBlock, visible.width);
case SwingConstants.VERTICAL:
@@ -258,16 +230,14 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
}
}
protected int getScrollableIncrement(IncrementInfo info, int distance)
{
protected int getScrollableIncrement(IncrementInfo info, int distance) {
if (info.getIncrement() == IncrementType.PIXELS)
return info.getAmount();
else
return distance * info.getAmount() / 100;
}
public boolean getScrollableTracksViewportWidth()
{
public boolean getScrollableTracksViewportWidth() {
if (scrollableWidth == ScrollableSizeHint.NONE)
return false;
@@ -276,16 +246,14 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
// STRETCH sizing, use the greater of the panel or viewport width
if (getParent() instanceof JViewport)
{
return (((JViewport)getParent()).getWidth() > getPreferredSize().width);
if (getParent() instanceof JViewport) {
return (((JViewport) getParent()).getWidth() > getPreferredSize().width);
}
return false;
}
public boolean getScrollableTracksViewportHeight()
{
public boolean getScrollableTracksViewportHeight() {
if (scrollableHeight == ScrollableSizeHint.NONE)
return false;
@@ -295,9 +263,8 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
// STRETCH sizing, use the greater of the panel or viewport height
if (getParent() instanceof JViewport)
{
return (((JViewport)getParent()).getHeight() > getPreferredSize().height);
if (getParent() instanceof JViewport) {
return (((JViewport) getParent()).getHeight() > getPreferredSize().height);
}
return false;
@@ -306,29 +273,24 @@ public class ScrollablePanel extends JPanel implements Scrollable, SwingConstant
/**
* Helper class to hold the information required to calculate the scroll amount.
*/
static class IncrementInfo
{
static class IncrementInfo {
private IncrementType type;
private int amount;
public IncrementInfo(IncrementType type, int amount)
{
public IncrementInfo(IncrementType type, int amount) {
this.type = type;
this.amount = amount;
}
public IncrementType getIncrement()
{
public IncrementType getIncrement() {
return type;
}
public int getAmount()
{
public int getAmount() {
return amount;
}
public String toString()
{
public String toString() {
return
"ScrollablePanel[" +
type + ", " +

View File

@@ -1,29 +1,5 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.ConfigCache;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
@@ -36,6 +12,14 @@ import com.gpl.rpg.atcontentstudio.model.saves.SavedGame;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
public class StudioFrame extends JFrame {
private static final long serialVersionUID = -3391514100319186661L;
@@ -158,7 +142,7 @@ public class StudioFrame extends JFrame {
JMenu viewMenu = new JMenu("View");
JMenu changeLaF = new JMenu("Change Look and Feel");
for (final LookAndFeelInfo i : UIManager.getInstalledLookAndFeels()) {
final JMenuItem lafItem = new JMenuItem("Switch to "+i.getName());
final JMenuItem lafItem = new JMenuItem("Switch to " + i.getName());
changeLaF.add(lafItem);
lafItem.addActionListener(new ActionListener() {
@Override
@@ -254,5 +238,4 @@ public class StudioFrame extends JFrame {
}
}

View File

@@ -1,31 +1,5 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListDataListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement.State;
import com.gpl.rpg.atcontentstudio.model.GameSource;
@@ -33,6 +7,17 @@ import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListDataListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class TMXMapCreationWizard extends JDialog {
private static final long serialVersionUID = -474689694453543575L;
@@ -49,11 +34,11 @@ public class TMXMapCreationWizard extends JDialog {
final JButton ok;
final Project proj;
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public TMXMapCreationWizard(final Project proj) {
super(ATContentStudio.frame);
this.proj = proj;
templateFile=new File(proj.baseContent.gameMaps.mapFolder, DEFAULT_TEMPLATE);
templateFile = new File(proj.baseContent.gameMaps.mapFolder, DEFAULT_TEMPLATE);
setTitle("Create new TMX map");
@@ -74,7 +59,7 @@ public class TMXMapCreationWizard extends JDialog {
idPane.add(idField, BorderLayout.CENTER);
pane.add(idPane, JideBoxLayout.FIX);
useTemplate = new JRadioButton("Use default template file ("+DEFAULT_TEMPLATE+")");
useTemplate = new JRadioButton("Use default template file (" + DEFAULT_TEMPLATE + ")");
useTemplate.setToolTipText(templateFile.getAbsolutePath());
pane.add(useTemplate, JideBoxLayout.FIX);
copyMap = new JRadioButton("Copy existing map");
@@ -102,7 +87,7 @@ public class TMXMapCreationWizard extends JDialog {
} else {
useTemplate.setSelected(false);
useTemplate.setEnabled(false);
useTemplate.setToolTipText("Cannot find file "+templateFile.getAbsolutePath());
useTemplate.setToolTipText("Cannot find file " + templateFile.getAbsolutePath());
templateCombo.setEnabled(true);
copyMap.setSelected(true);
}
@@ -113,7 +98,7 @@ public class TMXMapCreationWizard extends JDialog {
public void actionPerformed(ActionEvent e) {
if (useTemplate.isSelected()) {
templateCombo.setEnabled(false);
} else if(copyMap.isSelected()) {
} else if (copyMap.isSelected()) {
templateCombo.setEnabled(true);
}
updateStatus();
@@ -146,13 +131,13 @@ public class TMXMapCreationWizard extends JDialog {
public void actionPerformed(ActionEvent e) {
if (copyMap.isSelected()) {
creation = ((TMXMap)templateCombo.getSelectedItem()).clone();
creation = ((TMXMap) templateCombo.getSelectedItem()).clone();
} else if (useTemplate.isSelected()) {
creation = new TMXMap(proj.createdContent.gameMaps, templateFile);
creation.parse();
}
creation.id = idField.getText();
creation.tmxFile = new File(creation.id+".tmx");
creation.tmxFile = new File(creation.id + ".tmx");
TMXMapCreationWizard.this.setVisible(false);
TMXMapCreationWizard.this.dispose();
creation.state = State.created;
@@ -177,10 +162,12 @@ public class TMXMapCreationWizard extends JDialog {
public void removeUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void changedUpdate(DocumentEvent e) {
updateStatus();
@@ -191,13 +178,13 @@ public class TMXMapCreationWizard extends JDialog {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(pane, BorderLayout.CENTER);
setMinimumSize(new Dimension(350,250));
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);
setLocation((sdim.width - wdim.width) / 2, (sdim.height - wdim.height) / 2);
}
public void updateStatus() {
@@ -288,8 +275,8 @@ public class TMXMapCreationWizard extends JDialog {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel && value != null) {
((JLabel)c).setText(((TMXMap)value).getDesc());
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getTiledIconIcon()));
((JLabel) c).setText(((TMXMap) value).getDesc());
((JLabel) c).setIcon(new ImageIcon(DefaultIcons.getTiledIconIcon()));
}
return c;
}

View File

@@ -1,26 +1,20 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import java.awt.*;
public class WorkerDialog extends JDialog {
private static final long serialVersionUID = 8239669104275145995L;
private static final long serialVersionUID = 8239669104275145995L;
private WorkerDialog(String message, Frame parent) {
super(parent, "Loading...");
this.setIconImage(DefaultIcons.getMainIconImage());
this.getContentPane().setLayout(new JideBoxLayout(this.getContentPane(), JideBoxLayout.PAGE_AXIS, 6));
this.getContentPane().add(new JLabel("<html><font size="+(int)(5 * ATContentStudio.SCALING)+">Please wait.<br/>"+message+"</font></html>"), JideBoxLayout.VARY);
this.getContentPane().add(new JLabel("<html><font size=" + (int) (5 * ATContentStudio.SCALING) + ">Please wait.<br/>" + message + "</font></html>"), JideBoxLayout.VARY);
JMovingIdler idler = new JMovingIdler();
idler.setBackground(Color.WHITE);
idler.setForeground(Color.GREEN);
@@ -32,7 +26,7 @@ private static final long serialVersionUID = 8239669104275145995L;
idler.setPreferredSize(new Dimension(wdim.width, 10));
this.pack();
wdim = this.getSize();
this.setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
this.setLocation((sdim.width - wdim.width) / 2, (sdim.height - wdim.height) / 2);
this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
@@ -47,8 +41,10 @@ private static final long serialVersionUID = 8239669104275145995L;
info.setVisible(true);
workload.run();
info.dispose();
if (showConfirm) JOptionPane.showMessageDialog(parent, "<html><font size="+(int)(5 * ATContentStudio.SCALING)+">Done !</font></html>");
};
if (showConfirm)
JOptionPane.showMessageDialog(parent, "<html><font size=" + (int) (5 * ATContentStudio.SCALING) + ">Done !</font></html>");
}
}.start();
}
}

View File

@@ -1,38 +1,8 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.tree.TreePath;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.ClosedProject;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
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.Workspace;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
import com.gpl.rpg.atcontentstudio.model.*;
import com.gpl.rpg.atcontentstudio.model.gamedata.*;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.Worldmap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
@@ -43,6 +13,16 @@ import com.gpl.rpg.atcontentstudio.ui.tools.BeanShellView;
import com.gpl.rpg.atcontentstudio.ui.tools.ItemsTableView;
import com.gpl.rpg.atcontentstudio.ui.tools.NPCsTableView;
import javax.swing.*;
import javax.swing.tree.TreePath;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
public class WorkspaceActions {
ProjectTreeNode selectedNode = null;
@@ -51,7 +31,8 @@ public class WorkspaceActions {
public ATCSAction createProject = new ATCSAction("Create project...", "Opens the project creation wizard") {
public void actionPerformed(ActionEvent e) {
new ProjectCreationWizard().setVisible(true);
};
}
};
@@ -60,10 +41,12 @@ public class WorkspaceActions {
if (!(selectedNode instanceof Project)) return;
Workspace.closeProject((Project) selectedNode);
selectedNode = null;
};
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode instanceof Project);
};
}
};
@@ -71,53 +54,63 @@ public class WorkspaceActions {
public void actionPerformed(ActionEvent e) {
if (!(selectedNode instanceof ClosedProject)) return;
Workspace.openProject((ClosedProject) selectedNode);
};
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode instanceof ClosedProject);
};
}
};
public ATCSAction deleteProject = new ATCSAction("Delete project", "Deletes the project, and all created/altered data, from disk") {
public void actionPerformed(ActionEvent e) {
if (selectedNode instanceof Project) {
if (JOptionPane.showConfirmDialog(ATContentStudio.frame, "Are you sure you wish to delete this project ?\nAll files created for it will be deleted too...", "Delete this project ?", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
Workspace.deleteProject((Project)selectedNode);
if (JOptionPane.showConfirmDialog(ATContentStudio.frame, "Are you sure you wish to delete this project ?\nAll files created for it will be deleted too...", "Delete this project ?",
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
Workspace.deleteProject((Project) selectedNode);
}
} else if (selectedNode instanceof ClosedProject) {
if (JOptionPane.showConfirmDialog(ATContentStudio.frame, "Are you sure you wish to delete this project ?\nAll files created for it will be deleted too...", "Delete this project ?", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
Workspace.deleteProject((ClosedProject)selectedNode);
if (JOptionPane.showConfirmDialog(ATContentStudio.frame, "Are you sure you wish to delete this project ?\nAll files created for it will be deleted too...", "Delete this project ?",
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
Workspace.deleteProject((ClosedProject) selectedNode);
}
}
};
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode instanceof Project || selectedNode instanceof ClosedProject);
};
}
};
public ATCSAction saveElement = new ATCSAction("Save this element", "Saves the current state of this element on disk"){
public ATCSAction saveElement = new ATCSAction("Save this element", "Saves the current state of this element on disk") {
public void actionPerformed(ActionEvent e) {
if (!(selectedNode instanceof GameDataElement)) return;
final GameDataElement node = ((GameDataElement)selectedNode);
if (node.needsSaving()){
final GameDataElement node = ((GameDataElement) selectedNode);
if (node.needsSaving()) {
node.save();
ATContentStudio.frame.nodeChanged(node);
}
};
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
if (selectedNode instanceof GameDataElement) {
setEnabled(((GameDataElement)selectedNode).needsSaving());
setEnabled(((GameDataElement) selectedNode).needsSaving());
} else {
setEnabled(false);
}
};
}
};
public ATCSAction deleteSelected = new ATCSAction("Delete", "Deletes the selected items") {
boolean multiMode = false;
List<GameDataElement> elementsToDelete = null;
public void init() {
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
};
}
public void actionPerformed(ActionEvent e) {
if (multiMode) {
if (elementsToDelete == null) return;
@@ -134,7 +127,7 @@ public class WorkspaceActions {
impactedCategories.put(category, new HashSet<File>());
}
GameDataElement newOne = element.getProject().getGameDataElement(((JSONElement)element).getClass(), element.id);
GameDataElement newOne = element.getProject().getGameDataElement(((JSONElement) element).getClass(), element.id);
if (element instanceof Quest) {
for (QuestStage oldStage : ((Quest) element).stages) {
QuestStage newStage = newOne != null ? ((Quest) newOne).getStage(oldStage.progress) : null;
@@ -149,7 +142,7 @@ public class WorkspaceActions {
impactedCategories.get(category).add(((JSONElement) element).jsonFile);
}
} else if (element instanceof TMXMap) {
((TMXMap)element).delete();
((TMXMap) element).delete();
GameDataElement newOne = element.getProject().getMap(element.id);
for (GameDataElement backlink : element.getBacklinks()) {
backlink.elementChanged(element, newOne);
@@ -159,7 +152,7 @@ public class WorkspaceActions {
parent.writerModeDataList.remove(element);
} else if (element instanceof WorldmapSegment) {
if (element.getParent() instanceof Worldmap) {
((Worldmap)element.getParent()).remove(element);
((Worldmap) element.getParent()).remove(element);
element.save();
for (GameDataElement backlink : element.getBacklinks()) {
backlink.elementChanged(element, element.getProject().getWorldmapSegment(element.id));
@@ -171,7 +164,7 @@ public class WorkspaceActions {
@Override
public void run() {
final List<SaveEvent> events = new ArrayList<SaveEvent>();
List<SaveEvent> catEvents = null;
List<SaveEvent> catEvents;
for (GameDataCategory<JSONElement> category : impactedCategories.keySet()) {
for (File f : impactedCategories.get(category)) {
catEvents = category.attemptSave(true, f.getName());
@@ -189,7 +182,7 @@ public class WorkspaceActions {
}.start();
} else {
if (!(selectedNode instanceof GameDataElement)) return;
final GameDataElement node = ((GameDataElement)selectedNode);
final GameDataElement node = ((GameDataElement) selectedNode);
ATContentStudio.frame.closeEditor(node);
new Thread() {
@Override
@@ -197,14 +190,14 @@ public class WorkspaceActions {
node.childrenRemoved(new ArrayList<ProjectTreeNode>());
if (node instanceof JSONElement) {
if (node.getParent() instanceof GameDataCategory<?>) {
((GameDataCategory<?>)node.getParent()).remove(node);
((GameDataCategory<?>) node.getParent()).remove(node);
List<SaveEvent> events = node.attemptSave();
if (events == null || events.isEmpty()) {
node.save();
} else {
new SaveItemsWizard(events, null).setVisible(true);
}
GameDataElement newOne = node.getProject().getGameDataElement(((JSONElement)node).getClass(), node.id);
GameDataElement newOne = node.getProject().getGameDataElement(((JSONElement) node).getClass(), node.id);
if (node instanceof Quest) {
for (QuestStage oldStage : ((Quest) node).stages) {
QuestStage newStage = newOne != null ? ((Quest) newOne).getStage(oldStage.progress) : null;
@@ -225,7 +218,7 @@ public class WorkspaceActions {
// new SaveItemsWizard(events, null).setVisible(true);
// }
} else if (node instanceof TMXMap) {
((TMXMap)node).delete();
((TMXMap) node).delete();
GameDataElement newOne = node.getProject().getMap(node.id);
for (GameDataElement backlink : node.getBacklinks()) {
backlink.elementChanged(node, newOne);
@@ -235,7 +228,7 @@ public class WorkspaceActions {
parent.writerModeDataList.remove(node);
} else if (node instanceof WorldmapSegment) {
if (node.getParent() instanceof Worldmap) {
((Worldmap)node.getParent()).remove(node);
((Worldmap) node.getParent()).remove(node);
node.save();
for (GameDataElement backlink : node.getBacklinks()) {
backlink.elementChanged(node, node.getProject().getWorldmapSegment(node.id));
@@ -245,21 +238,22 @@ public class WorkspaceActions {
}
}.start();
}
};
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
elementsToDelete = null;
if (selectedPaths != null && selectedPaths.length > 1) {
multiMode = false;
elementsToDelete = new ArrayList<GameDataElement>();
for (TreePath selected : selectedPaths) {
if (selected.getLastPathComponent() instanceof GameDataElement && ((GameDataElement)selected.getLastPathComponent()).writable) {
if (selected.getLastPathComponent() instanceof GameDataElement && ((GameDataElement) selected.getLastPathComponent()).writable) {
elementsToDelete.add((GameDataElement) selected.getLastPathComponent());
}
}
multiMode = elementsToDelete.size() > 1;
putValue(Action.NAME, "Delete all selected elements");
setEnabled(multiMode);
} else if (selectedNode instanceof GameDataElement && ((GameDataElement)selectedNode).writable) {
} else if (selectedNode instanceof GameDataElement && ((GameDataElement) selectedNode).writable) {
multiMode = false;
if (selectedNode.getDataType() == GameSource.Type.created) {
putValue(Action.NAME, "Delete this element");
@@ -273,7 +267,8 @@ public class WorkspaceActions {
} else {
setEnabled(false);
}
};
}
};
public ATCSAction createGDE = new ATCSAction("Create Game Data Element (JSON)", "Opens the game object creation wizard") {
@@ -281,6 +276,7 @@ public class WorkspaceActions {
if (selectedNode == null || selectedNode.getProject() == null) return;
new JSONCreationWizard(selectedNode.getProject()).setVisible(true);
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
}
@@ -291,6 +287,7 @@ public class WorkspaceActions {
if (selectedNode == null || selectedNode.getProject() == null) return;
new TMXMapCreationWizard(selectedNode.getProject()).setVisible(true);
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
}
@@ -301,6 +298,7 @@ public class WorkspaceActions {
if (selectedNode == null || selectedNode.getProject() == null) return;
new WorldmapCreationWizard(selectedNode.getProject()).setVisible(true);
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
}
@@ -311,81 +309,92 @@ public class WorkspaceActions {
if (selectedNode == null || selectedNode.getProject() == null) return;
new JSONImportWizard(selectedNode.getProject()).setVisible(true);
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
}
};
public ATCSAction loadSave = new ATCSAction("Load saved game...", "Opens the saved game loading wizard"){
public ATCSAction loadSave = new ATCSAction("Load saved game...", "Opens the saved game loading wizard") {
public void actionPerformed(ActionEvent e) {
if(!(selectedNode instanceof Project || selectedNode instanceof SavedGamesSet)) return;
if (!(selectedNode instanceof Project || selectedNode instanceof SavedGamesSet)) return;
JFileChooser chooser = new JFileChooser("Select an Andor's Trail save file");
if (chooser.showOpenDialog(ATContentStudio.frame) == JFileChooser.APPROVE_OPTION) {
selectedNode.getProject().addSave(chooser.getSelectedFile());
selectedNode.getProject().save();
}
};
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode instanceof Project || selectedNode instanceof SavedGamesSet);
};
}
};
public ATCSAction compareItems = new ATCSAction("Items comparator", "Opens an editor showing all the items of the project in a table"){
public ATCSAction compareItems = new ATCSAction("Items comparator", "Opens an editor showing all the items of the project in a table") {
public void actionPerformed(ActionEvent e) {
if (selectedNode == null || selectedNode.getProject() == null) return;
ATContentStudio.frame.editors.openEditor(new ItemsTableView(selectedNode.getProject()));
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
}
};
public ATCSAction compareNPCs = new ATCSAction("NPCs comparator", "Opens an editor showing all the NPCs of the project in a table"){
public ATCSAction compareNPCs = new ATCSAction("NPCs comparator", "Opens an editor showing all the NPCs of the project in a table") {
public void actionPerformed(ActionEvent e) {
if (selectedNode == null || selectedNode.getProject() == null) return;
ATContentStudio.frame.editors.openEditor(new NPCsTableView(selectedNode.getProject()));
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
}
};
public ATCSAction exportProject = new ATCSAction("Export project", "Generates a zip file containing all the created & altered resources of the project, ready to merge with the game source."){
public ATCSAction exportProject = new ATCSAction("Export project", "Generates a zip file containing all the created & altered resources of the project, ready to merge with the game source.") {
public void actionPerformed(ActionEvent e) {
if (selectedNode == null || selectedNode.getProject() == null) return;
new ExportProjectWizard(selectedNode.getProject()).setVisible(true);
};
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
};
}
};
public ATCSAction runBeanShell = new ATCSAction("Run Beanshell console", "Opens a beanshell scripting pad."){
public ATCSAction runBeanShell = new ATCSAction("Run Beanshell console", "Opens a beanshell scripting pad.") {
public void actionPerformed(ActionEvent e) {
new BeanShellView();
};
}
};
public ATCSAction showAbout = new ATCSAction("About...", "Displays credits and other informations about ATCS"){
public ATCSAction showAbout = new ATCSAction("About...", "Displays credits and other informations about ATCS") {
public void actionPerformed(ActionEvent e) {
ATContentStudio.frame.showAbout();
};
}
};
public ATCSAction exitATCS = new ATCSAction("Exit", "Closes the program"){
public ATCSAction exitATCS = new ATCSAction("Exit", "Closes the program") {
public void actionPerformed(ActionEvent e) {
if (Workspace.activeWorkspace.needsSaving()) {
int answer = JOptionPane.showConfirmDialog(ATContentStudio.frame, "There are unsaved changes in your workspace.\nExiting ATCS will discard these changes.\nDo you really want to exit?", "Unsaved changes. Confirm exit.", JOptionPane.YES_NO_OPTION);
int answer = JOptionPane.showConfirmDialog(ATContentStudio.frame, "There are unsaved changes in your workspace.\nExiting ATCS will discard these changes.\nDo you really want to exit?",
"Unsaved changes. Confirm exit.", JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION) {
System.exit(0);
}
} else {
System.exit(0);
}
};
}
};
public ATCSAction createWriter = new ATCSAction("Create dialogue sketch", "Create a dialogue sketch for fast dialogue edition"){
public ATCSAction createWriter = new ATCSAction("Create dialogue sketch", "Create a dialogue sketch for fast dialogue edition") {
public void actionPerformed(ActionEvent e) {
if (selectedNode == null || selectedNode.getProject() == null) return;
new WriterSketchCreationWizard(selectedNode.getProject()).setVisible(true);
@@ -400,7 +409,8 @@ public class WorkspaceActions {
// frame.setMinimumSize(new Dimension(250, 200));
// frame.pack();
// frame.setVisible(true);
};
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
}
@@ -422,10 +432,12 @@ public class WorkspaceActions {
public ATCSAction generateWriter = new ATCSAction("Generate dialogue sketch", "Generates a dialogue sketch from this dialogue and its tree.") {
public void actionPerformed(ActionEvent e) {
if (selectedNode == null || selectedNode.getProject() == null || !(selectedNode instanceof Dialogue)) return;
new WriterSketchCreationWizard(selectedNode.getProject(), (Dialogue)selectedNode).setVisible(true);
if (selectedNode == null || selectedNode.getProject() == null || !(selectedNode instanceof Dialogue))
return;
new WriterSketchCreationWizard(selectedNode.getProject(), (Dialogue) selectedNode).setVisible(true);
}
};
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode instanceof Dialogue);
}
@@ -434,10 +446,12 @@ public class WorkspaceActions {
public ATCSAction editWorkspaceSettings = new ATCSAction("Edit Workspace Settings", "Change the preferences of this workspace.") {
public void actionPerformed(ActionEvent e) {
new WorkspaceSettingsEditor(Workspace.activeWorkspace.settings);
};
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(true);
};
}
};
List<ATCSAction> actions = new ArrayList<WorkspaceActions.ATCSAction>();
@@ -465,10 +479,10 @@ public class WorkspaceActions {
selectionChanged(null, null);
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths){
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
this.selectedNode = selectedNode;
this.selectedPaths = selectedPaths;
synchronized(actions) {
synchronized (actions) {
for (ATCSAction action : actions) {
action.selectionChanged(selectedNode, selectedPaths);
}
@@ -486,12 +500,15 @@ public class WorkspaceActions {
init();
}
public void init(){}
public void init() {
}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths){}
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
}
@Override
public void actionPerformed(ActionEvent e) {};
public void actionPerformed(ActionEvent e) {
}
public Map<String, Object> values = new LinkedHashMap<String, Object>();

View File

@@ -1,8 +1,10 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import com.gpl.rpg.atcontentstudio.ConfigCache;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
@@ -10,17 +12,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.gpl.rpg.atcontentstudio.ConfigCache;
public class WorkspaceSelector extends JFrame {
private static final long serialVersionUID = 7518745499760748574L;
@@ -82,7 +73,7 @@ public class WorkspaceSelector extends JFrame {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc;
if(workspaces.isEmpty()) {
if (workspaces.isEmpty()) {
fc = new JFileChooser();
} else {
if (ConfigCache.getLatestWorkspace() != null) {
@@ -114,7 +105,8 @@ public class WorkspaceSelector extends JFrame {
JLabel logoLabel = new JLabel();
try {
logoLabel = new JLabel(new ImageIcon(ImageIO.read(WorkspaceSelector.class.getResource("/com/gpl/rpg/atcontentstudio/img/atcs_logo_banner.png"))), JLabel.CENTER);
} catch (IOException e1) {}
} catch (IOException e1) {
}
JPanel dialogPane = new JPanel();
dialogPane.setLayout(new BorderLayout());

View File

@@ -1,24 +1,14 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.WorkspaceSettings;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class WorkspaceSettingsEditor extends JDialog {
private static final long serialVersionUID = -1326158719217162879L;
@@ -37,7 +27,6 @@ public class WorkspaceSettingsEditor extends JDialog {
JCheckBox checkUpdatesBox;
public WorkspaceSettingsEditor(WorkspaceSettings settings) {
super(ATContentStudio.frame, "Workspace settings", true);
setIconImage(DefaultIcons.getMainIconImage());
@@ -236,7 +225,7 @@ public class WorkspaceSettingsEditor extends JDialog {
//Internet
settings.useInternet.setCurrentValue(useInternetBox.isSelected());
if (translatorModeBox.isSelected()) {
settings.translatorLanguage.setCurrentValue((String)translatorLanguagesBox.getSelectedItem());
settings.translatorLanguage.setCurrentValue((String) translatorLanguagesBox.getSelectedItem());
} else {
settings.translatorLanguage.resetDefault();
}

View File

@@ -1,27 +1,20 @@
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 java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
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.maps.WorldmapSegment;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class WorldmapCreationWizard extends JDialog {
private static final long serialVersionUID = 6491044105090917567L;
@@ -93,10 +86,12 @@ public class WorldmapCreationWizard extends JDialog {
public void removeUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void changedUpdate(DocumentEvent e) {
updateStatus();
@@ -107,13 +102,13 @@ public class WorldmapCreationWizard extends JDialog {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(pane, BorderLayout.CENTER);
setMinimumSize(new Dimension(350,120));
setMinimumSize(new Dimension(350, 120));
updateStatus();
pack();
Dimension sdim = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wdim = getSize();
setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
setLocation((sdim.width - wdim.width) / 2, (sdim.height - wdim.height) / 2);
}
public void updateStatus() {

View File

@@ -1,25 +1,18 @@
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 java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
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.maps.WorldmapSegment;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class WorldmapLabelEditionWizard extends JDialog {
private static final long serialVersionUID = 4911946705579386332L;
@@ -32,7 +25,7 @@ public class WorldmapLabelEditionWizard extends JDialog {
final WorldmapSegment segment;
final WorldmapSegment.NamedArea label;
boolean createMode = false;
boolean createMode;
public WorldmapLabelEditionWizard(WorldmapSegment segment) {
this(segment, new WorldmapSegment.NamedArea(null, null, null), true);
@@ -126,10 +119,12 @@ public class WorldmapLabelEditionWizard extends JDialog {
public void removeUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void changedUpdate(DocumentEvent e) {
updateStatus();
@@ -142,13 +137,13 @@ public class WorldmapLabelEditionWizard extends JDialog {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(pane, BorderLayout.CENTER);
setMinimumSize(new Dimension(350,170));
setMinimumSize(new Dimension(350, 170));
updateStatus();
pack();
Dimension sdim = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wdim = getSize();
setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
setLocation((sdim.width - wdim.width) / 2, (sdim.height - wdim.height) / 2);
}
public void updateStatus() {

View File

@@ -1,19 +1,5 @@
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.GameDataElement.State;
import com.gpl.rpg.atcontentstudio.model.Project;
@@ -21,6 +7,13 @@ import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class WriterSketchCreationWizard extends JDialog {
private static final long serialVersionUID = 175788847797352548L;
@@ -98,10 +91,12 @@ public class WriterSketchCreationWizard extends JDialog {
public void removeUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void changedUpdate(DocumentEvent e) {
updateStatus();
@@ -112,14 +107,14 @@ public class WriterSketchCreationWizard extends JDialog {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(pane, BorderLayout.CENTER);
setMinimumSize(new Dimension(350,250));
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);
setLocation((sdim.width - wdim.width) / 2, (sdim.height - wdim.height) / 2);
}

View File

@@ -1,15 +1,5 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
@@ -20,6 +10,9 @@ import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener;
import com.gpl.rpg.atcontentstudio.ui.IntegerBasedCheckBox;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import java.util.ArrayList;
public class ActorConditionEditor extends JSONElementEditor {
private static final long serialVersionUID = 799130864545495819L;
@@ -74,7 +67,7 @@ public class ActorConditionEditor extends JSONElementEditor {
@Override
public void insertFormViewDataField(JPanel pane) {
final ActorCondition ac = ((ActorCondition)target);
final ActorCondition ac = ((ActorCondition) target);
final FieldUpdateListener listener = new ActorConditionFieldUpdater();
@@ -96,7 +89,7 @@ public class ActorConditionEditor extends JSONElementEditor {
} else {
roundEffect = new ActorCondition.RoundEffect();
}
roundVisualField = addEnumValueBox(roundEffectPane, "Visual effect ID:", ActorCondition.VisualEffectID.values(), roundEffect.visual_effect, ac.writable, listener);//addTextField(roundEffectPane, "Visual effect ID: ", roundEffect.visual_effect, ac.writable, listener);
roundVisualField = addEnumValueBox(roundEffectPane, "Visual effect ID:", ActorCondition.VisualEffectID.values(), roundEffect.visual_effect, ac.writable, listener);
roundHpMinField = addIntegerField(roundEffectPane, "HP Bonus Min: ", roundEffect.hp_boost_min, true, ac.writable, listener);
roundHpMaxField = addIntegerField(roundEffectPane, "HP Bonus Max: ", roundEffect.hp_boost_max, true, ac.writable, listener);
roundApMinField = addIntegerField(roundEffectPane, "AP Bonus Min: ", roundEffect.ap_boost_min, true, ac.writable, listener);
@@ -113,7 +106,7 @@ public class ActorConditionEditor extends JSONElementEditor {
} else {
fullRoundEffect = new ActorCondition.RoundEffect();
}
fullRoundVisualField = addEnumValueBox(fullRoundEffectPane, "Visual effect ID:", ActorCondition.VisualEffectID.values(), fullRoundEffect.visual_effect, ac.writable, listener);//addTextField(fullRoundEffectPane, "Visual effect ID: ", fullRoundEffect.visual_effect, ac.writable, listener);
fullRoundVisualField = addEnumValueBox(fullRoundEffectPane, "Visual effect ID:", ActorCondition.VisualEffectID.values(), fullRoundEffect.visual_effect, ac.writable, listener);
fullRoundHpMinField = addIntegerField(fullRoundEffectPane, "HP Bonus min: ", fullRoundEffect.hp_boost_min, true, ac.writable, listener);
fullRoundHpMaxField = addIntegerField(fullRoundEffectPane, "HP Bonus max: ", fullRoundEffect.hp_boost_max, true, ac.writable, listener);
fullRoundApMinField = addIntegerField(fullRoundEffectPane, "AP Bonus min: ", fullRoundEffect.ap_boost_min, true, ac.writable, listener);
@@ -151,7 +144,7 @@ public class ActorConditionEditor extends JSONElementEditor {
public class ActorConditionFieldUpdater implements FieldUpdateListener {
@Override
public void valueChanged(JComponent source, Object value) {
ActorCondition aCond = (ActorCondition)target;
ActorCondition aCond = (ActorCondition) target;
if (source == idField) {
//Events caused by cancel an ID edition. Dismiss.
if (skipNext) {
@@ -174,7 +167,7 @@ public class ActorConditionEditor extends JSONElementEditor {
ActorConditionEditor.this.name = aCond.getDesc();
aCond.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(ActorConditionEditor.this);
}else if (source == descriptionField) {
} else if (source == descriptionField) {
aCond.description = (String) value;
aCond.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(ActorConditionEditor.this);
@@ -512,18 +505,17 @@ public class ActorConditionEditor extends JSONElementEditor {
}
private boolean isEmpty(ActorCondition.RoundEffect round_effect) {
return round_effect == null || (
round_effect.visual_effect == null &&
return round_effect == null ||
(round_effect.visual_effect == null &&
round_effect.hp_boost_min == null &&
round_effect.hp_boost_max == null &&
round_effect.ap_boost_min == null &&
round_effect.ap_boost_max == null
);
round_effect.ap_boost_max == null);
}
private boolean isEmpty(ActorCondition.AbilityEffect ability_effect) {
return ability_effect == null || (
ability_effect.max_hp_boost == null &&
return ability_effect == null ||
(ability_effect.max_hp_boost == null &&
ability_effect.max_ap_boost == null &&
ability_effect.increase_move_cost == null &&
ability_effect.increase_use_cost == null &&
@@ -534,16 +526,9 @@ public class ActorConditionEditor extends JSONElementEditor {
ability_effect.increase_damage_max == null &&
ability_effect.increase_critical_skill == null &&
ability_effect.increase_block_chance == null &&
ability_effect.increase_damage_resistance == null
);
ability_effect.increase_damage_resistance == null);
}
}
}

View File

@@ -0,0 +1,539 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Common;
import com.gpl.rpg.atcontentstudio.ui.*;
import com.gpl.rpg.atcontentstudio.utils.BasicLambda;
import com.gpl.rpg.atcontentstudio.utils.BasicLambdaWithArg;
import com.gpl.rpg.atcontentstudio.utils.BasicLambdaWithReturn;
import com.gpl.rpg.atcontentstudio.utils.UiUtils;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.function.Supplier;
import static com.gpl.rpg.atcontentstudio.ui.Editor.addIntegerField;
public class CommonEditor {
public static class TimedConditionsCellRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
Common.TimedActorConditionEffect effect = (Common.TimedActorConditionEffect) value;
if (effect.condition != null) {
boolean immunity = effect.isImmunity();
boolean clear = effect.isClear();
boolean forever = effect.isInfinite();
if (clear) {
label.setIcon(new ImageIcon(effect.condition.getIcon()));
label.setText(
effect.chance + "% chances to clear actor condition " + effect.condition.getDesc());
} else if (immunity) {
label.setIcon(new OverlayIcon(effect.condition.getIcon(), DefaultIcons.getImmunityIcon()));
label.setText(
effect.chance + "% chances to give immunity to " + effect.condition.getDesc() + (forever ? " forever" : " for " + effect.duration + " rounds"));
} else {
label.setIcon(new ImageIcon(effect.condition.getIcon()));
label.setText(
effect.chance +
"% chances to give actor condition " +
effect.condition.getDesc() +
" x" +
effect.magnitude +
(forever ? " forever" : " for " + effect.duration + " rounds"));
}
} else {
label.setText("New, undefined actor condition effect.");
}
}
return c;
}
}
public static class ConditionsCellRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
Common.ActorConditionEffect effect = (Common.ActorConditionEffect) value;
if (effect.condition != null) {
if (effect.isClear()) {
label.setIcon(new OverlayIcon(effect.condition.getIcon(), DefaultIcons.getImmunityIcon()));
label.setText("Immune to actor condition " + effect.condition.getDesc());
} else {
label.setIcon(new ImageIcon(effect.condition.getIcon()));
label.setText("Give actor condition " + effect.condition.getDesc() + " x" + effect.magnitude);
}
} else {
label.setText("New, undefined actor condition effect.");
}
}
return c;
}
}
public static class HitRecievedEffectPane<EFFECT extends Common.HitReceivedEffect, LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> extends HitEffectPane<EFFECT, LIST_MODEL_SOURCE, ELEMENT, MODEL> {
/// this should just be a convenience field, to access it, without casting. DO NOT SET WITHOUT ALSO SETTING THE FIELD IN THE SUPER-CLASS!
EFFECT effect;
private JSpinner hitReceivedEffectHPMinTarget;
private JSpinner hitReceivedEffectHPMaxTarget;
private JSpinner hitReceivedEffectAPMinTarget;
private JSpinner hitReceivedEffectAPMaxTarget;
public HitRecievedEffectPane(String title, Supplier<ELEMENT> sourceNewSupplier, Editor editor, String applyToHint, String applyToTargetHint) {
super(title, sourceNewSupplier, editor, applyToHint, applyToTargetHint);
}
void createHitReceivedEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModelInput, MODEL targetConditionsModelInput) {
effect = e;
createHitEffectPaneContent(listener, writable, e, sourceConditionsModelInput, targetConditionsModelInput);
}
@Override
protected void addFields(FieldUpdateListener listener, boolean writable) {
super.addFields(listener, writable);
hitReceivedEffectHPMinTarget = addIntegerField(effectPane, String.format("HP bonus min%s: ", applyToTargetHint),
effect.target.hp_boost_min, true, writable, listener);
hitReceivedEffectHPMaxTarget = addIntegerField(effectPane, String.format("HP bonus max%s: ", applyToTargetHint),
effect.target.hp_boost_max, true, writable, listener);
hitReceivedEffectAPMinTarget = addIntegerField(effectPane, String.format("AP bonus min%s: ", applyToTargetHint),
effect.target.ap_boost_min, true, writable, listener);
hitReceivedEffectAPMaxTarget = addIntegerField(effectPane, String.format("AP bonus max%s: ", applyToTargetHint),
effect.target.ap_boost_max, true, writable, listener);
}
@Override
public boolean valueChanged(JComponent source, Object value, GameDataElement backlink) {
boolean updateHitReceived = super.valueChanged(source, value, backlink);
if (!updateHitReceived) {
if (source == hitReceivedEffectHPMinTarget) {
effect.target.hp_boost_min = (Integer) value;
updateHitReceived = true;
} else if (source == hitReceivedEffectHPMaxTarget) {
effect.target.hp_boost_max = (Integer) value;
updateHitReceived = true;
} else if (source == hitReceivedEffectAPMinTarget) {
effect.target.ap_boost_min = (Integer) value;
updateHitReceived = true;
} else if (source == hitReceivedEffectAPMaxTarget) {
effect.target.ap_boost_max = (Integer) value;
updateHitReceived = true;
}
}
return updateHitReceived;
}
}
public static class HitEffectPane<EFFECT extends Common.HitEffect, LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> extends DeathEffectPane<EFFECT, LIST_MODEL_SOURCE, ELEMENT, MODEL> {
/// this should just be a convenience field, to access it, without casting. DO NOT SET WITHOUT ALSO SETTING THE FIELD IN THE SUPER-CLASS!
public EFFECT effect;
protected final String applyToTargetHint;
private JList hitTargetConditionsList;
private final ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT, MODEL> hitTargetConditionPane;
/*
* create a new HitEffectPane with the selections (probably passed in from last time)
*/
public HitEffectPane(String title, Supplier<ELEMENT> sourceNewSupplier, Editor editor, String applyToHint, String applyToTargetHint) {
super(title, sourceNewSupplier, editor, applyToHint);
hitTargetConditionPane = new ConditionEffectEditorPane<>(editor);
if (applyToTargetHint == null || applyToTargetHint == "") {
this.applyToTargetHint = "";
} else {
this.applyToTargetHint = String.format(" (%s)", applyToTargetHint);
}
}
void createHitEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModelInput, MODEL targetConditionsListModel) {
effect = e;
hitTargetConditionPane.conditionsModel = targetConditionsListModel;
createDeathEffectPaneContent(listener, writable, e, sourceConditionsModelInput);
}
@Override
protected void addLists(FieldUpdateListener listener, boolean writable) {
super.addLists(listener, writable);
String titleTarget = String.format("Actor Conditions applied to the target%s: ", applyToTargetHint);
CommonEditor.TimedConditionsCellRenderer cellRendererTarget = new CommonEditor.TimedConditionsCellRenderer();
BasicLambdaWithArg<ELEMENT> selectedSetTarget = (value) -> hitTargetConditionPane.selectedCondition = value;
BasicLambdaWithReturn<ELEMENT> selectedGetTarget = () -> hitTargetConditionPane.selectedCondition;
BasicLambda selectedResetTarget = () -> hitTargetConditionPane.selectedCondition = null;
BasicLambdaWithArg<JPanel> updatePaneTarget = (editorPane) -> hitTargetConditionPane.updateEffectTimedConditionEditorPane(
editorPane, hitTargetConditionPane.selectedCondition, listener);
var resultTarget = UiUtils.getCollapsibleItemList(listener, hitTargetConditionPane.conditionsModel,
selectedResetTarget, selectedSetTarget, selectedGetTarget,
(x) -> {
}, updatePaneTarget, writable, this.conditionSupplier,
cellRendererTarget, titleTarget, (x) -> null);
hitTargetConditionsList = resultTarget.list;
CollapsiblePanel hitTargetConditionsPane = resultTarget.collapsiblePanel;
if (effect == null || effect.conditions_target == null || effect.conditions_target.isEmpty()) {
hitTargetConditionsPane.collapse();
}
effectPane.add(hitTargetConditionsPane, JideBoxLayout.FIX);
}
@Override
public boolean valueChanged(JComponent source, Object value, GameDataElement backlink) {
boolean updateHit = false;
if (super.valueChanged(source, value, backlink)) {
updateHit = true;
} else if (source == hitTargetConditionsList) {
updateHit = true;
} else if (hitTargetConditionPane.valueChanged(source, value, backlink)) {
updateHit = true;
}
return updateHit;
}
}
public static class DeathEffectPane<EFFECT extends Common.DeathEffect, LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> {
protected final Supplier<ELEMENT> conditionSupplier;
protected final String title;
protected final String applyToHint;
EFFECT effect;
CollapsiblePanel effectPane;
private JSpinner effectHPMin;
private JSpinner effectHPMax;
private JSpinner effectAPMin;
private JSpinner effectAPMax;
private JList<ELEMENT> sourceConditionsList;
private final ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT, MODEL> sourceConditionPane;
/*
* create a new DeatchEffectPane with the selections (probably passed in from last time)
*/
public DeathEffectPane(String title, Supplier<ELEMENT> conditionSupplier, Editor editor, String applyToHint) {
this.title = title;
this.conditionSupplier = conditionSupplier;
this.sourceConditionPane = new ConditionEffectEditorPane<>(editor);
if (applyToHint == null || applyToHint == "") {
this.applyToHint = "";
} else {
this.applyToHint = String.format(" (%s)", applyToHint);
}
}
void createDeathEffectPaneContent(FieldUpdateListener listener, boolean writable, EFFECT e, MODEL sourceConditionsModel) {
effect = e;
sourceConditionPane.conditionsModel = sourceConditionsModel;
effectPane = new CollapsiblePanel(title);
effectPane.setLayout(new JideBoxLayout(effectPane, JideBoxLayout.PAGE_AXIS));
addFields(listener, writable);
addLists(listener, writable);
}
protected void addFields(FieldUpdateListener listener, boolean writable) {
effectHPMin = addIntegerField(effectPane, String.format("HP bonus min%s: ", applyToHint), effect.hp_boost_min,
true, writable, listener);
effectHPMax = addIntegerField(effectPane, String.format("HP bonus max%s: ", applyToHint), effect.hp_boost_max,
true, writable, listener);
effectAPMin = addIntegerField(effectPane, String.format("AP bonus min%s: ", applyToHint), effect.ap_boost_min,
true, writable, listener);
effectAPMax = addIntegerField(effectPane, String.format("AP bonus max%s: ", applyToHint), effect.ap_boost_max,
true, writable, listener);
}
protected void addLists(FieldUpdateListener listener, boolean writable) {
String titleSource = String.format("Actor Conditions applied to the source%s: ", applyToHint);
TimedConditionsCellRenderer cellRendererSource = new TimedConditionsCellRenderer();
BasicLambdaWithArg<ELEMENT> selectedSetSource = (value) -> sourceConditionPane.selectedCondition = value;
BasicLambdaWithReturn<ELEMENT> selectedGetSource = () -> sourceConditionPane.selectedCondition;
BasicLambda selectedResetSource = () -> sourceConditionPane.selectedCondition = null;
BasicLambdaWithArg<JPanel> updatePaneSource = (editorPane) -> sourceConditionPane.updateEffectTimedConditionEditorPane(
editorPane, sourceConditionPane.selectedCondition, listener);
var resultSource = UiUtils.getCollapsibleItemList(listener, sourceConditionPane.conditionsModel, selectedResetSource,
selectedSetSource, selectedGetSource, (x) -> {
}, updatePaneSource, writable, conditionSupplier, cellRendererSource, titleSource, (x) -> null);
sourceConditionsList = resultSource.list;
CollapsiblePanel sourceConditionsPane = resultSource.collapsiblePanel;
if (effect == null || effect.conditions_source == null || effect.conditions_source.isEmpty()) {
sourceConditionsPane.collapse();
}
effectPane.add(sourceConditionsPane, JideBoxLayout.FIX);
}
public boolean valueChanged(JComponent source, Object value, GameDataElement backlink) {
boolean updateHit = false;
if (source == effectHPMin) {
effect.hp_boost_min = (Integer) value;
updateHit = true;
} else if (source == effectHPMax) {
effect.hp_boost_max = (Integer) value;
updateHit = true;
} else if (source == effectAPMin) {
effect.ap_boost_min = (Integer) value;
updateHit = true;
} else if (source == effectAPMax) {
effect.ap_boost_max = (Integer) value;
updateHit = true;
} else if (source == sourceConditionsList) {
updateHit = true;
} else if (sourceConditionPane.valueChanged(source, value, backlink)) {
updateHit = true;
}
return updateHit;
}
}
static class ConditionEffectEditorPane<LIST_MODEL_SOURCE, ELEMENT extends Common.TimedActorConditionEffect, MODEL extends OrderedListenerListModel<LIST_MODEL_SOURCE, ELEMENT>> {
private final Editor editor;
ELEMENT selectedCondition;
MODEL conditionsModel;
Editor.MyComboBox conditionBox;
JSpinner conditionChance;
JRadioButton conditionClear;
JRadioButton conditionApply;
JRadioButton conditionImmunity;
JSpinner conditionMagnitude;
JRadioButton conditionTimed;
JRadioButton conditionForever;
JSpinner conditionDuration;
ConditionEffectEditorPane(Editor editor) {
this.editor = editor;
}
public void updateEffectTimedConditionWidgets(ELEMENT condition) {
boolean writable = editor.target.writable;
boolean immunity = condition.isImmunity();
boolean clear = condition.isClear();
boolean forever = condition.isInfinite();
conditionClear.setSelected(clear);
conditionApply.setSelected(!clear && !immunity);
conditionImmunity.setSelected(immunity);
conditionTimed.setSelected(!forever);
conditionForever.setSelected(forever);
conditionDuration.setEnabled(!clear && !forever && writable);
conditionClear.setEnabled(writable);
conditionApply.setEnabled(writable);
conditionMagnitude.setEnabled(!clear && !immunity && writable);
conditionImmunity.setEnabled(writable);
conditionTimed.setEnabled(!clear && writable);
conditionForever.setEnabled(!clear && writable);
}
public void updateEffectTimedConditionEditorPane(JPanel pane, ELEMENT condition, final FieldUpdateListener listener) {
pane.removeAll();
if (conditionBox != null) {
editor.removeElementListener(conditionBox);
}
if (condition == null) {
pane.revalidate();
pane.repaint();
return;
}
boolean writable = editor.target.writable;
Project proj = editor.target.getProject();
conditionBox = editor.addActorConditionBox(pane, proj, "Actor Condition: ", condition.condition, writable,
listener);
conditionChance = Editor.addDoubleField(pane, "Chance: ", condition.chance, writable, listener);
conditionClear = new JRadioButton("Clear active condition");
pane.add(conditionClear, JideBoxLayout.FIX);
conditionApply = new JRadioButton("Apply condition with magnitude");
pane.add(conditionApply, JideBoxLayout.FIX);
conditionMagnitude = addIntegerField(pane, "Magnitude: ",
condition.magnitude == null ? null : condition.magnitude >= 0 ? condition.magnitude : 0,
1, false, writable, listener);
conditionImmunity = new JRadioButton("Give immunity to condition");
pane.add(conditionImmunity, JideBoxLayout.FIX);
ButtonGroup radioEffectGroup = new ButtonGroup();
radioEffectGroup.add(conditionApply);
radioEffectGroup.add(conditionClear);
radioEffectGroup.add(conditionImmunity);
conditionTimed = new JRadioButton("For a number of rounds");
pane.add(conditionTimed, JideBoxLayout.FIX);
conditionDuration = addIntegerField(pane, "Duration: ", condition.duration, 1, false, writable,
listener);
conditionForever = new JRadioButton("Forever");
pane.add(conditionForever, JideBoxLayout.FIX);
ButtonGroup radioDurationGroup = new ButtonGroup();
radioDurationGroup.add(conditionTimed);
radioDurationGroup.add(conditionForever);
updateEffectTimedConditionWidgets(condition);
conditionClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(conditionClear, conditionClear.isSelected());
}
});
conditionApply.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(conditionApply, conditionApply.isSelected());
}
});
conditionImmunity.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(conditionImmunity, conditionImmunity.isSelected());
}
});
conditionTimed.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(conditionTimed, conditionTimed.isSelected());
}
});
conditionForever.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(conditionForever, conditionForever.isSelected());
}
});
pane.revalidate();
pane.repaint();
}
public boolean valueChanged(JComponent source, Object value, GameDataElement backlink) {
boolean updateHit = false;
if (source == conditionBox) {
if (selectedCondition.condition != null) {
selectedCondition.condition.removeBacklink(backlink);
}
selectedCondition.condition = (ActorCondition) value;
if (selectedCondition.condition != null) {
selectedCondition.condition.addBacklink(backlink);
selectedCondition.condition_id = selectedCondition.condition.id;
} else {
selectedCondition.condition_id = null;
}
conditionsModel.itemChanged(selectedCondition);
} else if (source == conditionClear && (Boolean) value) {
selectedCondition.magnitude = ActorCondition.MAGNITUDE_CLEAR;
selectedCondition.duration = null;
updateEffectTimedConditionWidgets(selectedCondition);
conditionsModel.itemChanged(selectedCondition);
updateHit = true;
} else if (source == conditionApply && (Boolean) value) {
selectedCondition.magnitude = (Integer) conditionMagnitude.getValue();
selectedCondition.duration = conditionForever.isSelected() ? ActorCondition.DURATION_FOREVER : (Integer) conditionDuration.getValue();
setDurationToDefaultIfNone();
updateEffectTimedConditionWidgets(selectedCondition);
conditionsModel.itemChanged(selectedCondition);
updateHit = true;
} else if (source == conditionImmunity && (Boolean) value) {
selectedCondition.magnitude = ActorCondition.MAGNITUDE_CLEAR;
selectedCondition.duration = conditionForever.isSelected() ? ActorCondition.DURATION_FOREVER : (Integer) conditionDuration.getValue();
setDurationToDefaultIfNone();
updateEffectTimedConditionWidgets(selectedCondition);
conditionsModel.itemChanged(selectedCondition);
updateHit = true;
} else if (source == conditionMagnitude) {
selectedCondition.magnitude = (Integer) value;
conditionsModel.itemChanged(selectedCondition);
updateHit = true;
} else if (source == conditionTimed && (Boolean) value) {
selectedCondition.duration = (Integer) conditionDuration.getValue();
setDurationToDefaultIfNone();
updateEffectTimedConditionWidgets(selectedCondition);
conditionsModel.itemChanged(selectedCondition);
updateHit = true;
} else if (source == conditionForever && (Boolean) value) {
selectedCondition.duration = ActorCondition.DURATION_FOREVER;
updateEffectTimedConditionWidgets(selectedCondition);
conditionsModel.itemChanged(selectedCondition);
updateHit = true;
} else if (source == conditionDuration) {
selectedCondition.duration = (Integer) value;
conditionsModel.itemChanged(selectedCondition);
updateHit = true;
} else if (source == conditionChance) {
selectedCondition.chance = (Double) value;
conditionsModel.itemChanged(selectedCondition);
}
return updateHit;
}
private void setDurationToDefaultIfNone() {
if (selectedCondition.duration == null || selectedCondition.duration == ActorCondition.DURATION_NONE) {
selectedCondition.duration = 1;
}
}
}
//region list-models
public static class TargetTimedConditionsListModel extends OrderedListenerListModel<Common.HitEffect, Common.TimedActorConditionEffect> {
public TargetTimedConditionsListModel(Common.HitEffect effect) {
super(effect);
}
@Override
protected java.util.List<Common.TimedActorConditionEffect> getItems() {
return source.conditions_target;
}
@Override
protected void setItems(java.util.List<Common.TimedActorConditionEffect> items) {
source.conditions_target = items;
}
}
public static class SourceTimedConditionsListModel extends OrderedListenerListModel<Common.DeathEffect, Common.TimedActorConditionEffect> {
public SourceTimedConditionsListModel(Common.DeathEffect effect) {
super(effect);
}
@Override
protected java.util.List<Common.TimedActorConditionEffect> getItems() {
return source.conditions_source;
}
@Override
protected void setItems(List<Common.TimedActorConditionEffect> items) {
source.conditions_source = items;
}
}
//endregion
}

View File

@@ -1,61 +1,25 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
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.gamedata.ActorCondition;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement;
import com.gpl.rpg.atcontentstudio.model.gamedata.*;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.ui.BooleanBasedCheckBox;
import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener;
import com.gpl.rpg.atcontentstudio.ui.OverlayIcon;
import com.gpl.rpg.atcontentstudio.ui.*;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.dialoguetree.DialogueGraphView;
import com.gpl.rpg.atcontentstudio.utils.UiUtils;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
public class DialogueEditor extends JSONElementEditor {
private static final long serialVersionUID = 4140553240585599873L;
@@ -144,15 +108,7 @@ public class DialogueEditor extends JSONElementEditor {
dialogueGraphView = new DialogueGraphView(dialogue, null);
pane.add(dialogueGraphView, BorderLayout.CENTER);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new JideBoxLayout(buttonPane, JideBoxLayout.LINE_AXIS));
JButton reloadButton = new JButton("Refresh graph");
buttonPane.add(reloadButton, JideBoxLayout.FIX);
buttonPane.add(new JPanel(), JideBoxLayout.VARY);
pane.add(buttonPane, BorderLayout.NORTH);
reloadButton.addActionListener(new ActionListener() {
JPanel buttonPane = UiUtils.createRefreshButtonPane(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
pane.remove(dialogueGraphView);
@@ -162,11 +118,12 @@ public class DialogueEditor extends JSONElementEditor {
pane.repaint();
}
});
pane.add(buttonPane, BorderLayout.NORTH);
return pane;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public void insertFormViewDataField(final JPanel pane) {
final Dialogue dialogue = (Dialogue) target;
@@ -178,159 +135,56 @@ public class DialogueEditor extends JSONElementEditor {
messageField = addTranslatableTextArea(pane, "Message: ", dialogue.message, dialogue.writable, listener);
switchToNpcBox = addNPCBox(pane, dialogue.getProject(), "Switch active NPC to: ", dialogue.switch_to_npc, dialogue.writable, listener);
CollapsiblePanel rewards = new CollapsiblePanel("Reaching this phrase gives the following rewards: ");
rewards.setLayout(new JideBoxLayout(rewards, JideBoxLayout.PAGE_AXIS));
String titleRewards = "Reaching this phrase gives the following rewards: ";
RewardsCellRenderer cellRendererRewards = new RewardsCellRenderer();
rewardsListModel = new RewardsListModel(dialogue);
rewardsList = new JList(rewardsListModel);
rewardsList.setCellRenderer(new RewardsCellRenderer());
rewardsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
rewards.add(new JScrollPane(rewardsList), JideBoxLayout.FIX);
final JPanel rewardsEditorPane = new JPanel();
final JButton createReward = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteReward = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
deleteReward.setEnabled(false);
rewardsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedReward = (Dialogue.Reward) rewardsList.getSelectedValue();
if (selectedReward == null) {
deleteReward.setEnabled(false);
} else {
deleteReward.setEnabled(true);
}
updateRewardsEditorPane(rewardsEditorPane, selectedReward, listener);
}
});
if (dialogue.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createReward.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Dialogue.Reward reward = new Dialogue.Reward();
rewardsListModel.addItem(reward);
rewardsList.setSelectedValue(reward, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteReward.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedReward != null) {
rewardsListModel.removeItem(selectedReward);
selectedReward = null;
rewardsList.clearSelection();
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
listButtonsPane.add(createReward, JideBoxLayout.FIX);
listButtonsPane.add(deleteReward, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
rewards.add(listButtonsPane, JideBoxLayout.FIX);
}
CollapsiblePanel rewards = UiUtils.getCollapsibleItemList(
listener,
rewardsListModel,
() -> selectedReward = null,
(selectedItem) -> this.selectedReward = selectedItem,
() -> this.selectedReward,
(reward) -> {
},
(editorPane) -> updateRewardsEditorPane(editorPane, this.selectedReward, listener),
dialogue.writable,
Dialogue.Reward::new,
cellRendererRewards,
titleRewards,
(x) -> null
).collapsiblePanel;
if (dialogue.rewards == null || dialogue.rewards.isEmpty()) {
rewards.collapse();
}
rewardsEditorPane.setLayout(new JideBoxLayout(rewardsEditorPane, JideBoxLayout.PAGE_AXIS));
rewards.add(rewardsEditorPane, JideBoxLayout.FIX);
pane.add(rewards, JideBoxLayout.FIX);
CollapsiblePanel replies = new CollapsiblePanel("Replies / Next Phrase: ");
replies.setLayout(new JideBoxLayout(replies, JideBoxLayout.PAGE_AXIS));
RepliesCellRenderer cellRendererReplies = new RepliesCellRenderer();
String titleReplies = "Replies / Next Phrase: ";
repliesListModel = new RepliesListModel(dialogue);
repliesList = new JList(repliesListModel);
repliesList.setCellRenderer(new RepliesCellRenderer());
repliesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
replies.add(new JScrollPane(repliesList), JideBoxLayout.FIX);
final JPanel repliesEditorPane = new JPanel();
final JButton createReply = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteReply = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
final JButton moveReplyUp = new JButton(new ImageIcon(DefaultIcons.getArrowUpIcon()));
final JButton moveReplyDown = new JButton(new ImageIcon(DefaultIcons.getArrowDownIcon()));
deleteReply.setEnabled(false);
moveReplyUp.setEnabled(false);
moveReplyDown.setEnabled(false);
repliesList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedReply = (Dialogue.Reply) repliesList.getSelectedValue();
CollapsiblePanel replies = UiUtils.getCollapsibleItemList(
listener,
repliesListModel,
() -> selectedReply = null,
(selectedItem) -> this.selectedReply = selectedItem,
() -> this.selectedReply,
(selectedReply) -> {
if (selectedReply != null && !Dialogue.Reply.GO_NEXT_TEXT.equals(selectedReply.text)) {
replyTextCache = selectedReply.text;
} else {
replyTextCache = null;
}
if (selectedReply != null) {
deleteReply.setEnabled(true);
moveReplyUp.setEnabled(repliesList.getSelectedIndex() > 0);
moveReplyDown.setEnabled(repliesList.getSelectedIndex() < (repliesListModel.getSize() - 1));
} else {
deleteReply.setEnabled(false);
moveReplyUp.setEnabled(false);
moveReplyDown.setEnabled(false);
}
updateRepliesEditorPane(repliesEditorPane, selectedReply, listener);
}
});
if (dialogue.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createReply.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Dialogue.Reply reply = new Dialogue.Reply();
repliesListModel.addItem(reply);
repliesList.setSelectedValue(reply, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteReply.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedReply != null) {
repliesListModel.removeItem(selectedReply);
selectedReply = null;
repliesList.clearSelection();
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
moveReplyUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedReply != null) {
repliesListModel.moveUp(selectedReply);
repliesList.setSelectedValue(selectedReply, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
moveReplyDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedReply != null) {
repliesListModel.moveDown(selectedReply);
repliesList.setSelectedValue(selectedReply, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
listButtonsPane.add(createReply, JideBoxLayout.FIX);
listButtonsPane.add(deleteReply, JideBoxLayout.FIX);
listButtonsPane.add(moveReplyUp, JideBoxLayout.FIX);
listButtonsPane.add(moveReplyDown, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
replies.add(listButtonsPane, JideBoxLayout.FIX);
}
},
(editorPane) -> updateRepliesEditorPane(editorPane, this.selectedReply, listener),
dialogue.writable,
Dialogue.Reply::new,
cellRendererReplies,
titleReplies,
(x) -> null
).collapsiblePanel;
if (dialogue.replies == null || dialogue.replies.isEmpty()) {
replies.collapse();
}
repliesEditorPane.setLayout(new JideBoxLayout(repliesEditorPane, JideBoxLayout.PAGE_AXIS));
replies.add(repliesEditorPane, JideBoxLayout.FIX);
pane.add(replies, JideBoxLayout.FIX);
@@ -347,7 +201,7 @@ public class DialogueEditor extends JSONElementEditor {
}
if (reward != null) {
rewardTypeCombo = addEnumValueBox(pane, "Reward type: ", Dialogue.Reward.RewardType.values(), reward.type, ((Dialogue)target).writable, listener);
rewardTypeCombo = addEnumValueBox(pane, "Reward type: ", Dialogue.Reward.RewardType.values(), reward.type, ((Dialogue) target).writable, listener);
rewardsParamsPane = new JPanel();
rewardsParamsPane.setLayout(new JideBoxLayout(rewardsParamsPane, JideBoxLayout.PAGE_AXIS));
updateRewardsParamsEditorPane(rewardsParamsPane, reward, listener);
@@ -358,7 +212,7 @@ public class DialogueEditor extends JSONElementEditor {
}
public void updateRewardsParamsEditorPane(final JPanel pane, final Dialogue.Reward reward, final FieldUpdateListener listener) {
boolean writable = ((Dialogue)target).writable;
boolean writable = ((Dialogue) target).writable;
pane.removeAll();
if (rewardMap != null) {
removeElementListener(rewardMap);
@@ -371,21 +225,22 @@ public class DialogueEditor extends JSONElementEditor {
switch (reward.type) {
case activateMapObjectGroup:
case deactivateMapObjectGroup:
rewardMap = addMapBox(pane, ((Dialogue)target).getProject(), "Map Name: ", reward.map, writable, listener);
rewardMap = addMapBox(pane, ((Dialogue) target).getProject(), "Map Name: ", reward.map, writable, listener);
rewardObjId = addTextField(pane, "Group ID: ", reward.reward_obj_id, writable, listener);
rewardObjIdCombo = null;
rewardObj = null;
rewardValue = null;
break;
case changeMapFilter:
rewardMap = addMapBox(pane, ((Dialogue)target).getProject(), "Map Name: ", reward.map, writable, listener);
rewardMap = addMapBox(pane, ((Dialogue) target).getProject(), "Map Name: ", reward.map, writable, listener);
rewardObjId = null;
rewardObjIdCombo = addEnumValueBox(pane, "Color Filter", TMXMap.ColorFilter.values(), reward.reward_obj_id != null ? TMXMap.ColorFilter.valueOf(reward.reward_obj_id) : TMXMap.ColorFilter.none, writable, listener);
rewardObjIdCombo = addEnumValueBox(pane, "Color Filter", TMXMap.ColorFilter.values(),
reward.reward_obj_id != null ? TMXMap.ColorFilter.valueOf(reward.reward_obj_id) : TMXMap.ColorFilter.none, writable, listener);
rewardObj = null;
rewardValue = null;
break;
case mapchange:
rewardMap = addMapBox(pane, ((Dialogue)target).getProject(), "Map Name: ", reward.map, writable, listener);
rewardMap = addMapBox(pane, ((Dialogue) target).getProject(), "Map Name: ", reward.map, writable, listener);
rewardObjId = addTextField(pane, "Place: ", reward.reward_obj_id, writable, listener);
rewardObjIdCombo = null;
rewardObj = null;
@@ -394,7 +249,7 @@ public class DialogueEditor extends JSONElementEditor {
case deactivateSpawnArea:
case removeSpawnArea:
case spawnAll:
rewardMap = addMapBox(pane, ((Dialogue)target).getProject(), "Map Name: ", reward.map, writable, listener);
rewardMap = addMapBox(pane, ((Dialogue) target).getProject(), "Map Name: ", reward.map, writable, listener);
rewardObjId = addTextField(pane, "Area ID: ", reward.reward_obj_id, writable, listener);
rewardObjIdCombo = null;
rewardObj = null;
@@ -407,7 +262,7 @@ public class DialogueEditor extends JSONElementEditor {
rewardMap = null;
rewardObjId = null;
rewardObjIdCombo = null;
rewardObj = addActorConditionBox(pane, ((Dialogue)target).getProject(), "Actor Condition: ", (ActorCondition) reward.reward_obj, writable, listener);
rewardObj = addActorConditionBox(pane, ((Dialogue) target).getProject(), "Actor Condition: ", (ActorCondition) reward.reward_obj, writable, listener);
rewardConditionTimed = new JRadioButton("For a number of rounds");
pane.add(rewardConditionTimed, JideBoxLayout.FIX);
rewardValue = addIntegerField(pane, "Duration: ", reward.reward_value, 1, false, writable, listener);
@@ -424,12 +279,13 @@ public class DialogueEditor extends JSONElementEditor {
if (!immunity) radioGroup.add(rewardConditionClear);
if (immunity) {
rewardConditionTimed.setSelected(reward.reward_value == null || (reward.reward_value != ActorCondition.DURATION_FOREVER && reward.reward_value != ActorCondition.MAGNITUDE_CLEAR));
rewardConditionForever.setSelected(reward.reward_value != null && reward.reward_value != ActorCondition.DURATION_FOREVER);
rewardConditionClear.setSelected(reward.reward_value != null && reward.reward_value != ActorCondition.MAGNITUDE_CLEAR);
rewardConditionTimed.setSelected(
reward.reward_value == null || (!reward.reward_value.equals(ActorCondition.DURATION_FOREVER) && !reward.reward_value.equals(ActorCondition.MAGNITUDE_CLEAR)));
rewardConditionForever.setSelected(reward.reward_value != null && !reward.reward_value.equals(ActorCondition.DURATION_FOREVER));
rewardConditionClear.setSelected(reward.reward_value != null && !reward.reward_value.equals(ActorCondition.MAGNITUDE_CLEAR));
} else {
rewardConditionTimed.setSelected(reward.reward_value != null && reward.reward_value != ActorCondition.DURATION_FOREVER);
rewardConditionForever.setSelected(reward.reward_value == null || reward.reward_value == ActorCondition.DURATION_FOREVER);
rewardConditionTimed.setSelected(reward.reward_value != null && !reward.reward_value.equals(ActorCondition.DURATION_FOREVER));
rewardConditionForever.setSelected(reward.reward_value == null || reward.reward_value.equals(ActorCondition.DURATION_FOREVER));
}
rewardValue.setEnabled(rewardConditionTimed.isSelected());
@@ -473,13 +329,13 @@ public class DialogueEditor extends JSONElementEditor {
rewardMap = null;
rewardObjId = null;
rewardObjIdCombo = null;
rewardObj = addDroplistBox(pane, ((Dialogue)target).getProject(), "Droplist: ", (Droplist) reward.reward_obj, writable, listener);
rewardObj = addDroplistBox(pane, ((Dialogue) target).getProject(), "Droplist: ", (Droplist) reward.reward_obj, writable, listener);
rewardValue = null;
break;
case giveItem:
rewardMap = null;
rewardObjId = null;
rewardObj = addItemBox(pane, ((Dialogue)target).getProject(), "Item: ", (Item) reward.reward_obj, writable, listener);
rewardObj = addItemBox(pane, ((Dialogue) target).getProject(), "Item: ", (Item) reward.reward_obj, writable, listener);
rewardValue = addIntegerField(pane, "Quantity: ", reward.reward_value, true, writable, listener);
break;
case removeQuestProgress:
@@ -487,14 +343,15 @@ public class DialogueEditor extends JSONElementEditor {
rewardMap = null;
rewardObjId = null;
rewardObjIdCombo = null;
rewardObj = addQuestBox(pane, ((Dialogue)target).getProject(), "Quest: ", (Quest) reward.reward_obj, writable, listener);
rewardValue = addQuestStageBox(pane, ((Dialogue)target).getProject(), "Quest stage: ", reward.reward_value, writable, listener, (Quest) reward.reward_obj, rewardObj);
rewardObj = addQuestBox(pane, ((Dialogue) target).getProject(), "Quest: ", (Quest) reward.reward_obj, writable, listener);
rewardValue = addQuestStageBox(pane, ((Dialogue) target).getProject(), "Quest stage: ", reward.reward_value, writable, listener, (Quest) reward.reward_obj, rewardObj);
break;
case skillIncrease:
Requirement.SkillID skillId = null;
try {
skillId = reward.reward_obj_id == null ? null : Requirement.SkillID.valueOf(reward.reward_obj_id);
} catch(IllegalArgumentException e) {}
} catch (IllegalArgumentException e) {
}
rewardMap = null;
rewardObjId = null;// addTextField(pane, "Skill ID: ", reward.reward_obj_id, writable, listener);
rewardObjIdCombo = addEnumValueBox(pane, "Skill ID: ", Requirement.SkillID.values(), skillId, writable, listener);
@@ -508,7 +365,7 @@ public class DialogueEditor extends JSONElementEditor {
pane.repaint();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public void updateRepliesEditorPane(final JPanel pane, final Dialogue.Reply reply, final FieldUpdateListener listener) {
pane.removeAll();
if (replyNextPhrase != null) {
@@ -525,7 +382,7 @@ public class DialogueEditor extends JSONElementEditor {
comboPane.add(comboLabel, BorderLayout.WEST);
replyTypeCombo = new JComboBox(replyTypes);
replyTypeCombo.setEnabled(((Dialogue)target).writable);
replyTypeCombo.setEnabled(((Dialogue) target).writable);
repliesParamsPane = new JPanel();
repliesParamsPane.setLayout(new JideBoxLayout(repliesParamsPane, JideBoxLayout.PAGE_AXIS));
if (Dialogue.Reply.GO_NEXT_TEXT.equals(reply.text)) {
@@ -586,83 +443,31 @@ public class DialogueEditor extends JSONElementEditor {
updateRepliesParamsEditorPane(repliesParamsPane, reply, listener);
pane.add(repliesParamsPane, JideBoxLayout.FIX);
CollapsiblePanel requirementsPane = new CollapsiblePanel("Requirements the player must fulfill to select this reply: ");
requirementsPane.setLayout(new JideBoxLayout(requirementsPane, JideBoxLayout.PAGE_AXIS));
ReplyRequirementsCellRenderer cellRendererRequirements = new ReplyRequirementsCellRenderer();
String titleRequirements = "Requirements the player must fulfill to select this reply: ";
requirementsListModel = new ReplyRequirementsListModel(reply);
requirementsList = new JList(requirementsListModel);
requirementsList.setCellRenderer(new ReplyRequirementsCellRenderer());
requirementsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
requirementsPane.add(new JScrollPane(requirementsList), JideBoxLayout.FIX);
final JPanel requirementsEditorPane = new JPanel();
final JButton createReq = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteReq = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
deleteReq.setEnabled(false);
requirementsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedRequirement = (Requirement) requirementsList.getSelectedValue();
if (selectedRequirement != null) {
deleteReq.setEnabled(true);
} else {
deleteReq.setEnabled(false);
}
updateRequirementsEditorPane(requirementsEditorPane, selectedRequirement, listener);
}
});
requirementsList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
if (requirementsList.getSelectedValue() != null && ((Requirement)requirementsList.getSelectedValue()).required_obj != null) {
ATContentStudio.frame.openEditor(((Requirement)requirementsList.getSelectedValue()).required_obj);
ATContentStudio.frame.selectInTree(((Requirement)requirementsList.getSelectedValue()).required_obj);
}
}
}
});
requirementsList.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
ATContentStudio.frame.openEditor(((Requirement)requirementsList.getSelectedValue()).required_obj);
ATContentStudio.frame.selectInTree(((Requirement)requirementsList.getSelectedValue()).required_obj);
}
}
});
if (((Dialogue)target).writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createReq.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Requirement req = new Requirement();
requirementsListModel.addItem(req);
requirementsList.setSelectedValue(req, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteReq.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedRequirement != null) {
requirementsListModel.removeItem(selectedRequirement);
selectedRequirement = null;
requirementsList.clearSelection();
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
UiUtils.CollapsibleItemListCreation itemsPane = UiUtils.getCollapsibleItemList(
listener,
requirementsListModel,
() -> selectedRequirement = null,
(selectedItem) -> this.selectedRequirement = selectedItem,
() -> this.selectedRequirement,
(selectedItem) -> {
},
(droppedItemsEditorPane) -> updateRequirementsEditorPane(droppedItemsEditorPane, this.selectedRequirement, listener),
target.writable,
Requirement::new,
cellRendererRequirements,
titleRequirements,
(x) -> x.required_obj
);
CollapsiblePanel requirementsPane = itemsPane.collapsiblePanel;
requirementsList = itemsPane.list;
listButtonsPane.add(createReq, JideBoxLayout.FIX);
listButtonsPane.add(deleteReq, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
requirementsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
requirementsEditorPane.setLayout(new JideBoxLayout(requirementsEditorPane, JideBoxLayout.PAGE_AXIS));
requirementsPane.add(requirementsEditorPane, JideBoxLayout.FIX);
if (reply.requirements == null || reply.requirements.isEmpty()) {
requirementsPane.collapse();
}
pane.add(requirementsPane, JideBoxLayout.FIX);
pane.revalidate();
@@ -670,7 +475,7 @@ public class DialogueEditor extends JSONElementEditor {
}
public void updateRepliesParamsEditorPane(final JPanel pane, final Dialogue.Reply reply, final FieldUpdateListener listener) {
boolean writable = ((Dialogue)target).writable;
boolean writable = ((Dialogue) target).writable;
pane.removeAll();
if (replyNextPhrase != null) {
@@ -682,13 +487,13 @@ public class DialogueEditor extends JSONElementEditor {
if (Dialogue.Reply.GO_NEXT_TEXT.equals(reply.text)) {
replyText = null;
replyNextPhrase = addDialogueBox(pane, ((Dialogue)target).getProject(), "Next phrase: ", reply.next_phrase, writable, listener);
replyNextPhrase = addDialogueBox(pane, ((Dialogue) target).getProject(), "Next phrase: ", reply.next_phrase, writable, listener);
} else if (Dialogue.Reply.KEY_PHRASE_ID.contains(reply.next_phrase_id)) {
replyText = addTranslatableTextField(pane, "Reply text: ", reply.text, writable, listener);
replyNextPhrase = null;
} else {
replyText = addTranslatableTextField(pane, "Reply text: ", reply.text, writable, listener);
replyNextPhrase = addDialogueBox(pane, ((Dialogue)target).getProject(), "Next phrase: ", reply.next_phrase, writable, listener);
replyNextPhrase = addDialogueBox(pane, ((Dialogue) target).getProject(), "Next phrase: ", reply.next_phrase, writable, listener);
}
@@ -697,7 +502,7 @@ public class DialogueEditor extends JSONElementEditor {
}
public void updateRequirementsEditorPane(final JPanel pane, final Requirement requirement, final FieldUpdateListener listener) {
boolean writable = ((Dialogue)target).writable;
boolean writable = ((Dialogue) target).writable;
pane.removeAll();
if (requirementObj != null) {
@@ -714,8 +519,8 @@ public class DialogueEditor extends JSONElementEditor {
}
public void updateRequirementParamsEditorPane(final JPanel pane, final Requirement requirement, final FieldUpdateListener listener) {
boolean writable = ((Dialogue)target).writable;
Project project = ((Dialogue)target).getProject();
boolean writable = ((Dialogue) target).writable;
Project project = ((Dialogue) target).getProject();
pane.removeAll();
if (requirementObj != null) {
removeElementListener(requirementObj);
@@ -763,7 +568,8 @@ public class DialogueEditor extends JSONElementEditor {
Requirement.SkillID skillId = null;
try {
skillId = requirement.required_obj_id == null ? null : Requirement.SkillID.valueOf(requirement.required_obj_id);
} catch(IllegalArgumentException e) {}
} catch (IllegalArgumentException e) {
}
requirementObj = null;
requirementSkill = addEnumValueBox(pane, "Skill ID:", Requirement.SkillID.values(), skillId, writable, listener);
requirementObjId = null;//addTextField(pane, "Skill ID:", requirement.required_obj_id, writable, listener);
@@ -812,65 +618,19 @@ public class DialogueEditor extends JSONElementEditor {
}
public static class RewardsListModel implements ListModel<Dialogue.Reward> {
public static class RewardsListModel extends OrderedListenerListModel<Dialogue, Dialogue.Reward> {
@Override
protected List<Dialogue.Reward> getItems() {
return source.rewards;
}
Dialogue source;
@Override
protected void setItems(List<Dialogue.Reward> items) {
source.rewards = items;
}
public RewardsListModel(Dialogue dialogue) {
this.source = dialogue;
}
@Override
public int getSize() {
if (source.rewards == null) return 0;
return source.rewards.size();
}
@Override
public Dialogue.Reward getElementAt(int index) {
if (source.rewards == null) return null;
return source.rewards.get(index);
}
public void addItem(Dialogue.Reward item) {
if (source.rewards == null) {
source.rewards = new ArrayList<Dialogue.Reward>();
}
source.rewards.add(item);
int index = source.rewards.indexOf(item);
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
}
}
public void removeItem(Dialogue.Reward item) {
int index = source.rewards.indexOf(item);
source.rewards.remove(item);
if (source.rewards.isEmpty()) {
source.rewards = null;
}
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
}
}
public void itemChanged(Dialogue.Reward item) {
int index = source.rewards.indexOf(item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
}
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
super(dialogue);
}
}
@@ -881,8 +641,8 @@ public class DialogueEditor extends JSONElementEditor {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel label = ((JLabel)c);
Dialogue.Reward reward = (Dialogue.Reward)value;
JLabel label = ((JLabel) c);
Dialogue.Reward reward = (Dialogue.Reward) value;
decorateRewardJLabel(label, reward);
}
@@ -893,85 +653,86 @@ public class DialogueEditor extends JSONElementEditor {
public static void decorateRewardJLabel(JLabel label, Dialogue.Reward reward) {
if (reward.type != null) {
String rewardObjDesc = null;
if( reward.reward_obj != null) {
if (reward.reward_obj != null) {
rewardObjDesc = reward.reward_obj.getDesc();
} else if (reward.reward_obj_id != null) {
rewardObjDesc = reward.reward_obj_id;
}
switch (reward.type) {
case activateMapObjectGroup:
label.setText("Activate map object group "+rewardObjDesc+" on map "+reward.map_name);
label.setText("Activate map object group " + rewardObjDesc + " on map " + reward.map_name);
label.setIcon(new ImageIcon(DefaultIcons.getObjectLayerIcon()));
break;
case actorCondition:
boolean rewardClear = reward.reward_value != null && reward.reward_value.intValue() == ActorCondition.MAGNITUDE_CLEAR;
boolean rewardClear = reward.reward_value != null && reward.reward_value.equals(ActorCondition.MAGNITUDE_CLEAR);
if (rewardClear) {
label.setText("Clear actor condition "+rewardObjDesc);
label.setText("Clear actor condition " + rewardObjDesc);
} else {
boolean rewardForever = reward.reward_value != null && reward.reward_value.intValue() == ActorCondition.DURATION_FOREVER;
label.setText("Give actor condition "+rewardObjDesc+(rewardForever ? " forever" : " for "+reward.reward_value+" turns"));
label.setText("Give actor condition " + rewardObjDesc + (rewardForever ? " forever" : " for " + reward.reward_value + " turns"));
}
if (reward.reward_obj != null) label.setIcon(new ImageIcon(reward.reward_obj.getIcon()));
break;
case actorConditionImmunity:
boolean rewardForever = reward.reward_value == null || reward.reward_value.intValue() == ActorCondition.DURATION_FOREVER;
label.setText("Give immunity to actor condition "+rewardObjDesc+(rewardForever ? " forever" : " for "+reward.reward_value+" turns"));
if (reward.reward_obj != null) label.setIcon(new OverlayIcon(reward.reward_obj.getIcon(), DefaultIcons.getImmunityIcon()));
label.setText("Give immunity to actor condition " + rewardObjDesc + (rewardForever ? " forever" : " for " + reward.reward_value + " turns"));
if (reward.reward_obj != null)
label.setIcon(new OverlayIcon(reward.reward_obj.getIcon(), DefaultIcons.getImmunityIcon()));
break;
case alignmentChange:
label.setText("Change alignment for faction "+rewardObjDesc+" : "+reward.reward_value);
label.setText("Change alignment for faction " + rewardObjDesc + " : " + reward.reward_value);
label.setIcon(new ImageIcon(DefaultIcons.getAlignmentIcon()));
break;
case alignmentSet:
label.setText("Set alignment for faction "+rewardObjDesc+" : "+reward.reward_value);
label.setText("Set alignment for faction " + rewardObjDesc + " : " + reward.reward_value);
label.setIcon(new ImageIcon(DefaultIcons.getAlignmentIcon()));
break;
case createTimer:
label.setText("Create timer "+rewardObjDesc);
label.setText("Create timer " + rewardObjDesc);
label.setIcon(new ImageIcon(DefaultIcons.getTimerIcon()));
break;
case deactivateMapObjectGroup:
label.setText("Deactivate map object group "+rewardObjDesc+" on map "+reward.map_name);
label.setText("Deactivate map object group " + rewardObjDesc + " on map " + reward.map_name);
label.setIcon(new ImageIcon(DefaultIcons.getObjectLayerIcon()));
break;
case deactivateSpawnArea:
label.setText("Deactivate spawnarea area "+rewardObjDesc+" on map "+reward.map_name);
label.setText("Deactivate spawnarea area " + rewardObjDesc + " on map " + reward.map_name);
label.setIcon(new ImageIcon(DefaultIcons.getNPCIcon()));
break;
case dropList:
label.setText("Give contents of droplist "+rewardObjDesc);
label.setText("Give contents of droplist " + rewardObjDesc);
if (reward.reward_obj != null) label.setIcon(new ImageIcon(reward.reward_obj.getIcon()));
break;
case giveItem:
label.setText("Give "+reward.reward_value+" "+rewardObjDesc);
label.setText("Give " + reward.reward_value + " " + rewardObjDesc);
if (reward.reward_obj != null) label.setIcon(new ImageIcon(reward.reward_obj.getIcon()));
break;
case questProgress:
label.setText("Give quest progress "+rewardObjDesc+":"+reward.reward_value);
label.setText("Give quest progress " + rewardObjDesc + ":" + reward.reward_value);
if (reward.reward_obj != null) label.setIcon(new ImageIcon(reward.reward_obj.getIcon()));
break;
case removeQuestProgress:
label.setText("Removes quest progress "+rewardObjDesc+":"+reward.reward_value);
label.setText("Removes quest progress " + rewardObjDesc + ":" + reward.reward_value);
if (reward.reward_obj != null) label.setIcon(new ImageIcon(reward.reward_obj.getIcon()));
break;
case removeSpawnArea:
label.setText("Remove all monsters in spawnarea area "+rewardObjDesc+" on map "+reward.map_name);
label.setText("Remove all monsters in spawnarea area " + rewardObjDesc + " on map " + reward.map_name);
label.setIcon(new ImageIcon(DefaultIcons.getNPCIcon()));
break;
case skillIncrease:
label.setText("Increase skill "+rewardObjDesc+" level");
label.setText("Increase skill " + rewardObjDesc + " level");
label.setIcon(new ImageIcon(DefaultIcons.getSkillIcon()));
break;
case spawnAll:
label.setText("Respawn all monsters in spawnarea area "+rewardObjDesc+" on map "+reward.map_name);
label.setText("Respawn all monsters in spawnarea area " + rewardObjDesc + " on map " + reward.map_name);
label.setIcon(new ImageIcon(DefaultIcons.getNPCIcon()));
break;
case changeMapFilter:
label.setText("Change map filter to "+rewardObjDesc+" on map "+reward.map_name);
label.setText("Change map filter to " + rewardObjDesc + " on map " + reward.map_name);
label.setIcon(new ImageIcon(DefaultIcons.getReplaceIcon()));
break;
case mapchange:
label.setText("Teleport to "+rewardObjDesc+" on map "+reward.map_name);
label.setText("Teleport to " + rewardObjDesc + " on map " + reward.map_name);
label.setIcon(new ImageIcon(DefaultIcons.getMapchangeIcon()));
break;
}
@@ -981,87 +742,19 @@ public class DialogueEditor extends JSONElementEditor {
}
public static class RepliesListModel implements ListModel<Dialogue.Reply> {
public static class RepliesListModel extends OrderedListenerListModel<Dialogue, Dialogue.Reply> {
@Override
protected List<Dialogue.Reply> getItems() {
return source.replies;
}
Dialogue source;
@Override
protected void setItems(List<Dialogue.Reply> items) {
source.replies = items;
}
public RepliesListModel(Dialogue dialogue) {
this.source = dialogue;
}
@Override
public int getSize() {
if (source.replies == null) return 0;
return source.replies.size();
}
@Override
public Dialogue.Reply getElementAt(int index) {
if (source.replies == null) return null;
return source.replies.get(index);
}
public void addItem(Dialogue.Reply item) {
if (source.replies == null) {
source.replies = new ArrayList<Dialogue.Reply>();
}
source.replies.add(item);
int index = source.replies.indexOf(item);
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
}
}
public void removeItem(Dialogue.Reply item) {
int index = source.replies.indexOf(item);
source.replies.remove(item);
if (source.replies.isEmpty()) {
source.replies = null;
}
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
}
}
public void itemChanged(Dialogue.Reply item) {
int index = source.replies.indexOf(item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
}
}
public void moveUp(Dialogue.Reply item) {
int index = source.replies.indexOf(item);
Dialogue.Reply exchanged = source.replies.get(index - 1);
source.replies.set(index, exchanged);
source.replies.set(index - 1, item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index - 1, index));
}
}
public void moveDown(Dialogue.Reply item) {
int index = source.replies.indexOf(item);
Dialogue.Reply exchanged = source.replies.get(index + 1);
source.replies.set(index, exchanged);
source.replies.set(index + 1, item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index + 1));
}
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
super(dialogue);
}
}
@@ -1072,8 +765,8 @@ public class DialogueEditor extends JSONElementEditor {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel label = ((JLabel)c);
Dialogue.Reply reply = (Dialogue.Reply)value;
JLabel label = ((JLabel) c);
Dialogue.Reply reply = (Dialogue.Reply) value;
StringBuffer buf = new StringBuffer();
if (reply.requirements != null) {
buf.append("[Reqs]");
@@ -1115,69 +808,20 @@ public class DialogueEditor extends JSONElementEditor {
}
}
public static class ReplyRequirementsListModel implements ListModel<Requirement> {
public static class ReplyRequirementsListModel extends OrderedListenerListModel<Dialogue.Reply, Requirement> {
@Override
protected List<Requirement> getItems() {
return source.requirements;
}
Dialogue.Reply reply;
@Override
protected void setItems(List<Requirement> items) {
source.requirements = items;
}
public ReplyRequirementsListModel(Dialogue.Reply reply) {
this.reply = reply;
super(reply);
}
@Override
public int getSize() {
if (reply.requirements == null) return 0;
return reply.requirements.size();
}
@Override
public Requirement getElementAt(int index) {
if (reply.requirements == null) return null;
return reply.requirements.get(index);
}
public void addItem(Requirement item) {
if (reply.requirements == null) {
reply.requirements = new ArrayList<Requirement>();
}
reply.requirements.add(item);
int index = reply.requirements.indexOf(item);
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
}
}
public void removeItem(Requirement item) {
int index = reply.requirements.indexOf(item);
reply.requirements.remove(item);
if (reply.requirements.isEmpty()) {
reply.requirements = null;
}
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
}
}
public void itemChanged(Requirement item) {
int index = reply.requirements.indexOf(item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
}
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
}
}
public static class ReplyRequirementsCellRenderer extends DefaultListCellRenderer {
@@ -1187,7 +831,7 @@ public class DialogueEditor extends JSONElementEditor {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
decorateRequirementJLabel((JLabel)c, (Requirement)value);
decorateRequirementJLabel((JLabel) c, (Requirement) value);
}
return c;
}
@@ -1299,9 +943,9 @@ public class DialogueEditor extends JSONElementEditor {
} else if (source == rewardValue) {
//Backlink removal to quest stages when selecting another quest are handled in the addQuestStageBox() method. Too complex too handle here
Quest quest = null;
QuestStage stage = null;
QuestStage stage;
if (rewardValue instanceof JComboBox<?>) {
quest = ((Quest)selectedReward.reward_obj);
quest = ((Quest) selectedReward.reward_obj);
if (quest != null && selectedReward.reward_value != null) {
stage = quest.getStage(selectedReward.reward_value);
if (stage != null) stage.removeBacklink(dialogue);
@@ -1322,7 +966,7 @@ public class DialogueEditor extends JSONElementEditor {
rewardValue.setEnabled(false);
rewardsListModel.itemChanged(selectedReward);
} else if (source == rewardConditionTimed) {
selectedReward.reward_value = (Integer) ((JSpinner)rewardValue).getValue();
selectedReward.reward_value = (Integer) ((JSpinner) rewardValue).getValue();
rewardValue.setEnabled(true);
rewardsListModel.itemChanged(selectedReward);
} else if (source == replyTypeCombo) {
@@ -1344,7 +988,7 @@ public class DialogueEditor extends JSONElementEditor {
}
repliesListModel.itemChanged(selectedReply);
} else if (source == requirementTypeCombo) {
selectedRequirement.changeType((Requirement.RequirementType)requirementTypeCombo.getSelectedItem());
selectedRequirement.changeType((Requirement.RequirementType) requirementTypeCombo.getSelectedItem());
updateRequirementParamsEditorPane(requirementParamsPane, selectedRequirement, this);
requirementsListModel.itemChanged(selectedRequirement);
} else if (source == requirementObj) {
@@ -1375,9 +1019,9 @@ public class DialogueEditor extends JSONElementEditor {
} else if (source == requirementValue) {
//Backlink removal to quest stages when selecting another quest are handled in the addQuestStageBox() method. Too complex too handle here
Quest quest = null;
QuestStage stage = null;
QuestStage stage;
if (requirementValue instanceof JComboBox<?>) {
quest = ((Quest)selectedRequirement.required_obj);
quest = ((Quest) selectedRequirement.required_obj);
if (quest != null && selectedRequirement.required_value != null) {
stage = quest.getStage(selectedRequirement.required_value);
if (stage != null) stage.removeBacklink(dialogue);

View File

@@ -1,29 +1,5 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.Project;
@@ -32,10 +8,16 @@ import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist.DroppedItem;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener;
import com.gpl.rpg.atcontentstudio.ui.OrderedListenerListModel;
import com.gpl.rpg.atcontentstudio.utils.UiUtils;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class DroplistEditor extends JSONElementEditor {
private static final long serialVersionUID = 1139455254096811058L;
@@ -58,71 +40,34 @@ public class DroplistEditor extends JSONElementEditor {
addEditorTab(json_view_id, getJSONView());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void insertFormViewDataField(JPanel pane) {
final Droplist droplist = (Droplist)target;
final Droplist droplist = (Droplist) target;
final FieldUpdateListener listener = new DroplistFieldUpdater();
createButtonPane(pane, droplist.getProject(), droplist, Droplist.class, Droplist.getImage(), null, listener);
idField = addTextField(pane, "Droplist ID: ", droplist.id, droplist.writable, listener);
CollapsiblePanel itemsPane = new CollapsiblePanel("Items in this droplist: ");
itemsPane.setLayout(new JideBoxLayout(itemsPane, JideBoxLayout.PAGE_AXIS));
droppedItemsListModel = new DroppedItemsListModel(droplist);
final JList itemsList = new JList(droppedItemsListModel);
itemsList.setCellRenderer(new DroppedItemsCellRenderer());
itemsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
itemsPane.add(new JScrollPane(itemsList), JideBoxLayout.FIX);
final JPanel droppedItemsEditorPane = new JPanel();
final JButton createDroppedItem = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteDroppedItem = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
deleteDroppedItem.setEnabled(false);
itemsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedItem = (Droplist.DroppedItem) itemsList.getSelectedValue();
if (selectedItem == null) {
deleteDroppedItem.setEnabled(false);
} else {
deleteDroppedItem.setEnabled(true);
}
updateDroppedItemsEditorPane(droppedItemsEditorPane, selectedItem, listener);
}
});
if (droplist.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createDroppedItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Droplist.DroppedItem tempItem = new Droplist.DroppedItem();
droppedItemsListModel.addItem(tempItem);
itemsList.setSelectedValue(tempItem, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteDroppedItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedItem != null) {
droppedItemsListModel.removeItem(selectedItem);
selectedItem = null;
itemsList.clearSelection();
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
listButtonsPane.add(createDroppedItem, JideBoxLayout.FIX);
listButtonsPane.add(deleteDroppedItem, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
itemsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
droppedItemsEditorPane.setLayout(new JideBoxLayout(droppedItemsEditorPane, JideBoxLayout.PAGE_AXIS));
itemsPane.add(droppedItemsEditorPane, JideBoxLayout.FIX);
droppedItemsListModel = new DroplistEditor.DroppedItemsListModel(droplist);
CollapsiblePanel itemsPane = UiUtils.getCollapsibleItemList(
listener,
droppedItemsListModel,
() -> selectedItem = null,
(selectedItem) -> this.selectedItem = selectedItem,
() -> this.selectedItem,
(selectedItem) -> {
},
(droppedItemsEditorPane) -> updateDroppedItemsEditorPane(droppedItemsEditorPane, this.selectedItem, listener),
droplist.writable,
DroppedItem::new,
new DroppedItemsCellRenderer(),
"Items in this droplist: ",
(x) -> x.item
).collapsiblePanel;
if (droplist.dropped_items == null || droplist.dropped_items.isEmpty()) {
itemsPane.collapse();
}
@@ -132,8 +77,8 @@ public class DroplistEditor extends JSONElementEditor {
}
public void updateDroppedItemsEditorPane(JPanel pane, DroppedItem di, FieldUpdateListener listener) {
boolean writable = ((Droplist)target).writable;
Project proj = ((Droplist)target).getProject();
boolean writable = ((Droplist) target).writable;
Project proj = ((Droplist) target).getProject();
pane.removeAll();
if (itemCombo != null) {
removeElementListener(itemCombo);
@@ -148,65 +93,19 @@ public class DroplistEditor extends JSONElementEditor {
pane.repaint();
}
public class DroppedItemsListModel implements ListModel<Droplist.DroppedItem> {
Droplist source;
public class DroppedItemsListModel extends OrderedListenerListModel<Droplist, DroppedItem> {
public DroppedItemsListModel(Droplist droplist) {
this.source = droplist;
super(droplist);
}
@Override
public int getSize() {
if (source.dropped_items == null) return 0;
return source.dropped_items.size();
protected List<DroppedItem> getItems() {
return source.dropped_items;
}
@Override
public Droplist.DroppedItem getElementAt(int index) {
if (source.dropped_items == null) return null;
return source.dropped_items.get(index);
}
public void addItem(Droplist.DroppedItem item) {
if (source.dropped_items == null) {
source.dropped_items = new ArrayList<Droplist.DroppedItem>();
}
source.dropped_items.add(item);
int index = source.dropped_items.indexOf(item);
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
}
}
public void removeItem(Droplist.DroppedItem item) {
int index = source.dropped_items.indexOf(item);
source.dropped_items.remove(item);
if (source.dropped_items.isEmpty()) {
source.dropped_items = null;
}
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
}
}
public void itemChanged(Droplist.DroppedItem item) {
int index = source.dropped_items.indexOf(item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
}
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
protected void setItems(List<DroppedItem> items) {
source.dropped_items = items;
}
}
@@ -217,13 +116,13 @@ public class DroplistEditor extends JSONElementEditor {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel label = ((JLabel)c);
Droplist.DroppedItem di = (Droplist.DroppedItem)value;
JLabel label = ((JLabel) c);
Droplist.DroppedItem di = (Droplist.DroppedItem) value;
if (di.item != null) {
label.setIcon(new ImageIcon(di.item.getIcon()));
label.setText(di.chance+(di.chance != null && di.chance.contains("/") ? "" : "%")+" to get "+di.quantity_min+"-"+di.quantity_max+" "+di.item.getDesc());
label.setText(di.chance + (di.chance != null && di.chance.contains("/") ? "" : "%") + " to get " + di.quantity_min + "-" + di.quantity_max + " " + di.item.getDesc());
} else if (!isNull(di)) {
label.setText(di.chance+(di.chance != null && di.chance.contains("/") ? "" : "%")+" to get "+di.quantity_min+"-"+di.quantity_max+" "+di.item_id);
label.setText(di.chance + (di.chance != null && di.chance.contains("/") ? "" : "%") + " to get " + di.quantity_min + "-" + di.quantity_max + " " + di.item_id);
} else {
label.setText("New, undefined, dropped item.");
}
@@ -246,7 +145,7 @@ public class DroplistEditor extends JSONElementEditor {
public class DroplistFieldUpdater implements FieldUpdateListener {
@Override
public void valueChanged(JComponent source, Object value) {
Droplist droplist = ((Droplist)target);
Droplist droplist = ((Droplist) target);
if (source == idField) {
//Events caused by cancel an ID edition. Dismiss.
if (skipNext) {

View File

@@ -1,24 +1,15 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import java.awt.Component;
import java.util.ArrayList;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class ItemCategoryEditor extends JSONElementEditor {
private static final long serialVersionUID = -2893876158803488355L;
@@ -45,7 +36,7 @@ public class ItemCategoryEditor extends JSONElementEditor {
@SuppressWarnings("unchecked")
@Override
public void insertFormViewDataField(JPanel pane) {
final ItemCategory ic = ((ItemCategory)target);
final ItemCategory ic = ((ItemCategory) target);
final FieldUpdateListener listener = new ItemCategoryFieldUpdater();
icIcon = createButtonPane(pane, ic.getProject(), ic, ItemCategory.class, ic.getImage(), null, listener);
@@ -69,12 +60,12 @@ public class ItemCategoryEditor extends JSONElementEditor {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
((JLabel)c).setIcon(new ImageIcon(ItemCategory.getIcon((ItemCategory.InventorySlot) value)));
((JLabel) c).setIcon(new ImageIcon(ItemCategory.getIcon((ItemCategory.InventorySlot) value)));
if (value == null) {
if (typeBox.getSelectedItem() == ItemCategory.ActionType.equip) {
((JLabel)c).setText("Undefined. Select the slot to use when equipped.");
((JLabel) c).setText("Undefined. Select the slot to use when equipped.");
} else {
((JLabel)c).setText("Non equippable. Select \"equip\" action type.");
((JLabel) c).setText("Non equippable. Select \"equip\" action type.");
}
}
}
@@ -85,7 +76,7 @@ public class ItemCategoryEditor extends JSONElementEditor {
public class ItemCategoryFieldUpdater implements FieldUpdateListener {
@Override
public void valueChanged(JComponent source, Object value) {
ItemCategory ic = (ItemCategory)target;
ItemCategory ic = (ItemCategory) target;
if (source == idField) {
//Events caused by cancel an ID edition. Dismiss.
if (skipNext) {

View File

@@ -1,33 +1,7 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
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.*;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
@@ -35,16 +9,20 @@ import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.Editor;
import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener;
import com.gpl.rpg.atcontentstudio.ui.IdChangeImpactWizard;
import com.gpl.rpg.atcontentstudio.ui.SaveItemsWizard;
import com.gpl.rpg.atcontentstudio.ui.ScrollablePanel;
import com.gpl.rpg.atcontentstudio.ui.*;
import com.gpl.rpg.atcontentstudio.ui.ScrollablePanel.ScrollableSizeHint;
import com.gpl.rpg.atcontentstudio.ui.sprites.SpriteChooser;
import com.jidesoft.swing.JideBoxLayout;
import com.jidesoft.swing.JideTabbedPane;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.*;
public abstract class JSONElementEditor extends Editor {
@@ -82,17 +60,18 @@ public abstract class JSONElementEditor extends Editor {
public void removeEditorTab(String id) {
if (id == null) return;
for (int i =0; i <editorTabsHolder.getTabCount(); i++) {
for (int i = 0; i < editorTabsHolder.getTabCount(); i++) {
if (id.equals(editorTabsHolder.getTitleAt(i))) {
editorTabsHolder.removeTabAt(i);
editorTabs.remove(id);
}
}
}
public JPanel getJSONView() {
jsonEditorPane = new RSyntaxTextArea();
jsonEditorPane.setText(((JSONElement)target).toJsonString());
jsonEditorPane.setEditable(((JSONElement)target).writable);
jsonEditorPane.setText(((JSONElement) target).toJsonString());
jsonEditorPane.setEditable(((JSONElement) target).writable);
jsonEditorPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
jsonEditorPane.setFont(jsonEditorPane.getFont().deriveFont(ATContentStudio.SCALING * jsonEditorPane.getFont().getSize()));
JPanel result = new JPanel();
@@ -108,8 +87,8 @@ public abstract class JSONElementEditor extends Editor {
public JPanel getFormView() {
JPanel pane = new JPanel();
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.PAGE_AXIS, 6));
if (((JSONElement)target).jsonFile != null) {
addLabelField(pane, "JSON File: ", ((JSONElement)target).jsonFile.getAbsolutePath());
if (((JSONElement) target).jsonFile != null) {
addLabelField(pane, "JSON File: ", ((JSONElement) target).jsonFile.getAbsolutePath());
}
insertFormViewDataField(pane);
@@ -125,7 +104,6 @@ public abstract class JSONElementEditor extends Editor {
public abstract void insertFormViewDataField(JPanel pane);
public JButton createButtonPane(JPanel pane, final Project proj, final JSONElement node, final Class<? extends JSONElement> concreteNodeClass, Image icon, final Spritesheet.Category iconCat, final FieldUpdateListener listener) {
final JButton gdeIcon = new JButton(new ImageIcon(icon));
JPanel savePane = new JPanel();
@@ -186,7 +164,7 @@ public abstract class JSONElementEditor extends Editor {
ATContentStudio.frame.closeEditor(node);
node.childrenRemoved(new ArrayList<ProjectTreeNode>());
if (node.getParent() instanceof GameDataCategory<?>) {
((GameDataCategory<?>)node.getParent()).remove(node);
((GameDataCategory<?>) node.getParent()).remove(node);
node.save();
GameDataElement newOne = proj.getGameDataElement(node.getClass(), node.id);
if (node instanceof Quest) {
@@ -294,8 +272,8 @@ public abstract class JSONElementEditor extends Editor {
@Override
public void targetUpdated() {
this.icon = new ImageIcon(((GameDataElement)target).getIcon());
this.name = ((GameDataElement)target).getDesc();
this.icon = new ImageIcon(((GameDataElement) target).getIcon());
this.name = ((GameDataElement) target).getDesc();
updateMessage();
}
@@ -351,11 +329,11 @@ public abstract class JSONElementEditor extends Editor {
}
for (GameDataElement element : toAlter) {
if (element instanceof JSONElement) {
node.getProject().makeWritable((JSONElement)element);
node.getProject().makeWritable((JSONElement) element);
} else if (element instanceof TMXMap) {
node.getProject().makeWritable((TMXMap)element);
node.getProject().makeWritable((TMXMap) element);
} else if (element instanceof WorldmapSegment) {
node.getProject().makeWritable((WorldmapSegment)element);
node.getProject().makeWritable((WorldmapSegment) element);
}
}
return true;
@@ -368,8 +346,9 @@ public abstract class JSONElementEditor extends Editor {
//setText in cancelIdEdit generates to edit events, one replacing the contents with the empty string, and one with the target.id. We want to skip the first one.
public boolean skipNext = false;
public void cancelIdEdit(final JTextField idField) {
Runnable revertField = new Runnable(){
Runnable revertField = new Runnable() {
@Override
public void run() {
skipNext = true;

Some files were not shown because too many files have changed in this diff Show More