diff options
Diffstat (limited to 'linden/indra/newview/llfloatertopobjects.cpp')
-rw-r--r-- | linden/indra/newview/llfloatertopobjects.cpp | 460 |
1 files changed, 460 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloatertopobjects.cpp b/linden/indra/newview/llfloatertopobjects.cpp new file mode 100644 index 0000000..093b840 --- /dev/null +++ b/linden/indra/newview/llfloatertopobjects.cpp | |||
@@ -0,0 +1,460 @@ | |||
1 | /** | ||
2 | * @file llfloatertopobjects.cpp | ||
3 | * @brief Shows top colliders, top scripts, etc. | ||
4 | * | ||
5 | * Copyright (c) 2005-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "llfloatertopobjects.h" | ||
31 | |||
32 | #include "message.h" | ||
33 | #include "llfontgl.h" | ||
34 | |||
35 | #include "llagent.h" | ||
36 | #include "llbutton.h" | ||
37 | #include "llfloatergodtools.h" | ||
38 | #include "llparcel.h" | ||
39 | #include "llscrolllistctrl.h" | ||
40 | #include "lllineeditor.h" | ||
41 | #include "lltextbox.h" | ||
42 | #include "lltracker.h" | ||
43 | #include "llviewerparcelmgr.h" | ||
44 | #include "llviewerregion.h" | ||
45 | #include "llvieweruictrlfactory.h" | ||
46 | #include "llviewerwindow.h" | ||
47 | |||
48 | LLFloaterTopObjects* LLFloaterTopObjects::sInstance = NULL; | ||
49 | |||
50 | |||
51 | // static | ||
52 | void LLFloaterTopObjects::show() | ||
53 | { | ||
54 | if (sInstance) | ||
55 | { | ||
56 | sInstance->setVisibleAndFrontmost(); | ||
57 | return; | ||
58 | } | ||
59 | |||
60 | sInstance = new LLFloaterTopObjects(); | ||
61 | gUICtrlFactory->buildFloater(sInstance, "floater_top_objects.xml"); | ||
62 | sInstance->center(); | ||
63 | } | ||
64 | |||
65 | LLFloaterTopObjects::LLFloaterTopObjects() | ||
66 | : LLFloater("top_objects"), | ||
67 | mInitialized(FALSE), | ||
68 | mtotalScore(0.f) | ||
69 | { | ||
70 | sInstance = this; | ||
71 | } | ||
72 | |||
73 | LLFloaterTopObjects::~LLFloaterTopObjects() | ||
74 | { | ||
75 | sInstance = NULL; | ||
76 | } | ||
77 | |||
78 | // virtual | ||
79 | BOOL LLFloaterTopObjects::postBuild() | ||
80 | { | ||
81 | childSetCommitCallback("objects_list", onCommitObjectsList, this); | ||
82 | childSetDoubleClickCallback("objects_list", onDoubleClickObjectsList); | ||
83 | childSetFocus("objects_list"); | ||
84 | LLScrollListCtrl *objects_list = LLUICtrlFactory::getScrollListByName(this, "objects_list"); | ||
85 | if (objects_list) | ||
86 | { | ||
87 | objects_list->setCommitOnSelectionChange(TRUE); | ||
88 | } | ||
89 | |||
90 | childSetAction("show_beacon_btn", onClickShowBeacon, this); | ||
91 | setDefaultBtn("show_beacon_btn"); | ||
92 | |||
93 | childSetAction("return_selected_btn", onReturnSelected, this); | ||
94 | childSetAction("return_all_btn", onReturnAll, this); | ||
95 | childSetAction("disable_selected_btn", onDisableSelected, this); | ||
96 | childSetAction("disable_all_btn", onDisableAll, this); | ||
97 | childSetAction("refresh_btn", onRefresh, this); | ||
98 | |||
99 | |||
100 | childSetAction("filter_object_btn", onGetByObjectNameClicked, this); | ||
101 | childSetAction("filter_owner_btn", onGetByOwnerNameClicked, this); | ||
102 | |||
103 | |||
104 | /* | ||
105 | LLLineEditor* line_editor = LLUICtrlFactory::getLineEditorByName(this, "owner_name_editor"); | ||
106 | if (line_editor) | ||
107 | { | ||
108 | line_editor->setCommitOnFocusLost(FALSE); | ||
109 | line_editor->setCommitCallback(onGetByOwnerName); | ||
110 | line_editor->setCallbackUserData(this); | ||
111 | } | ||
112 | |||
113 | line_editor = LLUICtrlFactory::getLineEditorByName(this, "object_name_editor"); | ||
114 | if (line_editor) | ||
115 | { | ||
116 | line_editor->setCommitOnFocusLost(FALSE); | ||
117 | line_editor->setCommitCallback(onGetByObjectName); | ||
118 | line_editor->setCallbackUserData(this); | ||
119 | }*/ | ||
120 | |||
121 | mCurrentMode = STAT_REPORT_TOP_SCRIPTS; | ||
122 | mFlags = 0; | ||
123 | mFilter = ""; | ||
124 | |||
125 | return TRUE; | ||
126 | } | ||
127 | |||
128 | void LLFloaterTopObjects::handle_land_reply(LLMessageSystem* msg, void** data) | ||
129 | { | ||
130 | // Make sure dialog is on screen | ||
131 | show(); | ||
132 | sInstance->handleReply(msg, data); | ||
133 | |||
134 | //HACK: for some reason sometimes top scripts originally comes back | ||
135 | //with no results even though they're there | ||
136 | if (!sInstance->mObjectListIDs.size() && !sInstance->mInitialized) | ||
137 | { | ||
138 | sInstance->onRefresh(NULL); | ||
139 | sInstance->mInitialized = TRUE; | ||
140 | } | ||
141 | |||
142 | } | ||
143 | |||
144 | void LLFloaterTopObjects::handleReply(LLMessageSystem *msg, void** data) | ||
145 | { | ||
146 | U32 request_flags; | ||
147 | U32 total_count; | ||
148 | |||
149 | msg->getU32Fast(_PREHASH_RequestData, _PREHASH_RequestFlags, request_flags); | ||
150 | msg->getU32Fast(_PREHASH_RequestData, _PREHASH_TotalObjectCount, total_count); | ||
151 | msg->getU32Fast(_PREHASH_RequestData, _PREHASH_ReportType, mCurrentMode); | ||
152 | |||
153 | LLCtrlListInterface *list = childGetListInterface("objects_list"); | ||
154 | if (!list) return; | ||
155 | |||
156 | S32 block_count = msg->getNumberOfBlocks("ReportData"); | ||
157 | for (S32 block = 0; block < block_count; ++block) | ||
158 | { | ||
159 | U32 task_local_id; | ||
160 | LLUUID task_id; | ||
161 | F32 location_x, location_y, location_z; | ||
162 | F32 score; | ||
163 | char name_buf[MAX_STRING]; | ||
164 | char owner_buf[MAX_STRING]; | ||
165 | |||
166 | msg->getU32Fast(_PREHASH_ReportData, _PREHASH_TaskLocalID, task_local_id, block); | ||
167 | msg->getUUIDFast(_PREHASH_ReportData, _PREHASH_TaskID, task_id, block); | ||
168 | msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationX, location_x, block); | ||
169 | msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationY, location_y, block); | ||
170 | msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationZ, location_z, block); | ||
171 | msg->getF32Fast(_PREHASH_ReportData, _PREHASH_Score, score, block); | ||
172 | msg->getStringFast(_PREHASH_ReportData, _PREHASH_TaskName, MAX_STRING, name_buf, block); | ||
173 | msg->getStringFast(_PREHASH_ReportData, _PREHASH_OwnerName, MAX_STRING, owner_buf, block); | ||
174 | |||
175 | LLSD element; | ||
176 | |||
177 | element["id"] = task_id; | ||
178 | element["object_name"] = LLString(name_buf); | ||
179 | element["owner_name"] = LLString(owner_buf); | ||
180 | element["columns"][0]["column"] = "score"; | ||
181 | element["columns"][0]["value"] = llformat("%0.3f", score); | ||
182 | element["columns"][0]["font"] = "SANSSERIF"; | ||
183 | element["columns"][1]["column"] = "name"; | ||
184 | element["columns"][1]["value"] = name_buf; | ||
185 | element["columns"][1]["font"] = "SANSSERIF"; | ||
186 | element["columns"][2]["column"] = "owner"; | ||
187 | element["columns"][2]["value"] = owner_buf; | ||
188 | element["columns"][2]["font"] = "SANSSERIF"; | ||
189 | element["columns"][3]["column"] = "location"; | ||
190 | element["columns"][3]["value"] = llformat("<%0.1f,%0.1f,%0.1f>", location_x, location_y, location_z); | ||
191 | element["columns"][3]["font"] = "SANSSERIF"; | ||
192 | |||
193 | list->addElement(element); | ||
194 | |||
195 | mObjectListData.append(element); | ||
196 | mObjectListIDs.push_back(task_id); | ||
197 | |||
198 | mtotalScore += score; | ||
199 | } | ||
200 | |||
201 | if (total_count == 0 && list->getItemCount() == 0) | ||
202 | { | ||
203 | LLSD element; | ||
204 | element["id"] = LLUUID::null; | ||
205 | element["columns"][0]["column"] = "name"; | ||
206 | element["columns"][0]["value"] = childGetText("none_descriptor"); | ||
207 | element["columns"][0]["font"] = "SANSSERIF"; | ||
208 | |||
209 | list->addElement(element); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | list->selectFirstItem(); | ||
214 | } | ||
215 | |||
216 | if (mCurrentMode == STAT_REPORT_TOP_SCRIPTS) | ||
217 | { | ||
218 | setTitle(childGetText("top_scripts_title")); | ||
219 | list->setColumnLabel("score", childGetText("scripts_score_label")); | ||
220 | |||
221 | LLUIString format = childGetText("top_scripts_text"); | ||
222 | format.setArg("[COUNT]", llformat("%d", total_count)); | ||
223 | format.setArg("[TIME]", llformat("%0.1f", mtotalScore)); | ||
224 | childSetValue("title_text", LLSD(format)); | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | setTitle(childGetText("top_colliders_title")); | ||
229 | list->setColumnLabel("score", childGetText("colliders_score_label")); | ||
230 | LLUIString format = childGetText("top_colliders_text"); | ||
231 | format.setArg("[COUNT]", llformat("%d", total_count)); | ||
232 | childSetValue("title_text", LLSD(format)); | ||
233 | } | ||
234 | } | ||
235 | |||
236 | // static | ||
237 | void LLFloaterTopObjects::onCommitObjectsList(LLUICtrl* ctrl, void* data) | ||
238 | { | ||
239 | LLFloaterTopObjects* self = (LLFloaterTopObjects*)data; | ||
240 | |||
241 | self->updateSelectionInfo(); | ||
242 | } | ||
243 | |||
244 | void LLFloaterTopObjects::updateSelectionInfo() | ||
245 | { | ||
246 | LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(this, "objects_list"); | ||
247 | |||
248 | if (!list) return; | ||
249 | |||
250 | LLUUID object_id = list->getCurrentID(); | ||
251 | if (object_id.isNull()) return; | ||
252 | |||
253 | LLString object_id_string = object_id.getString(); | ||
254 | |||
255 | childSetValue("id_editor", LLSD(object_id_string)); | ||
256 | childSetValue("object_name_editor", list->getFirstSelected()->getColumn(1)->getText()); | ||
257 | childSetValue("owner_name_editor", list->getFirstSelected()->getColumn(2)->getText()); | ||
258 | } | ||
259 | |||
260 | // static | ||
261 | void LLFloaterTopObjects::onDoubleClickObjectsList(void* data) | ||
262 | { | ||
263 | LLFloaterTopObjects* self = (LLFloaterTopObjects*)data; | ||
264 | self->showBeacon(); | ||
265 | } | ||
266 | |||
267 | // static | ||
268 | void LLFloaterTopObjects::onClickShowBeacon(void* data) | ||
269 | { | ||
270 | LLFloaterTopObjects* self = (LLFloaterTopObjects*)data; | ||
271 | if (!self) return; | ||
272 | self->showBeacon(); | ||
273 | } | ||
274 | |||
275 | void LLFloaterTopObjects::doToObjects(int action, bool all) | ||
276 | { | ||
277 | LLMessageSystem *msg = gMessageSystem; | ||
278 | |||
279 | LLViewerRegion* region = gAgent.getRegion(); | ||
280 | if (!region) return; | ||
281 | |||
282 | LLCtrlListInterface *list = childGetListInterface("objects_list"); | ||
283 | if (!list || list->getItemCount() == 0) return; | ||
284 | |||
285 | std::vector<LLUUID>::iterator id_itor; | ||
286 | |||
287 | bool start_message = true; | ||
288 | |||
289 | for (id_itor = mObjectListIDs.begin(); id_itor != mObjectListIDs.end(); ++id_itor) | ||
290 | { | ||
291 | LLUUID task_id = *id_itor; | ||
292 | if (!all && !list->isSelected(task_id)) | ||
293 | { | ||
294 | // Selected only | ||
295 | continue; | ||
296 | } | ||
297 | if (start_message) | ||
298 | { | ||
299 | if (action == ACTION_RETURN) | ||
300 | { | ||
301 | msg->newMessageFast(_PREHASH_ParcelReturnObjects); | ||
302 | } | ||
303 | else | ||
304 | { | ||
305 | msg->newMessageFast(_PREHASH_ParcelDisableObjects); | ||
306 | } | ||
307 | msg->nextBlockFast(_PREHASH_AgentData); | ||
308 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); | ||
309 | msg->addUUIDFast(_PREHASH_SessionID,gAgent.getSessionID()); | ||
310 | msg->nextBlockFast(_PREHASH_ParcelData); | ||
311 | msg->addS32Fast(_PREHASH_LocalID, -1); // Whole region | ||
312 | msg->addS32Fast(_PREHASH_ReturnType, RT_NONE); | ||
313 | start_message = false; | ||
314 | } | ||
315 | |||
316 | msg->nextBlockFast(_PREHASH_TaskIDs); | ||
317 | msg->addUUIDFast(_PREHASH_TaskID, task_id); | ||
318 | |||
319 | if (msg->isSendFullFast(_PREHASH_TaskIDs)) | ||
320 | { | ||
321 | msg->sendReliable(region->getHost()); | ||
322 | start_message = true; | ||
323 | } | ||
324 | } | ||
325 | |||
326 | if (!start_message) | ||
327 | { | ||
328 | msg->sendReliable(region->getHost()); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | //static | ||
333 | void LLFloaterTopObjects::callbackReturnAll(S32 option, void* userdata) | ||
334 | { | ||
335 | if (option == 0) | ||
336 | { | ||
337 | sInstance->doToObjects(ACTION_RETURN, true); | ||
338 | } | ||
339 | } | ||
340 | |||
341 | void LLFloaterTopObjects::onReturnAll(void* data) | ||
342 | { | ||
343 | gViewerWindow->alertXml("ReturnAllTopObjects", callbackReturnAll, NULL); | ||
344 | } | ||
345 | |||
346 | |||
347 | void LLFloaterTopObjects::onReturnSelected(void* data) | ||
348 | { | ||
349 | sInstance->doToObjects(ACTION_RETURN, false); | ||
350 | } | ||
351 | |||
352 | |||
353 | //static | ||
354 | void LLFloaterTopObjects::callbackDisableAll(S32 option, void* userdata) | ||
355 | { | ||
356 | if (option == 0) | ||
357 | { | ||
358 | sInstance->doToObjects(ACTION_DISABLE, true); | ||
359 | } | ||
360 | } | ||
361 | |||
362 | void LLFloaterTopObjects::onDisableAll(void* data) | ||
363 | { | ||
364 | gViewerWindow->alertXml("DisableAllTopObjects", callbackDisableAll, NULL); | ||
365 | } | ||
366 | |||
367 | void LLFloaterTopObjects::onDisableSelected(void* data) | ||
368 | { | ||
369 | sInstance->doToObjects(ACTION_DISABLE, false); | ||
370 | } | ||
371 | |||
372 | void LLFloaterTopObjects::clearList() | ||
373 | { | ||
374 | LLCtrlListInterface *list = childGetListInterface("objects_list"); | ||
375 | |||
376 | if (list) | ||
377 | { | ||
378 | list->operateOnAll(LLCtrlListInterface::OP_DELETE); | ||
379 | } | ||
380 | |||
381 | mObjectListData.clear(); | ||
382 | mObjectListIDs.clear(); | ||
383 | } | ||
384 | |||
385 | void LLFloaterTopObjects::onRefresh(void* data) | ||
386 | { | ||
387 | U32 mode = STAT_REPORT_TOP_SCRIPTS; | ||
388 | U32 flags = 0; | ||
389 | LLString filter = ""; | ||
390 | |||
391 | if (sInstance) | ||
392 | { | ||
393 | mode = sInstance->mCurrentMode; | ||
394 | flags = sInstance->mFlags; | ||
395 | filter = sInstance->mFilter; | ||
396 | sInstance->clearList(); | ||
397 | } | ||
398 | |||
399 | sInstance->mtotalScore = 0.f; | ||
400 | |||
401 | LLMessageSystem *msg = gMessageSystem; | ||
402 | msg->newMessageFast(_PREHASH_LandStatRequest); | ||
403 | msg->nextBlockFast(_PREHASH_AgentData); | ||
404 | msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() ); | ||
405 | msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() ); | ||
406 | msg->nextBlockFast(_PREHASH_RequestData); | ||
407 | msg->addU32Fast(_PREHASH_ReportType, mode); | ||
408 | msg->addU32Fast(_PREHASH_RequestFlags, flags); | ||
409 | msg->addStringFast(_PREHASH_Filter, filter); | ||
410 | msg->addS32Fast(_PREHASH_ParcelLocalID, 0); | ||
411 | |||
412 | msg->sendReliable(gAgent.getRegionHost()); | ||
413 | |||
414 | if (sInstance) | ||
415 | { | ||
416 | sInstance->mFilter = ""; | ||
417 | sInstance->mFlags = 0; | ||
418 | } | ||
419 | } | ||
420 | |||
421 | void LLFloaterTopObjects::onGetByObjectName(LLUICtrl* ctrl, void* data) | ||
422 | { | ||
423 | if (sInstance) | ||
424 | { | ||
425 | sInstance->mFlags = STAT_FILTER_BY_OBJECT; | ||
426 | sInstance->mFilter = sInstance->childGetText("object_name_editor"); | ||
427 | onRefresh(NULL); | ||
428 | } | ||
429 | } | ||
430 | |||
431 | void LLFloaterTopObjects::onGetByOwnerName(LLUICtrl* ctrl, void* data) | ||
432 | { | ||
433 | if (sInstance) | ||
434 | { | ||
435 | sInstance->mFlags = STAT_FILTER_BY_OWNER; | ||
436 | sInstance->mFilter = sInstance->childGetText("owner_name_editor"); | ||
437 | onRefresh(NULL); | ||
438 | } | ||
439 | } | ||
440 | |||
441 | void LLFloaterTopObjects::showBeacon() | ||
442 | { | ||
443 | LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(this, "objects_list"); | ||
444 | if (!list) return; | ||
445 | |||
446 | LLScrollListItem* first_selected = list->getFirstSelected(); | ||
447 | if (!first_selected) return; | ||
448 | |||
449 | LLString name = first_selected->getColumn(1)->getText(); | ||
450 | LLString pos_string = first_selected->getColumn(3)->getText(); | ||
451 | |||
452 | F32 x, y, z; | ||
453 | S32 matched = sscanf(pos_string.c_str(), "<%g,%g,%g>", &x, &y, &z); | ||
454 | if (matched != 3) return; | ||
455 | |||
456 | LLVector3 pos_agent(x, y, z); | ||
457 | LLVector3d pos_global = gAgent.getPosGlobalFromAgent(pos_agent); | ||
458 | LLString tooltip(""); | ||
459 | LLTracker::trackLocation(pos_global, name, tooltip, LLTracker::LOCATION_ITEM); | ||
460 | } | ||