/indra/newview/llviewerchat.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 284 lines · 215 code · 30 blank · 39 comment · 39 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. #include "llviewerprecompiledheaders.h"
  27. #include "llviewerchat.h"
  28. // newview includes
  29. #include "llagent.h" // gAgent
  30. #include "llslurl.h"
  31. #include "lluicolor.h"
  32. #include "lluicolortable.h"
  33. #include "llviewercontrol.h" // gSavedSettings
  34. #include "llviewerregion.h"
  35. #include "llworld.h"
  36. #include "llinstantmessage.h" //SYSTEM_FROM
  37. // LLViewerChat
  38. LLViewerChat::font_change_signal_t LLViewerChat::sChatFontChangedSignal;
  39. //static
  40. void LLViewerChat::getChatColor(const LLChat& chat, LLColor4& r_color)
  41. {
  42. if(chat.mMuted)
  43. {
  44. r_color= LLUIColorTable::instance().getColor("LtGray");
  45. }
  46. else
  47. {
  48. switch(chat.mSourceType)
  49. {
  50. case CHAT_SOURCE_SYSTEM:
  51. r_color = LLUIColorTable::instance().getColor("SystemChatColor");
  52. break;
  53. case CHAT_SOURCE_AGENT:
  54. if (chat.mFromID.isNull() || SYSTEM_FROM == chat.mFromName)
  55. {
  56. r_color = LLUIColorTable::instance().getColor("SystemChatColor");
  57. }
  58. else
  59. {
  60. if(gAgentID == chat.mFromID)
  61. {
  62. r_color = LLUIColorTable::instance().getColor("UserChatColor");
  63. }
  64. else
  65. {
  66. r_color = LLUIColorTable::instance().getColor("AgentChatColor");
  67. }
  68. }
  69. break;
  70. case CHAT_SOURCE_OBJECT:
  71. if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
  72. {
  73. r_color = LLUIColorTable::instance().getColor("ScriptErrorColor");
  74. }
  75. else if ( chat.mChatType == CHAT_TYPE_OWNER )
  76. {
  77. r_color = LLUIColorTable::instance().getColor("llOwnerSayChatColor");
  78. }
  79. else if ( chat.mChatType == CHAT_TYPE_DIRECT )
  80. {
  81. r_color = LLUIColorTable::instance().getColor("DirectChatColor");
  82. }
  83. else
  84. {
  85. r_color = LLUIColorTable::instance().getColor("ObjectChatColor");
  86. }
  87. break;
  88. default:
  89. r_color.setToWhite();
  90. }
  91. if (!chat.mPosAgent.isExactlyZero())
  92. {
  93. LLVector3 pos_agent = gAgent.getPositionAgent();
  94. F32 distance_squared = dist_vec_squared(pos_agent, chat.mPosAgent);
  95. F32 dist_near_chat = gAgent.getNearChatRadius();
  96. if (distance_squared > dist_near_chat * dist_near_chat)
  97. {
  98. // diminish far-off chat
  99. r_color.mV[VALPHA] = 0.8f;
  100. }
  101. }
  102. }
  103. }
  104. //static
  105. void LLViewerChat::getChatColor(const LLChat& chat, std::string& r_color_name, F32& r_color_alpha)
  106. {
  107. if(chat.mMuted)
  108. {
  109. r_color_name = "LtGray";
  110. }
  111. else
  112. {
  113. switch(chat.mSourceType)
  114. {
  115. case CHAT_SOURCE_SYSTEM:
  116. r_color_name = "SystemChatColor";
  117. break;
  118. case CHAT_SOURCE_AGENT:
  119. if (chat.mFromID.isNull())
  120. {
  121. r_color_name = "SystemChatColor";
  122. }
  123. else
  124. {
  125. if(gAgentID == chat.mFromID)
  126. {
  127. r_color_name = "UserChatColor";
  128. }
  129. else
  130. {
  131. r_color_name = "AgentChatColor";
  132. }
  133. }
  134. break;
  135. case CHAT_SOURCE_OBJECT:
  136. if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
  137. {
  138. r_color_name = "ScriptErrorColor";
  139. }
  140. else if ( chat.mChatType == CHAT_TYPE_OWNER )
  141. {
  142. r_color_name = "llOwnerSayChatColor";
  143. }
  144. else if ( chat.mChatType == CHAT_TYPE_DIRECT )
  145. {
  146. r_color_name = "DirectChatColor";
  147. }
  148. else
  149. {
  150. r_color_name = "ObjectChatColor";
  151. }
  152. break;
  153. default:
  154. r_color_name = "White";
  155. }
  156. if (!chat.mPosAgent.isExactlyZero())
  157. {
  158. LLVector3 pos_agent = gAgent.getPositionAgent();
  159. F32 distance_squared = dist_vec_squared(pos_agent, chat.mPosAgent);
  160. F32 dist_near_chat = gAgent.getNearChatRadius();
  161. if (distance_squared > dist_near_chat * dist_near_chat)
  162. {
  163. // diminish far-off chat
  164. r_color_alpha = 0.8f;
  165. }
  166. else
  167. {
  168. r_color_alpha = 1.0f;
  169. }
  170. }
  171. }
  172. }
  173. //static
  174. LLFontGL* LLViewerChat::getChatFont()
  175. {
  176. S32 font_size = gSavedSettings.getS32("ChatFontSize");
  177. LLFontGL* fontp = NULL;
  178. switch(font_size)
  179. {
  180. case 0:
  181. fontp = LLFontGL::getFontSansSerifSmall();
  182. break;
  183. default:
  184. case 1:
  185. fontp = LLFontGL::getFontSansSerif();
  186. break;
  187. case 2:
  188. fontp = LLFontGL::getFontSansSerifBig();
  189. break;
  190. }
  191. return fontp;
  192. }
  193. //static
  194. S32 LLViewerChat::getChatFontSize()
  195. {
  196. return gSavedSettings.getS32("ChatFontSize");
  197. }
  198. //static
  199. void LLViewerChat::formatChatMsg(const LLChat& chat, std::string& formated_msg)
  200. {
  201. std::string tmpmsg = chat.mText;
  202. if(chat.mChatStyle == CHAT_STYLE_IRC)
  203. {
  204. formated_msg = chat.mFromName + tmpmsg.substr(3);
  205. }
  206. else
  207. {
  208. formated_msg = tmpmsg;
  209. }
  210. }
  211. //static
  212. std::string LLViewerChat::getSenderSLURL(const LLChat& chat, const LLSD& args)
  213. {
  214. switch (chat.mSourceType)
  215. {
  216. case CHAT_SOURCE_AGENT:
  217. return LLSLURL("agent", chat.mFromID, "about").getSLURLString();
  218. case CHAT_SOURCE_OBJECT:
  219. return getObjectImSLURL(chat, args);
  220. default:
  221. llwarns << "Getting SLURL for an unsupported sender type: " << chat.mSourceType << llendl;
  222. }
  223. return LLStringUtil::null;
  224. }
  225. //static
  226. std::string LLViewerChat::getObjectImSLURL(const LLChat& chat, const LLSD& args)
  227. {
  228. std::string url = LLSLURL("objectim", chat.mFromID, "").getSLURLString();
  229. url += "?name=" + chat.mFromName;
  230. url += "&owner=" + chat.mOwnerID.asString();
  231. std::string slurl = args["slurl"].asString();
  232. if (slurl.empty())
  233. {
  234. LLViewerRegion *region = LLWorld::getInstance()->getRegionFromPosAgent(chat.mPosAgent);
  235. if(region)
  236. {
  237. LLSLURL region_slurl(region->getName(), chat.mPosAgent);
  238. slurl = region_slurl.getLocationString();
  239. }
  240. }
  241. url += "&slurl=" + LLURI::escape(slurl);
  242. return url;
  243. }
  244. //static
  245. boost::signals2::connection LLViewerChat::setFontChangedCallback(const font_change_signal_t::slot_type& cb)
  246. {
  247. return sChatFontChangedSignal.connect(cb);
  248. }
  249. //static
  250. void LLViewerChat::signalChatFontChanged()
  251. {
  252. // Notify all observers that our font has changed
  253. sChatFontChangedSignal(getChatFont());
  254. }