diff --git a/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java b/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java
index 4a3a8a175..d29660b04 100644
--- a/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java
+++ b/src/java/com/threerings/miso/client/DisplayMisoSceneImpl.java
@@ -1,5 +1,5 @@
//
-// $Id: DisplayMisoSceneImpl.java,v 1.41 2001/10/17 22:21:22 shaper Exp $
+// $Id: DisplayMisoSceneImpl.java,v 1.42 2001/10/25 16:36:42 shaper Exp $
package com.threerings.miso.scene;
@@ -37,6 +37,9 @@ public class MisoSceneImpl implements EditableMisoScene
/** The portals to different scenes. */
public ArrayList portals = new ArrayList();
+ /** The default entrance portal. */
+ public Portal entrance;
+
/** The base tiles in the scene. */
public MisoTile[][] baseTiles;
@@ -186,7 +189,7 @@ public class MisoSceneImpl implements EditableMisoScene
// documentation inherited
public Portal getEntrance ()
{
- return _entrance;
+ return entrance;
}
// documentation inherited
@@ -210,7 +213,7 @@ public class MisoSceneImpl implements EditableMisoScene
// documentation inherited
public void setEntrance (Portal entrance)
{
- _entrance = entrance;
+ this.entrance = entrance;
}
/**
@@ -378,9 +381,6 @@ public class MisoSceneImpl implements EditableMisoScene
/** The scene version. */
protected int _version;
- /** The default entrance portal. */
- protected Portal _entrance;
-
/** The default tile for the base layer in the scene. */
protected MisoTile _deftile;
diff --git a/src/java/com/threerings/miso/client/IsoSceneView.java b/src/java/com/threerings/miso/client/IsoSceneView.java
index 233c14b30..13ddeaa90 100644
--- a/src/java/com/threerings/miso/client/IsoSceneView.java
+++ b/src/java/com/threerings/miso/client/IsoSceneView.java
@@ -1,5 +1,5 @@
//
-// $Id: IsoSceneView.java,v 1.68 2001/10/24 01:33:47 shaper Exp $
+// $Id: IsoSceneView.java,v 1.69 2001/10/25 16:36:42 shaper Exp $
package com.threerings.miso.scene;
@@ -196,6 +196,7 @@ public class IsoSceneView implements SceneView
*/
protected void renderScene (Graphics2D gfx)
{
+ // Log.info("renderScene");
renderTiles(gfx);
renderDirtyItems(gfx);
}
@@ -236,7 +237,8 @@ public class IsoSceneView implements SceneView
*/
protected void renderDirtyItems (Graphics2D gfx)
{
- // Log.info("renderDirtyItems");
+ // Log.info("renderDirtyItems [rects=" + _dirtyRects.size() +
+ // ", items=" + _dirtyItems.size() + "].");
// sort the dirty sprites and objects visually back-to-front
DirtyItem items[] = _dirtyItems.sort();
@@ -244,6 +246,7 @@ public class IsoSceneView implements SceneView
// render each item clipping to its dirty rectangle
for (int ii = 0; ii < items.length; ii++) {
items[ii].paint(gfx, items[ii].dirtyRect);
+ // Log.info("Painting item [item=" + items[ii] + "].");
}
}
@@ -352,56 +355,34 @@ public class IsoSceneView implements SceneView
List locations = _scene.getLocations();
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++) {
-
// retrieve the location
Location loc = (Location)locations.get(ii);
// get the cluster index this location is in, if any
int clusteridx = MisoSceneUtil.getClusterIndex(_scene, loc);
+ // get the location's center coordinate
Point spos = new Point();
IsoUtil.fullToScreen(_model, loc.x, loc.y, spos);
-
int cx = spos.x, cy = spos.y;
- // translate the origin to center on the location
- gfx.translate(cx, cy);
-
- // rotate to reflect the location orientation
- double rot = (Math.PI / 4.0f) * loc.orient;
- gfx.rotate(rot);
-
- // draw the triangle
- Color fcol = (loc instanceof Portal) ? Color.green : Color.yellow;
- gfx.setColor(fcol);
- gfx.fill(tri);
-
- // outline the triangle in black
- gfx.setColor(Color.black);
- gfx.draw(tri);
-
- // draw the rectangle
- gfx.setColor(Color.red);
- gfx.fillRect(-1, 2, 3, 3);
-
- // restore the original transform
- gfx.rotate(-rot);
- gfx.translate(-cx, -cy);
+ // paint the location
+ loc.paint(gfx, cx, cy);
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);
+ gfx.drawString(String.valueOf(clusteridx), cx + 5, cy + 3);
}
- }
+
+ // highlight the location if it's the default entrance
+ if (_scene.getEntrance() == loc) {
+ gfx.setColor(Color.cyan);
+ gfx.drawRect(spos.x - 5, spos.y - 5, 10, 10);
+ }
+ }
}
// documentation inherited
diff --git a/src/java/com/threerings/miso/client/Location.java b/src/java/com/threerings/miso/client/Location.java
index 2eeddb511..2e5f55a31 100644
--- a/src/java/com/threerings/miso/client/Location.java
+++ b/src/java/com/threerings/miso/client/Location.java
@@ -1,17 +1,21 @@
//
-// $Id: Location.java,v 1.7 2001/09/28 01:25:26 mdb Exp $
+// $Id: Location.java,v 1.8 2001/10/25 16:36:42 shaper Exp $
package com.threerings.miso.scene;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Polygon;
+
import com.threerings.media.sprite.Sprite;
/**
- * The Location class represents a unique well-defined
- * location within the scene at the lowest level of granularity
- * available within the scene coordinate system. Locations reside at
- * a full coordinate (comprised of tile coordinates and fine
- * coordinates within the tile), and only one location may reside at
- * each full coordinate in the scene.
+ * A location object represents a unique well-defined location within
+ * the scene at the lowest level of granularity available within the
+ * scene coordinate system. Locations reside at a full coordinate
+ * (comprised of tile coordinates and fine coordinates within the
+ * tile), and only one location may reside at each full coordinate in
+ * the scene.
*/
public class Location
{
@@ -25,7 +29,7 @@ public class Location
public int orient;
/**
- * Construct a Location object.
+ * Constructs a location object.
*
* @param x the x-position full coordinate.
* @param y the y-position full coordinate.
@@ -39,7 +43,7 @@ public class Location
}
/**
- * Construct a Location object with a default orientation.
+ * Constructs a location object with a default orientation.
*
* @param x the x-position full coordinate.
* @param y the y-position full coordinate.
@@ -52,7 +56,41 @@ public class Location
}
/**
- * Return a String representation of this object.
+ * Renders the location centered at the given coordinates to the
+ * given graphics context.
+ *
+ * @param gfx the graphics context.
+ * @param cx the center x-coordinate.
+ * @param cy the center y-coordinate.
+ */
+ public void paint (Graphics2D gfx, int cx, int cy)
+ {
+ // translate the origin to center on the location
+ gfx.translate(cx, cy);
+
+ // rotate to reflect the location orientation
+ double rot = (Math.PI / 4.0f) * orient;
+ gfx.rotate(rot);
+
+ // draw the triangle
+ gfx.setColor(getColor());
+ gfx.fill(_tri);
+
+ // outline the triangle in black
+ gfx.setColor(Color.black);
+ gfx.draw(_tri);
+
+ // draw the rectangle
+ gfx.setColor(Color.red);
+ gfx.fillRect(-1, 2, 3, 3);
+
+ // restore the original transform
+ gfx.rotate(-rot);
+ gfx.translate(-cx, -cy);
+ }
+
+ /**
+ * Returns a string representation of the location.
*/
public String toString ()
{
@@ -74,4 +112,22 @@ public class Location
buf.append(", y=").append(y);
buf.append(", orient=").append(orient);
}
+
+ /**
+ * Returns the color to paint the inside of the location.
+ */
+ protected Color getColor ()
+ {
+ return Color.yellow;
+ }
+
+ /** The triangle used to render a location on-screen. */
+ protected static Polygon _tri;
+
+ static {
+ _tri = new Polygon();
+ _tri.addPoint(-3, -3);
+ _tri.addPoint(3, -3);
+ _tri.addPoint(0, 3);
+ };
}
diff --git a/src/java/com/threerings/miso/client/Portal.java b/src/java/com/threerings/miso/client/Portal.java
index 5b848655e..c60ca0c17 100644
--- a/src/java/com/threerings/miso/client/Portal.java
+++ b/src/java/com/threerings/miso/client/Portal.java
@@ -1,8 +1,10 @@
//
-// $Id: Portal.java,v 1.3 2001/08/21 01:15:16 shaper Exp $
+// $Id: Portal.java,v 1.4 2001/10/25 16:36:43 shaper Exp $
package com.threerings.miso.scene;
+import java.awt.Color;
+
/**
* The portal class represents a {@link Location} in a scene that both
* leads to a different scene and serves as a potential entrance into
@@ -53,9 +55,7 @@ public class Portal extends Location
return (sid != MisoScene.SID_INVALID && dest != null);
}
- /**
- * Return a String representation of this object.
- */
+ // documentation inherited
protected void toString (StringBuffer buf)
{
super.toString(buf);
@@ -63,4 +63,10 @@ public class Portal extends Location
buf.append(", sid=").append(sid);
buf.append(", dest=").append(dest);
}
+
+ // documentation inherited
+ protected Color getColor ()
+ {
+ return Color.green;
+ }
}
diff --git a/src/java/com/threerings/miso/tools/xml/XMLSceneParser.java b/src/java/com/threerings/miso/tools/xml/XMLSceneParser.java
index 9a71e23f6..43f5c2c69 100644
--- a/src/java/com/threerings/miso/tools/xml/XMLSceneParser.java
+++ b/src/java/com/threerings/miso/tools/xml/XMLSceneParser.java
@@ -1,5 +1,5 @@
//
-// $Id: XMLSceneParser.java,v 1.22 2001/10/22 18:21:41 shaper Exp $
+// $Id: XMLSceneParser.java,v 1.23 2001/10/25 16:36:43 shaper Exp $
package com.threerings.miso.scene.xml;
@@ -74,6 +74,9 @@ public class XMLSceneParser extends SimpleParser
String vals[] = StringUtil.parseStringArray(data);
addPortals(_info.scene.portals, _info.scene.locations, vals);
+ } else if (qName.equals("entrance")) {
+ _info.scene.entrance = getEntrancePortal(data);
+
} else if (qName.equals("row")) {
addTileRow(_info, data);
@@ -244,6 +247,23 @@ public class XMLSceneParser extends SimpleParser
}
}
+ /**
+ * Returns the default entrance portal for the scene, or
+ * null if an error occurs.
+ */
+ protected Portal getEntrancePortal (String data)
+ {
+ ArrayList locs = _info.scene.locations;
+ int size = locs.size();
+ int pidx = parseInt(data);
+
+ if (size == 0 || pidx < 0 || pidx > size - 1) {
+ return null;
+ }
+
+ return (Portal)locs.get(pidx);
+ }
+
/**
* Parse the specified XML file and return a miso scene object with
* the data contained therein.
@@ -271,9 +291,6 @@ public class XMLSceneParser extends SimpleParser
/** Temporary storage of scene info while parsing. */
protected SceneInfo _info;
- // TODO: allow specifying the entrance location for a scene in the
- // editor, read/write to XML scene description files.
-
/**
* A class to hold the information gathered while parsing.
*/
diff --git a/src/java/com/threerings/miso/tools/xml/XMLSceneWriter.java b/src/java/com/threerings/miso/tools/xml/XMLSceneWriter.java
index 6a60ee14b..9375bab0f 100644
--- a/src/java/com/threerings/miso/tools/xml/XMLSceneWriter.java
+++ b/src/java/com/threerings/miso/tools/xml/XMLSceneWriter.java
@@ -1,5 +1,5 @@
//
-// $Id: XMLSceneWriter.java,v 1.17 2001/10/22 18:21:42 shaper Exp $
+// $Id: XMLSceneWriter.java,v 1.18 2001/10/25 16:36:43 shaper Exp $
package com.threerings.miso.scene.xml;
@@ -62,6 +62,8 @@ public class XMLSceneWriter extends DataWriter
dataElement("portals", getPortalData(scene));
+ dataElement("entrance", getEntranceData(scene));
+
startElement("tiles");
for (int lnum = 0; lnum < MisoScene.NUM_LAYERS; lnum++) {
writeLayer(scene, lnum);
@@ -189,6 +191,23 @@ public class XMLSceneWriter extends DataWriter
return buf.toString();
}
+ /**
+ * Returns a string detailing the location index of the default
+ * entrance portal for the scene, or "-1" if no
+ * default portal is specified or an error occurs.
+ */
+ protected String getEntranceData (MisoScene scene)
+ {
+ List locs = scene.getLocations();
+ Portal entrance = scene.getEntrance();
+
+ if (locs.size() == 0 || entrance == null) {
+ return "-1";
+ }
+
+ return String.valueOf(locs.indexOf(entrance));
+ }
+
/**
* Return a string representation of the tiles at the specified
* row and layer in the given scene. Only len tiles