From 77e9cfce005c023940d9fbb699d8c00db3fbeb99 Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Fri, 27 Aug 2010 21:32:46 +0000 Subject: [PATCH] Wire up handling of clicking on portals. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@962 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../stage/client/CrowdStageScenePanel.as | 41 ++++++++++++++++++- .../stage/client/PortalIsoSprite.as | 11 ++++- .../stage/client/StageSceneBlock.as | 2 +- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/as/com/threerings/stage/client/CrowdStageScenePanel.as b/src/as/com/threerings/stage/client/CrowdStageScenePanel.as index 391ccaec..20458db9 100644 --- a/src/as/com/threerings/stage/client/CrowdStageScenePanel.as +++ b/src/as/com/threerings/stage/client/CrowdStageScenePanel.as @@ -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. diff --git a/src/as/com/threerings/stage/client/PortalIsoSprite.as b/src/as/com/threerings/stage/client/PortalIsoSprite.as index 8b270ca3..3ede48a8 100644 --- a/src/as/com/threerings/stage/client/PortalIsoSprite.as +++ b/src/as/com/threerings/stage/client/PortalIsoSprite.as @@ -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; } } \ No newline at end of file diff --git a/src/as/com/threerings/stage/client/StageSceneBlock.as b/src/as/com/threerings/stage/client/StageSceneBlock.as index 29040411..93e79ffa 100644 --- a/src/as/com/threerings/stage/client/StageSceneBlock.as +++ b/src/as/com/threerings/stage/client/StageSceneBlock.as @@ -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 = [];