Have the LocationDirector configure the ChatDirector with the current place
rather than having the ChatDirector listen for location changes from the location director. This allows us to have multiple location directors work with the same chat director as long as we're only in one place in one of the location directors at a time. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5621 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -44,7 +44,6 @@ import com.threerings.util.MessageManager;
|
|||||||
import com.threerings.util.Name;
|
import com.threerings.util.Name;
|
||||||
import com.threerings.util.TimeUtil;
|
import com.threerings.util.TimeUtil;
|
||||||
|
|
||||||
import com.threerings.crowd.client.LocationObserver;
|
|
||||||
import com.threerings.crowd.data.BodyObject;
|
import com.threerings.crowd.data.BodyObject;
|
||||||
import com.threerings.crowd.data.CrowdCodes;
|
import com.threerings.crowd.data.CrowdCodes;
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
import com.threerings.crowd.data.PlaceObject;
|
||||||
@@ -64,15 +63,13 @@ import com.threerings.crowd.chat.data.UserSystemMessage;
|
|||||||
* place constrained chat as well as direct messaging.
|
* place constrained chat as well as direct messaging.
|
||||||
*/
|
*/
|
||||||
public class ChatDirector extends BasicDirector
|
public class ChatDirector extends BasicDirector
|
||||||
implements LocationObserver, MessageListener
|
implements MessageListener
|
||||||
{
|
{
|
||||||
// statically reference classes we require
|
// statically reference classes we require
|
||||||
ChatMarshaller;
|
ChatMarshaller;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a chat director and initializes it with the supplied context. The chat director will
|
* Creates a chat director and initializes it with the supplied context.
|
||||||
* register itself as a location observer so that it can automatically process place
|
|
||||||
* constrained chat.
|
|
||||||
*
|
*
|
||||||
* @param msgmgr the message manager via which we do our translations.
|
* @param msgmgr the message manager via which we do our translations.
|
||||||
* @param bundle the message bundle from which we obtain our chat-related translation strings.
|
* @param bundle the message bundle from which we obtain our chat-related translation strings.
|
||||||
@@ -86,11 +83,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
_msgmgr = msgmgr;
|
_msgmgr = msgmgr;
|
||||||
_bundle = bundle;
|
_bundle = bundle;
|
||||||
|
|
||||||
// register ourselves as a location observer
|
|
||||||
_cctx.getLocationDirector().addLocationObserver(this);
|
|
||||||
|
|
||||||
if (_bundle == null || _msgmgr == null) {
|
if (_bundle == null || _msgmgr == null) {
|
||||||
Log.getLog(this).warning("Null bundle or message manager given to ChatDirector");
|
log.warning("Null bundle or message manager given to ChatDirector");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var msg :MessageBundle = _msgmgr.getBundle(_bundle);
|
var msg :MessageBundle = _msgmgr.getBundle(_bundle);
|
||||||
@@ -564,32 +558,38 @@ public class ChatDirector extends BasicDirector
|
|||||||
return mogrifyChatImpl(text, false, true);
|
return mogrifyChatImpl(text, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface LocationObserver
|
/**
|
||||||
public function locationMayChange (placeId :int) :Boolean
|
* Called by a LocationDirector when we enter a new location to configure our place chat.
|
||||||
|
*/
|
||||||
|
public function enteredLocation (place :PlaceObject) :void
|
||||||
{
|
{
|
||||||
// we accept all location change requests
|
if (place == null) {
|
||||||
return true;
|
log.warning("enteredLocation must be passed a non-null place object!");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited from interface LocationObserver
|
// nix our old location if we have one
|
||||||
public function locationDidChange (place :PlaceObject) :void
|
|
||||||
{
|
|
||||||
if (_place != null) {
|
if (_place != null) {
|
||||||
// unlisten to our old object
|
leftLocation(_place);
|
||||||
_place.removeListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// listen to the new object
|
// listen to the new object
|
||||||
_place = place;
|
_place = place;
|
||||||
if (_place != null) {
|
_place.addListener(this);
|
||||||
_place.addListener(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface LocationObserver
|
/**
|
||||||
public function locationChangeFailed (placeId :int, reason :String) :void
|
* Called by a LocationDirector when we leave our current place.
|
||||||
|
*/
|
||||||
|
public function leftLocation (place :PlaceObject) :void
|
||||||
{
|
{
|
||||||
// nothing we care about
|
// if this is our current place chat, then stop listening to it
|
||||||
|
if (place == _place) {
|
||||||
|
_place.removeListener(this);
|
||||||
|
_place = null;
|
||||||
|
} else {
|
||||||
|
log.warning("leftLocation called with unknown place?", "have", _place, "left", place);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface MessageListener
|
// documentation inherited from interface MessageListener
|
||||||
@@ -649,8 +649,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
_chatters.length = 0;
|
_chatters.length = 0;
|
||||||
notifyChatterObservers();
|
notifyChatterObservers();
|
||||||
|
|
||||||
// clear the _place
|
// the location director will call leftLocation() when we logoff
|
||||||
locationDidChange(null);
|
|
||||||
|
|
||||||
// clear our service
|
// clear our service
|
||||||
_cservice = null;
|
_cservice = null;
|
||||||
@@ -942,8 +941,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
if (bundle != null && _msgmgr != null) {
|
if (bundle != null && _msgmgr != null) {
|
||||||
var msgb :MessageBundle = _msgmgr.getBundle(bundle);
|
var msgb :MessageBundle = _msgmgr.getBundle(bundle);
|
||||||
if (msgb == null) {
|
if (msgb == null) {
|
||||||
Log.getLog(this).warning("No message bundle available to translate message " +
|
log.warning("No message bundle available to translate message",
|
||||||
"[bundle=" + bundle + ", message=" + message + "].");
|
"bundle", bundle, "message", message);
|
||||||
} else {
|
} else {
|
||||||
message = msgb.xlate(message);
|
message = msgb.xlate(message);
|
||||||
}
|
}
|
||||||
@@ -1001,6 +1000,9 @@ public class ChatDirector extends BasicDirector
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Log this! */
|
||||||
|
protected const log :Log = Log.getLog(this);
|
||||||
|
|
||||||
/** Our active chat context. */
|
/** Our active chat context. */
|
||||||
protected var _cctx :CrowdContext;
|
protected var _cctx :CrowdContext;
|
||||||
|
|
||||||
|
|||||||
@@ -332,6 +332,9 @@ public class LocationDirector extends BasicDirector
|
|||||||
_controller = null;
|
_controller = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// let the chat director know that we're leaving this place
|
||||||
|
_cctx.getChatDirector().leftLocation(_plobj);
|
||||||
|
|
||||||
// unsubscribe from our old place object
|
// unsubscribe from our old place object
|
||||||
_cctx.getDObjectManager().unsubscribeFromObject(_plobj.getOid(), this);
|
_cctx.getDObjectManager().unsubscribeFromObject(_plobj.getOid(), this);
|
||||||
_plobj = null;
|
_plobj = null;
|
||||||
@@ -467,6 +470,9 @@ public class LocationDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// let the chat director know that we're entering this place
|
||||||
|
_cctx.getChatDirector().enteredLocation(_plobj);
|
||||||
|
|
||||||
// let our observers know that all is well on the western front
|
// let our observers know that all is well on the western front
|
||||||
_observers.apply(didChangeOp);
|
_observers.apply(didChangeOp);
|
||||||
}
|
}
|
||||||
@@ -558,8 +564,7 @@ public class LocationDirector extends BasicDirector
|
|||||||
/** The place controller in effect for our current place. */
|
/** The place controller in effect for our current place. */
|
||||||
protected var _controller :PlaceController;
|
protected var _controller :PlaceController;
|
||||||
|
|
||||||
/** The oid of the place for which we have an outstanding moveTo request, or -1 if we have no
|
/** The place oid to whihc we have an outstanding moveTo request, or -1 if we have none. */
|
||||||
* outstanding request. */
|
|
||||||
protected var _pendingPlaceId :int = -1;
|
protected var _pendingPlaceId :int = -1;
|
||||||
|
|
||||||
/** The oid of the place we previously occupied. */
|
/** The oid of the place we previously occupied. */
|
||||||
@@ -574,8 +579,7 @@ public class LocationDirector extends BasicDirector
|
|||||||
/** A listener that wants to know if we succeeded or how we failed to move. */
|
/** A listener that wants to know if we succeeded or how we failed to move. */
|
||||||
protected var _moveListener :ResultListener;
|
protected var _moveListener :ResultListener;
|
||||||
|
|
||||||
/** We require that a moveTo request be outstanding for one minute before it is declared to be
|
/** Allow a moveTo request be outstanding for one minute before it is declared to be stale. */
|
||||||
* stale. */
|
|
||||||
protected static const STALE_REQUEST_DURATION :int = 60 * 1000;
|
protected static const STALE_REQUEST_DURATION :int = 60 * 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user