Created a base Controller class; added a CommandButton that submits
controller commands; have PlaceController extend Controller. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4275 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.threerings.util {
|
||||
|
||||
import flash.events.IEventDispatcher;
|
||||
|
||||
import com.threerings.events.ControllerEvent;
|
||||
|
||||
public class Controller
|
||||
{
|
||||
/**
|
||||
* Set the panel being controlled.
|
||||
*/
|
||||
protected function setControlledPanel (panel :IEventDispatcher) :void
|
||||
{
|
||||
if (_panel != null) {
|
||||
_panel.removeEventListener(
|
||||
ControllerEvent.TYPE, handleControllerEvent);
|
||||
}
|
||||
_panel = panel;
|
||||
if (_panel != null) {
|
||||
_panel.addEventListener(
|
||||
ControllerEvent.TYPE, handleControllerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an action that was generated by our panel or some child.
|
||||
*
|
||||
* @return true if the specified action was handled, false otherwise.
|
||||
*
|
||||
* When creating your own controller, override this function and return
|
||||
* true for any command handled, and call super for any unknown commands.
|
||||
*/
|
||||
public function handleAction (cmd :String, arg :Object) :Boolean
|
||||
{
|
||||
// TODO: This warning should really be inside the ControllerEvent
|
||||
// somewhere, and only generated if the event never gets cancelled
|
||||
Log.getLog(this).warning("Unhandled controller command " +
|
||||
"[cmd=" + cmd + ", arg=" + arg + "].");
|
||||
return false; // not handled
|
||||
}
|
||||
|
||||
/**
|
||||
* Private function to handle the controller event and call
|
||||
* handleAction.
|
||||
*/
|
||||
private function handleControllerEvent (event :ControllerEvent) :void
|
||||
{
|
||||
if (handleAction(event.command, event.arg)) {
|
||||
// if we handle the event, stop it from moving outward to another
|
||||
// controller
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
}
|
||||
|
||||
/** The panel currently being controlled. */
|
||||
private var _panel :IEventDispatcher;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user