lltooldraganddrop.cpp 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365
  1. /**
  2. * @file lltooldraganddrop.cpp
  3. * @brief LLToolDragAndDrop 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 "lltooldraganddrop.h"
  34. #include "indra_constants.h" // For BLANK_MATERIAL_ASSET_ID
  35. #include "llinstantmessage.h"
  36. #include "llnotifications.h"
  37. #include "llparcel.h"
  38. #include "lltrans.h"
  39. #include "llvolume.h"
  40. #include "llmessage.h"
  41. #include "object_flags.h"
  42. #include "llagent.h"
  43. #include "llagentwearables.h"
  44. #include "llappearancemgr.h"
  45. #include "llfirstuse.h"
  46. #include "llfloatertools.h"
  47. #include "llgesturemgr.h"
  48. #include "llhudeffectspiral.h"
  49. #include "llimmgr.h"
  50. #include "llinventorybridge.h"
  51. #include "llmaterialmgr.h"
  52. #include "llmutelist.h"
  53. #include "llpanelface.h"
  54. #include "llpreviewnotecard.h"
  55. //MK
  56. #include "mkrlinterface.h"
  57. //mk
  58. #include "llselectmgr.h"
  59. #include "lltoolmgr.h"
  60. #include "llviewercontrol.h"
  61. #include "llviewerinventory.h"
  62. #include "llviewerobjectlist.h"
  63. #include "llviewerparcelmgr.h"
  64. #include "llviewerregion.h"
  65. #include "llviewertexturelist.h"
  66. #include "llviewerstats.h"
  67. #include "llviewerwindow.h"
  68. #include "llvoavatarself.h"
  69. #include "llworld.h"
  70. // MAX ITEMS is based on (sizeof(uuid) + 2) * count must be < MTUBYTES or
  71. // 18 * count < 1200 => count < 1200 / 18 => 66. I've cut it down a bit from
  72. // there to give some pad.
  73. constexpr S32 MAX_ITEMS = 42;
  74. // LLVM/clang does not like our sugar...
  75. #if LL_CLANG
  76. # pragma clang diagnostic ignored "-Wunused-value"
  77. #endif
  78. // Syntactic sugar
  79. #define callMemberFunction(object,ptrToMember) ((object).*(ptrToMember))
  80. LLToolDragAndDrop gToolDragAndDrop;
  81. class LLNoPreferredType final : public LLInventoryCollectFunctor
  82. {
  83. public:
  84. LLNoPreferredType() = default;
  85. bool operator()(LLInventoryCategory* catp, LLInventoryItem*) override
  86. {
  87. return catp && catp->getPreferredType() == LLFolderType::FT_NONE;
  88. }
  89. };
  90. class LLNoPreferredTypeOrItem final : public LLInventoryCollectFunctor
  91. {
  92. public:
  93. LLNoPreferredTypeOrItem() = default;
  94. bool operator()(LLInventoryCategory* catp, LLInventoryItem* itemp) override
  95. {
  96. return itemp ||
  97. (catp && catp->getPreferredType() == LLFolderType::FT_NONE);
  98. }
  99. };
  100. class LLDroppableItem final : public LLInventoryCollectFunctor
  101. {
  102. public:
  103. LLDroppableItem(bool is_transfer)
  104. : mCountLosing(0),
  105. mIsTransfer(is_transfer)
  106. {
  107. }
  108. bool operator()(LLInventoryCategory*, LLInventoryItem* itemp) override
  109. {
  110. if (!itemp || !itemTransferCommonlyAllowed(itemp))
  111. {
  112. return false;
  113. }
  114. if (mIsTransfer &&
  115. !itemp->getPermissions().allowTransferBy(gAgentID))
  116. {
  117. return false;
  118. }
  119. if (!itemp->getPermissions().allowCopyBy(gAgentID))
  120. {
  121. ++mCountLosing;
  122. }
  123. return true;
  124. }
  125. LL_INLINE S32 countNoCopy() const { return mCountLosing; }
  126. protected:
  127. S32 mCountLosing;
  128. bool mIsTransfer;
  129. };
  130. class LLUncopyableItems final : public LLInventoryCollectFunctor
  131. {
  132. public:
  133. LLUncopyableItems() = default;
  134. bool operator()(LLInventoryCategory*, LLInventoryItem* itemp) override
  135. {
  136. return itemp && itemTransferCommonlyAllowed(itemp) &&
  137. !itemp->getPermissions().allowCopyBy(gAgentID);
  138. }
  139. };
  140. class LLDropCopyableItems final : public LLInventoryCollectFunctor
  141. {
  142. public:
  143. LLDropCopyableItems() = default;
  144. bool operator()(LLInventoryCategory*, LLInventoryItem* itemp) override
  145. {
  146. return itemp && itemTransferCommonlyAllowed(itemp) &&
  147. itemp->getPermissions().allowCopyBy(gAgentID);
  148. }
  149. };
  150. class LLGiveable final : public LLInventoryCollectFunctor
  151. {
  152. public:
  153. LLGiveable()
  154. : mCountLosing(0)
  155. {
  156. }
  157. bool operator()(LLInventoryCategory* catp, LLInventoryItem* itemp) override
  158. {
  159. // All categories can be given.
  160. if (catp)
  161. {
  162. return true;
  163. }
  164. if (!itemp || !itemTransferCommonlyAllowed(itemp))
  165. {
  166. return false;
  167. }
  168. if (!itemp->getPermissions().allowTransferBy(gAgentID))
  169. {
  170. return false;
  171. }
  172. if (!itemp->getPermissions().allowCopyBy(gAgentID))
  173. {
  174. ++mCountLosing;
  175. }
  176. return true;
  177. }
  178. LL_INLINE S32 countNoCopy() const { return mCountLosing; }
  179. protected:
  180. S32 mCountLosing;
  181. };
  182. // Starts a fetch on folders and items. This is really not used as an observer
  183. // in the traditional sense; we are just using it to request a fetch and we do
  184. // not care about when/if the response arrives.
  185. class LLCategoryFireAndForget final : public LLInventoryFetchComboObserver
  186. {
  187. protected:
  188. LOG_CLASS(LLCategoryFireAndForget);
  189. public:
  190. LLCategoryFireAndForget() = default;
  191. void done() override
  192. {
  193. // No-op: it is fire and forget, right ?
  194. LL_DEBUGS("DragAndDrop") << "Done." << LL_ENDL;
  195. }
  196. };
  197. class LLCategoryDropObserver final : public LLInventoryFetchObserver
  198. {
  199. public:
  200. LLCategoryDropObserver(const LLUUID& obj_id,
  201. LLToolDragAndDrop::ESource src)
  202. : mObjectID(obj_id),
  203. mSource(src)
  204. {
  205. }
  206. void done() override
  207. {
  208. gInventory.removeObserver(this);
  209. LLViewerObject* dst_objp = gObjectList.findObject(mObjectID);
  210. if (dst_objp)
  211. {
  212. // *FIX: coalesce these...
  213. for (U32 i = 0, count = mComplete.size(); i < count; ++i)
  214. {
  215. LLInventoryItem* itemp = gInventory.getItem(mComplete[i]);
  216. if (itemp)
  217. {
  218. LLToolDragAndDrop::dropInventory(dst_objp, itemp, mSource);
  219. }
  220. }
  221. }
  222. delete this;
  223. }
  224. protected:
  225. LLUUID mObjectID;
  226. LLToolDragAndDrop::ESource mSource;
  227. };
  228. LLToolDragAndDrop::DragAndDropEntry::DragAndDropEntry(dragOrDrop3dImpl f_none,
  229. dragOrDrop3dImpl f_self,
  230. dragOrDrop3dImpl f_avatar,
  231. dragOrDrop3dImpl f_object,
  232. dragOrDrop3dImpl f_land) :
  233. LLDictionaryEntry("")
  234. {
  235. mFunctions[DT_NONE] = f_none;
  236. mFunctions[DT_SELF] = f_self;
  237. mFunctions[DT_AVATAR] = f_avatar;
  238. mFunctions[DT_OBJECT] = f_object;
  239. mFunctions[DT_LAND] = f_land;
  240. }
  241. LLToolDragAndDrop::dragOrDrop3dImpl
  242. LLToolDragAndDrop::LLDragAndDropDictionary::get(EDragAndDropType dad_type,
  243. EDropTarget drop_target)
  244. {
  245. const DragAndDropEntry* entry = lookup(dad_type);
  246. if (entry)
  247. {
  248. return entry->mFunctions[(U8)drop_target];
  249. }
  250. return &LLToolDragAndDrop::dad3dNULL;
  251. }
  252. LLToolDragAndDrop::LLDragAndDropDictionary::LLDragAndDropDictionary()
  253. {
  254. // DT_NONE DT_SELF DT_AVATAR DT_OBJECT DT_LAND
  255. // |-------------------------------|----------------------------------------------|-----------------------------------------------|---------------------------------------------------|--------------------------------|
  256. addEntry(DAD_NONE, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL));
  257. addEntry(DAD_TEXTURE, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dTextureObject, &LLToolDragAndDrop::dad3dNULL));
  258. addEntry(DAD_MATERIAL, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dMaterialObject, &LLToolDragAndDrop::dad3dNULL));
  259. addEntry(DAD_SOUND, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dUpdateInventory, &LLToolDragAndDrop::dad3dNULL));
  260. addEntry(DAD_CALLINGCARD, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dUpdateInventory, &LLToolDragAndDrop::dad3dNULL));
  261. addEntry(DAD_LANDMARK, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dUpdateInventory, &LLToolDragAndDrop::dad3dNULL));
  262. addEntry(DAD_SCRIPT, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dRezScript, &LLToolDragAndDrop::dad3dNULL));
  263. addEntry(DAD_CLOTHING, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dWearItem, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dUpdateInventory, &LLToolDragAndDrop::dad3dNULL));
  264. addEntry(DAD_OBJECT, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dRezAttachmentFromInv, &LLToolDragAndDrop::dad3dGiveInventoryObject, &LLToolDragAndDrop::dad3dRezObjectOnObject, &LLToolDragAndDrop::dad3dRezObjectOnLand));
  265. addEntry(DAD_NOTECARD, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dUpdateInventory, &LLToolDragAndDrop::dad3dNULL));
  266. addEntry(DAD_CATEGORY, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dWearCategory, &LLToolDragAndDrop::dad3dGiveInventoryCategory, &LLToolDragAndDrop::dad3dRezCategoryOnObject, &LLToolDragAndDrop::dad3dNULL));
  267. addEntry(DAD_ROOT_CATEGORY, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL));
  268. addEntry(DAD_BODYPART, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dWearItem, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dUpdateInventory, &LLToolDragAndDrop::dad3dNULL));
  269. addEntry(DAD_ANIMATION, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dUpdateInventory, &LLToolDragAndDrop::dad3dNULL));
  270. addEntry(DAD_GESTURE, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dActivateGesture, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dUpdateInventory, &LLToolDragAndDrop::dad3dNULL));
  271. addEntry(DAD_LINK, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL));
  272. #if LL_MESH_ASSET_SUPPORT
  273. addEntry(DAD_MESH, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dMeshObject, &LLToolDragAndDrop::dad3dNULL));
  274. addEntry(DAD_GLTF, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL));
  275. addEntry(DAD_GLTF_BIN, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL));
  276. #endif
  277. addEntry(DAD_SETTINGS, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dGiveInventory, &LLToolDragAndDrop::dad3dUpdateInventory, &LLToolDragAndDrop::dad3dNULL));
  278. // *TODO: animation on self could play it ? edit it ?
  279. // *TODO: gesture on self could play it ? edit it ?
  280. };
  281. LLToolDragAndDrop::LLToolDragAndDrop()
  282. : LLTool("draganddrop", NULL),
  283. mDragStartX(0),
  284. mDragStartY(0),
  285. mSource(SOURCE_AGENT),
  286. mCursor(UI_CURSOR_NO),
  287. mLastAccept(ACCEPT_NO),
  288. mDrop(false),
  289. mCurItemIndex(0)
  290. {
  291. }
  292. bool LLToolDragAndDrop::isOverThreshold(S32 x, S32 y)
  293. {
  294. constexpr S32 MIN_MANHATTAN_DIST = 3;
  295. S32 manhattan_dist = abs(x - mDragStartX) + abs(y - mDragStartY);
  296. return manhattan_dist >= MIN_MANHATTAN_DIST;
  297. }
  298. void LLToolDragAndDrop::beginDrag(EDragAndDropType type,
  299. const LLUUID& cargo_id, ESource source,
  300. const LLUUID& source_id,
  301. const LLUUID& object_id)
  302. {
  303. if (type == DAD_NONE)
  304. {
  305. llwarns << "Attempted to start drag without a cargo type" << llendl;
  306. return;
  307. }
  308. LL_DEBUGS("DragAndDrop") << "Type: " << type << " - Source: " << source
  309. << LL_ENDL;
  310. mCargoTypes.clear();
  311. mCargoTypes.push_back(type);
  312. mCargoIDs.clear();
  313. mCargoIDs.emplace_back(cargo_id);
  314. mSource = source;
  315. mSourceID = source_id;
  316. mObjectID = object_id;
  317. setMouseCapture(true);
  318. gToolMgr.setTransientTool(this);
  319. mCursor = UI_CURSOR_NO;
  320. if (mCargoTypes[0] == DAD_CATEGORY &&
  321. (mSource == SOURCE_AGENT || mSource == SOURCE_LIBRARY))
  322. {
  323. LLInventoryCategory* cat = gInventory.getCategory(cargo_id);
  324. // Go ahead and fire & forget the descendents if we are not dragging a
  325. // protected folder.
  326. if (cat)
  327. {
  328. LLViewerInventoryCategory::cat_array_t cats;
  329. LLViewerInventoryItem::item_array_t items;
  330. LLNoPreferredTypeOrItem is_not_preferred;
  331. uuid_vec_t folder_ids, item_ids;
  332. if (is_not_preferred(cat, NULL))
  333. {
  334. folder_ids.emplace_back(cargo_id);
  335. }
  336. gInventory.collectDescendentsIf(cargo_id, cats, items,
  337. LLInventoryModel::EXCLUDE_TRASH,
  338. is_not_preferred);
  339. for (S32 i = 0, count = cats.size(); i < count; ++i)
  340. {
  341. folder_ids.emplace_back(cats[i]->getUUID());
  342. }
  343. for (S32 i = 0, count = items.size(); i < count; ++i)
  344. {
  345. item_ids.emplace_back(items[i]->getUUID());
  346. }
  347. if (!folder_ids.empty() || !item_ids.empty())
  348. {
  349. LLCategoryFireAndForget fetcher;
  350. fetcher.fetch(folder_ids, item_ids);
  351. }
  352. }
  353. }
  354. }
  355. void LLToolDragAndDrop::beginMultiDrag(const std::vector<EDragAndDropType> types,
  356. const std::vector<LLUUID>& cargo_ids,
  357. ESource source, const LLUUID& source_id)
  358. {
  359. for (std::vector<EDragAndDropType>::const_iterator it = types.begin(),
  360. end = types.end();
  361. it != end; ++it)
  362. {
  363. if (*it == DAD_NONE)
  364. {
  365. llwarns << "Attempted to start drag without a cargo type"
  366. << llendl;
  367. return;
  368. }
  369. }
  370. LL_DEBUGS("DragAndDrop") << "Source: " << source << LL_ENDL;
  371. mCargoTypes = types;
  372. mCargoIDs = cargo_ids;
  373. mSource = source;
  374. mSourceID = source_id;
  375. setMouseCapture(true);
  376. gToolMgr.setTransientTool(this);
  377. mCursor = UI_CURSOR_NO;
  378. if (mSource == SOURCE_AGENT || mSource == SOURCE_LIBRARY)
  379. {
  380. // Find categories (i.e. inventory folders) in the cargo.
  381. std::set<LLUUID> cat_ids;
  382. for (S32 i = 0, count = llmin(cargo_ids.size(), types.size());
  383. i < count; ++i)
  384. {
  385. LLInventoryCategory* catp = gInventory.getCategory(cargo_ids[i]);
  386. if (catp)
  387. {
  388. LLViewerInventoryCategory::cat_array_t cats;
  389. LLViewerInventoryItem::item_array_t items;
  390. LLNoPreferredType is_not_preferred;
  391. const LLUUID& cat_id = catp->getUUID();
  392. if (is_not_preferred(catp, NULL))
  393. {
  394. cat_ids.emplace(cat_id);
  395. }
  396. gInventory.collectDescendentsIf(cat_id, cats, items,
  397. LLInventoryModel::EXCLUDE_TRASH,
  398. is_not_preferred);
  399. for (S32 i = 0, cat_count = cats.size(); i < cat_count; ++i)
  400. {
  401. cat_ids.emplace(cat_id);
  402. }
  403. }
  404. }
  405. if (!cat_ids.empty())
  406. {
  407. uuid_vec_t folder_ids, item_ids;
  408. std::back_insert_iterator<uuid_vec_t> copier(folder_ids);
  409. std::copy(cat_ids.begin(), cat_ids.end(), copier);
  410. LLCategoryFireAndForget fetcher;
  411. fetcher.fetch(folder_ids, item_ids);
  412. }
  413. }
  414. }
  415. void LLToolDragAndDrop::endDrag()
  416. {
  417. gSelectMgr.unhighlightAll();
  418. setMouseCapture(false);
  419. }
  420. // Called whenever the drag ends or if mouse capture is simply lost
  421. //virtual
  422. void LLToolDragAndDrop::onMouseCaptureLost()
  423. {
  424. gToolMgr.clearTransientTool();
  425. mCargoTypes.clear();
  426. mCargoIDs.clear();
  427. mSource = SOURCE_AGENT;
  428. mSourceID.setNull();
  429. mObjectID.setNull();
  430. }
  431. //virtual
  432. bool LLToolDragAndDrop::handleMouseUp(S32 x, S32 y, MASK mask)
  433. {
  434. if (hasMouseCapture())
  435. {
  436. EAcceptance acceptance = ACCEPT_NO;
  437. dragOrDrop(x, y, mask, true, &acceptance);
  438. endDrag();
  439. }
  440. return true;
  441. }
  442. ECursorType LLToolDragAndDrop::acceptanceToCursor(EAcceptance acceptance)
  443. {
  444. switch (acceptance)
  445. {
  446. case ACCEPT_YES_MULTI:
  447. mCursor = mCargoIDs.size() > 1 ? UI_CURSOR_ARROWDRAGMULTI
  448. : UI_CURSOR_ARROWDRAG;
  449. break;
  450. case ACCEPT_YES_SINGLE:
  451. if (mCargoIDs.size() > 1)
  452. {
  453. mToolTipMsg = LLTrans::getString("TooltipMustSingleDrop");
  454. mCursor = UI_CURSOR_NO;
  455. }
  456. else
  457. {
  458. mCursor = UI_CURSOR_ARROWDRAG;
  459. }
  460. break;
  461. case ACCEPT_NO_LOCKED:
  462. mCursor = UI_CURSOR_NOLOCKED;
  463. break;
  464. case ACCEPT_NO:
  465. mCursor = UI_CURSOR_NO;
  466. break;
  467. case ACCEPT_YES_COPY_MULTI:
  468. mCursor = mCargoIDs.size() > 1 ? UI_CURSOR_ARROWCOPYMULTI
  469. : UI_CURSOR_ARROWCOPY;
  470. break;
  471. case ACCEPT_YES_COPY_SINGLE:
  472. if (mCargoIDs.size() > 1)
  473. {
  474. mToolTipMsg = LLTrans::getString("TooltipMustSingleDrop");
  475. mCursor = UI_CURSOR_NO;
  476. }
  477. else
  478. {
  479. mCursor = UI_CURSOR_ARROWCOPY;
  480. }
  481. break;
  482. case ACCEPT_POSTPONED:
  483. break;
  484. default:
  485. llassert(false);
  486. }
  487. return mCursor;
  488. }
  489. //virtual
  490. bool LLToolDragAndDrop::handleHover(S32 x, S32 y, MASK mask)
  491. {
  492. EAcceptance acceptance = ACCEPT_NO;
  493. dragOrDrop(x, y, mask, false, &acceptance);
  494. ECursorType cursor = acceptanceToCursor(acceptance);
  495. gWindowp->setCursor(cursor);
  496. LL_DEBUGS("UserInput") << "hover handled by LLToolDragAndDrop" << LL_ENDL;
  497. return true;
  498. }
  499. //virtual
  500. bool LLToolDragAndDrop::handleKey(KEY key, MASK mask)
  501. {
  502. if (key == KEY_ESCAPE && mask == MASK_NONE)
  503. {
  504. // Cancel drag and drop operation
  505. endDrag();
  506. return true;
  507. }
  508. return false;
  509. }
  510. //virtual
  511. bool LLToolDragAndDrop::handleToolTip(S32 x, S32 y, std::string& msg,
  512. LLRect* sticky_rect_screen)
  513. {
  514. if (!mToolTipMsg.empty())
  515. {
  516. msg = mToolTipMsg;
  517. return true;
  518. }
  519. return false;
  520. }
  521. //virtual
  522. void LLToolDragAndDrop::handleDeselect()
  523. {
  524. mToolTipMsg.clear();
  525. }
  526. void LLToolDragAndDrop::dragOrDrop(S32 x, S32 y, MASK mask, bool drop,
  527. EAcceptance* acceptance)
  528. {
  529. *acceptance = ACCEPT_YES_MULTI;
  530. bool handled = false;
  531. LLView* top_view = gFocusMgr.getTopCtrl();
  532. LLViewerInventoryItem* item;
  533. LLViewerInventoryCategory* cat;
  534. mToolTipMsg.clear();
  535. if (top_view)
  536. {
  537. handled = true;
  538. for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size();
  539. ++mCurItemIndex)
  540. {
  541. LLInventoryObject* cargo = locateInventory(item, cat);
  542. if (cargo)
  543. {
  544. S32 local_x, local_y;
  545. top_view->screenPointToLocal(x, y, &local_x, &local_y);
  546. EAcceptance item_acceptance = ACCEPT_NO;
  547. handled &=
  548. top_view->handleDragAndDrop(local_x, local_y,
  549. mask, false,
  550. mCargoTypes[mCurItemIndex],
  551. (void*)cargo, &item_acceptance,
  552. mToolTipMsg);
  553. if (handled)
  554. {
  555. // Use sort order to determine priority of acceptance
  556. *acceptance = (EAcceptance)llmin((U32)item_acceptance,
  557. (U32)*acceptance);
  558. }
  559. }
  560. else
  561. {
  562. return;
  563. }
  564. }
  565. // All objects passed, go ahead and perform drop if necessary
  566. if (handled && drop && (U32)*acceptance >= ACCEPT_YES_COPY_SINGLE)
  567. {
  568. if ((U32)*acceptance < ACCEPT_YES_COPY_MULTI &&
  569. mCargoIDs.size() > 1)
  570. {
  571. // Tried to give multi-cargo to a single-acceptor: refuse and
  572. // return.
  573. *acceptance = ACCEPT_NO;
  574. return;
  575. }
  576. for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size();
  577. ++mCurItemIndex)
  578. {
  579. LLInventoryObject* cargo = locateInventory(item, cat);
  580. if (cargo)
  581. {
  582. S32 local_x, local_y;
  583. EAcceptance item_acceptance;
  584. top_view->screenPointToLocal(x, y, &local_x, &local_y);
  585. handled &=
  586. top_view->handleDragAndDrop(local_x, local_y,
  587. mask, true,
  588. mCargoTypes[mCurItemIndex],
  589. (void*)cargo,
  590. &item_acceptance,
  591. mToolTipMsg);
  592. }
  593. }
  594. }
  595. if (handled)
  596. {
  597. mLastAccept = (EAcceptance)*acceptance;
  598. }
  599. }
  600. if (!handled)
  601. {
  602. handled = true;
  603. LLView* root_view = gViewerWindowp->getRootView();
  604. for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size();
  605. ++mCurItemIndex)
  606. {
  607. LLInventoryObject* cargo = locateInventory(item, cat);
  608. if (!cargo)
  609. {
  610. handled = false;
  611. break;
  612. }
  613. EAcceptance item_acceptance = ACCEPT_NO;
  614. handled &=
  615. root_view->handleDragAndDrop(x, y, mask, false,
  616. mCargoTypes[mCurItemIndex],
  617. (void*)cargo, &item_acceptance,
  618. mToolTipMsg);
  619. if (handled)
  620. {
  621. // Use sort order to determine priority of acceptance
  622. *acceptance = (EAcceptance)llmin((U32)item_acceptance,
  623. (U32)*acceptance);
  624. }
  625. }
  626. // All objects passed, go ahead and perform drop if necessary
  627. if (handled && drop && (U32)*acceptance > ACCEPT_NO_LOCKED)
  628. {
  629. if ((U32)*acceptance < ACCEPT_YES_COPY_MULTI &&
  630. mCargoIDs.size() > 1)
  631. {
  632. // Tried to give multi-cargo to a single-acceptor: refuse and
  633. // return.
  634. *acceptance = ACCEPT_NO;
  635. return;
  636. }
  637. for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size();
  638. ++mCurItemIndex)
  639. {
  640. LLInventoryObject* cargo = locateInventory(item, cat);
  641. if (cargo)
  642. {
  643. EAcceptance item_acceptance;
  644. handled &=
  645. root_view->handleDragAndDrop(x, y, mask, true,
  646. mCargoTypes[mCurItemIndex],
  647. (void*)cargo,
  648. &item_acceptance,
  649. mToolTipMsg);
  650. }
  651. }
  652. }
  653. if (handled)
  654. {
  655. mLastAccept = (EAcceptance)*acceptance;
  656. }
  657. }
  658. if (!handled)
  659. {
  660. dragOrDrop3D(x, y, mask, drop, acceptance);
  661. }
  662. }
  663. void LLToolDragAndDrop::dragOrDrop3D(S32 x, S32 y, MASK mask, bool drop,
  664. EAcceptance* acceptance)
  665. {
  666. mDrop = drop;
  667. if (mDrop)
  668. {
  669. // Note: do not allow drag and drop onto transparent objects (this
  670. // defaults to false already in pickImmediate()).
  671. pickCallback(gViewerWindowp->pickImmediate(x, y));
  672. }
  673. else
  674. {
  675. // Note: do not allow drag and drop onto transparent objects (this
  676. // defaults to false already in pickAsync()).
  677. gViewerWindowp->pickAsync(x, y, mask, pickCallback);
  678. }
  679. *acceptance = mLastAccept;
  680. }
  681. //static
  682. void LLToolDragAndDrop::pickCallback(const LLPickInfo& pick_info)
  683. {
  684. LLToolDragAndDrop* self = &gToolDragAndDrop;
  685. EDropTarget target = DT_NONE;
  686. S32 hit_face = -1;
  687. LLViewerObject* hit_objp = pick_info.getObject();
  688. gSelectMgr.unhighlightAll();
  689. bool highlight_object = false;
  690. // Treat attachments as part of the avatar they are attached to.
  691. if (hit_objp)
  692. {
  693. // Do not allow drag and drop on grass, trees, etc.
  694. if (pick_info.mPickType == LLPickInfo::PICK_FLORA)
  695. {
  696. self->mCursor = UI_CURSOR_NO;
  697. gWindowp->setCursor(self->mCursor);
  698. return;
  699. }
  700. if (hit_objp->isAttachment() && !hit_objp->isHUDAttachment())
  701. {
  702. LLVOAvatar* avp = LLVOAvatar::findAvatarFromAttachment(hit_objp);
  703. if (!avp)
  704. {
  705. self->mLastAccept = ACCEPT_NO;
  706. self->mCursor = UI_CURSOR_NO;
  707. gWindowp->setCursor(self->mCursor);
  708. return;
  709. }
  710. hit_objp = avp;
  711. }
  712. if (hit_objp->isAvatar())
  713. {
  714. if (((LLVOAvatar*)hit_objp)->isSelf())
  715. {
  716. target = DT_SELF;
  717. hit_face = -1;
  718. }
  719. else
  720. {
  721. target = DT_AVATAR;
  722. hit_face = -1;
  723. }
  724. }
  725. else
  726. {
  727. target = DT_OBJECT;
  728. hit_face = pick_info.mObjectFace;
  729. highlight_object = true;
  730. }
  731. }
  732. else if (pick_info.mPickType == LLPickInfo::PICK_LAND)
  733. {
  734. target = DT_LAND;
  735. hit_face = -1;
  736. }
  737. self->mLastAccept = ACCEPT_YES_MULTI;
  738. for (self->mCurItemIndex = 0;
  739. self->mCurItemIndex < (S32)self->mCargoIDs.size();
  740. self->mCurItemIndex++)
  741. {
  742. const S32 item_index = self->mCurItemIndex;
  743. const EDragAndDropType dad_type = self->mCargoTypes[item_index];
  744. // Call the right implementation function
  745. self->mLastAccept = (EAcceptance)llmin(
  746. (U32)self->mLastAccept,
  747. (U32)callMemberFunction(*self,
  748. LLDragAndDropDictionary::getInstance()->get(dad_type,
  749. target))
  750. (hit_objp, hit_face,
  751. pick_info.mKeyMask, false));
  752. }
  753. if (self->mDrop && (U32)self->mLastAccept >= ACCEPT_YES_COPY_SINGLE)
  754. {
  755. // If target allows multi-drop or there is only one item being dropped,
  756. // go ahead
  757. if (self->mLastAccept >= ACCEPT_YES_COPY_MULTI ||
  758. self->mCargoIDs.size() == 1)
  759. {
  760. // Target accepts multi, or cargo is a single-drop
  761. for (self->mCurItemIndex = 0;
  762. self->mCurItemIndex < (S32)self->mCargoIDs.size();
  763. ++self->mCurItemIndex)
  764. {
  765. const S32 item_index = self->mCurItemIndex;
  766. const EDragAndDropType dad_type = self->mCargoTypes[item_index];
  767. // Call the right implementation function
  768. (U32)callMemberFunction(*self,
  769. LLDragAndDropDictionary::getInstance()->get(dad_type,
  770. target))
  771. (hit_objp, hit_face,
  772. pick_info.mKeyMask, true);
  773. }
  774. }
  775. else
  776. {
  777. // Target does not accept multi, but cargo is multi
  778. self->mLastAccept = ACCEPT_NO;
  779. }
  780. }
  781. if (highlight_object && self->mLastAccept > ACCEPT_NO_LOCKED)
  782. {
  783. // If any item being dragged will be applied to the object under our
  784. // cursor highlight that object
  785. for (S32 i = 0, count = self->mCargoIDs.size(); i < count; ++i)
  786. {
  787. if (self->mCargoTypes[i] != DAD_OBJECT ||
  788. (pick_info.mKeyMask & MASK_CONTROL))
  789. {
  790. gSelectMgr.highlightObjectAndFamily(hit_objp);
  791. break;
  792. }
  793. }
  794. }
  795. ECursorType cursor = self->acceptanceToCursor(self->mLastAccept);
  796. gWindowp->setCursor(cursor);
  797. self->mLastHitPos = pick_info.mPosGlobal;
  798. self->mLastCameraPos = gAgent.getCameraPositionGlobal();
  799. }
  800. //static
  801. bool LLToolDragAndDrop::handleDropAssetProtections(LLViewerObject* hit_objp,
  802. LLInventoryItem* itemp,
  803. ESource source,
  804. const LLUUID& src_id)
  805. {
  806. if (!itemp) return false;
  807. // Always succeed if asset is from the library or already in the contents
  808. // of the object
  809. if (source == SOURCE_LIBRARY)
  810. {
  811. // Dropping an asset from the library always just works.
  812. return true;
  813. }
  814. // In case the inventory has not been updated (e.g. due to some recent
  815. // operation causing a dirty inventory) and we can do an update, stall the
  816. // user while fetching the inventory.
  817. // Fetch if inventory is both dirty and listener is present (otherwise we
  818. // will not receive update).
  819. if (hit_objp->isInventoryDirty() && hit_objp->hasInventoryListeners())
  820. {
  821. hit_objp->requestInventory();
  822. LLSD args;
  823. args["ERROR_MESSAGE"] = "Unable to add asset.\nPlease wait a few seconds and try again.";
  824. gNotifications.add("ErrorMessage", args);
  825. return false;
  826. }
  827. // Make sure to verify both asset Id and asset type since a null UUID is a
  828. // shared default for different asset types.
  829. if (hit_objp->getInventoryItemByAsset(itemp->getAssetUUID(),
  830. itemp->getType()))
  831. {
  832. // If the asset is already in the object's inventory then it can always
  833. // be added to a side. This saves some work if the task's inventory is
  834. // already loaded and ensures that the texture item is only added once.
  835. return true;
  836. }
  837. LLPointer<LLViewerInventoryItem> new_itemp =
  838. new LLViewerInventoryItem(itemp);
  839. const LLPermissions& perms = itemp->getPermissions();
  840. if (!perms.allowCopyBy(gAgentID))
  841. {
  842. // Check that we can add the asset as inventory to the object
  843. if (willObjectAcceptInventory(hit_objp,
  844. itemp) < ACCEPT_YES_COPY_SINGLE)
  845. {
  846. return false;
  847. }
  848. // Make sure the object has the asset in its inventory.
  849. if (source == SOURCE_AGENT)
  850. {
  851. // Remove the asset from local inventory. The server will actually
  852. // remove the item from agent inventory.
  853. gInventory.deleteObject(itemp->getUUID());
  854. gInventory.notifyObservers();
  855. }
  856. else if (source == SOURCE_WORLD)
  857. {
  858. LLViewerObject* src_objp = gObjectList.findObject(src_id);
  859. // *FIX: if the objects are in different regions, and the source
  860. // region has crashed, you can bypass these permissions.
  861. if (!src_objp)
  862. {
  863. llwarns << "Unable to find source object." << llendl;
  864. return false;
  865. }
  866. src_objp->removeInventory(itemp->getUUID());
  867. }
  868. // Add the asset's corresponding item to the target object's inventory.
  869. hit_objp->updateInventory(new_itemp, true);
  870. // Force the object to update and refetch its inventory so it has this
  871. // asset.
  872. hit_objp->dirtyInventory();
  873. hit_objp->requestInventory();
  874. // *TODO: check to see if adding the item was successful; if not, then
  875. // we should return false here.
  876. }
  877. else if (!perms.allowTransferBy(gAgentID))
  878. {
  879. // Check that we can add the asset as inventory to the object
  880. if (willObjectAcceptInventory(hit_objp,
  881. itemp) < ACCEPT_YES_COPY_SINGLE)
  882. {
  883. return false;
  884. }
  885. // Add the asset item to the target object's inventory.
  886. hit_objp->updateInventory(new_itemp, true);
  887. // Force the object to update and refetch its inventory so it has this
  888. // asset.
  889. hit_objp->dirtyInventory();
  890. hit_objp->requestInventory();
  891. // *TODO: check to see if adding the item was successful; if not, then
  892. // we should return false here. This will requre a separate listener
  893. // since without listener, we have no way to receive update.
  894. }
  895. else if (new_itemp->getType() == LLAssetType::AT_MATERIAL &&
  896. !itemp->getPermissions().allowModifyBy(gAgentID))
  897. {
  898. // Check that we can add the material as inventory to the object
  899. if (willObjectAcceptInventory(hit_objp,
  900. itemp) < ACCEPT_YES_COPY_SINGLE)
  901. {
  902. return false;
  903. }
  904. // *FIXME: may want to make sure agent can paint hit_objp.
  905. // Add the material item to the target object's inventory.
  906. hit_objp->updateInventory(new_itemp, true);
  907. // Force the object to update and refetch its inventory so it has this
  908. // asset.
  909. hit_objp->dirtyInventory();
  910. hit_objp->requestInventory();
  911. // *TODO: check to see if adding the item was successful; if not, then
  912. // we should return false here. This will requre a separate listener
  913. // since without listener, we have no way to receive update.
  914. }
  915. return true;
  916. }
  917. //static
  918. void LLToolDragAndDrop::dropTextureOneFace(LLViewerObject* hit_objp,
  919. S32 hit_face,
  920. LLInventoryItem* itemp,
  921. ESource source,
  922. const LLUUID& src_id)
  923. {
  924. if (!hit_objp)
  925. {
  926. llwarns << "No hit object." << llendl;
  927. return;
  928. }
  929. if (hit_face == -1)
  930. {
  931. return;
  932. }
  933. if (!itemp)
  934. {
  935. llwarns << "No texture item." << llendl;
  936. return;
  937. }
  938. #if 0 // Do allow changing the legacy maps on GLTF-material bearing faces. HB
  939. if (hit_objp->getRenderMaterialID(hit_face).notNull())
  940. {
  941. return;
  942. }
  943. #endif
  944. const LLUUID& asset_id = itemp->getAssetUUID();
  945. if (!handleDropAssetProtections(hit_objp, itemp, source, src_id))
  946. {
  947. return;
  948. }
  949. // Update viewer side image in anticipation of update from simulator
  950. LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(asset_id);
  951. if (!image)
  952. {
  953. llwarns << "Image " << asset_id << " not found" << llendl;
  954. return;
  955. }
  956. gViewerStats.incStat(LLViewerStats::ST_EDIT_TEXTURE_COUNT);
  957. LLPanelFace* panelp =
  958. LLFloaterTools::isVisible() ? gFloaterToolsp->getPanelFace() : NULL;
  959. LLTextureEntry* tep = hit_objp ? hit_objp->getTE(hit_face) : NULL;
  960. LLRender::eTexIndex channel = LLPanelFace::getTextureChannelToEdit();
  961. if (tep && panelp &&
  962. (channel == LLRender::NORMAL_MAP || channel == LLRender::SPECULAR_MAP))
  963. {
  964. LLMaterialPtr old_matp = tep->getMaterialParams();
  965. LLMaterialPtr new_matp = panelp->createDefaultMaterial(old_matp);
  966. if (channel == LLRender::NORMAL_MAP)
  967. {
  968. new_matp->setNormalID(asset_id);
  969. tep->setMaterialParams(new_matp);
  970. hit_objp->setTENormalMap(hit_face, asset_id);
  971. }
  972. else
  973. {
  974. new_matp->setSpecularID(asset_id);
  975. tep->setMaterialParams(new_matp);
  976. hit_objp->setTESpecularMap(hit_face, asset_id);
  977. }
  978. LLMaterialMgr::getInstance()->put(hit_objp->getID(), hit_face,
  979. *new_matp);
  980. }
  981. else
  982. {
  983. hit_objp->setTEImage(hit_face, image);
  984. }
  985. dialog_refresh_all();
  986. // Send the update to the simulator
  987. hit_objp->sendTEUpdate();
  988. }
  989. //static
  990. void LLToolDragAndDrop::dropTextureAllFaces(LLViewerObject* hit_objp,
  991. LLInventoryItem* itemp,
  992. ESource source,
  993. const LLUUID& src_id)
  994. {
  995. if (!hit_objp)
  996. {
  997. llwarns << "No hit object." << llendl;
  998. return;
  999. }
  1000. if (!itemp)
  1001. {
  1002. llwarns << "No texture item." << llendl;
  1003. return;
  1004. }
  1005. U8 num_tes = hit_objp->getNumTEs();
  1006. #if 0 // Do allow changing the legacy maps on GLTF-material bearing faces. HB
  1007. for (U8 te = 0; te < num_tes; ++te)
  1008. {
  1009. if (hit_objp->getRenderMaterialID(te).notNull())
  1010. {
  1011. return; // Got a PBR face: do not ruin it.
  1012. }
  1013. }
  1014. #endif
  1015. const LLUUID& asset_id = itemp->getAssetUUID();
  1016. bool success = handleDropAssetProtections(hit_objp, itemp, source, src_id);
  1017. if (!success)
  1018. {
  1019. return;
  1020. }
  1021. LLViewerTexture* texp =
  1022. LLViewerTextureManager::getFetchedTexture(asset_id);
  1023. if (!texp)
  1024. {
  1025. llwarns << "Texture " << asset_id << " not found" << llendl;
  1026. return;
  1027. }
  1028. bool updated = false;
  1029. for (U8 i = 0; i < num_tes; ++i)
  1030. {
  1031. if (hit_objp->getRenderMaterialID(i).isNull())
  1032. {
  1033. // Update viewer side texture in anticipation of update from
  1034. // simulator
  1035. hit_objp->setTEImage(i, texp);
  1036. updated = true;
  1037. }
  1038. }
  1039. if (updated)
  1040. {
  1041. // Send the update to the simulator
  1042. hit_objp->sendTEUpdate();
  1043. dialog_refresh_all();
  1044. gViewerStats.incStat(LLViewerStats::ST_EDIT_TEXTURE_COUNT);
  1045. }
  1046. }
  1047. void LLToolDragAndDrop::dropMaterialOneFace(LLViewerObject* hit_objp,
  1048. S32 hit_face,
  1049. LLInventoryItem* itemp,
  1050. ESource source,
  1051. const LLUUID& src_id)
  1052. {
  1053. if (!hit_objp)
  1054. {
  1055. llwarns << "No hit object." << llendl;
  1056. return;
  1057. }
  1058. if (hit_face == -1)
  1059. {
  1060. return;
  1061. }
  1062. if (!itemp || itemp->getInventoryType() != LLInventoryType::IT_MATERIAL)
  1063. {
  1064. llwarns << "No material item." << llendl;
  1065. return;
  1066. }
  1067. // SL-20013 must save asset_id before handleDropAssetProtections since
  1068. // our itemp instance may be deleted if it is moved into task inventory.
  1069. LLUUID asset_id = itemp->getAssetUUID();
  1070. if (!handleDropAssetProtections(hit_objp, itemp, source, src_id))
  1071. {
  1072. return;
  1073. }
  1074. if (asset_id.isNull())
  1075. {
  1076. // Use blank material
  1077. asset_id = BLANK_MATERIAL_ASSET_ID;
  1078. }
  1079. hit_objp->setRenderMaterialID(hit_face, asset_id);
  1080. dialog_refresh_all();
  1081. // Send the update to the simulator
  1082. hit_objp->sendTEUpdate();
  1083. }
  1084. void LLToolDragAndDrop::dropMaterialAllFaces(LLViewerObject* hit_objp,
  1085. LLInventoryItem* itemp,
  1086. ESource source,
  1087. const LLUUID& src_id)
  1088. {
  1089. if (!itemp || itemp->getInventoryType() != LLInventoryType::IT_MATERIAL)
  1090. {
  1091. llwarns << "No material item." << llendl;
  1092. return;
  1093. }
  1094. // SL-20013 must save asset_id before handleDropAssetProtections since
  1095. // our itemp instance may be deleted if it is moved into task inventory.
  1096. LLUUID asset_id = itemp->getAssetUUID();
  1097. if (!handleDropAssetProtections(hit_objp, itemp, source, src_id))
  1098. {
  1099. return;
  1100. }
  1101. if (asset_id.isNull())
  1102. {
  1103. // Use blank material
  1104. asset_id = BLANK_MATERIAL_ASSET_ID;
  1105. }
  1106. hit_objp->setRenderMaterialIDs(asset_id);
  1107. dialog_refresh_all();
  1108. // Send the update to the simulator
  1109. hit_objp->sendTEUpdate();
  1110. }
  1111. #if LL_MESH_ASSET_SUPPORT
  1112. //static
  1113. void LLToolDragAndDrop::dropMesh(LLViewerObject* hit_objp,
  1114. LLInventoryItem* itemp,
  1115. ESource source,
  1116. const LLUUID& src_id)
  1117. {
  1118. if (!hit_objp)
  1119. {
  1120. llwarns << "No hit object." << llendl;
  1121. return;
  1122. }
  1123. if (!itemp)
  1124. {
  1125. llwarns << "No inventory item." << llendl;
  1126. return;
  1127. }
  1128. if (!handleDropAssetProtections(hit_objp, itemp, source, src_id)
  1129. {
  1130. return;
  1131. }
  1132. const LLUUID& asset_id = itemp->getAssetUUID();
  1133. LLSculptParams sculpt_params;
  1134. sculpt_params.setSculptTexture(asset_id, LL_SCULPT_TYPE_MESH);
  1135. hit_objp->setParameterEntry(LLNetworkData::PARAMS_SCULPT, sculpt_params,
  1136. true);
  1137. dialog_refresh_all();
  1138. }
  1139. #endif
  1140. //static
  1141. void LLToolDragAndDrop::dropScript(LLViewerObject* hit_objp,
  1142. LLInventoryItem* itemp, bool active,
  1143. ESource source, const LLUUID& src_id)
  1144. {
  1145. // *HACK: In order to resolve SL-22177, we need to block drags
  1146. // from notecards and objects onto other objects.
  1147. ESource source2 = gToolDragAndDrop.mSource;
  1148. if (source2 == SOURCE_WORLD || source2 == SOURCE_NOTECARD)
  1149. {
  1150. llwarns << "Illegal call, from world or notecard." << llendl;
  1151. return;
  1152. }
  1153. if (!hit_objp || !itemp)
  1154. {
  1155. return;
  1156. }
  1157. //MK
  1158. if (gRLenabled)
  1159. {
  1160. // Cannot edit objects that we are sitting on, when sit-restricted
  1161. if ((gRLInterface.mSittpMax < EXTREMUM ||
  1162. gRLInterface.mContainsUnsit) &&
  1163. hit_objp->isAgentSeat())
  1164. {
  1165. LL_DEBUGS("DragAndDrop") << "Cannot drop script in RLV locked seat"
  1166. << LL_ENDL;
  1167. return;
  1168. }
  1169. if (!gRLInterface.canDetach(hit_objp))
  1170. {
  1171. LL_DEBUGS("DragAndDrop") << "Cannot drop script in RLV locked attachment"
  1172. << LL_ENDL;
  1173. return;
  1174. }
  1175. }
  1176. //mk
  1177. LLPointer<LLViewerInventoryItem> new_scriptp =
  1178. new LLViewerInventoryItem(itemp);
  1179. if (!itemp->getPermissions().allowCopyBy(gAgentID))
  1180. {
  1181. if (source == SOURCE_AGENT)
  1182. {
  1183. // Remove the script from local inventory. The server will actually
  1184. // remove the item from agent inventory.
  1185. gInventory.deleteObject(itemp->getUUID());
  1186. gInventory.notifyObservers();
  1187. }
  1188. else if (source == SOURCE_WORLD)
  1189. {
  1190. // *FIX: if the objects are in different regions, and the source
  1191. // region has crashed, you can bypass these permissions.
  1192. LLViewerObject* src_objp = gObjectList.findObject(src_id);
  1193. if (!src_objp)
  1194. {
  1195. llwarns << "Unable to find source object." << llendl;
  1196. return;
  1197. }
  1198. src_objp->removeInventory(itemp->getUUID());
  1199. }
  1200. }
  1201. hit_objp->saveScript(new_scriptp, active, true);
  1202. if (gFloaterToolsp)
  1203. {
  1204. gFloaterToolsp->dirty();
  1205. }
  1206. // VEFFECT: SetScript
  1207. LLHUDEffectSpiral::agentBeamToObject(hit_objp);
  1208. }
  1209. void LLToolDragAndDrop::dropObject(LLViewerObject* hit_objp,
  1210. bool bypass_sim_raycast,
  1211. bool from_task_inventory,
  1212. bool remove_from_inventory)
  1213. {
  1214. LLViewerRegion* regionp = gWorld.getRegionFromPosGlobal(mLastHitPos);
  1215. if (!regionp)
  1216. {
  1217. llwarns << "Could not find region to rez object" << llendl;
  1218. return;
  1219. }
  1220. //MK
  1221. if (gRLenabled &&
  1222. (gRLInterface.mContainsRez || gRLInterface.mContainsInteract))
  1223. {
  1224. return;
  1225. }
  1226. //mk
  1227. LLViewerInventoryItem* itemp;
  1228. LLViewerInventoryCategory* catp;
  1229. locateInventory(itemp, catp);
  1230. if (!itemp || !itemp->isFinished())
  1231. {
  1232. LL_DEBUGS("DragAndDrop") << "Inventory item is not finished. Aborted."
  1233. << LL_ENDL;
  1234. return;
  1235. }
  1236. const LLUUID& item_id = itemp->getUUID();
  1237. LL_DEBUGS("DragAndDrop") << "Rezzing object" << LL_ENDL;
  1238. make_ui_sound("UISndObjectRezIn");
  1239. if (regionp && regionp->getRegionFlag(REGION_FLAGS_SANDBOX))
  1240. {
  1241. LLFirstUse::useSandbox();
  1242. }
  1243. // Limit raycast to a single object. Speeds up server raycast and avoids
  1244. // problems with server ray hitting objects that were clipped by the near
  1245. // plane or culled on the viewer.
  1246. LLUUID ray_target_id;
  1247. if (hit_objp)
  1248. {
  1249. ray_target_id = hit_objp->getID();
  1250. }
  1251. // Check if it cannot be copied, and mark as remove in that case: this will
  1252. // remove the object from inventory after rezzing. Only bother with this
  1253. // check if we would not normally remove from inventory.
  1254. if (!remove_from_inventory &&
  1255. !itemp->getPermissions().allowCopyBy(gAgentID))
  1256. {
  1257. remove_from_inventory = true;
  1258. }
  1259. // Check if it is in the trash.
  1260. bool is_in_trash = gInventory.isInTrash(item_id);
  1261. const LLUUID& source_id = from_task_inventory ? mSourceID : LLUUID::null;
  1262. // Select the object only if we're editing.
  1263. bool rez_selected = gToolMgr.inEdit();
  1264. LLVector3 ray_start = regionp->getPosRegionFromGlobal(mLastCameraPos);
  1265. LLVector3 ray_end = regionp->getPosRegionFromGlobal(mLastHitPos);
  1266. // Currently the ray's end point is an approximation, and is sometimes too
  1267. // short (causing failure), so we double the ray's length:
  1268. if (!bypass_sim_raycast)
  1269. {
  1270. LLVector3 ray_direction = ray_start - ray_end;
  1271. ray_end = ray_end - ray_direction;
  1272. }
  1273. // Message packing code should be it's own uninterrupted block
  1274. LLMessageSystem* msg = gMessageSystemp;
  1275. if (mSource == SOURCE_NOTECARD)
  1276. {
  1277. msg->newMessageFast(_PREHASH_RezObjectFromNotecard);
  1278. }
  1279. else
  1280. {
  1281. msg->newMessageFast(_PREHASH_RezObject);
  1282. }
  1283. msg->nextBlockFast(_PREHASH_AgentData);
  1284. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1285. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  1286. LLUUID group_id = gAgent.getGroupID();
  1287. if (gSavedSettings.getBool("RezWithLandGroup"))
  1288. {
  1289. LLParcel* parcelp = gViewerParcelMgr.getAgentParcel();
  1290. if (gAgent.isInGroup(parcelp->getGroupID()))
  1291. {
  1292. group_id = parcelp->getGroupID();
  1293. }
  1294. else if (gAgent.isInGroup(parcelp->getOwnerID()))
  1295. {
  1296. group_id = parcelp->getOwnerID();
  1297. }
  1298. }
  1299. msg->addUUIDFast(_PREHASH_GroupID, group_id);
  1300. msg->nextBlock("RezData");
  1301. // If it is being rezzed from task inventory, we need to enable saving it
  1302. // back into the task inventory.
  1303. // *FIXME: We can probably compress this to a single byte, since I think
  1304. // folderid == mSourceID. This will be a later optimization.
  1305. msg->addUUIDFast(_PREHASH_FromTaskID, source_id);
  1306. msg->addU8Fast(_PREHASH_BypassRaycast, (U8)bypass_sim_raycast);
  1307. msg->addVector3Fast(_PREHASH_RayStart, ray_start);
  1308. msg->addVector3Fast(_PREHASH_RayEnd, ray_end);
  1309. msg->addUUIDFast(_PREHASH_RayTargetID, ray_target_id);
  1310. msg->addBoolFast(_PREHASH_RayEndIsIntersection, false);
  1311. msg->addBoolFast(_PREHASH_RezSelected, rez_selected);
  1312. msg->addBoolFast(_PREHASH_RemoveItem, remove_from_inventory);
  1313. // Deal with permissions slam logic
  1314. pack_permissions_slam(msg, itemp->getFlags(), itemp->getPermissions());
  1315. LLUUID folder_id = itemp->getParentUUID();
  1316. if (mSource == SOURCE_LIBRARY || is_in_trash)
  1317. {
  1318. // Since it is coming from the library or trash, we want to not 'take'
  1319. // it back to the same place.
  1320. itemp->setParent(LLUUID::null);
  1321. // *TODO this code is not working: the parent (FolderID) is still set
  1322. // when the object is "taken". So code on the "take" side is checking
  1323. // for trash and library as well (llviewermenu.cpp)
  1324. LL_DEBUGS("DragAndDrop") << "Rezzed object parent set to a null UUID"
  1325. << LL_ENDL;
  1326. }
  1327. if (mSource == SOURCE_NOTECARD)
  1328. {
  1329. msg->nextBlockFast(_PREHASH_NotecardData);
  1330. msg->addUUIDFast(_PREHASH_NotecardItemID, mSourceID);
  1331. msg->addUUIDFast(_PREHASH_ObjectID, mObjectID);
  1332. msg->nextBlockFast(_PREHASH_InventoryData);
  1333. msg->addUUIDFast(_PREHASH_ItemID, item_id);
  1334. LL_DEBUGS("DragAndDrop") << "Rezzed object parent set to a notecard"
  1335. << LL_ENDL;
  1336. }
  1337. else
  1338. {
  1339. msg->nextBlockFast(_PREHASH_InventoryData);
  1340. itemp->packMessage(msg);
  1341. LL_DEBUGS("DragAndDrop") << "Rezzed object parent set to category: "
  1342. << folder_id.asString() << LL_ENDL;
  1343. }
  1344. msg->sendReliable(regionp->getHost());
  1345. // Back out the change; no actual internal changes take place.
  1346. itemp->setParent(folder_id);
  1347. // If we are going to select it, get ready for the incoming selected object
  1348. if (rez_selected)
  1349. {
  1350. gSelectMgr.deselectAll();
  1351. gWindowp->incBusyCount();
  1352. }
  1353. if (remove_from_inventory)
  1354. {
  1355. // Delete it from inventory immediately so that users cannot easily
  1356. // bypass copy protection in laggy situations. If the rez fails, we
  1357. // will put it back on the server.
  1358. gInventory.deleteObject(item_id);
  1359. gInventory.notifyObservers();
  1360. }
  1361. // VEFFECT: DropObject
  1362. LLHUDEffectSpiral::agentBeamToPosition(mLastHitPos);
  1363. gViewerStats.incStat(LLViewerStats::ST_REZ_COUNT);
  1364. }
  1365. //static
  1366. void LLToolDragAndDrop::dropInventory(LLViewerObject* hit_objp,
  1367. LLInventoryItem* itemp,
  1368. ESource source,
  1369. const LLUUID& src_id)
  1370. {
  1371. if (!hit_objp)
  1372. {
  1373. llwarns << "No hit object." << llendl;
  1374. return;
  1375. }
  1376. if (!itemp)
  1377. {
  1378. llwarns << "No inventory item." << llendl;
  1379. return;
  1380. }
  1381. // *HACK: in order to resolve SL-22177, we need to block drags from
  1382. // notecards and objects onto other objects.
  1383. ESource source2 = gToolDragAndDrop.mSource;
  1384. if (source2 == SOURCE_WORLD || source2 == SOURCE_NOTECARD)
  1385. {
  1386. llwarns << "Illegal call done from world or notecard." << llendl;
  1387. return;
  1388. }
  1389. LLPointer<LLViewerInventoryItem> new_itemp =
  1390. new LLViewerInventoryItem(itemp);
  1391. time_t creation_date = time_corrected();
  1392. new_itemp->setCreationDate(creation_date);
  1393. if (!itemp->getPermissions().allowCopyBy(gAgentID))
  1394. {
  1395. if (source == SOURCE_AGENT)
  1396. {
  1397. // Remove the inventory item from local inventory. The server will
  1398. // actually remove the item from agent inventory.
  1399. gInventory.deleteObject(itemp->getUUID());
  1400. gInventory.notifyObservers();
  1401. }
  1402. else if (source == SOURCE_WORLD)
  1403. {
  1404. // *FIX: if the objects are in different regions, and the source
  1405. // region has crashed, you can bypass these permissions.
  1406. LLViewerObject* src_objp = gObjectList.findObject(src_id);
  1407. if (src_objp)
  1408. {
  1409. src_objp->removeInventory(itemp->getUUID());
  1410. }
  1411. else
  1412. {
  1413. llwarns << "Unable to find source object." << llendl;
  1414. return;
  1415. }
  1416. }
  1417. }
  1418. hit_objp->updateInventory(new_itemp, true);
  1419. if (LLFloaterTools::isVisible())
  1420. {
  1421. // *FIX: only show this if panel not expanded ?
  1422. gFloaterToolsp->showPanel(LLFloaterTools::PANEL_CONTENTS);
  1423. }
  1424. // VEFFECT: AddToInventory
  1425. LLHUDEffectSpiral::agentBeamToObject(hit_objp);
  1426. if (gFloaterToolsp)
  1427. {
  1428. gFloaterToolsp->dirty();
  1429. }
  1430. }
  1431. struct LLGiveInventoryInfo
  1432. {
  1433. LLUUID mToAgentID;
  1434. LLUUID mInventoryObjectID;
  1435. LLUUID mIMSessionID;
  1436. LLGiveInventoryInfo(const LLUUID& to_agent, const LLUUID& obj_id,
  1437. const LLUUID& im_session_id = LLUUID::null)
  1438. : mToAgentID(to_agent),
  1439. mInventoryObjectID(obj_id),
  1440. mIMSessionID(im_session_id)
  1441. {
  1442. }
  1443. };
  1444. //static
  1445. void LLToolDragAndDrop::giveInventory(const LLUUID& to_agent,
  1446. LLInventoryItem* itemp,
  1447. const LLUUID& im_session_id)
  1448. {
  1449. if (!itemp || !isInventoryGiveAcceptable(itemp))
  1450. {
  1451. return;
  1452. }
  1453. //MK
  1454. if (gRLenabled &&
  1455. gRLInterface.containsWithoutException("share", to_agent.asString()))
  1456. {
  1457. gNotifications.add("CannotGiveItem");
  1458. return;
  1459. }
  1460. //mk
  1461. const LLUUID& item_id = itemp->getUUID();
  1462. llinfos << "Giving inventory item " << item_id << " to agent "
  1463. << to_agent << llendl;
  1464. if (itemp->getPermissions().allowCopyBy(gAgentID))
  1465. {
  1466. // Just give it away.
  1467. commitGiveInventoryItem(to_agent, itemp, im_session_id);
  1468. }
  1469. else
  1470. {
  1471. // Ask if the agent is sure.
  1472. LLSD payload;
  1473. payload["agent_id"] = to_agent;
  1474. payload["item_id"] = item_id;
  1475. gNotifications.add("CannotCopyWarning", LLSD(), payload,
  1476. &handleCopyProtectedItem);
  1477. }
  1478. }
  1479. //static
  1480. bool LLToolDragAndDrop::handleCopyProtectedItem(const LLSD& notification,
  1481. const LLSD& response)
  1482. {
  1483. if (LLNotification::getSelectedOption(notification, response))
  1484. {
  1485. // No, cancel, whatever, who cares, not yes.
  1486. gNotifications.add("TransactionCancelled");
  1487. return false;
  1488. }
  1489. LLInventoryItem* itemp =
  1490. gInventory.getItem(notification["payload"]["item_id"].asUUID());
  1491. if (!itemp)
  1492. {
  1493. gNotifications.add("CannotGiveItem");
  1494. return false;
  1495. }
  1496. LLUUID agent_id = notification["payload"]["agent_id"].asUUID();
  1497. commitGiveInventoryItem(agent_id, itemp);
  1498. // Delete it from viewer inventory for now; it will be deleted on the
  1499. // server quickly enough.
  1500. gInventory.deleteObject(notification["payload"]["item_id"].asUUID());
  1501. gInventory.notifyObservers();
  1502. return false;
  1503. }
  1504. //static
  1505. void LLToolDragAndDrop::commitGiveInventoryItem(const LLUUID& to_agent,
  1506. LLInventoryItem* itemp,
  1507. const LLUUID& im_session_id)
  1508. {
  1509. if (!itemp) return;
  1510. std::string name;
  1511. gAgent.buildFullname(name);
  1512. LLUUID transaction_id;
  1513. transaction_id.generate();
  1514. constexpr S32 BUCKET_SIZE = sizeof(U8) + UUID_BYTES;
  1515. U8 bucket[BUCKET_SIZE];
  1516. bucket[0] = (U8)itemp->getType();
  1517. memcpy(&bucket[1], &(itemp->getUUID().mData), UUID_BYTES);
  1518. pack_instant_message(gAgentID, false, gAgentSessionID, to_agent, name,
  1519. itemp->getName(), IM_ONLINE, IM_INVENTORY_OFFERED,
  1520. transaction_id, 0, LLUUID::null,
  1521. gAgent.getPositionAgent(), NO_TIMESTAMP, bucket,
  1522. BUCKET_SIZE);
  1523. gAgent.sendReliableMessage();
  1524. // VEFFECT: giveInventory
  1525. LLHUDEffectSpiral::agentBeamToObject(gObjectList.findObject(to_agent));
  1526. if (gFloaterToolsp)
  1527. {
  1528. gFloaterToolsp->dirty();
  1529. }
  1530. LLMuteList::autoRemove(to_agent, LLMuteList::AR_INVENTORY);
  1531. // If this item was given by drag-and-drop into an IM panel, log this
  1532. // action in the IM panel chat.
  1533. if (im_session_id.notNull() && gIMMgrp)
  1534. {
  1535. LLSD args;
  1536. gIMMgrp->addSystemMessage(im_session_id, "inventory_item_offered",
  1537. args);
  1538. }
  1539. }
  1540. //static
  1541. void LLToolDragAndDrop::giveInventoryCategory(const LLUUID& to_agent,
  1542. LLInventoryCategory* catp,
  1543. const LLUUID& im_session_id)
  1544. {
  1545. if (!catp || !isAgentAvatarValid())
  1546. {
  1547. return;
  1548. }
  1549. //MK
  1550. if (gRLenabled &&
  1551. gRLInterface.containsWithoutException("share", to_agent.asString()))
  1552. {
  1553. gNotifications.add("CannotGiveItem");
  1554. return;
  1555. }
  1556. //mk
  1557. const LLUUID& cat_id = catp->getUUID();
  1558. llinfos << "Giving inventory folder " << cat_id << " to agent "
  1559. << to_agent << llendl;
  1560. // Test out how many items are being given.
  1561. LLViewerInventoryCategory::cat_array_t cats;
  1562. LLViewerInventoryItem::item_array_t items;
  1563. LLGiveable giveable;
  1564. gInventory.collectDescendentsIf(cat_id, cats, items,
  1565. LLInventoryModel::EXCLUDE_TRASH, giveable);
  1566. S32 count = cats.size();
  1567. bool complete = true;
  1568. for (S32 i = 0; i < count; ++i)
  1569. {
  1570. if (!gInventory.isCategoryComplete(cats[i]->getUUID()))
  1571. {
  1572. complete = false;
  1573. break;
  1574. }
  1575. }
  1576. if (!complete)
  1577. {
  1578. gNotifications.add("IncompleteInventory");
  1579. return;
  1580. }
  1581. count = items.size() + cats.size();
  1582. if (count > MAX_ITEMS)
  1583. {
  1584. gNotifications.add("TooManyItems");
  1585. return;
  1586. }
  1587. if (count == 0)
  1588. {
  1589. gNotifications.add("NoItems");
  1590. return;
  1591. }
  1592. if (giveable.countNoCopy() == 0)
  1593. {
  1594. commitGiveInventoryCategory(to_agent, catp, im_session_id);
  1595. }
  1596. else
  1597. {
  1598. LLSD args;
  1599. args["COUNT"] = llformat("%d",giveable.countNoCopy());
  1600. LLSD payload;
  1601. payload["agent_id"] = to_agent;
  1602. payload["folder_id"] = cat_id;
  1603. gNotifications.add("CannotCopyCountItems", args, payload,
  1604. &LLToolDragAndDrop::handleCopyProtectedCategory);
  1605. }
  1606. }
  1607. //static
  1608. bool LLToolDragAndDrop::handleCopyProtectedCategory(const LLSD& notification,
  1609. const LLSD& response)
  1610. {
  1611. if (LLNotification::getSelectedOption(notification, response) == 0)
  1612. {
  1613. LLInventoryCategory* cat =
  1614. gInventory.getCategory(notification["payload"]["folder_id"].asUUID());
  1615. if (cat)
  1616. {
  1617. LLUUID agent_id = notification["payload"]["agent_id"].asUUID();
  1618. commitGiveInventoryCategory(agent_id, cat);
  1619. LLViewerInventoryCategory::cat_array_t cats;
  1620. LLViewerInventoryItem::item_array_t items;
  1621. LLUncopyableItems remove;
  1622. gInventory.collectDescendentsIf(cat->getUUID(), cats, items,
  1623. LLInventoryModel::EXCLUDE_TRASH,
  1624. remove);
  1625. for (S32 i = 0, count = items.size(); i < count; ++i)
  1626. {
  1627. gInventory.deleteObject(items[i]->getUUID());
  1628. }
  1629. gInventory.notifyObservers();
  1630. }
  1631. else
  1632. {
  1633. gNotifications.add("CannotGiveCategory");
  1634. }
  1635. }
  1636. else // No, cancel, whatever, who cares, not yes.
  1637. {
  1638. gNotifications.add("TransactionCancelled");
  1639. }
  1640. return false;
  1641. }
  1642. //static
  1643. void LLToolDragAndDrop::commitGiveInventoryCategory(const LLUUID& to_agent,
  1644. LLInventoryCategory* cat,
  1645. const LLUUID& im_session_id)
  1646. {
  1647. if (!cat) return;
  1648. // Test out how many items are being given.
  1649. LLViewerInventoryCategory::cat_array_t cats;
  1650. LLViewerInventoryItem::item_array_t items;
  1651. LLGiveable giveable;
  1652. gInventory.collectDescendentsIf(cat->getUUID(), cats, items,
  1653. LLInventoryModel::EXCLUDE_TRASH,
  1654. giveable);
  1655. // MAX ITEMS is based on (sizeof(uuid)+2) * count must be < MTUBYTES or
  1656. // 18 * count < 1200 => count < 1200/18 => 66. I have cut it down a bit
  1657. // from there to give some pad.
  1658. S32 count = items.size() + cats.size();
  1659. if (count > MAX_ITEMS)
  1660. {
  1661. gNotifications.add("TooManyItems");
  1662. return;
  1663. }
  1664. if (count == 0)
  1665. {
  1666. gNotifications.add("NoItems");
  1667. return;
  1668. }
  1669. llinfos << "Giving inventory folder " << cat->getUUID() << " now."
  1670. << llendl;
  1671. std::string name;
  1672. gAgent.buildFullname(name);
  1673. LLUUID transaction_id;
  1674. transaction_id.generate();
  1675. S32 bucket_size = (sizeof(U8) + UUID_BYTES) * (count + 1);
  1676. U8* bucket = new U8[bucket_size];
  1677. U8* pos = bucket;
  1678. U8 type = (U8)cat->getType();
  1679. memcpy(pos, &type, sizeof(U8));
  1680. pos += sizeof(U8);
  1681. memcpy(pos, &(cat->getUUID()), UUID_BYTES);
  1682. pos += UUID_BYTES;
  1683. for (S32 i = 0, count = cats.size(); i < count; ++i)
  1684. {
  1685. memcpy(pos, &type, sizeof(U8));
  1686. pos += sizeof(U8);
  1687. memcpy(pos, &(cats[i]->getUUID()), UUID_BYTES);
  1688. pos += UUID_BYTES;
  1689. }
  1690. for (S32 i = 0, count = items.size(); i < count; ++i)
  1691. {
  1692. type = (U8)items[i]->getType();
  1693. memcpy(pos, &type, sizeof(U8));
  1694. pos += sizeof(U8);
  1695. memcpy(pos, &(items[i]->getUUID()), UUID_BYTES);
  1696. pos += UUID_BYTES;
  1697. }
  1698. pack_instant_message(gAgentID, false, gAgentSessionID, to_agent, name,
  1699. cat->getName(), IM_ONLINE, IM_INVENTORY_OFFERED,
  1700. transaction_id, 0, LLUUID::null,
  1701. gAgent.getPositionAgent(), NO_TIMESTAMP, bucket,
  1702. bucket_size);
  1703. gAgent.sendReliableMessage();
  1704. delete[] bucket;
  1705. // VEFFECT: giveInventoryCategory
  1706. LLHUDEffectSpiral::agentBeamToObject(gObjectList.findObject(to_agent));
  1707. if (gFloaterToolsp)
  1708. {
  1709. gFloaterToolsp->dirty();
  1710. }
  1711. LLMuteList::autoRemove(to_agent, LLMuteList::AR_INVENTORY);
  1712. // If this item was given by drag-and-drop into an IM panel, log this
  1713. // action in the IM panel chat.
  1714. if (im_session_id.notNull() && gIMMgrp)
  1715. {
  1716. LLSD args;
  1717. gIMMgrp->addSystemMessage(im_session_id, "inventory_item_offered",
  1718. args);
  1719. }
  1720. }
  1721. //static
  1722. bool LLToolDragAndDrop::isInventoryGiveAcceptable(LLInventoryItem* itemp)
  1723. {
  1724. if (!isAgentAvatarValid() || !itemp ||
  1725. !itemp->getPermissions().allowTransferBy(gAgentID))
  1726. {
  1727. LL_DEBUGS("DragAndDrop") << "Cannot give away this inventory item"
  1728. << LL_ENDL;
  1729. return false;
  1730. }
  1731. bool acceptable = true;
  1732. switch (itemp->getType())
  1733. {
  1734. case LLAssetType::AT_OBJECT:
  1735. if (gAgentAvatarp->isWearingAttachment(itemp->getUUID()))
  1736. {
  1737. acceptable = false;
  1738. LL_DEBUGS("DragAndDrop") << "Cannot give away an attached inventory item"
  1739. << LL_ENDL;
  1740. }
  1741. break;
  1742. case LLAssetType::AT_BODYPART:
  1743. case LLAssetType::AT_CLOTHING:
  1744. if (!itemp->getPermissions().allowCopyBy(gAgentID) &&
  1745. gAgentWearables.isWearingItem(itemp->getUUID()))
  1746. {
  1747. acceptable = false;
  1748. LL_DEBUGS("DragAndDrop") << "Cannot give away a worn inventory item"
  1749. << LL_ENDL;
  1750. }
  1751. break;
  1752. default:
  1753. break;
  1754. }
  1755. return acceptable;
  1756. }
  1757. //static
  1758. bool LLToolDragAndDrop::isInventoryGroupGiveAcceptable(LLInventoryItem* itemp)
  1759. {
  1760. if (!itemp || !isAgentAvatarValid()) return false;
  1761. const LLPermissions& perms = itemp->getPermissions();
  1762. if (!perms.allowTransferBy(gAgentID) || !perms.allowCopyBy(gAgentID))
  1763. {
  1764. LL_DEBUGS("DragAndDrop") << "Cannot give away this inventory item: insufficient permissions."
  1765. << LL_ENDL;
  1766. return false;
  1767. }
  1768. if (itemp->getType() == LLAssetType::AT_OBJECT &&
  1769. gAgentAvatarp->isWearingAttachment(itemp->getUUID()))
  1770. {
  1771. LL_DEBUGS("DragAndDrop") << "Cannot give away an attached inventory item"
  1772. << LL_ENDL;
  1773. return false;
  1774. }
  1775. return true;
  1776. }
  1777. // Accessor that looks at permissions, copyability, and names of inventory
  1778. // items to determine if a drop would be ok.
  1779. EAcceptance LLToolDragAndDrop::willObjectAcceptInventory(LLViewerObject* objp,
  1780. LLInventoryItem* itemp,
  1781. EDragAndDropType type)
  1782. {
  1783. // Check the basics
  1784. if (!itemp || !objp) return ACCEPT_NO;
  1785. //MK
  1786. if (gRLenabled)
  1787. {
  1788. // Cannot edit objects that someone is sitting on, when prevented from
  1789. // sit-tping
  1790. if ((gRLInterface.mSittpMax < EXTREMUM ||
  1791. gRLInterface.mContainsUnsit) &&
  1792. objp->isAgentSeat())
  1793. {
  1794. LL_DEBUGS("DragAndDrop") << "Object is a seat and sit is RLV locked; drop refused."
  1795. << LL_ENDL;
  1796. return ACCEPT_NO_LOCKED;
  1797. }
  1798. if (!gRLInterface.canDetach(objp))
  1799. {
  1800. LL_DEBUGS("DragAndDrop") << "Attachment is RLV locked; drop refused."
  1801. << LL_ENDL;
  1802. return ACCEPT_NO_LOCKED;
  1803. }
  1804. // If the origin folder is locked, do not allow to drop an item from
  1805. // it into the inventory of an object because then the user could
  1806. // get back the item from that object and place it into a non-locked
  1807. // inventory folder to wear it, bypassing the lock.
  1808. const LLUUID& parent_id = itemp->getParentUUID();
  1809. if (gRLInterface.isFolderLocked(gInventory.getCategory(parent_id)))
  1810. {
  1811. LL_DEBUGS("DragAndDrop") << "Inventory folder is RLV locked; drop refused."
  1812. << LL_ENDL;
  1813. return ACCEPT_NO_LOCKED;
  1814. }
  1815. }
  1816. //mk
  1817. // *HACK: down-cast
  1818. LLViewerInventoryItem* vitemp = (LLViewerInventoryItem*)itemp;
  1819. if (type != DAD_CATEGORY && !vitemp->isFinished())
  1820. {
  1821. // Note: for DAD_CATEGORY we assume that folder version check passed
  1822. // and folder is complete, meaning that items inside are up to date.
  1823. // isFinished() is false at the moment shows that item was loaded from
  1824. // cache. Library or agent inventory only.
  1825. LL_DEBUGS("DragAndDrop") << "Inventory item not yet fully loaded, refusing drop for now."
  1826. << LL_ENDL;
  1827. return ACCEPT_NO;
  1828. }
  1829. if (vitemp->getIsLinkType())
  1830. {
  1831. // Never give away links
  1832. LL_DEBUGS("DragAndDrop") << "Cannot give away an inventory link"
  1833. << LL_ENDL;
  1834. return ACCEPT_NO;
  1835. }
  1836. // Deny attempts to drop from an object onto itself. This is to help and
  1837. // make sure that drops that are from an object to an object do not have to
  1838. // worry about order of evaluation. Think of this like check for self in
  1839. // assignment.
  1840. if (objp->getID() == itemp->getParentUUID())
  1841. {
  1842. LL_DEBUGS("DragAndDrop") << "Cannot drop object onto itself"
  1843. << LL_ENDL;
  1844. return ACCEPT_NO;
  1845. }
  1846. bool worn = false;
  1847. switch (itemp->getType())
  1848. {
  1849. case LLAssetType::AT_OBJECT:
  1850. if (isAgentAvatarValid() &&
  1851. gAgentAvatarp->isWearingAttachment(itemp->getUUID()))
  1852. {
  1853. worn = true;
  1854. }
  1855. break;
  1856. case LLAssetType::AT_BODYPART:
  1857. case LLAssetType::AT_CLOTHING:
  1858. if (gAgentWearables.isWearingItem(itemp->getUUID()))
  1859. {
  1860. worn = true;
  1861. }
  1862. break;
  1863. case LLAssetType::AT_CALLINGCARD:
  1864. // Calling cards in object are disabled for now because of
  1865. // incomplete LSL support. See STORM-1117.
  1866. LL_DEBUGS("DragAndDrop") << "Calling cards cannot be dropped in objects"
  1867. << LL_ENDL;
  1868. return ACCEPT_NO;
  1869. default:
  1870. break;
  1871. }
  1872. const LLPermissions& perm = itemp->getPermissions();
  1873. // If attached and not full perm, cannot accept.
  1874. if (objp->isAttachment() && !perm.unrestricted())
  1875. {
  1876. return ACCEPT_NO_LOCKED;
  1877. }
  1878. bool modify = objp->permModify() || objp->flagAllowInventoryAdd();
  1879. bool transfer = false;
  1880. if ((objp->permYouOwner() && perm.getOwner() == gAgentID) ||
  1881. perm.allowTransferBy(gAgentID))
  1882. {
  1883. transfer = true;
  1884. }
  1885. bool volume = objp->getPCode() == LL_PCODE_VOLUME;
  1886. if (modify && transfer && volume && !worn)
  1887. {
  1888. return ACCEPT_YES_MULTI;
  1889. }
  1890. else if (!modify)
  1891. {
  1892. LL_DEBUGS("DragAndDrop") << "Object is no mod and does not allow inventory add"
  1893. << LL_ENDL;
  1894. return ACCEPT_NO_LOCKED;
  1895. }
  1896. LL_DEBUGS("DragAndDrop") << " - worn: " << (worn ? "true": "false")
  1897. << " - mod/add permission: "
  1898. << (modify ? "true": "false")
  1899. << " - transfer permission: "
  1900. << (transfer ? "true": "false")
  1901. << " - Drop action refused." << LL_ENDL;
  1902. return ACCEPT_NO;
  1903. }
  1904. // Method used as drag-and-drop handler for simple agent give inventory
  1905. // requests
  1906. //static
  1907. bool LLToolDragAndDrop::handleGiveDragAndDrop(const LLUUID& dest_agent,
  1908. const LLUUID& session_id,
  1909. bool drop,
  1910. EDragAndDropType cargo_type,
  1911. void* cargo_data,
  1912. EAcceptance* accept)
  1913. {
  1914. //MK
  1915. if (gRLenabled &&
  1916. gRLInterface.containsWithoutException("share", dest_agent.asString()))
  1917. {
  1918. *accept = ACCEPT_NO;
  1919. return true;
  1920. }
  1921. //mk
  1922. if ((cargo_type == DAD_SETTINGS && !gAgent.hasInventorySettings()) ||
  1923. (cargo_type == DAD_MATERIAL && !gAgent.hasInventoryMaterial()))
  1924. {
  1925. return false;
  1926. }
  1927. // Check the type
  1928. switch (cargo_type)
  1929. {
  1930. case DAD_TEXTURE:
  1931. case DAD_SOUND:
  1932. case DAD_LANDMARK:
  1933. case DAD_SCRIPT:
  1934. case DAD_OBJECT:
  1935. case DAD_NOTECARD:
  1936. case DAD_CLOTHING:
  1937. case DAD_BODYPART:
  1938. case DAD_ANIMATION:
  1939. case DAD_GESTURE:
  1940. case DAD_CALLINGCARD:
  1941. #if LL_MESH_ASSET_SUPPORT
  1942. case DAD_MESH:
  1943. case DAD_GLTF:
  1944. case DAD_GLTF_BIN:
  1945. #endif
  1946. case DAD_SETTINGS:
  1947. case DAD_MATERIAL:
  1948. {
  1949. LLInventoryObject* inv_objp = (LLInventoryObject*)cargo_data;
  1950. LLInventoryItem* inv_item = inv_objp->asInventoryItem();
  1951. if (inv_item && gInventory.getItem(inv_objp->getUUID()) &&
  1952. isInventoryGiveAcceptable(inv_item))
  1953. {
  1954. // *TODO: get multiple object transfers working
  1955. *accept = ACCEPT_YES_COPY_SINGLE;
  1956. if (drop)
  1957. {
  1958. giveInventory(dest_agent, inv_item, session_id);
  1959. }
  1960. }
  1961. else
  1962. {
  1963. // It is not in the user's inventory (it is probably contained
  1964. // in an object), so disallow dragging it here. You cannot give
  1965. // something you do not yet have.
  1966. *accept = ACCEPT_NO;
  1967. LL_DEBUGS("DragAndDrop") << "Item is not in user inventory. Refusing."
  1968. << LL_ENDL;
  1969. }
  1970. break;
  1971. }
  1972. case DAD_CATEGORY:
  1973. {
  1974. LLViewerInventoryCategory* inv_cat =
  1975. (LLViewerInventoryCategory*)cargo_data;
  1976. if (gInventory.getCategory(inv_cat->getUUID()))
  1977. {
  1978. // *TODO: get multiple object transfers working
  1979. *accept = ACCEPT_YES_COPY_SINGLE;
  1980. if (drop)
  1981. {
  1982. giveInventoryCategory(dest_agent, inv_cat, session_id);
  1983. }
  1984. }
  1985. else
  1986. {
  1987. // It is not in the user's inventory (it is probably contained
  1988. // in an object), so disallow dragging it here. You cannot give
  1989. // something you do not yet have.
  1990. *accept = ACCEPT_NO;
  1991. LL_DEBUGS("DragAndDrop") << "Folder is not in user inventory. Refusing."
  1992. << LL_ENDL;
  1993. }
  1994. break;
  1995. }
  1996. default:
  1997. *accept = ACCEPT_NO;
  1998. LL_DEBUGS("DragAndDrop") << "Cannot give this type of inventory item."
  1999. << LL_ENDL;
  2000. }
  2001. return true;
  2002. }
  2003. //
  2004. // Methods called in the drag & drop array
  2005. //
  2006. EAcceptance LLToolDragAndDrop::dad3dNULL(LLViewerObject*, S32, MASK, bool)
  2007. {
  2008. LL_DEBUGS("DragAndDrop") << "No operation" << LL_ENDL;
  2009. return ACCEPT_NO;
  2010. }
  2011. EAcceptance LLToolDragAndDrop::dad3dRezAttachmentFromInv(LLViewerObject* objp,
  2012. S32 face, MASK mask,
  2013. bool drop)
  2014. {
  2015. //MK
  2016. if (gRLenabled && gRLInterface.mContainsDetach)
  2017. {
  2018. LL_DEBUGS("DragAndDrop") << "Attachment is RLV locked. Refusing."
  2019. << LL_ENDL;
  2020. return ACCEPT_NO;
  2021. }
  2022. //mk
  2023. // Must be in the user's inventory
  2024. if (mSource != SOURCE_AGENT && mSource != SOURCE_LIBRARY)
  2025. {
  2026. LL_DEBUGS("DragAndDrop") << "Not in user inventory. Refusing."
  2027. << LL_ENDL;
  2028. return ACCEPT_NO;
  2029. }
  2030. LLViewerInventoryItem* itemp;
  2031. LLViewerInventoryCategory* catp;
  2032. locateInventory(itemp, catp);
  2033. if (!itemp || !itemp->isFinished())
  2034. {
  2035. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2036. << LL_ENDL;
  2037. return ACCEPT_NO;
  2038. }
  2039. const LLUUID& item_id = itemp->getUUID();
  2040. // Must not be in the trash
  2041. if (gInventory.isInTrash(item_id))
  2042. {
  2043. LL_DEBUGS("DragAndDrop") << "Inventory item is in Trash. Refusing."
  2044. << LL_ENDL;
  2045. return ACCEPT_NO;
  2046. }
  2047. // Must not be already wearing it
  2048. if (!isAgentAvatarValid() || gAgentAvatarp->isWearingAttachment(item_id))
  2049. {
  2050. LL_DEBUGS("DragAndDrop") << "Cannot give a worn inventory item."
  2051. << LL_ENDL;
  2052. return ACCEPT_NO;
  2053. }
  2054. if (drop)
  2055. {
  2056. if (mSource == SOURCE_LIBRARY)
  2057. {
  2058. LLPointer<LLInventoryCallback> cb =
  2059. new LLRezAttachmentCallback(NULL);
  2060. copy_inventory_item(itemp->getPermissions().getOwner(),
  2061. item_id, LLUUID::null, std::string(), cb);
  2062. }
  2063. else
  2064. {
  2065. gAppearanceMgr.rezAttachment(itemp, 0);
  2066. }
  2067. }
  2068. return ACCEPT_YES_SINGLE;
  2069. }
  2070. EAcceptance LLToolDragAndDrop::dad3dRezObjectOnLand(LLViewerObject* objp,
  2071. S32 face, MASK mask,
  2072. bool drop)
  2073. {
  2074. //MK
  2075. if (gRLenabled &&
  2076. (gRLInterface.mContainsRez || gRLInterface.mContainsInteract))
  2077. {
  2078. LL_DEBUGS("DragAndDrop") << "Rezzing is forbidden by RLV. Refusing."
  2079. << LL_ENDL;
  2080. return ACCEPT_NO_LOCKED;
  2081. }
  2082. //mk
  2083. if (mSource == SOURCE_WORLD)
  2084. {
  2085. return dad3dRezFromObjectOnLand(objp, face, mask, drop);
  2086. }
  2087. LLViewerInventoryItem* itemp;
  2088. LLViewerInventoryCategory* catp;
  2089. locateInventory(itemp, catp);
  2090. if (!itemp || !itemp->isFinished()) return ACCEPT_NO;
  2091. const LLUUID& item_id = itemp->getUUID();
  2092. if (!isAgentAvatarValid() || gAgentAvatarp->isWearingAttachment(item_id))
  2093. {
  2094. LL_DEBUGS("DragAndDrop") << "Cannot drop attached inventory item."
  2095. << LL_ENDL;
  2096. return ACCEPT_NO;
  2097. }
  2098. #if 1 // For now, always make copy
  2099. EAcceptance accept = ACCEPT_YES_COPY_SINGLE;
  2100. bool remove_inventory = false;
  2101. #else
  2102. EAcceptance accept;
  2103. bool remove_inventory;
  2104. // Get initial settings based on shift key
  2105. if (mask & MASK_SHIFT)
  2106. {
  2107. accept = ACCEPT_YES_SINGLE;
  2108. remove_inventory = true;
  2109. }
  2110. else
  2111. {
  2112. accept = ACCEPT_YES_COPY_SINGLE;
  2113. remove_inventory = false;
  2114. }
  2115. #endif
  2116. // Check if the item can be copied. If not, send that to the sim which will
  2117. // remove the inventory item.
  2118. if (!itemp->getPermissions().allowCopyBy(gAgentID))
  2119. {
  2120. accept = ACCEPT_YES_SINGLE;
  2121. remove_inventory = true;
  2122. }
  2123. // Check if it is in the trash.
  2124. if (gInventory.isInTrash(item_id))
  2125. {
  2126. accept = ACCEPT_YES_SINGLE;
  2127. remove_inventory = true;
  2128. }
  2129. if (drop)
  2130. {
  2131. dropObject(objp, true, false, remove_inventory);
  2132. }
  2133. return accept;
  2134. }
  2135. EAcceptance LLToolDragAndDrop::dad3dRezObjectOnObject(LLViewerObject* objp,
  2136. S32 face, MASK mask,
  2137. bool drop)
  2138. {
  2139. //MK
  2140. if (gRLenabled &&
  2141. (gRLInterface.mContainsRez || gRLInterface.mContainsInteract))
  2142. {
  2143. LL_DEBUGS("DragAndDrop") << "Rezzing is forbidden by RLV. Refusing."
  2144. << LL_ENDL;
  2145. return ACCEPT_NO_LOCKED;
  2146. }
  2147. //mk
  2148. // handle objects coming from object inventory
  2149. if (mSource == SOURCE_WORLD)
  2150. {
  2151. return dad3dRezFromObjectOnObject(objp, face, mask, drop);
  2152. }
  2153. LLViewerInventoryItem* itemp;
  2154. LLViewerInventoryCategory* catp;
  2155. locateInventory(itemp, catp);
  2156. if (!itemp || !itemp->isFinished())
  2157. {
  2158. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2159. << LL_ENDL;
  2160. return ACCEPT_NO;
  2161. }
  2162. const LLUUID& item_id = itemp->getUUID();
  2163. if (!isAgentAvatarValid() || gAgentAvatarp->isWearingAttachment(item_id))
  2164. {
  2165. LL_DEBUGS("DragAndDrop") << "Cannot drop attached inventory item."
  2166. << LL_ENDL;
  2167. return ACCEPT_NO;
  2168. }
  2169. if ((mask & MASK_CONTROL))
  2170. {
  2171. // *HACK: In order to resolve SL-22177, we need to block drags from
  2172. // notecards and objects onto other objects.
  2173. if (mSource == SOURCE_NOTECARD)
  2174. {
  2175. LL_DEBUGS("DragAndDrop") << "Cannot drop notecards into objects."
  2176. << LL_ENDL;
  2177. return ACCEPT_NO;
  2178. }
  2179. EAcceptance rv = willObjectAcceptInventory(objp, itemp);
  2180. if (drop && (ACCEPT_YES_SINGLE <= rv))
  2181. {
  2182. dropInventory(objp, itemp, mSource, mSourceID);
  2183. }
  2184. return rv;
  2185. }
  2186. #if 1 // For now, always make copy
  2187. EAcceptance accept = ACCEPT_YES_COPY_SINGLE;
  2188. bool remove_inventory = false;
  2189. #else
  2190. EAcceptance accept;
  2191. bool remove_inventory;
  2192. // Get initial settings based on shift key
  2193. if (mask & MASK_SHIFT)
  2194. {
  2195. accept = ACCEPT_YES_SINGLE;
  2196. remove_inventory = true;
  2197. }
  2198. else
  2199. {
  2200. accept = ACCEPT_YES_COPY_SINGLE;
  2201. remove_inventory = false;
  2202. }
  2203. #endif
  2204. // Check if the item can be copied. If not, send that to the sim which will
  2205. // remove the inventory item.
  2206. if (!itemp->getPermissions().allowCopyBy(gAgentID))
  2207. {
  2208. accept = ACCEPT_YES_SINGLE;
  2209. remove_inventory = true;
  2210. }
  2211. // Check if it is in the trash.
  2212. if (gInventory.isInTrash(item_id))
  2213. {
  2214. accept = ACCEPT_YES_SINGLE;
  2215. }
  2216. if (drop)
  2217. {
  2218. dropObject(objp, false, false, remove_inventory);
  2219. }
  2220. return accept;
  2221. }
  2222. EAcceptance LLToolDragAndDrop::dad3dRezCategoryOnObject(LLViewerObject* obj,
  2223. S32 face, MASK mask,
  2224. bool drop)
  2225. {
  2226. if (mask & MASK_CONTROL)
  2227. {
  2228. return dad3dUpdateInventoryCategory(obj, face, mask, drop);
  2229. }
  2230. else
  2231. {
  2232. return ACCEPT_NO;
  2233. }
  2234. }
  2235. EAcceptance LLToolDragAndDrop::dad3dRezScript(LLViewerObject* objp, S32 face,
  2236. MASK mask, bool drop)
  2237. {
  2238. // *HACK: In order to resolve SL-22177, we need to block drags from
  2239. // notecards and objects onto other objects.
  2240. if (mSource == SOURCE_WORLD || mSource == SOURCE_NOTECARD)
  2241. {
  2242. LL_DEBUGS("DragAndDrop") << "Cannot drop script from this source."
  2243. << LL_ENDL;
  2244. return ACCEPT_NO;
  2245. }
  2246. LLViewerInventoryItem* itemp;
  2247. LLViewerInventoryCategory* catp;
  2248. locateInventory(itemp, catp);
  2249. if (!itemp || !itemp->isFinished())
  2250. {
  2251. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2252. << LL_ENDL;
  2253. return ACCEPT_NO;
  2254. }
  2255. EAcceptance rv = willObjectAcceptInventory(objp, itemp);
  2256. if (drop && rv >= ACCEPT_YES_SINGLE)
  2257. {
  2258. LLViewerObject* root_objectp = objp;
  2259. if (objp && objp->getParent())
  2260. {
  2261. LLViewerObject* parent_objp = (LLViewerObject*)objp->getParent();
  2262. if (!parent_objp->isAvatar())
  2263. {
  2264. root_objectp = parent_objp;
  2265. }
  2266. }
  2267. // Rez in the script active by default, rez in inactive if the
  2268. // control key is being held down.
  2269. bool active = (mask & MASK_CONTROL) == 0;
  2270. dropScript(root_objectp, itemp, active, mSource, mSourceID);
  2271. }
  2272. return rv;
  2273. }
  2274. EAcceptance LLToolDragAndDrop::dad3dApplyToObject(LLViewerObject* objp,
  2275. S32 face, MASK mask,
  2276. bool drop,
  2277. EDragAndDropType cargo_type)
  2278. {
  2279. // *HACK: In order to resolve SL-22177, we need to block drags from
  2280. // notecards and objects onto other objects.
  2281. if (mSource == SOURCE_WORLD || mSource == SOURCE_NOTECARD)
  2282. {
  2283. LL_DEBUGS("DragAndDrop") << "Cannot drop script from this source."
  2284. << LL_ENDL;
  2285. return ACCEPT_NO;
  2286. }
  2287. LLViewerInventoryItem* itemp;
  2288. LLViewerInventoryCategory* catp;
  2289. locateInventory(itemp, catp);
  2290. if (!itemp || !itemp->isFinished())
  2291. {
  2292. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2293. << LL_ENDL;
  2294. return ACCEPT_NO;
  2295. }
  2296. EAcceptance rv = willObjectAcceptInventory(objp, itemp);
  2297. if ((mask & MASK_CONTROL))
  2298. {
  2299. if (drop && rv >= ACCEPT_YES_SINGLE)
  2300. {
  2301. dropInventory(objp, itemp, mSource, mSourceID);
  2302. }
  2303. return rv;
  2304. }
  2305. if (!objp->permModify())
  2306. {
  2307. LL_DEBUGS("DragAndDrop") << "Object is no-modify, cannot apply item to it."
  2308. << LL_ENDL;
  2309. return ACCEPT_NO_LOCKED;
  2310. }
  2311. if (!itemp->getPermissions().allowCopyBy(gAgentID))
  2312. {
  2313. LL_DEBUGS("DragAndDrop") << "Inventory item is not copyable, cannot apply to object."
  2314. << LL_ENDL;
  2315. return ACCEPT_NO;
  2316. }
  2317. U8 num_tes = objp->getNumTEs();
  2318. #if 0 // Do allow changing the legacy maps on GLTF-material bearing faces. HB
  2319. if (cargo_type == DAD_TEXTURE)
  2320. {
  2321. if ((mask & MASK_SHIFT))
  2322. {
  2323. for (U8 te = 0; te < num_tes; ++te)
  2324. {
  2325. if (objp->getRenderMaterialID(te).notNull())
  2326. {
  2327. return ACCEPT_NO; // Got a PBR face: do not ruin it.
  2328. }
  2329. }
  2330. }
  2331. else if (objp->getRenderMaterialID(face).notNull())
  2332. {
  2333. return ACCEPT_NO; // This is a PBR face: do not ruin it.
  2334. }
  2335. }
  2336. #endif
  2337. if (drop && rv >= ACCEPT_YES_SINGLE)
  2338. {
  2339. if (cargo_type == DAD_TEXTURE)
  2340. {
  2341. // Get ready to save textures of any selected node.
  2342. LLSelectNode* nodep = NULL;
  2343. if (objp->isSelected())
  2344. {
  2345. nodep = gSelectMgr.getSelection()->findNode(objp);
  2346. }
  2347. if ((mask & MASK_SHIFT))
  2348. {
  2349. dropTextureAllFaces(objp, itemp, mSource, mSourceID);
  2350. // If the user dropped a texture onto a face, it implies
  2351. // applying texture now without cancel, save to selection.
  2352. if (nodep)
  2353. {
  2354. uuid_vec_t tids;
  2355. for (U8 te = 0; te < num_tes; ++te)
  2356. {
  2357. LLViewerTexture* texp = objp->getTEImage(te);
  2358. tids.emplace_back(texp ? texp->getID() : LLUUID::null);
  2359. }
  2360. nodep->saveTextures(tids);
  2361. }
  2362. }
  2363. else
  2364. {
  2365. dropTextureOneFace(objp, face, itemp, mSource, mSourceID);
  2366. // If the user dropped a texture onto a face, it implies
  2367. // applying texture now without cancel, save to selection.
  2368. if (nodep && LLFloaterTools::isVisible() &&
  2369. // If the diffuse channel is being selected only
  2370. gSelectMgr.getTextureChannel() == 0 &&
  2371. (S32)nodep->mSavedGLTFMaterialIds.size() > face)
  2372. {
  2373. LLViewerTexture* texp = objp->getTEImage(face);
  2374. nodep->mSavedTextures[face] = texp ? texp->getID()
  2375. : LLUUID::null;
  2376. }
  2377. }
  2378. }
  2379. else if (cargo_type == DAD_MATERIAL)
  2380. {
  2381. // Get ready to save textures of any selected node.
  2382. LLSelectNode* nodep = NULL;
  2383. if (objp->isSelected())
  2384. {
  2385. nodep = gSelectMgr.getSelection()->findNode(objp);
  2386. }
  2387. if ((mask & MASK_SHIFT))
  2388. {
  2389. dropMaterialAllFaces(objp, itemp, mSource, mSourceID);
  2390. // If the user dropped a texture onto a face, it implies
  2391. // applying texture now without cancel, save to selection.
  2392. if (nodep)
  2393. {
  2394. uuid_vec_t matids;
  2395. gltf_mat_vec_t mats;
  2396. for (U8 te = 0; te < num_tes; ++te)
  2397. {
  2398. matids.emplace_back(objp->getRenderMaterialID(te));
  2399. mats.emplace_back(nullptr);
  2400. }
  2401. nodep->saveGLTFMaterials(matids, mats);
  2402. }
  2403. }
  2404. else
  2405. {
  2406. dropMaterialOneFace(objp, face, itemp, mSource, mSourceID);
  2407. // If the user dropped a texture onto a face, it implies
  2408. // applying texture now without cancel, save to selection.
  2409. if (nodep && LLFloaterTools::isVisible() &&
  2410. (S32)nodep->mSavedGLTFMaterialIds.size() > face)
  2411. {
  2412. nodep->mSavedGLTFMaterialIds[face] =
  2413. objp->getRenderMaterialID(face);
  2414. nodep->mSavedGLTFOverrideMaterials[face] = nullptr;
  2415. }
  2416. }
  2417. }
  2418. #if LL_MESH_ASSET_SUPPORT
  2419. else if (cargo_type == DAD_MESH)
  2420. {
  2421. dropMesh(objp, itemp, mSource, mSourceID);
  2422. }
  2423. #endif
  2424. else
  2425. {
  2426. llwarns << "Unsupported asset type" << llendl;
  2427. }
  2428. // VEFFECT: SetTexture
  2429. LLHUDEffectSpiral::agentBeamToObject(objp);
  2430. }
  2431. // Enable multi-drop, although last texture will win
  2432. return ACCEPT_YES_MULTI;
  2433. }
  2434. EAcceptance LLToolDragAndDrop::dad3dTextureObject(LLViewerObject* objp,
  2435. S32 face, MASK mask,
  2436. bool drop)
  2437. {
  2438. return dad3dApplyToObject(objp, face, mask, drop, DAD_TEXTURE);
  2439. }
  2440. EAcceptance LLToolDragAndDrop::dad3dMaterialObject(LLViewerObject* objp,
  2441. S32 face, MASK mask,
  2442. bool drop)
  2443. {
  2444. return dad3dApplyToObject(objp, face, mask, drop, DAD_MATERIAL);
  2445. }
  2446. #if LL_MESH_ASSET_SUPPORT
  2447. EAcceptance LLToolDragAndDrop::dad3dMeshObject(LLViewerObject* objp, S32 face,
  2448. MASK mask, bool drop)
  2449. {
  2450. return dad3dApplyToObject(objp, face, mask, drop, DAD_MESH);
  2451. }
  2452. #endif
  2453. EAcceptance LLToolDragAndDrop::dad3dWearItem(LLViewerObject* objp, S32 face,
  2454. MASK mask, bool drop)
  2455. {
  2456. LLViewerInventoryItem* itemp;
  2457. LLViewerInventoryCategory* catp;
  2458. locateInventory(itemp, catp);
  2459. if (!itemp || !itemp->isFinished())
  2460. {
  2461. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2462. << LL_ENDL;
  2463. return ACCEPT_NO;
  2464. }
  2465. if (mSource == SOURCE_AGENT || mSource == SOURCE_LIBRARY)
  2466. {
  2467. // Is it in the agent inventory ?
  2468. if (gInventory.isInTrash(itemp->getUUID()))
  2469. {
  2470. LL_DEBUGS("DragAndDrop") << "Inventory item is not in agent inventory. Refused."
  2471. << LL_ENDL;
  2472. return ACCEPT_NO;
  2473. }
  2474. if (drop)
  2475. {
  2476. // Do not wear anything until initial wearables are loaded, can
  2477. // destroy clothing items.
  2478. if (!gAgentWearables.areWearablesLoaded())
  2479. {
  2480. gNotifications.add("CanNotChangeAppearanceUntilLoaded");
  2481. LL_DEBUGS("DragAndDrop") << "Agent not fully rezzed. Refused for now."
  2482. << LL_ENDL;
  2483. return ACCEPT_NO;
  2484. }
  2485. gAppearanceMgr.wearItemOnAvatar(itemp->getUUID(), false);
  2486. }
  2487. return ACCEPT_YES_MULTI;
  2488. }
  2489. // *TODO: copy/move item to avatar's inventory and then wear it.
  2490. LL_DEBUGS("DragAndDrop") << "Invalid source. Refused." << LL_ENDL;
  2491. return ACCEPT_NO;
  2492. }
  2493. EAcceptance LLToolDragAndDrop::dad3dActivateGesture(LLViewerObject* objp,
  2494. S32 face, MASK mask,
  2495. bool drop)
  2496. {
  2497. LLViewerInventoryItem* itemp;
  2498. LLViewerInventoryCategory* catp;
  2499. locateInventory(itemp, catp);
  2500. if (!itemp || !itemp->isFinished())
  2501. {
  2502. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2503. << LL_ENDL;
  2504. return ACCEPT_NO;
  2505. }
  2506. const LLUUID& item_id = itemp->getUUID();
  2507. if (mSource == SOURCE_AGENT || mSource == SOURCE_LIBRARY)
  2508. {
  2509. // It is in the agent inventory
  2510. if (gInventory.isInTrash(item_id))
  2511. {
  2512. LL_DEBUGS("DragAndDrop") << "Inventory item is not in agent inventory. Refused."
  2513. << LL_ENDL;
  2514. return ACCEPT_NO;
  2515. }
  2516. if (drop)
  2517. {
  2518. if (mSource == SOURCE_LIBRARY)
  2519. {
  2520. // Create item based on that one, and put it on if that was a
  2521. // success.
  2522. LLPointer<LLInventoryCallback> cb =
  2523. new ActivateGestureCallback();
  2524. copy_inventory_item(itemp->getPermissions().getOwner(),
  2525. item_id, LLUUID::null, std::string(), cb);
  2526. }
  2527. else
  2528. {
  2529. gGestureManager.activateGesture(item_id);
  2530. gInventory.updateItem(itemp);
  2531. gInventory.notifyObservers();
  2532. }
  2533. }
  2534. return ACCEPT_YES_MULTI;
  2535. }
  2536. LL_DEBUGS("DragAndDrop") << "Invalid source. Refused." << LL_ENDL;
  2537. return ACCEPT_NO;
  2538. }
  2539. EAcceptance LLToolDragAndDrop::dad3dWearCategory(LLViewerObject* objp,
  2540. S32 face, MASK mask,
  2541. bool drop)
  2542. {
  2543. LLViewerInventoryItem* itemp;
  2544. LLViewerInventoryCategory* catp;
  2545. locateInventory(itemp, catp);
  2546. if (!catp)
  2547. {
  2548. return ACCEPT_NO;
  2549. }
  2550. //MK
  2551. if (gRLenabled && (gRLInterface.mContainsDetach ||
  2552. gRLInterface.contains("addoutfit") ||
  2553. gRLInterface.contains("remoutfit")))
  2554. {
  2555. LL_DEBUGS("DragAndDrop") << "Outfit is RLV locked. Refused" << LL_ENDL;
  2556. return ACCEPT_NO;
  2557. }
  2558. //mk
  2559. if (drop)
  2560. {
  2561. // Do not wear anything until initial wearables are loaded; can destroy
  2562. // clothing items.
  2563. if (!gAgentWearables.areWearablesLoaded())
  2564. {
  2565. gNotifications.add("CanNotChangeAppearanceUntilLoaded");
  2566. return ACCEPT_NO;
  2567. }
  2568. }
  2569. if (mSource == SOURCE_AGENT)
  2570. {
  2571. if (gInventory.isInTrash(catp->getUUID()))
  2572. {
  2573. LL_DEBUGS("DragAndDrop") << "Item is in Trash. Refused" << LL_ENDL;
  2574. return ACCEPT_NO;
  2575. }
  2576. if (drop)
  2577. {
  2578. bool append = (mask & MASK_SHIFT);
  2579. gAppearanceMgr.wearInventoryCategory(catp, false, append);
  2580. }
  2581. return ACCEPT_YES_MULTI;
  2582. }
  2583. if (mSource == SOURCE_LIBRARY)
  2584. {
  2585. if (drop)
  2586. {
  2587. gAppearanceMgr.wearInventoryCategory(catp, true, false);
  2588. }
  2589. return ACCEPT_YES_MULTI;
  2590. }
  2591. // *TODO: copy/move category to avatar's inventory and then wear it.
  2592. LL_DEBUGS("DragAndDrop") << "Invalid source. Refused." << LL_ENDL;
  2593. return ACCEPT_NO;
  2594. }
  2595. EAcceptance LLToolDragAndDrop::dad3dUpdateInventory(LLViewerObject* objp,
  2596. S32 face, MASK mask,
  2597. bool drop)
  2598. {
  2599. // *HACK: In order to resolve SL-22177, we need to block drags from
  2600. // notecards and objects onto other objects.
  2601. if (mSource == SOURCE_WORLD || mSource == SOURCE_NOTECARD)
  2602. {
  2603. LL_DEBUGS("DragAndDrop") << "Invalid source. Refused." << LL_ENDL;
  2604. return ACCEPT_NO;
  2605. }
  2606. LLViewerInventoryItem* itemp;
  2607. LLViewerInventoryCategory* catp;
  2608. locateInventory(itemp, catp);
  2609. if (!itemp || !itemp->isFinished())
  2610. {
  2611. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2612. << LL_ENDL;
  2613. return ACCEPT_NO;
  2614. }
  2615. LLViewerObject* root_objectp = objp;
  2616. if (objp && objp->getParent())
  2617. {
  2618. LLViewerObject* parent_objp = (LLViewerObject*)objp->getParent();
  2619. if (!parent_objp->isAvatar())
  2620. {
  2621. root_objectp = parent_objp;
  2622. }
  2623. }
  2624. EAcceptance rv = willObjectAcceptInventory(root_objectp, itemp);
  2625. if (root_objectp && drop && (ACCEPT_YES_COPY_SINGLE <= rv))
  2626. {
  2627. dropInventory(root_objectp, itemp, mSource, mSourceID);
  2628. }
  2629. return rv;
  2630. }
  2631. bool LLToolDragAndDrop::dadUpdateInventory(LLViewerObject* objp, bool drop)
  2632. {
  2633. EAcceptance rv = dad3dUpdateInventory(objp, -1, MASK_NONE, drop);
  2634. return rv >= ACCEPT_YES_COPY_SINGLE;
  2635. }
  2636. EAcceptance LLToolDragAndDrop::dad3dUpdateInventoryCategory(LLViewerObject* objp,
  2637. S32 face,
  2638. MASK mask,
  2639. bool drop)
  2640. {
  2641. if (!objp)
  2642. {
  2643. llwarns << "NULL object pointer; aborting func with ACCEPT_NO"
  2644. << llendl;
  2645. return ACCEPT_NO;
  2646. }
  2647. if (mSource != SOURCE_AGENT && mSource != SOURCE_LIBRARY)
  2648. {
  2649. LL_DEBUGS("DragAndDrop") << "Invalid source. Refused." << LL_ENDL;
  2650. return ACCEPT_NO;
  2651. }
  2652. if (objp->isAttachment())
  2653. {
  2654. LL_DEBUGS("DragAndDrop") << "Cannot apply to attachments." << LL_ENDL;
  2655. return ACCEPT_NO_LOCKED;
  2656. }
  2657. LLViewerInventoryItem* itemp;
  2658. LLViewerInventoryCategory* catp;
  2659. locateInventory(itemp, catp);
  2660. if (!catp)
  2661. {
  2662. LL_DEBUGS("DragAndDrop") << "Category not found. Refused." << LL_ENDL;
  2663. return ACCEPT_NO;
  2664. }
  2665. // Find all the items in the category
  2666. LLDroppableItem droppable(!objp->permYouOwner());
  2667. LLInventoryModel::cat_array_t cats;
  2668. LLInventoryModel::item_array_t items;
  2669. gInventory.collectDescendentsIf(catp->getUUID(), cats, items,
  2670. LLInventoryModel::EXCLUDE_TRASH,
  2671. droppable);
  2672. cats.push_back(catp);
  2673. if (droppable.countNoCopy() > 0)
  2674. {
  2675. llwarns << "*** Need to confirm this step" << llendl;
  2676. }
  2677. LLViewerObject* root_objectp = objp;
  2678. if (objp->getParent())
  2679. {
  2680. LLViewerObject* parent_objp = (LLViewerObject*)objp->getParent();
  2681. if (!parent_objp->isAvatar())
  2682. {
  2683. root_objectp = parent_objp;
  2684. }
  2685. }
  2686. EAcceptance rv = ACCEPT_NO;
  2687. // Check for accept
  2688. for (S32 i = 0, count = cats.size(); i < count; ++i)
  2689. {
  2690. rv = gInventory.isCategoryComplete(cats[i]->getUUID()) ? ACCEPT_YES_MULTI
  2691. : ACCEPT_NO;
  2692. if (rv < ACCEPT_YES_SINGLE)
  2693. {
  2694. LL_DEBUGS("DragAndDrop") << "Category " << cats[i]->getUUID()
  2695. << "is not complete." << LL_ENDL;
  2696. break;
  2697. }
  2698. }
  2699. if (ACCEPT_YES_COPY_SINGLE <= rv)
  2700. {
  2701. for (S32 i = 0, count = items.size(); i < count; ++i)
  2702. {
  2703. LLViewerInventoryItem* itemp = items[i];
  2704. #if 0
  2705. // Pass the base objects, not the links.
  2706. if (itemp && itemp->getIsLinkType())
  2707. {
  2708. itemp = itemp->getLinkedItem();
  2709. items[i] = itemp;
  2710. }
  2711. #endif
  2712. rv = willObjectAcceptInventory(root_objectp, itemp, DAD_CATEGORY);
  2713. if (rv < ACCEPT_YES_COPY_SINGLE)
  2714. {
  2715. LL_DEBUGS("DragAndDrop") << "Object will not accept "
  2716. << itemp->getUUID() << LL_ENDL;
  2717. break;
  2718. }
  2719. }
  2720. }
  2721. // If every item is accepted, send it on.
  2722. if (drop && ACCEPT_YES_COPY_SINGLE <= rv)
  2723. {
  2724. uuid_vec_t ids;
  2725. for (S32 i = 0, count = items.size(); i < count; ++i)
  2726. {
  2727. ids.emplace_back(items[i]->getUUID());
  2728. }
  2729. LLCategoryDropObserver* dropperp =
  2730. new LLCategoryDropObserver(objp->getID(), mSource);
  2731. dropperp->fetchItems(ids);
  2732. if (dropperp->isFinished())
  2733. {
  2734. dropperp->done();
  2735. }
  2736. else
  2737. {
  2738. gInventory.addObserver(dropperp);
  2739. }
  2740. }
  2741. return rv;
  2742. }
  2743. bool LLToolDragAndDrop::dadUpdateInventoryCategory(LLViewerObject* objp,
  2744. bool drop)
  2745. {
  2746. EAcceptance rv = dad3dUpdateInventoryCategory(objp, -1, MASK_NONE, drop);
  2747. return rv >= ACCEPT_YES_COPY_SINGLE;
  2748. }
  2749. EAcceptance LLToolDragAndDrop::dad3dGiveInventoryObject(LLViewerObject* objp,
  2750. S32 face, MASK mask,
  2751. bool drop)
  2752. {
  2753. // Item has to be in agent inventory.
  2754. if (mSource != SOURCE_AGENT) return ACCEPT_NO;
  2755. //MK
  2756. if (gRLenabled &&
  2757. (gRLInterface.mContainsShownames ||
  2758. gRLInterface.mContainsShownametags))
  2759. {
  2760. // To avoid having "so-and-so accepted/declined your inventory offer."
  2761. // messages
  2762. LL_DEBUGS("DragAndDrop") << "Refused under RLV show names restrictions."
  2763. << LL_ENDL;
  2764. return ACCEPT_NO;
  2765. }
  2766. //mk
  2767. // Find the item now.
  2768. LLViewerInventoryItem* itemp;
  2769. LLViewerInventoryCategory* catp;
  2770. locateInventory(itemp, catp);
  2771. if (!itemp || !itemp->isFinished())
  2772. {
  2773. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2774. << LL_ENDL;
  2775. return ACCEPT_NO;
  2776. }
  2777. if (!itemp->getPermissions().allowTransferBy(gAgentID))
  2778. {
  2779. // Cannot give away no-transfer objects
  2780. LL_DEBUGS("DragAndDrop") << "No transfer inventory item. Refused."
  2781. << LL_ENDL;
  2782. return ACCEPT_NO;
  2783. }
  2784. if (isAgentAvatarValid() &&
  2785. gAgentAvatarp->isWearingAttachment(itemp->getUUID()))
  2786. {
  2787. // You cannot give objects that are attached to you
  2788. LL_DEBUGS("DragAndDrop") << "Attached inventory item. Refused."
  2789. << LL_ENDL;
  2790. return ACCEPT_NO;
  2791. }
  2792. if (objp && isAgentAvatarValid())
  2793. {
  2794. if (drop)
  2795. {
  2796. giveInventory(objp->getID(), itemp);
  2797. }
  2798. // *TODO: deal with all the issues surrounding multi-object inventory
  2799. // transfers.
  2800. return ACCEPT_YES_SINGLE;
  2801. }
  2802. LL_DEBUGS("DragAndDrop") << "Refused action." << LL_ENDL;
  2803. return ACCEPT_NO;
  2804. }
  2805. EAcceptance LLToolDragAndDrop::dad3dGiveInventory(LLViewerObject* objp,
  2806. S32 face, MASK mask,
  2807. bool drop)
  2808. {
  2809. // Item has to be in agent inventory.
  2810. if (mSource != SOURCE_AGENT) return ACCEPT_NO;
  2811. //MK
  2812. if (gRLenabled &&
  2813. (gRLInterface.mContainsShownames ||
  2814. gRLInterface.mContainsShownametags))
  2815. {
  2816. // To avoid having "so-and-so accepted/declined your inventory offer."
  2817. // messages
  2818. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2819. << LL_ENDL;
  2820. return ACCEPT_NO;
  2821. }
  2822. //mk
  2823. LLViewerInventoryItem* itemp;
  2824. LLViewerInventoryCategory* catp;
  2825. locateInventory(itemp, catp);
  2826. if (!itemp || !itemp->isFinished())
  2827. {
  2828. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2829. << LL_ENDL;
  2830. return ACCEPT_NO;
  2831. }
  2832. if (!isInventoryGiveAcceptable(itemp))
  2833. {
  2834. return ACCEPT_NO;
  2835. }
  2836. if (drop && objp)
  2837. {
  2838. giveInventory(objp->getID(), itemp);
  2839. }
  2840. // *TODO: deal with all the issues surrounding multi-object inventory
  2841. // transfers.
  2842. return ACCEPT_YES_SINGLE;
  2843. }
  2844. EAcceptance LLToolDragAndDrop::dad3dGiveInventoryCategory(LLViewerObject* objp,
  2845. S32 face, MASK mask,
  2846. bool drop)
  2847. {
  2848. //MK
  2849. if (gRLenabled &&
  2850. (gRLInterface.mContainsShownames ||
  2851. gRLInterface.mContainsShownametags))
  2852. {
  2853. // To avoid having "so-and-so accepted/declined your inventory offer."
  2854. // messages
  2855. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2856. << LL_ENDL;
  2857. return ACCEPT_NO;
  2858. }
  2859. //mk
  2860. if (drop && objp)
  2861. {
  2862. LLViewerInventoryItem* itemp;
  2863. LLViewerInventoryCategory* catp;
  2864. locateInventory(itemp, catp);
  2865. if (!catp)
  2866. {
  2867. LL_DEBUGS("DragAndDrop") << "Category not found. Refused."
  2868. << LL_ENDL;
  2869. return ACCEPT_NO;
  2870. }
  2871. giveInventoryCategory(objp->getID(), catp);
  2872. }
  2873. // *TODO: deal with all the issues surrounding multi-object inventory
  2874. // transfers.
  2875. return ACCEPT_YES_SINGLE;
  2876. }
  2877. EAcceptance LLToolDragAndDrop::dad3dRezFromObjectOnLand(LLViewerObject* objp,
  2878. S32 face, MASK mask,
  2879. bool drop)
  2880. {
  2881. LLViewerInventoryItem* itemp;
  2882. LLViewerInventoryCategory* catp;
  2883. locateInventory(itemp, catp);
  2884. if (!itemp || !itemp->isFinished())
  2885. {
  2886. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2887. << LL_ENDL;
  2888. return ACCEPT_NO;
  2889. }
  2890. if (!gAgent.allowOperation(PERM_COPY, itemp->getPermissions()) ||
  2891. !itemp->getPermissions().allowTransferTo(LLUUID::null))
  2892. {
  2893. LL_DEBUGS("DragAndDrop") << "Insufficient permisions for inventory item."
  2894. << LL_ENDL;
  2895. return ACCEPT_NO_LOCKED;
  2896. }
  2897. if (drop)
  2898. {
  2899. dropObject(objp, true, true, false);
  2900. }
  2901. return ACCEPT_YES_SINGLE;
  2902. }
  2903. EAcceptance LLToolDragAndDrop::dad3dRezFromObjectOnObject(LLViewerObject* objp,
  2904. S32 face, MASK mask,
  2905. bool drop)
  2906. {
  2907. LLViewerInventoryItem* itemp;
  2908. LLViewerInventoryCategory* catp;
  2909. locateInventory(itemp, catp);
  2910. if (!itemp || !itemp->isFinished())
  2911. {
  2912. LL_DEBUGS("DragAndDrop") << "Unfinished inventory item. Refusing for now."
  2913. << LL_ENDL;
  2914. return ACCEPT_NO;
  2915. }
  2916. if ((mask & MASK_CONTROL))
  2917. {
  2918. #if 1 // *HACK: in order to resolve SL-22177, we need to block drags from
  2919. // notecards and objects onto other objects.
  2920. LL_DEBUGS("DragAndDrop") << "Cannot drop from this source" << LL_ENDL;
  2921. return ACCEPT_NO;
  2922. #else
  2923. EAcceptance rv = willObjectAcceptInventory(objp, itemp);
  2924. if (drop && (ACCEPT_YES_SINGLE <= rv))
  2925. {
  2926. dropInventory(objp, itemp, mSource, mSourceID);
  2927. }
  2928. return rv;
  2929. #endif
  2930. }
  2931. if (!itemp->getPermissions().allowCopyBy(gAgentID, gAgent.getGroupID()) ||
  2932. !itemp->getPermissions().allowTransferTo(LLUUID::null))
  2933. {
  2934. LL_DEBUGS("DragAndDrop") << "Insufficient permisions for inventory item."
  2935. << LL_ENDL;
  2936. return ACCEPT_NO_LOCKED;
  2937. }
  2938. if (drop)
  2939. {
  2940. dropObject(objp, false, true, false);
  2941. }
  2942. return ACCEPT_YES_SINGLE;
  2943. }
  2944. EAcceptance LLToolDragAndDrop::dad3dCategoryOnLand(LLViewerObject*, S32, MASK,
  2945. bool)
  2946. {
  2947. return ACCEPT_NO;
  2948. }
  2949. EAcceptance LLToolDragAndDrop::dad3dAssetOnLand(LLViewerObject*, S32, MASK,
  2950. bool)
  2951. {
  2952. return ACCEPT_NO;
  2953. }
  2954. LLInventoryObject* LLToolDragAndDrop::locateInventory(LLViewerInventoryItem*& itemp,
  2955. LLViewerInventoryCategory*& catp)
  2956. {
  2957. itemp = NULL;
  2958. catp = NULL;
  2959. if (mCargoIDs.empty())
  2960. {
  2961. return NULL;
  2962. }
  2963. const LLUUID& cargo_id = mCargoIDs[mCurItemIndex];
  2964. if (mSource == SOURCE_AGENT || mSource == SOURCE_LIBRARY)
  2965. {
  2966. // The object should be in user inventory.
  2967. itemp = (LLViewerInventoryItem*)gInventory.getItem(cargo_id);
  2968. if (itemp) return itemp;
  2969. catp = (LLViewerInventoryCategory*)gInventory.getCategory(cargo_id);
  2970. return catp;
  2971. }
  2972. if (mSource == SOURCE_NOTECARD)
  2973. {
  2974. LLPreviewNotecard* previewp =
  2975. (LLPreviewNotecard*)LLPreview::find(mSourceID);
  2976. if (previewp)
  2977. {
  2978. itemp = (LLViewerInventoryItem*)previewp->getDragItem();
  2979. }
  2980. return itemp;
  2981. }
  2982. if (mSource != SOURCE_WORLD)
  2983. {
  2984. return NULL;
  2985. }
  2986. // This object is in some task inventory somewhere.
  2987. LLViewerObject* objp = gObjectList.findObject(mSourceID);
  2988. if (!objp)
  2989. {
  2990. return NULL;
  2991. }
  2992. EDragAndDropType type = mCargoTypes[mCurItemIndex];
  2993. if (type == DAD_CATEGORY || type == DAD_ROOT_CATEGORY)
  2994. {
  2995. catp = (LLViewerInventoryCategory*)objp->getInventoryObject(cargo_id);
  2996. return catp;
  2997. }
  2998. itemp = (LLViewerInventoryItem*)objp->getInventoryObject(cargo_id);
  2999. return itemp;
  3000. }
  3001. // Utility function
  3002. void pack_permissions_slam(LLMessageSystem* msg, U32 flags,
  3003. const LLPermissions& perms)
  3004. {
  3005. // CRUFT: The server no longer pays attention to this data
  3006. U32 group_mask = perms.getMaskGroup();
  3007. U32 everyone_mask = perms.getMaskEveryone();
  3008. U32 next_owner_mask = perms.getMaskNextOwner();
  3009. msg->addU32Fast(_PREHASH_ItemFlags, flags);
  3010. msg->addU32Fast(_PREHASH_GroupMask, group_mask);
  3011. msg->addU32Fast(_PREHASH_EveryoneMask, everyone_mask);
  3012. msg->addU32Fast(_PREHASH_NextOwnerMask, next_owner_mask);
  3013. }