From 0cc5484b60b4348e5a6a204ca247ff0175757033 Mon Sep 17 00:00:00 2001 From: Inusaito Sayori Date: Thu, 10 Oct 2013 03:35:54 -0400 Subject: [PATCH] [LLIMMgr/LLIMPanel Revision] Add convert_roleplay_text() to centralize roleplay chat preprocessing Unifies CAPSLock /ME handling Unifies AutoCloseOOC impls so they share full common functionality Adds AutoCloseOOC functionality to do /me ((autocompleted out of character action)) Also, RP Mode now uses parentheses rather than square brackets, by popular demand --- indra/newview/llchatbar.cpp | 105 ++++++++++++++++++++---------------- indra/newview/llimpanel.cpp | 59 +++----------------- 2 files changed, 66 insertions(+), 98 deletions(-) diff --git a/indra/newview/llchatbar.cpp b/indra/newview/llchatbar.cpp index 95e39ee89..9a31e0d6f 100644 --- a/indra/newview/llchatbar.cpp +++ b/indra/newview/llchatbar.cpp @@ -404,6 +404,63 @@ LLWString LLChatBar::stripChannelNumber(const LLWString &mesg, S32* channel) } } +// Returns whether or not this is an action +bool convert_roleplay_text(std::string& utf8text) +{ + bool action(true); // Using /me with autoclose /me ((does something ooc)) + // Allow CAPSlock /me here + if (utf8text.find("/ME'") == 0 || utf8text.find("/ME ") == 0) + { + utf8text.replace(1, 2, "me"); + } + // Convert MU*s style poses into IRC emotes here. + else if (gSavedSettings.getBOOL("AscentAllowMUpose") && utf8text.length() > 3 && utf8text.find(":") == 0) + { + if (utf8text[1] == '\'') + utf8text.replace(0, 1, "/me"); + else if (isalpha(utf8text[1])) // Do not prevent smileys and such. + utf8text.replace(0, 1, "/me "); + else + action = false; + } + else if (utf8text.find("/me'") != 0 && utf8text.find("/me ") != 0) + { + action = false; + } + + if (gSavedSettings.getBOOL("AscentAutoCloseOOC") && (utf8text.length() > 3)) + { + const U32 pos(action ? 4 : 0); + //Check if it needs the end-of-chat brackets -HgB + if (utf8text.find("((") == pos && utf8text.find("))") == std::string::npos) + { + if (*utf8text.rbegin() == ')') + utf8text += " "; + utf8text += "))"; + } + else if (utf8text.find("[[") == pos && utf8text.find("]]") == std::string::npos) + { + if (*utf8text.rbegin() == ']') + utf8text += " "; + utf8text += "]]"; + } + // Check if it needs start-of-chat brackets + else if (utf8text.find("((") == std::string::npos && utf8text.find("))") == (utf8text.length() - 2)) + { + if (utf8text.at(pos) == '(') + utf8text.insert(pos, " "); + utf8text.insert(pos, "(("); + } + else if (utf8text.find("[[") == std::string::npos && utf8text.find("]]") == (utf8text.length() - 2)) + { + if (utf8text.at(pos) == '[') + utf8text.insert(pos, " "); + utf8text.insert(pos, "[["); + } + } + return action; +} + // void LLChatBar::sendChat( EChatType type ) { @@ -423,47 +480,7 @@ void LLChatBar::sendChat( EChatType type ) std::string utf8_revised_text; if (0 == channel) { - if (gSavedSettings.getBOOL("AscentAutoCloseOOC") && (utf8text.length() > 1)) - { - //Check if it needs the end-of-chat brackets -HgB - if (utf8text.find("((") == 0 && utf8text.find("))") == -1) - { - if(utf8text.at(utf8text.length() - 1) == ')') - utf8text+=" "; - utf8text+="))"; - } - else if(utf8text.find("[[") == 0 && utf8text.find("]]") == -1) - { - if(utf8text.at(utf8text.length() - 1) == ']') - utf8text+=" "; - utf8text+="]]"; - } - - if (utf8text.find("((") == -1 && utf8text.find("))") == (utf8text.length() - 2)) - { - if(utf8text.at(0) == '(') - utf8text.insert(0," "); - utf8text.insert(0,"(("); - } - else if (utf8text.find("[[") == -1 && utf8text.find("]]") == (utf8text.length() - 2)) - { - if(utf8text.at(0) == '[') - utf8text.insert(0," "); - utf8text.insert(0,"[["); - } - } - // Convert MU*s style poses into IRC emotes here. - if (gSavedSettings.getBOOL("AscentAllowMUpose") && utf8text.find(":") == 0 && utf8text.length() > 3) - { - if (utf8text.find(":'") == 0) - { - utf8text.replace(0, 1, "/me"); - } - else if (isalpha(utf8text.at(1))) // Do not prevent smileys and such. - { - utf8text.replace(0, 1, "/me "); - } - } + convert_roleplay_text(utf8text); // discard returned "found" boolean LLGestureMgr::instance().triggerAndReviseString(utf8text, &utf8_revised_text); } @@ -473,11 +490,7 @@ void LLChatBar::sendChat( EChatType type ) } utf8_revised_text = utf8str_trim(utf8_revised_text); - EChatType nType; - if(type == CHAT_TYPE_OOC) - nType=CHAT_TYPE_NORMAL; - else - nType=type; + EChatType nType(type == CHAT_TYPE_OOC ? CHAT_TYPE_NORMAL : type); if (!utf8_revised_text.empty() && cmd_line_chat(utf8_revised_text, nType)) { // Chat with animation diff --git a/indra/newview/llimpanel.cpp b/indra/newview/llimpanel.cpp index 9e37cacc8..76943aba4 100644 --- a/indra/newview/llimpanel.cpp +++ b/indra/newview/llimpanel.cpp @@ -1176,6 +1176,8 @@ void deliver_message(const std::string& utf8_text, } } +bool convert_roleplay_text(std::string& text); // Returns true if text is an action + void LLFloaterIMPanel::onSendMsg() { if (!gAgent.isGodlike() @@ -1195,55 +1197,9 @@ void LLFloaterIMPanel::onSendMsg() if (mInputEditor) mInputEditor->updateHistory(); // Truncate and convert to UTF8 for transport std::string utf8_text = wstring_to_utf8str(text); - // Convert MU*s style poses into IRC emotes here. - if (gSavedSettings.getBOOL("AscentAllowMUpose") && utf8_text.length() > 3 && utf8_text[0] == ':') - { - if (utf8_text[1] == '\'') - { - utf8_text.replace(0, 1, "/me"); - } - else if (isalpha(utf8_text[1])) // Do not prevent smileys and such. - { - utf8_text.replace(0, 1, "/me "); - } - } - if (utf8_text.find("/ME'") == 0 || utf8_text.find("/ME ") == 0) //Allow CAPSlock /me - utf8_text.replace(1, 2, "me"); - std::string prefix = utf8_text.substr(0, 4); - if (gSavedSettings.getBOOL("AscentAutoCloseOOC") && (utf8_text.length() > 1) && !mRPMode) - { - //Check if it needs the end-of-chat brackets -HgB - if (utf8_text.find("((") == 0 && utf8_text.find("))") == std::string::npos) - { - if(*utf8_text.rbegin() == ')') - utf8_text+=" "; - utf8_text+="))"; - } - else if(utf8_text.find("[[") == 0 && utf8_text.find("]]") == std::string::npos) - { - if(*utf8_text.rbegin() == ']') - utf8_text+=" "; - utf8_text+="]]"; - } - - if (prefix != "/me " && prefix != "/me'") //Allow /me to end with )) or ]] - { - if (utf8_text.find("((") == std::string::npos && utf8_text.find("))") == (utf8_text.length() - 2)) - { - if(utf8_text[0] == '(') - utf8_text.insert(0," "); - utf8_text.insert(0,"(("); - } - else if (utf8_text.find("[[") == std::string::npos && utf8_text.find("]]") == (utf8_text.length() - 2)) - { - if(utf8_text[0] == '[') - utf8_text.insert(0," "); - utf8_text.insert(0,"[["); - } - } - } - if (mRPMode && prefix != "/me " && prefix != "/me'") - utf8_text = "[[" + utf8_text + "]]"; + bool action = convert_roleplay_text(utf8_text); + if (!action && mRPMode) + utf8_text = "((" + utf8_text + "))"; // [RLVa:KB] - Checked: 2011-09-17 (RLVa-1.1.4b) | Modified: RLVa-1.1.4b if ( (gRlvHandler.hasBehaviour(RLV_BHVR_SENDIM)) || (gRlvHandler.hasBehaviour(RLV_BHVR_SENDIMTO)) ) { @@ -1344,9 +1300,8 @@ LL_WARNS("Splitting") << "Pos: " << pos << " next_split: " << next_split << LL_E std::string name; gAgent.buildFullname(name); - // Look for IRC-style emotes here. - std::string prefix = utf8_text.substr(0, 4); - if (prefix == "/me " || prefix == "/me'") + // Look for actions here. + if (action) { utf8_text.replace(0,3,""); }