From 1d37bcaa061d64b1f13ed5420c00fd0700e6b0f0 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 23 Aug 2006 21:15:16 +0000 Subject: [PATCH] A very boring and generic chatbox (moved from msoy). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4340 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/mx/controls/ChatDisplayBox.as | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/as/com/threerings/mx/controls/ChatDisplayBox.as diff --git a/src/as/com/threerings/mx/controls/ChatDisplayBox.as b/src/as/com/threerings/mx/controls/ChatDisplayBox.as new file mode 100644 index 000000000..a810f541d --- /dev/null +++ b/src/as/com/threerings/mx/controls/ChatDisplayBox.as @@ -0,0 +1,82 @@ +package com.threerings.mx.controls { + +import flash.display.DisplayObjectContainer; + +import flash.events.Event; + +import mx.controls.TextArea; + +import com.threerings.crowd.chat.client.ChatDirector; +import com.threerings.crowd.chat.client.ChatDisplay; +import com.threerings.crowd.chat.data.ChatMessage; +import com.threerings.crowd.chat.data.UserMessage; +import com.threerings.crowd.util.CrowdContext; + +/** + * IMPORTANT NOTE: this class was written for testing things and does not + * necessarily represent a valid starting point for writing the chat + * widget we'll eventually need. + */ +public class ChatDisplayBox extends TextArea + implements ChatDisplay +{ + public function ChatDisplayBox (ctx :CrowdContext) + { + _ctx = ctx; + this.editable = false; + + // TODO + width = 400; + height = 150; + } + + // documentation inherited from interface ChatDisplay + public function clear () :void + { + this.htmlText = ""; + } + + // documentation inherited from interface ChatDisplay + public function displayMessage (msg :ChatMessage) :void + { + if (!_scrollBot) { + _scrollBot = (verticalScrollPosition == maxVerticalScrollPosition); + } + + // display the message + if (msg is UserMessage) { + this.htmlText += "<" + + (msg as UserMessage).speaker + "> "; + } + this.htmlText += msg.message; + } + + override public function parentChanged (p :DisplayObjectContainer) :void + { + super.parentChanged(p); + + var chatdir :ChatDirector = _ctx.getChatDirector(); + if (p != null) { + chatdir.addChatDisplay(this); + } else { + chatdir.removeChatDisplay(this); + } + } + + // documentation inherited + override protected function updateDisplayList (uw :Number, uh :Number) :void + { + super.updateDisplayList(uw, uh); + + if (_scrollBot) { + verticalScrollPosition = maxVerticalScrollPosition; + _scrollBot = false; + } + } + + /** The giver of life. */ + protected var _ctx :CrowdContext; + + protected var _scrollBot :Boolean; +} +}