llfloaterpathfindingobjects.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. /**
  2. * @file llfloaterpathfindingobjects.cpp
  3. * @brief Base class for both the pathfinding linksets and characters floater.
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewergpl$
  6. *
  7. * Copyright (c) 2012, 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 "llfloaterpathfindingobjects.h"
  34. #include "llavatarnamecache.h"
  35. #include "llbutton.h"
  36. #include "llcheckboxctrl.h"
  37. #include "llfloater.h"
  38. #include "lllocale.h"
  39. #include "llnotifications.h"
  40. #include "llscrolllistctrl.h"
  41. #include "llstyle.h"
  42. #include "lltextbox.h"
  43. #include "llagent.h"
  44. #include "llpathfindingmanager.h"
  45. //MK
  46. #include "mkrlinterface.h"
  47. //mk
  48. #include "llselectmgr.h"
  49. #include "llviewermenu.h" // For enable_object_*(), etc
  50. #include "llviewerobjectlist.h"
  51. #include "llviewerregion.h"
  52. //---------------------------------------------------------------------------
  53. // LLFloaterPathfindingObjects
  54. //---------------------------------------------------------------------------
  55. LLFloaterPathfindingObjects::LLFloaterPathfindingObjects()
  56. : mObjectsScrollList(NULL),
  57. mMessagingStatus(NULL),
  58. mRefreshListButton(NULL),
  59. mSelectAllButton(NULL),
  60. mSelectNoneButton(NULL),
  61. mShowBeaconCheckBox(NULL),
  62. mTakeButton(NULL),
  63. mTakeCopyButton(NULL),
  64. mReturnButton(NULL),
  65. mDeleteButton(NULL),
  66. mTeleportButton(NULL),
  67. mMessagingState(kMessagingUnknown),
  68. mMessagingRequestId(0U),
  69. mHasObjectsToBeSelected(false)
  70. {
  71. }
  72. LLFloaterPathfindingObjects::~LLFloaterPathfindingObjects()
  73. {
  74. clearAllObjects();
  75. }
  76. bool LLFloaterPathfindingObjects::postBuild()
  77. {
  78. mDefaultBeaconColor =
  79. LLUI::sColorsGroup->getColor("PathfindingDefaultBeaconColor");
  80. mDefaultBeaconTextColor =
  81. LLUI::sColorsGroup->getColor("PathfindingDefaultBeaconTextColor");
  82. mGoodTextColor = LLUI::sColorsGroup->getColor("PathfindingGoodColor");
  83. mWarningTextColor =
  84. LLUI::sColorsGroup->getColor("PathfindingWarningColor");
  85. mErrorTextColor = LLUI::sColorsGroup->getColor("PathfindingErrorColor");
  86. mObjectsScrollList = getChild<LLScrollListCtrl>("objects_scroll_list");
  87. mObjectsScrollList->setCommitCallback(onScrollListSelectionChanged);
  88. mObjectsScrollList->setCallbackUserData(this);
  89. mObjectsScrollList->setCommitOnSelectionChange(true);
  90. mObjectsScrollList->sortByColumnIndex(getNameColumnIndex(), true);
  91. mMessagingStatus = getChild<LLTextBox>("messaging_status");
  92. mRefreshListButton = getChild<LLButton>("refresh_objects_list");
  93. mRefreshListButton->setClickedCallback(onRefreshObjectsClicked, this);
  94. mSelectAllButton = getChild<LLButton>("select_all_objects");
  95. mSelectAllButton->setClickedCallback(onSelectAllObjectsClicked, this);
  96. mSelectNoneButton = getChild<LLButton>("select_none_objects");
  97. mSelectNoneButton->setClickedCallback(onSelectNoneObjectsClicked, this);
  98. mShowBeaconCheckBox = getChild<LLCheckBoxCtrl>("show_beacon");
  99. mTakeButton = getChild<LLButton>("take_objects");
  100. mTakeButton->setClickedCallback(onTakeClicked, this);
  101. mTakeCopyButton = getChild<LLButton>("take_copy_objects");
  102. mTakeCopyButton->setClickedCallback(onTakeCopyClicked, this);
  103. mReturnButton = getChild<LLButton>("return_objects");
  104. mReturnButton->setClickedCallback(onReturnClicked, this);
  105. mDeleteButton = getChild<LLButton>("delete_objects");
  106. mDeleteButton->setClickedCallback(onDeleteClicked, this);
  107. mTeleportButton = getChild<LLButton>("teleport_me_to_object");
  108. mTeleportButton->setClickedCallback(onTeleportClicked, this);
  109. return true;
  110. }
  111. void LLFloaterPathfindingObjects::onOpen()
  112. {
  113. LLFloater::onOpen();
  114. selectNoneObjects();
  115. mObjectsScrollList->setCommitOnSelectionChange(true);
  116. if (!mSelectionUpdateSlot.connected())
  117. {
  118. mSelectionUpdateSlot =
  119. gSelectMgr.mUpdateSignal.connect(boost::bind(&LLFloaterPathfindingObjects::onInWorldSelectionListChanged,
  120. this));
  121. }
  122. if (!mRegionBoundaryCrossingSlot.connected())
  123. {
  124. mRegionBoundaryCrossingSlot =
  125. gAgent.addRegionChangedCB(boost::bind(&LLFloaterPathfindingObjects::onRegionBoundaryCrossed,
  126. this));
  127. }
  128. if (!mGodLevelChangeSlot.connected())
  129. {
  130. mGodLevelChangeSlot =
  131. gAgent.registerGodLevelChanageListener(boost::bind(&LLFloaterPathfindingObjects::onGodLevelChange, this, _1));
  132. }
  133. requestGetObjects();
  134. }
  135. void LLFloaterPathfindingObjects::onClose(bool app_quitting)
  136. {
  137. if (mGodLevelChangeSlot.connected())
  138. {
  139. mGodLevelChangeSlot.disconnect();
  140. }
  141. if (mRegionBoundaryCrossingSlot.connected())
  142. {
  143. mRegionBoundaryCrossingSlot.disconnect();
  144. }
  145. if (mSelectionUpdateSlot.connected())
  146. {
  147. mSelectionUpdateSlot.disconnect();
  148. }
  149. mObjectsScrollList->setCommitOnSelectionChange(false);
  150. selectNoneObjects();
  151. if (mObjectsSelection.notNull())
  152. {
  153. mObjectsSelection.clear();
  154. }
  155. if (app_quitting)
  156. {
  157. clearAllObjects();
  158. }
  159. LLFloater::onClose(app_quitting);
  160. }
  161. void LLFloaterPathfindingObjects::draw()
  162. {
  163. //MK
  164. // Fast enough that it can be kept here
  165. if (gRLenabled && gRLInterface.mContainsEdit)
  166. {
  167. close();
  168. return;
  169. }
  170. //mk
  171. LLFloater::draw();
  172. if (showBeacons())
  173. {
  174. std::vector<LLScrollListItem*> items =
  175. mObjectsScrollList->getAllSelected();
  176. if (items.empty())
  177. {
  178. return;
  179. }
  180. S32 name_col_idx = getNameColumnIndex();
  181. const LLColor4& beacon_color = getBeaconColor();
  182. const LLColor4& text_color = getBeaconTextColor();
  183. S32 beacon_width = getBeaconWidth();
  184. std::vector<LLViewerObject*> objects;
  185. objects.reserve(items.size());
  186. for (std::vector<LLScrollListItem*>::const_iterator it = items.begin(),
  187. end = items.end();
  188. it != end; ++it)
  189. {
  190. const LLScrollListItem* item = *it;
  191. LLViewerObject* vobj = gObjectList.findObject(item->getUUID());
  192. if (!vobj) continue;
  193. const std::string& name =
  194. item->getColumn(name_col_idx)->getValue().asString();
  195. gObjectList.addDebugBeacon(vobj->getPositionAgent(), name,
  196. beacon_color, text_color, beacon_width);
  197. }
  198. }
  199. }
  200. LLPathfindingManager::request_id_t LLFloaterPathfindingObjects::getNewRequestId()
  201. {
  202. return ++mMessagingRequestId;
  203. }
  204. void LLFloaterPathfindingObjects::handleNewObjectList(LLPathfindingManager::request_id_t req_id,
  205. LLPathfindingManager::ERequestStatus req_status,
  206. LLPathfindingObjectList::ptr_t pobjects)
  207. {
  208. if (req_id == mMessagingRequestId)
  209. {
  210. switch (req_status)
  211. {
  212. case LLPathfindingManager::kRequestStarted:
  213. setMessagingState(kMessagingGetRequestSent);
  214. break;
  215. case LLPathfindingManager::kRequestCompleted:
  216. mObjectList = pobjects;
  217. rebuildObjectsScrollList();
  218. setMessagingState(kMessagingComplete);
  219. break;
  220. case LLPathfindingManager::kRequestNotEnabled:
  221. clearAllObjects();
  222. setMessagingState(kMessagingNotEnabled);
  223. break;
  224. case LLPathfindingManager::kRequestError:
  225. clearAllObjects();
  226. setMessagingState(kMessagingGetError);
  227. break;
  228. default:
  229. clearAllObjects();
  230. setMessagingState(kMessagingGetError);
  231. llwarns << "Unknown status !" << llendl;
  232. }
  233. }
  234. else if (req_id > mMessagingRequestId)
  235. {
  236. llwarns << "Invalid request id !" << llendl;
  237. }
  238. }
  239. void LLFloaterPathfindingObjects::handleUpdateObjectList(LLPathfindingManager::request_id_t req_id,
  240. LLPathfindingManager::ERequestStatus req_status,
  241. LLPathfindingObjectList::ptr_t pobjects)
  242. {
  243. // We currently assume that handleUpdateObjectList is called only when
  244. // objects are being SET
  245. if (req_id == mMessagingRequestId)
  246. {
  247. switch (req_status)
  248. {
  249. case LLPathfindingManager::kRequestStarted:
  250. setMessagingState(kMessagingSetRequestSent);
  251. break;
  252. case LLPathfindingManager::kRequestCompleted:
  253. if (mObjectList == NULL)
  254. {
  255. mObjectList = pobjects;
  256. }
  257. else
  258. {
  259. mObjectList->update(pobjects);
  260. }
  261. rebuildObjectsScrollList();
  262. setMessagingState(kMessagingComplete);
  263. break;
  264. case LLPathfindingManager::kRequestNotEnabled:
  265. clearAllObjects();
  266. setMessagingState(kMessagingNotEnabled);
  267. break;
  268. case LLPathfindingManager::kRequestError:
  269. clearAllObjects();
  270. setMessagingState(kMessagingSetError);
  271. break;
  272. default:
  273. clearAllObjects();
  274. setMessagingState(kMessagingSetError);
  275. llwarns << "Unknown status !" << llendl;
  276. }
  277. }
  278. else if (req_id > mMessagingRequestId)
  279. {
  280. llwarns << "Invalid request id !" << llendl;
  281. }
  282. }
  283. void LLFloaterPathfindingObjects::rebuildObjectsScrollList(bool update_if_needed)
  284. {
  285. if (!mHasObjectsToBeSelected)
  286. {
  287. std::vector<LLScrollListItem*> items =
  288. mObjectsScrollList->getAllSelected();
  289. if (items.size() > 0)
  290. {
  291. mObjectsToBeSelected.reserve(items.size());
  292. for (std::vector<LLScrollListItem*>::const_iterator
  293. iter = items.begin(), end = items.end();
  294. iter != end; ++iter)
  295. {
  296. const LLScrollListItem* item = *iter;
  297. mObjectsToBeSelected.emplace_back(item->getUUID());
  298. }
  299. }
  300. }
  301. S32 orig_scroll_pos = mObjectsScrollList->getScrollPos();
  302. mObjectsScrollList->deleteAllItems();
  303. if (mObjectList && !mObjectList->isEmpty())
  304. {
  305. addObjectsIntoScrollList(mObjectList);
  306. if (mObjectsScrollList->selectMultiple(mObjectsToBeSelected) == 0)
  307. {
  308. if (update_if_needed && mRefreshListButton->getEnabled())
  309. {
  310. requestGetObjects();
  311. return;
  312. }
  313. }
  314. if (mHasObjectsToBeSelected)
  315. {
  316. mObjectsScrollList->scrollToShowSelected();
  317. }
  318. else
  319. {
  320. mObjectsScrollList->setScrollPos(orig_scroll_pos);
  321. }
  322. }
  323. mObjectsToBeSelected.clear();
  324. mHasObjectsToBeSelected = false;
  325. updateControlsOnScrollListChange();
  326. }
  327. void LLFloaterPathfindingObjects::updateControlsOnScrollListChange()
  328. {
  329. updateMessagingStatus();
  330. updateStateOnListControls();
  331. selectScrollListItemsInWorld();
  332. updateStateOnActionControls();
  333. }
  334. void LLFloaterPathfindingObjects::updateControlsOnInWorldSelectionChange()
  335. {
  336. updateStateOnActionControls();
  337. }
  338. void LLFloaterPathfindingObjects::showFloaterWithSelectionObjects()
  339. {
  340. mObjectsToBeSelected.clear();
  341. LLObjectSelectionHandle sel_handle = gSelectMgr.getSelection();
  342. if (sel_handle.notNull())
  343. {
  344. LLObjectSelection* objects = sel_handle.get();
  345. if (!objects->isEmpty())
  346. {
  347. for (LLObjectSelection::valid_iterator
  348. iter = objects->valid_begin();
  349. iter != objects->valid_end(); ++iter)
  350. {
  351. LLSelectNode* object = *iter;
  352. LLViewerObject* vobj = object->getObject();
  353. mObjectsToBeSelected.emplace_back(vobj->getID());
  354. }
  355. }
  356. }
  357. mHasObjectsToBeSelected = true;
  358. if (!getVisible())
  359. {
  360. open();
  361. setVisibleAndFrontmost();
  362. }
  363. else
  364. {
  365. rebuildObjectsScrollList(true);
  366. if (isMinimized())
  367. {
  368. setMinimized(false);
  369. }
  370. setVisibleAndFrontmost();
  371. }
  372. setFocus(true);
  373. }
  374. bool LLFloaterPathfindingObjects::showBeacons() const
  375. {
  376. return mShowBeaconCheckBox->get();
  377. }
  378. void LLFloaterPathfindingObjects::clearAllObjects()
  379. {
  380. selectNoneObjects();
  381. mObjectsScrollList->deleteAllItems();
  382. mObjectList.reset();
  383. }
  384. void LLFloaterPathfindingObjects::selectAllObjects()
  385. {
  386. mObjectsScrollList->selectAll();
  387. }
  388. void LLFloaterPathfindingObjects::selectNoneObjects()
  389. {
  390. mObjectsScrollList->deselectAllItems();
  391. }
  392. void LLFloaterPathfindingObjects::teleportToSelectedObject()
  393. {
  394. std::vector<LLScrollListItem*> items =
  395. mObjectsScrollList->getAllSelected();
  396. if (items.size() != 1)
  397. {
  398. llwarns << "Can only TP to one object !" << llendl;
  399. return;
  400. }
  401. std::vector<LLScrollListItem*>::const_reference item_ref = items.front();
  402. const LLScrollListItem* item = item_ref;
  403. LLVector3d tp_loc;
  404. LLViewerObject* vobj = gObjectList.findObject(item->getUUID());
  405. if (!vobj)
  406. {
  407. // If we cannot find the object in the viewer list, teleport to the
  408. // last reported position
  409. if (mObjectList)
  410. {
  411. const LLPathfindingObject::ptr_t objectp =
  412. mObjectList->find(item->getUUID());
  413. if (!objectp)
  414. {
  415. llwarns << "Cannot find the object, aborting !" << llendl;
  416. return;
  417. }
  418. tp_loc = gAgent.getPosGlobalFromAgent(objectp->getLocation());
  419. }
  420. else
  421. {
  422. llwarns << "NULL mObjectList, aborting !" << llendl;
  423. return;
  424. }
  425. }
  426. else
  427. {
  428. // If we can find the object in the viewer list, teleport to the
  429. // known current position
  430. tp_loc = vobj->getPositionGlobal();
  431. }
  432. gAgent.teleportViaLocationLookAt(tp_loc);
  433. }
  434. S32 LLFloaterPathfindingObjects::getNumSelectedObjects() const
  435. {
  436. return mObjectsScrollList->getNumSelected();
  437. }
  438. LLPathfindingObjectList::ptr_t LLFloaterPathfindingObjects::getSelectedObjects() const
  439. {
  440. LLPathfindingObjectList::ptr_t objects = getEmptyObjectList();
  441. std::vector<LLScrollListItem*> items =
  442. mObjectsScrollList->getAllSelected();
  443. if (!items.empty())
  444. {
  445. for (std::vector<LLScrollListItem*>::const_iterator it = items.begin(),
  446. end = items.end();
  447. it != end; ++it)
  448. {
  449. LLPathfindingObject::ptr_t objectp = findObject(*it);
  450. if (objectp)
  451. {
  452. objects->update(objectp);
  453. }
  454. }
  455. }
  456. return objects;
  457. }
  458. LLPathfindingObject::ptr_t LLFloaterPathfindingObjects::getFirstSelectedObject() const
  459. {
  460. LLPathfindingObject::ptr_t objectp;
  461. std::vector<LLScrollListItem*> items =
  462. mObjectsScrollList->getAllSelected();
  463. if (!items.empty())
  464. {
  465. objectp = findObject(items.front());
  466. }
  467. return objectp;
  468. }
  469. void LLFloaterPathfindingObjects::setMessagingState(EMessagingState state)
  470. {
  471. mMessagingState = state;
  472. updateControlsOnScrollListChange();
  473. }
  474. //static
  475. void LLFloaterPathfindingObjects::onRefreshObjectsClicked(void* data)
  476. {
  477. LLFloaterPathfindingObjects* self = (LLFloaterPathfindingObjects*)data;
  478. if (self)
  479. {
  480. self->resetLoadingNameObjectsList();
  481. self->requestGetObjects();
  482. }
  483. }
  484. //static
  485. void LLFloaterPathfindingObjects::onSelectAllObjectsClicked(void* data)
  486. {
  487. LLFloaterPathfindingObjects* self = (LLFloaterPathfindingObjects*)data;
  488. if (self)
  489. {
  490. self->selectAllObjects();
  491. }
  492. }
  493. //static
  494. void LLFloaterPathfindingObjects::onSelectNoneObjectsClicked(void* data)
  495. {
  496. LLFloaterPathfindingObjects* self = (LLFloaterPathfindingObjects*)data;
  497. if (self)
  498. {
  499. self->selectNoneObjects();
  500. }
  501. }
  502. //static
  503. void LLFloaterPathfindingObjects::onTakeClicked(void* data)
  504. {
  505. LLFloaterPathfindingObjects* self = (LLFloaterPathfindingObjects*)data;
  506. if (self)
  507. {
  508. handle_take();
  509. self->requestGetObjects();
  510. }
  511. }
  512. //static
  513. void LLFloaterPathfindingObjects::onTakeCopyClicked(void* data)
  514. {
  515. LLFloaterPathfindingObjects* self = (LLFloaterPathfindingObjects*)data;
  516. if (self)
  517. {
  518. handle_take_copy();
  519. }
  520. }
  521. //static
  522. void LLFloaterPathfindingObjects::onReturnClicked(void* data)
  523. {
  524. LLFloaterPathfindingObjects* self = (LLFloaterPathfindingObjects*)data;
  525. if (!self) return;
  526. LLNotification::Params params("PathfindingReturnMultipleItems");
  527. params.functor(boost::bind(&LLFloaterPathfindingObjects::handleReturnItemsResponse,
  528. self, _1, _2));
  529. LLSD substitutions;
  530. S32 count = self->getNumSelectedObjects();
  531. substitutions["NUM_ITEMS"] = LLSD::Integer(count);
  532. params.substitutions = substitutions;
  533. if (count == 1)
  534. {
  535. gNotifications.forceResponse(params, 0);
  536. }
  537. else if (count > 1)
  538. {
  539. gNotifications.add(params);
  540. }
  541. }
  542. //static
  543. void LLFloaterPathfindingObjects::onDeleteClicked(void* data)
  544. {
  545. LLFloaterPathfindingObjects* self = (LLFloaterPathfindingObjects*)data;
  546. if (!self) return;
  547. LLNotification::Params params("PathfindingDeleteMultipleItems");
  548. params.functor(boost::bind(&LLFloaterPathfindingObjects::handleDeleteItemsResponse,
  549. self, _1, _2));
  550. LLSD substitutions;
  551. S32 count = self->getNumSelectedObjects();
  552. substitutions["NUM_ITEMS"] = LLSD::Integer(count);
  553. params.substitutions = substitutions;
  554. if (count == 1)
  555. {
  556. gNotifications.forceResponse(params, 0);
  557. }
  558. else if (count > 1)
  559. {
  560. gNotifications.add(params);
  561. }
  562. }
  563. //static
  564. void LLFloaterPathfindingObjects::onTeleportClicked(void* data)
  565. {
  566. LLFloaterPathfindingObjects* self = (LLFloaterPathfindingObjects*)data;
  567. if (self)
  568. {
  569. self->teleportToSelectedObject();
  570. }
  571. }
  572. //static
  573. void LLFloaterPathfindingObjects::onScrollListSelectionChanged(LLUICtrl* ctrl,
  574. void* data)
  575. {
  576. LLFloaterPathfindingObjects* self = (LLFloaterPathfindingObjects*)data;
  577. if (self)
  578. {
  579. self->updateControlsOnScrollListChange();
  580. }
  581. }
  582. void LLFloaterPathfindingObjects::onInWorldSelectionListChanged()
  583. {
  584. updateControlsOnInWorldSelectionChange();
  585. }
  586. void LLFloaterPathfindingObjects::onRegionBoundaryCrossed()
  587. {
  588. requestGetObjects();
  589. }
  590. void LLFloaterPathfindingObjects::onGodLevelChange(U8 level)
  591. {
  592. requestGetObjects();
  593. }
  594. void LLFloaterPathfindingObjects::updateMessagingStatus()
  595. {
  596. std::string text;
  597. LLColor4 color = mGoodTextColor;
  598. switch (getMessagingState())
  599. {
  600. case kMessagingGetRequestSent:
  601. {
  602. static std::string get_in_progress =
  603. getString("messaging_get_inprogress");
  604. text = get_in_progress;
  605. color = mWarningTextColor;
  606. break;
  607. }
  608. case kMessagingGetError:
  609. {
  610. static std::string get_error = getString("messaging_get_error");
  611. text = get_error;
  612. color = mErrorTextColor;
  613. break;
  614. }
  615. case kMessagingSetRequestSent:
  616. {
  617. static std::string set_in_progress =
  618. getString("messaging_set_inprogress");
  619. text = set_in_progress;
  620. color = mWarningTextColor;
  621. break;
  622. }
  623. case kMessagingSetError:
  624. {
  625. static std::string set_error = getString("messaging_set_error");
  626. text = set_error;
  627. color = mErrorTextColor;
  628. break;
  629. }
  630. case kMessagingComplete:
  631. if (mObjectsScrollList->isEmpty())
  632. {
  633. static std::string not_found =
  634. getString("messaging_complete_none_found");
  635. text = not_found;
  636. }
  637. else
  638. {
  639. LLStringUtil::format_map_t args;
  640. LLLocale locale(LLStringUtil::getLocale());
  641. S32 count = mObjectsScrollList->getItemCount();
  642. std::string literal;
  643. LLLocale::getIntegerString(literal, count);
  644. args["[NUM_TOTAL]"] = literal;
  645. literal.clear();
  646. count = mObjectsScrollList->getNumSelected();
  647. LLLocale::getIntegerString(literal, count);
  648. args["[NUM_SELECTED]"] = literal;
  649. text = getString("messaging_complete_available", args);
  650. }
  651. break;
  652. case kMessagingNotEnabled:
  653. {
  654. static std::string disabled = getString("messaging_not_enabled");
  655. text = disabled;
  656. color = mErrorTextColor;
  657. break;
  658. }
  659. default:
  660. llwarns << "Unknown state !" << llendl;
  661. // Fall-through
  662. case kMessagingUnknown:
  663. {
  664. static std::string initial = getString("messaging_initial");
  665. text = initial;
  666. color = mErrorTextColor;
  667. }
  668. }
  669. mMessagingStatus->setText(text);
  670. mMessagingStatus->setColor(color);
  671. }
  672. void LLFloaterPathfindingObjects::updateStateOnListControls()
  673. {
  674. switch (getMessagingState())
  675. {
  676. case kMessagingUnknown:
  677. case kMessagingGetRequestSent:
  678. case kMessagingSetRequestSent:
  679. mRefreshListButton->setEnabled(false);
  680. mSelectAllButton->setEnabled(false);
  681. mSelectNoneButton->setEnabled(false);
  682. break;
  683. case kMessagingGetError:
  684. case kMessagingSetError:
  685. case kMessagingNotEnabled:
  686. mRefreshListButton->setEnabled(true);
  687. mSelectAllButton->setEnabled(false);
  688. mSelectNoneButton->setEnabled(false);
  689. break;
  690. case kMessagingComplete:
  691. {
  692. S32 numItems = mObjectsScrollList->getItemCount();
  693. S32 numSelectedItems = mObjectsScrollList->getNumSelected();
  694. mRefreshListButton->setEnabled(true);
  695. mSelectAllButton->setEnabled(numSelectedItems < numItems);
  696. mSelectNoneButton->setEnabled(numSelectedItems > 0);
  697. break;
  698. }
  699. default:
  700. llwarns << "Unknown state !" << llendl;
  701. }
  702. }
  703. void LLFloaterPathfindingObjects::updateStateOnActionControls()
  704. {
  705. S32 count = mObjectsScrollList->getNumSelected();
  706. bool enabled = count > 0;
  707. mShowBeaconCheckBox->setEnabled(enabled);
  708. mTakeButton->setEnabled(enabled && visible_take_object());
  709. mTakeCopyButton->setEnabled(enabled && enable_object_take_copy());
  710. mReturnButton->setEnabled(enabled && enable_object_return());
  711. mDeleteButton->setEnabled(enabled && enable_object_delete());
  712. mTeleportButton->setEnabled(count == 1);
  713. }
  714. void LLFloaterPathfindingObjects::selectScrollListItemsInWorld()
  715. {
  716. mObjectsSelection.clear();
  717. gSelectMgr.deselectAll();
  718. std::vector<LLScrollListItem*> items =
  719. mObjectsScrollList->getAllSelected();
  720. if (items.empty())
  721. {
  722. return;
  723. }
  724. std::vector<LLViewerObject*> objects;
  725. objects.reserve(items.size());
  726. for (std::vector<LLScrollListItem*>::const_iterator iter = items.begin(),
  727. end = items.end();
  728. iter != end; ++iter)
  729. {
  730. const LLScrollListItem* item = *iter;
  731. LLViewerObject* vobj = gObjectList.findObject(item->getUUID());
  732. if (vobj)
  733. {
  734. objects.push_back(vobj);
  735. }
  736. }
  737. if (!objects.empty())
  738. {
  739. mObjectsSelection = gSelectMgr.selectObjectAndFamily(objects);
  740. }
  741. }
  742. void LLFloaterPathfindingObjects::handleReturnItemsResponse(const LLSD& notif,
  743. const LLSD& response)
  744. {
  745. if (LLNotification::getSelectedOption(notif, response) == 0)
  746. {
  747. handle_object_return();
  748. requestGetObjects();
  749. }
  750. }
  751. void LLFloaterPathfindingObjects::handleDeleteItemsResponse(const LLSD& notif,
  752. const LLSD& response)
  753. {
  754. if (LLNotification::getSelectedOption(notif, response) == 0)
  755. {
  756. handle_object_delete();
  757. requestGetObjects();
  758. }
  759. }
  760. LLPathfindingObject::ptr_t LLFloaterPathfindingObjects::findObject(const LLScrollListItem* item) const
  761. {
  762. LLPathfindingObject::ptr_t objectp;
  763. const LLUUID& id = item->getUUID();
  764. if (mObjectList)
  765. {
  766. objectp = mObjectList->find(id);
  767. }
  768. else
  769. {
  770. llwarns << "NULL mObjectList !" << llendl;
  771. }
  772. return objectp;
  773. }