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:
@@ -504,7 +504,10 @@ public class CrowdStageScenePanel extends StageScenePanel
|
||||
if (hobject is CharacterIsoSprite) {
|
||||
handleSpriteClicked(CharacterIsoSprite(hobject));
|
||||
return true;
|
||||
}
|
||||
} else if (hobject is PortalIsoSprite) {
|
||||
handlePortalClicked(PortalIsoSprite(hobject).getPortal());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Move ourselves to the spot clicked.
|
||||
handleLocationClicked(new StageLocation(MisoUtil.tileToFull(iso.x),
|
||||
@@ -513,6 +516,37 @@ public class CrowdStageScenePanel extends StageScenePanel
|
||||
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
|
||||
{
|
||||
// Nothing by default.
|
||||
@@ -559,6 +593,11 @@ public class CrowdStageScenePanel extends StageScenePanel
|
||||
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
|
||||
* specified tile is inside an existing cluster.
|
||||
|
||||
@@ -28,16 +28,18 @@ import flash.geom.Point;
|
||||
import as3isolib.display.IsoSprite;
|
||||
|
||||
import com.threerings.miso.client.PriorityIsoDisplayObject;
|
||||
import com.threerings.whirled.spot.data.Portal;
|
||||
|
||||
public class PortalIsoSprite extends IsoSprite
|
||||
implements PriorityIsoDisplayObject
|
||||
{
|
||||
public function PortalIsoSprite (img :DisplayObject, x :int, y :int)
|
||||
public function PortalIsoSprite (img :DisplayObject, x :int, y :int, portal :Portal)
|
||||
{
|
||||
sprites = [img];
|
||||
setSize(1, 1, 1);
|
||||
moveTo(x, y, 0);
|
||||
setRaised(false);
|
||||
_portal = portal;
|
||||
}
|
||||
|
||||
public function getPriority () :int
|
||||
@@ -45,6 +47,11 @@ public class PortalIsoSprite extends IsoSprite
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPortal () :Portal
|
||||
{
|
||||
return _portal;
|
||||
}
|
||||
|
||||
public function hitTest (stageX :int, stageY :int) :Boolean
|
||||
{
|
||||
if (sprites == null || sprites.length == 0) {
|
||||
@@ -68,5 +75,7 @@ public class PortalIsoSprite extends IsoSprite
|
||||
{
|
||||
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);
|
||||
img.x = -img.width/2 + int(_metrics.finehwid * (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) {
|
||||
_portSprites = [];
|
||||
|
||||
Reference in New Issue
Block a user