Compare commits

...

46 Commits

Author SHA1 Message Date
Zukero
49f19abb91 Forgot the necessary cleanup of old jars in windows NSIS version. 2017-04-03 17:57:03 +02:00
Zukero
300b7bbbdd Fixed caching issue with spritesheet chooser. Improved actor condition
management for items.
2017-04-03 17:53:44 +02:00
Zukero
bbee5bef25 Bug fix regarding object groups and spawn areas "active in a new game"
parameter.
2017-03-31 09:29:53 +02:00
Zukero
1fc1cef233 Fixed issue with batch scripts being overly painful to use, and have
horrible quoting and escaping rules.
2017-03-06 18:01:05 +01:00
Zukero
ae9a6695b0 v0.5.2 updated. Messed up something in scripts about paths containing
spaces.
2017-03-03 17:34:21 +01:00
Zukero
572704fd73 v0.5.2 ! Upped the bash & batch game. Can run from any directory,
auto-adaptation to jar files in lib, creation, use, and preservation
upon update or reinstall of a startup customization file (Max JVM
memory, custom java binary and custom JVM options as environment
variables). This is valid for all OS types (bash or batch startup) and
all installation methods (zip and nsis). Robustified a stupid version
management for workspace settings.
2017-03-03 17:15:16 +01:00
Zukero
dfe3cc8480 UAC dirty script for better windows integration to create symlinks. More
data using a thread-safe collection. Some NPEs fixed. 
More data protection in tiled integration functions (better state
checking, backup tiled-made file before saving ATCS-made data).
jardesc file added for convenience.
2017-03-02 18:10:03 +01:00
Zukero
97ae63693a Enhanced Tiled integration. ATCS offers to save a modified map before
opening in Tiled, and attempts to save a backup of the
externally-modified one when saving in ATCS if necessary.
2017-03-02 15:30:02 +01:00
Zukero
940996aa30 Some refactoring. Replaced all "listeners" list by instances of
CopyOnWriteArrayList, to allow listeners to unregister themselves due to
an event while preventing ConcurrentModificationExceptions.
Modified all GameDataElement.elementChanged concrete implementation to
remove the backlink from the oldOne.An element pointed by an altered
element will not show the game source element in its backlink list
anymore.
2017-03-02 13:53:24 +01:00
Zukero
2a4cfb0684 Enhanced Tiled integration. Can now reload a map that has changed
externaly. Still some rough edges, notably the number of nitification
sto skip when saving in ATCS.
2017-03-01 19:02:00 +01:00
Zukero
061a0fa11b Create new TMX maps in your project, and edit them with Tiled from ATCS
!! Also, "created" elements show the "unsaved" asterisk in their
description until they're saved to disk. 
Added a button to the spritesheet editor to open image in an external
tool too. This may or may not remain in the app.
2017-02-28 18:43:47 +01:00
Zukero
41462137d6 Enhanced Tiled integration. Now in "File->Edit workspace settings" menu,
you have tools to help selecting external tools to bview/edit images and
tmx maps. Still rough.
2017-02-27 18:18:17 +01:00
Zukero
9888dfe678 Introducing the WorkspaceSettings, workspace-wide user-modifiable
settings. No UI yet, so it's useless for now.
2017-02-24 17:45:34 +01:00
Zukero
baa027bc41 Version 0.5.1 with bugfixes and support for map color filter changes as
dialogue reward.
2017-02-23 18:54:01 +01:00
Zukero
8f2e835e9c Fixed nasty and stupid bug about Actor Conditions' JSON format
(isStacking and isPositive)
2017-02-21 19:23:27 +01:00
Zukero
8333fe3621 Added support for the upcoming script reward "changeColorFilter" 2017-01-25 19:11:45 +01:00
Zukero
291808a564 Naive attempt at Tiled integration. Very primitive yet. Requires Java7
!! for symlink creation.
2017-01-20 18:38:44 +01:00
Zukero
900d0bc9b5 v0.5.0 ! First release of new Dialogue Sketch feature. 2016-12-20 16:43:10 +01:00
Zukero
6fe4d2a171 Warning hunt. Dialogue sketch I/O progress. Sketch creation from
existing Dialogue begins.
2016-12-19 18:10:25 +01:00
Kevin
1076693322 Dialogue sketches can be saved. Bug fixes in sketch export. 2016-12-19 08:51:00 +01:00
Zukero
5a9e66b7c9 Detect changes in preparation of edition of existing dialogues. 2016-12-16 15:03:57 +01:00
Zukero
b1d0175a9d Progress on Dialogue Sketch to JSON Data conversion.
Opportunistic bug fix in JSON import wizard.
2016-12-16 09:41:04 +01:00
Zukero
6ac332834d Progress on WriterMode. Project export package now create
deterministically-ordered JSON. Should make nicer diffs.
2016-12-15 19:16:53 +01:00
Zukero
32711449b2 Temporary commit 2016-10-14 17:13:03 +02:00
Zukero
c18ff9d2b4 First drafts of "Writer Mode".
Some bug fixes.
2016-09-16 15:23:00 +02:00
Zukero
ce908f0033 v0.4.8. Removed stupid feature (almost a bug) that made it painful to
handle adding spritesheets. Fixed colorfilters not showing on the
worldmap and replacements simulator. Added "display type" (a.k.a rarity)
item field in the Items comparator.
2016-08-12 15:35:17 +02:00
Zukero
1a70f87897 v0.4.7 ! 2016-08-10 18:03:11 +02:00
Zukero
c07fb4ddf3 Implemented all colorfilters in TMXMapEditor, thanks to the new
MatrixComposite that really emulates the ColorMatrixColorFilter of
Android ! Hi-fidelity filter emulation !
2016-08-10 16:20:48 +02:00
Zukero
1458fb0aaa Bug fix for the map's "outside" property that wasn't handled properly.
Added support for the new "colorfilter" map property. Due to Java2D
having no correct color filter support, only the "blackXX" values can be
previwed. "bw" and "invert" cannot, the performance cost was simply way
too high.
2016-08-08 16:31:38 +02:00
Zukero
57b8209b26 v0.4.6 ! Oh so many bugfixes... 2016-07-21 16:39:55 +02:00
Zukero
a7224755ff Fixed NPE in KeyArea creation. Rest areas can be renamed. 2016-07-19 18:49:42 +02:00
Zukero
e97168c62e v0.4.5 complete with packaging. 2016-07-19 17:57:02 +02:00
Zukero
1e8dd405c3 Addedchanges to match new datamodel in AT. Notably, ability to disable a
Map Object Group in a new game in a map, and the associated rewards
((de)activateMapObjectGroup) in dialogues that replace
(de)activateMapChangeArea.
2016-07-19 17:37:54 +02:00
Zukero
830e9de56b v0.4.5 to cope with changes to spawnareas definition in game code.
replaced gcode references by github repo.
2016-07-18 18:55:16 +02:00
Zukero
2a06002b51 Updated packaging for v0.4.4 2016-01-05 14:22:18 +01:00
Zukero
84b1b6a7eb v0.4.4 !
- Projects can now use either loadresources.xml or
loadresources_debug.xml, or none (as before). This must be selected at
project creation and cannot be changed.
- NPC and Items comparators now include both the source and altered
version of elements present in both.
- Spritesheets view should now be better laid out, as insets were not
taken into account, thus cropping a few pixels right and down.
2016-01-05 14:15:23 +01:00
Zukero
f924c481f8 v0.4.3 ! Only a bugfix on JSON import. 2016-01-01 22:59:20 +01:00
Zukero
ed004f5cfc v0.4.2 ! 2015-10-30 14:09:28 +01:00
Zukero
12ca21b9e4 Added "active" setting for SpawnAreas. Added cool tooltip to
DialogueGraphView
2015-10-30 14:02:38 +01:00
Zukero
f5c454807c Small bug fixes (started ignoring case for Spawn Group lookup, like in
the game; avoid NPE in Dialogue parser).
2015-10-30 12:50:03 +01:00
Zukero
6118fc39d8 Changed (enhanced ?) UI for Map replacement activation in simulator.
Added cool tooltip on the Map replacement simulator showing tiles used
for Ground, Objects and Above layers, as well as coordinates, taking the
active replacements into account.
2015-10-28 16:47:42 +01:00
Zukero
7d5a5008bd v0.4.1 packaging done. 2015-10-27 17:24:30 +01:00
Zukero
56b7ab4b92 v0.4.1 ! Now with ReplaceArea support and simulation tool ! 2015-10-27 17:14:15 +01:00
Zukero
0776bc4109 Added replace areas support in model (to preserve contents on map
saving)
2015-08-12 17:59:28 +02:00
Zukero
c870be2d1f Fixed missing attributes in TMX file loading and writing (sizes in
tilesets).
Added a fancy logo in the workspace selector... could look better
though.
2015-08-12 15:14:30 +02:00
Zukero
1c90d47bdf Update eclipse project's classpath. 2015-08-11 17:38:15 +02:00
95 changed files with 6877 additions and 617 deletions

View File

@@ -10,7 +10,7 @@
<classpathentry kind="lib" path="lib/prefuse.jar"/>
<classpathentry kind="lib" path="lib/rsyntaxtextarea.jar"/>
<classpathentry kind="lib" path="lib/ui.jar"/>
<classpathentry kind="lib" path="lib/AndorsTrainer_v0.1.1.jar"/>
<classpathentry kind="lib" path="lib/bsh-2.0b4.jar"/>
<classpathentry kind="lib" path="lib/AndorsTrainer_v0.1.3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

18
ATCS_JAR.jardesc Normal file
View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc>
<jar path="ATContentStudio/ATCS_v0.5.3.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/ATContentStudio/ATCS_JAR.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="true" exportOutputFolder="false">
<javaElement handleIdentifier="=ATContentStudio/res"/>
<javaElement handleIdentifier="=ATContentStudio/src"/>
<javaElement handleIdentifier="=ATContentStudio/hacked-libtiled"/>
</selectedElements>
</jardesc>

View File

@@ -29,7 +29,9 @@
package tiled.core;
import java.awt.Rectangle;
import java.util.*;
import java.util.Iterator;
import java.util.Properties;
import java.util.Vector;
/**
* The Map class is the focal point of the <code>tiled.core</code> package.

View File

@@ -28,10 +28,12 @@
package tiled.core;
import java.awt.*;
import java.util.Properties;
import java.awt.Image;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import javax.imageio.ImageIO;
/**

View File

@@ -33,8 +33,8 @@ import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**

View File

@@ -28,7 +28,7 @@
package tiled.core;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Properties;
/**
@@ -36,7 +36,7 @@ import java.util.Properties;
*/
public class Tile
{
private Image image;
private BufferedImage image;
private int id = -1;
private Properties properties;
private TileSet tileset;
@@ -76,7 +76,7 @@ public class Tile
*
* @param i the new image of the tile
*/
public void setImage(Image i) {
public void setImage(BufferedImage i) {
image = i;
}
@@ -133,7 +133,7 @@ public class Tile
*
* @return Image
*/
public Image getImage() {
public BufferedImage getImage() {
if (tileset != null && tileset.sheet != null) return tileset.sheet.getImage(getId());
return image;
}

View File

@@ -74,6 +74,7 @@ public class TileSet implements Iterable<Tile>
private Color transparentColor;
private Image tileSetImage;
public Spritesheet sheet = null;
public Rectangle sheetDimensions;
/**
* Default constructor
@@ -120,8 +121,10 @@ public class TileSet implements Iterable<Tile>
importTileBitmap(buffered, cutter);
}
public void loadFromProject(String name, TMXMap tmxMap) {
public void loadFromProject(String name, TMXMap tmxMap, int tileWidth, int tileHeight) {
sheet = tmxMap.getProject().getSpritesheet(name);
tileDimensions.width = tileWidth;
tileDimensions.height = tileHeight;
int i = 0;
Image tileImage = sheet.getImage(i);
while (tileImage != null) {
@@ -158,7 +161,7 @@ public class TileSet implements Iterable<Tile>
tilesPerRow = basicTileCutter.getTilesPerRow();
}
Image tileImage = cutter.getNextTile();
BufferedImage tileImage = cutter.getNextTile();
while (tileImage != null) {
Tile tile = new Tile();
tile.setImage(tileImage);
@@ -217,7 +220,7 @@ public class TileSet implements Iterable<Tile>
tileDimensions = new Rectangle(tileCutter.getTileDimensions());
int id = 0;
Image tileImage = tileCutter.getNextTile();
BufferedImage tileImage = tileCutter.getNextTile();
while (tileImage != null) {
Tile tile = getTile(id);
tile.setImage(tileImage);

View File

@@ -30,13 +30,14 @@ package tiled.io;
import java.awt.Color;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -222,9 +223,9 @@ public class TMXMapReader
return o;
}
private Image unmarshalImage(Node t, String baseDir) throws IOException
private BufferedImage unmarshalImage(Node t, String baseDir) throws IOException
{
Image img = null;
BufferedImage img = null;
String source = getAttributeValue(t, "source");
@@ -252,7 +253,7 @@ public class TMXMapReader
// size, somehow makes drawing of the tiles a lot
// faster on various systems (seen on Linux, Windows
// and MacOS X).
img = img.getScaledInstance(
img = (BufferedImage) img.getScaledInstance(
img.getWidth(null), img.getHeight(null),
Image.SCALE_FAST);
}
@@ -382,7 +383,10 @@ public class TMXMapReader
// case.
if (tmxMap.getProject().getSpritesheet(name) != null) {
set.loadFromProject(name, tmxMap);
set.loadFromProject(name, tmxMap, tileWidth, tileHeight);
set.sheetDimensions = new Rectangle();
set.sheetDimensions.width = getAttribute(child, "width", 0);
set.sheetDimensions.height = getAttribute(child, "height", 0);
} else {
@@ -530,7 +534,7 @@ public class TMXMapReader
Node child = children.item(i);
if ("image".equalsIgnoreCase(child.getNodeName())) {
int id = getAttribute(child, "id", -1);
Image img = unmarshalImage(child, baseDir);
BufferedImage img = unmarshalImage(child, baseDir);
tile.setImage(img);
} else if ("animation".equalsIgnoreCase(child.getNodeName())) {
// TODO: fill this in once TMXMapWriter is complete

View File

@@ -30,14 +30,32 @@ package tiled.io;
import java.awt.Color;
import java.awt.Rectangle;
import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Vector;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.GZIPOutputStream;
import tiled.core.*;
import tiled.core.AnimatedTile;
import tiled.core.Map;
import tiled.core.MapLayer;
import tiled.core.MapObject;
import tiled.core.ObjectGroup;
import tiled.core.Sprite;
import tiled.core.Tile;
import tiled.core.TileLayer;
import tiled.core.TileSet;
import tiled.io.xml.XMLWriter;
import tiled.util.Base64;
@@ -257,7 +275,11 @@ public class TMXMapWriter
if (tileBitmapFile != null) {
w.startElement("image");
w.writeAttribute("source", getRelativePath(wp, tileBitmapFile));
if (set.sheetDimensions != null) {
w.writeAttribute("width", set.sheetDimensions.width);
w.writeAttribute("height", set.sheetDimensions.height);
}
Color trans = set.getTransparentColor();
if (trans != null) {
w.writeAttribute("trans", Integer.toHexString(

View File

@@ -28,9 +28,8 @@
package tiled.io.xml;
import java.lang.String;
import java.io.Writer;
import java.io.IOException;
import java.io.Writer;
import java.util.Stack;
/**

View File

@@ -29,7 +29,6 @@
package tiled.util;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage;
/**
@@ -64,7 +63,7 @@ public class BasicTileCutter implements TileCutter
this.image = image;
}
public Image getNextTile() {
public BufferedImage getNextTile() {
if (nextY + tileHeight + tileMargin <= image.getHeight()) {
BufferedImage tile =
image.getSubimage(nextX, nextY, tileWidth, tileHeight);

View File

@@ -33,6 +33,7 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
/**

View File

@@ -29,7 +29,6 @@
package tiled.util;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage;
/**
@@ -48,7 +47,7 @@ public interface TileCutter
* @return the next tile image, or <code>null</code> when no more tile
* images are available
*/
public Image getNextTile();
public BufferedImage getNextTile();
/**
* Resets the tile cutter so that the next call to <code>getNextTile</code>

View File

@@ -27,9 +27,10 @@
package tiled.view;
import tiled.core.TileLayer;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.*;
import tiled.core.TileLayer;
/**
* An interface defining methods to render a map.

View File

@@ -27,12 +27,15 @@
package tiled.view;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import tiled.core.Map;
import tiled.core.Tile;
import tiled.core.TileLayer;
import java.awt.*;
/**
* The orthogonal map renderer. This is the most basic map renderer, dealing
* with maps that use rectangular tiles.
@@ -74,10 +77,12 @@ public class OrthogonalRenderer implements MapRenderer
final Tile tile = layer.getTileAt(x, y);
if (tile == null)
continue;
final Image image = tile.getImage();
final BufferedImage image = tile.getImage();
if (image == null)
continue;
g.drawImage(
image,
x * tileWidth,
@@ -90,4 +95,5 @@ public class OrthogonalRenderer implements MapRenderer
g.translate(-bounds.x * tileWidth, -bounds.y * tileHeight);
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -1 +1,20 @@
start "" "javaw.exe" -Xmx512M -cp "lib\jide-oss.jar;lib\ui.jar;lib\junit-4.10.jar;lib\json_simple-1.1.jar;lib\rsyntaxtextarea.jar;lib\prefuse.jar;lib\ATCS_v0.4.0.jar;lib\AndorsTrainer_v0.1.2.jar;lib\bsh-2.0b4.jar" com.gpl.rpg.atcontentstudio.ATContentStudio
@echo off
set "ATCS_DIR=%~dp0"
set "MAX_MEM=512M"
set "CP=%ATCS_DIR%lib\*"
set "JAVA=javaw.exe"
set "JAVA_OPTS="
set "ENV_FILE=%ATCS_DIR%ATCS.env.bat"
set "MAIN_CLASS=com.gpl.rpg.atcontentstudio.ATContentStudio"
if exist "%ENV_FILE%" (
call "%ENV_FILE%"
) else (
echo REM set "MAX_MEM=%MAX_MEM%">"%ENV_FILE%"
echo REM set "JAVA=%JAVA%">>"%ENV_FILE%"
echo REM set "JAVA_OPTS=%JAVA_OPTS%">>"%ENV_FILE%"
echo.>>"%ENV_FILE%"
)
start "" "%JAVA%" %JAVA_OPTS% -Xmx%MAX_MEM% -cp "%CP%" %MAIN_CLASS%

View File

@@ -1,2 +1,22 @@
#!/bin/bash
java -Xmx512M -cp lib/AndorsTrainer_v0.1.2.jar:lib/ATCS_v0.4.0.jar:lib/prefuse.jar:lib/json_simple-1.1.jar:lib/jide-oss.jar:lib/ui.jar:lib/junit-4.10.jar:lib/rsyntaxtextarea.jar:lib/bsh-2.0b4.jar com.gpl.rpg.atcontentstudio.ATContentStudio
ATCS_DIR=$(dirname $(readlink -f "$0" || greadlink -f "$0" || stat -f "$0"))
MAX_MEM=512M
CP=$(find ${ATCS_DIR}/lib/ -name '*.jar' | paste -sd: -)
JAVA=java
JAVA_OPTS=
ENV_FILE=${ATCS_DIR}/ATCS.env
MAIN_CLASS=com.gpl.rpg.atcontentstudio.ATContentStudio
if [ -f ${ENV_FILE} ]
then
source ${ENV_FILE}
else
echo "#MAX_MEM=${MAX_MEM}" > ${ENV_FILE}
echo "#JAVA=${JAVA}" >> ${ENV_FILE}
echo "#JAVA_OPTS=${JAVA_OPTS}" >> ${ENV_FILE}
echo "" >> ${ENV_FILE}
fi
export ENV_FILE
$JAVA ${JAVA_OPTS} -Xmx${MAX_MEM} -cp ${CP} ${MAIN_CLASS}

View File

@@ -1 +1,20 @@
start "" "D:\Programs\jdk1.6.0_24\\bin\javaw.exe" -Xmx512M -cp "lib\jide-oss.jar;lib\ui.jar;lib\junit-4.10.jar;lib\json_simple-1.1.jar;lib\rsyntaxtextarea.jar;lib\ATCS_v0.0.4.jar;lib\AndorsTrainer_V0.1.2.jar" com.gpl.rpg.atcontentstudio.ATContentStudio
@echo off
set "ATCS_DIR=%~dp0"
set "MAX_MEM=512M"
set "CP=%ATCS_DIR%lib\*"
set "JAVA=javaw.exe"
set "JAVA_OPTS="
set "ENV_FILE=%ATCS_DIR%ATCS.env.bat"
set "MAIN_CLASS=com.gpl.rpg.atcontentstudio.ATContentStudio"
if exist "%ENV_FILE%" (
call "%ENV_FILE%"
) else (
echo REM set "MAX_MEM=%MAX_MEM%">"%ENV_FILE%"
echo REM set "JAVA=%JAVA%">>"%ENV_FILE%"
echo REM set "JAVA_OPTS=%JAVA_OPTS%">>"%ENV_FILE%"
echo.>>"%ENV_FILE%"
)
start "" "%JAVA%" %JAVA_OPTS% -Xmx%MAX_MEM% -cp "%CP%" %MAIN_CLASS%

View File

@@ -1,7 +1,8 @@
!include MUI2.nsh
!define VERSION "0.4.0"
!define JAVA_BIN "java"
!define VERSION "0.5.3"
!define TRAINER_VERSION "0.1.3"
!define JAVA_BIN "javaw"
Name "Andor's Trail Content Studio v${VERSION}"
OutFile "ATCS_v${VERSION}_Setup.exe"
@@ -54,16 +55,37 @@ Section install
SetOutPath $INSTDIR
file "ATCS.ico"
Delete "$INSTDIR\lib\*"
Call GetJRE
Pop $R0
FileOpen $9 "ATCS.cmd" w
FileWrite $9 'start "" "$R0" -Xmx512M -cp "lib\AndorsTrainer_v0.1.1.jar;lib\jide-oss.jar;lib\ui.jar;lib\junit-4.10.jar;lib\json_simple-1.1.jar;lib\rsyntaxtextarea.jar;lib\prefuse.jar;lib\bsh-2.0b4.jar;lib\ATCS_v${VERSION}.jar" com.gpl.rpg.atcontentstudio.ATContentStudio'
FileWrite $9 '@echo off$\r$\n'
FileWrite $9 '$\r$\n'
FileWrite $9 'set "ATCS_DIR=%~dp0"$\r$\n'
FileWrite $9 'set "MAX_MEM=512M"$\r$\n'
FileWrite $9 'set "CP=%ATCS_DIR%lib\*"$\r$\n'
FileWrite $9 'set "JAVA=$R0"$\r$\n'
FileWrite $9 'set "JAVA_OPTS="$\r$\n'
FileWrite $9 'set "ENV_FILE=%ATCS_DIR%ATCS.env.bat"$\r$\n'
FileWrite $9 'set "MAIN_CLASS=com.gpl.rpg.atcontentstudio.ATContentStudio"$\r$\n'
FileWrite $9 '$\r$\n'
FileWrite $9 'if exist "%ENV_FILE%" ($\r$\n'
FileWrite $9 ' call "%ENV_FILE%"$\r$\n'
FileWrite $9 ') else ($\r$\n'
FileWrite $9 ' echo REM set "MAX_MEM=%MAX_MEM%">"%ENV_FILE%"$\r$\n'
FileWrite $9 ' echo REM set "JAVA=%JAVA%">>"%ENV_FILE%"$\r$\n'
FileWrite $9 ' echo REM set "JAVA_OPTS=%JAVA_OPTS%">>"%ENV_FILE%"$\r$\n'
FileWrite $9 ' echo.>>"%ENV_FILE%"$\r$\n'
FileWrite $9 ')$\r$\n'
FileWrite $9 '$\r$\n'
FileWrite $9 'start "" "%JAVA%" %JAVA_OPTS% -Xmx%MAX_MEM% -cp "%CP%" %MAIN_CLASS%$\r$\n'
FileClose $9
SetOutPath "$INSTDIR\lib\"
file "jide-oss.jar"
file "ui.jar"
file "AndorsTrainer_v0.1.2.jar"
file "AndorsTrainer_v${TRAINER_VERSION}.jar"
file "junit-4.10.jar"
file "json_simple-1.1.jar"
file "ATCS_v${VERSION}.jar"
@@ -93,13 +115,15 @@ Section uninstall
Delete "$INSTDIR\lib\ui.jar"
Delete "$INSTDIR\lib\junit-4.10.jar"
Delete "$INSTDIR\lib\json_simple-1.1.jar"
Delete "$INSTDIR\lib\AndorsTrainer_v0.1.2.jar"
Delete "$INSTDIR\lib\AndorsTrainer_v${TRAINER_VERSION}.jar"
Delete "$INSTDIR\lib\ATCS_v${VERSION}.jar"
Delete "$INSTDIR\lib\rsyntaxtextarea.jar"
Delete "$INSTDIR\lib\prefuse.jar"
Delete "$INSTDIR\lib\bsh-2.0b4.jar"
RMDir "$INSTDIR\lib\"
Delete "$INSTDIR\ATCS.ico"
Delete "$INSTDIR\ATCS.cmd"
Delete "$INSTDIR\ATCS.env.bat"
Delete "$INSTDIR\Uninstall.exe"

View File

@@ -1,5 +1,6 @@
atcs.spritesheet.actorconditions_1.category=actorcondition
atcs.spritesheet.actorconditions_2.category=actorcondition
atcs.spritesheet.actorconditions_japozero.category=actorcondition
atcs.spritesheet.items_armours.category=item
atcs.spritesheet.items_armours_2.category=item
atcs.spritesheet.items_armours_3.category=item
@@ -10,6 +11,7 @@ atcs.spritesheet.items_jewelry.category=item
atcs.spritesheet.items_rings_1.category=item
atcs.spritesheet.items_necklaces_1.category=item
atcs.spritesheet.items_consumables.category=item
atcs.spritesheet.items_japozero.category=item
atcs.spritesheet.items_books.category=item
atcs.spritesheet.items_misc.category=item
atcs.spritesheet.items_misc_2.category=item

View File

@@ -5,10 +5,14 @@ import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
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;
@@ -18,7 +22,7 @@ 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 = "v0.4.0";
public static final String APP_VERSION = "v0.5.3";
public static boolean STARTED = false;
public static StudioFrame frame = null;
@@ -30,6 +34,8 @@ public class ATContentStudio {
ConfigCache.init();
Logger.getLogger(ExpressionParser.class.getName()).setLevel(Level.OFF);
try {
String laf = ConfigCache.getFavoriteLaFClassName();
if (laf == null) laf = UIManager.getSystemLookAndFeelClassName();

View File

@@ -2,11 +2,12 @@ package com.gpl.rpg.atcontentstudio;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class Notification {
public static List<Notification> notifs = new ArrayList<Notification>();
private static List<NotificationListener> listeners = new ArrayList<NotificationListener>();
private static List<NotificationListener> listeners = new CopyOnWriteArrayList<NotificationListener>();
public static boolean showS = true, showI = true, showW = true, showE = true;
static {

View File

@@ -4,10 +4,10 @@ import java.awt.Image;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.tree.TreeNode;
@@ -32,7 +32,7 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
public boolean writable = false;
//List of objects whose transition to "linked" state made them point to this instance.
private Map<GameDataElement, Integer> backlinks = new HashMap<GameDataElement, Integer>();
private Map<GameDataElement, Integer> backlinks = new ConcurrentHashMap<GameDataElement, Integer>();
public String id = null;
@@ -99,7 +99,7 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
@Override
public Project getProject() {
return parent.getProject();
return parent == null ? null : parent.getProject();
}

View File

@@ -2,29 +2,49 @@ 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;
import com.gpl.rpg.atcontentstudio.model.maps.Worldmap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
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;
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 transient GameDataSet gameData;
public transient TMXMapSet gameMaps;
public transient SpriteSheetSet gameSprites;
public transient Worldmap worldmap;
public transient WriterModeDataSet writerModeDataSet;
private transient SavedSlotCollection v;
public static enum Type {
@@ -39,6 +59,8 @@ public class GameSource implements ProjectTreeNode, Serializable {
public transient Project parent = null;
public transient Map<String, List<String>> referencedSourceFiles = null;
public GameSource(File folder, Project parent) {
this.parent = parent;
this.baseFolder = folder;
@@ -59,6 +81,15 @@ public class GameSource implements ProjectTreeNode, Serializable {
}
public void initData() {
if (type == Type.source) {
if (parent.sourceSetToUse == ResourceSet.gameData || parent.sourceSetToUse == ResourceSet.debugData) {
referencedSourceFiles = new LinkedHashMap<String, List<String>>();
readResourceList();
}
}
if (type == Type.created) {
this.writerModeDataSet = new WriterModeDataSet(this);
}
this.gameData = new GameDataSet(this);
this.gameMaps = new TMXMapSet(this);
this.gameSprites = new SpriteSheetSet(this);
@@ -68,6 +99,61 @@ public class GameSource implements ProjectTreeNode, Serializable {
v.add(gameMaps);
v.add(gameSprites);
v.add(worldmap);
if (type == Type.created) {
v.add(writerModeDataSet);
}
}
public void readResourceList() {
File xmlFile = null;
if (parent.sourceSetToUse == ResourceSet.gameData) {
xmlFile = new File(baseFolder, DEFAULT_REL_PATH_FOR_GAME_RESOURCE);
} else if (parent.sourceSetToUse == ResourceSet.debugData) {
xmlFile = new File(baseFolder, DEFAULT_REL_PATH_FOR_DEBUG_RESOURCE);
} else {
return;
}
if (!xmlFile.exists()) return;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document doc;
try {
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
factory.setExpandEntityReferences(false);
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource insrc = new InputSource(new FileInputStream(xmlFile));
// insrc.setSystemId("http://worldmap/");
insrc.setEncoding("UTF-8");
doc = builder.parse(insrc);
Element root = (Element) doc.getElementsByTagName("resources").item(0);
if (root != null) {
NodeList arraysList = root.getElementsByTagName("array");
if (arraysList != null) {
for (int i = 0; i < arraysList.getLength(); i++) {
Element arrayNode = (Element) arraysList.item(i);
String name = arrayNode.getAttribute("name");
List<String> arrayContents = new ArrayList<String>();
NodeList arrayItems = arrayNode.getElementsByTagName("item");
if (arrayItems != null) {
for (int j = 0; j < arrayItems.getLength(); j++) {
arrayContents.add(((Element)arrayItems.item(j)).getTextContent());
}
referencedSourceFiles.put(name, arrayContents);
}
}
}
}
} catch (SAXException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override

View File

@@ -9,7 +9,8 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -44,6 +45,7 @@ import com.gpl.rpg.atcontentstudio.model.maps.Worldmap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.saves.SavedGamesSet;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
import com.gpl.rpg.atcontentstudio.utils.FileUtils;
@@ -73,10 +75,19 @@ public class Project implements ProjectTreeNode, Serializable {
public transient Workspace parent;
public Properties knownSpritesheetsProperties = null;
public static enum ResourceSet {
gameData,
debugData,
allFiles
}
public ResourceSet sourceSetToUse = ResourceSet.allFiles;
public Project(Workspace w, String name, File source) {
public Project(Workspace w, String name, File source, ResourceSet sourceSet) {
this.parent = w;
this.name = name;
this.sourceSetToUse = sourceSet;
//CREATE PROJECT
baseFolder = new File(w.baseFolder, name+File.separator);
@@ -210,14 +221,16 @@ public class Project implements ProjectTreeNode, Serializable {
public void refreshTransients(Workspace w) {
this.parent = w;
if (knownSpritesheetsProperties == null) {
try {
knownSpritesheetsProperties = new Properties();
knownSpritesheetsProperties.load(Project.class.getResourceAsStream("/spritesheets.properties"));
} catch (IOException e) {
Notification.addWarn("Unable to load default spritesheets properties.");
e.printStackTrace();
}
try {
knownSpritesheetsProperties = new Properties();
knownSpritesheetsProperties.load(Project.class.getResourceAsStream("/spritesheets.properties"));
} catch (IOException e) {
Notification.addWarn("Unable to load default spritesheets properties.");
e.printStackTrace();
}
if (sourceSetToUse == null) {
sourceSetToUse = ResourceSet.allFiles;
}
// long l = new Date().getTime();
@@ -477,6 +490,21 @@ public class Project implements ProjectTreeNode, Serializable {
return null;
}
public int getItemCountIncludingAltered() {
return createdContent.gameData.items.size() + alteredContent.gameData.items.size() + baseContent.gameData.items.size();
}
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()){
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()));
}
return null;
}
public int getItemIndex(Item item) {
if (item.getDataType() == GameSource.Type.created) {
return createdContent.gameData.items.getIndex(item);
@@ -522,6 +550,13 @@ public class Project implements ProjectTreeNode, Serializable {
return gde;
}
public NPC getNPCIgnoreCase(String id) {
NPC gde = createdContent.gameData.getNPCIgnoreCase(id);
if (gde == null) gde = alteredContent.gameData.getNPCIgnoreCase(id);
if (gde == null) gde = baseContent.gameData.getNPCIgnoreCase(id);
return gde;
}
public int getNPCCount() {
return createdContent.gameData.npcs.size() + baseContent.gameData.npcs.size();
}
@@ -535,6 +570,21 @@ public class Project implements ProjectTreeNode, Serializable {
return null;
}
public int getNPCCountIncludingAltered() {
return createdContent.gameData.npcs.size() + alteredContent.gameData.npcs.size() + baseContent.gameData.npcs.size();
}
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()){
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()));
}
return null;
}
public int getNPCIndex(NPC npc) {
if (npc.getDataType() == GameSource.Type.created) {
return createdContent.gameData.npcs.getIndex(npc);
@@ -615,6 +665,26 @@ public class Project implements ProjectTreeNode, Serializable {
return sheet;
}
public int getSpritesheetCount() {
return createdContent.gameSprites.spritesheets.size() + baseContent.gameSprites.spritesheets.size();
}
public Spritesheet getSpritesheet(int index) {
if (index < createdContent.gameSprites.spritesheets.size()) {
return createdContent.gameSprites.spritesheets.get(index);
} else if (index < getQuestCount()){
return getSpritesheet(baseContent.gameSprites.spritesheets.get(index - createdContent.gameSprites.spritesheets.size()).id);
}
return null;
}
public int getSpritesheetIndex(Spritesheet spritesheet) {
if (spritesheet.getDataType() == GameSource.Type.created) {
return createdContent.gameSprites.spritesheets.indexOf(spritesheet);
} else {
return createdContent.gameSprites.spritesheets.size() + baseContent.gameSprites.spritesheets.indexOf(baseContent.gameSprites.getSpritesheet(spritesheet.id));
}
}
public TMXMap getMap(String id) {
TMXMap map = createdContent.gameMaps.getMap(id);
@@ -644,6 +714,20 @@ public class Project implements ProjectTreeNode, Serializable {
}
}
public int getWriterSketchCount() {
return createdContent.writerModeDataSet.getChildCount();
}
public WriterModeData getWriterSketch(String id) {
return createdContent.writerModeDataSet.getWriterSketch(id);
}
public WriterModeData getWriterSketch(int index) {
if (index < createdContent.writerModeDataSet.getChildCount()) {
return createdContent.writerModeDataSet.get(index);
}
return null;
}
@Override
public Project getProject() {
@@ -736,7 +820,7 @@ public class Project implements ProjectTreeNode, Serializable {
/**
*
* @param node. Before calling this method, make sure that no other node with the same class exist in either created or altered.
* @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) {
node.writable = true;
@@ -747,13 +831,69 @@ public class Project implements ProjectTreeNode, Serializable {
}
existingNode.getBacklinks().clear();
node.writable = true;
node.state = GameDataElement.State.created;
alteredContent.gameData.addElement(node);
node.link();
node.state = GameDataElement.State.created;
} else {
createdContent.gameData.addElement(node);
node.state = GameDataElement.State.created;
node.link();
node.state = GameDataElement.State.created;
}
fireElementAdded(node, getNodeIndex(node));
}
/**
*
* @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) {
for (JSONElement node : nodes) {
//Already added.
if (node.getProject() != null) continue;
node.writable = true;
if (getGameDataElement(node.getClass(), node.id) != null) {
GameDataElement existingNode = getGameDataElement(node.getClass(), node.id);
for (GameDataElement backlink : existingNode.getBacklinks()) {
backlink.elementChanged(existingNode, node);
}
existingNode.getBacklinks().clear();
node.writable = true;
alteredContent.gameData.addElement(node);
} else {
createdContent.gameData.addElement(node);
}
}
for (JSONElement node : nodes) {
node.link();
node.state = GameDataElement.State.created;
fireElementAdded(node, getNodeIndex(node));
}
}
/**
*
* @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) {
node.writable = true;
if (getMap(node.id) != null) {
GameDataElement existingNode = getMap(node.id);
for (GameDataElement backlink : existingNode.getBacklinks()) {
backlink.elementChanged(existingNode, node);
}
existingNode.getBacklinks().clear();
node.writable = true;
node.tmxFile = new File(alteredContent.baseFolder, node.tmxFile.getName());
node.parent = alteredContent.gameMaps;
alteredContent.gameMaps.addMap(node);
node.link();
node.state = GameDataElement.State.created;
} else {
node.tmxFile = new File(createdContent.baseFolder, node.tmxFile.getName());
node.parent = createdContent.gameMaps;
createdContent.gameMaps.addMap(node);
node.link();
node.state = GameDataElement.State.created;
}
fireElementAdded(node, getNodeIndex(node));
}
@@ -794,6 +934,15 @@ public class Project implements ProjectTreeNode, Serializable {
fireElementAdded(node, getNodeIndex(node));
}
public void createWriterSketch(WriterModeData node) {
node.writable = true;
createdContent.writerModeDataSet.add(node);
node.link();
fireElementAdded(node, getNodeIndex(node));
}
@Override
public GameDataSet getDataSet() {
@@ -833,7 +982,7 @@ public class Project implements ProjectTreeNode, Serializable {
int index = -1;
while (--i >= 0) {
NPC npc = getNPC(i);
if (spawngroup_id.equals(npc.spawngroup_id)) {
if (spawngroup_id.equalsIgnoreCase(npc.spawngroup_id)) {
for (NPC present : result) {
if (present.id.equals(npc.id)) {
alreadyAdded = true;
@@ -851,7 +1000,7 @@ public class Project implements ProjectTreeNode, Serializable {
}
if (result.isEmpty()) {
//Fallback case. A single NPC does not declare a spawn group, but is referred by its ID in maps' spawn areas.
NPC npc = getNPC(spawngroup_id);
NPC npc = getNPCIgnoreCase(spawngroup_id);
if (npc != null) result.add(npc);
}
return result;
@@ -945,8 +1094,8 @@ public class Project implements ProjectTreeNode, Serializable {
@SuppressWarnings("rawtypes")
public void writeAltered(GameDataCategory<? extends JSONElement> altered, GameDataCategory<? extends JSONElement> source, Class<? extends JSONElement> gdeClass, File targetFolder) {
Set<String> alteredFileNames = new HashSet<String>();
Map<String, List<Map>> toWrite = new HashMap<String, List<Map>>();
Set<String> alteredFileNames = new LinkedHashSet<String>();
Map<String, List<Map>> toWrite = new LinkedHashMap<String, List<Map>>();
for (JSONElement gde : altered) {
alteredFileNames.add(gde.jsonFile.getName());
}
@@ -982,6 +1131,7 @@ public class Project implements ProjectTreeNode, Serializable {
}

View File

@@ -21,50 +21,54 @@ import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.SettingsSave;
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
import com.gpl.rpg.atcontentstudio.ui.ProjectsTree.ProjectsTreeModel;
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
public class Workspace implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = 7938633033601384956L;
public static final String WS_SETTINGS_FILE = ".workspace";
public static Workspace activeWorkspace;
public Preferences preferences = new Preferences();
public File baseFolder;
public File settingsFile;
public transient WorkspaceSettings settings;
public transient List<ProjectTreeNode> projects = new ArrayList<ProjectTreeNode>();
public Set<String> projectsName = new HashSet<String>();
public Map<String, Boolean> projectsOpenByName = new HashMap<String, Boolean>();
public Set<File> knownMapSourcesFolders = new HashSet<File>();
public transient ProjectsTreeModel projectsTreeModel = null;
public Workspace(File workspaceRoot) {
baseFolder = workspaceRoot;
if (!workspaceRoot.exists()) {
try {
workspaceRoot.mkdir();
} catch (SecurityException e) {
Notification.addError("Error creating workspace directory: "+e.getMessage());
Notification.addError("Error creating workspace directory: "
+ e.getMessage());
e.printStackTrace();
}
}
settings = new WorkspaceSettings(this);
settingsFile = new File(workspaceRoot, WS_SETTINGS_FILE);
if (!settingsFile.exists()) {
try {
settingsFile.createNewFile();
} catch (IOException e) {
Notification.addError("Error creating workspace datafile: "+e.getMessage());
Notification.addError("Error creating workspace datafile: "
+ e.getMessage());
e.printStackTrace();
}
}
Notification.addSuccess("New workspace created: "+workspaceRoot.getAbsolutePath());
Notification.addSuccess("New workspace created: "
+ workspaceRoot.getAbsolutePath());
save();
}
public static void setActive(File workspaceRoot) {
Workspace w = null;
@@ -81,12 +85,13 @@ public class Workspace implements ProjectTreeNode, Serializable {
}
activeWorkspace = w;
}
public static void saveActive() {
activeWorkspace.save();
}
public void save() {
settings.save();
SettingsSave.saveInstance(this, settingsFile, "Workspace");
}
@@ -94,82 +99,104 @@ public class Workspace implements ProjectTreeNode, Serializable {
public Enumeration<ProjectTreeNode> children() {
return Collections.enumeration(projects);
}
@Override
public boolean getAllowsChildren() {
return true;
}
@Override
public TreeNode getChildAt(int arg0) {
return projects.get(arg0);
}
@Override
public int getChildCount() {
return projects.size();
}
@Override
public int getIndex(TreeNode arg0) {
return projects.indexOf(arg0);
}
@Override
public TreeNode getParent() {
return null;
}
@Override
public boolean isLeaf() {
return false;
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0, this);
if (projectsTreeModel != null) projectsTreeModel.insertNode(new TreePath(path.toArray()));
if (projectsTreeModel != null)
projectsTreeModel.insertNode(new TreePath(path.toArray()));
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0, this);
if (projectsTreeModel != null) projectsTreeModel.changeNode(new TreePath(path.toArray()));
ATContentStudio.frame.editorChanged(path.get(path.size() - 1));
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0, this);
if (projectsTreeModel != null) projectsTreeModel.removeNode(new TreePath(path.toArray()));
if (projectsTreeModel != null)
projectsTreeModel.removeNode(new TreePath(path.toArray()));
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
for (ProjectTreeNode node : projects) {
if (node != null) node.notifyCreated();
if (node != null)
node.notifyCreated();
}
}
@Override
public String getDesc() {
return "Workspace: "+baseFolder.getAbsolutePath();
return "Workspace: " + baseFolder.getAbsolutePath();
}
public static void createProject(final String projectName, final File gameSourceFolder) {
WorkerDialog.showTaskMessage("Creating project "+projectName+"...", ATContentStudio.frame, new Runnable() {
@Override
public void run() {
if (activeWorkspace.projectsName.contains(projectName)) {
Notification.addError("A project named "+projectName+" already exists in this workspace.");
return;
}
Project p = new Project(activeWorkspace, projectName, gameSourceFolder);
activeWorkspace.projects.add(p);
activeWorkspace.projectsName.add(projectName);
activeWorkspace.projectsOpenByName.put(projectName, p.open);
activeWorkspace.knownMapSourcesFolders.add(gameSourceFolder);
p.notifyCreated();
Notification.addSuccess("Project "+projectName+" successfully created");
saveActive();
}
});
public static void createProject(final String projectName,
final File gameSourceFolder, final Project.ResourceSet sourceSet) {
WorkerDialog.showTaskMessage("Creating project " + projectName + "...",
ATContentStudio.frame, new Runnable() {
@Override
public void run() {
if (activeWorkspace.projectsName.contains(projectName)) {
Notification.addError("A project named "
+ projectName
+ " already exists in this workspace.");
return;
}
Project p = new Project(activeWorkspace, projectName,
gameSourceFolder, sourceSet);
activeWorkspace.projects.add(p);
activeWorkspace.projectsName.add(projectName);
activeWorkspace.projectsOpenByName.put(projectName,
p.open);
activeWorkspace.knownMapSourcesFolders
.add(gameSourceFolder);
p.notifyCreated();
Notification.addSuccess("Project " + projectName
+ " successfully created");
saveActive();
}
});
}
public static void closeProject(Project p) {
int index = activeWorkspace.projects.indexOf(p);
if (index < 0) {
Notification.addError("Cannot close unknown project "+p.name);
Notification.addError("Cannot close unknown project " + p.name);
return;
}
p.close();
@@ -179,28 +206,33 @@ public class Workspace implements ProjectTreeNode, Serializable {
cp.notifyCreated();
saveActive();
}
public static void openProject(final ClosedProject cp) {
WorkerDialog.showTaskMessage("Opening project "+cp.name+"...", ATContentStudio.frame, new Runnable() {
@Override
public void run() {
int index = activeWorkspace.projects.indexOf(cp);
if (index < 0) {
Notification.addError("Cannot open unknown project "+cp.name);
return;
}
cp.childrenRemoved(new ArrayList<ProjectTreeNode>());
Project p = Project.fromFolder(activeWorkspace, new File(activeWorkspace.baseFolder, cp.name));
p.open();
activeWorkspace.projects.set(index, p);
activeWorkspace.projectsOpenByName.put(p.name, true);
p.notifyCreated();
saveActive();
}
});
WorkerDialog.showTaskMessage("Opening project " + cp.name + "...",
ATContentStudio.frame, new Runnable() {
@Override
public void run() {
int index = activeWorkspace.projects.indexOf(cp);
if (index < 0) {
Notification
.addError("Cannot open unknown project "
+ cp.name);
return;
}
cp.childrenRemoved(new ArrayList<ProjectTreeNode>());
Project p = Project.fromFolder(activeWorkspace,
new File(activeWorkspace.baseFolder, cp.name));
p.open();
activeWorkspace.projects.set(index, p);
activeWorkspace.projectsOpenByName.put(p.name, true);
p.notifyCreated();
saveActive();
}
});
}
public void refreshTransients() {
this.settings = new WorkspaceSettings(this);
this.projects = new ArrayList<ProjectTreeNode>();
Set<String> projectsFailed = new HashSet<String>();
for (String projectName : projectsName) {
@@ -211,11 +243,16 @@ public class Workspace implements ProjectTreeNode, Serializable {
if (p != null) {
projects.add(p);
} else {
Notification.addError("Failed to open project "+projectName+". Removing it from workspace (not from filesystem though).");
Notification
.addError("Failed to open project "
+ projectName
+ ". Removing it from workspace (not from filesystem though).");
projectsFailed.add(projectName);
}
} else {
Notification.addError("Unable to find project "+projectName+"'s root folder. Removing it from workspace");
Notification.addError("Unable to find project "
+ projectName
+ "'s root folder. Removing it from workspace");
projectsFailed.add(projectName);
}
} else {
@@ -228,21 +265,31 @@ public class Workspace implements ProjectTreeNode, Serializable {
}
notifyCreated();
}
@Override
public Project getProject() {
return null;
}
@Override
public Image getIcon() {return null;}
@Override
public Image getClosedIcon() {return null;}
@Override
public Image getLeafIcon() {return null;}
@Override
public Image getOpenIcon() {return null;}
@Override
public Image getIcon() {
return null;
}
@Override
public Image getClosedIcon() {
return null;
}
@Override
public Image getLeafIcon() {
return null;
}
@Override
public Image getOpenIcon() {
return null;
}
public static void deleteProject(ClosedProject cp) {
cp.childrenRemoved(new ArrayList<ProjectTreeNode>());
@@ -250,37 +297,41 @@ public class Workspace implements ProjectTreeNode, Serializable {
activeWorkspace.projectsOpenByName.remove(cp.name);
activeWorkspace.projectsName.remove(cp.name);
if (delete(new File(activeWorkspace.baseFolder, cp.name))) {
Notification.addSuccess("Closed project "+cp.name+" successfully deleted.");
Notification.addSuccess("Closed project " + cp.name
+ " successfully deleted.");
} else {
Notification.addError("Error while deleting closed project "+cp.name+". Files may remain in the workspace.");
Notification.addError("Error while deleting closed project "
+ cp.name + ". Files may remain in the workspace.");
}
cp = null;
saveActive();
}
public static void deleteProject(Project p) {
p.childrenRemoved(new ArrayList<ProjectTreeNode>());
activeWorkspace.projects.remove(p);
activeWorkspace.projectsOpenByName.remove(p.name);
activeWorkspace.projectsName.remove(p.name);
if (delete(p.baseFolder)) {
Notification.addSuccess("Project "+p.name+" successfully deleted.");
Notification.addSuccess("Project " + p.name
+ " successfully deleted.");
} else {
Notification.addError("Error while deleting project "+p.name+". Files may remain in the workspace.");
Notification.addError("Error while deleting project " + p.name
+ ". Files may remain in the workspace.");
}
p = null;
saveActive();
}
private static boolean delete(File f) {
boolean b = true;
if (f.isDirectory()) {
for (File c : f.listFiles())
b &= delete(c);
}
return b&= f.delete();
return b &= f.delete();
}
@Override
public GameDataSet getDataSet() {
return null;
@@ -290,11 +341,10 @@ public class Workspace implements ProjectTreeNode, Serializable {
public Type getDataType() {
return null;
}
@Override
public boolean isEmpty() {
return projects.isEmpty();
}
}

View File

@@ -0,0 +1,204 @@
package com.gpl.rpg.atcontentstudio.model;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
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 org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
public class WorkspaceSettings {
public static final String VERSION_KEY = "ATCS_Version";
public static final String FILENAME = "workspace_settings.json";
public static final int SETTINGS_VERSION = 1;
public Workspace parent;
public File file;
public static Boolean DEFAULT_USE_SYS_MAP_EDITOR = true;
public Setting<Boolean> useSystemDefaultMapEditor = new PrimitiveSetting<Boolean>("useSystemDefaultMapEditor", DEFAULT_USE_SYS_MAP_EDITOR);
public static String DEFAULT_MAP_EDITOR_COMMAND = "tiled";
public Setting<String> mapEditorCommand = new PrimitiveSetting<String>("mapEditorCommand", DEFAULT_MAP_EDITOR_COMMAND);
public static Boolean DEFAULT_USE_SYS_IMG_VIEWER = true;
public Setting<Boolean> useSystemDefaultImageViewer = new PrimitiveSetting<Boolean>("useSystemDefaultImageViewer", DEFAULT_USE_SYS_IMG_VIEWER);
public static Boolean DEFAULT_USE_SYS_IMG_EDITOR = false;
public Setting<Boolean> useSystemDefaultImageEditor = new PrimitiveSetting<Boolean>("useSystemDefaultImageEditor", DEFAULT_USE_SYS_IMG_EDITOR);
public static String DEFAULT_IMG_EDITOR_COMMAND = "gimp";
public Setting<String> imageEditorCommand = new PrimitiveSetting<String>("imageEditorCommand", DEFAULT_IMG_EDITOR_COMMAND);
public List<Setting<? extends Object>> settings = new ArrayList<Setting<? extends Object>>();
public WorkspaceSettings(Workspace parent) {
this.parent = parent;
settings.add(useSystemDefaultMapEditor);
settings.add(mapEditorCommand);
settings.add(useSystemDefaultImageViewer);
settings.add(useSystemDefaultImageEditor);
settings.add(imageEditorCommand);
file = new File(parent.baseFolder, FILENAME);
if (file.exists()) {
load(file);
}
}
public void load(File f) {
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(f);
@SuppressWarnings("rawtypes")
Map jsonSettings = (Map) parser.parse(reader);
Integer version = (Integer) jsonSettings.get(VERSION_KEY);
if (version != null) {
if (version >= 1) {
loadv1(jsonSettings);
}
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing workspace settings: "+e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing workspace settings: "+e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing workspace settings: "+e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("rawtypes")
private void loadv1(Map jsonSettings) {
for (Setting s : settings) {
s.readFromJson(jsonSettings);
}
}
@SuppressWarnings("unchecked")
public void save() {
@SuppressWarnings("rawtypes")
Map json = new LinkedHashMap();
for (Setting<? extends Object> s : settings) {
s.saveToJson(json);
}
if (json.isEmpty()) {
//Everything is default.
file.delete();
return;
}
json.put(VERSION_KEY, SETTINGS_VERSION);
StringWriter writer = new JsonPrettyWriter();
try {
JSONObject.writeJSONString(json, writer);
} catch (IOException e) {
//Impossible with a StringWriter
}
String toWrite = writer.toString();
try {
FileWriter w = new FileWriter(file);
w.write(toWrite);
w.close();
Notification.addSuccess("Workspace settings saved.");
} catch (IOException e) {
Notification.addError("Error while saving workspace settings : "+e.getMessage());
e.printStackTrace();
}
}
public void resetDefault() {
for (Setting<? extends Object> s : settings) {
s.resetDefault();
}
}
public abstract class Setting<X extends Object> {
public String id;
public X value, defaultValue;
public void setCurrentValue(X value) {
this.value = value;
}
public X getCurrentValue() {
return value;
}
public X getDefaultValue() {
return defaultValue;
}
public void resetDefault() {
value = defaultValue;
}
public abstract void readFromJson(Map json);
@SuppressWarnings({ "rawtypes", "unchecked" })
public void saveToJson(Map json) {
if (!defaultValue.equals(value)) json.put(id, value);
}
}
public class PrimitiveSetting<X extends Object> extends Setting<X> {
public PrimitiveSetting(String id, X defaultValue) {
this.id = id;
this.value = this.defaultValue = defaultValue;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void readFromJson(Map json) {
if (json.get(id) != null) value = (X)json.get(id);
}
}
public class ListSetting<X extends Object> extends Setting<List<X>> {
public ListSetting(String id, List<X> defaultValue) {
this.id = id;
this.value = this.defaultValue = defaultValue;
}
@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);
}
}
}
}
}

View File

@@ -5,7 +5,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -20,6 +20,8 @@ import com.gpl.rpg.atcontentstudio.model.GameSource;
public class ActorCondition extends JSONElement {
private static final long serialVersionUID = -3969824899972048507L;
public static final Integer CLEAR_AC_MAGNITUDE = -99;
// Available from init state
//public String id; inherited.
@@ -86,7 +88,7 @@ public class ActorCondition extends JSONElement {
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+display_name+" ("+id+")";
return ((this.state == State.modified || this.state == State.created) ? "*" : "")+display_name+" ("+id+")";
}
@SuppressWarnings("rawtypes")
@@ -147,7 +149,7 @@ public class ActorCondition extends JSONElement {
public void parse(Map aCondJson) {
if (aCondJson.get("category") != null) this.category = ACCategory.valueOf((String) aCondJson.get("category"));
this.positive = JSONElement.getInteger((Number) aCondJson.get("positive"));
this.positive = JSONElement.getInteger((Number) aCondJson.get("isPositive"));
Map abilityEffect = (Map) aCondJson.get("abilityEffect");
if (abilityEffect != null) {
this.constant_ability_effect = new AbilityEffect();
@@ -264,18 +266,18 @@ public class ActorCondition extends JSONElement {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map jsonAC = new HashMap();
Map jsonAC = new LinkedHashMap();
jsonAC.put("id", this.id);
if (this.icon_id != null) jsonAC.put("iconID", this.icon_id);
if (this.display_name != null) jsonAC.put("name", this.display_name);
if (this.category != null) jsonAC.put("category", this.category.toString());
if (this.positive != null && this.positive == 1) jsonAC.put("positive", this.positive);
if (this.stacking != null && this.stacking == 1) jsonAC.put("stacking", this.stacking);
if (this.positive != null && this.positive == 1) jsonAC.put("isPositive", this.positive);
if (this.stacking != null && this.stacking == 1) jsonAC.put("isStacking", this.stacking);
if (this.round_effect != null) {
Map jsonRound = new HashMap();
Map jsonRound = new LinkedHashMap();
if (this.round_effect.visual_effect != null) jsonRound.put("visualEffectID", this.round_effect.visual_effect);
if (this.round_effect.hp_boost_min != null || this.round_effect.hp_boost_max != null) {
Map jsonHP = new HashMap();
Map jsonHP = new LinkedHashMap();
if (this.round_effect.hp_boost_min != null) jsonHP.put("min", this.round_effect.hp_boost_min);
else jsonHP.put("min", 0);
if (this.round_effect.hp_boost_max != null) jsonHP.put("max", this.round_effect.hp_boost_max);
@@ -283,7 +285,7 @@ public class ActorCondition extends JSONElement {
jsonRound.put("increaseCurrentHP", jsonHP);
}
if (this.round_effect.ap_boost_min != null || this.round_effect.ap_boost_max != null) {
Map jsonAP = new HashMap();
Map jsonAP = new LinkedHashMap();
if (this.round_effect.ap_boost_min != null) jsonAP.put("min", this.round_effect.ap_boost_min);
else jsonAP.put("min", 0);
if (this.round_effect.ap_boost_max != null) jsonAP.put("max", this.round_effect.ap_boost_max);
@@ -293,10 +295,10 @@ public class ActorCondition extends JSONElement {
jsonAC.put("roundEffect", jsonRound);
}
if (this.full_round_effect != null) {
Map jsonFullRound = new HashMap();
Map jsonFullRound = new LinkedHashMap();
if (this.full_round_effect.visual_effect != null) jsonFullRound.put("visualEffectID", this.full_round_effect.visual_effect);
if (this.full_round_effect.hp_boost_min != null || this.full_round_effect.hp_boost_max != null) {
Map jsonHP = new HashMap();
Map jsonHP = new LinkedHashMap();
if (this.full_round_effect.hp_boost_min != null) jsonHP.put("min", this.full_round_effect.hp_boost_min);
else jsonHP.put("min", 0);
if (this.full_round_effect.hp_boost_max != null) jsonHP.put("max", this.full_round_effect.hp_boost_max);
@@ -304,7 +306,7 @@ public class ActorCondition extends JSONElement {
jsonFullRound.put("increaseCurrentHP", jsonHP);
}
if (this.full_round_effect.ap_boost_min != null || this.full_round_effect.ap_boost_max != null) {
Map jsonAP = new HashMap();
Map jsonAP = new LinkedHashMap();
if (this.full_round_effect.ap_boost_min != null) jsonAP.put("min", this.full_round_effect.ap_boost_min);
else jsonAP.put("min", 0);
if (this.full_round_effect.ap_boost_max != null) jsonAP.put("max", this.full_round_effect.ap_boost_max);
@@ -314,10 +316,10 @@ public class ActorCondition extends JSONElement {
jsonAC.put("fullRoundEffect", jsonFullRound);
}
if (this.constant_ability_effect != null) {
Map jsonAbility = new HashMap();
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_damage_min != null || this.constant_ability_effect.increase_damage_max != null) {
Map jsonAD = new HashMap();
Map jsonAD = new LinkedHashMap();
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);

View File

@@ -7,7 +7,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -18,6 +18,7 @@ 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.GameDataElement.State;
import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement.RequirementType;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
@@ -63,8 +64,9 @@ public class Dialogue extends JSONElement {
spawnAll,
removeSpawnArea,
deactivateSpawnArea,
activateMapChangeArea,
deactivateMapChangeArea
activateMapObjectGroup,
deactivateMapObjectGroup,
changeMapFilter
}
}
@@ -90,7 +92,7 @@ public class Dialogue extends JSONElement {
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+id;
return ((this.state == State.modified || this.state == State.created) ? "*" : "")+id;
}
public static String getStaticDesc() {
@@ -171,7 +173,7 @@ public class Dialogue extends JSONElement {
requirement.parent = this;
if (requirementJson.get("requireType") != null) requirement.type = RequirementType.valueOf((String) requirementJson.get("requireType"));
requirement.required_obj_id = (String) requirementJson.get("requireID");
requirement.required_value = JSONElement.getInteger(Integer.parseInt(requirementJson.get("value").toString()));
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);
@@ -223,10 +225,7 @@ public class Dialogue extends JSONElement {
if (replies != null) {
for (Reply reply : replies) {
if (reply.next_phrase_id != null) {
if (!reply.next_phrase_id.equals(Reply.EXIT_PHRASE_ID)
&& !reply.next_phrase_id.equals(Reply.FIGHT_PHRASE_ID)
&& !reply.next_phrase_id.equals(Reply.SHOP_PHRASE_ID)
&& !reply.next_phrase_id.equals(Reply.REMOVE_PHRASE_ID)) {
if (!Reply.KEY_PHRASE_ID.contains(reply.next_phrase_id)) {
reply.next_phrase = proj.getDialogue(reply.next_phrase_id);
}
}
@@ -242,12 +241,13 @@ public class Dialogue extends JSONElement {
for (Reward reward : rewards) {
if (reward.reward_obj_id != null) {
switch (reward.type) {
case activateMapChangeArea:
case deactivateMapChangeArea:
case activateMapObjectGroup:
case deactivateMapObjectGroup:
case spawnAll:
case removeSpawnArea:
case deactivateSpawnArea:
reward.map = proj.getMap(reward.map_name);
case changeMapFilter:
reward.map = reward.map_name != null ? proj.getMap(reward.map_name) : null;
break;
case actorCondition:
reward.reward_obj = proj.getActorCondition(reward.reward_obj_id);
@@ -315,6 +315,11 @@ public class Dialogue extends JSONElement {
if (rclone.reward_obj != null) {
rclone.reward_obj.addBacklink(clone);
}
rclone.map = r.map;
rclone.map_name = r.map_name;
if (rclone.map != null) {
rclone.map.addBacklink(clone);
}
clone.rewards.add(rclone);
}
}
@@ -344,18 +349,21 @@ public class Dialogue extends JSONElement {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (switch_to_npc == oldOne) {
oldOne.removeBacklink(this);
switch_to_npc = (NPC) newOne;
if (newOne != null) newOne.addBacklink(this);
} else {
if (replies != null) {
for (Reply r : replies) {
if (r.next_phrase == oldOne) {
oldOne.removeBacklink(this);
r.next_phrase = (Dialogue) newOne;
if (newOne != null) newOne.addBacklink(this);
}
if (r.requirements != null) {
for (Requirement req : r.requirements) {
if (req.required_obj == oldOne) {
oldOne.removeBacklink(this);
req.required_obj = newOne;
if (newOne != null) newOne.addBacklink(this);
}
@@ -366,6 +374,7 @@ public class Dialogue extends JSONElement {
if (rewards != null) {
for (Reward r : rewards) {
if (r.reward_obj == oldOne) {
oldOne.removeBacklink(this);
r.reward_obj = newOne;
if (newOne != null) newOne.addBacklink(this);
}
@@ -377,7 +386,7 @@ public class Dialogue extends JSONElement {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map dialogueJson = new HashMap();
Map dialogueJson = new LinkedHashMap();
dialogueJson.put("id", this.id);
if (this.message != null) dialogueJson.put("message", this.message);
if (this.switch_to_npc != null) {
@@ -389,7 +398,7 @@ public class Dialogue extends JSONElement {
List repliesJson = new ArrayList();
dialogueJson.put("replies", repliesJson);
for (Reply reply : this.replies){
Map replyJson = new HashMap();
Map replyJson = new LinkedHashMap();
repliesJson.add(replyJson);
if (reply.text != null) replyJson.put("text", reply.text);
if (reply.next_phrase != null) {
@@ -401,7 +410,7 @@ public class Dialogue extends JSONElement {
List requirementsJson = new ArrayList();
replyJson.put("requires", requirementsJson);
for (Requirement requirement : reply.requirements) {
Map requirementJson = new HashMap();
Map requirementJson = new LinkedHashMap();
requirementsJson.add(requirementJson);
if (requirement.type != null) requirementJson.put("requireType", requirement.type.toString());
if (requirement.required_obj != null) {
@@ -421,7 +430,7 @@ public class Dialogue extends JSONElement {
List rewardsJson = new ArrayList();
dialogueJson.put("rewards", rewardsJson);
for (Reward reward : this.rewards) {
Map rewardJson = new HashMap();
Map rewardJson = new LinkedHashMap();
rewardsJson.add(rewardJson);
if (reward.type != null) rewardJson.put("rewardType", reward.type.toString());
if (reward.reward_obj != null) {

View File

@@ -6,7 +6,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +17,7 @@ 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.GameDataElement.State;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
@@ -46,7 +47,7 @@ public class Droplist extends JSONElement {
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+id;
return ((this.state == State.modified || this.state == State.created) ? "*" : "")+id;
}
public static String getStaticDesc() {
@@ -193,6 +194,7 @@ public class Droplist extends JSONElement {
if (dropped_items != null) {
for (DroppedItem di : dropped_items) {
if (di.item == oldOne) {
oldOne.removeBacklink(this);
di.item = (Item) newOne;
if (newOne != null) newOne.addBacklink(this);
}
@@ -203,13 +205,13 @@ public class Droplist extends JSONElement {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map droplistJson = new HashMap();
Map droplistJson = new LinkedHashMap();
droplistJson.put("id", this.id);
if (this.dropped_items != null) {
List droppedItemsJson = new ArrayList();
droplistJson.put("items", droppedItemsJson);
for (DroppedItem droppedItem : this.dropped_items) {
Map droppedItemJson = new HashMap();
Map droppedItemJson = new LinkedHashMap();
droppedItemsJson.add(droppedItemJson);
if (droppedItem.item != null) {
droppedItemJson.put("itemID", droppedItem.item.id);
@@ -218,7 +220,7 @@ public class Droplist extends JSONElement {
}
if (droppedItem.chance != null) droppedItemJson.put("chance", JSONElement.printJsonChance(droppedItem.chance));
if (droppedItem.quantity_min != null || droppedItem.quantity_max != null) {
Map quantityJson = new HashMap();
Map quantityJson = new LinkedHashMap();
droppedItemJson.put("quantity", quantityJson);
if (droppedItem.quantity_min != null) quantityJson.put("min", droppedItem.quantity_min);
else quantityJson.put("min", 0);

View File

@@ -9,7 +9,7 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -154,7 +154,7 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
dataToSave.add(element.toJson());
}
}
if (dataToSave.isEmpty()) {
if (dataToSave.isEmpty() && jsonFile.exists()) {
if (jsonFile.delete()) {
Notification.addSuccess("File "+jsonFile.getAbsolutePath()+" deleted.");
} else {
@@ -190,7 +190,7 @@ public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implem
List<SaveEvent> events = new ArrayList<SaveEvent>();
GameDataCategory<? extends JSONElement> impactedCategory = null;
String impactedFileName = fileName;
Map<String, Integer> containedIds = new HashMap<String, Integer>();
Map<String, Integer> containedIds = new LinkedHashMap<String, Integer>();
for (JSONElement node : this) {
if (node.getDataType() == GameSource.Type.created && getProject().baseContent.gameData.getGameDataElement(node.getClass(), node.id) != null) {
if (getProject().alteredContent.gameData.getGameDataElement(node.getClass(), node.id) != null) {

View File

@@ -13,6 +13,7 @@ import com.gpl.rpg.atcontentstudio.Notification;
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.Project.ResourceSet;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.SavedSlotCollection;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
@@ -25,6 +26,17 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
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";
public static final String GAME_DROPLISTS_ARRAY_NAME = "loadresource_droplists";
public static final String GAME_ITEMS_ARRAY_NAME = "loadresource_items";
public static final String GAME_ITEMCAT_ARRAY_NAME = "loadresource_itemcategories";
public static final String GAME_NPC_ARRAY_NAME = "loadresource_monsters";
public static final String GAME_QUESTS_ARRAY_NAME = "loadresource_quests";
public static final String DEBUG_SUFFIX = "_debug";
public static final String RESOURCE_PREFIX = "@raw/";
public static final String FILENAME_SUFFIX = ".json";
public File baseFolder;
public GameDataCategory<ActorCondition> actorConditions;
@@ -67,7 +79,87 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
v.add(quests);
//Start parsing to populate categories' content.
if (parent.type != GameSource.Type.referenced) {
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 (f.exists()) {
ActorCondition.fromJson(f, actorConditions);
} else {
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 (f.exists()) {
Dialogue.fromJson(f, dialogues);
} else {
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 (f.exists()) {
Droplist.fromJson(f, droplists);
} else {
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 (f.exists()) {
Item.fromJson(f, items);
} else {
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 (f.exists()) {
ItemCategory.fromJson(f, itemCategories);
} else {
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 (f.exists()) {
NPC.fromJson(f, npcs);
} else {
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 (f.exists()) {
Quest.fromJson(f, quests);
} else {
Notification.addWarn("Unable to locate resource "+resource+" in the game source for project "+getProject().name);
}
}
}
} else if (parent.type != GameSource.Type.referenced) {
for (File f : baseFolder.listFiles()) {
if (f.getName().startsWith("actorconditions_")) {
ActorCondition.fromJson(f, actorConditions);
@@ -212,6 +304,16 @@ public class GameDataSet implements ProjectTreeNode, Serializable {
return null;
}
public NPC getNPCIgnoreCase(String id) {
if (npcs == null) return null;
for (NPC gde : npcs) {
if (id.equalsIgnoreCase(gde.id)){
return gde;
}
}
return null;
}
public Quest getQuest(String id) {
if (quests == null) return null;
for (Quest gde : quests) {

View File

@@ -6,7 +6,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +17,7 @@ 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.GameDataElement.State;
public class Item extends JSONElement {
@@ -101,7 +102,7 @@ public class Item extends JSONElement {
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+name+" ("+id+")";
return ((this.state == State.modified || this.state == State.created) ? "*" : "")+name+" ("+id+")";
}
public static String getStaticDesc() {
@@ -450,12 +451,14 @@ public class Item extends JSONElement {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (this.category == oldOne) {
oldOne.removeBacklink(this);
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);
}
@@ -464,6 +467,7 @@ public class Item extends JSONElement {
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);
}
@@ -472,6 +476,7 @@ public class Item extends JSONElement {
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);
}
@@ -481,6 +486,7 @@ public class Item extends JSONElement {
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);
}
@@ -492,10 +498,12 @@ public class Item extends JSONElement {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map itemJson = new HashMap();
Map itemJson = new LinkedHashMap();
itemJson.put("id", this.id);
if (this.icon_id != null) itemJson.put("iconID", 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.has_manual_price != null) itemJson.put("hasManualPrice", this.has_manual_price);
if (this.base_market_cost != null) itemJson.put("baseMarketCost", this.base_market_cost);
if (this.category != null) {
@@ -505,10 +513,10 @@ public class Item extends JSONElement {
}
if (this.description != null) itemJson.put("description", this.description);
if (this.equip_effect != null) {
Map equipEffectJson = new HashMap();
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 HashMap();
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);
@@ -530,7 +538,7 @@ public class Item extends JSONElement {
List conditionsJson = new ArrayList();
equipEffectJson.put("addedConditions", conditionsJson);
for (ConditionEffect condition : this.equip_effect.conditions) {
Map conditionJson = new HashMap();
Map conditionJson = new LinkedHashMap();
conditionsJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
@@ -542,10 +550,10 @@ public class Item extends JSONElement {
}
}
if (this.hit_effect != null) {
Map hitEffectJson = new HashMap();
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 HashMap();
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);
@@ -553,7 +561,7 @@ public class Item extends JSONElement {
else hpJson.put("max", 0);
}
if (this.hit_effect.ap_boost_min != null || this.hit_effect.ap_boost_max != null) {
Map apJson = new HashMap();
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);
@@ -564,7 +572,7 @@ public class Item extends JSONElement {
List conditionsSourceJson = new ArrayList();
hitEffectJson.put("conditionsSource", conditionsSourceJson);
for (TimedConditionEffect condition : this.hit_effect.conditions_source) {
Map conditionJson = new HashMap();
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
@@ -580,7 +588,7 @@ public class Item extends JSONElement {
List conditionsTargetJson = new ArrayList();
hitEffectJson.put("conditionsTarget", conditionsTargetJson);
for (TimedConditionEffect condition : this.hit_effect.conditions_target) {
Map conditionJson = new HashMap();
Map conditionJson = new LinkedHashMap();
conditionsTargetJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
@@ -594,14 +602,14 @@ public class Item extends JSONElement {
}
}
if (this.kill_effect != null) {
Map killEffectJson = new HashMap();
Map killEffectJson = new LinkedHashMap();
if (this.category != null && this.category.action_type != null && this.category.action_type == ItemCategory.ActionType.equip) {
itemJson.put("killEffect", killEffectJson);
} 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 HashMap();
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);
@@ -609,7 +617,7 @@ public class Item extends JSONElement {
else hpJson.put("min", 0);
}
if (this.kill_effect.ap_boost_min != null || this.kill_effect.ap_boost_max != null) {
Map apJson = new HashMap();
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);
@@ -620,7 +628,7 @@ public class Item extends JSONElement {
List conditionsSourceJson = new ArrayList();
killEffectJson.put("conditionsSource", conditionsSourceJson);
for (TimedConditionEffect condition : this.kill_effect.conditions_source) {
Map conditionJson = new HashMap();
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);

View File

@@ -5,7 +5,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +17,7 @@ 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.GameDataElement.State;
public class ItemCategory extends JSONElement {
@@ -99,7 +100,7 @@ public class ItemCategory extends JSONElement {
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+name+" ("+id+")";
return ((this.state == State.modified || this.state == State.created) ? "*" : "")+name+" ("+id+")";
}
public static String getStaticDesc() {
@@ -310,7 +311,7 @@ public class ItemCategory extends JSONElement {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map itemCatJson = new HashMap();
Map itemCatJson = new LinkedHashMap();
itemCatJson.put("id", this.id);
if (this.name != null) itemCatJson.put("name", this.name);
if (this.action_type != null) itemCatJson.put("actionType", this.action_type.toString());

View File

@@ -6,7 +6,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +17,7 @@ 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.GameDataElement.State;
public class NPC extends JSONElement {
@@ -95,7 +96,7 @@ public class NPC extends JSONElement {
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+name+" ("+id+")";
return ((this.state == State.modified || this.state == State.created) ? "*" : "")+name+" ("+id+")";
}
public static String getStaticDesc() {
@@ -356,16 +357,19 @@ public class NPC extends JSONElement {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (dialogue == oldOne) {
oldOne.removeBacklink(this);
this.dialogue = (Dialogue) newOne;
if (newOne != null) newOne.addBacklink(this);
} else {
if (this.droplist == oldOne) {
oldOne.removeBacklink(this);
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);
}
@@ -374,6 +378,7 @@ public class NPC extends JSONElement {
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);
}
@@ -386,7 +391,7 @@ public class NPC extends JSONElement {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map npcJson = new HashMap();
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);
@@ -397,7 +402,7 @@ public class NPC extends JSONElement {
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 HashMap();
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);
@@ -423,10 +428,10 @@ public class NPC extends JSONElement {
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 HashMap();
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 HashMap();
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);
@@ -434,7 +439,7 @@ public class NPC extends JSONElement {
else hpJson.put("max", 0);
}
if (this.hit_effect.ap_boost_min != null || this.hit_effect.ap_boost_max != null) {
Map apJson = new HashMap();
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);
@@ -445,7 +450,7 @@ public class NPC extends JSONElement {
List conditionsSourceJson = new ArrayList();
hitEffectJson.put("conditionsSource", conditionsSourceJson);
for (TimedConditionEffect condition : this.hit_effect.conditions_source) {
Map conditionJson = new HashMap();
Map conditionJson = new LinkedHashMap();
conditionsSourceJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);
@@ -461,7 +466,7 @@ public class NPC extends JSONElement {
List conditionsTargetJson = new ArrayList();
hitEffectJson.put("conditionsTarget", conditionsTargetJson);
for (TimedConditionEffect condition : this.hit_effect.conditions_target) {
Map conditionJson = new HashMap();
Map conditionJson = new LinkedHashMap();
conditionsTargetJson.add(conditionJson);
if (condition.condition != null) {
conditionJson.put("condition", condition.condition.id);

View File

@@ -6,7 +6,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -16,6 +16,7 @@ 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.GameDataElement.State;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class Quest extends JSONElement {
@@ -48,7 +49,7 @@ public class Quest extends JSONElement {
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+name+" ("+id+")";
return ((this.state == State.modified || this.state == State.created) ? "*" : "")+name+" ("+id+")";
}
public static String getStaticDesc() {
@@ -180,7 +181,7 @@ public class Quest extends JSONElement {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map questJson = new HashMap();
Map questJson = new LinkedHashMap();
questJson.put("id", this.id);
if (this.name != null) questJson.put("name", this.name);
if (this.visible_in_log != null) questJson.put("showInLog", this.visible_in_log);
@@ -188,7 +189,7 @@ public class Quest extends JSONElement {
List stagesJson = new ArrayList();
questJson.put("stages", stagesJson);
for (QuestStage stage : this.stages) {
Map stageJson = new HashMap();
Map stageJson = new LinkedHashMap();
stagesJson.add(stageJson);
if (stage.progress != null) stageJson.put("progress", stage.progress);
if (stage.log_text != null) stageJson.put("logText", stage.log_text);

View File

@@ -1,7 +1,7 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -13,7 +13,7 @@ public class Requirement extends JSONElement {
private static final long serialVersionUID = 7295593297142310955L;
private static Map<RequirementType, List<RequirementType>> COMPATIBLE_TYPES = new HashMap<RequirementType, List<RequirementType>>();
private static Map<RequirementType, List<RequirementType>> COMPATIBLE_TYPES = new LinkedHashMap<RequirementType, List<RequirementType>>();
static {
List<RequirementType> questTypes = new ArrayList<RequirementType>();
@@ -145,8 +145,9 @@ public class Requirement extends JSONElement {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (this.required_obj == oldOne) {
oldOne.removeBacklink((GameDataElement) this.parent);
this.required_obj = newOne;
if (newOne != null) newOne.addBacklink(this);
if (newOne != null) newOne.addBacklink((GameDataElement) this.parent);
}
}
@Override

View File

@@ -29,8 +29,9 @@ public class ContainerArea extends MapObject {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (oldOne == droplist) {
oldOne.removeBacklink(parentMap);
droplist = (Droplist) newOne;
newOne.addBacklink(parentMap);
if (newOne != null) newOne.addBacklink(parentMap);
}
}

View File

@@ -12,6 +12,7 @@ public class KeyArea extends MapObject {
public String dialogue_id = null;
public Dialogue dialogue = null;
public Requirement requirement = null;
public boolean oldSchoolRequirement = true;
public KeyArea(tiled.core.MapObject obj) {
dialogue_id = obj.getProperties().getProperty("phrase");
@@ -29,9 +30,12 @@ public class KeyArea extends MapObject {
requireType = fields[0];
requireId = fields[1];
}
oldSchoolRequirement = true;
} else {
oldSchoolRequirement = false;
}
requirement = new Requirement();
requirement.type = Requirement.RequirementType.valueOf(requireType);
if (requireType != null) requirement.type = Requirement.RequirementType.valueOf(requireType);
requirement.required_obj_id = requireId;
if (requireValue != null) requirement.required_value = Integer.parseInt(requireValue);
requirement.state = GameDataElement.State.parsed;
@@ -56,9 +60,11 @@ public class KeyArea extends MapObject {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (oldOne == dialogue) {
oldOne.removeBacklink(parentMap);
dialogue = (Dialogue) newOne;
newOne.addBacklink(parentMap);
if (newOne != null) newOne.addBacklink(parentMap);
}
requirement.elementChanged(oldOne, newOne);
}
@Override
@@ -69,16 +75,36 @@ public class KeyArea extends MapObject {
tmxObject.getProperties().setProperty("phrase", dialogue_id);
}
if (requirement != null) {
tmxObject.getProperties().setProperty("requireType", requirement.type.toString());
if (requirement.required_obj != null) {
tmxObject.getProperties().setProperty("requireId", requirement.required_obj.id);
} else if (requirement.required_obj_id != null) {
tmxObject.getProperties().setProperty("requireId", requirement.required_obj_id);
}
if (requirement.required_value != null) {
tmxObject.getProperties().setProperty("requireValue", requirement.required_value.toString());
if (oldSchoolRequirement && Requirement.RequirementType.questProgress.equals(requirement.type) && (requirement.negated == null || !requirement.negated)) {
tmxObject.setName(requirement.required_obj_id+":"+Integer.toString(requirement.required_value));
} else {
if (requirement.type != null) {
tmxObject.getProperties().setProperty("requireType", requirement.type.toString());
}
if (requirement.required_obj != null) {
tmxObject.getProperties().setProperty("requireId", requirement.required_obj.id);
} else if (requirement.required_obj_id != null) {
tmxObject.getProperties().setProperty("requireId", requirement.required_obj_id);
}
if (requirement.required_value != null) {
tmxObject.getProperties().setProperty("requireValue", requirement.required_value.toString());
}
}
}
}
public void updateNameFromRequirementChange() {
if (oldSchoolRequirement && Requirement.RequirementType.questProgress.equals(requirement.type) && (requirement.negated == null || !requirement.negated)) {
name = requirement.required_obj_id+":"+Integer.toString(requirement.required_value);
} else if (oldSchoolRequirement) {
int i = 0;
String futureName = requirement.type.toString() + "#" + Integer.toString(i);
while (parentMap.getMapObject(futureName) != null) {
i++;
futureName = requirement.type.toString() + "#" + Integer.toString(i);
}
this.name = futureName;
}
}
}

View File

@@ -37,8 +37,9 @@ public class MapChange extends MapObject {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (oldOne == map) {
oldOne.removeBacklink(parentMap);
map = (TMXMap) newOne;
newOne.addBacklink(parentMap);
if (newOne != null) newOne.addBacklink(parentMap);
}
}

View File

@@ -94,6 +94,7 @@ public abstract class MapObject {
public abstract void savePropertiesInTmxObject(tiled.core.MapObject tmxObject);
public static MapObject newMapchange(tiled.core.MapObject obj, TMXMap parentMap) {
if (obj.getName() == null) obj.setName("Mapchange");
MapObject result = new MapChange(obj);
result.type = Types.mapchange;
initObj(result, obj, parentMap);
@@ -101,6 +102,7 @@ public abstract class MapObject {
}
public static MapObject newSpawnArea(tiled.core.MapObject obj, TMXMap parentMap) {
if (obj.getName() == null) obj.setName("Spawnarea");
MapObject result = new SpawnArea(obj);
result.type = Types.spawn;
initObj(result, obj, parentMap);
@@ -108,6 +110,7 @@ public abstract class MapObject {
}
public static MapObject newRest(tiled.core.MapObject obj, TMXMap parentMap) {
if (obj.getName() == null) obj.setName("Rest");
MapObject result = new RestArea(obj);
result.type = Types.rest;
initObj(result, obj, parentMap);
@@ -115,6 +118,7 @@ public abstract class MapObject {
}
public static MapObject newKey(tiled.core.MapObject obj, TMXMap parentMap) {
if (obj.getName() == null) obj.setName("Key");
MapObject result = new KeyArea(obj);
result.type = Types.key;
initObj(result, obj, parentMap);
@@ -122,6 +126,7 @@ public abstract class MapObject {
}
public static MapObject newReplace(tiled.core.MapObject obj, TMXMap parentMap) {
if (obj.getName() == null) obj.setName("Replace");
MapObject result = new ReplaceArea(obj);
result.type = Types.replace;
initObj(result, obj, parentMap);
@@ -129,6 +134,7 @@ public abstract class MapObject {
}
public static MapObject newScript(tiled.core.MapObject obj, TMXMap parentMap) {
if (obj.getName() == null) obj.setName("Script");
MapObject result = new ScriptArea(obj);
result.type = Types.script;
initObj(result, obj, parentMap);
@@ -136,6 +142,7 @@ public abstract class MapObject {
}
public static MapObject newContainer(tiled.core.MapObject obj, TMXMap parentMap) {
if (obj.getName() == null) obj.setName("Container");
MapObject result = new ContainerArea(obj);
result.type = Types.container;
initObj(result, obj, parentMap);
@@ -143,6 +150,7 @@ public abstract class MapObject {
}
public static MapObject newSign(tiled.core.MapObject obj, TMXMap parentMap) {
if (obj.getName() == null) obj.setName("Sign");
MapObject result = new SignArea(obj);
result.type = Types.sign;
initObj(result, obj, parentMap);

View File

@@ -13,12 +13,18 @@ public class MapObjectGroup {
public String name;
public boolean visible;
public List<MapObject> mapObjects = new ArrayList<MapObject>();
public Boolean active;
public MapObjectGroup(tiled.core.ObjectGroup layer, TMXMap map) {
this.tmxGroup = layer;
this.name = layer.getName();
this.visible = layer.isVisible();
this.parentMap = map;
if (layer.getProperties().get("active") != null) {
active = new Boolean(((String) layer.getProperties().get("active")));
} else {
active = true;
}
for (tiled.core.MapObject obj : layer.getObjectsList()) {
mapObjects.add(MapObject.buildObject(obj, map));
}
@@ -44,6 +50,9 @@ public class MapObjectGroup {
}
tmxGroup.setVisible(visible);
tmxGroup.setName(name);
if (!active) {
tmxGroup.getProperties().put("active", Boolean.toString(active));
}
for (MapObject object : mapObjects) {
tmxGroup.addObject(object.toTmxObject());
}

View File

@@ -1,21 +1,60 @@
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;
public class ReplaceArea extends MapObject {
public Requirement requirement = null;
public boolean oldSchoolRequirement = true;
public List<ReplaceArea.Replacement> replacements = null;
public ReplaceArea(tiled.core.MapObject obj) {
// TODO Auto-generated constructor stub
// String requireType = obj.getProperties().getProperty("requireType");
String requireId = obj.getProperties().getProperty("requireId");
String requireValue = obj.getProperties().getProperty("requireValue");
if (requireId == null) {
String[] fields = obj.getName().split(":");
if (fields.length == 2) {
// requireType = Requirement.RequirementType.questProgress.toString();
requireValue = fields[1];
requireId = fields[0];
} /*else if (fields.length == 3) {
requireValue = fields[2];
requireType = fields[0];
requireId = fields[1];
}*/
oldSchoolRequirement = true;
} else {
oldSchoolRequirement = false;
}
requirement = new Requirement();
//Replace areas only support questProgress requirements ATM
//requirement.type = Requirement.RequirementType.valueOf(requireType);
requirement.type = Requirement.RequirementType.questProgress;
requirement.required_obj_id = requireId;
if (requireValue != null) requirement.required_value = Integer.parseInt(requireValue);
requirement.state = GameDataElement.State.parsed;
for (Object s : obj.getProperties().keySet()) {
if (replacements == null) replacements = new ArrayList<ReplaceArea.Replacement>();
replacements.add(new Replacement(s.toString(), obj.getProperties().getProperty(s.toString())));
}
}
@Override
public void link() {
// TODO Auto-generated method stub
requirement.parent = parentMap;
requirement.link();
}
@Override
@@ -25,14 +64,79 @@ public class ReplaceArea extends MapObject {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
// TODO Auto-generated method stub
requirement.elementChanged(oldOne, newOne);
}
public ReplaceArea.Replacement addReplacement(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) {
// TODO Auto-generated method stub
if (replacements != null) {
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+":"+Integer.toString(requirement.required_value));
} else {
tmxObject.getProperties().setProperty("requireType", requirement.type.toString());
if (requirement.required_obj != null) {
tmxObject.getProperties().setProperty("requireId", requirement.required_obj.id);
} else if (requirement.required_obj_id != null) {
tmxObject.getProperties().setProperty("requireId", requirement.required_obj_id);
}
if (requirement.required_value != null) {
tmxObject.getProperties().setProperty("requireValue", requirement.required_value.toString());
}
}
}
}
//Don't use yet !
public void updateNameFromRequirementChange() {
if (oldSchoolRequirement && Requirement.RequirementType.questProgress.equals(requirement.type) && (requirement.negated == null || !requirement.negated)) {
name = requirement.required_obj_id+":"+Integer.toString(requirement.required_value);
} else if (oldSchoolRequirement) {
int i = 0;
String futureName = requirement.type.toString() + "#" + Integer.toString(i);
while (parentMap.getMapObject(futureName) != null) {
i++;
futureName = requirement.type.toString() + "#" + Integer.toString(i);
}
this.name = futureName;
}
}
public class Replacement {
public String sourceLayer, targetLayer;
public Replacement(String source, String target) {
this.sourceLayer = source;
this.targetLayer = target;
}
}
public boolean hasReplacementFor(String name) {
if (name == null) return false;
for (Replacement repl : replacements) {
if (name.equalsIgnoreCase(repl.sourceLayer)) return true;
}
return false;
}
}

View File

@@ -42,8 +42,9 @@ public class ScriptArea extends MapObject {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (oldOne == dialogue) {
oldOne.removeBacklink(parentMap);
dialogue = (Dialogue) newOne;
newOne.addBacklink(parentMap);
if (newOne != null) newOne.addBacklink(parentMap);
}
}

View File

@@ -31,8 +31,9 @@ public class SignArea extends MapObject {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (oldOne == dialogue) {
oldOne.removeBacklink(parentMap);
dialogue = (Dialogue) newOne;
newOne.addBacklink(parentMap);
if (newOne != null) newOne.addBacklink(parentMap);
}
}

View File

@@ -12,6 +12,8 @@ public class SpawnArea extends MapObject {
public int quantity = 1;
public int spawnchance = 10;
public boolean active = true;
public String spawngroup_id;
public List<NPC> spawnGroup = new ArrayList<NPC>();
public SpawnArea(tiled.core.MapObject obj) {
@@ -21,12 +23,20 @@ public class SpawnArea extends MapObject {
if (obj.getProperties().getProperty("spawnchance") != null) {
this.spawnchance = Integer.parseInt(obj.getProperties().getProperty("spawnchance"));
}
if (obj.getProperties().getProperty("active") != null) {
this.active = Boolean.parseBoolean(obj.getProperties().getProperty("active"));
}
if (obj.getProperties().getProperty("spawngroup") != null) {
this.spawngroup_id = obj.getProperties().getProperty("spawngroup");
} else if (obj.getName() != null ){
this.spawngroup_id = obj.getName();
}
}
@Override
public void link() {
if (name != null) {
spawnGroup = parentMap.getProject().getSpawnGroup(name);
if (spawngroup_id != null) {
spawnGroup = parentMap.getProject().getSpawnGroup(spawngroup_id);
} else {
spawnGroup = new ArrayList<NPC>();
}
@@ -54,19 +64,26 @@ public class SpawnArea extends MapObject {
}
}
if (replacedIndex >= 0) {
oldOne.removeBacklink(parentMap);
spawnGroup.set(replacedIndex, (NPC) newOne);
newOne.addBacklink(parentMap);
if (newOne != null) newOne.addBacklink(parentMap);
}
}
@Override
public void savePropertiesInTmxObject(tiled.core.MapObject tmxObject) {
if (spawngroup_id != null) {
tmxObject.getProperties().setProperty("spawngroup", spawngroup_id);
}
if (quantity != 1) {
tmxObject.getProperties().setProperty("quantity", Integer.toString(quantity));
}
if (spawnchance != 10) {
tmxObject.getProperties().setProperty("spawnchance", Integer.toString(spawnchance));
}
if (!this.active) {
tmxObject.getProperties().setProperty("active", Boolean.toString(active));
}
}
}

View File

@@ -12,6 +12,7 @@ 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;
@@ -21,11 +22,12 @@ 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.SaveEvent;
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;
@@ -33,6 +35,24 @@ public class TMXMap extends GameDataElement {
private static final long serialVersionUID = 1609502879500898837L;
public static final String GROUND_LAYER_NAME = "Ground";
public static final String OBJECTS_LAYER_NAME = "Objects";
public static final String ABOVE_LAYER_NAME = "Above";
public static final String WALKABLE_LAYER_NAME = "Walkable";
public enum ColorFilter {
none,
black20,
black40,
black60,
black80,
invert,
bw,
redtint,
greentint,
bluetint
}
public File tmxFile = null;
public tiled.core.Map tmxMap = null;
public Set<Spritesheet> usedSpritesheets = null;
@@ -40,8 +60,11 @@ public class TMXMap extends GameDataElement {
public ProjectTreeNode parent;
public Integer outside = null;
public ColorFilter colorFilter = null;
public boolean writable = false;
public boolean changedOnDisk = false;
public int dismissNextChangeNotif = 0;
public TMXMap(TMXMapSet parent, File f) {
this.parent = parent;
@@ -56,8 +79,11 @@ public class TMXMap extends GameDataElement {
usedSpritesheets = new HashSet<Spritesheet>();
try {
tmxMap = new TMXMapReader().readMap(tmxFile.getAbsolutePath(), this);
if (tmxMap.getProperties().get("outside") != null) {
outside = new Integer(((String) tmxMap.getProperties().get("outside")));
if (tmxMap.getProperties().get("outdoors") != null) {
outside = new Integer(((String) tmxMap.getProperties().get("outdoors")));
}
if (tmxMap.getProperties().get("colorfilter") != null) {
colorFilter = ColorFilter.valueOf(((String) tmxMap.getProperties().get("colorfilter")));
}
} catch (FileNotFoundException e) {
Notification.addError("Impossible to load TMX map file "+tmxFile.getAbsolutePath());
@@ -91,8 +117,11 @@ public class TMXMap extends GameDataElement {
try {
clone.usedSpritesheets = new HashSet<Spritesheet>();
clone.tmxMap = new TMXMapReader().readMap(new StringReader(this.toXml()), clone);
if (clone.tmxMap.getProperties().get("outside") != null) {
clone.outside = new Integer(((String) clone.tmxMap.getProperties().get("outside")));
if (clone.tmxMap.getProperties().get("outdoors") != null) {
clone.outside = new Integer(((String) clone.tmxMap.getProperties().get("outdoors")));
}
if (clone.tmxMap.getProperties().get("colorfilter") != null) {
clone.colorFilter = ColorFilter.valueOf(((String) tmxMap.getProperties().get("colorfilter")));
}
for (tiled.core.MapLayer layer : clone.tmxMap.getLayers()) {
if (layer instanceof tiled.core.ObjectGroup) {
@@ -172,7 +201,7 @@ public class TMXMap extends GameDataElement {
}
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+id;
return ((this.state == State.modified || this.state == State.created) ? "*" : "")+id;
}
@Override
@@ -204,6 +233,17 @@ public class TMXMap extends GameDataElement {
}
public String toXml() {
if (outside != null && outside == 1) {
tmxMap.getProperties().put("outdoors", Integer.toString(outside));
} else {
tmxMap.getProperties().remove("outdoors");
}
if (colorFilter != null) {
tmxMap.getProperties().put("colorfilter", colorFilter.toString());
} else {
tmxMap.getProperties().remove("colorfilter");
}
for (MapObjectGroup group : groups) {
group.pushBackToTiledProperties();
if (!tmxMap.containsLayer(group.tmxGroup)) {
@@ -234,10 +274,13 @@ public class TMXMap extends GameDataElement {
public void save() {
if (writable) {
try {
//TODO: check in fileutils, to test the workspace's filesystem once at startup, and figure out how many of these can occur, instead of hard-coded '2'
dismissNextChangeNotif += 2;
FileWriter w = new FileWriter(tmxFile);
w.write(toXml());
w.close();
this.state = State.saved;
changedOnDisk = false;
Notification.addSuccess("TMX file "+tmxFile.getAbsolutePath()+" saved.");
} catch (IOException e) {
Notification.addError("Error while writing TMX file "+tmxFile.getAbsolutePath()+" : "+e.getMessage());
@@ -273,8 +316,10 @@ public class TMXMap extends GameDataElement {
parse();
}
if (this.state == GameDataElement.State.parsed || this.state == GameDataElement.State.created) {
for (MapObjectGroup group : groups) {
group.link();
if (groups != null) {
for (MapObjectGroup group : groups) {
group.link();
}
}
}
}
@@ -335,4 +380,96 @@ public class TMXMap extends GameDataElement {
return result;
}
public MapObject getMapObject(String name) {
MapObject result = null;
for (MapObjectGroup group : groups) {
for (MapObject obj : group.mapObjects) {
if (obj.name.equals(name)) {
result = obj;
break;
}
}
}
return result;
}
public static boolean isPaintedLayerName(String name) {
return GROUND_LAYER_NAME.equalsIgnoreCase(name) ||
OBJECTS_LAYER_NAME.equalsIgnoreCase(name) ||
ABOVE_LAYER_NAME.equalsIgnoreCase(name) ||
WALKABLE_LAYER_NAME.equalsIgnoreCase(name);
}
public void reload() {
tmxMap = null;
for (Spritesheet s : usedSpritesheets) {
s.elementChanged(this, null);
}
usedSpritesheets.clear();
for (MapObjectGroup g : groups) {
for (MapObject o : g.mapObjects) {
if (o instanceof ContainerArea) {
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);
} else if (o instanceof MapChange) {
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);
} else if (o instanceof RestArea) {
} else if (o instanceof ScriptArea) {
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);
} else if (o instanceof SpawnArea) {
if (((SpawnArea)o).spawnGroup != null) {
for (NPC n : ((SpawnArea)o).spawnGroup) {
n.elementChanged(this, null);
}
}
}
}
}
groups.clear();
outside = null;
colorFilter = null;
state = GameDataElement.State.init;
this.link();
changedOnDisk = false;
for (MapChangedOnDiskListener l : listeners) {
l.mapReloaded();
}
}
public void mapChangedOnDisk() {
if (dismissNextChangeNotif > 0) {
dismissNextChangeNotif--;
} else {
changedOnDisk = true;
for (MapChangedOnDiskListener l : listeners) {
l.mapChanged();
}
}
}
public interface MapChangedOnDiskListener {
public void mapChanged();
public void mapReloaded();
}
private List<MapChangedOnDiskListener> listeners = new CopyOnWriteArrayList<TMXMap.MapChangedOnDiskListener>();
public void addMapChangedOnDiskListener(MapChangedOnDiskListener l) {
listeners.add(l);
}
public void removeMapChangedOnDiskListener(MapChangedOnDiskListener l) {
listeners.remove(l);
}
}

View File

@@ -2,6 +2,15 @@ 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.Files;
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;
@@ -10,18 +19,28 @@ 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;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.Project.ResourceSet;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.model.sprites.SpriteSheetSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.utils.FileUtils;
public class TMXMapSet implements ProjectTreeNode {
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res/xml/";
public static final String DEFAULT_REL_PATH_IN_PROJECT = "maps/";
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";
public static final String RESOURCE_PREFIX = "@xml/";
public static final String FILENAME_SUFFIX = ".tmx";
public File mapFolder = null;
public List<TMXMap> tmxMaps;
@@ -29,16 +48,34 @@ public class TMXMapSet implements ProjectTreeNode {
public TMXMapSet(GameSource source) {
this.parent = source;
if (source.type == GameSource.Type.source) this.mapFolder = new File(source.baseFolder, DEFAULT_REL_PATH_IN_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) {
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));
}
this.tmxMaps = new ArrayList<TMXMap>();
if (this.mapFolder != null) {
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 (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);
}
}
}
} else if (this.mapFolder != null) {
for (File f : this.mapFolder.listFiles()) {
if (f.getName().endsWith(".tmx") || f.getName().endsWith(".TMX")) {
TMXMap map = new TMXMap(this, f);
@@ -55,6 +92,43 @@ public class TMXMapSet implements ProjectTreeNode {
return o1.id.compareTo(o2.id);
}
});
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 "+source.type) {
public void run() {
WatchService watchService;
while(getProject().open) {
try {
watchService = FileSystems.getDefault().newWatchService();
WatchKey watchKey = folderPath.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
WatchKey wk;
validService: while(getProject().open) {
wk = watchService.take();
for (WatchEvent<?> event : wk.pollEvents()) {
Path changed = (Path) event.context();
String name = changed.getFileName().toString();
String id = name.substring(0, name.length() - 4);
TMXMap map = getMap(id);
if (map != null) {
map.mapChangedOnDisk();
}
}
if(!wk.reset()) {
watchService.close();
break validService;
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
};
watcher.start();
}
}
@Override

View File

@@ -10,7 +10,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -52,7 +52,7 @@ public class Worldmap extends ArrayList<WorldmapSegment> implements ProjectTreeN
public File worldmapFile;
public GameSource parent;
public Map<String, Map<String, Point>> segments = new HashMap<String, Map<String,Point>>();
public Map<String, Map<String, Point>> segments = new LinkedHashMap<String, Map<String,Point>>();
public Worldmap(GameSource gameSource) {
this.parent = gameSource;
@@ -261,6 +261,7 @@ public class Worldmap extends ArrayList<WorldmapSegment> implements ProjectTreeN
Source input = new DOMSource(doc);
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
transformer.transform(input, output);
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block

View File

@@ -2,12 +2,23 @@ package com.gpl.rpg.atcontentstudio.model.maps;
import java.awt.Image;
import java.awt.Point;
import java.util.HashMap;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
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;
@@ -55,7 +66,7 @@ public class WorldmapSegment extends GameDataElement {
String area;
if ((area = mapNode.getAttribute("area")) != null && !"".equals(area)) {
if (labelledMaps.get(area) == null) {
labelledMaps.put(area, new LinkedList<String>());
labelledMaps.put(area, new ArrayList<String>());
}
labelledMaps.get(area).add(mapNode.getAttribute("id"));
}
@@ -76,7 +87,9 @@ public class WorldmapSegment extends GameDataElement {
return;
}
for (String mapName : mapLocations.keySet()) {
getProject().getMap(mapName).addBacklink(this);
if (getProject().getMap(mapName) != null) {
getProject().getMap(mapName).addBacklink(this);
}
}
}
@@ -90,7 +103,7 @@ public class WorldmapSegment extends GameDataElement {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
oldOne.removeBacklink(this);
newOne.addBacklink(this);
if(newOne != null) newOne.addBacklink(this);
}
@Override
@@ -103,6 +116,32 @@ public class WorldmapSegment extends GameDataElement {
((Worldmap)parent).save();
}
public String toXml() {
Document doc;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
doc.setXmlVersion("1.0");
Element root = doc.createElement("worldmap");
doc.appendChild(root);
root.appendChild(this.toXmlElement(doc));
Transformer transformer = TransformerFactory.newInstance().newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Result output = new StreamResult(baos);
Source input = new DOMSource(doc);
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
transformer.transform(input, output);
return baos.toString();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
}
return null;
}
public Element toXmlElement(Document doc) {
Element element = doc.createElement("segment");
element.setAttribute("id", id);

View File

@@ -7,7 +7,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -43,8 +43,8 @@ public class Spritesheet extends GameDataElement {
//Lazy initialization.
public BufferedImage spritesheet = null;
public Map<Integer, BufferedImage> cache_full_size = new HashMap<Integer, BufferedImage>();
public Map<Integer, Image> cache_icon = new HashMap<Integer, Image>();
public Map<Integer, BufferedImage> cache_full_size = new LinkedHashMap<Integer, BufferedImage>();
public Map<Integer, Image> cache_icon = new LinkedHashMap<Integer, Image>();
public Spritesheet(SpriteSheetSet parent, File f) {
this.spritesheetFile = f;

View File

@@ -0,0 +1,646 @@
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.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
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;
public File jsonFile;
public Image npcIcon;
// public String sketchName;
public List<String> rootsId = new ArrayList<String>();
public List<WriterDialogue> roots = new ArrayList<WriterDialogue>();
public WriterDialogue begin;
public Map<String, WriterDialogue> nodesById = new LinkedHashMap<String, WriterDialogue>();
//public Map<String, WriterDialogue> dialogueThreads = new LinkedHashMap<String, WriterDialogue>();
public Map<String, Integer> threadsNextIndex = new LinkedHashMap<String, Integer>();
public WriterModeData(String id_prefix){
this.id = id_prefix;
}
@SuppressWarnings("rawtypes")
public WriterModeData(WriterModeDataSet parent, Map jsonObj) {
this.parent = parent;
this.jsonFile = parent.writerFile;
this.parse(jsonObj);
this.state = State.parsed;
}
public WriterModeData(String id_prefix, Dialogue imported) {
this.id = id_prefix;
this.begin = new WriterDialogue(imported);
this.state = State.linked;
}
public int getNextIndex(String id_prefix) {
Integer index = threadsNextIndex.get(id_prefix);
if (index == null) index = 0;
while (getProject().getDialogue(id_prefix+index) != null) {
index++;
}
threadsNextIndex.put(id_prefix, index + 1);
return index;
}
public abstract class WriterNode {
public String text;
public abstract String getTitle();
}
public WriterDialogue createDialogue(Dialogue dialogue) {
if (dialogue.message == null) {
return new SelectorDialogue(dialogue);
} else {
return new WriterDialogue(dialogue);
}
}
public class WriterDialogue extends WriterNode {
public String id;
public String id_prefix;
public int index;
public List<WriterReply> replies = new ArrayList<WriterReply>();
public List<WriterReply> parents = new ArrayList<WriterReply>();
public String dialogue_id;
public Dialogue dialogue;
public WriterDialogue() {}
public WriterDialogue(Dialogue dialogue) {
this.dialogue = dialogue;
this.text = dialogue.message;
this.id = this.dialogue_id = dialogue.id;
Pattern p = Pattern.compile("(.*)([0-9]+)");
Matcher m = p.matcher(dialogue.id);
if (m.matches()) {
this.id_prefix = m.group(1);
this.index = Integer.parseInt(m.group(2));
} else {
this.id_prefix = this.id+"_";
}
nodesById.put(this.id, this);
if (dialogue.replies != null) {
for (Dialogue.Reply reply : dialogue.replies) {
if (Dialogue.Reply.GO_NEXT_TEXT.equals(reply.text) || reply.text == null) {
replies.add(new EmptyReply(this, reply));
} else {
replies.add(new WriterReply(this, reply));
}
}
}
}
public WriterDialogue(String id_prefix) {
text = "";
this.id_prefix = id_prefix;
index = getNextIndex(id_prefix);
}
@Override
public String getTitle() {
return "Dialogue "+getID();
}
public String getID() {
return this.id != null ? this.id : this.id_prefix+this.index;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void toJson(List<WriterDialogue> visited, List<Map> jsonData) {
if (visited.contains(this)) return;
visited.add(this);
Map dialogueJson = new LinkedHashMap();
jsonData.add(dialogueJson);
dialogueJson.put("id", id);
dialogueJson.put("id_prefix", id_prefix);
dialogueJson.put("index", index);
dialogueJson.put("text", text);
if (dialogue != null) {
dialogueJson.put("dialogue", dialogue.id);
} else if (dialogue_id != null) {
dialogueJson.put("dialogue", dialogue_id);
}
dialogueJson.put("special", isSpecial());
dialogueJson.put("begin", begin == this);
if (!replies.isEmpty()) {
List repliesJson = new ArrayList();
for (WriterReply reply : replies) {
repliesJson.add(reply.toJson(visited, jsonData));
}
dialogueJson.put("replies", repliesJson);
}
}
@SuppressWarnings("rawtypes")
public WriterDialogue(Map json) {
this.id = (String) json.get("id");
this.index = ((Number)json.get("index")).intValue();
this.id_prefix = (String) json.get("id_prefix");
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("replies") != null) {
List repliesJson = (List) json.get("replies");
for (Object rJson : repliesJson) {
if (((Map)rJson).get("special") != null && (Boolean)((Map)rJson).get("special")) {
//TODO Check different cases. But there are none currently.
this.replies.add(new EmptyReply(this, ((Map)rJson)));
} else {
this.replies.add(new WriterReply(this, (Map)rJson));
}
}
}
}
public boolean isSpecial() {return false;}
public Dialogue toDialogue(Map<WriterDialogue, Dialogue> visited, List<Dialogue> created, List<Dialogue> modified) {
if (visited.get(this) != null) return visited.get(this);
//Creating a new Dialogue
if (dialogue == null) {
dialogue = new Dialogue();
dialogue.id = getID();
dialogue.state = GameDataElement.State.parsed;
created.add(dialogue);
} else {
if (hasChanged()) {
if (dialogue.writable) {
//Modifying a created or altered Dialogue
dialogue.state = GameDataElement.State.modified;
modified.add(dialogue);
} else {
//Altering a game source Dialogue
//Dialogue clone = (Dialogue) dialogue.clone();
dialogue.getProject().makeWritable(dialogue);
Dialogue clone = dialogue.getProject().getDialogue(dialogue.id);
if (this.replies != null) {
for (WriterReply wReply : this.replies) {
if (wReply.reply != null) {
wReply.reply = clone.replies.get(dialogue.replies.indexOf(wReply.reply));
}
}
}
dialogue = clone;
dialogue.state = GameDataElement.State.parsed;
created.add(dialogue);
}
}
}
visited.put(this, dialogue);
dialogue.message = this.text;
if (this.replies != null && !this.replies.isEmpty()) {
if (dialogue.replies == null) {
dialogue.replies = new ArrayList<Dialogue.Reply>();
} else {
dialogue.replies.clear();
}
for (WriterReply wReply : this.replies) {
//if (wReply.reply != null && dialogue.replies)
dialogue.replies.add(wReply.toReply(visited, created, modified));
}
} else {
dialogue.replies = null;
}
return dialogue;
}
public boolean hasChanged() {
return dialogue == null ||
text == null ? dialogue.message!=null : !text.equals(dialogue.message) ||
repliesHaveChanged();
}
public boolean repliesHaveChanged() {
if (replies.isEmpty() && (dialogue.replies == null || dialogue.replies.isEmpty())) return false;
if (!replies.isEmpty() && (dialogue.replies == null || dialogue.replies.isEmpty())) return true;
if (replies.isEmpty() && (dialogue.replies != null && !dialogue.replies.isEmpty())) return true;
if (replies.size() != dialogue.replies.size()) return true;
for (WriterReply reply : replies) {
if (reply.hasChanged()) return true;
}
return false;
}
}
public abstract class SpecialDialogue extends WriterDialogue {
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(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 class FightDialogue extends SpecialDialogue {
public static final String id = Dialogue.Reply.FIGHT_PHRASE_ID;
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 class RemoveNPCDialogue extends SpecialDialogue {
public static final String id = Dialogue.Reply.REMOVE_PHRASE_ID;
public SpecialDialogue duplicate() {return new RemoveNPCDialogue();}
}
public class WriterReply extends WriterNode {
public WriterDialogue parent;
public String next_dialogue_id;
public WriterDialogue next_dialogue;
public Dialogue.Reply reply;
public WriterReply() {}
public WriterReply(WriterDialogue parent) {
this.parent = parent;
this.text = "";
parent.replies.add(this);
}
public WriterReply(WriterDialogue parent, Dialogue.Reply reply) {
this.parent = parent;
this.reply = reply;
this.text = reply.text;
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 ){
this.next_dialogue = new WriterDialogue(reply.next_phrase);
}
}
@SuppressWarnings("rawtypes")
public WriterReply(WriterDialogue parent, Map json) {
this.parent = parent;
this.text = (String) json.get("text");
if (json.containsKey("next_dialogue_id")) {
next_dialogue_id = (String) json.get("next_dialogue_id");
}
}
@Override
public String getTitle() {
return "Reply in "+parent.id_prefix+parent.index;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public Map toJson(List<WriterDialogue> visited, List<Map> jsonData) {
Map replyJson = new LinkedHashMap();
replyJson.put("text", text);
replyJson.put("special", isSpecial());
if (next_dialogue != null) {
replyJson.put("next_dialogue_id", next_dialogue.getID());
next_dialogue.toJson(visited, jsonData);
}
return replyJson;
}
public boolean isSpecial() {return false;}
public Dialogue.Reply toReply(Map<WriterDialogue, Dialogue> visited, List<Dialogue> created, List<Dialogue> modified) {
if (reply == null) {
reply = new Dialogue.Reply();
}
reply.text = this.text;
if (this.next_dialogue != null) {
this.next_dialogue.toDialogue(visited, created, modified);
reply.next_phrase_id = this.next_dialogue.getID();
} else if (this.next_dialogue_id != null) {
reply.next_phrase_id = this.next_dialogue_id;
} else {
reply.next_phrase_id = Dialogue.Reply.EXIT_PHRASE_ID;
}
return reply;
}
public boolean hasChanged() {
if (reply == null) return true;
if (text == null && reply.text != null) return true;
if (text != null && reply.text == null) return true;
if (text != null && !text.equals(reply.text)) return true;
String targetDialogueId = next_dialogue != null ? next_dialogue.getID() : next_dialogue_id;
String replyTargetDialogueId = reply.next_phrase != null ? reply.next_phrase.id : reply.next_phrase_id;
if (targetDialogueId == null && replyTargetDialogueId != null) return true;
if (targetDialogueId != null && replyTargetDialogueId == null) return true;
if (targetDialogueId != null && !targetDialogueId.equals(replyTargetDialogueId)) return true;
return false;
}
}
public class SpecialReply extends WriterReply {
public boolean isSpecial() {return true;}
public SpecialReply(WriterDialogue parent, Dialogue.Reply reply) {
super(parent, reply);
}
public SpecialReply(WriterDialogue parent) {
super(parent);
}
public SpecialReply(WriterDialogue parent, @SuppressWarnings("rawtypes") Map json) {
super(parent, json);
}
}
public class EmptyReply extends SpecialReply {
public EmptyReply(WriterDialogue parent, Dialogue.Reply reply) {
super(parent, reply);
text = Dialogue.Reply.GO_NEXT_TEXT;
}
public EmptyReply(WriterDialogue parent) {
super(parent);
text = Dialogue.Reply.GO_NEXT_TEXT;
}
public EmptyReply(WriterDialogue parent, @SuppressWarnings("rawtypes") Map json) {
super(parent, json);
text = Dialogue.Reply.GO_NEXT_TEXT;
}
}
@Override
public String getDesc() {
return (this.state == State.modified ? "*" : "")+id;
}
@Override
public Project getProject() {
return parent.getProject();
}
@Override
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;
}
@Override
public GameDataElement clone() {
//TODO
return null;
}
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
// Useless here.
}
@Override
public String getProjectFilename() {
return WriterModeDataSet.DEFAULT_REL_PATH_IN_PROJECT;
}
@Override
public void save() {
((WriterModeDataSet)this.getParent()).save(this.jsonFile);
}
@Override
public List<SaveEvent> attemptSave() {
List<SaveEvent> events = ((WriterModeDataSet)parent).attemptSave();
if (events == null || events.isEmpty()) {
return null;
}
if (events.size() == 1 && events.get(0).type == SaveEvent.Type.alsoSave && events.get(0).target == this) {
save();
return null;
}
return events;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public Map toJson() {
List<Map> jsonData = new ArrayList<Map>();
begin.toJson(new ArrayList<WriterModeData.WriterDialogue>(), jsonData);
Map jsonObj = new LinkedHashMap();
jsonObj.put("id", id);
jsonObj.put("dialogues", jsonData);
return jsonObj;
}
@SuppressWarnings("rawtypes")
public void parse() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(jsonFile);
List gameDataElements = (List) parser.parse(reader);
for (Object obj : gameDataElements) {
Map jsonObj = (Map)obj;
String id = (String) jsonObj.get("id");
if (id != null && id.equals(this.id )) {
this.parse(jsonObj);
this.state = State.parsed;
break;
}
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("rawtypes")
public void parse(Map json) {
this.id = (String) json.get("id");
// this.sketchName = (String) json.get("name");
// List jsonRootsId = (List) json.get("roots_id");
// if (jsonRootsId != null) {
// for (Object jsonRootId : jsonRootsId) {
// rootsId.add((String) jsonRootId);
// }
// }
List jsonDialogues = (List) json.get("dialogues");
if (jsonDialogues != null) {
for (Object jsonDialogue : jsonDialogues) {
WriterDialogue dialogue = new WriterDialogue((Map)jsonDialogue);
nodesById.put(dialogue.getID(), dialogue);
}
}
this.state = State.parsed;
}
@Override
public void link() {
if (this.state == State.created) {
this.begin = new WriterDialogue();
begin.id_prefix = id;
begin.index = getNextIndex(id);
begin.text = "";
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
}
if (this.state == State.parsed) {
for (WriterDialogue dialogue : nodesById.values()) {
if (dialogue.dialogue_id != null) {
dialogue.dialogue = getProject().getDialogue(dialogue.dialogue_id);
}
if (dialogue.replies == null) continue;
for (WriterReply reply : dialogue.replies) {
if (reply.next_dialogue_id != null) {
if (isSpecial(reply.next_dialogue_id)) {
reply.next_dialogue = getSpecial(reply.next_dialogue_id);
} else {
reply.next_dialogue = nodesById.get(reply.next_dialogue_id);
}
}
//TODO Seriously, this is failure-prone by design. Can't do much better though...
List<Dialogue.Reply> linked = new ArrayList<Dialogue.Reply>(dialogue.dialogue.replies.size());
if (dialogue.dialogue != null && dialogue.dialogue.replies != null) {
//Try to hook to existing replies... not as easy when there's no ID.
Dialogue.Reply best = null;
int score, maxScore = 0;
for (Dialogue.Reply dReply : dialogue.dialogue.replies) {
//Never link twice to the same...
if (linked.contains(dReply)) continue;
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;
//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;
//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;
//Both have null text. It's not much, but it's something....
if (dReply.text == null && reply.text == null) score += 10;
if (score > maxScore) {
maxScore = score;
best = dReply;
}
}
if (maxScore > 0) {
reply.reply = best;
linked.add(best);
}
}
}
}
for (String rootId : rootsId) {
roots.add(nodesById.get(rootId));
}
}
if (this.state == State.linked) {
//Already linked.
return;
}
this.state = State.linked;
}
public boolean isSpecial(String id) {
if (id == null) return false;
if (ShopDialogue.id.equals(id)) return true;
if (FightDialogue.id.equals(id)) return true;
if (EndDialogue.id.equals(id)) return true;
if (RemoveNPCDialogue.id.equals(id)) return true;
return false;
}
public SpecialDialogue getSpecial(String id) {
if (id == null) return null;
if (ShopDialogue.id.equals(id)) return new ShopDialogue();
if (FightDialogue.id.equals(id)) return new FightDialogue();
if (EndDialogue.id.equals(id)) return new EndDialogue();
if (RemoveNPCDialogue.id.equals(id)) return new RemoveNPCDialogue();
return null;
}
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>();
begin.toDialogue(visited, created, modified);
for (Dialogue modifiedDialogue : modified) {
modifiedDialogue.childrenChanged(new ArrayList<ProjectTreeNode>());
}
return created;
}
}

View File

@@ -0,0 +1,266 @@
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 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.GameDataElement.State;
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;
public class WriterModeDataSet implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = 5434504851883441971L;
public static final String DEFAULT_REL_PATH_IN_PROJECT = "writer.json";
public GameSource parent;
public File writerFile;
public List<WriterModeData> writerModeDataList = new ArrayList<WriterModeData>();
public WriterModeDataSet(GameSource gameSource) {
this.parent = gameSource;
writerFile = new File(parent.baseFolder, DEFAULT_REL_PATH_IN_PROJECT);
parse();
}
@Override
public TreeNode getChildAt(int childIndex) {
return writerModeDataList.get(childIndex);
}
@Override
public int getChildCount() {
return writerModeDataList.size();
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public int getIndex(TreeNode node) {
return writerModeDataList.indexOf(node);
}
@Override
public boolean getAllowsChildren() {
return true;
}
@Override
public boolean isLeaf() {
return false;
}
@SuppressWarnings("rawtypes")
@Override
public Enumeration children() {
return Collections.enumeration(writerModeDataList);
}
@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 "Dialogue sketchs";
}
@Override
public Project getProject() {
return parent.getProject();
}
@Override
public GameDataSet getDataSet() {
return null;
}
@Override
public Image getIcon() {
return DefaultIcons.getStdClosedIcon();
}
@Override
public Image getOpenIcon() {
return DefaultIcons.getStdOpenIcon();
}
@Override
public Image getClosedIcon() {
return DefaultIcons.getStdClosedIcon();
}
@Override
public Image getLeafIcon() {
return null;
}
@Override
public Type getDataType() {
return parent.getDataType();
}
@Override
public boolean isEmpty() {
return writerModeDataList.isEmpty();
}
@SuppressWarnings("rawtypes")
public void save(File jsonFile) {
List<Map> dataToSave = new ArrayList<Map>();
for (WriterModeData data : writerModeDataList) {
if (data.jsonFile.equals(jsonFile)) {
dataToSave.add(data.toJson());
}
}
if (dataToSave.isEmpty() && writerFile.exists()) {
if (writerFile.delete()) {
Notification.addSuccess("File "+writerFile.getAbsolutePath()+" deleted.");
} else {
Notification.addError("Error deleting file "+writerFile.getAbsolutePath());
}
return;
}
StringWriter writer = new JsonPrettyWriter();
try {
JSONArray.writeJSONString(dataToSave, writer);
} catch (IOException e) {
//Impossible with a StringWriter
}
String toWrite = writer.toString();
try {
FileWriter w = new FileWriter(writerFile);
w.write(toWrite);
w.close();
for (WriterModeData element : writerModeDataList) {
element.state = GameDataElement.State.saved;
}
Notification.addSuccess("Json file "+writerFile.getAbsolutePath()+" saved.");
} catch (IOException e) {
Notification.addError("Error while writing json file "+writerFile.getAbsolutePath()+" : "+e.getMessage());
e.printStackTrace();
}
}
public List<SaveEvent> attemptSave() {
List<SaveEvent> events = new ArrayList<SaveEvent>();
for (WriterModeData data : writerModeDataList) {
if (data.state == State.created || data.state == State.modified) {
events.add(new SaveEvent(SaveEvent.Type.alsoSave, data));
}
}
return events;
}
@SuppressWarnings("rawtypes")
public void parse() {
if (!writerFile.exists()) return;
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(writerFile);
List writerDataListJson = (List) parser.parse(reader);
for (Object obj : writerDataListJson) {
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());
e.printStackTrace();
} catch (IOException e) {
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());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public WriterModeData getWriterSketch(String id) {
for (WriterModeData sketch : writerModeDataList) {
if (id.equals(sketch.id)){
return sketch;
}
}
return null;
}
public WriterModeData get(int index) {
return writerModeDataList.get(index);
}
public void add(WriterModeData node) {
ProjectTreeNode higherEmptyParent = this;
while (higherEmptyParent != null) {
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode)higherEmptyParent.getParent()).isEmpty()) higherEmptyParent = (ProjectTreeNode)higherEmptyParent.getParent();
else break;
}
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;
writerModeDataList.add(node);
node.writable = true;
if (node.jsonFile == null) node.jsonFile = this.writerFile;
node.parent = this;
if (higherEmptyParent != null) higherEmptyParent.notifyCreated();
else node.notifyCreated();
}
}

View File

@@ -36,7 +36,7 @@ public class AboutEditor extends Editor {
"<br/>" +
"Play <a href=\"https://play.google.com/store/apps/details?id=com.gpl.rpg.AndorsTrail\">Andor's Trail</a> for free on your Android device.<br/>" +
"Visit <a href=\"http://andorstrail.com/\">the official forum</a> to give or receive help.<br/>" +
"Open the project's <a href=\"https://code.google.com/p/andors-trail/\">Google Code page</a> to check out the game's source code.<br/>" +
"Open the project's <a href=\"https://github.com/Zukero/andors-trail/\">GitHub project page</a> to check out the game's source code.<br/>" +
"<br/>" +
"For content creation help, make sure to use the following resources:<br/>" +
"<a href=\"http://andorstrail.com/viewtopic.php?f=6&t=4560\">The contribution guide on the forums</a><br/>" +
@@ -81,6 +81,7 @@ public class AboutEditor extends Editor {
public static final AboutEditor instance = new AboutEditor();
@SuppressWarnings("resource")
private AboutEditor() {
this.name="About "+ATContentStudio.APP_NAME;
this.icon = new ImageIcon(DefaultIcons.getMainIconIcon());

View File

@@ -2,7 +2,7 @@ package com.gpl.rpg.atcontentstudio.ui;
import java.awt.Image;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.imageio.ImageIO;
@@ -11,8 +11,8 @@ import com.gpl.rpg.atcontentstudio.Notification;
public class DefaultIcons {
private static Map<String, Image> imageCache = new HashMap<String, Image>();
private static Map<String, Image> iconCache = new HashMap<String, Image>();
private static Map<String, Image> imageCache = new LinkedHashMap<String, Image>();
private static Map<String, Image> iconCache = new LinkedHashMap<String, Image>();
private static String MAIN_ICON_RES = "/com/gpl/rpg/atcontentstudio/img/andorstrainer.png";

View File

@@ -14,6 +14,8 @@ 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;
@@ -29,6 +31,7 @@ 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;
@@ -147,6 +150,51 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
});
return tfField;
}
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);
final JTextArea tfArea = new JTextArea(text);
tfArea.setEditable(editable);
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"));
// }
// });
return tfArea;
}
// public static JSpinner addIntegerField(JPanel pane, String label, Integer initialValue, boolean allowNegatives, boolean editable) {
// return addIntegerField(pane, label, initialValue, allowNegatives, editable, nullListener);
@@ -259,15 +307,18 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
return bbcb;
}
public static JComboBox addEnumValueBox(JPanel pane, String label, @SuppressWarnings("rawtypes") Enum[] values, @SuppressWarnings("rawtypes") Enum initialValue, boolean writable) {
@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) {}});
}
public static JComboBox addEnumValueBox(JPanel pane, String label, @SuppressWarnings("rawtypes") Enum[] values, @SuppressWarnings("rawtypes") Enum initialValue, boolean writable, final FieldUpdateListener listener) {
@SuppressWarnings("rawtypes")
public static JComboBox addEnumValueBox(JPanel pane, String label, Enum[] values, Enum initialValue, boolean writable, final FieldUpdateListener listener) {
JPanel comboPane = new JPanel();
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);
enumValuesCombo.setEnabled(writable);
enumValuesCombo.setSelectedItem(initialValue);
@@ -300,7 +351,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
final GDEComboModel<NPC> comboModel = new GDEComboModel<NPC>(proj, npc){
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Object getTypedElementAt(int index) {
public NPC getTypedElementAt(int index) {
return project.getNPC(index);
}
@Override
@@ -315,7 +366,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
final GDEComboModel<ActorCondition> comboModel = new GDEComboModel<ActorCondition>(proj, acond){
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Object getTypedElementAt(int index) {
public ActorCondition getTypedElementAt(int index) {
return project.getActorCondition(index);
}
@Override
@@ -330,7 +381,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
final GDEComboModel<Item> comboModel = new GDEComboModel<Item>(proj, item){
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Object getTypedElementAt(int index) {
public Item getTypedElementAt(int index) {
return project.getItem(index);
}
@Override
@@ -345,7 +396,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
final GDEComboModel<ItemCategory> comboModel = new GDEComboModel<ItemCategory>(proj, ic){
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Object getTypedElementAt(int index) {
public ItemCategory getTypedElementAt(int index) {
return project.getItemCategory(index);
}
@Override
@@ -360,7 +411,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
final GDEComboModel<Quest> comboModel = new GDEComboModel<Quest>(proj, quest){
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Object getTypedElementAt(int index) {
public Quest getTypedElementAt(int index) {
return project.getQuest(index);
}
@Override
@@ -375,7 +426,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
final GDEComboModel<Droplist> comboModel = new GDEComboModel<Droplist>(proj, droplist){
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Object getTypedElementAt(int index) {
public Droplist getTypedElementAt(int index) {
return project.getDroplist(index);
}
@Override
@@ -390,7 +441,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
final GDEComboModel<Dialogue> comboModel = new GDEComboModel<Dialogue>(proj, dialogue){
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Object getTypedElementAt(int index) {
public Dialogue getTypedElementAt(int index) {
return project.getDialogue(index);
}
@Override
@@ -405,7 +456,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
final GDEComboModel<TMXMap> comboModel = new GDEComboModel<TMXMap>(proj, map){
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Object getTypedElementAt(int index) {
public TMXMap getTypedElementAt(int index) {
return project.getMap(index);
}
@Override
@@ -416,6 +467,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
return addGDEBox(pane, label, map, TMXMap.class, comboModel, writable, listener);
}
@SuppressWarnings("unchecked")
public MyComboBox addGDEBox(JPanel pane, String label, GameDataElement gde, final Class<? extends GameDataElement> dataClass, final GDEComboModel<? extends GameDataElement> comboModel, final boolean writable, final FieldUpdateListener listener) {
JPanel gdePane = new JPanel();
gdePane.setLayout(new JideBoxLayout(gdePane, JideBoxLayout.LINE_AXIS, 6));
@@ -482,6 +534,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
return gdeBox;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public JList addBacklinksList(JPanel pane, GameDataElement gde) {
final JList list = new JList(new GDEBacklinksListModel(gde));
list.addMouseListener(new MouseAdapter() {
@@ -514,7 +567,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
return list;
}
public static abstract class GDEComboModel<E extends GameDataElement> extends AbstractListModel implements ComboBoxModel {
public static abstract class GDEComboModel<E extends GameDataElement> extends AbstractListModel<E> implements ComboBoxModel<E> {
private static final long serialVersionUID = -5854574666510314715L;
@@ -530,14 +583,14 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
public abstract int getSize();
@Override
public Object getElementAt(int index) {
public E getElementAt(int index) {
if (index == 0) {
return null;
}
return getTypedElementAt(index - 1);
}
public abstract Object getTypedElementAt(int index);
public abstract E getTypedElementAt(int index);
@SuppressWarnings("unchecked")
@Override
@@ -573,6 +626,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
this.writable = writable;
}
@SuppressWarnings("rawtypes")
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
@@ -595,7 +649,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
}
public static class GDEBacklinksListModel implements ListModel {
public static class GDEBacklinksListModel implements ListModel<GameDataElement> {
GameDataElement source;
@@ -620,7 +674,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
}
@Override
public Object getElementAt(int index) {
public GameDataElement getElementAt(int index) {
for (GameDataElement gde : source.getBacklinks()) {
if (index == 0) return gde;
index --;
@@ -628,7 +682,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
return null;
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -647,6 +701,7 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
}
}
@SuppressWarnings({"rawtypes", "unchecked"})
public class MyComboBox extends JComboBox implements ProjectElementListener {
private static final long serialVersionUID = -4184228604170642567L;
@@ -659,13 +714,11 @@ public abstract class Editor extends JPanel implements ProjectElementListener {
Editor.this.addElementListener(dataType, this);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void elementAdded(GameDataElement added, int index) {
((GDEComboModel)getModel()).itemAdded(added, index);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void elementRemoved(GameDataElement removed, int index) {
((GDEComboModel)getModel()).itemRemoved(removed, index);

View File

@@ -3,7 +3,7 @@ package com.gpl.rpg.atcontentstudio.ui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.swing.Action;
@@ -22,6 +22,7 @@ import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.saves.SavedGame;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.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;
@@ -33,13 +34,14 @@ import com.gpl.rpg.atcontentstudio.ui.map.TMXMapEditor;
import com.gpl.rpg.atcontentstudio.ui.map.WorldMapEditor;
import com.gpl.rpg.atcontentstudio.ui.saves.SavedGameEditor;
import com.gpl.rpg.atcontentstudio.ui.sprites.SpritesheetEditor;
import com.gpl.rpg.atcontentstudio.ui.tools.writermode.WriterModeEditor;
import com.jidesoft.swing.JideTabbedPane;
public class EditorsArea extends JPanel {
private static final long serialVersionUID = 8801849846876081538L;
private Map<Object, Editor> editors = new HashMap<Object, Editor>();
private Map<Object, Editor> editors = new LinkedHashMap<Object, Editor>();
private JideTabbedPane tabHolder;
public EditorsArea() {
@@ -155,6 +157,15 @@ public class EditorsArea extends JPanel {
openEditor(new WorldMapEditor(node));
}
public void openEditor(WriterModeData node) {
if (editors.containsKey(node)) {
tabHolder.setSelectedComponent(editors.get(node));
return;
}
node.link();
openEditor(new WriterModeEditor(node));
}
public void closeEditor(ProjectTreeNode node) {
if (editors.containsKey(node)) {
closeEditor(editors.get(node));

View File

@@ -10,6 +10,7 @@ import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultListCellRenderer;
@@ -27,6 +28,7 @@ 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;
@@ -58,6 +60,7 @@ public class JSONCreationWizard extends JDialog {
private JSONElement creation = null;
final JLabel message;
@SuppressWarnings("rawtypes")
final JComboBox dataTypeCombo;
final JTextField idField;
final JTextField nameField;
@@ -84,6 +87,7 @@ public class JSONCreationWizard extends JDialog {
dataTypeCombo.setEnabled(false);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public JSONCreationWizard(final Project proj) {
super(ATContentStudio.frame);
this.proj = proj;
@@ -293,6 +297,7 @@ public class JSONCreationWizard extends JDialog {
creation.id = idField.getText();
JSONCreationWizard.this.setVisible(false);
JSONCreationWizard.this.dispose();
creation.state = State.created;
proj.createElement(creation);
notifyCreated();
ATContentStudio.frame.selectInTree(creation);
@@ -499,6 +504,7 @@ public class JSONCreationWizard extends JDialog {
}
}
@SuppressWarnings("rawtypes")
public static class DataTypeComboModel implements ComboBoxModel {
DataType selected = DataType.none;
@@ -513,7 +519,7 @@ public class JSONCreationWizard extends JDialog {
return DataType.values()[index];
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -540,7 +546,7 @@ public class JSONCreationWizard extends JDialog {
private static final long serialVersionUID = 5621373849299980998L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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));
@@ -579,7 +585,7 @@ public class JSONCreationWizard extends JDialog {
public void elementCreated(JSONElement created);
}
private List<CreationCompletedListener> listeners = new ArrayList<JSONCreationWizard.CreationCompletedListener>();
private List<CreationCompletedListener> listeners = new CopyOnWriteArrayList<JSONCreationWizard.CreationCompletedListener>();
public void addCreationListener(CreationCompletedListener l) {
listeners.add(l);

View File

@@ -15,6 +15,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
@@ -75,6 +76,7 @@ public class JSONImportWizard extends JDialog {
JPanel pane;
JLabel message;
@SuppressWarnings("rawtypes")
JComboBox dataTypeCombo;
JRadioButton importFromFile;
JRadioButton importPasted;
@@ -83,11 +85,13 @@ public class JSONImportWizard extends JDialog {
JButton browse;
RSyntaxTextArea jsonPasteArea;
JScrollPane scroller;
@SuppressWarnings("rawtypes")
JList createdPreview;
JPanel buttonPane;
JButton ok, cancel;
ActionListener okListener, cancelListener;
@SuppressWarnings({ "rawtypes", "unchecked" })
public JSONImportWizard(Project proj) {
super(ATContentStudio.frame);
@@ -390,6 +394,7 @@ public class JSONImportWizard extends JDialog {
}
}
@SuppressWarnings("unchecked")
private void showImportPreviewScreen(final List<JSONElement> created) {
pane.removeAll();
message.setText("The following data has been found. Click \"Ok\" to confirm.");
@@ -404,11 +409,8 @@ public class JSONImportWizard extends JDialog {
okListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JSONElement lastNode = null;
for (JSONElement node : created) {
proj.createElement(node);
lastNode = node;
}
proj.createElements(created);
JSONElement lastNode = created.get(created.size() - 1);
if (lastNode != null) {
lastNode.save();
ATContentStudio.frame.selectInTree(lastNode);
@@ -432,6 +434,7 @@ public class JSONImportWizard extends JDialog {
pane.repaint();
}
@SuppressWarnings("unchecked")
private void showErrorScreen(List<String> errors) {
pane.removeAll();
message.setText("Failed to import. The following error(s) have been encountered:");
@@ -464,6 +467,7 @@ public class JSONImportWizard extends JDialog {
pane.repaint();
}
@SuppressWarnings("unchecked")
private void showWarningScreen(List<String> warnings, final List<JSONElement> created) {
pane.removeAll();
message.setText("The following warnings(s) were raised while importing:");
@@ -511,7 +515,7 @@ public class JSONImportWizard extends JDialog {
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") 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");
@@ -555,7 +559,7 @@ public class JSONImportWizard extends JDialog {
public static class ErrorRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = -4265342800284721660L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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));
@@ -568,7 +572,7 @@ public class JSONImportWizard extends JDialog {
public static class WarningRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = -3836045237946111606L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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));
@@ -577,6 +581,7 @@ public class JSONImportWizard extends JDialog {
}
}
@SuppressWarnings("rawtypes")
public static class GDEListModel implements ListModel {
List<? extends Object> source;
@@ -599,7 +604,7 @@ public class JSONImportWizard extends JDialog {
return null;
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -620,6 +625,7 @@ public class JSONImportWizard extends JDialog {
}
@SuppressWarnings("rawtypes")
public static class DataTypeComboModel implements ComboBoxModel {
DataType selected = DataType.none;
@@ -634,7 +640,7 @@ public class JSONImportWizard extends JDialog {
return DataType.values()[index];
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -661,7 +667,7 @@ public class JSONImportWizard extends JDialog {
private static final long serialVersionUID = 5621373849299980998L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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));

View File

@@ -5,9 +5,10 @@ import java.awt.Component;
import java.awt.Font;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
@@ -24,6 +25,7 @@ import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.NotificationListener;
@SuppressWarnings("rawtypes")
public class NotificationsPane extends JList {
private static final long serialVersionUID = -1100364214372392608L;
@@ -33,7 +35,7 @@ public class NotificationsPane extends JList {
public static final String warn_img_name = "/com/gpl/rpg/atcontentstudio/img/warn.png";
public static final String error_img_name = "/com/gpl/rpg/atcontentstudio/img/error.png";
public static final Map<Notification.Type, Icon> icons = new HashMap<Notification.Type, Icon>(Notification.Type.values().length);
public static final Map<Notification.Type, Icon> icons = new LinkedHashMap<Notification.Type, Icon>(Notification.Type.values().length);
static {
try {
@@ -47,6 +49,7 @@ public class NotificationsPane extends JList {
}
@SuppressWarnings("unchecked")
public NotificationsPane() {
super();
MyListModel model = new MyListModel();
@@ -99,7 +102,7 @@ public class NotificationsPane extends JList {
}
}
private List<ListDataListener> listeners = new ArrayList<ListDataListener>();
private List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);

View File

@@ -1,5 +1,6 @@
package com.gpl.rpg.atcontentstudio.ui;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@@ -8,18 +9,27 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
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;
import com.gpl.rpg.atcontentstudio.model.Workspace;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
@@ -30,7 +40,8 @@ public class ProjectCreationWizard extends JDialog {
private static final long serialVersionUID = -2854969975146867119L;
final JTextField projectNameField;
final JComboBox atSourceSelectionCombo;
final JComboBox<String> atSourceSelectionCombo;
final JComboBox<Project.ResourceSet> resourceSetToUse;
final JButton browse;
final JButton okButton;
@@ -42,7 +53,62 @@ public class ProjectCreationWizard extends JDialog {
super(ATContentStudio.frame);
setTitle("Create project");
projectNameField = new JTextField();
atSourceSelectionCombo = new JComboBox();
atSourceSelectionCombo = new JComboBox<String>();
resourceSetToUse = new JComboBox<Project.ResourceSet>(new ComboBoxModel<Project.ResourceSet>() {
Project.ResourceSet selected = Project.ResourceSet.gameData;
@Override
public int getSize() {
return Project.ResourceSet.values().length;
}
@Override
public ResourceSet getElementAt(int index) {
return Project.ResourceSet.values()[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);
}
@Override
public void setSelectedItem(Object anItem) {
selected = (ResourceSet) anItem;
}
@Override
public Object getSelectedItem() {
return selected;
}
});
resourceSetToUse.setRenderer(new ListCellRenderer<Project.ResourceSet>() {
@Override
public Component getListCellRendererComponent(
JList<? extends ResourceSet> list, ResourceSet value,
int index, boolean isSelected, boolean cellHasFocus) {
switch (value) {
case allFiles:
return new JLabel("All available files");
case debugData:
return new JLabel("Debug data");
case gameData:
return new JLabel("Real game data");
default:
return new JLabel();
}
}
});
browse = new JButton("Browse...");
okButton = new JButton("Ok");
cancelButton = new JButton("Cancel");
@@ -103,7 +169,7 @@ public class ProjectCreationWizard extends JDialog {
if (!Workspace.activeWorkspace.knownMapSourcesFolders.contains(atSourceFolder)) {
Workspace.activeWorkspace.knownMapSourcesFolders.add(atSourceFolder);
}
Workspace.createProject(projectNameField.getText(), atSourceFolder);
Workspace.createProject(projectNameField.getText(), atSourceFolder, (Project.ResourceSet)resourceSetToUse.getSelectedItem());
ProjectCreationWizard.this.dispose();
}
});
@@ -154,6 +220,17 @@ public class ProjectCreationWizard extends JDialog {
c.weightx = 20;
panel.add(browse, c);
c.gridy++;
c.gridx = 1;
c.gridwidth = 1;
c.weightx = 20;
panel.add(new JLabel("Resource set: "), c);
c.gridx++;
c.weightx = 80;
c.gridwidth = 2;
panel.add(resourceSetToUse, c);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new GridBagLayout());
GridBagConstraints c2 = new GridBagConstraints();

View File

@@ -11,6 +11,7 @@ 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;
@@ -37,6 +38,7 @@ import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.saves.SavedGame;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
import com.jidesoft.swing.TreeSearchable;
public class ProjectsTree extends JPanel {
@@ -201,6 +203,10 @@ public class ProjectsTree extends JPanel {
addNextSeparator = true;
popupMenu.add(new JMenuItem(actions.importJSON));
}
if (actions.createMap.isEnabled()) {
addNextSeparator = true;
popupMenu.add(new JMenuItem(actions.createMap));
}
if (actions.createWorldmap.isEnabled()) {
addNextSeparator = true;
popupMenu.add(new JMenuItem(actions.createWorldmap));
@@ -236,6 +242,23 @@ public class ProjectsTree extends JPanel {
addNextSeparator = false;
}
if (actions.testWriter.isEnabled()) {
addNextSeparator = true;
popupMenu.add(new JMenuItem(actions.testWriter));
}
// if (actions.testCommitWriter.isEnabled()) {
// addNextSeparator = true;
// popupMenu.add(new JMenuItem(actions.testCommitWriter));
// }
if (actions.createWriter.isEnabled()) {
addNextSeparator = true;
popupMenu.add(new JMenuItem(actions.createWriter));
}
if (addNextSeparator) {
popupMenu.add(new JSeparator());
addNextSeparator = false;
}
if (konamiCodeEntered) {
JMenuItem openTrainer = new JMenuItem("Start Andor's Trainer...");
popupMenu.add(openTrainer);
@@ -570,6 +593,8 @@ public class ProjectsTree extends JPanel {
ATContentStudio.frame.openEditor((TMXMap)node);
} else if (node instanceof WorldmapSegment) {
ATContentStudio.frame.openEditor((WorldmapSegment)node);
} else if (node instanceof WriterModeData) {
ATContentStudio.frame.openEditor((WriterModeData)node);
} else if (node instanceof SavedGame) {
if (konamiCodeEntered) {
ATContentStudio.frame.openEditor((SavedGame)node);
@@ -631,7 +656,7 @@ public class ProjectsTree extends JPanel {
return ((ProjectTreeNode)parent).getIndex((ProjectTreeNode) child);
}
List<TreeModelListener> listeners = new ArrayList<TreeModelListener>();
List<TreeModelListener> listeners = new CopyOnWriteArrayList<TreeModelListener>();
@Override
public void addTreeModelListener(TreeModelListener l) {

View File

@@ -35,11 +35,15 @@ public class SaveItemsWizard extends JDialog {
List<SaveEvent> events;
@SuppressWarnings("rawtypes")
JList movedToCreated;
@SuppressWarnings("rawtypes")
JList movedToAltered;
@SuppressWarnings("rawtypes")
JList willBeSaved;
@SuppressWarnings({ "unchecked", "rawtypes" })
public SaveItemsWizard(List<SaveEvent> events, GameDataElement originalRequester) {
super(ATContentStudio.frame);
this.events = events;
@@ -170,7 +174,6 @@ public class SaveItemsWizard extends JDialog {
buttonPane.add(okButton, JideBoxLayout.FIX);
pane.add(buttonPane, JideBoxLayout.FIX);
okButton.addActionListener(new ActionListener() {
@SuppressWarnings("unchecked")
@Override
public void actionPerformed(ActionEvent e) {
@@ -251,7 +254,7 @@ public class SaveItemsWizard extends JDialog {
private static final long serialVersionUID = 5764079243906396333L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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;

View File

@@ -34,6 +34,7 @@ import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
import com.gpl.rpg.atcontentstudio.model.saves.SavedGame;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
public class StudioFrame extends JFrame {
@@ -52,6 +53,7 @@ public class StudioFrame extends JFrame {
final JSplitPane topDown = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
final JSplitPane leftRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
@SuppressWarnings("rawtypes")
JList notifs = new NotificationsPane();
projectTree = new ProjectsTree();
editors = new EditorsArea();
@@ -127,6 +129,8 @@ public class StudioFrame extends JFrame {
fileMenu.add(new JMenuItem(actions.closeProject));
fileMenu.add(new JMenuItem(actions.deleteProject));
fileMenu.add(new JSeparator());
fileMenu.add(new JMenuItem(actions.editWorkspaceSettings));
fileMenu.add(new JSeparator());
fileMenu.add(new JMenuItem(actions.exitATCS));
getJMenuBar().add(fileMenu);
@@ -136,6 +140,7 @@ public class StudioFrame extends JFrame {
projectMenu.add(new JSeparator());
projectMenu.add(new JMenuItem(actions.createGDE));
projectMenu.add(new JMenuItem(actions.importJSON));
projectMenu.add(new JMenuItem(actions.createMap));
projectMenu.add(new JMenuItem(actions.createWorldmap));
projectMenu.add(new JMenuItem(actions.loadSave));
getJMenuBar().add(projectMenu);
@@ -193,6 +198,11 @@ public class StudioFrame extends JFrame {
editors.openEditor(node);
}
public void openEditor(WriterModeData node) {
node.link();
editors.openEditor(node);
}
public void openEditor(GameDataElement node) {
if (node instanceof JSONElement) {
@@ -201,6 +211,8 @@ public class StudioFrame extends JFrame {
openEditor((Spritesheet) node);
} else if (node instanceof TMXMap) {
openEditor((TMXMap) node);
} else if (node instanceof WriterModeData) {
openEditor((WriterModeData) node);
}
}

View File

@@ -0,0 +1,300 @@
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.ArrayList;
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;
import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.jidesoft.swing.JideBoxLayout;
public class TMXMapCreationWizard extends JDialog {
private static final long serialVersionUID = -474689694453543575L;
private static final String DEFAULT_TEMPLATE = "template.tmx";
private TMXMap creation = null;
final File templateFile;
final JLabel message;
final JRadioButton useTemplate, copyMap;
final JComboBox<TMXMap> templateCombo;
final JTextField idField;
final JButton ok;
final Project proj;
@SuppressWarnings({ "unchecked", "rawtypes" })
public TMXMapCreationWizard(final Project proj) {
super(ATContentStudio.frame);
this.proj = proj;
templateFile=new File(proj.baseContent.gameMaps.mapFolder, DEFAULT_TEMPLATE);
setTitle("Create new TMX map");
JPanel pane = new JPanel();
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.PAGE_AXIS, 6));
pane.add(new JLabel("Create a new TMX map."), JideBoxLayout.FIX);
message = new JLabel("Enter new map name:");
pane.add(message, JideBoxLayout.FIX);
final JPanel idPane = new JPanel();
idPane.setLayout(new BorderLayout());
JLabel idLabel = new JLabel("Internal ID: ");
idPane.add(idLabel, BorderLayout.WEST);
idField = new JTextField("");
idField.setEditable(true);
idPane.add(idField, BorderLayout.CENTER);
pane.add(idPane, JideBoxLayout.FIX);
useTemplate = new JRadioButton("Use default template file ("+DEFAULT_TEMPLATE+")");
useTemplate.setToolTipText(templateFile.getAbsolutePath());
pane.add(useTemplate, JideBoxLayout.FIX);
copyMap = new JRadioButton("Copy existing map");
pane.add(copyMap, JideBoxLayout.FIX);
ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(useTemplate);
radioGroup.add(copyMap);
final JPanel templatePane = new JPanel();
templatePane.setLayout(new BorderLayout());
JLabel templateLabel = new JLabel("Template to copy: ");
templatePane.add(templateLabel, BorderLayout.WEST);
templateCombo = new JComboBox(new TemplateComboModel());
templateCombo.setRenderer(new TemplateComboCellRenderer());
if (proj.getMap(DEFAULT_TEMPLATE) != null) templateCombo.setSelectedItem(proj.getMap(DEFAULT_TEMPLATE));
templatePane.add(templateCombo, BorderLayout.CENTER);
pane.add(templatePane, JideBoxLayout.FIX);
pane.add(templateCombo);
if (templateFile.exists()) {
useTemplate.setSelected(true);
copyMap.setSelected(false);
templateCombo.setEnabled(false);
} else {
useTemplate.setSelected(false);
useTemplate.setEnabled(false);
useTemplate.setToolTipText("Cannot find file "+templateFile.getAbsolutePath());
templateCombo.setEnabled(true);
copyMap.setSelected(true);
}
ActionListener radioListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (useTemplate.isSelected()) {
templateCombo.setEnabled(false);
} else if(copyMap.isSelected()) {
templateCombo.setEnabled(true);
}
updateStatus();
}
};
useTemplate.addActionListener(radioListener);
copyMap.addActionListener(radioListener);
templateCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateStatus();
}
});
pane.add(new JPanel(), JideBoxLayout.VARY);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new JideBoxLayout(buttonPane, JideBoxLayout.LINE_AXIS, 6));
buttonPane.add(new JPanel(), JideBoxLayout.VARY);
JButton cancel = new JButton("Cancel");
buttonPane.add(cancel, JideBoxLayout.FIX);
ok = new JButton("Ok");
buttonPane.add(ok, JideBoxLayout.FIX);
pane.add(new JPanel(), JideBoxLayout.VARY);
pane.add(buttonPane, JideBoxLayout.FIX);
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (copyMap.isSelected()) {
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");
TMXMapCreationWizard.this.setVisible(false);
TMXMapCreationWizard.this.dispose();
creation.state = State.created;
proj.createElement(creation);
notifyCreated();
ATContentStudio.frame.selectInTree(creation);
ATContentStudio.frame.openEditor(creation);
}
});
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
creation = null;
TMXMapCreationWizard.this.setVisible(false);
TMXMapCreationWizard.this.dispose();
}
});
DocumentListener statusUpdater = new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateStatus();
}
@Override
public void changedUpdate(DocumentEvent e) {
updateStatus();
}
};
idField.getDocument().addDocumentListener(statusUpdater);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(pane, BorderLayout.CENTER);
setMinimumSize(new Dimension(350,250));
updateStatus();
pack();
Dimension sdim = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wdim = getSize();
setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
}
public void updateStatus() {
boolean trouble = false;
message.setText("<html><font color=\"#00AA00\">Looks OK to me.</font></html>");
if (copyMap.isSelected() && templateCombo.getSelectedItem() == null) {
message.setText("<html><font color=\"#FF0000\">Select a map template below:</font></html>");
trouble = true;
} else if (idField.getText() == null || idField.getText().length() <= 0) {
message.setText("<html><font color=\"#FF0000\">Internal ID must not be empty.</font></html>");
trouble = true;
} else if (proj.getMap(idField.getText()) != null) {
if (proj.getMap(idField.getText()).getDataType() == GameSource.Type.created) {
message.setText("<html><font color=\"#FF0000\">A map with the same ID was already created in this project.</font></html>");
trouble = true;
} else if (proj.getMap(idField.getText()).getDataType() == GameSource.Type.altered) {
message.setText("<html><font color=\"#FF0000\">A map with the same ID exists in the game and is already altered in this project.</font></html>");
trouble = true;
} else if (proj.getMap(idField.getText()).getDataType() == GameSource.Type.source) {
message.setText("<html><font color=\"#FF9000\">A map with the same ID exists in the game. The new one will be added under \"altered\".</font></html>");
}
}
ok.setEnabled(!trouble);
message.revalidate();
message.repaint();
}
public static interface CreationCompletedListener {
public void mapCreated(TMXMap created);
}
private List<CreationCompletedListener> listeners = new CopyOnWriteArrayList<TMXMapCreationWizard.CreationCompletedListener>();
public void addCreationListener(CreationCompletedListener l) {
listeners.add(l);
}
public void notifyCreated() {
for (CreationCompletedListener l : listeners) {
l.mapCreated(creation);
}
}
class TemplateComboModel implements ComboBoxModel<TMXMap> {
Object selected;
@Override
public int getSize() {
return proj.getMapCount();
}
@Override
public TMXMap getElementAt(int index) {
return proj.getMap(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);
}
@Override
public void setSelectedItem(Object anItem) {
selected = anItem;
}
@Override
public Object getSelectedItem() {
return selected;
}
}
class TemplateComboCellRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = 5621373849299980998L;
@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 && value != null) {
((JLabel)c).setText(((TMXMap)value).getDesc());
((JLabel)c).setIcon(new ImageIcon(DefaultIcons.getTiledIconIcon()));
}
return c;
}
}
}

View File

@@ -6,12 +6,14 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
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.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.Action;
import javax.swing.JFileChooser;
@@ -19,8 +21,6 @@ import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.tree.TreePath;
import bsh.util.JConsole;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.ClosedProject;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
@@ -29,11 +29,14 @@ 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.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
import com.gpl.rpg.atcontentstudio.model.saves.SavedGamesSet;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeDataSet;
import com.gpl.rpg.atcontentstudio.ui.tools.BeanShellView;
import com.gpl.rpg.atcontentstudio.ui.tools.ItemsTableView;
import com.gpl.rpg.atcontentstudio.ui.tools.NPCsTableView;
@@ -130,6 +133,9 @@ public class WorkspaceActions {
} else if (element instanceof TMXMap) {
TMXMapSet parent = (TMXMapSet) element.getParent();
parent.tmxMaps.remove(element);
} else if (element instanceof WriterModeData) {
WriterModeDataSet parent = (WriterModeDataSet) element.getParent();
parent.writerModeDataList.remove(element);
}
}
new Thread() {
@@ -168,6 +174,12 @@ public class WorkspaceActions {
} else {
new SaveItemsWizard(events, null).setVisible(true);
}
} else if (node instanceof TMXMap) {
TMXMapSet parent = (TMXMapSet) node.getParent();
parent.tmxMaps.remove(node);
} else if (node instanceof WriterModeData) {
WriterModeDataSet parent = (WriterModeDataSet) node.getParent();
parent.writerModeDataList.remove(node);
}
}
}.start();
@@ -216,7 +228,16 @@ public class WorkspaceActions {
}
};
public ATCSAction createMap = new ATCSAction("Create TMX Map", "Opens the TMX Map creation wizard") {
public void actionPerformed(ActionEvent e) {
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);
}
};
public ATCSAction createWorldmap = new ATCSAction("Create Worldmap segment", "Opens the worldmap segment creation wizard") {
public void actionPerformed(ActionEvent e) {
if (selectedNode == null || selectedNode.getProject() == null) return;
@@ -314,6 +335,61 @@ public class WorkspaceActions {
};
};
public ATCSAction testWriter = 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);
//
//
// if (selectedNode == null || selectedNode.getProject() == null) return;
// WriterModeData data = new WriterModeData(selectedNode.getProject().createdContent.writerModeDataSet, "test_");
// JFrame frame = new JFrame("Writer Mode tests");
// frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// frame.getContentPane().setLayout(new BorderLayout());
// frame.getContentPane().add(new WriterModeEditor(data), BorderLayout.CENTER);
// frame.setMinimumSize(new Dimension(250, 200));
// frame.pack();
// frame.setVisible(true);
};
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode.getProject() != null);
}
};
/*public ATCSAction testCommitWriter = new ATCSAction("Export dialogue sketch", "Exports the dialogue sketch as real JSON data dialogues") {
public void actionPerformed(ActionEvent e) {
if (selectedNode == null || selectedNode.getProject() == null || !(selectedNode instanceof WriterModeData)) return;
WriterModeData wData = (WriterModeData)selectedNode;
Collection<Dialogue> exported = wData.toDialogue();
selectedNode.getProject().createElements(new ArrayList<JSONElement>(exported));
wData.begin.dialogue.save();
wData.save();
};
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode instanceof WriterModeData);
}
};*/
public ATCSAction createWriter = 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);
};
public void selectionChanged(ProjectTreeNode selectedNode, TreePath[] selectedPaths) {
setEnabled(selectedNode != null && selectedNode instanceof Dialogue);
}
};
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>();
public WorkspaceActions() {
@@ -324,6 +400,7 @@ public class WorkspaceActions {
actions.add(saveElement);
actions.add(deleteSelected);
actions.add(createGDE);
actions.add(createMap);
actions.add(importJSON);
actions.add(loadSave);
actions.add(compareItems);
@@ -331,6 +408,10 @@ public class WorkspaceActions {
actions.add(exportProject);
actions.add(showAbout);
actions.add(exitATCS);
actions.add(testWriter);
// actions.add(testCommitWriter);
actions.add(createWriter);
actions.add(editWorkspaceSettings);
selectionChanged(null, null);
}
@@ -362,7 +443,7 @@ public class WorkspaceActions {
@Override
public void actionPerformed(ActionEvent e) {};
public Map<String, Object> values = new HashMap<String, Object>();
public Map<String, Object> values = new LinkedHashMap<String, Object>();
@Override
public Object getValue(String key) {
@@ -392,7 +473,7 @@ public class WorkspaceActions {
return enabled;
}
private Set<PropertyChangeListener> listeners = new HashSet<PropertyChangeListener>();
private List<PropertyChangeListener> listeners = new CopyOnWriteArrayList<PropertyChangeListener>();
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {

View File

@@ -6,9 +6,12 @@ import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
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;
@@ -33,7 +36,7 @@ public class WorkspaceSelector extends JFrame {
final List<String> wsPaths = new ArrayList<String>();
//Active widgets declaration
final JComboBox combo = new JComboBox();
final JComboBox<String> combo = new JComboBox<String>();
final JButton browse = new JButton("Browse...");
final JButton cancel = new JButton("Cancel");
final JButton ok = new JButton("Ok");
@@ -108,9 +111,15 @@ public class WorkspaceSelector extends JFrame {
//Layout, labels and dialog behavior.
setTitle("Select your workspace");
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) {}
JPanel dialogPane = new JPanel();
dialogPane.setLayout(new BorderLayout());
dialogPane.add(logoLabel, BorderLayout.NORTH);
dialogPane.add(new JLabel("Workspace : "), BorderLayout.WEST);
dialogPane.add(combo, BorderLayout.CENTER);
dialogPane.add(browse, BorderLayout.EAST);

View File

@@ -0,0 +1,180 @@
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.JDialog;
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;
public class WorkspaceSettingsEditor extends JDialog {
private static final long serialVersionUID = -1326158719217162879L;
WorkspaceSettings settings;
JRadioButton useSystemDefaultMapEditorButton, useCustomMapEditorButton;
JTextField mapEditorCommandField;
JRadioButton useSystemDefaultImageViewerButton, useSystemDefaultImageEditorButton, useCustomImageEditorButton;
JTextField imageEditorCommandField;
public WorkspaceSettingsEditor(WorkspaceSettings settings) {
super(ATContentStudio.frame, "Workspace settings", true);
setIconImage(DefaultIcons.getMainIconImage());
this.settings = settings;
JPanel pane = new JPanel();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER);
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.PAGE_AXIS));
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new JideBoxLayout(buttonPane, JideBoxLayout.LINE_AXIS));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
pane.add(getExternalToolsPane(), JideBoxLayout.FIX);
pane.add(new JPanel(), JideBoxLayout.VARY);
buttonPane.add(new JPanel(), JideBoxLayout.VARY);
JButton ok = new JButton("Ok");
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
pushToModel();
dispose();
}
});
buttonPane.add(ok, JideBoxLayout.FIX);
JButton reset = new JButton("Reset to defaults");
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
resetDefaults();
}
});
buttonPane.add(reset, JideBoxLayout.FIX);
JButton cancel = new JButton("Cancel");
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
buttonPane.add(cancel, JideBoxLayout.FIX);
loadFromModel();
pack();
setVisible(true);
}
public JPanel getExternalToolsPane() {
CollapsiblePanel pane = new CollapsiblePanel("External tools");
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.PAGE_AXIS));
//Tiled
CollapsiblePanel tiledPane = new CollapsiblePanel("TMX Map viewer/editor");
tiledPane.setLayout(new JideBoxLayout(tiledPane, JideBoxLayout.PAGE_AXIS));
ButtonGroup tiledRadioGroup = new ButtonGroup();
useSystemDefaultMapEditorButton = new JRadioButton("Use system-default TMX Map editor");
tiledRadioGroup.add(useSystemDefaultMapEditorButton);
tiledPane.add(useSystemDefaultMapEditorButton, JideBoxLayout.FIX);
useCustomMapEditorButton = new JRadioButton("Use custom command to open TMX Map files");
tiledRadioGroup.add(useCustomMapEditorButton);
tiledPane.add(useCustomMapEditorButton, JideBoxLayout.FIX);
mapEditorCommandField = new JTextField();
tiledPane.add(mapEditorCommandField, JideBoxLayout.FIX);
ActionListener tiledRadioListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (useSystemDefaultMapEditorButton.equals(e.getSource())) {
mapEditorCommandField.setEnabled(false);
} else if (useCustomMapEditorButton.equals(e.getSource())) {
mapEditorCommandField.setEnabled(true);
}
}
};
useSystemDefaultMapEditorButton.addActionListener(tiledRadioListener);
useCustomMapEditorButton.addActionListener(tiledRadioListener);
pane.add(tiledPane, JideBoxLayout.FIX);
//Images
CollapsiblePanel imgPane = new CollapsiblePanel("Image viewer/editor");
imgPane.setLayout(new JideBoxLayout(imgPane, JideBoxLayout.PAGE_AXIS));
ButtonGroup imgRadioGroup = new ButtonGroup();
useSystemDefaultImageViewerButton = new JRadioButton("Use system-default image viewer");
imgRadioGroup.add(useSystemDefaultImageViewerButton);
imgPane.add(useSystemDefaultImageViewerButton, JideBoxLayout.FIX);
useSystemDefaultImageEditorButton = new JRadioButton("Use system-default image editor");
imgRadioGroup.add(useSystemDefaultImageEditorButton);
imgPane.add(useSystemDefaultImageEditorButton, JideBoxLayout.FIX);
useCustomImageEditorButton = new JRadioButton("Use custom command to open images");
imgRadioGroup.add(useCustomImageEditorButton);
imgPane.add(useCustomImageEditorButton, JideBoxLayout.FIX);
imageEditorCommandField = new JTextField();
imgPane.add(imageEditorCommandField, JideBoxLayout.FIX);
ActionListener imgRadioListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (useSystemDefaultMapEditorButton.equals(e.getSource())) {
imageEditorCommandField.setEnabled(false);
} else if (useSystemDefaultImageViewerButton.equals(e.getSource())) {
imageEditorCommandField.setEnabled(false);
} else if (useCustomImageEditorButton.equals(e.getSource())) {
imageEditorCommandField.setEnabled(true);
}
}
};
useSystemDefaultImageViewerButton.addActionListener(imgRadioListener);
useSystemDefaultImageEditorButton.addActionListener(imgRadioListener);
useCustomImageEditorButton.addActionListener(imgRadioListener);
pane.add(imgPane, JideBoxLayout.FIX);
pane.expand();
return pane;
}
public void loadFromModel() {
//Tiled
useSystemDefaultMapEditorButton.setSelected(settings.useSystemDefaultMapEditor.getCurrentValue());
useCustomMapEditorButton.setSelected(!settings.useSystemDefaultMapEditor.getCurrentValue());
mapEditorCommandField.setText(settings.mapEditorCommand.getCurrentValue());
//Images
useSystemDefaultImageViewerButton.setSelected(settings.useSystemDefaultImageViewer.getCurrentValue());
useSystemDefaultImageEditorButton.setSelected(settings.useSystemDefaultImageEditor.getCurrentValue());
useCustomImageEditorButton.setSelected(!(settings.useSystemDefaultImageViewer.getCurrentValue() || settings.useSystemDefaultImageEditor.getCurrentValue()));
imageEditorCommandField.setText(settings.imageEditorCommand.getCurrentValue());
}
public void pushToModel() {
//Tiled
settings.useSystemDefaultMapEditor.setCurrentValue(useSystemDefaultMapEditorButton.isSelected());
settings.mapEditorCommand.setCurrentValue(mapEditorCommandField.getText());
//Images
settings.useSystemDefaultImageViewer.setCurrentValue(useSystemDefaultImageViewerButton.isSelected());
settings.useSystemDefaultImageEditor.setCurrentValue(useSystemDefaultImageEditorButton.isSelected());
settings.imageEditorCommand.setCurrentValue(imageEditorCommandField.getText());
settings.save();
}
public void resetDefaults() {
settings.resetDefault();
settings.save();
loadFromModel();
}
}

View File

@@ -7,6 +7,7 @@ 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.JButton;
import javax.swing.JDialog;
@@ -144,7 +145,7 @@ public class WorldmapCreationWizard extends JDialog {
public void segmentCreated(WorldmapSegment created);
}
private List<CreationCompletedListener> listeners = new ArrayList<WorldmapCreationWizard.CreationCompletedListener>();
private List<CreationCompletedListener> listeners = new CopyOnWriteArrayList<WorldmapCreationWizard.CreationCompletedListener>();
public void addCreationListener(CreationCompletedListener l) {
listeners.add(l);

View File

@@ -7,6 +7,7 @@ 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.JButton;
import javax.swing.JDialog;
@@ -176,7 +177,7 @@ public class WorldmapLabelEditionWizard extends JDialog {
public void labelCreated(WorldmapSegment.NamedArea created);
}
private List<CreationCompletedListener> listeners = new ArrayList<WorldmapLabelEditionWizard.CreationCompletedListener>();
private List<CreationCompletedListener> listeners = new CopyOnWriteArrayList<WorldmapLabelEditionWizard.CreationCompletedListener>();
public void addCreationListener(CreationCompletedListener l) {
listeners.add(l);

View File

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

View File

@@ -30,6 +30,7 @@ public class ActorConditionEditor extends JSONElementEditor {
private JButton acIcon;
private JTextField idField;
private JTextField nameField;
@SuppressWarnings("rawtypes")
private JComboBox categoryBox;
private IntegerBasedCheckBox positiveBox;
private IntegerBasedCheckBox stackingBox;

View File

@@ -12,6 +12,7 @@ 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.DefaultListCellRenderer;
import javax.swing.ImageIcon;
@@ -23,6 +24,7 @@ import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
@@ -79,28 +81,35 @@ public class DialogueEditor extends JSONElementEditor {
private static final int SHOP_INDEX = 5;
private JTextField idField;
private JTextField messageField;
private JTextArea messageField;
private MyComboBox switchToNpcBox;
private RewardsListModel rewardsListModel;
@SuppressWarnings("rawtypes")
private JList rewardsList;
@SuppressWarnings("rawtypes")
private JComboBox rewardTypeCombo;
private JPanel rewardsParamsPane;
private MyComboBox rewardMap;
private JTextField rewardObjId;
private JComboBox rewardObjIdCombo;
private MyComboBox rewardObj;
private JSpinner rewardValue;
private RepliesListModel repliesListModel;
@SuppressWarnings("rawtypes")
private JList repliesList;
private JPanel repliesParamsPane;
@SuppressWarnings("rawtypes")
private JComboBox replyTypeCombo;
private MyComboBox replyNextPhrase;
private String replyTextCache = null;
private JTextField replyText;
private ReplyRequirementsListModel requirementsListModel;
@SuppressWarnings("rawtypes")
private JList requirementsList;
@SuppressWarnings("rawtypes")
private JComboBox requirementTypeCombo;
private JPanel requirementParamsPane;
private MyComboBox requirementObj;
@@ -108,17 +117,46 @@ public class DialogueEditor extends JSONElementEditor {
private JSpinner requirementValue;
private BooleanBasedCheckBox requirementNegated;
private DialogueGraphView dialogueGraphView;
public DialogueEditor(Dialogue dialogue) {
super(dialogue, dialogue.getDesc(), dialogue.getIcon());
addEditorTab(form_view_id, getFormView());
addEditorTab(json_view_id, getJSONView());
JPanel pane = new JPanel();
pane.setLayout(new BorderLayout());
pane.add(new JScrollPane(new DialogueGraphView(dialogue, null)), BorderLayout.CENTER);
addEditorTab(graph_view_id, pane);
addEditorTab(graph_view_id, createDialogueGraphView(dialogue));
}
public JPanel createDialogueGraphView(final Dialogue dialogue) {
final JPanel pane = new JPanel();
pane.setLayout(new BorderLayout());
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() {
@Override
public void actionPerformed(ActionEvent e) {
pane.remove(dialogueGraphView);
dialogueGraphView = new DialogueGraphView(dialogue, null);
pane.add(dialogueGraphView, BorderLayout.CENTER);
pane.revalidate();
pane.repaint();
}
});
return pane;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public void insertFormViewDataField(final JPanel pane) {
final Dialogue dialogue = (Dialogue) target;
@@ -127,7 +165,7 @@ public class DialogueEditor extends JSONElementEditor {
createButtonPane(pane, dialogue.getProject(), dialogue, Dialogue.class, dialogue.getImage(), null, listener);
idField = addTextField(pane, "Internal ID: ", dialogue.id, dialogue.writable, listener);
messageField = addTextField(pane, "Message: ", dialogue.message, dialogue.writable, listener);
messageField = addTextArea(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: ");
@@ -320,37 +358,55 @@ public class DialogueEditor extends JSONElementEditor {
}
if (reward.type != null) {
switch (reward.type) {
case activateMapChangeArea:
case deactivateMapChangeArea:
case activateMapObjectGroup:
case deactivateMapObjectGroup:
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);
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);
rewardObj = null;
rewardValue = null;
break;
case deactivateSpawnArea:
case removeSpawnArea:
case spawnAll:
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;
rewardValue = null;
break;
case actorCondition:
rewardMap = null;
rewardObjId = null;
rewardObjIdCombo = null;
rewardObj = addActorConditionBox(pane, ((Dialogue)target).getProject(), "Actor Condition: ", (ActorCondition) reward.reward_obj, writable, listener);
rewardValue = addIntegerField(pane, "Duration: ", reward.reward_value, false, writable, listener);
break;
case alignmentChange:
rewardMap = null;
rewardObjId = addTextField(pane, "Faction: ", reward.reward_obj_id, writable, listener);
rewardObjIdCombo = null;
rewardObj = null;
rewardValue = addIntegerField(pane, "Value: ", reward.reward_value, true, writable, listener);
break;
case createTimer:
rewardMap = null;
rewardObjId = addTextField(pane, "Timer ID: ", reward.reward_obj_id, writable, listener);
rewardObjIdCombo = null;
rewardObj = null;
rewardValue = null;
break;
case dropList:
rewardMap = null;
rewardObjId = null;
rewardObjIdCombo = null;
rewardObj = addDroplistBox(pane, ((Dialogue)target).getProject(), "Droplist: ", (Droplist) reward.reward_obj, writable, listener);
rewardValue = null;
break;
@@ -363,12 +419,14 @@ public class DialogueEditor extends JSONElementEditor {
case questProgress:
rewardMap = null;
rewardObjId = null;
rewardObjIdCombo = null;
rewardObj = addQuestBox(pane, ((Dialogue)target).getProject(), "Quest: ", (Quest) reward.reward_obj, writable, listener);
rewardValue = addIntegerField(pane, "Step ID: ", reward.reward_value, false, writable, listener);
break;
case skillIncrease:
rewardMap = null;
rewardObjId = addTextField(pane, "Skill ID: ", reward.reward_obj_id, writable, listener);
rewardObjIdCombo = null;
rewardObj = null;
rewardValue = null;
break;
@@ -379,6 +437,7 @@ public class DialogueEditor extends JSONElementEditor {
pane.repaint();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public void updateRepliesEditorPane(final JPanel pane, final Dialogue.Reply reply, final FieldUpdateListener listener) {
pane.removeAll();
if (replyNextPhrase != null) {
@@ -645,7 +704,7 @@ public class DialogueEditor extends JSONElementEditor {
}
public static class RewardsListModel implements ListModel {
public static class RewardsListModel implements ListModel<Dialogue.Reward> {
Dialogue source;
@@ -660,7 +719,7 @@ public class DialogueEditor extends JSONElementEditor {
}
@Override
public Object getElementAt(int index) {
public Dialogue.Reward getElementAt(int index) {
if (source.rewards == null) return null;
return source.rewards.get(index);
}
@@ -694,7 +753,7 @@ public class DialogueEditor extends JSONElementEditor {
}
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -711,71 +770,84 @@ public class DialogueEditor extends JSONElementEditor {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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;
if (reward.type != null) {
String rewardObjDesc = 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 activateMapChangeArea:
label.setText("Activate mapchange area "+rewardObjDesc+" on map "+reward.map_name);
break;
case actorCondition:
label.setText("Give actor condition "+rewardObjDesc+" for "+reward.reward_value+" turns");
if (reward.reward_obj != null) label.setIcon(new ImageIcon(reward.reward_obj.getIcon()));
break;
case alignmentChange:
label.setText("Change alignment for faction "+rewardObjDesc+" : "+reward.reward_value);
break;
case createTimer:
label.setText("Create timer "+rewardObjDesc);
break;
case deactivateMapChangeArea:
label.setText("Deactivate mapchange area "+rewardObjDesc+" on map "+reward.map_name);
break;
case deactivateSpawnArea:
label.setText("Deactivate spawnarea area "+rewardObjDesc+" on map "+reward.map_name);
break;
case dropList:
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);
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);
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);
break;
case skillIncrease:
label.setText("Increase skill "+rewardObjDesc+" level");
break;
case spawnAll:
label.setText("Respawn all monsters in spawnarea area "+rewardObjDesc+" on map "+reward.map_name);
break;
}
} else {
label.setText("New, undefined reward");
}
decorateRewardJLabel(label, reward);
}
return c;
}
}
public static void decorateRewardJLabel(JLabel label, Dialogue.Reward reward) {
if (reward.type != null) {
String rewardObjDesc = 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.setIcon(new ImageIcon(DefaultIcons.getObjectLayerIcon()));
break;
case actorCondition:
label.setText("Give actor condition "+rewardObjDesc+" for "+reward.reward_value+" turns");
if (reward.reward_obj != null) label.setIcon(new ImageIcon(reward.reward_obj.getIcon()));
break;
case alignmentChange:
label.setText("Change alignment for faction "+rewardObjDesc+" : "+reward.reward_value);
break;
case createTimer:
label.setText("Create timer "+rewardObjDesc);
break;
case deactivateMapObjectGroup:
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.setIcon(new ImageIcon(DefaultIcons.getNPCIcon()));
break;
case dropList:
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);
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);
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.setIcon(new ImageIcon(DefaultIcons.getNPCIcon()));
break;
case skillIncrease:
label.setText("Increase skill "+rewardObjDesc+" level");
break;
case spawnAll:
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.setIcon(new ImageIcon(DefaultIcons.getReplaceIcon()));
break;
}
} else {
label.setText("New, undefined reward");
}
}
public static class RepliesListModel implements ListModel {
public static class RepliesListModel implements ListModel<Dialogue.Reply> {
Dialogue source;
@@ -791,7 +863,7 @@ public class DialogueEditor extends JSONElementEditor {
}
@Override
public Object getElementAt(int index) {
public Dialogue.Reply getElementAt(int index) {
if (source.replies == null) return null;
return source.replies.get(index);
}
@@ -846,7 +918,7 @@ public class DialogueEditor extends JSONElementEditor {
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -863,7 +935,7 @@ public class DialogueEditor extends JSONElementEditor {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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);
@@ -909,7 +981,7 @@ public class DialogueEditor extends JSONElementEditor {
}
}
public static class ReplyRequirementsListModel implements ListModel {
public static class ReplyRequirementsListModel implements ListModel<Requirement> {
Dialogue.Reply reply;
@@ -924,7 +996,7 @@ public class DialogueEditor extends JSONElementEditor {
}
@Override
public Object getElementAt(int index) {
public Requirement getElementAt(int index) {
if (reply.requirements == null) return null;
return reply.requirements.get(index);
}
@@ -960,7 +1032,7 @@ public class DialogueEditor extends JSONElementEditor {
}
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -978,22 +1050,26 @@ public class DialogueEditor extends JSONElementEditor {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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(((Requirement)value).getDesc());
if (((Requirement)value).required_obj != null) {
if (((Requirement)value).required_obj.getIcon() != null) {
((JLabel)c).setIcon(new ImageIcon(((Requirement)value).required_obj.getIcon()));
}
} if (((Requirement)value).type == null) {
((JLabel)c).setText("New, undefined requirement.");
}
decorateRequirementJLabel((JLabel)c, (Requirement)value);
}
return c;
}
}
public static void decorateRequirementJLabel(JLabel label, Requirement req) {
label.setText(req.getDesc());
if (req.required_obj != null) {
if (req.required_obj.getIcon() != null) {
label.setIcon(new ImageIcon(req.required_obj.getIcon()));
}
} if (req.type == null) {
label.setText("New, undefined requirement.");
}
}
public class DialogueFieldUpdater implements FieldUpdateListener {
@Override
public void valueChanged(JComponent source, Object value) {
@@ -1019,6 +1095,10 @@ public class DialogueEditor extends JSONElementEditor {
} else if (source == rewardTypeCombo) {
if (selectedReward.type != value) {
selectedReward.type = (Dialogue.Reward.RewardType) value;
if (selectedReward.map != null) {
selectedReward.map.removeBacklink(dialogue);
}
selectedReward.map = null;
selectedReward.map_name = null;
selectedReward.reward_obj = null;
selectedReward.reward_obj_id = null;
@@ -1041,6 +1121,9 @@ public class DialogueEditor extends JSONElementEditor {
} else if (source == rewardObjId) {
selectedReward.reward_obj_id = rewardObjId.getText();
rewardsListModel.itemChanged(selectedReward);
} else if (source == rewardObjIdCombo) {
selectedReward.reward_obj_id = rewardObjIdCombo.getSelectedItem().toString();
rewardsListModel.itemChanged(selectedReward);
} else if (source == rewardObj) {
if (selectedReward.reward_obj != null) {
selectedReward.reward_obj.removeBacklink(dialogue);

View File

@@ -5,6 +5,7 @@ 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;
@@ -57,6 +58,7 @@ public class DroplistEditor extends JSONElementEditor {
addEditorTab(json_view_id, getJSONView());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void insertFormViewDataField(JPanel pane) {
@@ -146,7 +148,7 @@ public class DroplistEditor extends JSONElementEditor {
pane.repaint();
}
public class DroppedItemsListModel implements ListModel {
public class DroppedItemsListModel implements ListModel<Droplist.DroppedItem> {
Droplist source;
@@ -161,7 +163,7 @@ public class DroplistEditor extends JSONElementEditor {
}
@Override
public Object getElementAt(int index) {
public Droplist.DroppedItem getElementAt(int index) {
if (source.dropped_items == null) return null;
return source.dropped_items.get(index);
}
@@ -195,7 +197,7 @@ public class DroplistEditor extends JSONElementEditor {
}
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -212,7 +214,7 @@ public class DroplistEditor extends JSONElementEditor {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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);

View File

@@ -35,10 +35,14 @@ public class ItemCategoryEditor extends JSONElementEditor {
private JButton icIcon;
private JTextField idField;
private JTextField nameField;
@SuppressWarnings("rawtypes")
private JComboBox slotBox;
@SuppressWarnings("rawtypes")
private JComboBox typeBox;
@SuppressWarnings("rawtypes")
private JComboBox sizeBox;
@SuppressWarnings("unchecked")
@Override
public void insertFormViewDataField(JPanel pane) {
final ItemCategory ic = ((ItemCategory)target);
@@ -62,7 +66,7 @@ public class ItemCategoryEditor extends JSONElementEditor {
private static final long serialVersionUID = -8359181274986492979L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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)));

View File

@@ -5,7 +5,9 @@ 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.ButtonGroup;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
@@ -14,6 +16,7 @@ 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.JTextField;
@@ -59,6 +62,7 @@ public class ItemEditor extends JSONElementEditor {
private JTextField idField;
private JTextField nameField;
private JTextField descriptionField;
@SuppressWarnings("rawtypes")
private JComboBox typeBox;
private IntegerBasedCheckBox manualPriceBox;
private JSpinner baseCostField;
@@ -81,6 +85,7 @@ public class ItemEditor extends JSONElementEditor {
private JSpinner equipIncReequipCost;
private JSpinner equipIncAttackCost;
private ConditionsListModel equipConditionsModel;
@SuppressWarnings("rawtypes")
private JList equipConditionsList;
private MyComboBox equipConditionBox;
private JSpinner equipConditionMagnitude;
@@ -92,14 +97,20 @@ public class ItemEditor extends JSONElementEditor {
private JSpinner hitAPMin;
private JSpinner hitAPMax;
private SourceTimedConditionsListModel hitSourceConditionsModel;
@SuppressWarnings("rawtypes")
private JList hitSourceConditionsList;
private MyComboBox hitSourceConditionBox;
private JRadioButton hitSourceConditionClear;
private JRadioButton hitSourceConditionApply;
private JSpinner hitSourceConditionMagnitude;
private JSpinner hitSourceConditionDuration;
private JSpinner hitSourceConditionChance;
private TargetTimedConditionsListModel hitTargetConditionsModel;
@SuppressWarnings("rawtypes")
private JList hitTargetConditionsList;
private MyComboBox hitTargetConditionBox;
private JRadioButton hitTargetConditionClear;
private JRadioButton hitTargetConditionApply;
private JSpinner hitTargetConditionMagnitude;
private JSpinner hitTargetConditionDuration;
private JSpinner hitTargetConditionChance;
@@ -111,8 +122,11 @@ public class ItemEditor extends JSONElementEditor {
private JSpinner killAPMin;
private JSpinner killAPMax;
private SourceTimedConditionsListModel killSourceConditionsModel;
@SuppressWarnings("rawtypes")
private JList killSourceConditionsList;
private MyComboBox killSourceConditionBox;
private JRadioButton killSourceConditionClear;
private JRadioButton killSourceConditionApply;
private JSpinner killSourceConditionMagnitude;
private JSpinner killSourceConditionDuration;
private JSpinner killSourceConditionChance;
@@ -124,6 +138,7 @@ public class ItemEditor extends JSONElementEditor {
addEditorTab(json_view_id, getJSONView());
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void insertFormViewDataField(JPanel pane) {
@@ -454,55 +469,169 @@ public class ItemEditor extends JSONElementEditor {
}
public void updateHitSourceTimedConditionEditorPane(JPanel pane, Item.TimedConditionEffect condition, FieldUpdateListener listener) {
public void updateHitSourceTimedConditionEditorPane(JPanel pane, Item.TimedConditionEffect condition, final FieldUpdateListener listener) {
pane.removeAll();
if (hitSourceConditionBox != null) {
removeElementListener(hitSourceConditionBox);
}
if (condition == null) {
pane.revalidate();
pane.repaint();
return;
}
boolean writable = ((Item)target).writable;
Project proj = ((Item)target).getProject();
hitSourceConditionBox = addActorConditionBox(pane, proj, "Actor Condition: ", condition.condition, writable, listener);
hitSourceConditionMagnitude = addIntegerField(pane, "Magnitude: ", condition.magnitude, false, writable, listener);
hitSourceConditionDuration = addIntegerField(pane, "Duration: ", condition.duration, false, writable, listener);
hitSourceConditionChance = addDoubleField(pane, "Chance: ", condition.chance, writable, listener);
hitSourceConditionApply = new JRadioButton("Apply new condition");
pane.add(hitSourceConditionApply, JideBoxLayout.FIX);
hitSourceConditionMagnitude = addIntegerField(pane, "Magnitude: ", condition.magnitude == null ? null : condition.magnitude >= 0 ? condition.magnitude : 0, false, writable, listener);
hitSourceConditionDuration = addIntegerField(pane, "Duration: ", condition.duration, false, writable, listener);
hitSourceConditionClear = new JRadioButton("Clear active condition");
pane.add(hitSourceConditionClear, JideBoxLayout.FIX);
ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(hitSourceConditionApply);
radioGroup.add(hitSourceConditionClear);
if (condition != null && condition.magnitude != null && condition.magnitude == ActorCondition.CLEAR_AC_MAGNITUDE) {
hitSourceConditionClear.setSelected(true);
hitSourceConditionApply.setSelected(false);
hitSourceConditionMagnitude.setEnabled(false);
hitSourceConditionDuration.setEnabled(false);
} else {
hitSourceConditionClear.setSelected(false);
hitSourceConditionApply.setSelected(true);
hitSourceConditionMagnitude.setEnabled(true);
hitSourceConditionDuration.setEnabled(true);
}
hitSourceConditionClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(hitSourceConditionClear, new Boolean(hitSourceConditionClear.isSelected()));
}
});
hitSourceConditionApply.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(hitSourceConditionApply, new Boolean(hitSourceConditionApply.isSelected()));
}
});
pane.revalidate();
pane.repaint();
}
public void updateHitTargetTimedConditionEditorPane(JPanel pane, Item.TimedConditionEffect condition, FieldUpdateListener listener) {
public void updateHitTargetTimedConditionEditorPane(JPanel pane, Item.TimedConditionEffect condition, final FieldUpdateListener listener) {
pane.removeAll();
if (hitTargetConditionBox != null) {
removeElementListener(hitTargetConditionBox);
}
if (condition == null) {
pane.revalidate();
pane.repaint();
return;
}
boolean writable = ((Item)target).writable;
Project proj = ((Item)target).getProject();
hitTargetConditionBox = addActorConditionBox(pane, proj, "Actor Condition: ", condition.condition, writable, listener);
hitTargetConditionMagnitude = addIntegerField(pane, "Magnitude: ", condition.magnitude, false, writable, listener);
hitTargetConditionDuration = addIntegerField(pane, "Duration: ", condition.duration, false, writable, listener);
hitTargetConditionChance = addDoubleField(pane, "Chance: ", condition.chance, writable, listener);
hitTargetConditionApply = new JRadioButton("Apply new condition");
pane.add(hitTargetConditionApply, JideBoxLayout.FIX);
hitTargetConditionMagnitude = addIntegerField(pane, "Magnitude: ", condition.magnitude == null ? null : condition.magnitude >= 0 ? condition.magnitude : 0, false, writable, listener);
hitTargetConditionDuration = addIntegerField(pane, "Duration: ", condition.duration, false, writable, listener);
hitTargetConditionClear = new JRadioButton("Clear active condition");
pane.add(hitTargetConditionClear, JideBoxLayout.FIX);
ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(hitTargetConditionApply);
radioGroup.add(hitTargetConditionClear);
if (condition != null && condition.magnitude != null && condition.magnitude == ActorCondition.CLEAR_AC_MAGNITUDE) {
hitTargetConditionClear.setSelected(true);
hitTargetConditionApply.setSelected(false);
hitTargetConditionMagnitude.setEnabled(false);
hitTargetConditionDuration.setEnabled(false);
} else {
hitTargetConditionClear.setSelected(false);
hitTargetConditionApply.setSelected(true);
hitTargetConditionMagnitude.setEnabled(true);
hitTargetConditionDuration.setEnabled(true);
}
hitTargetConditionClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(hitTargetConditionClear, new Boolean(hitTargetConditionClear.isSelected()));
}
});
hitTargetConditionApply.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(hitTargetConditionApply, new Boolean(hitTargetConditionApply.isSelected()));
}
});
pane.revalidate();
pane.repaint();
}
public void updateKillSourceTimedConditionEditorPane(JPanel pane, Item.TimedConditionEffect condition, FieldUpdateListener listener) {
public void updateKillSourceTimedConditionEditorPane(JPanel pane, Item.TimedConditionEffect condition, final FieldUpdateListener listener) {
pane.removeAll();
if (killSourceConditionBox != null) {
removeElementListener(killSourceConditionBox);
}
if (condition == null) {
pane.revalidate();
pane.repaint();
return;
}
boolean writable = ((Item)target).writable;
Project proj = ((Item)target).getProject();
killSourceConditionBox = addActorConditionBox(pane, proj, "Actor Condition: ", condition.condition, writable, listener);
killSourceConditionMagnitude = addIntegerField(pane, "Magnitude: ", condition.magnitude, false, writable, listener);
killSourceConditionDuration = addIntegerField(pane, "Duration: ", condition.duration, false, writable, listener);
killSourceConditionChance = addDoubleField(pane, "Chance: ", condition.chance, writable, listener);
killSourceConditionApply = new JRadioButton("Apply new condition");
pane.add(killSourceConditionApply, JideBoxLayout.FIX);
killSourceConditionMagnitude = addIntegerField(pane, "Magnitude: ", condition.magnitude == null ? null : condition.magnitude >= 0 ? condition.magnitude : 0, false, writable, listener);
killSourceConditionDuration = addIntegerField(pane, "Duration: ", condition.duration, false, writable, listener);
killSourceConditionClear = new JRadioButton("Clear active condition");
pane.add(killSourceConditionClear, JideBoxLayout.FIX);
ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(killSourceConditionApply);
radioGroup.add(killSourceConditionClear);
if (condition != null && condition.magnitude != null && condition.magnitude == ActorCondition.CLEAR_AC_MAGNITUDE) {
killSourceConditionClear.setSelected(true);
killSourceConditionApply.setSelected(false);
killSourceConditionMagnitude.setEnabled(false);
killSourceConditionDuration.setEnabled(false);
} else {
killSourceConditionClear.setSelected(false);
killSourceConditionApply.setSelected(true);
killSourceConditionMagnitude.setEnabled(true);
killSourceConditionDuration.setEnabled(true);
}
killSourceConditionClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(killSourceConditionClear, new Boolean(killSourceConditionClear.isSelected()));
}
});
killSourceConditionApply.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.valueChanged(killSourceConditionApply, new Boolean(killSourceConditionApply.isSelected()));
}
});
pane.revalidate();
pane.repaint();
}
@@ -512,6 +641,11 @@ public class ItemEditor extends JSONElementEditor {
if (equipConditionBox != null) {
removeElementListener(equipConditionBox);
}
if (condition == null) {
pane.revalidate();
pane.repaint();
return;
}
boolean writable = ((Item)target).writable;
Project proj = ((Item)target).getProject();
@@ -523,7 +657,7 @@ public class ItemEditor extends JSONElementEditor {
pane.repaint();
}
public static class SourceTimedConditionsListModel implements ListModel {
public static class SourceTimedConditionsListModel implements ListModel<Item.TimedConditionEffect> {
Item.KillEffect source;
@@ -538,7 +672,7 @@ public class ItemEditor extends JSONElementEditor {
}
@Override
public Object getElementAt(int index) {
public Item.TimedConditionEffect getElementAt(int index) {
if (source.conditions_source == null) return null;
return source.conditions_source.get(index);
}
@@ -572,7 +706,7 @@ public class ItemEditor extends JSONElementEditor {
}
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -585,7 +719,7 @@ public class ItemEditor extends JSONElementEditor {
}
}
public static class TargetTimedConditionsListModel implements ListModel {
public static class TargetTimedConditionsListModel implements ListModel<Item.TimedConditionEffect> {
Item.HitEffect source;
@@ -600,7 +734,7 @@ public class ItemEditor extends JSONElementEditor {
}
@Override
public Object getElementAt(int index) {
public Item.TimedConditionEffect getElementAt(int index) {
if (source.conditions_target == null) return null;
return source.conditions_target.get(index);
}
@@ -634,7 +768,7 @@ public class ItemEditor extends JSONElementEditor {
}
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -651,7 +785,7 @@ public class ItemEditor extends JSONElementEditor {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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);
@@ -659,7 +793,11 @@ public class ItemEditor extends JSONElementEditor {
if (effect.condition != null) {
label.setIcon(new ImageIcon(effect.condition.getIcon()));
label.setText(effect.chance+"% chances to give "+effect.duration+" rounds of "+effect.condition.getDesc()+" x"+effect.magnitude);
if (effect.magnitude == ActorCondition.CLEAR_AC_MAGNITUDE) {
label.setText(effect.chance+"% chances to clear "+effect.condition.getDesc());
} else {
label.setText(effect.chance+"% chances to give "+effect.duration+" rounds of "+effect.condition.getDesc()+" x"+effect.magnitude);
}
} else {
label.setText("New, undefined actor condition effect.");
}
@@ -668,7 +806,7 @@ public class ItemEditor extends JSONElementEditor {
}
}
public static class ConditionsListModel implements ListModel {
public static class ConditionsListModel implements ListModel<Item.ConditionEffect> {
Item.EquipEffect source;
@@ -683,7 +821,7 @@ public class ItemEditor extends JSONElementEditor {
}
@Override
public Object getElementAt(int index) {
public Item.ConditionEffect getElementAt(int index) {
if (source.conditions == null) return null;
return source.conditions.get(index);
}
@@ -717,7 +855,7 @@ public class ItemEditor extends JSONElementEditor {
}
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -734,7 +872,7 @@ public class ItemEditor extends JSONElementEditor {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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);
@@ -977,6 +1115,20 @@ public class ItemEditor extends JSONElementEditor {
}
hitSourceConditionsModel.itemChanged(selectedHitEffectSourceCondition);
updateHit = true;
} else if (source == hitSourceConditionClear) {
selectedHitEffectSourceCondition.magnitude = ActorCondition.CLEAR_AC_MAGNITUDE;
selectedHitEffectSourceCondition.duration = null;
hitSourceConditionMagnitude.setEnabled(false);
hitSourceConditionDuration.setEnabled(false);
hitSourceConditionsModel.itemChanged(selectedHitEffectSourceCondition);
updateHit = true;
} else if (source == hitSourceConditionApply) {
selectedHitEffectSourceCondition.magnitude = 0;
selectedHitEffectSourceCondition.duration = 0;
hitSourceConditionMagnitude.setEnabled(true);
hitSourceConditionDuration.setEnabled(true);
hitSourceConditionsModel.itemChanged(selectedHitEffectSourceCondition);
updateHit = true;
} else if (source == hitSourceConditionMagnitude) {
selectedHitEffectSourceCondition.magnitude = (Integer) value;
hitSourceConditionsModel.itemChanged(selectedHitEffectSourceCondition);
@@ -1004,6 +1156,20 @@ public class ItemEditor extends JSONElementEditor {
}
hitTargetConditionsModel.itemChanged(selectedHitEffectTargetCondition);
updateHit = true;
} else if (source == hitTargetConditionClear) {
selectedHitEffectTargetCondition.magnitude = ActorCondition.CLEAR_AC_MAGNITUDE;
selectedHitEffectTargetCondition.duration = null;
hitTargetConditionMagnitude.setEnabled(false);
hitTargetConditionDuration.setEnabled(false);
hitTargetConditionsModel.itemChanged(selectedHitEffectTargetCondition);
updateHit = true;
} else if (source == hitTargetConditionApply) {
selectedHitEffectTargetCondition.magnitude = 0;
selectedHitEffectTargetCondition.duration = 0;
hitTargetConditionMagnitude.setEnabled(true);
hitTargetConditionDuration.setEnabled(true);
hitTargetConditionsModel.itemChanged(selectedHitEffectTargetCondition);
updateHit = true;
} else if (source == hitTargetConditionMagnitude) {
selectedHitEffectTargetCondition.magnitude = (Integer) value;
hitTargetConditionsModel.itemChanged(selectedHitEffectTargetCondition);
@@ -1047,6 +1213,20 @@ public class ItemEditor extends JSONElementEditor {
}
killSourceConditionsModel.itemChanged(selectedKillEffectCondition);
updateKill = true;
} else if (source == killSourceConditionClear) {
selectedKillEffectCondition.magnitude = ActorCondition.CLEAR_AC_MAGNITUDE;
selectedKillEffectCondition.duration = null;
killSourceConditionMagnitude.setEnabled(false);
killSourceConditionDuration.setEnabled(false);
killSourceConditionsModel.itemChanged(selectedKillEffectCondition);
updateKill = true;
} else if (source == killSourceConditionApply) {
selectedKillEffectCondition.magnitude = 0;
selectedKillEffectCondition.duration = 0;
killSourceConditionMagnitude.setEnabled(true);
killSourceConditionDuration.setEnabled(true);
killSourceConditionsModel.itemChanged(selectedKillEffectCondition);
updateKill = true;
} else if (source == killSourceConditionMagnitude) {
selectedKillEffectCondition.magnitude = (Integer) value;
killSourceConditionsModel.itemChanged(selectedKillEffectCondition);

View File

@@ -5,7 +5,7 @@ import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -40,7 +40,7 @@ public abstract class JSONElementEditor extends Editor {
private static final long serialVersionUID = -5889046987755079563L;
Map<String, JPanel> editorTabs = new HashMap<String, JPanel>();
Map<String, JPanel> editorTabs = new LinkedHashMap<String, JPanel>();
JideTabbedPane editorTabsHolder;
RSyntaxTextArea jsonEditorPane;
@@ -65,6 +65,15 @@ public abstract class JSONElementEditor extends Editor {
editorTabs.put(id, editor);
}
public void removeEditorTab(String id) {
if (id == null) return;
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());

View File

@@ -6,6 +6,7 @@ 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;
@@ -47,6 +48,7 @@ public class NPCEditor extends JSONElementEditor {
private static final String form_view_id = "Form";
private static final String json_view_id = "JSON";
private static final String dialogue_tree_id = "Dialogue Tree";
private NPC.TimedConditionEffect selectedHitEffectSourceCondition;
private NPC.TimedConditionEffect selectedHitEffectTargetCondition;
@@ -58,8 +60,10 @@ public class NPCEditor extends JSONElementEditor {
private JSpinner experienceField;
private MyComboBox dialogueBox;
private MyComboBox droplistBox;
@SuppressWarnings("rawtypes")
private JComboBox monsterClassBox;
private IntegerBasedCheckBox uniqueBox;
@SuppressWarnings("rawtypes")
private JComboBox moveTypeBox;
private CollapsiblePanel combatTraitPane;
@@ -83,6 +87,7 @@ public class NPCEditor extends JSONElementEditor {
private JSpinner hitEffectAPMax;
private SourceTimedConditionsListModel hitSourceConditionsListModel;
@SuppressWarnings("rawtypes")
private JList hitSourceConditionsList;
private MyComboBox sourceConditionBox;
private JSpinner sourceConditionMagnitude;
@@ -90,24 +95,73 @@ public class NPCEditor extends JSONElementEditor {
private JSpinner sourceConditionChance;
private TargetTimedConditionsListModel hitTargetConditionsListModel;
@SuppressWarnings("rawtypes")
private JList hitTargetConditionsList;
private MyComboBox targetConditionBox;
private JSpinner targetConditionMagnitude;
private JSpinner targetConditionDuration;
private JSpinner targetConditionChance;
private JPanel dialogueGraphPane;
private DialogueGraphView dialogueGraphView;
public NPCEditor(NPC npc) {
super(npc, npc.getDesc(), npc.getIcon());
addEditorTab(form_view_id, getFormView());
addEditorTab(json_view_id, getJSONView());
if (npc.dialogue != null) {
JPanel pane = new JPanel();
pane.setLayout(new BorderLayout());
pane.add(new JScrollPane(new DialogueGraphView(npc.dialogue, npc)), BorderLayout.CENTER);
addEditorTab("Dialogue Tree", pane);
createDialogueGraphView(npc);
addEditorTab(dialogue_tree_id, dialogueGraphPane);
}
}
public JPanel createDialogueGraphView(final NPC npc) {
dialogueGraphPane = new JPanel();
dialogueGraphPane.setLayout(new BorderLayout());
dialogueGraphView = new DialogueGraphView(npc.dialogue, npc);
dialogueGraphPane.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);
dialogueGraphPane.add(buttonPane, BorderLayout.NORTH);
reloadButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
reloadGraphView(npc);
}
});
return dialogueGraphPane;
}
public void reloadGraphView(NPC npc) {
if (npc.dialogue != null) {
if (dialogueGraphPane != null) {
dialogueGraphPane.remove(dialogueGraphView);
dialogueGraphView = new DialogueGraphView(npc.dialogue, npc);
dialogueGraphPane.add(dialogueGraphView, BorderLayout.CENTER);
dialogueGraphPane.revalidate();
dialogueGraphPane.repaint();
} else {
createDialogueGraphView(npc);
addEditorTab(dialogue_tree_id, dialogueGraphPane);
}
} else {
if (dialogueGraphPane != null) {
removeEditorTab(dialogue_tree_id);
dialogueGraphPane = null;
dialogueGraphView = null;
}
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void insertFormViewDataField(JPanel pane) {
final NPC npc = (NPC) target;
@@ -295,7 +349,7 @@ public class NPCEditor extends JSONElementEditor {
pane.repaint();
}
public static class TargetTimedConditionsListModel implements ListModel {
public static class TargetTimedConditionsListModel implements ListModel<NPC.TimedConditionEffect> {
NPC.HitEffect source;
@@ -310,7 +364,7 @@ public class NPCEditor extends JSONElementEditor {
}
@Override
public Object getElementAt(int index) {
public NPC.TimedConditionEffect getElementAt(int index) {
if (source.conditions_target == null) return null;
return source.conditions_target.get(index);
}
@@ -344,7 +398,7 @@ public class NPCEditor extends JSONElementEditor {
}
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -357,7 +411,7 @@ public class NPCEditor extends JSONElementEditor {
}
}
public static class SourceTimedConditionsListModel implements ListModel {
public static class SourceTimedConditionsListModel implements ListModel<NPC.TimedConditionEffect> {
NPC.HitEffect source;
@@ -372,7 +426,7 @@ public class NPCEditor extends JSONElementEditor {
}
@Override
public Object getElementAt(int index) {
public NPC.TimedConditionEffect getElementAt(int index) {
if (source.conditions_source == null) return null;
return source.conditions_source.get(index);
}
@@ -406,7 +460,7 @@ public class NPCEditor extends JSONElementEditor {
}
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -423,7 +477,7 @@ public class NPCEditor extends JSONElementEditor {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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);
@@ -487,6 +541,7 @@ public class NPCEditor extends JSONElementEditor {
} else {
npc.dialogue_id = null;
}
reloadGraphView(npc);
} else if (source == droplistBox) {
if (npc.droplist != null) {
npc.droplist.removeBacklink(npc);

View File

@@ -1,22 +1,28 @@
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.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
@@ -62,8 +68,8 @@ public class QuestEditor extends JSONElementEditor {
createButtonPane(pane, quest.getProject(), quest, Quest.class, quest.getImage(), null, listener);
addTextField(pane, "Internal ID: ", quest.id, quest.writable, listener);
addTextField(pane, "Quest Name: ", quest.name, quest.writable, listener);
idField = addTextField(pane, "Internal ID: ", quest.id, quest.writable, listener);
nameField = addTextField(pane, "Quest Name: ", quest.name, quest.writable, listener);
visibleBox = addIntegerBasedCheckBox(pane, "Visible in quest log", quest.visible_in_log, quest.writable, listener);
JPanel stagesPane = new JPanel();
@@ -79,6 +85,7 @@ public class QuestEditor extends JSONElementEditor {
stagesTable.getColumnModel().getColumn(3).setMinWidth(130);
stagesTable.getColumnModel().getColumn(3).setMaxWidth(130);
stagesTable.setCellSelectionEnabled(true);
stagesTable.getColumnModel().getColumn(1).setCellRenderer(new MultilineCellRenderer());
stagesPane.add(new JScrollPane(stagesTable), BorderLayout.CENTER);
if (quest.writable) {
JPanel buttonPane = new JPanel();
@@ -287,7 +294,7 @@ public class QuestEditor extends JSONElementEditor {
if (quest.stages.isEmpty()) quest.stages = null;
}
public List<TableModelListener> listeners = new ArrayList<TableModelListener>();
public List<TableModelListener> listeners = new CopyOnWriteArrayList<TableModelListener>();
@Override
public void addTableModelListener(TableModelListener l) {
@@ -330,6 +337,48 @@ public class QuestEditor extends JSONElementEditor {
updateJsonViewText(quest.toJsonString());
}
}
public class MultilineCellRenderer extends JTextArea implements TableCellRenderer {
private static final long serialVersionUID = 6539816623608859506L;
public MultilineCellRenderer() {
setLineWrap(true);
setWrapStyleWord(true);
//setOpaque(true);
}
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
if (isSelected) {
setForeground(stagesTable.getSelectionForeground());
setBackground(stagesTable.getSelectionBackground());
} else {
setForeground(stagesTable.getForeground());
setBackground(stagesTable.getBackground());
}
setFont(stagesTable.getFont());
if (hasFocus) {
setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
if (stagesTable.isCellEditable(row, column)) {
setForeground(UIManager.getColor("Table.focusCellForeground"));
setBackground(UIManager.getColor("Table.focusCellBackground"));
}
} else {
setBorder(BorderFactory.createLineBorder(getBackground(), 1));
}
setText((value == null ? "" : value.toString()));
int fh = getFontMetrics(getFont()).getHeight();
// int tl = getText().length();
setSize(stagesTable.getWidth(), fh);
stagesTable.setRowHeight(row, getPreferredSize().height);
return this;
}
}

View File

@@ -1,7 +1,9 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors.dialoguetree;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
@@ -9,6 +11,12 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolTip;
import javax.swing.ToolTipManager;
import prefuse.Display;
import prefuse.Visualization;
import prefuse.action.ActionList;
@@ -42,7 +50,10 @@ import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.gamedataeditors.DialogueEditor;
import com.jidesoft.swing.JideBoxLayout;
public class DialogueGraphView extends Display {
@@ -52,7 +63,6 @@ public class DialogueGraphView extends Display {
public static final String NODES = "graph.nodes";
public static final String EDGES = "graph.edges";
public static final String EDGES_LABELS = "edgesLabels";
public static final String AGGR = "aggregates";
public static final String LABEL = "label";
public static final String ICON = "icon";
@@ -147,6 +157,7 @@ public class DialogueGraphView extends Display {
setSize(500,500);
pan(250, 250);
setHighQuality(true);
addControlListener(new TooltipControl());
addControlListener(new DoubleClickControl());
addControlListener(new WheelZoomControl());
addControlListener(new ZoomControl());
@@ -434,6 +445,90 @@ public class DialogueGraphView extends Display {
}
}
}
class TooltipControl extends ControlAdapter {
@Override
public void itemEntered(VisualItem item, MouseEvent e) {
if (item.get(TARGET) != null) {
tooltippedItem = item;
if (!tooltipActivated) {
setToolTipText("");
ToolTipManager.sharedInstance().registerComponent(DialogueGraphView.this);
ToolTipManager.sharedInstance().setEnabled(true);
tooltipActivated = true;
}
}
}
@Override
public void itemExited(VisualItem item, MouseEvent e) {
//Hides the tooltip...
ToolTipManager.sharedInstance().setEnabled(false);
ToolTipManager.sharedInstance().unregisterComponent(DialogueGraphView.this);
tooltipActivated = false;
}
}
JToolTip tt = null;
private VisualItem tooltippedItem = null;
private VisualItem lastTTItem = null;
private boolean tooltipActivated = false;
@Override
public Point getToolTipLocation(MouseEvent event) {
return new Point(event.getX() + 5, event.getY() + 5);
}
@Override
public JToolTip createToolTip() {
if (tt == null) tt = super.createToolTip();
if (tooltippedItem == lastTTItem) {
return tt;
}
tt = super.createToolTip();
lastTTItem = tooltippedItem;
tt.setLayout(new BorderLayout());
JPanel content = new JPanel();
content.setLayout(new JideBoxLayout(content, JideBoxLayout.PAGE_AXIS));
JLabel label;
if (tooltippedItem != null) {
Object target = tooltippedItem.get(TARGET);
if (target != null) {
if (target instanceof Dialogue) {
Dialogue d = (Dialogue) target;
label = new JLabel(new ImageIcon(DefaultIcons.getDialogueIcon()));
label.setText(d.id);
content.add(label, JideBoxLayout.FIX);
if (tooltippedItem.get(REPLY) == null) {
if (d.rewards != null && !d.rewards.isEmpty()) {
for (Dialogue.Reward r : d.rewards) {
label = new JLabel();
DialogueEditor.decorateRewardJLabel(label, r);
content.add(label, JideBoxLayout.FIX);
}
}
} else {
Object replObj = tooltippedItem.get(REPLY);
if (replObj instanceof Dialogue.Reply) {
Dialogue.Reply r = (Dialogue.Reply) replObj;
if (r.requirements != null && !r.requirements.isEmpty()) {
for (Requirement req : r.requirements) {
label = new JLabel();
DialogueEditor.decorateRequirementJLabel(label, req);
content.add(label, JideBoxLayout.FIX);
}
}
}
}
}
}
}
tt.add(content, BorderLayout.CENTER);
tt.setPreferredSize(tt.getLayout().preferredLayoutSize(tt));
return tt;
}
}

View File

@@ -0,0 +1,116 @@
package com.gpl.rpg.atcontentstudio.ui.map;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.ui.tools.MatrixComposite;
public class MapColorFilters {
public static void applyColorfilter(TMXMap.ColorFilter colorFilter, Graphics2D g2d) {
Composite oldComp = g2d.getComposite();
Rectangle clip = g2d.getClipBounds();
MatrixComposite newComp = null;
float f=0.0f;
switch(colorFilter) {
case black20:
f=0.8f;
newComp = new MatrixComposite(new float[]{
f, 0.00f, 0.00f, 0.0f, 0.0f,
0.00f, f, 0.00f, 0.0f, 0.0f,
0.00f, 0.00f, f, 0.0f, 0.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
case black40:
f=0.6f;
newComp = new MatrixComposite(new float[]{
f, 0.00f, 0.00f, 0.0f, 0.0f,
0.00f, f, 0.00f, 0.0f, 0.0f,
0.00f, 0.00f, f, 0.0f, 0.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
case black60:
f=0.4f;
newComp = new MatrixComposite(new float[]{
f, 0.00f, 0.00f, 0.0f, 0.0f,
0.00f, f, 0.00f, 0.0f, 0.0f,
0.00f, 0.00f, f, 0.0f, 0.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
case black80:
f=0.2f;
newComp = new MatrixComposite(new float[]{
f, 0.00f, 0.00f, 0.0f, 0.0f,
0.00f, f, 0.00f, 0.0f, 0.0f,
0.00f, 0.00f, f, 0.0f, 0.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
case bw:
newComp = new MatrixComposite(new float[]{
0.33f, 0.59f, 0.11f, 0.0f, 0.0f,
0.33f, 0.59f, 0.11f, 0.0f, 0.0f,
0.33f, 0.59f, 0.11f, 0.0f, 0.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
case invert:
newComp = new MatrixComposite(new float[]{
-1.00f, 0.00f, 0.00f, 0.0f, 255.0f,
0.00f, -1.00f, 0.00f, 0.0f, 255.0f,
0.00f, 0.00f, -1.00f, 0.0f, 255.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
case redtint:
newComp = new MatrixComposite(new float[]{
1.20f, 0.20f, 0.20f, 0.0f, 25.0f,
0.00f, 0.80f, 0.00f, 0.0f, 0.0f,
0.00f, 0.00f, 0.80f, 0.0f, 0.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
case greentint:
newComp = new MatrixComposite(new float[]{
0.85f, 0.00f, 0.00f, 0.0f, 0.0f,
0.15f, 1.15f, 0.15f, 0.0f, 15.0f,
0.00f, 0.00f, 0.85f, 0.0f, 0.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
case bluetint:
newComp = new MatrixComposite(new float[]{
0.70f, 0.00f, 0.00f, 0.0f, 0.0f,
0.00f, 0.70f, 0.00f, 0.0f, 0.0f,
0.30f, 0.30f, 1.30f, 0.0f, 40.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
case none:
f=1f;
newComp = new MatrixComposite(new float[]{
f, 0.00f, 0.00f, 0.0f, 0.0f,
0.00f, f, 0.00f, 0.0f, 0.0f,
0.00f, 0.00f, f, 0.0f, 0.0f,
0.00f, 0.00f, 0.00f, 1.0f, 0.0f
});
break;
default:
break;
}
if (newComp != null) {
g2d.setComposite(newComp);
g2d.setPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f));
g2d.fill(clip);
g2d.setComposite(oldComp);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -10,7 +10,6 @@ import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import javax.swing.ButtonGroup;
@@ -25,6 +24,9 @@ import javax.swing.JViewport;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
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;
@@ -46,6 +48,9 @@ public class WorldMapEditor extends Editor {
private static final long serialVersionUID = -8358238912588729094L;
private RSyntaxTextArea editorPane;
public EditMode editMode = EditMode.moveViewSelect;
public enum EditMode {
@@ -72,6 +77,10 @@ public class WorldMapEditor extends Editor {
add(editorTabsHolder, BorderLayout.CENTER);
editorTabsHolder.add("Map", buildSegmentTab(worldmap));
JScrollPane xmlScroller = new JScrollPane(getXmlEditorPane(), JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
xmlScroller.getVerticalScrollBar().setUnitIncrement(16);
editorTabsHolder.add("XML", xmlScroller);
}
@Override
@@ -80,7 +89,24 @@ public class WorldMapEditor extends Editor {
}
public JPanel getXmlEditorPane() {
JPanel pane = new JPanel();
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.PAGE_AXIS, 6));
editorPane = new RSyntaxTextArea();
editorPane.setText(((WorldmapSegment)target).toXml());
editorPane.setEditable(false);
editorPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
pane.add(editorPane, JideBoxLayout.VARY);
return pane;
}
public void updateXmlViewText(String text) {
editorPane.setText(text);
}
@SuppressWarnings("unchecked")
private JPanel buildSegmentTab(final WorldmapSegment worldmap) {
JPanel pane = new JPanel();
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.PAGE_AXIS));
@@ -125,7 +151,7 @@ public class WorldMapEditor extends Editor {
final GDEComboModel<TMXMap> mapComboModel = new GDEComboModel<TMXMap>(worldmap.getProject(), null){
private static final long serialVersionUID = 2638082961277241764L;
@Override
public Object getTypedElementAt(int index) {
public TMXMap getTypedElementAt(int index) {
return project.getMap(index);
}
@Override
@@ -265,7 +291,7 @@ public class WorldMapEditor extends Editor {
if (map.labelledMaps.get(selectedLabel) != null) {
map.labelledMaps.get(selectedLabel).clear();
} else {
map.labelledMaps.put(selectedLabel, new LinkedList<String>());
map.labelledMaps.put(selectedLabel, new ArrayList<String>());
}
for (String s : mapView.selected) {
map.labelledMaps.get(selectedLabel).add(s);
@@ -320,7 +346,7 @@ public class WorldMapEditor extends Editor {
wiz.addCreationListener(new WorldmapLabelEditionWizard.CreationCompletedListener() {
@Override
public void labelCreated(NamedArea created) {
worldmap.labelledMaps.put(created.id, new LinkedList<String>());
worldmap.labelledMaps.put(created.id, new ArrayList<String>());
worldmap.labelledMaps.get(created.id).addAll(mapView.selected);
mapView.revalidate();
mapView.repaint();

View File

@@ -10,12 +10,13 @@ import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -44,7 +45,7 @@ public class WorldMapView extends JComponent implements Scrollable {
Project proj;
public Map<String, Rectangle> mapLocations = new HashMap<String, Rectangle>();
public Map<String, Rectangle> mapLocations = new LinkedHashMap<String, Rectangle>();
public Set<String> selected = new HashSet<String>();
@@ -86,6 +87,12 @@ public class WorldMapView extends JComponent implements Scrollable {
// paintObjectGroup(g2, map, (tiled.core.ObjectGroup) layer);
}
}
if (map.colorFilter != null) {
Shape oldClip = g2.getClip();
g2.setClip(0, 0, map.tmxMap.getWidth() * TILE_SIZE, map.tmxMap.getHeight() * TILE_SIZE);
MapColorFilters.applyColorfilter(map.colorFilter, g2);
g2.setClip(oldClip);
}
if (selected.contains(s)) {
g2.drawRect(0, 0, map.tmxMap.getWidth() * TILE_SIZE, map.tmxMap.getHeight() * TILE_SIZE);
}

View File

@@ -8,7 +8,7 @@ import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -34,14 +34,27 @@ public class SpriteChooser extends JDialog {
private static final int STD_HEIGHT = 32;
private static final int MAX_PER_ROW = 10;
public static Map<Project, Map<Spritesheet.Category, SpriteChooser>> cache = new HashMap<Project, Map<Spritesheet.Category,SpriteChooser>>();
public static Map<Project, Map<Spritesheet.Category, SpriteChooser>> cache = new LinkedHashMap<Project, Map<Spritesheet.Category,SpriteChooser>>();
public static Map<Project, Map<Spritesheet.Category, List<Spritesheet>>> cacheValidator = new LinkedHashMap<Project, Map<Category,List<Spritesheet>>>();
public static SpriteChooser getChooser(Project proj, Spritesheet.Category category) {
if (cache.get(proj) == null) {
cache.put(proj, new HashMap<Spritesheet.Category, SpriteChooser>());
cache.put(proj, new LinkedHashMap<Spritesheet.Category, SpriteChooser>());
}
if (cache.get(proj).get(category) == null) {
cache.get(proj).put(category, new SpriteChooser(proj, category));
} else {
List<Spritesheet> spritesheets = new ArrayList<Spritesheet>();
for (int i=0; i<proj.getSpritesheetCount(); i++) {
Spritesheet sheet = proj.getSpritesheet(i);
if (sheet.category == category) {
spritesheets.add(sheet);
}
}
if ( !spritesheets.equals(cacheValidator.get(proj).get(category)) ) {
cache.get(proj).put(category, new SpriteChooser(proj, category));
}
}
SpriteChooser wanted = cache.get(proj).get(category);
wanted.group.clearSelection();
@@ -65,11 +78,16 @@ public class SpriteChooser extends JDialog {
setTitle("Select a sprite");
setModalityType(ModalityType.APPLICATION_MODAL);
List<Spritesheet> spritesheets = new ArrayList<Spritesheet>();
for (Spritesheet sheet : proj.baseContent.gameSprites.spritesheets) {
for (int i=0; i<proj.getSpritesheetCount(); i++) {
Spritesheet sheet = proj.getSpritesheet(i);
if (sheet.category == category) {
spritesheets.add(sheet);
}
}
if (cacheValidator.get(proj) == null) {
cacheValidator.put(proj, new LinkedHashMap<Spritesheet.Category, List<Spritesheet>>());
}
cacheValidator.get(proj).put(category, spritesheets);
JPanel pane = new JPanel();

View File

@@ -4,19 +4,23 @@ import java.awt.BorderLayout;
import java.awt.Color;
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.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
@@ -41,8 +45,10 @@ import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
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.utils.DesktopIntegration;
import com.jidesoft.swing.JideBoxLayout;
import com.jidesoft.swing.JideTabbedPane;
@@ -50,12 +56,13 @@ public class SpritesheetEditor extends Editor {
private static final long serialVersionUID = 3956109815682889863L;
Map<String, JPanel> editorTabs = new HashMap<String, JPanel>();
Map<String, JPanel> editorTabs = new LinkedHashMap<String, JPanel>();
JideTabbedPane editorTabsHolder;
private JSpinner widthField;
private JSpinner heightField;
private JCheckBox animatedBox;
@SuppressWarnings("rawtypes")
private JComboBox categoryBox;
private JPanel spriteViewPane;
@@ -63,8 +70,8 @@ public class SpritesheetEditor extends Editor {
public static JComponent getWarningLabel() {
JLabel label = new JLabel(
"<html><i>" +
"The data presented here is not part of the game.<br/>" +
"What you change here will be changed in your ATCS project.<br/>" +
"The data accompamying the image here is not part of the game.<br/>" +
"What you change here will be changed in your ATCS project only.<br/>" +
"None of this is exported to JSON or TMX, although it must be set correctly in order to choose tiles & icons correctly.<br/>" +
"</i></html>");
return label;
@@ -82,7 +89,19 @@ public class SpritesheetEditor extends Editor {
pane.setLayout(new JideBoxLayout(pane, JideBoxLayout.PAGE_AXIS, 6));
add(getWarningLabel(), JideBoxLayout.FIX);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new JideBoxLayout(buttonPane, JideBoxLayout.LINE_AXIS));
JButton openImage = new JButton(new ImageIcon(DefaultIcons.getTileLayerImage()));
openImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DesktopIntegration.openImage(((Spritesheet)target).spritesheetFile);
}
});
buttonPane.add(openImage, JideBoxLayout.FIX);
buttonPane.add(getWarningLabel(), JideBoxLayout.FIX);
buttonPane.add(new JPanel(), JideBoxLayout.VARY);
pane.add(buttonPane, JideBoxLayout.FIX);
addLabelField(pane, "Spritesheet ID: ", sheet.id);
addLabelField(pane, "File: ", sheet.spritesheetFile.getAbsolutePath());
widthField = addIntegerField(pane, "Sprite width (px): ", sheet.spriteWidth, false, true, listener);
@@ -151,15 +170,16 @@ public class SpritesheetEditor extends Editor {
TableColumn col;
while (columns.hasMoreElements()) {
col = columns.nextElement();
col.setMinWidth(sheet.spriteWidth + 1);
col.setMaxWidth(sheet.spriteWidth + 1);
col.setMinWidth(sheet.spriteWidth + 4);
col.setMaxWidth(sheet.spriteWidth + 4);
}
spritesTable.setRowHeight(sheet.spriteHeight + 1);
spritesTable.setRowHeight(sheet.spriteHeight + 4);
pane.add(new JScrollPane(spritesTable), BorderLayout.CENTER);
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static JList addBacklinksList(JPanel pane, Spritesheet sheet) {
final JList list = new JList(new SpritesheetsBacklinksListModel(sheet));
list.addMouseListener(new MouseAdapter() {
@@ -240,7 +260,7 @@ public class SpritesheetEditor extends Editor {
}
List<TableModelListener> listeners = new ArrayList<TableModelListener>();
List<TableModelListener> listeners = new CopyOnWriteArrayList<TableModelListener>();
@Override
public void addTableModelListener(TableModelListener l) {
@@ -317,7 +337,7 @@ public class SpritesheetEditor extends Editor {
}
public static class SpritesheetsBacklinksListModel implements ListModel {
public static class SpritesheetsBacklinksListModel implements ListModel<ProjectTreeNode> {
Spritesheet sheet;
@@ -331,7 +351,7 @@ public class SpritesheetEditor extends Editor {
}
@Override
public Object getElementAt(int index) {
public ProjectTreeNode getElementAt(int index) {
for (ProjectTreeNode node : sheet.getBacklinks()) {
if (index == 0) return node;
index --;
@@ -339,7 +359,7 @@ public class SpritesheetEditor extends Editor {
return null;
}
List<ListDataListener> listeners = new ArrayList<ListDataListener>();
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
@@ -371,7 +391,7 @@ public class SpritesheetEditor extends Editor {
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") 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");
@@ -425,6 +445,7 @@ public class SpritesheetEditor extends Editor {
} else if (source == categoryBox) {
sheet.category = (Spritesheet.Category) value;
}
sheet.save();
}
}

View File

@@ -2,6 +2,7 @@ package com.gpl.rpg.atcontentstudio.ui.tools;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.Icon;
import javax.swing.ImageIcon;
@@ -18,7 +19,7 @@ public class ItemsTableView extends ElementTableView {
private static final long serialVersionUID = 1474255176349837609L;
public ItemsTableView(Project proj) {
super(new ItemsTableModel(proj), "Compare "+proj.getItemCount()+" items.", new ImageIcon(DefaultIcons.getItemIcon()));
super(new ItemsTableModel(proj), "Compare "+proj.getItemCountIncludingAltered()+" items.", new ImageIcon(DefaultIcons.getItemIcon()));
}
private static class ItemsTableModel implements TableModel {
@@ -32,12 +33,12 @@ public class ItemsTableView extends ElementTableView {
@Override
public int getRowCount() {
// return proj.getItemCount() + 1;
return proj.getItemCount();
return proj.getItemCountIncludingAltered();
}
@Override
public int getColumnCount() {
return 32;
return 33;
}
@Override
@@ -49,32 +50,33 @@ public class ItemsTableView extends ElementTableView {
case 3: return "Folder type"; //Source type (created, altered, source)
case 4: return "Use type"; //Use type ("none", "use", or equip slot name).
case 5: return "Category"; //Category id.
case 6: return "Manually set price ?"; //Has manual price
case 7: return "Price"; //Price
case 8: return "On use/hit - HP min";
case 9: return "On use/hit - HP max";
case 10: return "On use/hit - AP min";
case 11: return "On use/hit - AP max";
case 12: return "On use/hit - # conditions";
case 13: return "On kill - HP min";
case 14: return "On kill - HP max";
case 15: return "On kill - AP min";
case 16: return "On kill - AP max";
case 17: return "On kill - # conditions";
case 18: return "AD min";
case 19: return "AD max";
case 20: return "Max HP";
case 21: return "Max AP";
case 22: return "Attack cost";
case 23: return "AC";
case 24: return "BC";
case 25: return "DR";
case 26: return "CS";
case 27: return "CM";
case 28: return "Move cost";
case 29: return "Use cost";
case 30: return "Reequip cost";
case 31: return "# conditions";
case 6: return "DisplayType"; //Display type (ordinary, rare, extraordinary...)
case 7: return "Manually set price ?"; //Has manual price
case 8: return "Price"; //Price
case 9: return "On use/hit - HP min";
case 10: return "On use/hit - HP max";
case 11: return "On use/hit - AP min";
case 12: return "On use/hit - AP max";
case 13: return "On use/hit - # conditions";
case 14: return "On kill - HP min";
case 15: return "On kill - HP max";
case 16: return "On kill - AP min";
case 17: return "On kill - AP max";
case 18: return "On kill - # conditions";
case 19: return "AD min";
case 20: return "AD max";
case 21: return "Max HP";
case 22: return "Max AP";
case 23: return "Attack cost";
case 24: return "AC";
case 25: return "BC";
case 26: return "DR";
case 27: return "CS";
case 28: return "CM";
case 29: return "Move cost";
case 30: return "Use cost";
case 31: return "Reequip cost";
case 32: return "# conditions";
}
return null;
}
@@ -89,32 +91,33 @@ public class ItemsTableView extends ElementTableView {
case 3: return String.class; //Source type (created, altered, source)
case 4: return String.class; //Use type ("none", "use", or equip slot name).
case 5: return String.class; //Category id.
case 6: return Boolean.class; //Has manual price
case 7: return Integer.class; //Price
case 8: return Integer.class;//"On use/hit - HP min";
case 9: return Integer.class;//"On use/hit - HP max";
case 10: return Integer.class;//"On use/hit - AP min";
case 11: return Integer.class;//"On use/hit - AP max";
case 12: return Integer.class;//"On use/hit - # conditions";
case 13: return Integer.class;//"On kill - HP min";
case 14: return Integer.class;//"On kill - HP max";
case 15: return Integer.class;//"On kill - AP min";
case 16: return Integer.class;//"On kill - AP max";
case 17: return Integer.class;//"On kill - # conditions";
case 18: return Integer.class;//"AD min";
case 19: return Integer.class;//"AD max";
case 20: return Integer.class;//"Max HP";
case 21: return Integer.class;//"Max AP";
case 22: return Integer.class;//"Attack cost";
case 23: return Integer.class;//"AC";
case 24: return Integer.class;//"BC";
case 25: return Integer.class;//"DR";
case 26: return Integer.class;//"CS";
case 27: return Double.class;//"CM";
case 28: return Integer.class;//"Move cost";
case 29: return Integer.class;//"Use cost";
case 30: return Integer.class;//"Reequip cost";
case 31: return Integer.class;//"# conditions";
case 6: return String.class; //Display type (ordinary, rare, extraordinary...)
case 7: return Boolean.class; //Has manual price
case 8: return Integer.class; //Price
case 9: return Integer.class;//"On use/hit - HP min";
case 10: return Integer.class;//"On use/hit - HP max";
case 11: return Integer.class;//"On use/hit - AP min";
case 12: return Integer.class;//"On use/hit - AP max";
case 13: return Integer.class;//"On use/hit - # conditions";
case 14: return Integer.class;//"On kill - HP min";
case 15: return Integer.class;//"On kill - HP max";
case 16: return Integer.class;//"On kill - AP min";
case 17: return Integer.class;//"On kill - AP max";
case 18: return Integer.class;//"On kill - # conditions";
case 19: return Integer.class;//"AD min";
case 20: return Integer.class;//"AD max";
case 21: return Integer.class;//"Max HP";
case 22: return Integer.class;//"Max AP";
case 23: return Integer.class;//"Attack cost";
case 24: return Integer.class;//"AC";
case 25: return Integer.class;//"BC";
case 26: return Integer.class;//"DR";
case 27: return Integer.class;//"CS";
case 28: return Double.class;//"CM";
case 29: return Integer.class;//"Move cost";
case 30: return Integer.class;//"Use cost";
case 31: return Integer.class;//"Reequip cost";
case 32: return Integer.class;//"# conditions";
}
return null;
}
@@ -130,7 +133,7 @@ public class ItemsTableView extends ElementTableView {
// return getColumnName(columnIndex);
// }
// Item item = proj.getItem(rowIndex - 1);
Item item = proj.getItem(rowIndex);
Item item = proj.getItemIncludingAltered(rowIndex);
boolean canUse = item.category != null && item.category.action_type == ItemCategory.ActionType.use;
boolean canEquip = item.category != null && item.category.action_type == ItemCategory.ActionType.equip;
switch (columnIndex) {
@@ -144,15 +147,16 @@ public class ItemsTableView extends ElementTableView {
if (item.category.action_type != ItemCategory.ActionType.equip) return item.category.action_type.toString();
return item.category.slot.toString();
case 5: return item.category != null ? item.category.id : (item.category_id != null ? item.category_id : null ); //Category id.
case 6: return item.has_manual_price == null ? false : (item.has_manual_price == 1); //Has manual price
case 7: //Price
case 6: return item.display_type != null ? item.display_type.toString() : null; //Category id.
case 7: return item.has_manual_price == null ? false : (item.has_manual_price == 1); //Has manual price
case 8: //Price
if (item.has_manual_price == null || item.has_manual_price != 1) return item.computePrice();
return item.base_market_cost;
case 8: return canUse ? (item.kill_effect != null ? item.kill_effect.hp_boost_min : null) : (item.hit_effect != null ? item.hit_effect.hp_boost_min : null);//"On use/hit - HP min";
case 9: return canUse ? (item.kill_effect != null ? item.kill_effect.hp_boost_max : null) : (item.hit_effect != null ? item.hit_effect.hp_boost_max : null);//"On use/hit - HP max";
case 10: return canUse ? (item.kill_effect != null ? item.kill_effect.ap_boost_min : null) : (item.hit_effect != null ? item.hit_effect.ap_boost_min : null);//"On use/hit - AP min";
case 11: return canUse ? (item.kill_effect != null ? item.kill_effect.ap_boost_max : null) : (item.hit_effect != null ? item.hit_effect.ap_boost_max : null);//"On use/hit - AP max";
case 12: //"On use/hit - # conditions";
case 9: return canUse ? (item.kill_effect != null ? item.kill_effect.hp_boost_min : null) : (item.hit_effect != null ? item.hit_effect.hp_boost_min : null);//"On use/hit - HP min";
case 10: return canUse ? (item.kill_effect != null ? item.kill_effect.hp_boost_max : null) : (item.hit_effect != null ? item.hit_effect.hp_boost_max : null);//"On use/hit - HP max";
case 11: return canUse ? (item.kill_effect != null ? item.kill_effect.ap_boost_min : null) : (item.hit_effect != null ? item.hit_effect.ap_boost_min : null);//"On use/hit - AP min";
case 12: return canUse ? (item.kill_effect != null ? item.kill_effect.ap_boost_max : null) : (item.hit_effect != null ? item.hit_effect.ap_boost_max : null);//"On use/hit - AP max";
case 13: //"On use/hit - # conditions";
if (canUse) {
if (item.kill_effect != null && item.kill_effect.conditions_source != null) {
return item.kill_effect.conditions_source.size();
@@ -169,25 +173,25 @@ public class ItemsTableView extends ElementTableView {
return val;
}
return null;
case 13: return (!canUse && item.kill_effect != null) ? item.kill_effect.hp_boost_min : null;//"On kill - HP min";
case 14: return (!canUse && item.kill_effect != null) ? item.kill_effect.hp_boost_max : null;//"On kill - HP max";
case 15: return (!canUse && item.kill_effect != null) ? item.kill_effect.ap_boost_min : null;//"On kill - AP min";
case 16: return (!canUse && item.kill_effect != null) ? item.kill_effect.ap_boost_max : null;//"On kill - AP max";
case 17: return (!canUse && item.kill_effect != null && item.kill_effect.conditions_source != null) ? item.kill_effect.conditions_source.size() : null;//"On kill - # conditions";
case 18: return (canEquip && item.equip_effect != null) ? item.equip_effect.damage_boost_min : null;//"AD min";
case 19: return (canEquip && item.equip_effect != null) ? item.equip_effect.damage_boost_max : null;//"AD max";
case 20: return (canEquip && item.equip_effect != null) ? item.equip_effect.max_hp_boost : null;//"Max HP";
case 21: return (canEquip && item.equip_effect != null) ? item.equip_effect.max_ap_boost : null;//"Max AP";
case 22: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_attack_cost : null;//"Attack cost";
case 23: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_attack_chance : null;//"AC";
case 24: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_block_chance : null;//"BC";
case 25: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_damage_resistance : null;//"DR";
case 26: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_critical_skill : null;//"CS";
case 27: return (canEquip && item.equip_effect != null) ? item.equip_effect.critical_multiplier : null;//"CM";
case 28: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_move_cost : null;//"Move cost";
case 29: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_use_item_cost : null;//"Use cost";
case 30: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_reequip_cost : null;//"Reequip cost";
case 31: return (canEquip && item.equip_effect != null && item.equip_effect.conditions != null) ? item.equip_effect.conditions.size() : null;//"# conditions";
case 14: return (!canUse && item.kill_effect != null) ? item.kill_effect.hp_boost_min : null;//"On kill - HP min";
case 15: return (!canUse && item.kill_effect != null) ? item.kill_effect.hp_boost_max : null;//"On kill - HP max";
case 16: return (!canUse && item.kill_effect != null) ? item.kill_effect.ap_boost_min : null;//"On kill - AP min";
case 17: return (!canUse && item.kill_effect != null) ? item.kill_effect.ap_boost_max : null;//"On kill - AP max";
case 18: return (!canUse && item.kill_effect != null && item.kill_effect.conditions_source != null) ? item.kill_effect.conditions_source.size() : null;//"On kill - # conditions";
case 19: return (canEquip && item.equip_effect != null) ? item.equip_effect.damage_boost_min : null;//"AD min";
case 20: return (canEquip && item.equip_effect != null) ? item.equip_effect.damage_boost_max : null;//"AD max";
case 21: return (canEquip && item.equip_effect != null) ? item.equip_effect.max_hp_boost : null;//"Max HP";
case 22: return (canEquip && item.equip_effect != null) ? item.equip_effect.max_ap_boost : null;//"Max AP";
case 23: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_attack_cost : null;//"Attack cost";
case 24: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_attack_chance : null;//"AC";
case 25: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_block_chance : null;//"BC";
case 26: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_damage_resistance : null;//"DR";
case 27: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_critical_skill : null;//"CS";
case 28: return (canEquip && item.equip_effect != null) ? item.equip_effect.critical_multiplier : null;//"CM";
case 29: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_move_cost : null;//"Move cost";
case 30: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_use_item_cost : null;//"Use cost";
case 31: return (canEquip && item.equip_effect != null) ? item.equip_effect.increase_reequip_cost : null;//"Reequip cost";
case 32: return (canEquip && item.equip_effect != null && item.equip_effect.conditions != null) ? item.equip_effect.conditions.size() : null;//"# conditions";
}
return null;
}
@@ -197,7 +201,7 @@ public class ItemsTableView extends ElementTableView {
//not editable.
}
List<TableModelListener> listeners = new ArrayList<TableModelListener>();
List<TableModelListener> listeners = new CopyOnWriteArrayList<TableModelListener>();
@Override
public void addTableModelListener(TableModelListener l) {

View File

@@ -0,0 +1,124 @@
package com.gpl.rpg.atcontentstudio.ui.tools;
import java.awt.Composite;
import java.awt.CompositeContext;
import java.awt.RenderingHints;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
/**
* This Composite emulates the behaviour of Android's ColorMatrixColorFilter,
* except that you have to use this one a posteriori instead of a filtering paint.
*
* It applies a ColorMatrix to the destination pixels, regardless of potential "source" pixels.
* Once created and activated through Graphics2D.setComposite(), just paint anything over the pixels you want "filtered".
*
* Works on a per-pixel basis, no sampling of surrounding pixels, or anything.
*
* @author pochat
*
*/
public class MatrixComposite implements Composite {
final float[] matrix = new float[20];
/**
* Dismisses the source pixels. Just paint it black, or white, it only affects the dest RGB with the following formulae.
*
* R' = a*R + b*G + c*B + d*A + e;
* G' = f*R + g*G + h*B + i*A + j;
* B' = k*R + l*G + m*B + n*A + o;
* A' = p*R + q*G + r*B + s*A + t;
*
* @param matrix a flat float[20] array, giving the a..t values;
*/
public MatrixComposite(float[] matrix) {
if (matrix.length != this.matrix.length) {
throw new Error("MatrixComposite matrix must be of length "+this.matrix.length);
}
System.arraycopy(matrix, 0, this.matrix, 0, this.matrix.length);
}
@Override
public CompositeContext createContext(ColorModel srcColorModel,
ColorModel dstColorModel, RenderingHints hints) {
return new MatrixCompositeContext(this);
}
class MatrixCompositeContext implements CompositeContext {
MatrixComposite composite;
public MatrixCompositeContext(MatrixComposite composite) {
this.composite = composite;
}
@Override
public void dispose() {
}
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
if (src.getSampleModel().getDataType() != DataBuffer.TYPE_INT ||
dstIn.getSampleModel().getDataType() != DataBuffer.TYPE_INT ||
dstOut.getSampleModel().getDataType() != DataBuffer.TYPE_INT) {
throw new IllegalStateException(
"Source and destination must store pixels as INT.");
}
int width = Math.min(src.getWidth(), dstIn.getWidth());
int height = Math.min(src.getHeight(), dstIn.getHeight());
float alpha = 1.0f;
int[] srcPixel = new int[4];
int[] dstPixel = new int[4];
int[] srcPixels = new int[width];
int[] dstPixels = new int[width];
for (int y = 0; y < height; y++) {
src.getDataElements(0, y, width, 1, srcPixels);
dstIn.getDataElements(0, y, width, 1, dstPixels);
for (int x = 0; x < width; x++) {
// pixels are stored as INT_ARGB
// our arrays are [R, G, B, A]
int pixel = srcPixels[x];
srcPixel[0] = (pixel >> 16) & 0xFF;
srcPixel[1] = (pixel >> 8) & 0xFF;
srcPixel[2] = (pixel ) & 0xFF;
srcPixel[3] = (pixel >> 24) & 0xFF;
pixel = dstPixels[x];
dstPixel[0] = (pixel >> 16) & 0xFF;
dstPixel[1] = (pixel >> 8) & 0xFF;
dstPixel[2] = (pixel ) & 0xFF;
dstPixel[3] = (pixel >> 24) & 0xFF;
int[] result = applyMatrix(matrix, dstPixel);
// mixes the result with the opacity
dstPixels[x] = ((int) (dstPixel[3] + (result[3] - dstPixel[3]) * alpha) & 0xFF) << 24 |
((int) (dstPixel[0] + (result[0] - dstPixel[0]) * alpha) & 0xFF) << 16 |
((int) (dstPixel[1] + (result[1] - dstPixel[1]) * alpha) & 0xFF) << 8 |
(int) (dstPixel[2] + (result[2] - dstPixel[2]) * alpha) & 0xFF;
}
dstOut.setDataElements(0, y, width, 1, dstPixels);
}
}
private int[] applyMatrix(float[] matrix, int[] dstPixel) {
int[] result = new int[4];
result[0] = Math.max(0, Math.min(255, (int) (matrix[ 0] * dstPixel[0] + matrix[ 1] * dstPixel[1] + matrix[ 2] * dstPixel[2] + matrix[ 3] * dstPixel[3] + matrix[ 4]) ));
result[1] = Math.max(0, Math.min(255, (int) (matrix[ 5] * dstPixel[0] + matrix[ 6] * dstPixel[1] + matrix[ 7] * dstPixel[2] + matrix[ 8] * dstPixel[3] + matrix[ 9]) ));
result[2] = Math.max(0, Math.min(255, (int) (matrix[10] * dstPixel[0] + matrix[11] * dstPixel[1] + matrix[12] * dstPixel[2] + matrix[13] * dstPixel[3] + matrix[14]) ));
result[3] = Math.max(0, Math.min(255, (int) (matrix[15] * dstPixel[0] + matrix[16] * dstPixel[1] + matrix[17] * dstPixel[2] + matrix[18] * dstPixel[3] + matrix[19]) ));
return result;
}
}
}

View File

@@ -2,6 +2,7 @@ package com.gpl.rpg.atcontentstudio.ui.tools;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.Icon;
import javax.swing.ImageIcon;
@@ -17,7 +18,7 @@ public class NPCsTableView extends ElementTableView {
private static final long serialVersionUID = -4196852140899079621L;
public NPCsTableView(Project proj) {
super(new NPCsTableModel(proj), "Compare "+proj.getNPCCount()+" NPCs.", new ImageIcon(DefaultIcons.getNPCIcon()));
super(new NPCsTableModel(proj), "Compare "+proj.getNPCCountIncludingAltered()+" NPCs.", new ImageIcon(DefaultIcons.getNPCIcon()));
}
private static class NPCsTableModel implements TableModel {
@@ -30,7 +31,7 @@ public class NPCsTableView extends ElementTableView {
@Override
public int getRowCount() {
return proj.getNPCCount();
return proj.getNPCCountIncludingAltered();
}
@Override
@@ -109,7 +110,7 @@ public class NPCsTableView extends ElementTableView {
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
NPC npc = proj.getNPC(rowIndex);
NPC npc = proj.getNPCIncludingAltered(rowIndex);
switch (columnIndex) {
case 0: return new ImageIcon(npc.getIcon()); // Icon
case 1: return npc.id; //ID
@@ -157,7 +158,7 @@ public class NPCsTableView extends ElementTableView {
//not editable.
}
List<TableModelListener> listeners = new ArrayList<TableModelListener>();
List<TableModelListener> listeners = new CopyOnWriteArrayList<TableModelListener>();
@Override
public void addTableModelListener(TableModelListener l) {

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,67 @@
package com.gpl.rpg.atcontentstudio.utils;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import com.gpl.rpg.atcontentstudio.model.Workspace;
public class DesktopIntegration {
public static void openTmxMap(File f) {
if (Workspace.activeWorkspace.settings.useSystemDefaultMapEditor.getCurrentValue()) {
try {
Desktop.getDesktop().open(f);
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
Runtime.getRuntime().exec(Workspace.activeWorkspace.settings.mapEditorCommand.getCurrentValue()+" "+f.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void openImage(File f) {
if (Workspace.activeWorkspace.settings.useSystemDefaultImageViewer.getCurrentValue()) {
try {
Desktop.getDesktop().open(f);
} catch (IOException e) {
e.printStackTrace();
}
} else if (Workspace.activeWorkspace.settings.useSystemDefaultImageEditor.getCurrentValue()) {
try {
Desktop.getDesktop().edit(f);
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
Runtime.getRuntime().exec(Workspace.activeWorkspace.settings.imageEditorCommand.getCurrentValue()+" "+f.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static enum OSType {
Windows, MacOS, NIX, Other
}
public static OSType detectedOS = detectOS();
private static OSType detectOS() {
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((os.indexOf("mac") >= 0) || (os.indexOf("darwin") >= 0)) return OSType.MacOS;
if (os.indexOf("win") >= 0) return OSType.Windows;
if ((os.indexOf("nux") >= 0) || (os.indexOf("nix") >= 0) || (os.indexOf("aix") >= 0) || (os.indexOf("sunos") >= 0) || (os.indexOf("solaris") >= 0)) return OSType.NIX;
return OSType.Other;
}
}

View File

@@ -6,9 +6,15 @@ 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.InputStream;
import java.io.OutputStream;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -108,7 +114,85 @@ public class FileUtils {
}
}
}
}
public static boolean makeSymlink(File targetFile, File linkFile) {
Path target = Paths.get(targetFile.getAbsolutePath());
Path link = Paths.get(linkFile.getAbsolutePath());
if (!Files.exists(link)) {
try {
Files.createSymbolicLink(link, target);
} catch (Exception e) {
System.err.println("Failed to create symbolic link to target \""+targetFile.getAbsolutePath()+"\" as \""+linkFile.getAbsolutePath()+"\" the java.nio way:");
e.printStackTrace();
switch (DesktopIntegration.detectedOS) {
case Windows:
System.err.println("Trying the Windows way with mklink");
try {
Runtime.getRuntime().exec("cmd.exe /C mklink "+(targetFile.isDirectory() ? "/J " : "")+linkFile.getAbsolutePath()+" "+targetFile.getAbsolutePath());
} catch (IOException e1) {
e1.printStackTrace();
}
System.err.println("Attempting UAC elevation through VBS script.");
if (!linkFile.exists()) {
runWithUac("cmd.exe /C mklink "+(targetFile.isDirectory() ? "/J " : "")+linkFile.getAbsolutePath()+" "+targetFile.getAbsolutePath(), 3, linkFile);
}
break;
case MacOS:
case NIX:
case Other:
System.err.println("Trying the unix way with ln -s");
try {
Runtime.getRuntime().exec("ln -s "+targetFile.getAbsolutePath()+" "+linkFile.getAbsolutePath());
} catch (IOException e1) {
e1.printStackTrace();
}
break;
default:
System.out.println("Unrecognized OS. Please contact ATCS dev.");
break;
}
}
}
if (!Files.exists(link)) {
System.err.println("Failed to create link \""+linkFile.getAbsolutePath()+"\" targetting \""+targetFile.getAbsolutePath()+"\"");
System.err.println("You can try running ATCS with administrative privileges once, or create the symbolic link manually.");
}
return true;
}
public static File backupFile(File f) {
try {
Path returned = Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(f.getAbsolutePath()+".bak"), StandardCopyOption.REPLACE_EXISTING);
return returned.toFile();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
static final String uacBatName = "ATCS_elevateWithUac.bat";
public static void runWithUac(String command, int tries, File checkExists) {
File tmpFolder = new File(System.getProperty("java.io.tmpdir"));
File batFile = new File(tmpFolder, uacBatName);
batFile.deleteOnExit();
FileWriter writer;
try {
writer = new FileWriter(batFile, false);
writer.write(
"@echo Set objShell = CreateObject(\"Shell.Application\") > %temp%\\sudo.tmp.vbs\r\n"
+ "@echo args = Right(\"%*\", (Len(\"%*\") - Len(\"%1\"))) >> %temp%\\sudo.tmp.vbs\r\n"
+ "@echo objShell.ShellExecute \"%1\", args, \"\", \"runas\" >> %temp%\\sudo.tmp.vbs\r\n"
+ "@cscript %temp%\\sudo.tmp.vbs\r\n"
+ "del /f %temp%\\sudo.tmp.vbs\r\n");
writer.close();
while (!checkExists.exists() && tries-- > 0) {
Runtime.getRuntime().exec(new String[]{"cmd.exe","/C", batFile.getAbsolutePath()+" "+command});
}
} catch (IOException e) {
e.printStackTrace();
}
}

View File

@@ -0,0 +1,296 @@
package prefuse.data;
import java.util.BitSet;
import java.util.Iterator;
import java.util.LinkedList;
import prefuse.data.tuple.TupleManager;
import prefuse.visual.tuple.TableEdgeItem;
public class FilteredSpanningTree extends Tree {
/** Extra edge table data field recording the id of the source edge
* a tree edge represents. */
public static final String SOURCE_EDGE = "source";
/** Edge table schema used by the spanning tree. */
protected static final Schema EDGE_SCHEMA = new Schema();
static {
EDGE_SCHEMA.addColumn(DEFAULT_SOURCE_KEY, int.class, new Integer(-1));
EDGE_SCHEMA.addColumn(DEFAULT_TARGET_KEY, int.class, new Integer(-1));
EDGE_SCHEMA.addColumn(SOURCE_EDGE, int.class);
}
/** A reference to the backing graph that this tree spans. */
protected Graph m_backing;
/** The boolean field to check. If false, edge is filtered out. */
protected int m_filter;
/**
* Create a new SpanningTree.
* @param g the backing Graph to span
* @param root the Node to use as the root of the spanning tree
* @param filterField the Edge column to use to filter out non-tree edges (must be boolean);
*/
public FilteredSpanningTree(Graph g, Node root, String filterField) {
super(g.getNodeTable(), EDGE_SCHEMA.instantiate());
m_filter = g.getEdgeTable().getColumnNumber(filterField);
if (g.getEdgeTable().getColumn(m_filter) != null && !g.getEdgeTable().getColumn(m_filter).canGetBoolean()) {
throw new UnsupportedOperationException(
"The filter column must be boolean.");
}
m_backing = g;
TupleManager etm = new TupleManager(getEdgeTable(), null,
TableEdgeItem.class) {
public Tuple getTuple(int row) {
return m_backing.getEdge(m_table.getInt(row, SOURCE_EDGE));
}
};
getEdgeTable().setTupleManager(etm);
super.setTupleManagers(g.m_nodeTuples, etm);
buildSpanningTree(root);
}
/**
* Build the spanning tree, starting at the given root. Uses an
* unweighted breadth first traversal to build the spanning tree.
* @param root the root node of the spanning tree
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public void buildSpanningTree(Node root) {
// re-use a previously allocated tree if possible
super.clearEdges();
super.setRoot(root);
// build unweighted spanning tree by BFS
LinkedList q = new LinkedList();
BitSet visit = new BitSet();
q.add(root); visit.set(root.getRow());
Table edges = getEdgeTable();
while ( !q.isEmpty() ) {
Node p = (Node)q.removeFirst();
for ( Iterator iter = p.edges(); iter.hasNext(); ) {
Edge e = (Edge)iter.next();
if (e.getBoolean(m_filter)) {
Node n = e.getAdjacentNode(p);
if ( !visit.get(n.getRow()) ) {
q.add(n); visit.set(n.getRow());
int er = super.addChildEdge(p.getRow(), n.getRow());
edges.setInt(er, SOURCE_EDGE, e.getRow());
}
}
}
}
}
// ------------------------------------------------------------------------
// Disallow most mutator methods
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#addChild(int)
*/
public int addChild(int parent) {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#addChild(prefuse.data.Node)
*/
public Node addChild(Node parent) {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#addChildEdge(int, int)
*/
public int addChildEdge(int parent, int child) {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#addChildEdge(prefuse.data.Node, prefuse.data.Node)
*/
public Edge addChildEdge(Node parent, Node child) {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#addRoot()
*/
public Node addRoot() {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#addRootRow()
*/
public int addRootRow() {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#removeChild(int)
*/
public boolean removeChild(int node) {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#removeChild(prefuse.data.Node)
*/
public boolean removeChild(Node n) {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#removeChildEdge(prefuse.data.Edge)
*/
public boolean removeChildEdge(Edge e) {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#removeChildEdge(int)
*/
public boolean removeChildEdge(int edge) {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Tree#setRoot(prefuse.data.Node)
*/
void setRoot(Node root) {
throw new UnsupportedOperationException(
"Changes to tree structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#addEdge(int, int)
*/
public int addEdge(int s, int t) {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#addEdge(prefuse.data.Node, prefuse.data.Node)
*/
public Edge addEdge(Node s, Node t) {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#addNode()
*/
public Node addNode() {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#addNodeRow()
*/
public int addNodeRow() {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.tuple.TupleSet#clear()
*/
public void clear() {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#removeEdge(prefuse.data.Edge)
*/
public boolean removeEdge(Edge e) {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#removeEdge(int)
*/
public boolean removeEdge(int edge) {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#removeNode(int)
*/
public boolean removeNode(int node) {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#removeNode(prefuse.data.Node)
*/
public boolean removeNode(Node n) {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.tuple.TupleSet#removeTuple(prefuse.data.Tuple)
*/
public boolean removeTuple(Tuple t) {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#setEdgeTable(prefuse.data.Table)
*/
public void setEdgeTable(Table edges) {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
/**
* Unsupported operation. Spanning trees should not be edited.
* @see prefuse.data.Graph#setTupleManagers(prefuse.data.tuple.TupleManager, prefuse.data.tuple.TupleManager)
*/
public void setTupleManagers(TupleManager ntm, TupleManager etm) {
throw new UnsupportedOperationException(
"Changes to graph structure not allowed for spanning trees.");
}
}