llfloatertopobjects.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llfloatertopobjects.h"
00035 
00036 #include "message.h"
00037 #include "llfontgl.h"
00038 
00039 #include "llagent.h"
00040 #include "llbutton.h"
00041 #include "llfloatergodtools.h"
00042 #include "llparcel.h"
00043 #include "llscrolllistctrl.h"
00044 #include "lllineeditor.h"
00045 #include "lltextbox.h"
00046 #include "lltracker.h"
00047 #include "llviewerparcelmgr.h"
00048 #include "llviewerregion.h"
00049 #include "llvieweruictrlfactory.h"
00050 #include "llviewerwindow.h"
00051 
00052 LLFloaterTopObjects* LLFloaterTopObjects::sInstance = NULL;
00053 
00054 
00055 // static
00056 void LLFloaterTopObjects::show()
00057 {
00058         if (sInstance)
00059         {
00060                 sInstance->setVisibleAndFrontmost();
00061                 return;
00062         }
00063 
00064         sInstance = new LLFloaterTopObjects();
00065         gUICtrlFactory->buildFloater(sInstance, "floater_top_objects.xml");
00066         sInstance->center();
00067 }
00068 
00069 LLFloaterTopObjects::LLFloaterTopObjects()
00070 :       LLFloater("top_objects"),
00071         mInitialized(FALSE),
00072         mtotalScore(0.f)
00073 {
00074         sInstance = this;
00075 }
00076 
00077 LLFloaterTopObjects::~LLFloaterTopObjects()
00078 {
00079         sInstance = NULL;
00080 }
00081 
00082 // virtual
00083 BOOL LLFloaterTopObjects::postBuild()
00084 {
00085         childSetCommitCallback("objects_list", onCommitObjectsList, this);
00086         childSetDoubleClickCallback("objects_list", onDoubleClickObjectsList);
00087         childSetFocus("objects_list");
00088         LLScrollListCtrl *objects_list = LLUICtrlFactory::getScrollListByName(this, "objects_list");
00089         if (objects_list)
00090         {
00091                 objects_list->setCommitOnSelectionChange(TRUE);
00092         }
00093 
00094         childSetAction("show_beacon_btn", onClickShowBeacon, this);
00095         setDefaultBtn("show_beacon_btn");
00096 
00097         childSetAction("return_selected_btn", onReturnSelected, this);
00098         childSetAction("return_all_btn", onReturnAll, this);
00099         childSetAction("disable_selected_btn", onDisableSelected, this);
00100         childSetAction("disable_all_btn", onDisableAll, this);
00101         childSetAction("refresh_btn", onRefresh, this); 
00102 
00103 
00104         childSetAction("filter_object_btn", onGetByObjectNameClicked, this);
00105         childSetAction("filter_owner_btn", onGetByOwnerNameClicked, this);      
00106 
00107 
00108         /*
00109         LLLineEditor* line_editor = LLUICtrlFactory::getLineEditorByName(this, "owner_name_editor");
00110         if (line_editor)
00111         {
00112                 line_editor->setCommitOnFocusLost(FALSE);
00113                 line_editor->setCommitCallback(onGetByOwnerName);
00114                 line_editor->setCallbackUserData(this);
00115         }
00116 
00117         line_editor = LLUICtrlFactory::getLineEditorByName(this, "object_name_editor");
00118         if (line_editor)
00119         {
00120                 line_editor->setCommitOnFocusLost(FALSE);
00121                 line_editor->setCommitCallback(onGetByObjectName);
00122                 line_editor->setCallbackUserData(this);
00123         }*/
00124 
00125         mCurrentMode = STAT_REPORT_TOP_SCRIPTS;
00126         mFlags = 0;
00127         mFilter = "";
00128 
00129         return TRUE;
00130 }
00131 
00132 void LLFloaterTopObjects::handle_land_reply(LLMessageSystem* msg, void** data)
00133 {
00134         // Make sure dialog is on screen
00135         show();
00136         sInstance->handleReply(msg, data);
00137 
00138         //HACK: for some reason sometimes top scripts originally comes back
00139         //with no results even though they're there
00140         if (!sInstance->mObjectListIDs.size() && !sInstance->mInitialized)
00141         {
00142                 sInstance->onRefresh(NULL);
00143                 sInstance->mInitialized = TRUE;
00144         }
00145 
00146 }
00147 
00148 void LLFloaterTopObjects::handleReply(LLMessageSystem *msg, void** data)
00149 {
00150         U32 request_flags;
00151         U32 total_count;
00152 
00153         msg->getU32Fast(_PREHASH_RequestData, _PREHASH_RequestFlags, request_flags);
00154         msg->getU32Fast(_PREHASH_RequestData, _PREHASH_TotalObjectCount, total_count);
00155         msg->getU32Fast(_PREHASH_RequestData, _PREHASH_ReportType, mCurrentMode);
00156 
00157         LLCtrlListInterface *list = childGetListInterface("objects_list");
00158         if (!list) return;
00159         
00160         S32 block_count = msg->getNumberOfBlocks("ReportData");
00161         for (S32 block = 0; block < block_count; ++block)
00162         {
00163                 U32 task_local_id;
00164                 LLUUID task_id;
00165                 F32 location_x, location_y, location_z;
00166                 F32 score;
00167                 char name_buf[MAX_STRING];              /* Flawfinder: ignore */
00168                 char owner_buf[MAX_STRING];             /* Flawfinder: ignore */
00169 
00170                 msg->getU32Fast(_PREHASH_ReportData, _PREHASH_TaskLocalID, task_local_id, block);
00171                 msg->getUUIDFast(_PREHASH_ReportData, _PREHASH_TaskID, task_id, block);
00172                 msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationX, location_x, block);
00173                 msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationY, location_y, block);
00174                 msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationZ, location_z, block);
00175                 msg->getF32Fast(_PREHASH_ReportData, _PREHASH_Score, score, block);
00176                 msg->getStringFast(_PREHASH_ReportData, _PREHASH_TaskName, MAX_STRING, name_buf, block);
00177                 msg->getStringFast(_PREHASH_ReportData, _PREHASH_OwnerName, MAX_STRING, owner_buf, block);
00178                 
00179                 LLSD element;
00180 
00181                 element["id"] = task_id;
00182                 element["object_name"] = LLString(name_buf);
00183                 element["owner_name"] = LLString(owner_buf);
00184                 element["columns"][0]["column"] = "score";
00185                 element["columns"][0]["value"] = llformat("%0.3f", score);
00186                 element["columns"][0]["font"] = "SANSSERIF";
00187                 element["columns"][1]["column"] = "name";
00188                 element["columns"][1]["value"] = name_buf;
00189                 element["columns"][1]["font"] = "SANSSERIF";
00190                 element["columns"][2]["column"] = "owner";
00191                 element["columns"][2]["value"] = owner_buf;
00192                 element["columns"][2]["font"] = "SANSSERIF";
00193                 element["columns"][3]["column"] = "location";
00194                 element["columns"][3]["value"] = llformat("<%0.1f,%0.1f,%0.1f>", location_x, location_y, location_z);
00195                 element["columns"][3]["font"] = "SANSSERIF";
00196 
00197                 list->addElement(element);
00198                 
00199                 mObjectListData.append(element);
00200                 mObjectListIDs.push_back(task_id);
00201 
00202                 mtotalScore += score;
00203         }
00204 
00205         if (total_count == 0 && list->getItemCount() == 0)
00206         {
00207                 LLSD element;
00208                 element["id"] = LLUUID::null;
00209                 element["columns"][0]["column"] = "name";
00210                 element["columns"][0]["value"] = childGetText("none_descriptor");
00211                 element["columns"][0]["font"] = "SANSSERIF";
00212 
00213                 list->addElement(element);
00214         }
00215         else
00216         {
00217                 list->selectFirstItem();
00218         }
00219 
00220         if (mCurrentMode == STAT_REPORT_TOP_SCRIPTS)
00221         {
00222                 setTitle(childGetText("top_scripts_title"));
00223                 list->setColumnLabel("score", childGetText("scripts_score_label"));
00224                 
00225                 LLUIString format = childGetText("top_scripts_text");
00226                 format.setArg("[COUNT]", llformat("%d", total_count));
00227                 format.setArg("[TIME]", llformat("%0.1f", mtotalScore));
00228                 childSetValue("title_text", LLSD(format));
00229         }
00230         else
00231         {
00232                 setTitle(childGetText("top_colliders_title"));
00233                 list->setColumnLabel("score", childGetText("colliders_score_label"));
00234                 LLUIString format = childGetText("top_colliders_text");
00235                 format.setArg("[COUNT]", llformat("%d", total_count));
00236                 childSetValue("title_text", LLSD(format));
00237         }
00238 }
00239 
00240 // static
00241 void LLFloaterTopObjects::onCommitObjectsList(LLUICtrl* ctrl, void* data)
00242 {
00243         LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
00244 
00245         self->updateSelectionInfo();
00246 }
00247 
00248 void LLFloaterTopObjects::updateSelectionInfo()
00249 {
00250         LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(this, "objects_list");
00251 
00252         if (!list) return;
00253 
00254         LLUUID object_id = list->getCurrentID();
00255         if (object_id.isNull()) return;
00256 
00257         std::string object_id_string = object_id.asString();
00258 
00259         childSetValue("id_editor", LLSD(object_id_string));
00260         childSetValue("object_name_editor", list->getFirstSelected()->getColumn(1)->getText());
00261         childSetValue("owner_name_editor", list->getFirstSelected()->getColumn(2)->getText());
00262 }
00263 
00264 // static
00265 void LLFloaterTopObjects::onDoubleClickObjectsList(void* data)
00266 {
00267         LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
00268         self->showBeacon();
00269 }
00270 
00271 // static
00272 void LLFloaterTopObjects::onClickShowBeacon(void* data)
00273 {
00274         LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
00275         if (!self) return;
00276         self->showBeacon();
00277 }
00278 
00279 void LLFloaterTopObjects::doToObjects(int action, bool all)
00280 {
00281         LLMessageSystem *msg = gMessageSystem;
00282 
00283         LLViewerRegion* region = gAgent.getRegion();
00284         if (!region) return;
00285 
00286         LLCtrlListInterface *list = childGetListInterface("objects_list");
00287         if (!list || list->getItemCount() == 0) return;
00288 
00289         std::vector<LLUUID>::iterator id_itor;
00290 
00291         bool start_message = true;
00292 
00293         for (id_itor = mObjectListIDs.begin(); id_itor != mObjectListIDs.end(); ++id_itor)
00294         {
00295                 LLUUID task_id = *id_itor;
00296                 if (!all && !list->isSelected(task_id))
00297                 {
00298                         // Selected only
00299                         continue;
00300                 }
00301                 if (start_message)
00302                 {
00303                         if (action == ACTION_RETURN)
00304                         {
00305                                 msg->newMessageFast(_PREHASH_ParcelReturnObjects);
00306                         }
00307                         else
00308                         {
00309                                 msg->newMessageFast(_PREHASH_ParcelDisableObjects);
00310                         }
00311                         msg->nextBlockFast(_PREHASH_AgentData);
00312                         msg->addUUIDFast(_PREHASH_AgentID,      gAgent.getID());
00313                         msg->addUUIDFast(_PREHASH_SessionID,gAgent.getSessionID());
00314                         msg->nextBlockFast(_PREHASH_ParcelData);
00315                         msg->addS32Fast(_PREHASH_LocalID, -1); // Whole region
00316                         msg->addS32Fast(_PREHASH_ReturnType, RT_NONE);
00317                         start_message = false;
00318                 }
00319 
00320                 msg->nextBlockFast(_PREHASH_TaskIDs);
00321                 msg->addUUIDFast(_PREHASH_TaskID, task_id);
00322 
00323                 if (msg->isSendFullFast(_PREHASH_TaskIDs))
00324                 {
00325                         msg->sendReliable(region->getHost());
00326                         start_message = true;
00327                 }
00328         }
00329 
00330         if (!start_message)
00331         {
00332                 msg->sendReliable(region->getHost());
00333         }
00334 }
00335 
00336 //static
00337 void LLFloaterTopObjects::callbackReturnAll(S32 option, void* userdata)
00338 {
00339         if (option == 0)
00340         {
00341                 sInstance->doToObjects(ACTION_RETURN, true);
00342         }
00343 }
00344 
00345 void LLFloaterTopObjects::onReturnAll(void* data)
00346 {       
00347         gViewerWindow->alertXml("ReturnAllTopObjects", callbackReturnAll, NULL);
00348 }
00349 
00350 
00351 void LLFloaterTopObjects::onReturnSelected(void* data)
00352 {
00353         sInstance->doToObjects(ACTION_RETURN, false);
00354 }
00355 
00356 
00357 //static
00358 void LLFloaterTopObjects::callbackDisableAll(S32 option, void* userdata)
00359 {
00360         if (option == 0)
00361         {
00362                 sInstance->doToObjects(ACTION_DISABLE, true);
00363         }
00364 }
00365 
00366 void LLFloaterTopObjects::onDisableAll(void* data)
00367 {
00368         gViewerWindow->alertXml("DisableAllTopObjects", callbackDisableAll, NULL);
00369 }
00370 
00371 void LLFloaterTopObjects::onDisableSelected(void* data)
00372 {
00373         sInstance->doToObjects(ACTION_DISABLE, false);
00374 }
00375 
00376 //static
00377 void LLFloaterTopObjects::clearList()
00378 {
00379         LLCtrlListInterface *list = sInstance->childGetListInterface("objects_list");
00380         
00381         if (list) 
00382         {
00383                 list->operateOnAll(LLCtrlListInterface::OP_DELETE);
00384         }
00385 
00386         sInstance->mObjectListData.clear();
00387         sInstance->mObjectListIDs.clear();
00388         sInstance->mtotalScore = 0.f;
00389 }
00390 
00391 //static
00392 void LLFloaterTopObjects::onRefresh(void* data)
00393 {
00394         U32 mode = STAT_REPORT_TOP_SCRIPTS;
00395         U32 flags = 0;
00396         LLString filter = "";
00397 
00398         if (sInstance)
00399         {
00400                 mode = sInstance->mCurrentMode;
00401                 flags = sInstance->mFlags;
00402                 filter = sInstance->mFilter;
00403                 sInstance->clearList();
00404         }
00405 
00406         LLMessageSystem *msg = gMessageSystem;
00407         msg->newMessageFast(_PREHASH_LandStatRequest);
00408         msg->nextBlockFast(_PREHASH_AgentData);
00409         msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
00410         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
00411         msg->nextBlockFast(_PREHASH_RequestData);
00412         msg->addU32Fast(_PREHASH_ReportType, mode);
00413         msg->addU32Fast(_PREHASH_RequestFlags, flags);
00414         msg->addStringFast(_PREHASH_Filter, filter);
00415         msg->addS32Fast(_PREHASH_ParcelLocalID, 0);
00416 
00417         msg->sendReliable(gAgent.getRegionHost());
00418 
00419         if (sInstance)
00420         {
00421                 sInstance->mFilter = "";
00422                 sInstance->mFlags = 0;
00423         }
00424 }
00425 
00426 void LLFloaterTopObjects::onGetByObjectName(LLUICtrl* ctrl, void* data)
00427 {
00428         if (sInstance)
00429         {
00430                 sInstance->mFlags = STAT_FILTER_BY_OBJECT;
00431                 sInstance->mFilter = sInstance->childGetText("object_name_editor");
00432                 onRefresh(NULL);
00433         }
00434 }
00435 
00436 void LLFloaterTopObjects::onGetByOwnerName(LLUICtrl* ctrl, void* data)
00437 {
00438         if (sInstance)
00439         {
00440                 sInstance->mFlags = STAT_FILTER_BY_OWNER;
00441                 sInstance->mFilter = sInstance->childGetText("owner_name_editor");
00442                 onRefresh(NULL);
00443         }
00444 }
00445 
00446 void LLFloaterTopObjects::showBeacon()
00447 {       
00448         LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(this, "objects_list");
00449         if (!list) return;
00450 
00451         LLScrollListItem* first_selected = list->getFirstSelected();
00452         if (!first_selected) return;
00453 
00454         LLString name = first_selected->getColumn(1)->getText();
00455         LLString pos_string =  first_selected->getColumn(3)->getText();
00456 
00457         F32 x, y, z;
00458         S32 matched = sscanf(pos_string.c_str(), "<%g,%g,%g>", &x, &y, &z);
00459         if (matched != 3) return;
00460 
00461         LLVector3 pos_agent(x, y, z);
00462         LLVector3d pos_global = gAgent.getPosGlobalFromAgent(pos_agent);
00463         LLString tooltip("");
00464         LLTracker::trackLocation(pos_global, name, tooltip, LLTracker::LOCATION_ITEM);
00465 }

Generated on Thu Jul 1 06:08:36 2010 for Second Life Viewer by  doxygen 1.4.7