Fixed bug in saving clusters to XML. Added checkbox to editor to
allow display of locations and cluster indexes. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@212 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
//
|
//
|
||||||
// $Id: Cluster.java,v 1.1 2001/08/10 01:31:25 shaper Exp $
|
// $Id: Cluster.java,v 1.2 2001/08/10 21:17:07 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <code>Cluster</code> is a gathering of <code>Location</code> objects
|
* A <code>Cluster</code> is a gathering of <code>Location</code> objects
|
||||||
* that represent a logical grouping for the purposes of display and
|
* that represent a logical grouping for the purposes of display and
|
||||||
@@ -72,6 +74,14 @@ public class Cluster
|
|||||||
return _locations;
|
return _locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a string representation of this object.
|
||||||
|
*/
|
||||||
|
public String toString ()
|
||||||
|
{
|
||||||
|
return StringUtil.toString(_locations);
|
||||||
|
}
|
||||||
|
|
||||||
/** The list of locations in this cluster. */
|
/** The list of locations in this cluster. */
|
||||||
protected ArrayList _locations;
|
protected ArrayList _locations;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ClusterUtil.java,v 1.1 2001/08/10 01:31:25 shaper Exp $
|
// $Id: ClusterUtil.java,v 1.2 2001/08/10 21:17:07 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -14,9 +14,27 @@ import com.threerings.miso.Log;
|
|||||||
*/
|
*/
|
||||||
public class ClusterUtil
|
public class ClusterUtil
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Return the cluster index number the given location is in, or -1
|
||||||
|
* if the location is not in any cluster.
|
||||||
|
*
|
||||||
|
* @param clusters the cluster list.
|
||||||
|
* @param loc the location.
|
||||||
|
*/
|
||||||
|
public static int getClusterIndex (ArrayList clusters, Location loc)
|
||||||
|
{
|
||||||
|
int size = clusters.size();
|
||||||
|
for (int ii = 0; ii < size; ii++) {
|
||||||
|
Cluster cluster = (Cluster)clusters.get(ii);
|
||||||
|
if (cluster.contains(loc)) return ii;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the given location from its cluster, if any.
|
* Remove the given location from its cluster, if any.
|
||||||
*
|
*
|
||||||
|
* @param clusters the cluster list.
|
||||||
* @param loc the location.
|
* @param loc the location.
|
||||||
*/
|
*/
|
||||||
public static void remove (ArrayList clusters, Location loc)
|
public static void remove (ArrayList clusters, Location loc)
|
||||||
@@ -52,7 +70,7 @@ public class ClusterUtil
|
|||||||
* in the group, in which case a new cluster object will be created
|
* in the group, in which case a new cluster object will be created
|
||||||
* that initially contains only the given location.
|
* that initially contains only the given location.
|
||||||
*
|
*
|
||||||
* @param clusters the list of clusters.
|
* @param clusters the cluster list.
|
||||||
* @param loc the location.
|
* @param loc the location.
|
||||||
* @param clusteridx the cluster index, or -1 to remove the location
|
* @param clusteridx the cluster index, or -1 to remove the location
|
||||||
* from any cluster.
|
* from any cluster.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DisplayMisoSceneImpl.java,v 1.21 2001/08/10 01:31:25 shaper Exp $
|
// $Id: DisplayMisoSceneImpl.java,v 1.22 2001/08/10 21:17:07 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -104,11 +104,19 @@ public class Scene
|
|||||||
this.tiles = tiles;
|
this.tiles = tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the cluster index number the given location is in, or -1
|
||||||
|
* if the location is not in any cluster.
|
||||||
|
*
|
||||||
|
* @param loc the location.
|
||||||
|
*/
|
||||||
|
public int getClusterIndex (Location loc)
|
||||||
|
{
|
||||||
|
return ClusterUtil.getClusterIndex(_clusters, loc);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLocation (int x, int y, int orient, int clusteridx)
|
public void updateLocation (int x, int y, int orient, int clusteridx)
|
||||||
{
|
{
|
||||||
Log.info("updateLocation [x=" + x + ", y=" + y +
|
|
||||||
", orient=" + orient + ", clusteridx=" + clusteridx + "].");
|
|
||||||
|
|
||||||
// look the location up in our existing location list
|
// look the location up in our existing location list
|
||||||
int size = _locations.size();
|
int size = _locations.size();
|
||||||
Location loc = null;
|
Location loc = null;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoSceneView.java,v 1.37 2001/08/10 01:31:25 shaper Exp $
|
// $Id: IsoSceneView.java,v 1.38 2001/08/10 21:17:07 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -64,8 +64,8 @@ public class IsoSceneView implements EditableSceneView
|
|||||||
|
|
||||||
// clip the drawing region to our desired bounds since we
|
// clip the drawing region to our desired bounds since we
|
||||||
// currently draw tiles willy-nilly in undesirable areas.
|
// currently draw tiles willy-nilly in undesirable areas.
|
||||||
Shape oldclip = gfx.getClip();
|
Shape oldclip = gfx.getClip();
|
||||||
gfx.setClip(0, 0, _model.bounds.width, _model.bounds.height);
|
gfx.setClip(0, 0, _model.bounds.width, _model.bounds.height);
|
||||||
|
|
||||||
if (_numDirty == 0) {
|
if (_numDirty == 0) {
|
||||||
// render the full scene
|
// render the full scene
|
||||||
@@ -82,11 +82,13 @@ public class IsoSceneView implements EditableSceneView
|
|||||||
clearDirtyRegions();
|
clearDirtyRegions();
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw an outline around the highlighted tile
|
// draw marks at each location
|
||||||
paintHighlightedTile(gfx, _htile.x, _htile.y);
|
if (_model.showLocs) {
|
||||||
|
paintLocations(gfx);
|
||||||
|
}
|
||||||
|
|
||||||
// draw an outline around the highlighted full coordinate
|
// draw highlighted tiles and full coordinates
|
||||||
paintHighlightedFull(gfx, _hfull.x, _hfull.y);
|
paintHighlights(gfx);
|
||||||
|
|
||||||
// restore the original clipping region
|
// restore the original clipping region
|
||||||
gfx.setClip(oldclip);
|
gfx.setClip(oldclip);
|
||||||
@@ -161,6 +163,11 @@ public class IsoSceneView implements EditableSceneView
|
|||||||
// draw all sprites residing in the current tile
|
// draw all sprites residing in the current tile
|
||||||
_spritemgr.renderSprites(gfx, poly);
|
_spritemgr.renderSprites(gfx, poly);
|
||||||
|
|
||||||
|
// paint the tile coordinate if desired
|
||||||
|
if (_model.showCoords) {
|
||||||
|
paintCoords(gfx, xx, yy, poly.xpoints[0], poly.ypoints[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// bail early if we know we've drawn all dirty tiles
|
// bail early if we know we've drawn all dirty tiles
|
||||||
if (++numDrawn == _numDirty) break;
|
if (++numDrawn == _numDirty) break;
|
||||||
}
|
}
|
||||||
@@ -262,44 +269,86 @@ public class IsoSceneView implements EditableSceneView
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paint a highlight around the specified tile.
|
* Paint highlights around any highlighted tiles and fine coordinates.
|
||||||
*
|
*
|
||||||
* @param gfx the graphics context.
|
* @param gfx the graphics context.
|
||||||
* @param x the tile x-position coordinate.
|
|
||||||
* @param y the tile y-position coordinate.
|
|
||||||
*/
|
*/
|
||||||
protected void paintHighlightedTile (Graphics2D gfx, int x, int y)
|
protected void paintHighlights (Graphics2D gfx)
|
||||||
{
|
{
|
||||||
if (x == -1 || y == -1) return;
|
// paint the highlighted tile
|
||||||
|
if (_htile.x != -1 && _htile.y != -1) {
|
||||||
|
// set the desired stroke and color
|
||||||
|
Stroke ostroke = gfx.getStroke();
|
||||||
|
gfx.setStroke(_hstroke);
|
||||||
|
gfx.setColor(Color.green);
|
||||||
|
|
||||||
// set the desired stroke and color
|
// draw the tile outline
|
||||||
Stroke ostroke = gfx.getStroke();
|
gfx.draw(IsoUtil.getTilePolygon(_model, _htile.x, _htile.y));
|
||||||
gfx.setStroke(HLT_STROKE);
|
|
||||||
gfx.setColor(HLT_COLOR);
|
|
||||||
|
|
||||||
// draw the tile outline
|
// restore the original stroke
|
||||||
gfx.draw(IsoUtil.getTilePolygon(_model, x, y));
|
gfx.setStroke(ostroke);
|
||||||
|
}
|
||||||
|
|
||||||
// restore the original stroke
|
// paint the highlighted full coordinate
|
||||||
gfx.setStroke(ostroke);
|
if (_hfull.x != -1 && _hfull.y != -1) {
|
||||||
|
Point spos = new Point();
|
||||||
|
IsoUtil.fullToScreen(_model, _hfull.x, _hfull.y, spos);
|
||||||
|
|
||||||
|
// set the desired stroke and color
|
||||||
|
Stroke ostroke = gfx.getStroke();
|
||||||
|
gfx.setStroke(_hstroke);
|
||||||
|
|
||||||
|
// draw a red circle at the coordinate
|
||||||
|
gfx.setColor(Color.red);
|
||||||
|
gfx.draw(new Ellipse2D.Float(spos.x - 1, spos.y - 1, 3, 3));
|
||||||
|
|
||||||
|
// restore the original stroke
|
||||||
|
gfx.setStroke(ostroke);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paint a highlight around the specified full coordinate.
|
* Paint rectangular demarcations at all locations in the scene,
|
||||||
|
* with each location's cluster index, if any, along the right
|
||||||
|
* side of its rectangle.
|
||||||
*
|
*
|
||||||
* @param gfx the graphics context.
|
* @param gfx the graphics context.
|
||||||
* @param x the full x-position coordinate.
|
|
||||||
* @param y the full y-position coordinate.
|
|
||||||
*/
|
*/
|
||||||
protected void paintHighlightedFull (Graphics2D gfx, int x, int y)
|
protected void paintLocations (Graphics2D gfx)
|
||||||
{
|
{
|
||||||
if (x == -1 || y == -1) return;
|
ArrayList locations = _scene.getLocations();
|
||||||
|
int size = locations.size();
|
||||||
|
for (int ii = 0; ii < size; ii++) {
|
||||||
|
|
||||||
Point spos = new Point();
|
// retrieve the location
|
||||||
IsoUtil.fullToScreen(_model, x, y, spos);
|
Location loc = (Location)locations.get(ii);
|
||||||
|
|
||||||
gfx.setColor(Color.red);
|
// get the cluster index this location is in, if any
|
||||||
gfx.draw(new Ellipse2D.Float(spos.x, spos.y, 3, 3));
|
int clusteridx = _scene.getClusterIndex(loc);
|
||||||
|
|
||||||
|
Point spos = new Point();
|
||||||
|
IsoUtil.fullToScreen(_model, loc.x, loc.y, spos);
|
||||||
|
|
||||||
|
int cx = spos.x, cy = spos.y;
|
||||||
|
|
||||||
|
// outline the location in multiple colors to make sure
|
||||||
|
// it's visible atop the unknown smorgasbord of potential tiles
|
||||||
|
gfx.setColor(Color.yellow);
|
||||||
|
gfx.fillRect(cx - 1, cy - 1, 3, 3);
|
||||||
|
|
||||||
|
gfx.setColor(Color.red);
|
||||||
|
gfx.drawRect(cx - 2, cy - 2, 4, 4);
|
||||||
|
|
||||||
|
gfx.setColor(Color.green);
|
||||||
|
gfx.drawRect(cx - 3, cy - 3, 6, 6);
|
||||||
|
|
||||||
|
if (clusteridx != -1) {
|
||||||
|
// draw the cluster index number on the right side
|
||||||
|
gfx.setFont(_font);
|
||||||
|
gfx.setColor(Color.white);
|
||||||
|
gfx.drawString("" + clusteridx, cx + 5, cy + 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHighlightedTile (int sx, int sy)
|
public void setHighlightedTile (int sx, int sy)
|
||||||
@@ -447,16 +496,6 @@ public class IsoSceneView implements EditableSceneView
|
|||||||
_scene = scene;
|
_scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getShowCoordinates ()
|
|
||||||
{
|
|
||||||
return _model.showCoords;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setShowCoordinates (boolean show)
|
|
||||||
{
|
|
||||||
_model.showCoords = show;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTile (int x, int y, int lnum, Tile tile)
|
public void setTile (int x, int y, int lnum, Tile tile)
|
||||||
{
|
{
|
||||||
Point tpos = new Point();
|
Point tpos = new Point();
|
||||||
@@ -511,11 +550,8 @@ public class IsoSceneView implements EditableSceneView
|
|||||||
return (_scene == null) ? 0 : _scene.getNumClusters();
|
return (_scene == null) ? 0 : _scene.getNumClusters();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The color to draw the highlighted tile. */
|
/** The stroke object used to draw highlighted tiles and coordinates. */
|
||||||
protected static final Color HLT_COLOR = Color.green;
|
protected BasicStroke _hstroke = new BasicStroke(3);
|
||||||
|
|
||||||
/** The stroke object used to draw the highlighted tile. */
|
|
||||||
protected static final Stroke HLT_STROKE = new BasicStroke(3);
|
|
||||||
|
|
||||||
/** The currently highlighted tile. */
|
/** The currently highlighted tile. */
|
||||||
protected Point _htile;
|
protected Point _htile;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoSceneViewModel.java,v 1.5 2001/08/08 22:29:39 shaper Exp $
|
// $Id: IsoSceneViewModel.java,v 1.6 2001/08/10 21:17:07 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -62,6 +62,9 @@ public class IsoSceneModel
|
|||||||
/** Whether tile coordinates should be drawn. */
|
/** Whether tile coordinates should be drawn. */
|
||||||
public boolean showCoords;
|
public boolean showCoords;
|
||||||
|
|
||||||
|
/** Whether locations in the scene should be drawn. */
|
||||||
|
public boolean showLocs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an IsoSceneModel with reasonable default values.
|
* Construct an IsoSceneModel with reasonable default values.
|
||||||
*/
|
*/
|
||||||
@@ -72,6 +75,7 @@ public class IsoSceneModel
|
|||||||
setBounds(600, 600);
|
setBounds(600, 600);
|
||||||
setOrigin(bounds.width / 2, -(9 * tilehei));
|
setOrigin(bounds.width / 2, -(9 * tilehei));
|
||||||
showCoords = false;
|
showCoords = false;
|
||||||
|
showLocs = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,6 +90,42 @@ public class IsoSceneModel
|
|||||||
finegran = gran;
|
finegran = gran;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether locations in the scene are currently drawn.
|
||||||
|
*/
|
||||||
|
public boolean getShowLocations ()
|
||||||
|
{
|
||||||
|
return showLocs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether locations in the scene should be drawn.
|
||||||
|
*
|
||||||
|
* @param show whether to show locations.
|
||||||
|
*/
|
||||||
|
public void setShowLocations (boolean show)
|
||||||
|
{
|
||||||
|
showLocs = show;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether coordinates are currently drawn for each tile.
|
||||||
|
*/
|
||||||
|
public boolean getShowCoordinates ()
|
||||||
|
{
|
||||||
|
return showCoords;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether coordinates should be drawn for each tile.
|
||||||
|
*
|
||||||
|
* @param show whether to show coordinates.
|
||||||
|
*/
|
||||||
|
public void setShowCoordinates (boolean show)
|
||||||
|
{
|
||||||
|
showCoords = show;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the dimensions of the tiles that comprise the base layer of
|
* Set the dimensions of the tiles that comprise the base layer of
|
||||||
* the isometric view and therefore drive the view geometry as a
|
* the isometric view and therefore drive the view geometry as a
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: XMLSceneWriter.java,v 1.6 2001/08/10 01:31:25 shaper Exp $
|
// $Id: XMLSceneWriter.java,v 1.7 2001/08/10 21:17:07 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene.xml;
|
package com.threerings.miso.scene.xml;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class XMLSceneWriter extends DataWriter
|
|||||||
|
|
||||||
int clustersize = clusterlocs.size();
|
int clustersize = clusterlocs.size();
|
||||||
for (int jj = 0; jj < clustersize; jj++) {
|
for (int jj = 0; jj < clustersize; jj++) {
|
||||||
buf.append(locs.indexOf(clusterlocs.get(jj))).append(",");
|
buf.append(locs.indexOf(clusterlocs.get(jj)));
|
||||||
if (jj < clustersize - 1) buf.append(",");
|
if (jj < clustersize - 1) buf.append(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<name>Untitled Scene</name>
|
<name>Untitled Scene</name>
|
||||||
<version>1</version>
|
<version>1</version>
|
||||||
<locations></locations>
|
<locations></locations>
|
||||||
<spots></spots>
|
<clusters></clusters>
|
||||||
<exits></exits>
|
<exits></exits>
|
||||||
<tiles>
|
<tiles>
|
||||||
<layer lnum="0">
|
<layer lnum="0">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ViewerSceneViewPanel.java,v 1.5 2001/08/08 22:29:39 shaper Exp $
|
// $Id: ViewerSceneViewPanel.java,v 1.6 2001/08/10 21:17:07 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.viewer;
|
package com.threerings.miso.viewer;
|
||||||
|
|
||||||
@@ -40,8 +40,6 @@ public class ViewerSceneViewPanel extends SceneViewPanel
|
|||||||
// load up the initial scene
|
// load up the initial scene
|
||||||
prepareStartingScene();
|
prepareStartingScene();
|
||||||
|
|
||||||
//((EditableSceneView)_view).setShowCoordinates(true);
|
|
||||||
|
|
||||||
PerformanceMonitor.register(this, "paint", 1000);
|
PerformanceMonitor.register(this, "paint", 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user