llnearbychat.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:8k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file LLNearbyChat.cpp
  3.  * @brief Nearby chat history scrolling panel implementation
  4.  *
  5.  * $LicenseInfo:firstyear=2009&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2009-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llnearbychat.h"
  34. #include "llviewercontrol.h"
  35. #include "llviewerwindow.h"
  36. #include "llrootview.h"
  37. //#include "llchatitemscontainerctrl.h"
  38. #include "lliconctrl.h"
  39. #include "llsidetray.h"
  40. #include "llfocusmgr.h"
  41. #include "llresizebar.h"
  42. #include "llresizehandle.h"
  43. #include "llmenugl.h"
  44. #include "llviewermenu.h"//for gMenuHolder
  45. #include "llnearbychathandler.h"
  46. #include "llchannelmanager.h"
  47. #include "llagent.h"  // gAgent
  48. #include "llfloaterscriptdebug.h"
  49. #include "llchathistory.h"
  50. #include "llstylemap.h"
  51. #include "lldraghandle.h"
  52. #include "llbottomtray.h"
  53. #include "llnearbychatbar.h"
  54. #include "llfloaterreg.h"
  55. #include "lltrans.h"
  56. static const S32 RESIZE_BAR_THICKNESS = 3;
  57. const static std::string IM_TIME("time");
  58. const static std::string IM_TEXT("message");
  59. const static std::string IM_FROM("from");
  60. const static std::string IM_FROM_ID("from_id");
  61. LLNearbyChat::LLNearbyChat(const LLSD& key) 
  62. : LLDockableFloater(NULL, false, false, key)
  63. ,mChatHistory(NULL)
  64. {
  65. }
  66. LLNearbyChat::~LLNearbyChat()
  67. {
  68. }
  69. BOOL LLNearbyChat::postBuild()
  70. {
  71. //menu
  72. LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
  73. LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
  74. enable_registrar.add("NearbyChat.Check", boost::bind(&LLNearbyChat::onNearbyChatCheckContextMenuItem, this, _2));
  75. registrar.add("NearbyChat.Action", boost::bind(&LLNearbyChat::onNearbyChatContextMenuItemClicked, this, _2));
  76. LLMenuGL* menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_nearby_chat.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
  77. if(menu)
  78. mPopupMenuHandle = menu->getHandle();
  79. gSavedSettings.declareS32("nearbychat_showicons_and_names",2,"NearByChat header settings",true);
  80. mChatHistory = getChild<LLChatHistory>("chat_history");
  81. if(!LLDockableFloater::postBuild())
  82. return false;
  83. if (getDockControl() == NULL)
  84. {
  85. setDockControl(new LLDockControl(
  86. LLBottomTray::getInstance()->getNearbyChatBar(), this,
  87. getDockTongue(), LLDockControl::TOP, boost::bind(&LLNearbyChat::getAllowedRect, this, _1)));
  88. }
  89. setIsChrome(true);
  90. //chrome="true" hides floater caption 
  91. if (mDragHandle)
  92. mDragHandle->setTitleVisible(TRUE);
  93. return true;
  94. }
  95. void    LLNearbyChat::applySavedVariables()
  96. {
  97. if (mRectControl.size() > 1)
  98. {
  99. const LLRect& rect = LLUI::sSettingGroups["floater"]->getRect(mRectControl);
  100. if(!rect.isEmpty() && rect.isValid())
  101. {
  102. reshape(rect.getWidth(), rect.getHeight());
  103. setRect(rect);
  104. }
  105. }
  106. if(!LLUI::sSettingGroups["floater"]->controlExists(mDocStateControl))
  107. {
  108. setDocked(true);
  109. }
  110. else
  111. {
  112. if (mDocStateControl.size() > 1)
  113. {
  114. bool dockState = LLUI::sSettingGroups["floater"]->getBOOL(mDocStateControl);
  115. setDocked(dockState);
  116. }
  117. }
  118. }
  119. std::string appendTime()
  120. {
  121. time_t utc_time;
  122. utc_time = time_corrected();
  123. std::string timeStr ="["+ LLTrans::getString("TimeHour")+"]:["
  124. +LLTrans::getString("TimeMin")+"]";
  125. LLSD substitution;
  126. substitution["datetime"] = (S32) utc_time;
  127. LLStringUtil::format (timeStr, substitution);
  128. return timeStr;
  129. }
  130. void LLNearbyChat::addMessage(const LLChat& chat,bool archive,const LLSD &args)
  131. {
  132. if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
  133. {
  134. if(gSavedSettings.getBOOL("ShowScriptErrors") == FALSE)
  135. return;
  136. if (gSavedSettings.getS32("ShowScriptErrorsLocation")== 1)// show error in window //("ScriptErrorsAsChat"))
  137. {
  138. LLColor4 txt_color;
  139. LLViewerChat::getChatColor(chat,txt_color);
  140. LLFloaterScriptDebug::addScriptLine(chat.mText,
  141. chat.mFromName, 
  142. txt_color, 
  143. chat.mFromID);
  144. return;
  145. }
  146. }
  147. LLChat& tmp_chat = const_cast<LLChat&>(chat);
  148. if(tmp_chat.mTimeStr.empty())
  149. tmp_chat.mTimeStr = appendTime();
  150. bool use_plain_text_chat_history = gSavedSettings.getBOOL("PlainTextChatHistory");
  151. if (!chat.mMuted)
  152. {
  153. tmp_chat.mFromName = chat.mFromName;
  154. LLSD chat_args = args;
  155. chat_args["use_plain_text_chat_history"] = use_plain_text_chat_history;
  156. mChatHistory->appendMessage(chat, chat_args);
  157. }
  158. if(archive)
  159. {
  160. mMessageArchive.push_back(chat);
  161. if(mMessageArchive.size()>200)
  162. mMessageArchive.erase(mMessageArchive.begin());
  163. }
  164. if (args["do_not_log"].asBoolean()) 
  165. {
  166. return;
  167. }
  168. if (gSavedPerAccountSettings.getBOOL("LogChat")) 
  169. {
  170. LLLogChat::saveHistory("chat", chat.mFromName, chat.mFromID, chat.mText);
  171. }
  172. }
  173. void LLNearbyChat::onNearbySpeakers()
  174. {
  175. LLSD param;
  176. param["people_panel_tab_name"] = "nearby_panel";
  177. LLSideTray::getInstance()->showPanel("panel_people",param);
  178. }
  179. void LLNearbyChat::onNearbyChatContextMenuItemClicked(const LLSD& userdata)
  180. {
  181. }
  182. bool LLNearbyChat::onNearbyChatCheckContextMenuItem(const LLSD& userdata)
  183. {
  184. std::string str = userdata.asString();
  185. if(str == "nearby_people")
  186. onNearbySpeakers();
  187. return false;
  188. }
  189. void LLNearbyChat::setVisible(BOOL visible)
  190. {
  191. if(visible)
  192. {
  193. LLNotificationsUI::LLScreenChannelBase* chat_channel = LLNotificationsUI::LLChannelManager::getInstance()->findChannelByID(LLUUID(gSavedSettings.getString("NearByChatChannelUUID")));
  194. if(chat_channel)
  195. {
  196. chat_channel->removeToastsFromChannel();
  197. }
  198. }
  199. LLDockableFloater::setVisible(visible);
  200. }
  201. void LLNearbyChat::onOpen(const LLSD& key )
  202. {
  203. LLDockableFloater::onOpen(key);
  204. }
  205. void LLNearbyChat::setRect (const LLRect &rect)
  206. {
  207. LLDockableFloater::setRect(rect);
  208. }
  209. void LLNearbyChat::getAllowedRect(LLRect& rect)
  210. {
  211. rect = gViewerWindow->getWorldViewRectScaled();
  212. }
  213. void LLNearbyChat::updateChatHistoryStyle()
  214. {
  215. mChatHistory->clear();
  216. for(std::vector<LLChat>::iterator it = mMessageArchive.begin();it!=mMessageArchive.end();++it)
  217. {
  218. addMessage(*it,false);
  219. }
  220. }
  221. //static 
  222. void LLNearbyChat::processChatHistoryStyleUpdate(const LLSD& newvalue)
  223. {
  224. LLNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLNearbyChat>("nearby_chat", LLSD());
  225. if(nearby_chat)
  226. nearby_chat->updateChatHistoryStyle();
  227. }
  228. void LLNearbyChat::loadHistory()
  229. {
  230. LLSD do_not_log;
  231. do_not_log["do_not_log"] = true;
  232. std::list<LLSD> history;
  233. LLLogChat::loadAllHistory("chat", history);
  234. std::list<LLSD>::const_iterator it = history.begin();
  235. while (it != history.end())
  236. {
  237. const LLSD& msg = *it;
  238. std::string from = msg[IM_FROM];
  239. LLUUID from_id = LLUUID::null;
  240. if (msg[IM_FROM_ID].isUndefined())
  241. {
  242. gCacheName->getUUID(from, from_id);
  243. }
  244. LLChat chat;
  245. chat.mFromName = from;
  246. chat.mFromID = from_id;
  247. chat.mText = msg[IM_TEXT].asString();
  248. chat.mTimeStr = msg[IM_TIME].asString();
  249. addMessage(chat, true, do_not_log);
  250. it++;
  251. }
  252. }
  253. //static
  254. LLNearbyChat* LLNearbyChat::getInstance()
  255. {
  256. return LLFloaterReg::getTypedInstance<LLNearbyChat>("nearby_chat", LLSD());
  257. }
  258. ////////////////////////////////////////////////////////////////////////////////
  259. //
  260. void LLNearbyChat::onFocusReceived()
  261. {
  262. setBackgroundOpaque(true);
  263. LLPanel::onFocusReceived();
  264. }
  265. ////////////////////////////////////////////////////////////////////////////////
  266. //
  267. void LLNearbyChat::onFocusLost()
  268. {
  269. setBackgroundOpaque(false);
  270. LLPanel::onFocusLost();
  271. }