From 0fbdd7d10de8fa253cb008504e9e8dc44ed16b29 Mon Sep 17 00:00:00 2001 From: elektrahesse Date: Thu, 9 Sep 2010 18:48:15 +0200 Subject: Fixed chat colors and added group im colors --- linden/indra/llwindow/llwindowmacosx-objc.h | 1 - linden/indra/llwindow/llwindowmacosx-objc.mm | 1 - linden/indra/newview/app_settings/settings.xml | 11 +++ linden/indra/newview/llfloaterchat.cpp | 91 +++++++++++++++------- linden/indra/newview/llfloaterchat.h | 2 + linden/indra/newview/llimview.cpp | 38 ++++++++- linden/indra/newview/llprefsadvanced.cpp | 2 + .../xui/en-us/panel_preferences_advanced.xml | 6 +- 8 files changed, 117 insertions(+), 35 deletions(-) (limited to 'linden/indra') diff --git a/linden/indra/llwindow/llwindowmacosx-objc.h b/linden/indra/llwindow/llwindowmacosx-objc.h index ed5d7b1..14cddaa 100644 --- a/linden/indra/llwindow/llwindowmacosx-objc.h +++ b/linden/indra/llwindow/llwindowmacosx-objc.h @@ -40,4 +40,3 @@ void setupCocoa(); CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY); OSErr releaseImageCursor(CursorRef ref); OSErr setImageCursor(CursorRef ref); - diff --git a/linden/indra/llwindow/llwindowmacosx-objc.mm b/linden/indra/llwindow/llwindowmacosx-objc.mm index da01c2a..bc47164 100644 --- a/linden/indra/llwindow/llwindowmacosx-objc.mm +++ b/linden/indra/llwindow/llwindowmacosx-objc.mm @@ -116,4 +116,3 @@ OSErr setImageCursor(CursorRef ref) return noErr; } - diff --git a/linden/indra/newview/app_settings/settings.xml b/linden/indra/newview/app_settings/settings.xml index a459623..75f37df 100644 --- a/linden/indra/newview/app_settings/settings.xml +++ b/linden/indra/newview/app_settings/settings.xml @@ -4,6 +4,17 @@ + HighlightOwnNameInIM + + Comment + Show GroupIM messages containing your name in a different color + Persist + 1 + Type + Boolean + Value + 1 + HighlightFriendsChat Comment diff --git a/linden/indra/newview/llfloaterchat.cpp b/linden/indra/newview/llfloaterchat.cpp index a38684a..d7465fa 100644 --- a/linden/indra/newview/llfloaterchat.cpp +++ b/linden/indra/newview/llfloaterchat.cpp @@ -78,6 +78,8 @@ #include "llstylemap.h" #include "llviewermenu.h" +#include "regex.h" + // Used for LCD display extern void AddNewIMToLCD(const std::string &newLine); extern void AddNewChatToLCD(const std::string &newLine); @@ -383,7 +385,6 @@ void LLFloaterChat::setHistoryCursorAndScrollToEnd() } } - //static void LLFloaterChat::onClickMute(void *data) { @@ -452,6 +453,65 @@ void LLFloaterChat::updateSettings() LLFloaterChat::getInstance(LLSD())->getChild("translate chat")->set(translate_chat); } +BOOL LLFloaterChat::isOwnNameInText(const std::string &text_line) +{ + std::string my_name = gSavedSettings.getString("FirstName"); + + std::transform(my_name.begin(), my_name.end(), my_name.begin(), tolower); + + std::string lower_chat = std::string(text_line); + std::transform(lower_chat.begin(), lower_chat.end(), lower_chat.begin(), tolower); + + std::string blank = " "; + + // yes yes, this sucks, will move to a nicer regexp as soon as i have time to make it lol + if (lower_chat.find(my_name + blank) == 0 || // at the beginning of the text + (lower_chat.find(my_name) == 0 && lower_chat.length() == my_name.length()) || // only my name in the text + lower_chat.find(blank + my_name + blank) != std::string::npos || // my name in the middle of the text + lower_chat.rfind(blank + my_name) == lower_chat.length() - (blank + my_name).length()) // my name at the end of the text + { + return TRUE; + } + +/* + regex_t compiled; + // ^.*([\.\?!:;\*\(\s]+)(elektra)([,\.\?!:;\*\)\s$]+).* <--- this works :) + std::string pre_pattern = "^.*([\\.\\?!:;\\*\\(\\s]+)("; + std::string post_pattern = ")([,\\.\\?!:;\\*\\)\\s$]+).*"; + std::string pattern_s = pre_pattern + my_name + post_pattern; + regcomp(&compiled, pattern_s.c_str(), REG_ICASE); + + if (regexec(&compiled, text_line.c_str(), 0, NULL, 0) == 0) + return TRUE; +*/ + return FALSE; +} + +LLColor4 get_extended_text_color(const LLChat& chat, LLColor4 defaultColor) +{ + if (gSavedSettings.getBOOL("HighlightOwnNameInChat")) + { + std::string new_line = std::string(chat.mText); + int name_pos = new_line.find(chat.mFromName); + if (name_pos == 0) + { + new_line = new_line.substr(chat.mFromName.length()); + if (new_line.find(": ") == 0) + new_line = new_line.substr(2); + else + new_line = new_line.substr(1); + } + + if (LLFloaterChat::isOwnNameInText(new_line)) + return gSavedSettings.getColor4("OwnNameChatColor"); + } + + if (gSavedSettings.getBOOL("HighlightFriendsChat") && is_agent_friend(chat.mFromID)) + return gSavedSettings.getColor4("FriendsChatColor"); + + return defaultColor; +} + // Put a line of chat in all the right places void LLFloaterChat::addChat(const LLChat& chat, BOOL from_instant_message, @@ -565,34 +625,7 @@ LLColor4 get_text_color(const LLChat& chat) } else { - if (gSavedSettings.getBOOL("HighlightOwnNameInChat")) - { - std::string my_name = gSavedSettings.getString("FirstName"); - std::transform(my_name.begin(), my_name.end(), my_name.begin(), tolower); - - std::string lower_chat = std::string(chat.mText); - std::transform(lower_chat.begin(), lower_chat.end(), lower_chat.begin(), tolower); - - std::string blank = " "; - - // yes yes, this sucks, will move to a nicer regexp as soon as i have time to make it lol - if (lower_chat.find(my_name + blank) == 0 || // at the beginning of the text - (lower_chat.find(my_name) == 0 && lower_chat.length() == my_name.length()) || // only my name in the text - lower_chat.find(blank + my_name + blank) != std::string::npos || // my name in the middle of the text - lower_chat.rfind(blank + my_name) == lower_chat.length() - (blank + my_name).length()) // my name at the end of the text - { - text_color = gSavedSettings.getColor4("OwnNameChatColor"); - break; - } - } - - if (gSavedSettings.getBOOL("HighlightFriendsChat") && is_agent_friend(chat.mFromID)) - { - text_color = gSavedSettings.getColor4("FriendsChatColor"); - break; - } - - text_color = gSavedSettings.getColor4("AgentChatColor"); + text_color = get_extended_text_color(chat, gSavedSettings.getColor4("AgentChatColor")); } } } diff --git a/linden/indra/newview/llfloaterchat.h b/linden/indra/newview/llfloaterchat.h index f894675..5a26567 100644 --- a/linden/indra/newview/llfloaterchat.h +++ b/linden/indra/newview/llfloaterchat.h @@ -40,6 +40,7 @@ #include "llfloater.h" #include "lllogchat.h" + class LLButton; class LLChat; class LLComboBox; @@ -72,6 +73,7 @@ public: // Add chat to console and history list. // Color based on source, type, distance. static void addChat(const LLChat& chat, BOOL from_im = FALSE, BOOL local_agent = FALSE); + static BOOL isOwnNameInText(const std::string &text_line); // Add chat to history alone. static void addChatHistory(const LLChat& chat, bool log_to_file = true); diff --git a/linden/indra/newview/llimview.cpp b/linden/indra/newview/llimview.cpp index e3ec5e6..b5b1df2 100644 --- a/linden/indra/newview/llimview.cpp +++ b/linden/indra/newview/llimview.cpp @@ -544,6 +544,26 @@ LLIMMgr::~LLIMMgr() // Children all cleaned up by default view destructor. } +LLColor4 get_extended_text_color(const LLUUID session_id, const LLUUID other_partecipant_id, const std::string& msg, LLColor4 defaultColor) +{ + if (gSavedSettings.getBOOL("HighlightOwnNameInIM") && (other_partecipant_id != LLUUID::null)) + { + LLDynamicArray::iterator i; + for (i = gAgent.mGroups.begin(); i != gAgent.mGroups.end(); i++) + { + if (i->mID == session_id) + { + if (LLFloaterChat::isOwnNameInText(msg)) + return gSavedSettings.getColor4("OwnNameChatColor"); + else + break; + } + } + } + + return defaultColor; +} + // Add a message to a session. void LLIMMgr::addMessage( const LLUUID& session_id, @@ -660,9 +680,21 @@ void LLIMMgr::addMessage( // now add message to floater bool is_from_system = target_id.isNull() || (from == SYSTEM_FROM); - const LLColor4& color = ( is_from_system ? - gSavedSettings.getColor4("SystemChatColor") : - gSavedSettings.getColor("IMChatColor")); + + LLColor4 color; + if (is_from_system) + color = gSavedSettings.getColor4("SystemChatColor"); + else + { + std::string new_line = std::string(msg); + if (new_line.find(": ") == 0) + new_line = new_line.substr(2); + else + new_line = new_line.substr(1); + + color = get_extended_text_color(session_id, other_participant_id, msg, gSavedSettings.getColor("IMChatColor")); + } + if ( !link_name ) { floater->addHistoryLine(msg,color); // No name to prepend, so just add the message normally diff --git a/linden/indra/newview/llprefsadvanced.cpp b/linden/indra/newview/llprefsadvanced.cpp index 695e604..898ba2c 100644 --- a/linden/indra/newview/llprefsadvanced.cpp +++ b/linden/indra/newview/llprefsadvanced.cpp @@ -112,6 +112,7 @@ BOOL LLPrefsAdvanced::postBuild() initHelpBtn("EmeraldHelp_SpellCheck", "EmeraldHelp_SpellCheck"); + childSetValue("HighlightOwnNameInIM", gSavedSettings.getBOOL("HighlightOwnNameInIM")); childSetValue("HighlightFriendsChat", gSavedSettings.getBOOL("HighlightFriendsChat")); getChild("FriendsChatColor")->set(gSavedSettings.getColor4("FriendsChatColor")); childSetValue("HighlightOwnNameInChat", gSavedSettings.getBOOL("HighlightOwnNameInChat")); @@ -139,6 +140,7 @@ void LLPrefsAdvanced::apply() gSavedSettings.setU32("LightShareAllowed", (U32)childGetValue("lightshare_combo").asInteger()); + gSavedSettings.setBOOL("HighlightOwnNameInIM", childGetValue("HighlightOwnNameInIM")); gSavedSettings.setBOOL("HighlightFriendsChat", childGetValue("HighlightFriendsChat")); gSavedSettings.setColor4("FriendsChatColor", getChild("FriendsChatColor")->get()); gSavedSettings.setBOOL("HighlightOwnNameInChat", childGetValue("HighlightOwnNameInChat")); diff --git a/linden/indra/newview/skins/default/xui/en-us/panel_preferences_advanced.xml b/linden/indra/newview/skins/default/xui/en-us/panel_preferences_advanced.xml index 65d118d..b344d14 100644 --- a/linden/indra/newview/skins/default/xui/en-us/panel_preferences_advanced.xml +++ b/linden/indra/newview/skins/default/xui/en-us/panel_preferences_advanced.xml @@ -190,7 +190,11 @@ label="Show chat messages containing your name in a different color" left="12" mouse_opaque="true" name="HighlightOwnNameInChat" radio_style="false" width="217" /> - + + -- cgit v1.1