Allow placement of the selected tile in scenes undergoing edit in the

scene editor application.  Added comments.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@53 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-07-16 22:12:01 +00:00
parent 6806cfb6f7
commit ab18d9742e
10 changed files with 100 additions and 53 deletions
@@ -1,5 +1,5 @@
// //
// $Id: TileManager.java,v 1.3 2001/07/16 18:59:31 shaper Exp $ // $Id: TileManager.java,v 1.4 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.tile; package com.threerings.cocktail.miso.tile;
@@ -10,17 +10,22 @@ import com.samskivert.util.IntMap;
import java.awt.*; import java.awt.*;
/** /**
* Provides a simplified interface for retrieving tile objects from * Provides a simplified interface for managing multiple tilesets and
* various tilesets, by name or identifier, and manages caching of * tiles.
* tiles and related resources as appropriate.
*/ */
public class TileManager public class TileManager
{ {
/**
* Initialize the tile manager with the given TileSetManager object.
*/
public TileManager (TileSetManager tsmgr) public TileManager (TileSetManager tsmgr)
{ {
_tsmgr = tsmgr; _tsmgr = tsmgr;
} }
/**
* Return the total number of tiles in the specified tileset.
*/
public int getNumTilesInSet (int tsid) public int getNumTilesInSet (int tsid)
{ {
TileSet tset = _tsmgr.getTileSet(tsid); TileSet tset = _tsmgr.getTileSet(tsid);
@@ -28,11 +33,18 @@ public class TileManager
return tset.getNumTiles(); return tset.getNumTiles();
} }
/**
* Return a String array of all tileset names ordered by ascending
* tileset id.
*/
public String[] getTileSetNames () public String[] getTileSetNames ()
{ {
return _tsmgr.getTileSetNames(); return _tsmgr.getTileSetNames();
} }
/**
* Return the Tile object for the specified tileset and tile id.
*/
public Tile getTile (int tsid, int tid) 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
@@ -55,7 +67,7 @@ public class TileManager
_tiles.put(utid, tile); _tiles.put(utid, tile);
Log.info("Loaded tile into cache [tsid="+tsid+", tid="+tid+"]."); // Log.info("Loaded tile into cache [tsid="+tsid+", tid="+tid+"].");
return tile; return tile;
} }
@@ -1,5 +1,5 @@
// //
// $Id: TileSet.java,v 1.4 2001/07/16 18:59:31 shaper Exp $ // $Id: TileSet.java,v 1.5 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.tile; package com.threerings.cocktail.miso.tile;
@@ -73,9 +73,9 @@ public class TileSet
{ {
// load the full tile image if we don't already have it // load the full tile image if we don't already have it
if (_imgTiles == null) { if (_imgTiles == null) {
Log.info("Getting full tileset image [file=" + _file + "].");
if ((_imgTiles = ImageManager.getImage(_file)) == null) { if ((_imgTiles = ImageManager.getImage(_file)) == null) {
Log.warning("Failed to retrieve full tileset image."); Log.warning("Failed to retrieve full tileset image " +
"[file=" + _file + "].");
return null; return null;
} }
} }
@@ -1,20 +1,8 @@
// //
// $Id: CompiledSceneManager.java,v 1.1 2001/07/12 22:38:03 shaper Exp $ // $Id: CompiledSceneManager.java,v 1.2 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.scene; package com.threerings.cocktail.miso.scene;
public class CompiledSceneManager implements SceneManager public class CompiledSceneManager extends SceneManagerImpl
{ {
// context, rsrc mgr, loads compiled scene files via rsrc mgr
public Scene getScene (String name)
{
// TBD
return null;
}
public Scene getScene (int sid)
{
// TBD
return null;
}
} }
@@ -1,5 +1,5 @@
// //
// $Id: DisplayMisoSceneImpl.java,v 1.3 2001/07/16 00:45:06 shaper Exp $ // $Id: DisplayMisoSceneImpl.java,v 1.4 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.scene; package com.threerings.cocktail.miso.scene;
@@ -16,6 +16,8 @@ import java.io.*;
*/ */
public class Scene public class Scene
{ {
public static final String[] XLATE_LAYERS = { "Base", "Object" };
public Tile tiles[][][]; // the tiles comprising the scene public Tile tiles[][][]; // the tiles comprising the scene
/** /**
@@ -1,19 +1,8 @@
// //
// $Id: EditableSceneManager.java,v 1.1 2001/07/12 22:38:03 shaper Exp $ // $Id: EditableSceneManager.java,v 1.2 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.scene; package com.threerings.cocktail.miso.scene;
public class EditableSceneManager implements SceneManager public class EditableSceneManager extends SceneManagerImpl
{ {
public Scene getScene (String name)
{
// TBD
return null;
}
public Scene getScene (int sid)
{
// TBD
return null;
}
} }
@@ -1,5 +1,5 @@
// //
// $Id: IsoSceneView.java,v 1.3 2001/07/16 00:45:06 shaper Exp $ // $Id: IsoSceneView.java,v 1.4 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.scene; package com.threerings.cocktail.miso.scene;
@@ -128,6 +128,10 @@ public class IsoSceneView implements SceneView
g2.drawRect(_lineY[0].x - 1, _lineY[0].y - 1, 3, 3); g2.drawRect(_lineY[0].x - 1, _lineY[0].y - 1, 3, 3);
} }
/**
* Paint the tile coordinates in tile (x, y) whose top-left corner
* is at screen coordinates (sx, sy).
*/
protected void paintCoords (Graphics2D g2, int x, int y, int sx, int sy) protected void paintCoords (Graphics2D g2, int x, int y, int sx, int sy)
{ {
g2.setFont(_font); g2.setFont(_font);
@@ -136,6 +140,9 @@ public class IsoSceneView implements SceneView
g2.drawString(""+y, sx+Tile.HALF_WIDTH-2, sy+Tile.HEIGHT-2); g2.drawString(""+y, sx+Tile.HALF_WIDTH-2, sy+Tile.HEIGHT-2);
} }
/**
* Paint a highlight around the tile at screen coordinates (sx, sy).
*/
protected void paintHighlightedTile (Graphics2D g2, int sx, int sy) protected void paintHighlightedTile (Graphics2D g2, int sx, int sy)
{ {
int x = sx; int x = sx;
@@ -163,7 +170,21 @@ public class IsoSceneView implements SceneView
*/ */
public void setHighlightedTile (int x, int y) public void setHighlightedTile (int x, int y)
{ {
float mX, mY; Point tpos = screenToTile(x, y);
if (tpos != null) _htile = tpos;
// Log.info("Highlighting tile [x="+_htile.x+", y="+_htile.y+"].");
}
/**
* Returns a new Point object containing the tile coordinates
* corresponding to the specified screen-based mouse-position
* coordinates.
*/
protected Point screenToTile (int x, int y)
{
Point tpos = new Point();
float mX, mY;
int bX, bY; int bX, bY;
// calculate the x-axis line (from tile origin to end of visible axis) // calculate the x-axis line (from tile origin to end of visible axis)
@@ -188,22 +209,20 @@ public class IsoSceneView implements SceneView
int xdist = (int) int xdist = (int)
MathUtil.distance(_lineX[0].x, _lineX[0].y, MathUtil.distance(_lineX[0].x, _lineX[0].y,
_lineY[1].x, _lineY[1].y); _lineY[1].x, _lineY[1].y);
_htile.x = (int)((xdist - Tile.EDGE_LENGTH) / Tile.EDGE_LENGTH); tpos.x = (int)((xdist - Tile.EDGE_LENGTH) / Tile.EDGE_LENGTH);
// determine distance of mouse pos along the y-axis // determine distance of mouse pos along the y-axis
int ydist = (int) int ydist = (int)
MathUtil.distance(_lineY[0].x, _lineY[0].y, MathUtil.distance(_lineY[0].x, _lineY[0].y,
_lineY[1].x, _lineY[1].y); _lineY[1].x, _lineY[1].y);
_htile.y = (int)(ydist / Tile.EDGE_LENGTH); tpos.y = (int)(ydist / Tile.EDGE_LENGTH);
//Log.info("[mX="+mX+", bX="+bX+", mY="+mY+", bY="+bY+"]"); //Log.info("[mX="+mX+", bX="+bX+", mY="+mY+", bY="+bY+"]");
//Log.info("x-axis=" + MathUtil.lineToString(_lineX[0], _lineX[1])); //Log.info("x-axis=" + MathUtil.lineToString(_lineX[0], _lineX[1]));
//Log.info("y-axis=" + MathUtil.lineToString(_lineY[0], _lineY[1])); //Log.info("y-axis=" + MathUtil.lineToString(_lineY[0], _lineY[1]));
//Log.info("Highlighting tile [x="+_htile.x+", y="+_htile.y+"].");
}
// TODO: abstract into methods for tile -> screen coords, return tpos;
// screen -> tile coords }
public void setScene (Scene scene) public void setScene (Scene scene)
{ {
@@ -222,6 +241,12 @@ public class IsoSceneView implements SceneView
height + "]."); height + "].");
} }
public void setTile (int x, int y, int lnum, Tile tile)
{
Point tpos = screenToTile(x, y);
_scene.tiles[tpos.x][tpos.y][lnum] = tile;
}
protected static final int OFF_X = 0; protected static final int OFF_X = 0;
protected static final int OFF_Y = 0; protected static final int OFF_Y = 0;
@@ -1,5 +1,5 @@
// //
// $Id: SceneManager.java,v 1.1 2001/07/12 22:38:03 shaper Exp $ // $Id: SceneManager.java,v 1.2 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.scene; package com.threerings.cocktail.miso.scene;
@@ -9,7 +9,14 @@ package com.threerings.cocktail.miso.scene;
*/ */
public interface SceneManager public interface SceneManager
{ {
public Scene getScene (String name); /**
* Return the Scene object for the specified scene id.
*/
public Scene getScene (int sid); public Scene getScene (int sid);
/**
* Return a String array of all layer names ordered by ascending
* layer id.
*/
public String[] getLayerNames ();
} }
@@ -0,0 +1,18 @@
//
// $Id: SceneManagerImpl.java,v 1.1 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.scene;
public class SceneManagerImpl implements SceneManager
{
public Scene getScene (int sid)
{
// TBD
return null;
}
public String[] getLayerNames ()
{
return Scene.XLATE_LAYERS;
}
}
@@ -1,8 +1,10 @@
// //
// $Id: SceneView.java,v 1.2 2001/07/16 00:45:06 shaper Exp $ // $Id: SceneView.java,v 1.3 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.scene; package com.threerings.cocktail.miso.scene;
import com.threerings.cocktail.miso.tile.Tile;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics; import java.awt.Graphics;
@@ -32,4 +34,9 @@ public interface SceneView
* Set the target component to which we're rendering. * Set the target component to which we're rendering.
*/ */
public void setTarget (Component target); public void setTarget (Component target);
/**
* Set the tile at the specified location and layer in the scene.
*/
public void setTile (int x, int y, int lnum, Tile tile);
} }
@@ -1,5 +1,5 @@
// //
// $Id: ImageManager.java,v 1.3 2001/07/16 00:45:06 shaper Exp $ // $Id: ImageManager.java,v 1.4 2001/07/16 22:12:01 shaper Exp $
package com.threerings.cocktail.miso.media; package com.threerings.cocktail.miso.media;
@@ -46,7 +46,6 @@ public class ImageManager
} else { } else {
_imgs.put(fname, img); _imgs.put(fname, img);
Log.info("Loaded image into cache successfully.");
} }
} catch (Exception e) { } catch (Exception e) {