From 1baf1d218644ac5dc00d9b41119a1ef168c709a2 Mon Sep 17 00:00:00 2001 From: angela Date: Mon, 16 Nov 2009 20:46:40 +0800 Subject: fix chat format for /me --- indra/llui/llstyle.cpp | 29 ++++++++++++++++++++-- indra/llui/llstyle.h | 5 ++++ indra/llui/lltextbase.cpp | 11 ++++---- indra/newview/llchathistory.cpp | 6 +++-- indra/newview/llchathistory.h | 2 +- indra/newview/llchatitemscontainerctrl.cpp | 24 ++++++++++++++++-- indra/newview/llexpandabletextbox.cpp | 5 ++-- indra/newview/llimfloater.cpp | 28 ++++++++++++++++++++- indra/newview/llnearbychat.cpp | 28 ++++++++++++++++++++- indra/newview/llnearbychathandler.cpp | 1 + indra/newview/lltoastimpanel.cpp | 4 +-- indra/newview/llviewerchat.cpp | 17 +++++++++++++ indra/newview/llviewerchat.h | 3 +-- indra/newview/llviewermessage.cpp | 40 ++++++++++++++++-------------- 14 files changed, 163 insertions(+), 40 deletions(-) (limited to 'indra') diff --git a/indra/llui/llstyle.cpp b/indra/llui/llstyle.cpp index 71511f69a4..92c0b7c1b4 100644 --- a/indra/llui/llstyle.cpp +++ b/indra/llui/llstyle.cpp @@ -44,7 +44,10 @@ LLStyle::Params::Params() color("color", LLColor4::black), font("font", LLFontGL::getFontMonospace()), image("image"), - link_href("href") + link_href("href"), + italic("italic", false ), + bold("bold", false), + underline("bold", false) {} @@ -55,7 +58,10 @@ LLStyle::LLStyle(const LLStyle::Params& p) mFont(p.font()), mLink(p.link_href), mDropShadow(p.drop_shadow), - mImagep(p.image()) + mImagep(p.image()), + mItalic(p.italic()), + mBold(p.bold), + mUnderline(p.underline) {} void LLStyle::setFont(const LLFontGL* font) @@ -69,6 +75,25 @@ const LLFontGL* LLStyle::getFont() const return mFont; } +const S32 LLStyle::getFontStyle() const +{ + S32 ret = 0; + if (mBold) + { + ret |= LLFontGL::BOLD; + } + if (mItalic) + { + ret |= LLFontGL::ITALIC; + } + if (mUnderline) + { + ret |= LLFontGL::UNDERLINE; + } + return ret; +} + + void LLStyle::setLinkHREF(const std::string& href) { mLink = href; diff --git a/indra/llui/llstyle.h b/indra/llui/llstyle.h index ee9ca730e9..cc72011903 100644 --- a/indra/llui/llstyle.h +++ b/indra/llui/llstyle.h @@ -51,12 +51,17 @@ public: Optional font; Optional image; Optional link_href; + Optional italic; + Optional bold; + Optional underline; Params(); }; LLStyle(const Params& p = Params()); public: const LLColor4& getColor() const { return mColor; } void setColor(const LLColor4 &color) { mColor = color; } + + const S32 getFontStyle() const; const LLColor4& getReadOnlyColor() const { return mReadOnlyColor; } diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp index 7b1aaac35c..d7697ac7cc 100644 --- a/indra/llui/lltextbase.cpp +++ b/indra/llui/lltextbase.cpp @@ -1506,9 +1506,8 @@ void LLTextBase::appendText(const std::string &new_text, bool prepend_newline, c LLStyle::Params link_params = style_params; link_params.color = match.getColor(); // apply font name from requested style_params - std::string font_name = LLFontGL::nameFromFont(style_params.font()); - link_params.font.name.setIfNotProvided(font_name); - link_params.font.style = "UNDERLINE"; + std::string font_name = LLFontGL::nameFromFont(style_params.font()); + link_params.underline = true; link_params.link_href = match.getUrl(); // output the text before the Url @@ -2251,7 +2250,7 @@ F32 LLNormalTextSegment::drawClippedSegment(S32 seg_start, S32 seg_end, S32 sele rect.mLeft, rect.mTop, color, LLFontGL::LEFT, LLFontGL::TOP, - 0, + mStyle->getFontStyle(), mStyle->getShadowType(), length, rect.getWidth(), &right_x, @@ -2270,7 +2269,7 @@ F32 LLNormalTextSegment::drawClippedSegment(S32 seg_start, S32 seg_end, S32 sele rect.mLeft, rect.mTop, LLColor4( 1.f - color.mV[0], 1.f - color.mV[1], 1.f - color.mV[2], 1.f ), LLFontGL::LEFT, LLFontGL::TOP, - 0, + mStyle->getFontStyle(), LLFontGL::NO_SHADOW, length, rect.mRight, &right_x, @@ -2287,7 +2286,7 @@ F32 LLNormalTextSegment::drawClippedSegment(S32 seg_start, S32 seg_end, S32 sele rect.mLeft, rect.mTop, color, LLFontGL::LEFT, LLFontGL::TOP, - 0, + mStyle->getFontStyle(), mStyle->getShadowType(), length, rect.mRight, &right_x, diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp index 028bb7a384..bec8eb2666 100644 --- a/indra/newview/llchathistory.cpp +++ b/indra/newview/llchathistory.cpp @@ -345,7 +345,7 @@ LLView* LLChatHistory::getHeader(const LLChat& chat,const LLStyle::Params& style return header; } -void LLChatHistory::appendWidgetMessage(const LLChat& chat) +void LLChatHistory::appendWidgetMessage(const LLChat& chat, const LLStyle::Params& input_append_params) { LLView* view = NULL; std::string view_text = "\n[" + formatCurrentTime() + "] "; @@ -367,7 +367,9 @@ void LLChatHistory::appendWidgetMessage(const LLChat& chat) style_params.color(txt_color); style_params.readonly_color(txt_color); style_params.font(fontp); - + style_params.italic = input_append_params.italic; + style_params.underline = input_append_params.underline; + style_params.bold = input_append_params.bold; if (mLastFromName == chat.mFromName) { diff --git a/indra/newview/llchathistory.h b/indra/newview/llchathistory.h index f689a225fe..c89d4b4ec6 100644 --- a/indra/newview/llchathistory.h +++ b/indra/newview/llchathistory.h @@ -109,7 +109,7 @@ class LLChatHistory : public LLTextEditor * @param time time of a message. * @param message message itself. */ - void appendWidgetMessage(const LLChat& chat); + void appendWidgetMessage(const LLChat& chat, const LLStyle::Params& input_append_params = LLStyle::Params()); private: std::string mLastFromName; diff --git a/indra/newview/llchatitemscontainerctrl.cpp b/indra/newview/llchatitemscontainerctrl.cpp index d2e3247250..1cc6b2beef 100644 --- a/indra/newview/llchatitemscontainerctrl.cpp +++ b/indra/newview/llchatitemscontainerctrl.cpp @@ -173,10 +173,28 @@ void LLNearbyChatToastPanel::init(LLSD& notification) caption->getChild("msg_time", false)->setText(appendTime() , style_params ); - LLChatMsgBox* msg_text = getChild("msg_text", false); - msg_text->setText(mText, style_params); + + if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC) + { + if (mFromName.size() > 0) + { + style_params.italic= true; + + msg_text->setText(mFromName, style_params); + } + mText = mText.substr(3); + style_params.underline = true; + msg_text->addText(mText,style_params); + } + else + { + msg_text->setText(mText, style_params); + } + + + LLUICtrl* msg_inspector = caption->getChild("msg_inspector"); if(mSourceType != CHAT_SOURCE_AGENT) msg_inspector->setVisible(false); @@ -196,6 +214,8 @@ void LLNearbyChatToastPanel::setMessage (const LLChat& chat_msg) notification["from_id"] = chat_msg.mFromID; notification["time"] = chat_msg.mTime; notification["source"] = (S32)chat_msg.mSourceType; + notification["chat_type"] = (S32)chat_msg.mChatType; + notification["chat_style"] = (S32)chat_msg.mChatStyle; std::string r_color_name="White"; F32 r_color_alpha = 1.0f; diff --git a/indra/newview/llexpandabletextbox.cpp b/indra/newview/llexpandabletextbox.cpp index 6d7da107ac..27df6be730 100644 --- a/indra/newview/llexpandabletextbox.cpp +++ b/indra/newview/llexpandabletextbox.cpp @@ -80,7 +80,7 @@ public: draw_rect.mRight, draw_rect.mTop, mStyle->getColor(), LLFontGL::RIGHT, LLFontGL::TOP, - 0, + mStyle->getFontStyle(), mStyle->getShadowType(), end - start, draw_rect.getWidth(), &right_x, @@ -164,8 +164,7 @@ void LLExpandableTextBox::LLTextBoxEx::showExpandText() S32 last_line = visible_lines.second - 1; LLStyle::Params expander_style = getDefaultStyle(); - expander_style.font.name.setIfNotProvided(LLFontGL::nameFromFont(expander_style.font)); - expander_style.font.style = "UNDERLINE"; + expander_style.underline = true; expander_style.color = LLUIColorTable::instance().getColor("HTMLLinkColor"); LLExpanderSegment* expanderp = new LLExpanderSegment(new LLStyle(expander_style), getLineStart(last_line), getLength() + 1, mExpanderLabel, *this); insertSegment(expanderp); diff --git a/indra/newview/llimfloater.cpp b/indra/newview/llimfloater.cpp index e3121fbc7a..dff27ee032 100644 --- a/indra/newview/llimfloater.cpp +++ b/indra/newview/llimfloater.cpp @@ -477,7 +477,33 @@ void LLIMFloater::updateMessages() chat.mFromName = from; chat.mText = message; - mChatHistory->appendWidgetMessage(chat); + LLStyle::Params append_style_params; + //Handle IRC styled /me messages. + std::string prefix = message.substr(0, 4); + if (prefix == "/me " || prefix == "/me'") + { + if (from.size() > 0) + { + append_style_params.italic= true; + chat.mText = from + " "; + mChatHistory->appendWidgetMessage(chat, append_style_params); + } + message = message.substr(3); + + LLColor4 txt_color = LLUIColorTable::instance().getColor("White"); + LLViewerChat::getChatColor(chat,txt_color); + LLFontGL* fontp = LLViewerChat::getChatFont(); + append_style_params.color(txt_color); + append_style_params.readonly_color(txt_color); + append_style_params.font(fontp); + append_style_params.underline = true; + mChatHistory->appendText(message, FALSE, append_style_params); + } + else + { + chat.mText = message; + mChatHistory->appendWidgetMessage(chat); + } mLastMessageIndex = msg["index"].asInteger(); } diff --git a/indra/newview/llnearbychat.cpp b/indra/newview/llnearbychat.cpp index 85db69174d..68677decae 100644 --- a/indra/newview/llnearbychat.cpp +++ b/indra/newview/llnearbychat.cpp @@ -155,7 +155,33 @@ void LLNearbyChat::addMessage(const LLChat& chat) if (!chat.mMuted) { - mChatHistory->appendWidgetMessage(chat); + std::string message = chat.mText; + std::string prefix = message.substr(0, 4); + if (chat.mChatStyle == CHAT_STYLE_IRC) + { + LLStyle::Params append_style_params; + if (chat.mFromName.size() > 0) + { + append_style_params.italic= true; + LLChat add_chat=chat; + add_chat.mText = chat.mFromName + " "; + mChatHistory->appendWidgetMessage(add_chat, append_style_params); + } + message = message.substr(3); + + LLColor4 txt_color = LLUIColorTable::instance().getColor("White"); + LLViewerChat::getChatColor(chat,txt_color); + LLFontGL* fontp = LLViewerChat::getChatFont(); + append_style_params.color(txt_color); + append_style_params.readonly_color(txt_color); + append_style_params.font(fontp); + append_style_params.underline = true; + mChatHistory->appendText(message, FALSE, append_style_params); + } + else + { + mChatHistory->appendWidgetMessage(chat); + } } } diff --git a/indra/newview/llnearbychathandler.cpp b/indra/newview/llnearbychathandler.cpp index 458845fff3..74a75d0369 100644 --- a/indra/newview/llnearbychathandler.cpp +++ b/indra/newview/llnearbychathandler.cpp @@ -341,6 +341,7 @@ void LLNearbyChatHandler::processChat(const LLChat& chat_msg) notification["time"] = chat_msg.mTime; notification["source"] = (S32)chat_msg.mSourceType; notification["chat_type"] = (S32)chat_msg.mChatType; + notification["chat_style"] = (S32)chat_msg.mChatStyle; std::string r_color_name = "White"; F32 r_color_alpha = 1.0f; diff --git a/indra/newview/lltoastimpanel.cpp b/indra/newview/lltoastimpanel.cpp index 1ea5f515b7..3acab85bf7 100644 --- a/indra/newview/lltoastimpanel.cpp +++ b/indra/newview/lltoastimpanel.cpp @@ -56,9 +56,9 @@ LLToastIMPanel::LLToastIMPanel(LLToastIMPanel::Params &p) : LLToastPanel(p.notif if (prefix == "/me " || prefix == "/me'") { mMessage->clear(); - style_params.font.style= "ITALIC"; + style_params.italic = true; mMessage->appendText(p.from + " ", FALSE, style_params); - style_params.font.style= "UNDERLINE"; + style_params.underline = true; mMessage->appendText(p.message.substr(3), FALSE, style_params); } else diff --git a/indra/newview/llviewerchat.cpp b/indra/newview/llviewerchat.cpp index d65a060bbc..ccf9ce9056 100644 --- a/indra/newview/llviewerchat.cpp +++ b/indra/newview/llviewerchat.cpp @@ -201,3 +201,20 @@ S32 LLViewerChat::getChatFontSize() { return gSavedSettings.getS32("ChatFontSize"); } + + +//static +void LLViewerChat::formatChatMsg(const LLChat& chat, std::string& formated_msg) +{ + std::string tmpmsg = chat.mText; + + if(chat.mChatStyle == CHAT_STYLE_IRC) + { + formated_msg = chat.mFromName + tmpmsg.substr(3); + } + else + { + formated_msg = tmpmsg; + } + +} \ No newline at end of file diff --git a/indra/newview/llviewerchat.h b/indra/newview/llviewerchat.h index d8840d5dd2..502d6ea7e5 100644 --- a/indra/newview/llviewerchat.h +++ b/indra/newview/llviewerchat.h @@ -45,8 +45,7 @@ public: static void getChatColor(const LLChat& chat, std::string& r_color_name, F32& r_color_alpha); static LLFontGL* getChatFont(); static S32 getChatFontSize(); - - + static void formatChatMsg(const LLChat& chat, std::string& formated_msg); }; diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp index 0153116887..ef6a621323 100644 --- a/indra/newview/llviewermessage.cpp +++ b/indra/newview/llviewermessage.cpp @@ -2343,14 +2343,14 @@ void process_chat_from_simulator(LLMessageSystem *msg, void **user_data) std::string prefix = mesg.substr(0, 4); if (prefix == "/me " || prefix == "/me'") { - chat.mText = from_name; - chat.mText += mesg.substr(3); +// chat.mText = from_name; +// chat.mText += mesg.substr(3); ircstyle = TRUE; } - else - { +// else +// { chat.mText = mesg; - } +// } // Look for the start of typing so we can put "..." in the bubbles. if (CHAT_TYPE_START == chat.mChatType) @@ -2376,19 +2376,6 @@ void process_chat_from_simulator(LLMessageSystem *msg, void **user_data) return; } - // We have a real utterance now, so can stop showing "..." and proceed. - if (chatter && chatter->isAvatar()) - { - LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE); - ((LLVOAvatar*)chatter)->stopTyping(); - - if (!is_muted && !is_busy) - { - visible_in_chat_bubble = gSavedSettings.getBOOL("UseChatBubbles"); - ((LLVOAvatar*)chatter)->addChat(chat); - } - } - // Look for IRC-style emotes if (ircstyle) { @@ -2428,6 +2415,23 @@ void process_chat_from_simulator(LLMessageSystem *msg, void **user_data) chat.mText += mesg; } + // We have a real utterance now, so can stop showing "..." and proceed. + if (chatter && chatter->isAvatar()) + { + LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE); + ((LLVOAvatar*)chatter)->stopTyping(); + + if (!is_muted && !is_busy) + { + visible_in_chat_bubble = gSavedSettings.getBOOL("UseChatBubbles"); + std::string formated_msg = ""; + LLViewerChat::formatChatMsg(chat, formated_msg); + LLChat chat_bubble = chat; + chat_bubble.mText = formated_msg; + ((LLVOAvatar*)chatter)->addChat(chat_bubble); + } + } + if (chatter) { chat.mPosAgent = chatter->getPositionAgent(); -- cgit v1.2.3