Draw locations such that orientation is apparent. Added support for

editing existing location information.
 CVS: ----------------------------------------------------------------------


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@213 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-08-10 23:07:04 +00:00
parent 8d7c2fc4e9
commit 356f15595e
3 changed files with 85 additions and 27 deletions
@@ -1,5 +1,5 @@
// //
// $Id: DisplayMisoSceneImpl.java,v 1.22 2001/08/10 21:17:07 shaper Exp $ // $Id: DisplayMisoSceneImpl.java,v 1.23 2001/08/10 23:07:04 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -115,31 +115,45 @@ public class Scene
return ClusterUtil.getClusterIndex(_clusters, loc); return ClusterUtil.getClusterIndex(_clusters, loc);
} }
public void updateLocation (int x, int y, int orient, int clusteridx) public void updateLocation (Location loc, int 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;
for (int ii = 0; ii < size; ii++) { for (int ii = 0; ii < size; ii++) {
Location tloc = (Location)_locations.get(ii); Location tloc = (Location)_locations.get(ii);
if (tloc.x == x && tloc.y == y) { if (tloc == loc) {
// if we found it, update the location information // if we found it, just update the cluster contents
tloc.x = x;
tloc.y = y;
tloc.orient = orient;
// and update the cluster contents
ClusterUtil.regroup(_clusters, tloc, clusteridx); ClusterUtil.regroup(_clusters, tloc, clusteridx);
return; return;
} }
} }
// else we didn't find a location object, so create one // else we didn't find it, so hold on to the sucker
_locations.add(loc = new Location(x, y, orient)); _locations.add(loc);
// and update the cluster contents
ClusterUtil.regroup(_clusters, loc, clusteridx); ClusterUtil.regroup(_clusters, loc, clusteridx);
} }
/**
* Return the location object at the given full coordinates, or
* null if no location is currently present.
*
* @param x the full x-position coordinate.
* @param y the full y-position coordinate.
*
* @return the location object.
*/
public Location getLocation (int x, int y)
{
int size = _locations.size();
for (int ii = 0; ii < size; ii++) {
Location loc = (Location)_locations.get(ii);
if (loc.x == x && loc.y == y) return loc;
}
return null;
}
/** /**
* Return the scene name. * Return the scene name.
@@ -1,5 +1,5 @@
// //
// $Id: IsoSceneView.java,v 1.38 2001/08/10 21:17:07 shaper Exp $ // $Id: IsoSceneView.java,v 1.39 2001/08/10 23:07:04 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -308,9 +308,9 @@ public class IsoSceneView implements EditableSceneView
} }
/** /**
* Paint rectangular demarcations at all locations in the scene, * Paint demarcations at all locations in the scene, with each
* with each location's cluster index, if any, along the right * location's cluster index, if any, along the right side of its
* side of its rectangle. * rectangle.
* *
* @param gfx the graphics context. * @param gfx the graphics context.
*/ */
@@ -318,6 +318,13 @@ public class IsoSceneView implements EditableSceneView
{ {
ArrayList locations = _scene.getLocations(); ArrayList locations = _scene.getLocations();
int size = locations.size(); int size = locations.size();
// create the location triangle
Polygon tri = new Polygon();
tri.addPoint(-3, -3);
tri.addPoint(3, -3);
tri.addPoint(0, 3);
for (int ii = 0; ii < size; ii++) { for (int ii = 0; ii < size; ii++) {
// retrieve the location // retrieve the location
@@ -331,16 +338,28 @@ public class IsoSceneView implements EditableSceneView
int cx = spos.x, cy = spos.y; int cx = spos.x, cy = spos.y;
// outline the location in multiple colors to make sure // translate the origin to center on the location
// it's visible atop the unknown smorgasbord of potential tiles gfx.translate(cx, cy);
// rotate to reflect the location orientation
double rot = (Math.PI / 4.0f) * loc.orient;
gfx.rotate(rot);
// draw the triangle
gfx.setColor(Color.yellow); gfx.setColor(Color.yellow);
gfx.fillRect(cx - 1, cy - 1, 3, 3); gfx.fill(tri);
// outline the triangle in black
gfx.setColor(Color.black);
gfx.draw(tri);
// draw the rectangle
gfx.setColor(Color.red); gfx.setColor(Color.red);
gfx.drawRect(cx - 2, cy - 2, 4, 4); gfx.fillRect(-1, 2, 3, 3);
gfx.setColor(Color.green); // restore the original transform
gfx.drawRect(cx - 3, cy - 3, 6, 6); gfx.rotate(-rot);
gfx.translate(-cx, -cy);
if (clusteridx != -1) { if (clusteridx != -1) {
// draw the cluster index number on the right side // draw the cluster index number on the right side
@@ -540,9 +559,19 @@ public class IsoSceneView implements EditableSceneView
return path; return path;
} }
public void updateLocation (int x, int y, int orient, int clusteridx) public void updateLocation (Location loc, int clusteridx)
{ {
_scene.updateLocation(x, y, orient, clusteridx); _scene.updateLocation(loc, clusteridx);
}
public Location getLocation (int x, int y)
{
return _scene.getLocation(x, y);
}
public int getClusterIndex (Location loc)
{
return _scene.getClusterIndex(loc);
} }
public int getNumClusters () public int getNumClusters ()
@@ -1,8 +1,10 @@
// //
// $Id: Location.java,v 1.2 2001/08/10 00:47:34 shaper Exp $ // $Id: Location.java,v 1.3 2001/08/10 23:07:04 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
import com.threerings.miso.sprite.Path;
/** /**
* The <code>Location</code> class represents a unique well-defined * The <code>Location</code> class represents a unique well-defined
* location within the scene at the lowest level of granularity * location within the scene at the lowest level of granularity
@@ -33,6 +35,19 @@ public class Location
this.orient = orient; this.orient = orient;
} }
/**
* Construct a <code>Location</code> object with a default orientation.
*
* @param x the x-position full coordinate.
* @param y the y-position full coordinate.
*/
public Location (int x, int y)
{
this.x = x;
this.y = y;
this.orient = Path.DIR_SOUTHWEST;
}
/** /**
* Return a String representation of this object. * Return a String representation of this object.
*/ */