PageRenderTime 25ms CodeModel.GetById 9ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llviewerchat.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 284 lines | 215 code | 30 blank | 39 comment | 36 complexity | 100ecddb9e83c6d4442e995f4bf335fa MD5 | raw file
  1/** 
  2 * @file llviewerchat.cpp
  3 * @brief Builds menus out of items.
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28#include "llviewerchat.h" 
 29
 30// newview includes
 31#include "llagent.h" 	// gAgent		
 32#include "llslurl.h"
 33#include "lluicolor.h"
 34#include "lluicolortable.h"
 35#include "llviewercontrol.h" // gSavedSettings
 36#include "llviewerregion.h"
 37#include "llworld.h"
 38#include "llinstantmessage.h" //SYSTEM_FROM
 39
 40// LLViewerChat
 41LLViewerChat::font_change_signal_t LLViewerChat::sChatFontChangedSignal;
 42
 43//static 
 44void LLViewerChat::getChatColor(const LLChat& chat, LLColor4& r_color)
 45{
 46	if(chat.mMuted)
 47	{
 48		r_color= LLUIColorTable::instance().getColor("LtGray");
 49	}
 50	else
 51	{
 52		switch(chat.mSourceType)
 53		{
 54			case CHAT_SOURCE_SYSTEM:
 55				r_color = LLUIColorTable::instance().getColor("SystemChatColor"); 
 56				break;
 57			case CHAT_SOURCE_AGENT:
 58				if (chat.mFromID.isNull() || SYSTEM_FROM == chat.mFromName)
 59				{
 60					r_color = LLUIColorTable::instance().getColor("SystemChatColor");
 61				}
 62				else
 63				{
 64					if(gAgentID == chat.mFromID)
 65					{
 66						r_color = LLUIColorTable::instance().getColor("UserChatColor");
 67					}
 68					else
 69					{
 70						r_color = LLUIColorTable::instance().getColor("AgentChatColor");
 71					}
 72				}
 73				break;
 74			case CHAT_SOURCE_OBJECT:
 75				if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
 76				{
 77					r_color = LLUIColorTable::instance().getColor("ScriptErrorColor");
 78				}
 79				else if ( chat.mChatType == CHAT_TYPE_OWNER )
 80				{
 81					r_color = LLUIColorTable::instance().getColor("llOwnerSayChatColor");
 82				}
 83				else if ( chat.mChatType == CHAT_TYPE_DIRECT )
 84				{
 85					r_color = LLUIColorTable::instance().getColor("DirectChatColor");
 86				}
 87				else
 88				{
 89					r_color = LLUIColorTable::instance().getColor("ObjectChatColor");
 90				}
 91				break;
 92			default:
 93				r_color.setToWhite();
 94		}
 95		
 96		if (!chat.mPosAgent.isExactlyZero())
 97		{
 98			LLVector3 pos_agent = gAgent.getPositionAgent();
 99			F32 distance_squared = dist_vec_squared(pos_agent, chat.mPosAgent);
100			F32 dist_near_chat = gAgent.getNearChatRadius();
101			if (distance_squared > dist_near_chat * dist_near_chat)
102			{
103				// diminish far-off chat
104				r_color.mV[VALPHA] = 0.8f;
105			}
106		}
107	}
108}
109
110
111//static 
112void LLViewerChat::getChatColor(const LLChat& chat, std::string& r_color_name, F32& r_color_alpha)
113{
114	if(chat.mMuted)
115	{
116		r_color_name = "LtGray";
117	}
118	else
119	{
120		switch(chat.mSourceType)
121		{
122			case CHAT_SOURCE_SYSTEM:
123				r_color_name = "SystemChatColor";
124				break;
125				
126			case CHAT_SOURCE_AGENT:
127				if (chat.mFromID.isNull())
128				{
129					r_color_name = "SystemChatColor";
130				}
131				else
132				{
133					if(gAgentID == chat.mFromID)
134					{
135						r_color_name = "UserChatColor";
136					}
137					else
138					{
139						r_color_name = "AgentChatColor";
140					}
141				}
142				break;
143				
144			case CHAT_SOURCE_OBJECT:
145				if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
146				{
147					r_color_name = "ScriptErrorColor";
148				}
149				else if ( chat.mChatType == CHAT_TYPE_OWNER )
150				{
151					r_color_name = "llOwnerSayChatColor";
152				}
153				else if ( chat.mChatType == CHAT_TYPE_DIRECT )
154				{
155					r_color_name = "DirectChatColor";
156				}
157				else
158				{
159					r_color_name = "ObjectChatColor";
160				}
161				break;
162			default:
163				r_color_name = "White";
164		}
165		
166		if (!chat.mPosAgent.isExactlyZero())
167		{
168			LLVector3 pos_agent = gAgent.getPositionAgent();
169			F32 distance_squared = dist_vec_squared(pos_agent, chat.mPosAgent);
170			F32 dist_near_chat = gAgent.getNearChatRadius();
171			if (distance_squared > dist_near_chat * dist_near_chat)
172			{
173				// diminish far-off chat
174				r_color_alpha = 0.8f; 
175			}
176			else
177			{
178				r_color_alpha = 1.0f;
179			}
180		}
181	}
182	
183}
184
185
186//static 
187LLFontGL* LLViewerChat::getChatFont()
188{
189	S32 font_size = gSavedSettings.getS32("ChatFontSize");
190	LLFontGL* fontp = NULL;
191	switch(font_size)
192	{
193		case 0:
194			fontp = LLFontGL::getFontSansSerifSmall();
195			break;
196		default:
197		case 1:
198			fontp = LLFontGL::getFontSansSerif();
199			break;
200		case 2:
201			fontp = LLFontGL::getFontSansSerifBig();
202			break;
203	}
204	
205	return fontp;
206	
207}
208
209//static
210S32 LLViewerChat::getChatFontSize()
211{
212	return gSavedSettings.getS32("ChatFontSize");
213}
214
215
216//static
217void LLViewerChat::formatChatMsg(const LLChat& chat, std::string& formated_msg)
218{
219	std::string tmpmsg = chat.mText;
220	
221	if(chat.mChatStyle == CHAT_STYLE_IRC)
222	{
223		formated_msg = chat.mFromName + tmpmsg.substr(3);
224	}
225	else 
226	{
227		formated_msg = tmpmsg;
228	}
229
230}
231
232//static
233std::string LLViewerChat::getSenderSLURL(const LLChat& chat, const LLSD& args)
234{
235	switch (chat.mSourceType)
236	{
237	case CHAT_SOURCE_AGENT:
238		return LLSLURL("agent", chat.mFromID, "about").getSLURLString();
239
240	case CHAT_SOURCE_OBJECT:
241		return getObjectImSLURL(chat, args);
242
243	default:
244		llwarns << "Getting SLURL for an unsupported sender type: " << chat.mSourceType << llendl;
245	}
246
247	return LLStringUtil::null;
248}
249
250//static
251std::string LLViewerChat::getObjectImSLURL(const LLChat& chat, const LLSD& args)
252{
253	std::string url = LLSLURL("objectim", chat.mFromID, "").getSLURLString();
254	url += "?name=" + chat.mFromName;
255	url += "&owner=" + chat.mOwnerID.asString();
256
257	std::string slurl = args["slurl"].asString();
258	if (slurl.empty())
259	{
260		LLViewerRegion *region = LLWorld::getInstance()->getRegionFromPosAgent(chat.mPosAgent);
261		if(region)
262		{
263			LLSLURL region_slurl(region->getName(), chat.mPosAgent);
264			slurl = region_slurl.getLocationString();
265		}
266	}
267
268	url += "&slurl=" + LLURI::escape(slurl);
269
270	return url;
271}
272
273//static 
274boost::signals2::connection LLViewerChat::setFontChangedCallback(const font_change_signal_t::slot_type& cb)
275{
276	return sChatFontChangedSignal.connect(cb);
277}
278
279//static
280void LLViewerChat::signalChatFontChanged()
281{
282	// Notify all observers that our font has changed
283	sChatFontChangedSignal(getChatFont());
284}