diff --git a/src/as/com/threerings/crowd/client/PlaceController.as b/src/as/com/threerings/crowd/client/PlaceController.as index 827f8d09d..6e8a68a46 100644 --- a/src/as/com/threerings/crowd/client/PlaceController.as +++ b/src/as/com/threerings/crowd/client/PlaceController.as @@ -25,6 +25,8 @@ import com.threerings.crowd.data.PlaceConfig; import com.threerings.crowd.data.PlaceObject; import com.threerings.crowd.util.CrowdContext; +import com.threerings.events.ControllerEvent; + /** * Controls the user interface that is used to display a place. When the * client moves to a new place, the appropriate place controller is @@ -119,6 +121,9 @@ public /*abstract*/ class PlaceController /*extends Controller*/ _plobj = plobj; if (_view != null ) { + _view.addEventListener( + ControllerEvent.TYPE, handleControllerEvent); + // let the UI hierarchy know that we've got our place PlaceViewUtil.dispatchWillEnterPlace(_view, plobj); // and display the user interface @@ -172,6 +177,8 @@ public /*abstract*/ class PlaceController /*extends Controller*/ // let the UI hierarchy know that we're outta here if (_view != null ) { + _view.removeEventListener( + ControllerEvent.TYPE, handleControllerEvent); PlaceViewUtil.dispatchDidLeavePlace(_view, plobj); _ctx.clearPlaceView(_view); _view = null; @@ -180,6 +187,28 @@ public /*abstract*/ class PlaceController /*extends Controller*/ _plobj = null; } + /** + * Handle the specified action that was generated somewhere in our + * view. + * + * @return true if the action has been handled, false otherwise. + */ + public function handleAction (cmd :String, arg :Object) :Boolean + { + return false; // by default, no action is handled + } + + /** + * A callback where we listen to ControllerEvents and unwrap + * them for easy handling. + */ + private function handleControllerEvent (event :ControllerEvent) :void + { + if (handleAction(event.command, event.arg)) { + event.stopImmediatePropagation(); + } + } + /** * Handles basic place controller action events. Derived classes * should be sure to call super.handleAction for events diff --git a/src/as/com/threerings/crowd/client/PlaceView.as b/src/as/com/threerings/crowd/client/PlaceView.as index 1b486b815..310472629 100644 --- a/src/as/com/threerings/crowd/client/PlaceView.as +++ b/src/as/com/threerings/crowd/client/PlaceView.as @@ -21,6 +21,8 @@ package com.threerings.crowd.client { +import flash.events.IEventDispatcher; + import com.threerings.crowd.data.PlaceObject; /** @@ -56,7 +58,7 @@ import com.threerings.crowd.data.PlaceObject; * com.threerings.crowd.util.CrowdContext} derivative in use by * the client, but those are best supplied at construct time. */ -public interface PlaceView +public interface PlaceView extends IEventDispatcher { /** * Called when the client has entered a place and is about to display diff --git a/src/as/com/threerings/events/ControllerEvent.as b/src/as/com/threerings/events/ControllerEvent.as new file mode 100644 index 000000000..0ed61bae0 --- /dev/null +++ b/src/as/com/threerings/events/ControllerEvent.as @@ -0,0 +1,25 @@ +package com.threerings.events { + +import flash.events.Event; + +public class ControllerEvent extends Event +{ + /** The event type for all controller events. */ + public static const TYPE :String = "controller"; + + public var command :String; + public var arg :Object; + + public function ControllerEvent (command :String, arg :Object = null) + { + super(TYPE, true); + this.command = command; + this.arg = arg; + } + + public override function toString () :String + { + return "ControllerEvent[" + command + " (" + arg + ")]"; + } +} +}