Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cca2e2

Browse files
committed
Merged addition of tileset margin support with other changes
2 parents e2c7fb4 + 4f7fc90 commit 2cca2e2

File tree

12 files changed

+77
-37
lines changed

12 files changed

+77
-37
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Added support for a margin around a tileset image
12
* Improved the tileset manager and allow tileset reorganizing (by Jared Adams)
23
* Fixed automatically adding extension to tileset Save As... dialog
34
* Fixed saving/loading of layers with an origin other than 0,0

SUGGESTIONS

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ State: To be discussed
1919
Problems: The engine the user is using will still need to understand the
2020
way Tiled uses the coordinates.
2121

22-
- 04 --------------------------------------------------------------------------
23-
Suggestor: Ahmed Mohombe <[email protected]>
24-
Date: 08/04/04
25-
Summary: Allow tilesets with a border to be used by Tiled. Borders around
26-
the tileset image are used by FreeCiv for example.
27-
State: To be implemented (offset attributes, task #79)
28-
2922
- 06 --------------------------------------------------------------------------
3023
Suggestor: Ahmed Mohombe <[email protected]>
3124
Date: 08/04/04

examples/tilespacing-test.tmx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE map SYSTEM "http://mapeditor.org/dtd/1.0/map.dtd">
33
<map version="1.0" orientation="orthogonal" width="32" height="32" tilewidth="32" tileheight="32">
4-
<tileset name="Desert" firstgid="1" tilewidth="32" tileheight="32" spacing="1">
4+
<tileset name="Desert" firstgid="1" tilewidth="32" tileheight="32" spacing="1" margin="1">
55
<image source="tmw_desert_spacing.png"/>
66
</tileset>
77
<!-- Layer data is compressed (GZip) binary data, encoded in Base64 -->

examples/tmw_desert_spacing.png

107 Bytes
Loading

src/tiled/core/MapObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class MapObject implements Cloneable
2222
{
2323
private Properties properties = new Properties();
2424

25-
protected float x, y;
25+
protected int x, y;
2626
protected Rectangle bounds = new Rectangle();
2727
protected boolean bVisible = true;
2828
protected String name = "Object";
@@ -82,11 +82,11 @@ public void translate(int x, int y) {
8282
}
8383

8484
public int getX() {
85-
return (int) x;
85+
return x;
8686
}
8787

8888
public int getY() {
89-
return (int) y;
89+
return y;
9090
}
9191

9292
public String getName() {

src/tiled/core/TileSet.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class TileSet
4646
private TileCutter tileCutter;
4747
private Rectangle tileDimensions;
4848
private int tileSpacing;
49+
private int tileMargin;
4950
private int tilesPerRow;
5051
private String externalSource;
5152
private File tilebmpFile;
@@ -110,8 +111,8 @@ public void importTileBitmap(String imgFilename, TileCutter cutter)
110111
*/
111112
private void importTileBitmap(BufferedImage tilebmp, TileCutter cutter)
112113
{
113-
assert(tilebmp != null);
114-
assert(cutter != null);
114+
assert tilebmp != null;
115+
assert cutter != null;
115116

116117
tileCutter = cutter;
117118
tileSetImage = tilebmp;
@@ -122,6 +123,7 @@ private void importTileBitmap(BufferedImage tilebmp, TileCutter cutter)
122123
if (cutter instanceof BasicTileCutter) {
123124
BasicTileCutter basicTileCutter = (BasicTileCutter) cutter;
124125
tileSpacing = basicTileCutter.getTileSpacing();
126+
tileMargin = basicTileCutter.getTileMargin();
125127
tilesPerRow = basicTileCutter.getTilesPerRow();
126128
}
127129

@@ -409,6 +411,14 @@ public int getTileSpacing() {
409411
return tileSpacing;
410412
}
411413

414+
/**
415+
* Returns the margin around the tiles on the tileset image.
416+
* @return the margin in pixels around the tiles on the tileset image
417+
*/
418+
public int getTileMargin() {
419+
return tileMargin;
420+
}
421+
412422
/**
413423
* Returns the number of tiles per row in the original tileset image.
414424
* @return the number of tiles per row in the original tileset image.

src/tiled/io/xml/XMLMapTransformer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,10 @@ private TileSet unmarshalTileset(Node t) throws Exception {
322322
return ext;
323323
}
324324
else {
325-
int tileWidth = getAttribute(t, "tilewidth", map != null ? map.getTileWidth() : 0);
326-
int tileHeight = getAttribute(t, "tileheight", map != null ? map.getTileHeight() : 0);
327-
int tileSpacing = getAttribute(t, "spacing", 0);
325+
final int tileWidth = getAttribute(t, "tilewidth", map != null ? map.getTileWidth() : 0);
326+
final int tileHeight = getAttribute(t, "tileheight", map != null ? map.getTileHeight() : 0);
327+
final int tileSpacing = getAttribute(t, "spacing", 0);
328+
final int tileMargin = getAttribute(t, "margin", 0);
328329

329330
TileSet set = new TileSet();
330331

@@ -369,7 +370,7 @@ private TileSet unmarshalTileset(Node t) throws Exception {
369370
}
370371

371372
set.importTileBitmap(sourcePath, new BasicTileCutter(
372-
tileWidth, tileHeight, tileSpacing, 0));
373+
tileWidth, tileHeight, tileSpacing, tileMargin));
373374
} else {
374375
Image image = unmarshalImage(child, tilesetBaseDir);
375376
String idValue = getAttributeValue(child, "id");

src/tiled/io/xml/XMLMapWriter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,14 @@ private static void writeTileset(TileSet set, XMLWriter w, String wp)
216216
w.writeAttribute("tilewidth", set.getTileWidth());
217217
w.writeAttribute("tileheight", set.getTileHeight());
218218

219-
int tileSpacing = set.getTileSpacing();
219+
final int tileSpacing = set.getTileSpacing();
220+
final int tileMargin = set.getTileMargin();
220221
if (tileSpacing != 0) {
221222
w.writeAttribute("spacing", tileSpacing);
222223
}
224+
if (tileMargin != 0) {
225+
w.writeAttribute("margin", tileMargin);
226+
}
223227
}
224228

225229
if (set.getBaseDir() != null) {

src/tiled/mapeditor/dialogs/NewTilesetDialog.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ public class NewTilesetDialog extends JDialog implements ChangeListener
4242
private TileSet newTileset;
4343
private IntegerSpinner tileWidth, tileHeight;
4444
private IntegerSpinner tileSpacing;
45+
private IntegerSpinner tileMargin;
4546
private JTextField tilesetName;
4647
private JTextField tilebmpFile;
4748
private JLabel spacingLabel;
49+
private JLabel marginLabel;
4850
private JLabel tilebmpFileLabel, cutterLabel;
4951
private JCheckBox tilebmpCheck;
5052
private JCheckBox transCheck;
@@ -63,6 +65,7 @@ public class NewTilesetDialog extends JDialog implements ChangeListener
6365
private static final String TILE_WIDTH_LABEL = Resources.getString("dialog.newtileset.tilewidth.label");
6466
private static final String TILE_HEIGHT_LABEL = Resources.getString("dialog.newtileset.tileheight.label");
6567
private static final String TILE_SPACING_LABEL = Resources.getString("dialog.newtileset.tilespacing.label");
68+
private static final String TILE_MARGIN_LABEL = Resources.getString("dialog.newtileset.tilemargin.label");
6669
private static final String IMAGE_LABEL = Resources.getString("dialog.newtileset.image.label");
6770
private static final String UNTITLED_FILE = Resources.getString("general.file.untitled");
6871
private static final String TILESET_IMG_LABEL = Resources.getString("dialog.newtileset.tilesetimgref.label");
@@ -96,20 +99,23 @@ private void init() {
9699
JLabel tileWidthLabel = new JLabel(TILE_WIDTH_LABEL);
97100
JLabel tileHeightLabel = new JLabel(TILE_HEIGHT_LABEL);
98101
spacingLabel = new JLabel(TILE_SPACING_LABEL);
102+
marginLabel = new JLabel(TILE_MARGIN_LABEL);
99103
tilebmpFileLabel = new JLabel(IMAGE_LABEL);
100104
cutterLabel = new JLabel("Tile Cutter: ");
101105

102106
tilesetName = new JTextField(UNTITLED_FILE);
103107
tileWidth = new IntegerSpinner(map.getTileWidth(), 1, 1024);
104108
tileHeight = new IntegerSpinner(map.getTileHeight(), 1, 1024);
105109
tileSpacing = new IntegerSpinner(0, 0);
110+
tileMargin = new IntegerSpinner(0, 0);
106111
tilebmpFile = new JTextField(10);
107112
tilebmpFile.setEnabled(false);
108113

109114
nameLabel.setLabelFor(tilesetName);
110115
tileWidthLabel.setLabelFor(tileWidth);
111116
tileHeightLabel.setLabelFor(tileHeight);
112117
spacingLabel.setLabelFor(tileSpacing);
118+
marginLabel.setLabelFor(tileMargin);
113119
tilebmpFileLabel.setLabelFor(tilebmpFile);
114120

115121
tileWidthLabel.setEnabled(false);
@@ -173,7 +179,7 @@ private void init() {
173179
c.insets = new Insets(5, 0, 0, 0);
174180
c.anchor = GridBagConstraints.EAST;
175181
c.fill = GridBagConstraints.HORIZONTAL;
176-
c.gridwidth = 2;
182+
c.gridwidth = 4;
177183
tilebmpPanel.add(tilebmpCheck, c);
178184
c.gridy = 1;
179185
c.gridwidth = 1;
@@ -191,7 +197,9 @@ private void init() {
191197
c.weightx = 1;
192198
c.insets = new Insets(5, 0, 0, 0);
193199
c.fill = GridBagConstraints.HORIZONTAL;
200+
c.gridwidth = 3;
194201
tilebmpPanel.add(tilebmpPathPanel, c);
202+
c.gridwidth = 1;
195203
c.gridy = 2;
196204
tilebmpPanel.add(tileSpacing, c);
197205
/*
@@ -200,8 +208,17 @@ private void init() {
200208
*/
201209
c.gridx = 0;
202210
c.gridy = 4;
203-
c.gridwidth = 2;
211+
c.gridwidth = 4;
204212
tilebmpPanel.add(tileColorPanel, c);
213+
c.gridx = 2;
214+
c.gridy = 2;
215+
c.gridwidth = 1;
216+
c.weightx = 0;
217+
c.insets = new Insets(5, 5, 0, 0);
218+
tilebmpPanel.add(marginLabel, c);
219+
c.gridx = 3;
220+
c.weightx = 1;
221+
tilebmpPanel.add(tileMargin, c);
205222
c.gridx = 1;
206223
c.gridwidth = 1;
207224

@@ -313,10 +330,10 @@ public TileSet create() {
313330
return newTileset;
314331
}
315332

316-
public TileCutter getCutter(int w, int h, int s) {
333+
public TileCutter getCutter(int w, int h, int spacing, int margin) {
317334
final String selectedItem = (String) cutterBox.getSelectedItem();
318335
if (selectedItem.equalsIgnoreCase("basic")) {
319-
return new BasicTileCutter(w, h, s, 0);
336+
return new BasicTileCutter(w, h, spacing, margin);
320337
} else if (selectedItem.equalsIgnoreCase("border")) {
321338
return new BorderTileCutter();
322339
}
@@ -330,10 +347,11 @@ private void createSetAndDispose() {
330347
newTileset.setDefaultProperties(defaultSetProperties);
331348

332349
if (tilebmpCheck.isSelected()) {
333-
String file = tilebmpFile.getText();
334-
int spacing = tileSpacing.intValue();
335-
int width = tileWidth.intValue();
336-
int height = tileHeight.intValue();
350+
final String file = tilebmpFile.getText();
351+
final int spacing = tileSpacing.intValue();
352+
final int margin = tileMargin.intValue();
353+
final int width = tileWidth.intValue();
354+
final int height = tileHeight.intValue();
337355

338356
try {
339357
if (transCheck.isSelected()) {
@@ -342,7 +360,7 @@ private void createSetAndDispose() {
342360
}
343361

344362
newTileset.importTileBitmap(file,
345-
getCutter(width, height, spacing));
363+
getCutter(width, height, spacing, margin));
346364
}
347365
catch (IOException e) {
348366
JOptionPane.showMessageDialog(this, e.getLocalizedMessage(),
@@ -386,7 +404,9 @@ private void setUseTileBitmap(boolean value) {
386404
tilebmpFileLabel.setEnabled(value);
387405
browseButton.setEnabled(value);
388406
tileSpacing.setEnabled(value);
407+
tileMargin.setEnabled(value);
389408
spacingLabel.setEnabled(value);
409+
marginLabel.setEnabled(value);
390410
transCheck.setEnabled(value);
391411
colorButton.setEnabled(value && transCheck.isSelected());
392412
/*

src/tiled/mapeditor/resources/gui.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ dialog.newtileset.name.label=Tileset name:
110110
dialog.newtileset.tileheight.label=Tile height:
111111
dialog.newtileset.tilesetimgref.label=Reference tileset image
112112
dialog.newtileset.tilespacing.label=Tile spacing:
113+
dialog.newtileset.tilemargin.label=Margin:
113114
dialog.newtileset.tilewidth.label=Tile width:
114115
dialog.newtileset.title=New Tileset
115116
dialog.newtileset.usetransparentcolor.label=Use transparent color

0 commit comments

Comments
 (0)