Wire up handling of clicking on portals.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@962 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Mike Thomas
2010-08-27 21:32:46 +00:00
parent 338309d543
commit 77e9cfce00
3 changed files with 51 additions and 3 deletions
@@ -504,6 +504,9 @@ public class CrowdStageScenePanel extends StageScenePanel
if (hobject is CharacterIsoSprite) { if (hobject is CharacterIsoSprite) {
handleSpriteClicked(CharacterIsoSprite(hobject)); handleSpriteClicked(CharacterIsoSprite(hobject));
return true; return true;
} else if (hobject is PortalIsoSprite) {
handlePortalClicked(PortalIsoSprite(hobject).getPortal());
return true;
} }
// Move ourselves to the spot clicked. // Move ourselves to the spot clicked.
@@ -513,6 +516,37 @@ public class CrowdStageScenePanel extends StageScenePanel
return true; return true;
} }
public function handlePortalClicked (portal :Portal) :void
{
// if the portal goes to the same scene, we do some special stuff
if (portal.targetSceneId == _scene.getId()) {
var tport :Portal = _scene.getPortal(portal.targetPortalId);
if (tport == null) {
log.warning("Requested to warp via bogus portal? " + portal);
return;
}
// start walking there and issue a request to walk there to
// let everyone else know that we're walking there
var ploc :StageLocation = StageLocation(portal.getLocation());
moveSprite(_selfSprite, ploc);
changeLocation(ploc);
// when we arrive at the first portal, issue a request to "warp" to the other one
addArrivalListener(
myOid(), ploc, function (sprite :CharacterIsoSprite, sloc :Location) :void {
changeLocation(StageLocation(tport.getOppLocation()));
});
return;
}
// otherwise, traverse the portal like a civilized pirate: start
// walking toward it, and immediately issue the traversal request
log.info("Traversing " + portal + " from " + _scene.getId() + ".");
moveSprite(_selfSprite, StageLocation(portal.getLocation()));
traversePortal(portal);
}
protected function handleSpriteClicked (sprite :CharacterIsoSprite) :void protected function handleSpriteClicked (sprite :CharacterIsoSprite) :void
{ {
// Nothing by default. // Nothing by default.
@@ -559,6 +593,11 @@ public class CrowdStageScenePanel extends StageScenePanel
throw new Error("abstract"); throw new Error("abstract");
} }
protected function traversePortal (portal :Portal) :void
{
throw new Error("abstract");
}
/** /**
* Returns true if the specified tile coordinate is occupied by any sprites or if the * Returns true if the specified tile coordinate is occupied by any sprites or if the
* specified tile is inside an existing cluster. * specified tile is inside an existing cluster.
@@ -28,16 +28,18 @@ import flash.geom.Point;
import as3isolib.display.IsoSprite; import as3isolib.display.IsoSprite;
import com.threerings.miso.client.PriorityIsoDisplayObject; import com.threerings.miso.client.PriorityIsoDisplayObject;
import com.threerings.whirled.spot.data.Portal;
public class PortalIsoSprite extends IsoSprite public class PortalIsoSprite extends IsoSprite
implements PriorityIsoDisplayObject implements PriorityIsoDisplayObject
{ {
public function PortalIsoSprite (img :DisplayObject, x :int, y :int) public function PortalIsoSprite (img :DisplayObject, x :int, y :int, portal :Portal)
{ {
sprites = [img]; sprites = [img];
setSize(1, 1, 1); setSize(1, 1, 1);
moveTo(x, y, 0); moveTo(x, y, 0);
setRaised(false); setRaised(false);
_portal = portal;
} }
public function getPriority () :int public function getPriority () :int
@@ -45,6 +47,11 @@ public class PortalIsoSprite extends IsoSprite
return 0; return 0;
} }
public function getPortal () :Portal
{
return _portal;
}
public function hitTest (stageX :int, stageY :int) :Boolean public function hitTest (stageX :int, stageY :int) :Boolean
{ {
if (sprites == null || sprites.length == 0) { if (sprites == null || sprites.length == 0) {
@@ -68,5 +75,7 @@ public class PortalIsoSprite extends IsoSprite
{ {
sprites[0].alpha = (raised ? 1.0 : 0.5); sprites[0].alpha = (raised ? 1.0 : 0.5);
} }
protected var _portal :Portal;
} }
} }
@@ -73,7 +73,7 @@ public class StageSceneBlock extends SceneBlock
StageScenePanel(panel).getPortalImage(StageLocation(portal.loc).orient); StageScenePanel(panel).getPortalImage(StageLocation(portal.loc).orient);
img.x = -img.width/2 + int(_metrics.finehwid * (fineX - fineY)); img.x = -img.width/2 + int(_metrics.finehwid * (fineX - fineY));
img.y = -img.height/2 + int(_metrics.finehhei * (fineX + fineY)); img.y = -img.height/2 + int(_metrics.finehhei * (fineX + fineY));
var portalSprite :PortalIsoSprite = new PortalIsoSprite(img, x, y); var portalSprite :PortalIsoSprite = new PortalIsoSprite(img, x, y, portal);
if (_portSprites == null) { if (_portSprites == null) {
_portSprites = []; _portSprites = [];