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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloatertopobjects.cpp
  3.  * @brief Shows top colliders, top scripts, etc.
  4.  *
  5.  * $LicenseInfo:firstyear=2005&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2005-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 "llfloatertopobjects.h"
  34. #include "message.h"
  35. #include "llfontgl.h"
  36. #include "llagent.h"
  37. #include "llbutton.h"
  38. #include "llfloatergodtools.h"
  39. #include "llfloaterreg.h"
  40. #include "llnotificationsutil.h"
  41. #include "llparcel.h"
  42. #include "llscrolllistctrl.h"
  43. #include "llscrolllistitem.h"
  44. #include "llscrolllistcell.h"
  45. #include "lllineeditor.h"
  46. #include "lltextbox.h"
  47. #include "lltracker.h"
  48. #include "llviewermessage.h"
  49. #include "llviewerparcelmgr.h"
  50. #include "llviewerregion.h"
  51. #include "lluictrlfactory.h"
  52. #include "llviewerwindow.h"
  53. //LLFloaterTopObjects* LLFloaterTopObjects::sInstance = NULL;
  54. // Globals
  55. // const U32 TIME_STR_LENGTH = 30;
  56. /*
  57. // static
  58. void LLFloaterTopObjects::show()
  59. {
  60. if (sInstance)
  61. {
  62. sInstance->setVisibleAndFrontmost();
  63. return;
  64. }
  65. sInstance = new LLFloaterTopObjects();
  66. // LLUICtrlFactory::getInstance()->buildFloater(sInstance, "floater_top_objects.xml");
  67. sInstance->center();
  68. }
  69. */
  70. LLFloaterTopObjects::LLFloaterTopObjects(const LLSD& key)
  71. : LLFloater(key),
  72. mInitialized(FALSE),
  73. mtotalScore(0.f)
  74. {
  75. mCommitCallbackRegistrar.add("TopObjects.ShowBeacon", boost::bind(&LLFloaterTopObjects::onClickShowBeacon, this));
  76. mCommitCallbackRegistrar.add("TopObjects.ReturnSelected", boost::bind(&LLFloaterTopObjects::onReturnSelected, this));
  77. mCommitCallbackRegistrar.add("TopObjects.ReturnAll", boost::bind(&LLFloaterTopObjects::onReturnAll, this));
  78. mCommitCallbackRegistrar.add("TopObjects.DisableSelected", boost::bind(&LLFloaterTopObjects::onDisableSelected, this));
  79. mCommitCallbackRegistrar.add("TopObjects.DisableAll", boost::bind(&LLFloaterTopObjects::onDisableAll, this));
  80. mCommitCallbackRegistrar.add("TopObjects.Refresh", boost::bind(&LLFloaterTopObjects::onRefresh, this));
  81. mCommitCallbackRegistrar.add("TopObjects.GetByObjectName", boost::bind(&LLFloaterTopObjects::onGetByObjectName, this));
  82. mCommitCallbackRegistrar.add("TopObjects.GetByOwnerName", boost::bind(&LLFloaterTopObjects::onGetByOwnerName, this));
  83. mCommitCallbackRegistrar.add("TopObjects.CommitObjectsList",boost::bind(&LLFloaterTopObjects::onCommitObjectsList, this));
  84. }
  85. LLFloaterTopObjects::~LLFloaterTopObjects()
  86. {
  87. }
  88. // virtual
  89. BOOL LLFloaterTopObjects::postBuild()
  90. {
  91. LLScrollListCtrl *objects_list = getChild<LLScrollListCtrl>("objects_list");
  92. childSetFocus("objects_list");
  93. objects_list->setDoubleClickCallback(onDoubleClickObjectsList, this);
  94. objects_list->setCommitOnSelectionChange(TRUE);
  95. setDefaultBtn("show_beacon_btn");
  96. /*
  97. LLLineEditor* line_editor = getChild<LLLineEditor>("owner_name_editor");
  98. if (line_editor)
  99. {
  100. line_editor->setCommitOnFocusLost(FALSE);
  101. line_editor->setCommitCallback(onGetByOwnerName, this);
  102. }
  103. line_editor = getChild<LLLineEditor>("object_name_editor");
  104. if (line_editor)
  105. {
  106. line_editor->setCommitOnFocusLost(FALSE);
  107. line_editor->setCommitCallback(onGetByObjectName, this);
  108. }*/
  109. mCurrentMode = STAT_REPORT_TOP_SCRIPTS;
  110. mFlags = 0;
  111. mFilter.clear();
  112. return TRUE;
  113. }
  114. // static
  115. void LLFloaterTopObjects::setMode(U32 mode)
  116. {
  117. LLFloaterTopObjects* instance = LLFloaterReg::getTypedInstance<LLFloaterTopObjects>("top_objects");
  118. if(!instance) return;
  119. instance->mCurrentMode = mode; 
  120. }
  121. // static 
  122. void LLFloaterTopObjects::handle_land_reply(LLMessageSystem* msg, void** data)
  123. {
  124. LLFloaterTopObjects* instance = LLFloaterReg::getTypedInstance<LLFloaterTopObjects>("top_objects");
  125. if(!instance) return;
  126. // Make sure dialog is on screen
  127. LLFloaterReg::showInstance("top_objects");
  128. instance->handleReply(msg, data);
  129. //HACK: for some reason sometimes top scripts originally comes back
  130. //with no results even though they're there
  131. if (!instance->mObjectListIDs.size() && !instance->mInitialized)
  132. {
  133. instance->onRefresh();
  134. instance->mInitialized = TRUE;
  135. }
  136. }
  137. void LLFloaterTopObjects::handleReply(LLMessageSystem *msg, void** data)
  138. {
  139. U32 request_flags;
  140. U32 total_count;
  141. msg->getU32Fast(_PREHASH_RequestData, _PREHASH_RequestFlags, request_flags);
  142. msg->getU32Fast(_PREHASH_RequestData, _PREHASH_TotalObjectCount, total_count);
  143. msg->getU32Fast(_PREHASH_RequestData, _PREHASH_ReportType, mCurrentMode);
  144. LLScrollListCtrl *list = getChild<LLScrollListCtrl>("objects_list");
  145. S32 block_count = msg->getNumberOfBlocks("ReportData");
  146. for (S32 block = 0; block < block_count; ++block)
  147. {
  148. U32 task_local_id;
  149. U32 time_stamp = 0;
  150. LLUUID task_id;
  151. F32 location_x, location_y, location_z;
  152. F32 score;
  153. std::string name_buf;
  154. std::string owner_buf;
  155. F32 mono_score = 0.f;
  156. bool have_extended_data = false;
  157. S32 public_urls = 0;
  158. msg->getU32Fast(_PREHASH_ReportData, _PREHASH_TaskLocalID, task_local_id, block);
  159. msg->getUUIDFast(_PREHASH_ReportData, _PREHASH_TaskID, task_id, block);
  160. msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationX, location_x, block);
  161. msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationY, location_y, block);
  162. msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationZ, location_z, block);
  163. msg->getF32Fast(_PREHASH_ReportData, _PREHASH_Score, score, block);
  164. msg->getStringFast(_PREHASH_ReportData, _PREHASH_TaskName, name_buf, block);
  165. msg->getStringFast(_PREHASH_ReportData, _PREHASH_OwnerName, owner_buf, block);
  166. if(msg->has("DataExtended"))
  167. {
  168. have_extended_data = true;
  169. msg->getU32("DataExtended", "TimeStamp", time_stamp, block);
  170. msg->getF32("DataExtended", "MonoScore", mono_score, block);
  171. msg->getS32(_PREHASH_ReportData,"PublicURLs",public_urls,block);
  172. }
  173. LLSD element;
  174. element["id"] = task_id;
  175. element["object_name"] = name_buf;
  176. element["owner_name"] = owner_buf;
  177. element["columns"][0]["column"] = "score";
  178. element["columns"][0]["value"] = llformat("%0.3f", score);
  179. element["columns"][0]["font"] = "SANSSERIF";
  180. element["columns"][1]["column"] = "name";
  181. element["columns"][1]["value"] = name_buf;
  182. element["columns"][1]["font"] = "SANSSERIF";
  183. element["columns"][2]["column"] = "owner";
  184. element["columns"][2]["value"] = owner_buf;
  185. element["columns"][2]["font"] = "SANSSERIF";
  186. element["columns"][3]["column"] = "location";
  187. element["columns"][3]["value"] = llformat("<%0.1f,%0.1f,%0.1f>", location_x, location_y, location_z);
  188. element["columns"][3]["font"] = "SANSSERIF";
  189. element["columns"][4]["column"] = "time";
  190. element["columns"][4]["value"] = formatted_time((time_t)time_stamp);
  191. element["columns"][4]["font"] = "SANSSERIF";
  192. if (mCurrentMode == STAT_REPORT_TOP_SCRIPTS
  193. && have_extended_data)
  194. {
  195. element["columns"][5]["column"] = "mono_time";
  196. element["columns"][5]["value"] = llformat("%0.3f", mono_score);
  197. element["columns"][5]["font"] = "SANSSERIF";
  198. element["columns"][6]["column"] = "URLs";
  199. element["columns"][6]["value"] = llformat("%d", public_urls);
  200. element["columns"][6]["font"] = "SANSSERIF";
  201. }
  202. list->addElement(element);
  203. mObjectListData.append(element);
  204. mObjectListIDs.push_back(task_id);
  205. mtotalScore += score;
  206. }
  207. if (total_count == 0 && list->getItemCount() == 0)
  208. {
  209. list->setCommentText(getString("none_descriptor"));
  210. }
  211. else
  212. {
  213. list->selectFirstItem();
  214. }
  215. if (mCurrentMode == STAT_REPORT_TOP_SCRIPTS)
  216. {
  217. setTitle(getString("top_scripts_title"));
  218. list->setColumnLabel("score", getString("scripts_score_label"));
  219. list->setColumnLabel("mono_time", getString("scripts_mono_time_label"));
  220. LLUIString format = getString("top_scripts_text");
  221. format.setArg("[COUNT]", llformat("%d", total_count));
  222. format.setArg("[TIME]", llformat("%0.1f", mtotalScore));
  223. childSetValue("title_text", LLSD(format));
  224. }
  225. else
  226. {
  227. setTitle(getString("top_colliders_title"));
  228. list->setColumnLabel("score", getString("colliders_score_label"));
  229. list->setColumnLabel("mono_time", "");
  230. LLUIString format = getString("top_colliders_text");
  231. format.setArg("[COUNT]", llformat("%d", total_count));
  232. childSetValue("title_text", LLSD(format));
  233. }
  234. }
  235. void LLFloaterTopObjects::onCommitObjectsList()
  236. {
  237. updateSelectionInfo();
  238. }
  239. void LLFloaterTopObjects::updateSelectionInfo()
  240. {
  241. LLScrollListCtrl* list = getChild<LLScrollListCtrl>("objects_list");
  242. if (!list) return;
  243. LLUUID object_id = list->getCurrentID();
  244. if (object_id.isNull()) return;
  245. std::string object_id_string = object_id.asString();
  246. childSetValue("id_editor", LLSD(object_id_string));
  247. LLScrollListItem* sli = list->getFirstSelected();
  248. llassert(sli);
  249. if (sli)
  250. {
  251. childSetValue("object_name_editor", sli->getColumn(1)->getValue().asString());
  252. childSetValue("owner_name_editor", sli->getColumn(2)->getValue().asString());
  253. }
  254. }
  255. // static
  256. void LLFloaterTopObjects::onDoubleClickObjectsList(void* data)
  257. {
  258. LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
  259. self->showBeacon();
  260. }
  261. // static
  262. void LLFloaterTopObjects::onClickShowBeacon()
  263. {
  264. showBeacon();
  265. }
  266. void LLFloaterTopObjects::doToObjects(int action, bool all)
  267. {
  268. LLMessageSystem *msg = gMessageSystem;
  269. LLViewerRegion* region = gAgent.getRegion();
  270. if (!region) return;
  271. LLCtrlListInterface *list = childGetListInterface("objects_list");
  272. if (!list || list->getItemCount() == 0) return;
  273. std::vector<LLUUID>::iterator id_itor;
  274. bool start_message = true;
  275. for (id_itor = mObjectListIDs.begin(); id_itor != mObjectListIDs.end(); ++id_itor)
  276. {
  277. LLUUID task_id = *id_itor;
  278. if (!all && !list->isSelected(task_id))
  279. {
  280. // Selected only
  281. continue;
  282. }
  283. if (start_message)
  284. {
  285. if (action == ACTION_RETURN)
  286. {
  287. msg->newMessageFast(_PREHASH_ParcelReturnObjects);
  288. }
  289. else
  290. {
  291. msg->newMessageFast(_PREHASH_ParcelDisableObjects);
  292. }
  293. msg->nextBlockFast(_PREHASH_AgentData);
  294. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  295. msg->addUUIDFast(_PREHASH_SessionID,gAgent.getSessionID());
  296. msg->nextBlockFast(_PREHASH_ParcelData);
  297. msg->addS32Fast(_PREHASH_LocalID, -1); // Whole region
  298. msg->addS32Fast(_PREHASH_ReturnType, RT_NONE);
  299. start_message = false;
  300. }
  301. msg->nextBlockFast(_PREHASH_TaskIDs);
  302. msg->addUUIDFast(_PREHASH_TaskID, task_id);
  303. if (msg->isSendFullFast(_PREHASH_TaskIDs))
  304. {
  305. msg->sendReliable(region->getHost());
  306. start_message = true;
  307. }
  308. }
  309. if (!start_message)
  310. {
  311. msg->sendReliable(region->getHost());
  312. }
  313. }
  314. //static
  315. bool LLFloaterTopObjects::callbackReturnAll(const LLSD& notification, const LLSD& response)
  316. {
  317. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  318. LLFloaterTopObjects* instance = LLFloaterReg::getTypedInstance<LLFloaterTopObjects>("top_objects");
  319. if(!instance) return false;
  320. if (option == 0)
  321. {
  322. instance->doToObjects(ACTION_RETURN, true);
  323. }
  324. return false;
  325. }
  326. void LLFloaterTopObjects::onReturnAll()
  327. {
  328. LLNotificationsUtil::add("ReturnAllTopObjects", LLSD(), LLSD(), &callbackReturnAll);
  329. }
  330. void LLFloaterTopObjects::onReturnSelected()
  331. {
  332. doToObjects(ACTION_RETURN, false);
  333. }
  334. //static
  335. bool LLFloaterTopObjects::callbackDisableAll(const LLSD& notification, const LLSD& response)
  336. {
  337. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  338. LLFloaterTopObjects* instance = LLFloaterReg::getTypedInstance<LLFloaterTopObjects>("top_objects");
  339. if(!instance) return false;
  340. if (option == 0)
  341. {
  342. instance->doToObjects(ACTION_DISABLE, true);
  343. }
  344. return false;
  345. }
  346. void LLFloaterTopObjects::onDisableAll()
  347. {
  348. LLNotificationsUtil::add("DisableAllTopObjects", LLSD(), LLSD(), callbackDisableAll);
  349. }
  350. void LLFloaterTopObjects::onDisableSelected()
  351. {
  352. doToObjects(ACTION_DISABLE, false);
  353. }
  354. void LLFloaterTopObjects::clearList()
  355. {
  356. LLCtrlListInterface *list = childGetListInterface("objects_list");
  357. if (list) 
  358. {
  359. list->operateOnAll(LLCtrlListInterface::OP_DELETE);
  360. }
  361. mObjectListData.clear();
  362. mObjectListIDs.clear();
  363. mtotalScore = 0.f;
  364. }
  365. void LLFloaterTopObjects::onRefresh()
  366. {
  367. U32 mode = STAT_REPORT_TOP_SCRIPTS;
  368. U32 flags = 0;
  369. std::string filter = "";
  370. mode   = mCurrentMode;
  371. flags  = mFlags;
  372. filter = mFilter;
  373. clearList();
  374. LLMessageSystem *msg = gMessageSystem;
  375. msg->newMessageFast(_PREHASH_LandStatRequest);
  376. msg->nextBlockFast(_PREHASH_AgentData);
  377. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
  378. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
  379. msg->nextBlockFast(_PREHASH_RequestData);
  380. msg->addU32Fast(_PREHASH_ReportType, mode);
  381. msg->addU32Fast(_PREHASH_RequestFlags, flags);
  382. msg->addStringFast(_PREHASH_Filter, filter);
  383. msg->addS32Fast(_PREHASH_ParcelLocalID, 0);
  384. msg->sendReliable(gAgent.getRegionHost());
  385. mFilter.clear();
  386. mFlags = 0;
  387. }
  388. void LLFloaterTopObjects::onGetByObjectName()
  389. {
  390. mFlags  = STAT_FILTER_BY_OBJECT;
  391. mFilter = childGetText("object_name_editor");
  392. onRefresh();
  393. }
  394. void LLFloaterTopObjects::onGetByOwnerName()
  395. {
  396. mFlags  = STAT_FILTER_BY_OWNER;
  397. mFilter = childGetText("owner_name_editor");
  398. onRefresh();
  399. }
  400. void LLFloaterTopObjects::showBeacon()
  401. {
  402. LLScrollListCtrl* list = getChild<LLScrollListCtrl>("objects_list");
  403. if (!list) return;
  404. LLScrollListItem* first_selected = list->getFirstSelected();
  405. if (!first_selected) return;
  406. std::string name = first_selected->getColumn(1)->getValue().asString();
  407. std::string pos_string =  first_selected->getColumn(3)->getValue().asString();
  408. F32 x, y, z;
  409. S32 matched = sscanf(pos_string.c_str(), "<%g,%g,%g>", &x, &y, &z);
  410. if (matched != 3) return;
  411. LLVector3 pos_agent(x, y, z);
  412. LLVector3d pos_global = gAgent.getPosGlobalFromAgent(pos_agent);
  413. std::string tooltip("");
  414. LLTracker::trackLocation(pos_global, name, tooltip, LLTracker::LOCATION_ITEM);
  415. }