Got object tile highlighting working. Now the IsoSceneView correctly keeps
track of the front-most object that the mouse is over. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@902 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoSceneView.java,v 1.84 2002/01/31 01:07:02 mdb Exp $
|
// $Id: IsoSceneView.java,v 1.85 2002/01/31 02:10:00 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.samskivert.util.HashIntMap;
|
import com.samskivert.util.HashIntMap;
|
||||||
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
import com.threerings.media.animation.AnimationManager;
|
import com.threerings.media.animation.AnimationManager;
|
||||||
import com.threerings.media.sprite.Path;
|
import com.threerings.media.sprite.Path;
|
||||||
@@ -59,7 +60,7 @@ public class IsoSceneView implements SceneView
|
|||||||
/** Instructs the scene view to highlight whatever tile the mouse is
|
/** Instructs the scene view to highlight whatever tile the mouse is
|
||||||
* over, regardless of whether or not it is an object tile. This is
|
* over, regardless of whether or not it is an object tile. This is
|
||||||
* generally only useful in an editor rather than a game. */
|
* generally only useful in an editor rather than a game. */
|
||||||
public static final int HIGHLIGHT_ALL = 2;
|
public static final int HIGHLIGHT_ALL = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an iso scene view.
|
* Constructs an iso scene view.
|
||||||
@@ -186,9 +187,23 @@ public class IsoSceneView implements SceneView
|
|||||||
|
|
||||||
Polygon hpoly = null;
|
Polygon hpoly = null;
|
||||||
|
|
||||||
|
// if the highlighted object is an object tile, we want to
|
||||||
|
// highlight that
|
||||||
|
if (_hobject instanceof ObjectTile) {
|
||||||
|
// if we're only highlighting objects with actions, make sure
|
||||||
|
// this one has an action
|
||||||
|
if (_hmode != HIGHLIGHT_WITH_ACTION ||
|
||||||
|
!StringUtil.blank(_scene.getObjectAction(
|
||||||
|
_hcoords.x, _hcoords.y))) {
|
||||||
|
hpoly = IsoUtil.getObjectFootprint(
|
||||||
|
_model, _polys[_hcoords.x][_hcoords.y],
|
||||||
|
(ObjectTile)_hobject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if we have no highlight object, but we're in HIGHLIGHT_ALL,
|
// if we have no highlight object, but we're in HIGHLIGHT_ALL,
|
||||||
// then paint the bounds of the highlighted base tile
|
// then paint the bounds of the highlighted base tile
|
||||||
if (_hobject == null && _hmode == HIGHLIGHT_ALL &&
|
if (hpoly == null && _hmode == HIGHLIGHT_ALL &&
|
||||||
_hcoords.x != -1 && _hcoords.y != -1) {
|
_hcoords.x != -1 && _hcoords.y != -1) {
|
||||||
hpoly = _polys[_hcoords.x][_hcoords.y];
|
hpoly = _polys[_hcoords.x][_hcoords.y];
|
||||||
}
|
}
|
||||||
@@ -688,6 +703,12 @@ public class IsoSceneView implements SceneView
|
|||||||
int x = e.getX(), y = e.getY();
|
int x = e.getX(), y = e.getY();
|
||||||
boolean repaint = false;
|
boolean repaint = false;
|
||||||
|
|
||||||
|
// update the base tile coordinates that the mouse is over (if
|
||||||
|
// it's also over an object tile, we'll override these values)
|
||||||
|
if (_hmode == HIGHLIGHT_ALL) {
|
||||||
|
repaint = (updateTileCoords(x, y, _hcoords) || repaint);
|
||||||
|
}
|
||||||
|
|
||||||
// compute the list of objects over which the mouse is hovering
|
// compute the list of objects over which the mouse is hovering
|
||||||
_hitList.clear();
|
_hitList.clear();
|
||||||
_hitSpritesList.clear();
|
_hitSpritesList.clear();
|
||||||
@@ -714,6 +735,13 @@ public class IsoSceneView implements SceneView
|
|||||||
hobject = items[items.length-1].obj;
|
hobject = items[items.length-1].obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if this is an object tile, we need to update the hcoords
|
||||||
|
if (hobject != null && hobject instanceof ObjectTile) {
|
||||||
|
DirtyItem item = items[items.length-1];
|
||||||
|
_hcoords.x = item.ox;
|
||||||
|
_hcoords.y = item.oy;
|
||||||
|
}
|
||||||
|
|
||||||
// if this hover object is different than before, we'll need to be
|
// if this hover object is different than before, we'll need to be
|
||||||
// repainted
|
// repainted
|
||||||
if (hobject != _hobject) {
|
if (hobject != _hobject) {
|
||||||
@@ -722,11 +750,6 @@ public class IsoSceneView implements SceneView
|
|||||||
repaint = true;
|
repaint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the tile coordinates that the mouse is over
|
|
||||||
if (_hmode == HIGHLIGHT_ALL) {
|
|
||||||
repaint = (updateTileCoords(x, y, _hcoords) || repaint);
|
|
||||||
}
|
|
||||||
|
|
||||||
return repaint;
|
return repaint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,30 +761,31 @@ public class IsoSceneView implements SceneView
|
|||||||
*/
|
*/
|
||||||
protected void getHitObjects (DirtyItemList list, int x, int y)
|
protected void getHitObjects (DirtyItemList list, int x, int y)
|
||||||
{
|
{
|
||||||
// ObjectTileLayer tiles = _scene.getObjectLayer();
|
ObjectTileLayer tiles = _scene.getObjectLayer();
|
||||||
// Iterator iter = _objpolys.keys();
|
Iterator iter = _objpolys.keys();
|
||||||
|
|
||||||
// while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
// // get the object's coordinates and bounding polygon
|
// get the object's coordinates and bounding polygon
|
||||||
// int coord = ((Integer)iter.next()).intValue();
|
int coord = ((Integer)iter.next()).intValue();
|
||||||
// Polygon poly = (Polygon)_objpolys.get(coord);
|
Polygon poly = (Polygon)_objpolys.get(coord);
|
||||||
|
|
||||||
// // skip polys that don't contain the point
|
// skip polys that don't contain the point
|
||||||
// if (!poly.contains(x, y)) {
|
if (!poly.contains(x, y)) {
|
||||||
// continue;
|
continue;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // do further analysis on those that do
|
// now check that the pixel in the tile image is
|
||||||
// int tx = coord >> 16, ty = coord & 0x0000FFFF;
|
// non-transparent at that point
|
||||||
// ObjectTile tile = tiles.getTile(tx, ty);
|
int tx = coord >> 16, ty = coord & 0x0000FFFF;
|
||||||
|
ObjectTile tile = tiles.getTile(tx, ty);
|
||||||
|
Rectangle pbounds = poly.getBounds();
|
||||||
|
if (!tile.hitTest(x - pbounds.x, y - pbounds.y)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// // get the dirty portion of the object
|
// we've passed the test, add the object to the list
|
||||||
// Rectangle drect = poly.getBounds();
|
list.appendDirtyObject(tile, poly, tx, ty, pbounds);
|
||||||
// _dirtyItems.appendDirtyObject(
|
}
|
||||||
// , poly, tx, ty, drect);
|
|
||||||
// // Log.info("Dirtied item: Object(" + tx + ", " +
|
|
||||||
// // ty + ")");
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
@@ -851,9 +875,10 @@ public class IsoSceneView implements SceneView
|
|||||||
protected DirtyItemList _hitList = new DirtyItemList();
|
protected DirtyItemList _hitList = new DirtyItemList();
|
||||||
|
|
||||||
/** The highlight mode. */
|
/** The highlight mode. */
|
||||||
protected int _hmode = HIGHLIGHT_NEVER;
|
protected int _hmode = HIGHLIGHT_ALWAYS;
|
||||||
|
|
||||||
/** The coordinates of the currently highlighted tile. */
|
/** The coordinates of the currently highlighted base or object
|
||||||
|
* tile. */
|
||||||
protected Point _hcoords = new Point(-1, -1);
|
protected Point _hcoords = new Point(-1, -1);
|
||||||
|
|
||||||
/** The object that the mouse is currently hovering over. */
|
/** The object that the mouse is currently hovering over. */
|
||||||
|
|||||||
Reference in New Issue
Block a user