Made PlaceView extend flash's IEventDispatcher, wired up something

that sorta behaves like our controllers in java. I might be able to make
this better.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4161 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-05-31 01:27:13 +00:00
parent 2766a6c1f9
commit e981a9eed9
3 changed files with 57 additions and 1 deletions
@@ -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 <code>super.handleAction</code> for events
@@ -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
@@ -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 + ")]";
}
}
}