Mostly kinda fixed up keyboard issues for EZGames.

They can add their keyboard listeners directly to the GameControl object
to receive global key events.

There are strange focus weirdnesses on the flex side- sometimes you have
focus with no focus highlight and sometimes you don't have focus and you
do have the highlight. Punting, rather than spending more hours on this.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@138 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Ray Greenwell
2007-01-06 01:44:05 +00:00
parent 3b08974f73
commit 00e2c45f01
4 changed files with 137 additions and 14 deletions
@@ -5,6 +5,12 @@ import flash.errors.IllegalOperationError;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.display.InteractiveObject;
import flash.utils.IExternalizable;
import flash.utils.ByteArray;
@@ -38,6 +44,9 @@ import com.threerings.ezgame.data.PropertySetListener;
import com.threerings.ezgame.data.UserCookie;
import com.threerings.ezgame.util.EZObjectMarshaller;
/**
* Manages the backend of the game.
*/
public class GameControlBackend
implements MessageListener, SetListener, PropertySetListener
{
@@ -59,6 +68,11 @@ public class GameControlBackend
disp.addEventListener("ezgameQuery", handleEZQuery);
}
public function setContainer (container :GameContainer) :void
{
_container = container;
}
public function shutdown () :void
{
_ezObj.removeListener(this);
@@ -76,6 +90,8 @@ public class GameControlBackend
{
// here we would handle adapting old functions to a new version
_ezDispatcher = (o["dispatchEvent_v1"] as Function);
_userFuncs = o;
}
@@ -121,6 +137,8 @@ public class GameControlBackend
o["endGame_v1"] = endGame_v1;
o["populateCollection_v1"] = populateCollection_v1;
o["getFromCollection_v1"] = getFromCollection_v1;
o["alterKeyEvents_v1"] = alterKeyEvents_v1;
o["focusContainer_v1"] = focusContainer_v1;
}
public function setProperty_v1 (
@@ -342,6 +360,30 @@ public class GameControlBackend
playerIndex, listener);
}
public function alterKeyEvents_v1 (
keyEventType :String, add :Boolean) :void
{
if (add) {
_container.addEventListener(keyEventType, handleKeyEvent);
} else {
_container.removeEventListener(keyEventType, handleKeyEvent);
}
}
public function focusContainer_v1 () :void
{
_container.setFocus();
}
/**
* Handle key events on our container and pass them into the game.
*/
protected function handleKeyEvent (evt :KeyboardEvent) :void
{
// dispatch a cloned copy of the event, so that it's safe
_ezDispatcher(evt.clone());
}
/**
* Convenience function to get our name.
*/
@@ -564,10 +606,16 @@ public class GameControlBackend
protected var _userListener :MessageAdapter =
new MessageAdapter(messageReceivedOnUserObject);
protected var _container :GameContainer;
protected var _ezObj :EZGameObject;
protected var _userFuncs :Object;
/** The function on the EZGameControl which we can use to directly
* dispatch events to the user's game. */
protected var _ezDispatcher :Function;
protected var _gameData :GameData;
/** playerIndex -> callback functions waiting for the cookie. */