Resources.getString("action.tile.delete.confirm.message"),
Resources.getString("action.tile.delete.confirm.title"),
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (answer == JOptionPane.YES_OPTION) {
Tile tile = (Tile)tileList.getSelectedValue();
if (tile != null) {
tileset.removeTile(tile.getId());
}
queryTiles();
}
} else if (source == changeImageButton) {
changeImage();
} else if (source == addImagesButton) {
addImages();
} else if (source == duplicateTileButton) {
Tile newTile = new Tile(currentTile);
tileset.addNewTile(newTile);
queryTiles();
// Select the last (cloned) tile
tileList.setSelectedIndex(tileset.size() - 1);
tileList.ensureIndexIsVisible(tileset.size() - 1);
} else if (source == editAnimationButton) {
MapEditor.runTimer = false;
AnimationDialog ad = new AnimationDialog(this, ((AnimatedTile)currentTile).getSprite());
ad.setVisible(true);
MapEditor.runTimer = true;
}
/*
else if (source == setImagesCheck) {
if (setImagesCheck.isSelected()) {
tileset.enablesetImages();
updateEnabledState();
} else {
int answer = JOptionPane.YES_OPTION;
if (!tileset.safeToDisablesetImages()) {
answer = JOptionPane.showConfirmDialog(
this, "This tileset uses features that require the "
+ "use of shared images. Disable the use of shared "
+ "images?",
"Are you sure?",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
}
if (answer == JOptionPane.YES_OPTION) {
tileset.disablesetImages();
updateEnabledState();
} else {
setImagesCheck.setSelected(true);
}
}
}
*/
else if (source == createTileButton) {
Image img = (Image) imageList.getSelectedValue();
if (img != null) {
Tile newTile = new Tile(tileset);
newTile.setImage(tileset.getIdByImage(img));
tileset.addNewTile(newTile);
queryTiles();
// Select the last (cloned) tile
tileList.setSelectedIndex(tileset.size() - 1);
tileList.ensureIndexIsVisible(tileset.size() - 1);
JOptionPane.showMessageDialog(
this,
MessageFormat.format(
TILE_CREATED_MESSAGE,
new Object[]{new Integer(newTile.getId())}),
TILE_CREATED_TITLE,
JOptionPane.INFORMATION_MESSAGE);
}
}
else if (source == createAnimatedTileButton) {
Image img = (Image) imageList.getSelectedValue();
if (img != null) {
AnimatedTile newTile = new AnimatedTile(tileset);
if(img.getWidth(null)%map.getTileWidth() != 0 || img.getHeight(null)%map.getTileHeight() != 0) {
JOptionPane.showMessageDialog(
this,
"The x and y sizes of the image aren't multiples of the tilewidth/height.",
"Couldn't create animated tile",
JOptionPane.ERROR_MESSAGE);
return;
}
int framesx = img.getWidth(null)/map.getTileWidth();
int framesy = img.getHeight(null)/map.getTileHeight();
Image frames[] = new Image[framesx*framesy];
int id = tileset.addImage(img);
for(int x = 0; x < framesx; x++) {
for(int y = 0; y < framesy; y++) {
frames[framesx*y+x] = createImage(new FilteredImageSource(img.getSource(), new CropImageFilter(x*map.getTileWidth(), y*map.getTileHeight(), map.getTileWidth(), map.getTileHeight())));
}
}
//TODO add delay input through dialog
newTile.setSprite(new Sprite(frames, 10)); //chopped up animation
newTile.setImage(id); //complete animation
tileset.addNewTile(newTile);
queryTiles();
queryImages();
// Select the last (cloned) tile
tileList.setSelectedIndex(tileset.size() - 1);
tileList.ensureIndexIsVisible(tileset.size() - 1);
JOptionPane.showMessageDialog(
this,
MessageFormat.format(
TILE_CREATED_MESSAGE,
new Object[]{new Integer(newTile.getId())}),
TILE_CREATED_TITLE,
JOptionPane.INFORMATION_MESSAGE);
}
}