lltoolpie.cpp 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. /**
  2. * @file lltoolpie.cpp
  3. * @brief LLToolPie class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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 "lltoolpie.h"
  34. #include "lleditmenuhandler.h"
  35. #include "llmediaentry.h"
  36. #include "llmenugl.h"
  37. #include "llparcel.h"
  38. #include "lltrans.h"
  39. #include "llwindow.h" // For gDebugClicks
  40. #include "llagent.h"
  41. #include "llfirstuse.h"
  42. #include "llfloateravatarinfo.h"
  43. #include "llfloaterland.h"
  44. #include "llfloatertools.h"
  45. #include "llhoverview.h"
  46. #include "llhudeffectspiral.h"
  47. #include "llmutelist.h"
  48. //MK
  49. #include "mkrlinterface.h"
  50. //mk
  51. #include "llselectmgr.h"
  52. #include "lltoolfocus.h"
  53. #include "lltoolgrab.h"
  54. #include "lltoolmgr.h"
  55. #include "lltoolselect.h"
  56. #include "hbviewerautomation.h"
  57. #include "llviewercamera.h"
  58. #include "llviewercontrol.h"
  59. #include "llviewermedia.h"
  60. #include "llviewermediafocus.h"
  61. #include "llviewermenu.h"
  62. #include "llviewerobjectlist.h"
  63. #include "llviewerparcelmedia.h"
  64. #include "llviewerparcelmgr.h"
  65. #include "llvoavatarself.h"
  66. #include "llvovolume.h"
  67. #include "llworld.h"
  68. #include "llweb.h"
  69. extern void handle_buy(void*);
  70. static void handle_click_action_play();
  71. static void handle_click_action_open_media(LLPointer<LLViewerObject> objectp);
  72. static ECursorType cursor_from_parcel_media(U8 click_action);
  73. LLToolPie gToolPie;
  74. LLToolPie::LLToolPie()
  75. : LLTool("Pie"),
  76. mPieMouseButtonDown(false),
  77. mGrabMouseButtonDown(false),
  78. mClickAction(0)
  79. {
  80. }
  81. bool LLToolPie::handleMouseDown(S32 x, S32 y, MASK mask)
  82. {
  83. static LLCachedControl<bool> pick_transparent(gSavedSettings,
  84. "AllowPickTransparent");
  85. gViewerWindowp->pickAsync(x, y, mask, leftMouseCallback,
  86. // maybe pick transparent (normally no)
  87. pick_transparent,
  88. // not rigged, not particles, get surface info
  89. false, false, true);
  90. mGrabMouseButtonDown = true;
  91. return true;
  92. }
  93. //static
  94. void LLToolPie::leftMouseCallback(const LLPickInfo& pick_info)
  95. {
  96. gToolPie.mPick = pick_info;
  97. gToolPie.handleLeftClickPick();
  98. }
  99. bool LLToolPie::handleLeftClickPick()
  100. {
  101. S32 x = mPick.mMousePt.mX;
  102. S32 y = mPick.mMousePt.mY;
  103. MASK mask = mPick.mKeyMask;
  104. if (handleMediaClick(mPick))
  105. {
  106. return true;
  107. }
  108. if (mPick.mPickType == LLPickInfo::PICK_PARCEL_WALL)
  109. {
  110. LLParcel* parcelp = gViewerParcelMgr.getCollisionParcel();
  111. if (parcelp)
  112. {
  113. gViewerParcelMgr.selectCollisionParcel();
  114. if (parcelp->getParcelFlag(PF_USE_PASS_LIST) &&
  115. !gViewerParcelMgr.isCollisionBanned())
  116. {
  117. // If selling passes, just buy one
  118. void* deselect_when_done = (void*)true;
  119. LLPanelLandGeneral::onClickBuyPass(deselect_when_done);
  120. }
  121. else
  122. //MK
  123. if (!gRLenabled || !gRLInterface.mContainsShowloc)
  124. //mk
  125. {
  126. // Not selling passes, get info
  127. LLFloaterLand::showInstance();
  128. }
  129. }
  130. gFocusMgr.setKeyboardFocus(NULL);
  131. return LLTool::handleMouseDown(x, y, mask);
  132. }
  133. if (mPick.mPickType != LLPickInfo::PICK_LAND)
  134. {
  135. gViewerParcelMgr.deselectLand();
  136. }
  137. // Did not click in any UI object, so must have clicked in the world
  138. LLViewerObject* parent = NULL;
  139. LLViewerObject* object = mPick.getObject();
  140. if (object)
  141. {
  142. parent = object->getRootEdit();
  143. }
  144. // If we have a special action, do it.
  145. if (useClickAction(mask, object, parent))
  146. {
  147. //MK
  148. if (gRLenabled && !gRLInterface.canTouch(object, mPick.mIntersection))
  149. {
  150. return true;
  151. }
  152. //mk
  153. mClickAction = 0;
  154. if (object && object->getClickAction())
  155. {
  156. mClickAction = object->getClickAction();
  157. }
  158. else if (parent && parent->getClickAction())
  159. {
  160. mClickAction = parent->getClickAction();
  161. }
  162. switch (mClickAction)
  163. {
  164. case CLICK_ACTION_SIT:
  165. {
  166. if (isAgentAvatarValid() && !gAgentAvatarp->mIsSitting &&
  167. gSavedSettings.getBool("LeftClickToSit"))
  168. {
  169. // Agent is not already sitting
  170. handle_sit_or_stand();
  171. // Put focus in world when sitting on an object
  172. gFocusMgr.setKeyboardFocus(NULL);
  173. return true;
  174. }
  175. break; // else nothing (fall through to touch)
  176. }
  177. case CLICK_ACTION_PAY:
  178. {
  179. if (((object && object->flagTakesMoney()) ||
  180. (parent && parent->flagTakesMoney())) &&
  181. gSavedSettings.getBool("LeftClickToPay"))
  182. {
  183. // Pay event goes to object actually clicked on
  184. mClickActionObject = object;
  185. mLeftClickSelection =
  186. LLToolSelect::handleObjectSelection(mPick, false,
  187. true);
  188. if (gSelectMgr.selectGetAllValid())
  189. {
  190. // Call this right away, since we have all the info we
  191. // need to continue the action
  192. selectionPropertiesReceived();
  193. }
  194. return true;
  195. }
  196. break; // Else nothing (fall through to touch)
  197. }
  198. case CLICK_ACTION_BUY:
  199. {
  200. if (gSavedSettings.getBool("LeftClickToPay"))
  201. {
  202. mClickActionObject = parent;
  203. mLeftClickSelection =
  204. LLToolSelect::handleObjectSelection(mPick, false,
  205. true, true);
  206. if (gSelectMgr.selectGetAllValid())
  207. {
  208. // Call this right away, since we have all the info we
  209. // need to continue the action
  210. selectionPropertiesReceived();
  211. }
  212. return true;
  213. }
  214. break; // Else nothing (fall through to touch)
  215. }
  216. case CLICK_ACTION_OPEN:
  217. {
  218. if (parent && parent->allowOpen() &&
  219. gSavedSettings.getBool("LeftClickToOpen"))
  220. {
  221. mClickActionObject = parent;
  222. mLeftClickSelection =
  223. LLToolSelect::handleObjectSelection(mPick, false,
  224. true, true);
  225. if (gSelectMgr.selectGetAllValid())
  226. {
  227. // Call this right away, since we have all the info we
  228. // need to continue the action
  229. selectionPropertiesReceived();
  230. }
  231. return true;
  232. }
  233. break; // Else nothing (fall through to touch)
  234. }
  235. case CLICK_ACTION_PLAY:
  236. {
  237. if (gSavedSettings.getBool("LeftClickToPlay"))
  238. {
  239. handle_click_action_play();
  240. return true;
  241. }
  242. }
  243. case CLICK_ACTION_OPEN_MEDIA:
  244. {
  245. if (gSavedSettings.getBool("LeftClickToPlay"))
  246. {
  247. // mClickActionObject = object;
  248. handle_click_action_open_media(object);
  249. return true;
  250. }
  251. break; // Else nothing (fall through to touch)
  252. }
  253. case CLICK_ACTION_ZOOM:
  254. {
  255. if (gSavedSettings.getBool("LeftClickToZoom"))
  256. {
  257. constexpr F32 PADDING_FACTOR = 2.f;
  258. LLViewerObject* object =
  259. gObjectList.findObject(mPick.mObjectID);
  260. if (object)
  261. {
  262. gAgent.setFocusOnAvatar(false);
  263. LLBBox bbox = object->getBoundingBoxAgent();
  264. F32 aspect = gViewerCamera.getAspect();
  265. F32 view = gViewerCamera.getView();
  266. F32 angle_of_view = llmax(0.1f,
  267. aspect > 1.f ? view * aspect
  268. : view);
  269. F32 distance = bbox.getExtentLocal().length() *
  270. PADDING_FACTOR / atanf(angle_of_view);
  271. LLVector3 obj_to_cam = gViewerCamera.getOrigin() -
  272. bbox.getCenterAgent();
  273. obj_to_cam.normalize();
  274. LLVector3d center_global =
  275. gAgent.getPosGlobalFromAgent(bbox.getCenterAgent());
  276. gAgent.setCameraPosAndFocusGlobal(center_global +
  277. LLVector3d(obj_to_cam *
  278. distance),
  279. center_global,
  280. mPick.mObjectID);
  281. }
  282. return true;
  283. }
  284. break; // Else nothing (fall through to touch)
  285. }
  286. case CLICK_ACTION_DISABLED:
  287. return true;
  288. case CLICK_ACTION_TOUCH:
  289. default:
  290. break; // fall through to touch
  291. }
  292. }
  293. // Put focus back "in world"
  294. gFocusMgr.setKeyboardFocus(NULL);
  295. // Switch to grab tool if physical or triggerable
  296. bool touchable = (object && object->flagHandleTouch()) ||
  297. (parent && parent->flagHandleTouch());
  298. if (object && !object->isAvatar() &&
  299. (touchable || object->flagUsePhysics() ||
  300. (parent && !parent->isAvatar() && parent->flagUsePhysics())))
  301. {
  302. gGrabTransientTool = this;
  303. gToolMgr.getCurrentToolset()->selectTool(&gToolGrab);
  304. return gToolGrab.handleObjectHit(mPick);
  305. }
  306. if (!object)
  307. {
  308. LLHUDIcon* icon = mPick.mHUDIcon;
  309. LLViewerObject* src_obj = icon ? icon->getSourceObject() : NULL;
  310. if (src_obj)
  311. {
  312. const LLUUID& object_id = src_obj->getID();
  313. icon->fireClickedCallback(object_id);
  314. }
  315. }
  316. if (gSavedSettings.getBool("LeftClickSteersAvatar"))
  317. {
  318. // Mouse already released
  319. if (!mGrabMouseButtonDown)
  320. {
  321. return true;
  322. }
  323. while (object && object->isAttachment() && !object->flagHandleTouch())
  324. {
  325. // Do not pick avatar through hud attachment
  326. if (object->isHUDAttachment())
  327. {
  328. break;
  329. }
  330. object = (LLViewerObject*)object->getParent();
  331. }
  332. if (object && object == gAgentAvatarp)
  333. {
  334. // We left clicked on avatar, switch to focus mode
  335. gToolMgr.setTransientTool(&gToolFocus);
  336. gViewerWindowp->hideCursor();
  337. gToolFocus.setMouseCapture(true);
  338. gToolFocus.pickCallback(mPick);
  339. gAgent.setFocusOnAvatar();
  340. return true;
  341. }
  342. }
  343. // Could be first left-click on nothing
  344. LLFirstUse::useLeftClickNoHit();
  345. return LLTool::handleMouseDown(x, y, mask);
  346. }
  347. bool LLToolPie::handleRightMouseDown(S32 x, S32 y, MASK mask)
  348. {
  349. //MK
  350. // HACK : if alt-right-clicking and not in mouselook, HUDs are passed
  351. // through and we risk right-clicking in-world => discard this click
  352. if (gRLenabled && (mask & MASK_ALT) &&
  353. gAgent.getCameraMode() != CAMERA_MODE_MOUSELOOK)
  354. {
  355. handleMouseDown(x, y, mask);
  356. return true;
  357. }
  358. //mk
  359. static LLCachedControl<bool> pick_rigged_meshes(gSavedSettings,
  360. "AllowPickRiggedMeshes");
  361. static LLCachedControl<bool> pick_particles(gSavedSettings,
  362. "AllowPickParticles");
  363. mPieMouseButtonDown = true;
  364. // Note: we do not pick transparent so users cannot "pay" transparent
  365. // objects.
  366. gViewerWindowp->pickAsync(x, y, mask, rightMouseCallback,
  367. // do not (always) pick transparent
  368. false,
  369. // maybe pick rigged meshes or particles
  370. pick_rigged_meshes, pick_particles,
  371. // get surface info
  372. true);
  373. // Do not steal focus from UI
  374. return false;
  375. }
  376. bool LLToolPie::handleScrollWheel(S32 x, S32 y, S32 clicks)
  377. {
  378. return LLViewerMediaFocus::getInstance()->handleScrollWheel(x, y, clicks);
  379. }
  380. //static
  381. void LLToolPie::rightMouseCallback(const LLPickInfo& pick_info)
  382. {
  383. gToolPie.mPick = pick_info;
  384. gToolPie.handleRightClickPick();
  385. }
  386. bool LLToolPie::handleRightClickPick()
  387. {
  388. S32 x = mPick.mMousePt.mX;
  389. S32 y = mPick.mMousePt.mY;
  390. MASK mask = mPick.mKeyMask;
  391. LLViewerMediaFocus::getInstance()->clearFocus();
  392. if (mPick.mPickType != LLPickInfo::PICK_LAND)
  393. {
  394. gViewerParcelMgr.deselectLand();
  395. }
  396. // Put focus back "in world"
  397. gFocusMgr.setKeyboardFocus(NULL);
  398. // Cannot ignore children here.
  399. LLToolSelect::handleObjectSelection(mPick, false, true);
  400. if (!gMenuHolderp)
  401. {
  402. // Either at early initialization or late quitting stage
  403. return true;
  404. }
  405. // Did not click in any UI object, so must have clicked in-world
  406. LLViewerObject* object = mPick.getObject();
  407. if (object && object->isAttachment() && !object->isHUDAttachment() &&
  408. !object->permYouOwner())
  409. {
  410. // Find the avatar corresponding to any attachment object we do not own
  411. while (object->isAttachment())
  412. {
  413. object = (LLViewerObject*)object->getParent();
  414. if (!object) return false; // Orphaned object ?
  415. }
  416. }
  417. if (mask == MASK_SHIFT && gLuaPiep && gLuaPiep->onPieMenu(mPick, object))
  418. {
  419. gLuaPiep->show(x, y, mPieMouseButtonDown);
  420. LLTool::handleRightMouseDown(x, y, mask);
  421. return true;
  422. }
  423. // Spawn the pie menu
  424. if ((!object || !object->isHUDAttachment()) && // HUDs got priority !
  425. gPieParticlep && mPick.mPickParticle &&
  426. mPick.mParticleOwnerID.notNull())
  427. {
  428. gPieParticlep->show(x, y, mPieMouseButtonDown);
  429. return true;
  430. }
  431. else if (mPick.mPickType == LLPickInfo::PICK_LAND)
  432. {
  433. LLParcelSelectionHandle selection =
  434. gViewerParcelMgr.selectParcelAt(mPick.mPosGlobal);
  435. gMenuHolderp->setParcelSelection(selection);
  436. gPieLandp->show(x, y, mPieMouseButtonDown);
  437. // VEFFECT: ShowPie
  438. LLHUDEffectSpiral::sphereAtPosition(mPick.mPosGlobal);
  439. }
  440. else if (mPick.mObjectID == gAgentID)
  441. {
  442. LLMenuItemGL* item =
  443. gPieSelfp->getChild<LLMenuItemGL>("Self Sit", true, false);
  444. if (item)
  445. {
  446. if (isAgentAvatarValid() && gAgentAvatarp->mIsSitting)
  447. {
  448. item->setValue(LLTrans::getString("stand_up"));
  449. }
  450. else
  451. {
  452. item->setValue(LLTrans::getString("sit_here"));
  453. }
  454. }
  455. gPieSelfp->show(x, y, mPieMouseButtonDown);
  456. }
  457. else if (object)
  458. {
  459. if (gRLenabled && !object->isAvatar() && LLFloaterTools::isVisible() &&
  460. !gRLInterface.canEdit(object))
  461. {
  462. gFloaterToolsp->close();
  463. }
  464. gMenuHolderp->setObjectSelection(gSelectMgr.getSelection());
  465. if (object->isAvatar())
  466. {
  467. // Object is an avatar, so check for mute by id.
  468. LLVOAvatar* avatar = (LLVOAvatar*)object;
  469. LLUUID id = avatar->getID();
  470. std::string name = avatar->getFullname();
  471. if (gMutesPieMenup)
  472. {
  473. bool fully_muted = LLMuteList::isMuted(id, name);
  474. LLMenuItemGL* item =
  475. gMutesPieMenup->getChild<LLMenuItemGL>("Avatar Mute",
  476. true, false);
  477. if (item)
  478. {
  479. if (fully_muted)
  480. {
  481. item->setValue(LLTrans::getString("unmute_all"));
  482. }
  483. else
  484. {
  485. item->setValue(LLTrans::getString("mute_all"));
  486. }
  487. }
  488. item = gMutesPieMenup->getChild<LLMenuItemGL>("Avatar Mute chat",
  489. true, false);
  490. if (item)
  491. {
  492. if (LLMuteList::isMuted(id, name, LLMute::flagTextChat))
  493. {
  494. item->setValue(LLTrans::getString("unmute_chat"));
  495. }
  496. else
  497. {
  498. item->setValue(LLTrans::getString("mute_chat"));
  499. }
  500. }
  501. item = gMutesPieMenup->getChild<LLMenuItemGL>("Avatar Mute voice",
  502. true, false);
  503. if (item)
  504. {
  505. if (LLMuteList::isMuted(id, name, LLMute::flagVoiceChat))
  506. {
  507. item->setValue(LLTrans::getString("unmute_voice"));
  508. }
  509. else
  510. {
  511. item->setValue(LLTrans::getString("mute_voice"));
  512. }
  513. }
  514. item = gMutesPieMenup->getChild<LLMenuItemGL>("Avatar Mute sounds",
  515. true, false);
  516. if (item)
  517. {
  518. if (LLMuteList::isMuted(id, name, LLMute::flagObjectSounds))
  519. {
  520. item->setValue(LLTrans::getString("unmute_sounds"));
  521. }
  522. else
  523. {
  524. item->setValue(LLTrans::getString("mute_sounds"));
  525. }
  526. }
  527. item = gMutesPieMenup->getChild<LLMenuItemGL>("Avatar Mute particles",
  528. true, false);
  529. if (item)
  530. {
  531. if (LLMuteList::isMuted(id, name, LLMute::flagParticles))
  532. {
  533. item->setValue(LLTrans::getString("unmute_particles"));
  534. }
  535. else
  536. {
  537. item->setValue(LLTrans::getString("mute_particles"));
  538. }
  539. }
  540. LLVOAvatar::VisualMuteSettings val =
  541. avatar->getVisualMuteSettings();
  542. bool settings_available = LLVOAvatar::sUseImpostors;
  543. //MK
  544. settings_available = settings_available &&
  545. (!gRLenabled || !avatar->isRLVMuted());
  546. //mk
  547. item = gMutesPieMenup->getChild<LLMenuItemGL>("Avatar Always Render",
  548. true, false);
  549. if (item)
  550. {
  551. item->setEnabled(!fully_muted && settings_available &&
  552. val != LLVOAvatar::AV_ALWAYS_RENDER);
  553. }
  554. item = gMutesPieMenup->getChild<LLMenuItemGL>("Avatar Normal Render",
  555. true, false);
  556. if (item)
  557. {
  558. item->setEnabled(!fully_muted && settings_available &&
  559. val != LLVOAvatar::AV_RENDER_NORMALLY);
  560. }
  561. item = gMutesPieMenup->getChild<LLMenuItemGL>("Avatar Never Render",
  562. true, false);
  563. if (item)
  564. {
  565. item->setEnabled(!fully_muted && settings_available &&
  566. val != LLVOAvatar::AV_DO_NOT_RENDER);
  567. }
  568. }
  569. gPieAvatarp->show(x, y, mPieMouseButtonDown);
  570. }
  571. else if (object->isAttachment())
  572. {
  573. LLMenuItemGL* item =
  574. gPieAttachmentp->getChild<LLMenuItemGL>("Self Sit Attachment",
  575. true, false);
  576. if (item)
  577. {
  578. if (isAgentAvatarValid() && gAgentAvatarp->mIsSitting)
  579. {
  580. item->setValue(LLTrans::getString("stand_up"));
  581. }
  582. else
  583. {
  584. item->setValue(LLTrans::getString("sit_here"));
  585. }
  586. }
  587. gPieAttachmentp->show(x, y, mPieMouseButtonDown);
  588. }
  589. else
  590. {
  591. #if 0 // Sadly, the object name is unknown/empty when the pie menu is
  592. // built...
  593. std::string name;
  594. LLSelectNode* node = gSelectMgr.getSelection()->getFirstRootNode();
  595. if (node)
  596. {
  597. name = node->mName;
  598. }
  599. #endif
  600. if (gPieObjectMutep)
  601. {
  602. LLMenuItemGL* item =
  603. gPieObjectMutep->getChild<LLMenuItemGL>("Mute object",
  604. true, false);
  605. if (item)
  606. {
  607. if (LLMuteList::isMuted(object->getID()))
  608. {
  609. item->setValue(LLTrans::getString("unmute"));
  610. }
  611. else
  612. {
  613. item->setValue(LLTrans::getString("mute"));
  614. }
  615. }
  616. #if 0 // Sadly, the object name is unknown/empty when the pie menu is
  617. // built... So, we cannot determine wether this object is
  618. // already muted by name of not.
  619. item = gPieObjectMutep->getChild<LLMenuItemGL>("Mute by name",
  620. true, false);
  621. if (item)
  622. {
  623. if (LLMuteList::isMuted(LLUUID::null, name))
  624. {
  625. item->setValue(LLTrans::getString("unmute_by_name"));
  626. }
  627. else
  628. {
  629. item->setValue(LLTrans::getString("mute_by_name"));
  630. }
  631. }
  632. #endif
  633. }
  634. #if 0 // Avatar puppets "jelly-dollifying" does not work anyway...
  635. LLVOAvatarPuppet* puppet = object->getPuppetAvatar();
  636. if (puppet && gPieObjectMutep)
  637. {
  638. LLVOAvatar::VisualMuteSettings val =
  639. puppet->getVisualMuteSettings();
  640. bool settings_available = LLVOAvatar::sUseImpostors;
  641. //MK
  642. settings_available = settings_available &&
  643. (!gRLenabled || !puppet->isRLVMuted());
  644. //mk
  645. LLMenuItemGL* item =
  646. gPieObjectMutep->getChild<LLMenuItemGL>("Puppet Always Render",
  647. true, false);
  648. if (item)
  649. {
  650. item->setEnabled(settings_available &&
  651. val != LLVOAvatar::AV_ALWAYS_RENDER);
  652. }
  653. item = gPieObjectMutep->getChild<LLMenuItemGL>("Puppet Normal Render",
  654. true, false);
  655. if (item)
  656. {
  657. item->setEnabled(settings_available &&
  658. val != LLVOAvatar::AV_RENDER_NORMALLY);
  659. }
  660. item = gPieObjectMutep->getChild<LLMenuItemGL>("Puppet Never Render",
  661. true, false);
  662. if (item)
  663. {
  664. item->setEnabled(settings_available &&
  665. val != LLVOAvatar::AV_DO_NOT_RENDER);
  666. }
  667. }
  668. #endif
  669. gPieObjectp->show(x, y, mPieMouseButtonDown);
  670. // VEFFECT: ShowPie object. Do not show when you click on someone
  671. // else: it could freak them out.
  672. LLHUDEffectSpiral::sphereAtPosition(mPick.mPosGlobal);
  673. }
  674. }
  675. // Ignore return value
  676. LLTool::handleRightMouseDown(x, y, mask);
  677. // We handled the event.
  678. return true;
  679. }
  680. bool LLToolPie::useClickAction(MASK mask, LLViewerObject* object,
  681. LLViewerObject* parent)
  682. {
  683. if (mask != MASK_NONE || !object || object->isAttachment() ||
  684. !LLPrimitive::isPrimitive(object->getPCode()))
  685. {
  686. return false;
  687. }
  688. U8 object_action = object->getClickAction();
  689. U8 parent_action = parent ? parent->getClickAction() : 0;
  690. return (object_action && object_action != CLICK_ACTION_DISABLED) ||
  691. (parent_action && parent_action != CLICK_ACTION_DISABLED);
  692. }
  693. U8 final_click_action(LLViewerObject* obj)
  694. {
  695. if (!obj || obj->isAttachment())
  696. {
  697. return CLICK_ACTION_NONE;
  698. }
  699. U8 object_action = obj->getClickAction();
  700. if (object_action)
  701. {
  702. return object_action;
  703. }
  704. // Note: at this point object_action = 0 = CLICK_ACTION_TOUCH
  705. LLViewerObject* parent = obj->getRootEdit();
  706. if (!parent)
  707. {
  708. return CLICK_ACTION_TOUCH;
  709. }
  710. U8 parent_action = parent->getClickAction();
  711. // CLICK_ACTION_DISABLED ("None" in UI) is intended for child action to
  712. // override parents action when assigned to parent or to child.
  713. if (/*parent_action && */parent_action != CLICK_ACTION_DISABLED)
  714. {
  715. // Note: no need to test for parent_action != 0 because
  716. // CLICK_ACTION_TOUCH = 0, which would be returned below anyway.
  717. return parent_action;
  718. }
  719. return CLICK_ACTION_TOUCH;
  720. }
  721. ECursorType cursor_from_object(LLViewerObject* object)
  722. {
  723. LLViewerObject* parent = NULL;
  724. if (object)
  725. {
  726. parent = object->getRootEdit();
  727. }
  728. U8 click_action = final_click_action(object);
  729. ECursorType cursor = UI_CURSOR_ARROW;
  730. switch (click_action)
  731. {
  732. case CLICK_ACTION_SIT:
  733. // Not already sitting ?
  734. if (isAgentAvatarValid() && !gAgentAvatarp->mIsSitting)
  735. {
  736. cursor = UI_CURSOR_TOOLSIT;
  737. }
  738. break;
  739. case CLICK_ACTION_BUY:
  740. cursor = UI_CURSOR_TOOLBUY;
  741. break;
  742. case CLICK_ACTION_OPEN:
  743. // Open always opens the parent.
  744. if (parent && parent->allowOpen())
  745. {
  746. cursor = UI_CURSOR_TOOLOPEN;
  747. }
  748. break;
  749. case CLICK_ACTION_PAY:
  750. if ((object && object->flagTakesMoney()) ||
  751. (parent && parent->flagTakesMoney()))
  752. {
  753. cursor = UI_CURSOR_TOOLPAY;
  754. }
  755. break;
  756. case CLICK_ACTION_ZOOM:
  757. cursor = UI_CURSOR_TOOLZOOMIN;
  758. break;
  759. case CLICK_ACTION_PLAY:
  760. case CLICK_ACTION_OPEN_MEDIA:
  761. cursor = cursor_from_parcel_media(click_action);
  762. break;
  763. default:
  764. break;
  765. }
  766. return cursor;
  767. }
  768. void LLToolPie::resetSelection()
  769. {
  770. mLeftClickSelection = NULL;
  771. mClickActionObject = NULL;
  772. mClickAction = 0;
  773. }
  774. //static
  775. void LLToolPie::selectionPropertiesReceived()
  776. {
  777. // Make sure all data has been received since this function will be called
  778. // repeatedly as the data comes in.
  779. if (!gSelectMgr.selectGetAllValid())
  780. {
  781. return;
  782. }
  783. LLObjectSelection* selection = gToolPie.getLeftClickSelection();
  784. if (selection)
  785. {
  786. LLViewerObject* selected_object = selection->getPrimaryObject();
  787. // since we don't currently have a way to lock a selection, it could
  788. // have changed after we initially clicked on the object
  789. if (selected_object == gToolPie.getClickActionObject())
  790. {
  791. U8 click_action = gToolPie.getClickAction();
  792. switch (click_action)
  793. {
  794. case CLICK_ACTION_BUY:
  795. // When we get object properties after left-clicking on an
  796. // object with left-click = buy, if it's the same object, do
  797. // the buy.
  798. handle_buy(NULL);
  799. break;
  800. case CLICK_ACTION_PAY:
  801. handle_give_money_dialog();
  802. break;
  803. case CLICK_ACTION_OPEN:
  804. //MK
  805. if (gRLenabled &&
  806. !gRLInterface.canEdit(gSelectMgr.getSelection()->getPrimaryObject()))
  807. {
  808. return;
  809. }
  810. if (gRLenabled &&
  811. !gRLInterface.canTouchFar(selected_object,
  812. gToolPie.getPick().mIntersection))
  813. {
  814. return;
  815. }
  816. //mk
  817. handle_object_open();
  818. break;
  819. default:
  820. break;
  821. }
  822. }
  823. }
  824. gToolPie.resetSelection();
  825. }
  826. bool LLToolPie::handleHover(S32 x, S32 y, MASK mask)
  827. {
  828. LLPickInfo hover_pick = gViewerWindowp->getHoverPick();
  829. LLViewerObject* object = hover_pick.getObject();
  830. LLViewerObject* parent = object ? object->getRootEdit() : NULL;
  831. if (handleMediaHover(hover_pick))
  832. {
  833. // Cursor set by media object
  834. // *TODO: implement glow-like highlighting ?
  835. }
  836. else if (object)
  837. {
  838. if (useClickAction(mask, object, parent))
  839. {
  840. ECursorType cursor = cursor_from_object(object);
  841. gWindowp->setCursor(cursor);
  842. }
  843. else if ((!object->isAvatar() && object->flagUsePhysics()) ||
  844. (parent && !parent->isAvatar() && parent->flagUsePhysics()))
  845. {
  846. gWindowp->setCursor(UI_CURSOR_TOOLGRAB);
  847. }
  848. else if ((object->getClickAction() != CLICK_ACTION_DISABLED ||
  849. !object->isAttachment()) &&
  850. (object->flagHandleTouch() ||
  851. (parent && parent->flagHandleTouch())))
  852. {
  853. gWindowp->setCursor(UI_CURSOR_HAND);
  854. }
  855. else
  856. {
  857. gWindowp->setCursor(UI_CURSOR_ARROW);
  858. }
  859. }
  860. else
  861. {
  862. gWindowp->setCursor(UI_CURSOR_ARROW);
  863. LLViewerMediaFocus::getInstance()->clearHover();
  864. }
  865. return true;
  866. }
  867. bool LLToolPie::handleMouseUp(S32 x, S32 y, MASK mask)
  868. {
  869. LLViewerObject* obj = mPick.getObject();
  870. U8 click_action = final_click_action(obj);
  871. if (click_action == CLICK_ACTION_BUY || click_action == CLICK_ACTION_PAY ||
  872. click_action == CLICK_ACTION_OPEN)
  873. {
  874. // Because these actions open UI dialogs, we won't change the cursor
  875. // again until the next hover and GL pick over the world. Keep the
  876. // cursor an arrow, assuming that after the user moves off the UI, they
  877. // won't be on the same object anymore.
  878. gWindowp->setCursor(UI_CURSOR_ARROW);
  879. // Make sure the hover-picked object is ignored.
  880. gHoverViewp->resetLastHoverObject();
  881. }
  882. mGrabMouseButtonDown = false;
  883. gToolMgr.clearTransientTool();
  884. // Maybe look at object/person clicked on
  885. gAgent.setLookAt(LOOKAT_TARGET_CONVERSATION, obj);
  886. return LLTool::handleMouseUp(x, y, mask);
  887. }
  888. bool LLToolPie::handleRightMouseUp(S32 x, S32 y, MASK mask)
  889. {
  890. mPieMouseButtonDown = false;
  891. gToolMgr.clearTransientTool();
  892. return LLTool::handleRightMouseUp(x, y, mask);
  893. }
  894. bool LLToolPie::handleDoubleClick(S32 x, S32 y, MASK mask)
  895. {
  896. if (gDebugClicks)
  897. {
  898. llinfos << "LLToolPie handleDoubleClick (becoming mouseDown)"
  899. << llendl;
  900. }
  901. if (handleMediaDblClick(mPick))
  902. {
  903. return true;
  904. }
  905. if (mPick.mPosGlobal.isExactlyZero())
  906. {
  907. return false;
  908. }
  909. LLViewerObject* objp = mPick.getObject();
  910. LLViewerObject* parentp = objp ? objp->getRootEdit() : NULL;
  911. bool is_in_world = mPick.mObjectID.notNull() && objp &&
  912. !objp->isHUDAttachment();
  913. bool is_land = mPick.mPickType == LLPickInfo::PICK_LAND;
  914. bool has_touch_handler = false;
  915. bool has_click_action = false;
  916. if (!is_land && is_in_world && // Note: if is_in_world then objp != NULL
  917. !gSavedSettings.getBool("DoubleClickScriptedObject"))
  918. {
  919. has_touch_handler = objp->flagHandleTouch() ||
  920. (parentp && parentp->flagHandleTouch());
  921. has_click_action = final_click_action(objp);
  922. if (!has_touch_handler || !has_click_action)
  923. {
  924. // Is media playing on this face ?
  925. const LLTextureEntry* tep = objp->getTE(mPick.mObjectFace);
  926. viewer_media_t mediap =
  927. LLViewerMedia::getMediaImplFromTextureEntry(tep);
  928. if (mediap.notNull() && mediap->hasMedia())
  929. {
  930. has_touch_handler = has_click_action = true;
  931. }
  932. }
  933. }
  934. if (is_land || (is_in_world && !has_touch_handler && !has_click_action))
  935. {
  936. U32 action = gSavedSettings.getU32("DoubleClickAction");
  937. if (action == 1)
  938. {
  939. handle_go_to();
  940. return true;
  941. }
  942. else if (action == 2 && isAgentAvatarValid()
  943. //MK
  944. && !(gRLenabled && gRLInterface.contains ("tploc")))
  945. //mk
  946. {
  947. LLVector3d pos = mPick.mPosGlobal;
  948. pos.mdV[VZ] += gAgentAvatarp->getPelvisToFoot();
  949. gAgent.teleportViaLocationLookAt(pos);
  950. return true;
  951. }
  952. }
  953. return false;
  954. }
  955. void LLToolPie::handleDeselect()
  956. {
  957. if (hasMouseCapture())
  958. {
  959. setMouseCapture(false); // Calls onMouseCaptureLost() indirectly
  960. }
  961. // Remove temporary selection for pie menu
  962. gSelectMgr.validateSelection();
  963. }
  964. LLTool* LLToolPie::getOverrideTool(MASK mask)
  965. {
  966. if (mask == MASK_CONTROL || mask == (MASK_CONTROL | MASK_SHIFT))
  967. {
  968. return &gToolGrab;
  969. }
  970. return LLTool::getOverrideTool(mask);
  971. }
  972. void LLToolPie::stopEditing()
  973. {
  974. if (hasMouseCapture())
  975. {
  976. setMouseCapture(false); // Calls onMouseCaptureLost() indirectly
  977. }
  978. }
  979. static void handle_click_action_play()
  980. {
  981. LLViewerMediaImpl::EMediaStatus status = LLViewerParcelMedia::getStatus();
  982. switch (status)
  983. {
  984. case LLViewerMediaImpl::MEDIA_PLAYING:
  985. LLViewerParcelMedia::pause();
  986. break;
  987. case LLViewerMediaImpl::MEDIA_PAUSED:
  988. LLViewerParcelMedia::start();
  989. break;
  990. default:
  991. LLViewerParcelMedia::play();
  992. }
  993. }
  994. bool LLToolPie::handleMediaClick(const LLPickInfo& pick)
  995. {
  996. // *FIXME: how do we handle object in different parcel than us ?
  997. LLParcel* parcelp = gViewerParcelMgr.getAgentParcel();
  998. LLPointer<LLViewerObject> objectp = pick.getObject();
  999. LLViewerMediaFocus* focusp = LLViewerMediaFocus::getInstance();
  1000. if (!LLVOVolume::sObjectMediaClient || !parcelp || objectp.isNull() ||
  1001. pick.mObjectFace < 0 || pick.mObjectFace >= objectp->getNumTEs())
  1002. {
  1003. focusp->clearFocus();
  1004. return false;
  1005. }
  1006. // Does this face have media ?
  1007. const LLTextureEntry* tep = objectp->getTE(pick.mObjectFace);
  1008. viewer_media_t mediap = LLViewerMedia::getMediaImplFromTextureEntry(tep);
  1009. if (mediap.isNull() || !mediap->hasMedia())
  1010. {
  1011. focusp->clearFocus();
  1012. return false;
  1013. }
  1014. if (!focusp->isFocusedOnFace(pick.getObject(), pick.mObjectFace))
  1015. {
  1016. LL_DEBUGS("Media") << (mediap.isNull() ? "Media impl is NULL"
  1017. : "New focus detected")
  1018. << ", focusing on media face." << LL_ENDL;
  1019. focusp->setFocusFace(true, pick.getObject(), pick.mObjectFace,
  1020. mediap, pick.mNormal);
  1021. }
  1022. else if (gKeyboardp)
  1023. {
  1024. // Make sure keyboard focus is set to the media focus object.
  1025. gFocusMgr.setKeyboardFocus(focusp);
  1026. gEditMenuHandlerp = focusp->getFocusedMediaImpl();
  1027. mediap->mouseDown(pick.mUVCoords, gKeyboardp->currentMask(true));
  1028. // The mouse-up will happen when capture is lost
  1029. mediap->mouseCapture();
  1030. LL_DEBUGS("Media") << "Mouse down event passed to media" << LL_ENDL;
  1031. }
  1032. return true;
  1033. }
  1034. bool LLToolPie::handleMediaDblClick(const LLPickInfo& pick)
  1035. {
  1036. // *FIXME: how do we handle object in different parcel than us ?
  1037. LLParcel* parcelp = gViewerParcelMgr.getAgentParcel();
  1038. if (!parcelp)
  1039. {
  1040. return false;
  1041. }
  1042. LLViewerMediaFocus* focusp = LLViewerMediaFocus::getInstance();
  1043. LLPointer<LLViewerObject> objectp = mPick.getObject();
  1044. if (!LLVOVolume::sObjectMediaClient || objectp.isNull() ||
  1045. pick.mObjectFace < 0 || pick.mObjectFace >= objectp->getNumTEs())
  1046. {
  1047. focusp->clearFocus();
  1048. return false;
  1049. }
  1050. const LLTextureEntry* tep = objectp->getTE(pick.mObjectFace);
  1051. viewer_media_t mediap = LLViewerMedia::getMediaImplFromTextureEntry(tep);
  1052. if (mediap.isNull() || !mediap->hasMedia())
  1053. {
  1054. focusp->clearFocus();
  1055. return false;
  1056. }
  1057. if (!focusp->isFocusedOnFace(pick.getObject(), pick.mObjectFace))
  1058. {
  1059. focusp->setFocusFace(true, pick.getObject(), pick.mObjectFace,
  1060. mediap, pick.mNormal);
  1061. }
  1062. else if (gKeyboardp)
  1063. {
  1064. // Make sure keyboard focus is set to the media focus object.
  1065. gFocusMgr.setKeyboardFocus(focusp);
  1066. gEditMenuHandlerp = focusp->getFocusedMediaImpl();
  1067. mediap->mouseDoubleClick(pick.mUVCoords,
  1068. gKeyboardp->currentMask(true));
  1069. // The mouse-up will happen when capture is lost
  1070. mediap->mouseCapture();
  1071. LL_DEBUGS("Media") << "Mouse double-click event passed to media"
  1072. << LL_ENDL;
  1073. }
  1074. return true;
  1075. }
  1076. bool LLToolPie::handleMediaHover(const LLPickInfo& pick)
  1077. {
  1078. // *FIXME: how do we handle object in different parcel than us ?
  1079. LLParcel* parcelp = gViewerParcelMgr.getAgentParcel();
  1080. if (!parcelp)
  1081. {
  1082. return false;
  1083. }
  1084. LLViewerMediaFocus* focusp = LLViewerMediaFocus::getInstance();
  1085. LLPointer<LLViewerObject> objectp = pick.getObject();
  1086. // Early out cases. Must clear mouse over media focus flag did not hit an
  1087. // object or did not hit a valid face
  1088. if (!LLVOVolume::sObjectMediaClient || objectp.isNull() ||
  1089. pick.mObjectFace < 0 || pick.mObjectFace >= objectp->getNumTEs())
  1090. {
  1091. focusp->clearHover();
  1092. return false;
  1093. }
  1094. const LLTextureEntry* tep = objectp->getTE(pick.mObjectFace);
  1095. viewer_media_t mediap = LLViewerMedia::getMediaImplFromTextureEntry(tep);
  1096. if (mediap.notNull() && gKeyboardp && LLVOVolume::sObjectMediaClient)
  1097. {
  1098. // Update media hover object
  1099. if (!focusp->isHoveringOverFace(objectp, pick.mObjectFace))
  1100. {
  1101. focusp->setHoverFace(objectp, pick.mObjectFace, mediap,
  1102. pick.mNormal);
  1103. gSelectMgr.setHoverObject(objectp, pick.mObjectFace);
  1104. focusp->setPickInfo(pick);
  1105. }
  1106. // If this is the focused media face, send mouse move events.
  1107. if (focusp->isFocusedOnFace(objectp, pick.mObjectFace))
  1108. {
  1109. mediap->mouseMove(pick.mUVCoords,
  1110. gKeyboardp->currentMask(true));
  1111. gViewerWindowp->setCursor(mediap->getLastSetCursor());
  1112. }
  1113. else
  1114. {
  1115. // This is not the focused face -- set the default cursor.
  1116. gViewerWindowp->setCursor(UI_CURSOR_ARROW);
  1117. }
  1118. return true;
  1119. }
  1120. // In all other cases, clear media hover.
  1121. focusp->clearHover();
  1122. return false;
  1123. }
  1124. static void handle_click_action_open_media(LLPointer<LLViewerObject> objectp)
  1125. {
  1126. if (!LLVOVolume::sObjectMediaClient)
  1127. {
  1128. return; // Media disabled.
  1129. }
  1130. // *FIXME: how do we handle object in different parcel than us ?
  1131. LLParcel* parcelp = gViewerParcelMgr.getAgentParcel();
  1132. if (!parcelp)
  1133. {
  1134. return;
  1135. }
  1136. // Did we hit an object ?
  1137. if (objectp.isNull()) return;
  1138. // Did we hit a valid face on the object ?
  1139. S32 face = gToolPie.getPick().mObjectFace;
  1140. if (face < 0 || face >= objectp->getNumTEs()) return;
  1141. // Is media playing on this face ?
  1142. LLTextureEntry* tep = objectp->getTE(face);
  1143. if (tep && LLViewerMedia::getMediaImplFromTextureID(tep->getID()))
  1144. {
  1145. handle_click_action_play();
  1146. return;
  1147. }
  1148. std::string media_url = parcelp->getMediaURL();
  1149. std::string media_type = parcelp->getMediaType();
  1150. LLStringUtil::trim(media_url);
  1151. // Get the scheme, see if that is handled as well.
  1152. LLURI uri(media_url);
  1153. std::string media_scheme = uri.scheme() != "" ? uri.scheme() : "http";
  1154. LLWeb::loadURL(media_url);
  1155. }
  1156. static ECursorType cursor_from_parcel_media(U8 click_action)
  1157. {
  1158. if (!LLVOVolume::sObjectMediaClient)
  1159. {
  1160. return UI_CURSOR_ARROW; // Media disabled.
  1161. }
  1162. // *FIXME: how do we handle object in different parcel than us ?
  1163. LLParcel* parcelp = gViewerParcelMgr.getAgentParcel();
  1164. if (!parcelp)
  1165. {
  1166. return UI_CURSOR_ARROW;
  1167. }
  1168. LLViewerMediaImpl::EMediaStatus status = LLViewerParcelMedia::getStatus();
  1169. if (status == LLViewerMediaImpl::MEDIA_PLAYING)
  1170. {
  1171. return click_action == CLICK_ACTION_PLAY ? UI_CURSOR_TOOLPAUSE
  1172. : UI_CURSOR_TOOLMEDIAOPEN;
  1173. }
  1174. return UI_CURSOR_TOOLPLAY;
  1175. }