Initial work on adding a selectable tile panel to the right of the
scene display. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@52 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileManager.java,v 1.2 2001/07/14 00:21:24 shaper Exp $
|
// $Id: TileManager.java,v 1.3 2001/07/16 18:59:31 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cocktail.miso.tile;
|
package com.threerings.cocktail.miso.tile;
|
||||||
|
|
||||||
@@ -20,42 +20,49 @@ public class TileManager
|
|||||||
{
|
{
|
||||||
_tsmgr = tsmgr;
|
_tsmgr = tsmgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tile getTile (String setName, String tileName)
|
public int getNumTilesInSet (int tsid)
|
||||||
{
|
{
|
||||||
return new Tile(0, 0);
|
TileSet tset = _tsmgr.getTileSet(tsid);
|
||||||
|
if (tset == null) return -1;
|
||||||
|
return tset.getNumTiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tile getTile (short tsid, short tid)
|
public String[] getTileSetNames ()
|
||||||
|
{
|
||||||
|
return _tsmgr.getTileSetNames();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tile getTile (int tsid, int tid)
|
||||||
{
|
{
|
||||||
// the fully unique tile id is the conjoined tile set and tile id
|
// the fully unique tile id is the conjoined tile set and tile id
|
||||||
int utid = tsid << 16 | tid;
|
int utid = tsid << 16 | tid;
|
||||||
|
|
||||||
// look the tile up in our hash
|
// look the tile up in our hash
|
||||||
Tile tile = (Tile) _tiles.get(utid);
|
Tile tile = (Tile) _tiles.get(utid);
|
||||||
if (tile == null) {
|
if (tile != null) {
|
||||||
|
// Log.info("Retrieved tile from cache [tsid=" + tsid +
|
||||||
// retrieve the tileset containing the tile
|
// ", tid=" + tid + "].");
|
||||||
TileSet tset = _tsmgr.getTileSet(tsid);
|
return tile;
|
||||||
Log.info("Retrieved tileset [tsid=" + tsid + ", tid=" +
|
|
||||||
tid + ", tset=" + tset + "].");
|
|
||||||
|
|
||||||
// retrieve the tile image from the tileset
|
|
||||||
tile = new Tile(tsid, tid);
|
|
||||||
tile.img = tset.getTileImage(tid);
|
|
||||||
|
|
||||||
_tiles.put(utid, tile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// retrieve the tileset containing the tile
|
||||||
|
TileSet tset = _tsmgr.getTileSet(tsid);
|
||||||
|
|
||||||
|
// retrieve the tile image from the tileset
|
||||||
|
tile = new Tile(tsid, tid);
|
||||||
|
tile.img = tset.getTileImage(tid);
|
||||||
|
|
||||||
|
_tiles.put(utid, tile);
|
||||||
|
|
||||||
|
Log.info("Loaded tile into cache [tsid="+tsid+", tid="+tid+"].");
|
||||||
|
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapping from (tsid << 16 | tid) to tile objects
|
// mapping from (tsid << 16 | tid) to tile objects
|
||||||
protected IntMap _tiles = new IntMap();
|
protected IntMap _tiles = new IntMap();
|
||||||
|
|
||||||
// mapping from tileset ids to tileset objects
|
|
||||||
protected IntMap _tilesets = new IntMap();
|
|
||||||
|
|
||||||
// our tile set manager
|
// our tile set manager
|
||||||
protected TileSetManager _tsmgr;
|
protected TileSetManager _tsmgr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileSet.java,v 1.3 2001/07/16 00:45:07 shaper Exp $
|
// $Id: TileSet.java,v 1.4 2001/07/16 18:59:31 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cocktail.miso.tile;
|
package com.threerings.cocktail.miso.tile;
|
||||||
|
|
||||||
@@ -44,6 +44,25 @@ public class TileSet
|
|||||||
// get the row height and tile count for each row
|
// get the row height and tile count for each row
|
||||||
_rowHeight = config.getValue(PREFIX + CONF_ROWHEIGHT, (int[])null);
|
_rowHeight = config.getValue(PREFIX + CONF_ROWHEIGHT, (int[])null);
|
||||||
_tileCount = config.getValue(PREFIX + CONF_TILECOUNT, (int[])null);
|
_tileCount = config.getValue(PREFIX + CONF_TILECOUNT, (int[])null);
|
||||||
|
|
||||||
|
// determine the total number of tiles in the set
|
||||||
|
for (int ii = 0; ii < _tileCount.length; ii++)
|
||||||
|
_numTiles += _tileCount[ii];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId ()
|
||||||
|
{
|
||||||
|
return _tsid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName ()
|
||||||
|
{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumTiles ()
|
||||||
|
{
|
||||||
|
return _numTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,7 +83,7 @@ public class TileSet
|
|||||||
// find the row number containing the sought-after tile
|
// find the row number containing the sought-after tile
|
||||||
int ridx, tcount, ty, tx;
|
int ridx, tcount, ty, tx;
|
||||||
ridx = tcount = ty = tx = 0;
|
ridx = tcount = ty = tx = 0;
|
||||||
while ((tcount += _tileCount[ridx]) < tid) {
|
while ((tcount += _tileCount[ridx]) < tid + 1) {
|
||||||
ty += _rowHeight[ridx++];
|
ty += _rowHeight[ridx++];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,9 +91,9 @@ public class TileSet
|
|||||||
int xidx = tid - (tcount - _tileCount[ridx]);
|
int xidx = tid - (tcount - _tileCount[ridx]);
|
||||||
tx = Tile.WIDTH * xidx;
|
tx = Tile.WIDTH * xidx;
|
||||||
|
|
||||||
Log.info("Retrieving tile image [tid=" + tid + ", ridx=" +
|
// Log.info("Retrieving tile image [tid=" + tid + ", ridx=" +
|
||||||
ridx + ", xidx=" + xidx + ", tx=" + tx +
|
// ridx + ", xidx=" + xidx + ", tx=" + tx +
|
||||||
", ty=" + ty + "].");
|
// ", ty=" + ty + "].");
|
||||||
|
|
||||||
// crop the tile-sized image chunk from the full image
|
// crop the tile-sized image chunk from the full image
|
||||||
return ImageManager.getImageCropped(_imgTiles, tx, ty,
|
return ImageManager.getImageCropped(_imgTiles, tx, ty,
|
||||||
@@ -91,6 +110,7 @@ public class TileSet
|
|||||||
buf.append("[name=").append(_name);
|
buf.append("[name=").append(_name);
|
||||||
buf.append(", file=").append(_file);
|
buf.append(", file=").append(_file);
|
||||||
buf.append(", tsid=").append(_tsid);
|
buf.append(", tsid=").append(_tsid);
|
||||||
|
buf.append(", numtiles=").append(_numTiles);
|
||||||
|
|
||||||
buf.append(", rowheight={");
|
buf.append(", rowheight={");
|
||||||
for (int ii = 0; ii < _rowHeight.length; ii++) {
|
for (int ii = 0; ii < _rowHeight.length; ii++) {
|
||||||
@@ -119,6 +139,7 @@ public class TileSet
|
|||||||
protected int _tsid; // the tileset unique identifier
|
protected int _tsid; // the tileset unique identifier
|
||||||
protected int _rowHeight[]; // the height of each row in pixels
|
protected int _rowHeight[]; // the height of each row in pixels
|
||||||
protected int _tileCount[]; // the number of tiles in each row
|
protected int _tileCount[]; // the number of tiles in each row
|
||||||
|
protected int _numTiles; // the total number of tiles
|
||||||
|
|
||||||
protected Image _imgTiles;
|
protected Image _imgTiles;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,27 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileSetManager.java,v 1.1 2001/07/12 22:38:03 shaper Exp $
|
// $Id: TileSetManager.java,v 1.2 2001/07/16 18:59:31 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cocktail.miso.tile;
|
package com.threerings.cocktail.miso.tile;
|
||||||
|
|
||||||
public interface TileSetManager
|
public interface TileSetManager
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Return the tileset object corresponding to the specified tileset id.
|
||||||
|
*/
|
||||||
public TileSet getTileSet (int tsid);
|
public TileSet getTileSet (int tsid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a String array of all tileset names.
|
||||||
|
*/
|
||||||
|
public String[] getTileSetNames ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the tileset id associated with the named tileset.
|
||||||
|
*/
|
||||||
|
public int getTileSetId (String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the total number of tilesets.
|
||||||
|
*/
|
||||||
|
public int getNumTileSets ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
//
|
||||||
|
// $Id: TileSetManagerImpl.java,v 1.1 2001/07/16 18:59:31 shaper Exp $
|
||||||
|
|
||||||
|
package com.threerings.cocktail.miso.tile;
|
||||||
|
|
||||||
|
import com.samskivert.util.Config;
|
||||||
|
import com.samskivert.util.IntMap;
|
||||||
|
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
public class TileSetManagerImpl implements TileSetManager
|
||||||
|
{
|
||||||
|
public TileSetManagerImpl (Config config)
|
||||||
|
{
|
||||||
|
_config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileSet getTileSet (int tsid)
|
||||||
|
{
|
||||||
|
TileSet tset = (TileSet)_tilesets.get(tsid);
|
||||||
|
if (tset != null) return tset;
|
||||||
|
|
||||||
|
_tilesets.put(tsid, tset = new TileSet(_config, tsid));
|
||||||
|
return tset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getTileSetNames ()
|
||||||
|
{
|
||||||
|
int size = _tilesets.size();
|
||||||
|
if (size == 0) return null;
|
||||||
|
|
||||||
|
String[] names = new String[size];
|
||||||
|
Enumeration sets = _tilesets.elements();
|
||||||
|
for (int ii = 0; ii < size; ii++) {
|
||||||
|
names[ii] = ((TileSet)sets.nextElement()).getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTileSetId (String name)
|
||||||
|
{
|
||||||
|
Enumeration sets = _tilesets.elements();
|
||||||
|
while (sets.hasMoreElements()) {
|
||||||
|
TileSet tset = (TileSet)sets.nextElement();
|
||||||
|
if (tset.getName().equals(name)) return tset.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumTileSets ()
|
||||||
|
{
|
||||||
|
return _tilesets.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Config _config;
|
||||||
|
protected IntMap _tilesets = new IntMap();
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
//
|
//
|
||||||
// $Id: CompiledTileSetManager.java,v 1.1 2001/07/12 22:38:03 shaper Exp $
|
// $Id: CompiledTileSetManager.java,v 1.2 2001/07/16 18:59:31 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cocktail.miso.tile;
|
package com.threerings.cocktail.miso.tile;
|
||||||
|
|
||||||
public class CompiledTileSetManager implements TileSetManager
|
import com.samskivert.util.Config;
|
||||||
|
|
||||||
|
public class CompiledTileSetManager extends TileSetManagerImpl
|
||||||
{
|
{
|
||||||
public TileSet getTileSet (int tsid)
|
public CompiledTileSetManager (Config config)
|
||||||
{
|
{
|
||||||
// TBD
|
super(config);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,14 @@
|
|||||||
//
|
//
|
||||||
// $Id: EditableTileSetManager.java,v 1.1 2001/07/14 00:02:47 shaper Exp $
|
// $Id: EditableTileSetManager.java,v 1.2 2001/07/16 18:59:31 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cocktail.miso.tile;
|
package com.threerings.cocktail.miso.tile;
|
||||||
|
|
||||||
import com.samskivert.util.Config;
|
import com.samskivert.util.Config;
|
||||||
import com.samskivert.util.IntMap;
|
|
||||||
|
|
||||||
public class EditableTileSetManager implements TileSetManager
|
public class EditableTileSetManager extends TileSetManagerImpl
|
||||||
{
|
{
|
||||||
public EditableTileSetManager (Config config)
|
public EditableTileSetManager (Config config)
|
||||||
{
|
{
|
||||||
_config = config;
|
super(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileSet getTileSet (int tsid)
|
|
||||||
{
|
|
||||||
TileSet tset = (TileSet)_tilesets.get(tsid);
|
|
||||||
if (tset != null) return tset;
|
|
||||||
|
|
||||||
_tilesets.put(tsid, tset = new TileSet(_config, tsid));
|
|
||||||
return tset;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Config _config;
|
|
||||||
protected IntMap _tilesets = new IntMap();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user