assetBrowser.tscript 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870
  1. //AssetBrowser.addToolbarButton
  2. function AssetBrowser::addToolbarButton(%this)
  3. {
  4. %button = new GuiBitmapButtonCtrl() {
  5. canSaveDynamicFields = "0";
  6. internalName = AssetBrowserBtn;
  7. Enabled = "1";
  8. isContainer = "0";
  9. Profile = "ToolsGuiButtonProfile";
  10. HorizSizing = "right";
  11. VertSizing = "bottom";
  12. position = "180 0";
  13. Extent = "25 19";
  14. MinExtent = "8 2";
  15. canSave = "1";
  16. Visible = "1";
  17. Command = "AssetBrowser.ShowDialog();";
  18. tooltipprofile = "ToolsGuiToolTipProfile";
  19. ToolTip = "Asset Browser";
  20. hovertime = "750";
  21. bitmapAsset = "ToolsModule:assetBrowser_n_image";
  22. bitmapMode = "Stretched";
  23. buttonType = "ToggleButton";
  24. groupNum = "0";
  25. useMouseEvents = "0";
  26. };
  27. ToolsToolbarArray.add(%button);
  28. EWToolsToolbar.setExtent((29 + 4) * (ToolsToolbarArray.getCount()) + 4 SPC "32");
  29. }
  30. //
  31. function AssetBrowser::initialize(%this)
  32. {
  33. // manage preview array
  34. if(!isObject(AssetPreviewArray))
  35. new ArrayObject(AssetPreviewArray);
  36. if(!isObject(ObjectCreator))
  37. new ScriptObject(ObjectCreator);
  38. if(!isObject(%this.dirHandler))
  39. {
  40. %this.dirHandler = makedirectoryHandler(AssetBrowser-->filterTree, "cache,shaderCache", "");
  41. %this.dirHandler.currentAddress = "data/";
  42. }
  43. AssetBrowser-->filterTree.buildIconTable( ":tools/classIcons/Prefab:tools/classIcons/Prefab" @
  44. ":tools/classIcons/SimSet:tools/classIcons/SimSet");
  45. %this.isReImportingAsset = false;
  46. %this.coreModulesFilter = false;
  47. %this.toolsModulesFilter = false;
  48. %this.onlyShowModulesWithAssets = false;
  49. %this.folderPanelState = true;
  50. %this.folderPanelSplit = 0;
  51. %this.templateFilesPath = "tools/assetBrowser/scripts/templateFiles/";
  52. //First, build our our list of active modules
  53. %modulesList = ModuleDatabase.findModules(true);
  54. AssetBrowser-->previewSlider.setValue(EditorSettings.value("Assets/Browser/previewTileSize", "1.0"));
  55. AssetBrowser-->filterAssetsButton.setActive(true);
  56. }
  57. function AssetBrowser::onAdd(%this)
  58. {
  59. }
  60. function AssetBrowser::onWake(%this)
  61. {
  62. %this.initialize();
  63. // Make the window fit next to the side panel
  64. // We do a simple resize so that we don't have to redo the whole GUI layout
  65. %newWidth = getWord($pref::Video::mode, 0) - 360;
  66. %vertPos = getWord($pref::Video::mode, 1) - 360 - 35;
  67. AssetBrowserWindow.resize("0", %vertPos, %newWidth, "360");
  68. AssetBrowserWindow.dockPanel();
  69. }
  70. function AssetBrowser::onDialogPop(%this)
  71. {
  72. $AssetBrowser::Open = false;
  73. %lastPosExt = AssetBrowserWindow.position SPC AssetBrowserWindow.extent;
  74. EditorSettings.setValue("Assets/Browser/LastPosExt", %lastPosExt);
  75. }
  76. function AssetBrowser::onDialogPush(%this)
  77. {
  78. $AssetBrowser::Open = true;
  79. EditorGui.updateSideBar();
  80. }
  81. function AssetBrowser::setTab(%this, %tab, %text, %command)
  82. {
  83. if(isObject(%tab))
  84. {
  85. %tab.setActive(true);
  86. %tab.setHidden(false);
  87. %tab.setText(%text);
  88. %tab.command = %command;
  89. }
  90. }
  91. function AssetBrowser::putToFront(%this)
  92. {
  93. // Close the object
  94. AssetBrowser.hideDialog();
  95. // Create the object again so it will render on top
  96. AssetBrowser.ShowDialog();
  97. // Put the focus on this window
  98. AssetBrowser.restoreLastPosExt();
  99. AssetBrowserWindow.selectWindow();
  100. }
  101. function AssetBrowser::restoreLastPosExt(%this)
  102. {
  103. %lastPosExt = EditorSettings.value("Assets/Browser/LastPosExt", "");
  104. if(%lastPosExt !$= "")
  105. {
  106. AssetBrowserWindow.resize(getWord(%lastPosExt, 0), getWord(%lastPosExt, 1), getWord(%lastPosExt, 2), getWord(%lastPosExt, 3));
  107. }
  108. EditorGui.updateSideBar();
  109. }
  110. function contentTreeTabBook::onTabSelected(%this, %tabText, %tabIndex)
  111. {
  112. if(%tabText $= "Content")
  113. {
  114. //Force it to navigate to current active directory, which also rebuilds the
  115. //tree
  116. AssetBrowser.dirHandler.navigateTo(AssetBrowser.dirHandler.currentAddress);
  117. }
  118. else
  119. {
  120. AssetBrowser-->filterTree.clear();
  121. AssetBrowser-->filterTree.buildVisibleTree(true);
  122. }
  123. }
  124. //Filters
  125. function AssetBrowser::showFilterPopup(%this)
  126. {
  127. BrowserVisibilityPopup.showPopup(Canvas);
  128. }
  129. function AssetBrowser::viewCoreModulesFilter(%this)
  130. {
  131. %oldVal = EditorSettings.value("Assets/Browser/showCoreModule", false);
  132. %newVal = !%oldVal;
  133. %this.coreModulesFilter = %newVal;
  134. BrowserVisibilityPopup.checkItem(0,%newVal);
  135. EditorSettings.setValue("Assets/Browser/showCoreModule", %newVal);
  136. AssetBrowser.loadDirectories();
  137. }
  138. function AssetBrowser::viewToolsModulesFilter(%this)
  139. {
  140. %oldVal = EditorSettings.value("Assets/Browser/showToolsModule", false);
  141. %newVal = !%oldVal;
  142. %this.toolsModulesFilter = %newVal;
  143. BrowserVisibilityPopup.checkItem(1,%newVal);
  144. EditorSettings.setValue("Assets/Browser/showToolsModule", %newVal);
  145. AssetBrowser.loadDirectories();
  146. }
  147. function AssetBrowser::viewPopulatedModulesFilter(%this)
  148. {
  149. %oldVal = EditorSettings.value("Assets/Browser/showOnlyPopulatedModule", false);
  150. %newVal = !%oldVal;
  151. BrowserVisibilityPopup.checkItem(2,%newVal);
  152. EditorSettings.setValue("Assets/Browser/showOnlyPopulatedModule", %newVal);
  153. AssetBrowser.loadDirectories();
  154. }
  155. function AssetBrowser::toggleShowingFolders(%this)
  156. {
  157. %oldVal = EditorSettings.value("Assets/Browser/showFolders", false);
  158. %newVal = !%oldVal;
  159. BrowserVisibilityPopup.checkItem(4,%newVal);
  160. EditorSettings.setValue("Assets/Browser/showFolders", %newVal);
  161. AssetBrowser.loadDirectories();
  162. }
  163. function AssetBrowser::toggleShowingEmptyFolders(%this)
  164. {
  165. %oldVal = EditorSettings.value("Assets/Browser/showEmptyFolders", false);
  166. %newVal = !%oldVal;
  167. BrowserVisibilityPopup.checkItem(5,%newVal);
  168. EditorSettings.setValue("Assets/Browser/showEmptyFolders", %newVal);
  169. AssetBrowser.refresh();
  170. }
  171. function AssetBrowser::toggleAssetTypeFilter(%this, %assetTypeIdx)
  172. {
  173. %isChecked = AssetTypeListPopup.isItemChecked(%assetTypeIdx);
  174. //Clear existing filters
  175. if(%assetTypeIdx == 0)
  176. {
  177. for(%i=0; %i < AssetFilterTypeList.Count() + 1; %i++)
  178. {
  179. AssetTypeListPopup.checkItem(%i, false);
  180. }
  181. AssetTypeListPopup.checkItem(0, true);
  182. }
  183. else
  184. {
  185. if(%isChecked)
  186. {
  187. %anyOtherFilters = false;
  188. for(%i=1; %i < AssetFilterTypeList.Count() + 1; %i++)
  189. {
  190. if(%assetTypeIdx == %i)
  191. continue;
  192. if(AssetTypeListPopup.isItemChecked(%i))
  193. {
  194. %anyOtherFilters = true;
  195. break;
  196. }
  197. }
  198. }
  199. if(%isChecked && !%anyOtherFilters)
  200. {
  201. for(%i=0; %i < AssetFilterTypeList.Count() + 1; %i++)
  202. {
  203. AssetTypeListPopup.checkItem(%i, false);
  204. }
  205. AssetTypeListPopup.checkItem(0, true);
  206. }
  207. else
  208. {
  209. AssetTypeListPopup.checkItem(0, false);
  210. AssetTypeListPopup.checkItem(%assetTypeIdx, !%isChecked);
  211. }
  212. }
  213. //Update the displayed search text!
  214. //First, clear out the old type search term
  215. for(%i=0; %i < AssetSearchTerms.count(); %i++)
  216. {
  217. %action = AssetSearchTerms.getKey(%i);
  218. if(%action $= "type")
  219. {
  220. AssetSearchTerms.erase(%i);
  221. %i--;
  222. }
  223. }
  224. //Update our search terms
  225. %newSearchPhrase = "";
  226. for(%i=0; %i < AssetFilterTypeList.Count() + 1; %i++)
  227. {
  228. %isChecked = AssetTypeListPopup.isItemChecked(%i);
  229. if(!%isChecked)
  230. continue;
  231. %itemText = AssetTypeListPopup.getItemText(%i);
  232. if(%itemText $= "All")
  233. continue;
  234. AssetSearchTerms.add("type", %itemText);
  235. }
  236. %this.updateSearchTextFromFilter();
  237. %this.rebuildAssetArray();
  238. }
  239. //
  240. function AssetBrowser::selectAsset( %this, %asset )
  241. {
  242. if(AssetBrowser.selectCallback !$= "")
  243. {
  244. // The callback function should be ready to intake the returned material
  245. //eval("materialEd_previewMaterial." @ %propertyField @ " = " @ %value @ ";");
  246. if( AssetBrowser.returnType $= "name" )
  247. {
  248. // TODO!
  249. %name = "";
  250. eval( "" @ AssetBrowser.selectCallback @ "(" @ %name @ ");");
  251. }
  252. else
  253. {
  254. %command = "" @ AssetBrowser.selectCallback @ "(\"" @ %asset @ "\");";
  255. eval(%command);
  256. }
  257. }
  258. else
  259. {
  260. //try just setting the asset
  261. %this.changeAsset();
  262. }
  263. if(isObject(Inspector))
  264. Inspector.refresh();
  265. AssetBrowser.hideDialog();
  266. }
  267. function AssetBrowser::showDialog( %this, %AssetTypeFilter, %selectCallback, %targetObj, %fieldName, %returnType)
  268. {
  269. // Set the select callback
  270. AssetBrowser.selectCallback = %selectCallback;
  271. AssetBrowser.returnType = %returnType;
  272. AssetBrowser.assetTypeFilter = %AssetTypeFilter;
  273. AssetBrowser.fieldTargetObject = %targetObj;
  274. AssetBrowser.fieldTargetName = %fieldName;
  275. Canvas.popDialog(AssetBrowser);
  276. Canvas.pushDialog(AssetBrowser);
  277. AssetBrowser.setVisible(1);
  278. AssetBrowserWindow.setVisible(1);
  279. AssetBrowserWindow.selectWindow();
  280. if(AssetBrowserWindow.docked)
  281. AssetBrowserWindow.dockPanel();
  282. else
  283. AssetBrowserWindow.releasePanel();
  284. //If we're special-case filtering(like for selecting a given type), then ignore our normal
  285. //visibility filter
  286. if(%AssetTypeFilter !$= "")
  287. {
  288. AssetBrowser-->filterAssetsButton.setActive(false);
  289. }
  290. else
  291. {
  292. AssetBrowser-->filterAssetsButton.setActive(true);
  293. }
  294. if(%selectCallback $= "")
  295. {
  296. //we're not in selection mode, so just hide the select button
  297. %this-->SelectButton.setHidden(true);
  298. %this.selectMode = 0;
  299. }
  300. else
  301. {
  302. %this-->SelectButton.setHidden(false);
  303. %this.selectMode = 1;
  304. }
  305. AssetBrowser.loadDirectories();
  306. AssetBrowser.restoreLastPosExt();
  307. }
  308. function AssetBrowser::hideDialog( %this )
  309. {
  310. AssetBrowser.setVisible(1);
  311. AssetBrowserWindow.setVisible(1);
  312. Canvas.popDialog(AssetBrowser_addModule);
  313. Canvas.popDialog(ImportAssetWindow);
  314. Canvas.popDialog(AssetBrowser);
  315. }
  316. function AssetBrowser::toggleDialog( %this )
  317. {
  318. if(AssetBrowser.isAwake())
  319. {
  320. AssetBrowser.hideDialog();
  321. }
  322. else
  323. {
  324. AssetBrowser.showDialog();
  325. }
  326. }
  327. function AssetBrowser::buildAssetPreview( %this, %asset, %moduleName )
  328. {
  329. if(!isObject(%this.previewData))
  330. {
  331. %this.previewData = new ScriptObject();
  332. }
  333. else
  334. {
  335. %this.previewData.tooltip = "";
  336. %this.previewData.assetName = "";
  337. %this.previewData.previewImage = "";
  338. %this.previewData.doubleClickCommand = "";
  339. }
  340. %previewImage = "core/art/warnmat";
  341. if(/*%moduleName !$= "" && */ModuleDatabase.findModule(%moduleName, 1) !$= "")
  342. {
  343. %assetDesc = AssetDatabase.acquireAsset(%asset);
  344. %assetName = AssetDatabase.getAssetName(%asset);
  345. %assetType = AssetDatabase.getAssetType(%asset);
  346. }
  347. else
  348. {
  349. //special-case entry
  350. if(getFieldCount(%asset) > 1)
  351. {
  352. %assetType = getField(%asset,0);
  353. %assetName = getField(%asset, 1);
  354. %sdfasdgah = true;
  355. if(%assetType $= "Folder")
  356. {
  357. %fullPath = %moduleName !$= "" ? %moduleName @ "/" @ %assetName : %assetName;
  358. %fullPath = strreplace(%fullPath, "/", "_");
  359. if(isObject(%fullPath))
  360. %assetDesc = %fullPath;
  361. else
  362. %assetDesc = new ScriptObject(%fullPath);
  363. %assetDesc.dirPath = %moduleName;
  364. %assetDesc.assetName = %assetName;
  365. %assetDesc.description = %moduleName @ "/" @ %assetName;
  366. %assetDesc.assetType = %assetType;
  367. }
  368. else if(%assetType $= "Datablock")
  369. {
  370. %assetDesc = %assetName;
  371. %assetDesc.assetType = %assetType;
  372. }
  373. else if(%assetType $= "LooseFile")
  374. {
  375. %fullPath = %moduleName !$= "" ? %moduleName @ "/" @ %assetName : %assetName;
  376. %fullPath = strreplace(%fullPath, "/", "_");
  377. %fullPath = strreplace(%fullPath, ".", "-");
  378. if(isObject(%fullPath))
  379. %assetDesc = %fullPath;
  380. else
  381. %assetDesc = new ScriptObject(%fullPath);
  382. %assetDesc.dirPath = %moduleName;
  383. %assetDesc.assetName = %assetName;
  384. %assetDesc.description = %moduleName @ "/" @ %assetName;
  385. %assetDesc.assetType = %assetType;
  386. }
  387. else if(%assetType $= "Prefab")
  388. {
  389. %fullPath = %moduleName !$= "" ? %moduleName @ "/" @ %assetName : %assetName;
  390. %fullPath = strreplace(%fullPath, "/", "_");
  391. %fullPath = strreplace(%fullPath, ".", "-");
  392. if(isObject(%fullPath))
  393. %assetDesc = %fullPath;
  394. else
  395. %assetDesc = new ScriptObject(%fullPath);
  396. %assetDesc.dirPath = %moduleName;
  397. %assetDesc.assetName = %assetName;
  398. %assetDesc.description = %moduleName @ "/" @ %assetName;
  399. %assetDesc.assetType = %assetType;
  400. }
  401. else if(%assetType $= "Cpp")
  402. {
  403. %fullPath = %moduleName !$= "" ? %moduleName @ "/" @ %assetName : %assetName;
  404. %fullPath = strreplace(%fullPath, "/", "_");
  405. %fullPath = strreplace(%fullPath, ".", "-");
  406. if(isObject(%fullPath))
  407. %assetDesc = %fullPath;
  408. else
  409. %assetDesc = new ScriptObject(%fullPath);
  410. %assetDesc.dirPath = %moduleName;
  411. %assetDesc.assetName = %assetName;
  412. %assetDesc.description = %moduleName @ "/" @ %assetName;
  413. %assetDesc.assetType = %assetType;
  414. }
  415. else if(%assetType $= "tscript")
  416. {
  417. %fullPath = %moduleName !$= "" ? %moduleName @ "/" @ %assetName : %assetName;
  418. %fullPath = strreplace(%fullPath, "/", "_");
  419. %fullPath = strreplace(%fullPath, ".", "-");
  420. if(isObject(%fullPath))
  421. %assetDesc = %fullPath;
  422. else
  423. %assetDesc = new ScriptObject(%fullPath);
  424. %assetDesc.dirPath = %moduleName;
  425. %assetDesc.assetName = %assetName;
  426. %assetDesc.description = %moduleName @ "/" @ %assetName;
  427. %assetDesc.assetType = %assetType;
  428. }
  429. else if(%assetType $= "Creator")
  430. {
  431. %assetDesc = %assetName;
  432. %assetDesc.assetType = %assetType;
  433. %moduleName = %assetDesc;
  434. }
  435. }
  436. /*%fullPath = %moduleName !$= "" ? %moduleName @ "/" @ %assetName : %assetName;
  437. %fullPath = strreplace(%fullPath, "/", "_");
  438. if(isObject(%fullPath))
  439. %assetDesc = %fullPath;
  440. else
  441. %assetDesc = new ScriptObject(%fullPath);
  442. %assetDesc.dirPath = %moduleName;
  443. %assetDesc.assetName = %assetName;
  444. %assetDesc.description = %moduleName @ "/" @ %assetName;
  445. %assetDesc.assetType = %assetType;*/
  446. //%assetName = %asset;
  447. //%assetType = "Folder";
  448. }
  449. %previewSize = 100 SPC 100;
  450. %previewBounds = 20;
  451. %tooltip = %assetName;
  452. %textBottomPad = 20;
  453. %previewButton = new GuiIconButtonCtrl()
  454. {
  455. class = "AssetBrowserPreviewButton";
  456. useMouseEvents = true;
  457. iconLocation = "Center";
  458. sizeIconToButton = true;
  459. makeIconSquare = true;
  460. textLocation = "Bottom";
  461. extent = %previewSize.x SPC %previewSize.y + %textBottomPad;
  462. buttonType = "RadioButton";
  463. buttonMargin = "0 -10";
  464. profile = ToolsGuiDefaultIconBtnProfile;
  465. };
  466. %previewScaleSize = AssetBrowser-->previewSlider.getValue();
  467. if(%previewScaleSize $= "")
  468. {
  469. %previewScaleSize = 1;
  470. AssetBrowser-->previewSlider.setValue(1);
  471. }
  472. if(%previewScaleSize == 0 || startsWith(AssetBrowser.dirHandler.currentAddress, "Creator"))
  473. {
  474. %previewButton.iconLocation = "Left";
  475. %previewButton.textLocation = "Right";
  476. %previewButton.setextent(160,34);
  477. %previewButton.buttonMargin = "8 8";
  478. %previewButton.textMargin = "6";
  479. AssetBrowser.previewListMode = true;
  480. }
  481. else
  482. {
  483. %size = %previewSize.x * %previewScaleSize;
  484. %previewButton.setextent(%size,%size + %textBottomPad);
  485. AssetBrowser.previewListMode = false;
  486. }
  487. //%previewButton.extent = %previewSize.x + %previewBounds SPC %previewSize.y + %previewBounds + 24;
  488. %previewButton.assetName = %assetName;
  489. %previewButton.moduleName = %moduleName;
  490. %previewButton.assetType = %assetType;
  491. if(%this.selectMode)
  492. {
  493. %doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );";
  494. }
  495. else
  496. {
  497. %doubleClickCommand = "AssetBrowser.editAsset( "@%assetDesc@" );";
  498. }
  499. %this.previewData.previewLoaded = true;
  500. //Build out the preview
  501. %buildCommand = %this @ ".build" @ %assetType @ "Preview(\"" @ %assetDesc @ "\"," @ %this.previewData @ ");";
  502. eval(%buildCommand);
  503. //debug dump
  504. %tooltip = %this.previewData.tooltip;
  505. %assetName = %this.previewData.assetName;
  506. %previewImage = %this.previewData.previewImage;
  507. if(%this.previewData.doubleClickCommand !$= "")
  508. %doubleClickCommand = %this.previewData.doubleClickCommand;
  509. %previewButton.assetName = %assetName;
  510. %previewButton.moduleName = %moduleName;
  511. %previewButton.assetType = %assetType;
  512. %previewButton.bitmapAsset = %this.previewData.previewImage;
  513. %previewButton.profile = "AssetBrowserPreview" @ %previewButton.assetType;
  514. %previewButton.tooltip = %this.previewData.tooltip;
  515. %previewButton.Command = "AssetBrowser.updateSelection( $ThisControl.assetName, $ThisControl.moduleName );";
  516. %previewButton.altCommand = %doubleClickCommand;
  517. %previewButton.text = %this.previewData.assetName;
  518. %previewButton.text.originalAssetName = %this.previewData.assetName;
  519. // add to the gui control array
  520. AssetBrowser-->assetList.add(%previewButton);
  521. // add to the array object for reference later
  522. if(%this.previewData.previewLoaded == false)
  523. AssetPreviewArray.add( %previewButton );
  524. }
  525. function AssetBrowser::refresh(%this)
  526. {
  527. if(!%this.dirty)
  528. {
  529. %this.dirty = true;
  530. %this.schedule(1, "doRefresh");
  531. }
  532. }
  533. function AssetBrowser::doRefresh(%this)
  534. {
  535. if(%this.dirty)
  536. {
  537. %this.navigateTo(%this.dirHandler.currentAddress);
  538. //Forces a clean collapse of the tree for any not-really-exposed items
  539. %dataItem = AssetBrowser-->filterTree.findItemByName("data");
  540. if(%dataItem != 0)
  541. {
  542. AssetBrowser-->filterTree.expandItem(%dataItem, false);
  543. AssetBrowser-->filterTree.expandItem(%dataItem);
  544. }
  545. %this.dirty = false;
  546. }
  547. }
  548. function AssetBrowser::populatePreviewImages(%this)
  549. {
  550. if (AssetPreviewArray.count()>0)
  551. echo("AssetBrowser::populatePreviewImages() - Previews to generate: " @ AssetPreviewArray.count());
  552. for(%i=0; %i < AssetPreviewArray.count(); %i++)
  553. {
  554. %previewButton = AssetPreviewArray.getKey(%i);
  555. %type = %previewButton.assetType;
  556. echo(" - Generating preview for asset: " @ %previewButton.moduleName @ ":" @ %previewButton.assetName);
  557. AssetBrowser.call("generate" @ %previewButton.assetType @ "PreviewImage", %previewButton);
  558. AssetPreviewArray.erase(%i);
  559. echo(" - done, scheduling another pass");
  560. AssetBrowser.schedule(32, "populatePreviewImages");
  561. return;
  562. }
  563. }
  564. //
  565. //
  566. /*function AssetPreviewButton::onClick(%this)
  567. {
  568. echo("CLICKED AN ASSET PREVIEW BUTTON");
  569. }
  570. function AssetPreviewButton::onDoubleClick(%this)
  571. {
  572. echo("DOUBLE CLICKED AN ASSET PREVIEW BUTTON");
  573. }*/
  574. //
  575. //
  576. function assetBrowserPreviewSlider::onMouseDragged(%this)
  577. {
  578. EditorSettings.setValue("Assets/Browser/previewTileSize", %this.getValue());
  579. AssetBrowser.refresh();
  580. }
  581. function AssetBrowser::loadDirectories( %this )
  582. {
  583. AssetBrowser-->filterTree.clear();
  584. %dataItem = AssetBrowser-->filterTree.insertItem(0, "Content");
  585. AssetBrowser-->filterTree.collectionsIdx = AssetBrowser-->filterTree.insertItem(1, "Collections");
  586. AssetBrowser-->filterTree.modulesIdx = AssetBrowser-->filterTree.insertItem(1, "Modules");
  587. %dataItem = AssetBrowser-->filterTree.insertItem(AssetBrowser-->filterTree.modulesIdx, "data");
  588. AssetBrowser-->filterTree.tagsIdx = AssetBrowser-->filterTree.insertItem(1, "Tags");
  589. AssetBrowser-->filterTree.creatorIdx = AssetBrowser-->filterTree.insertItem(1, "Creator");
  590. AssetBrowser-->filterTree.clearSelection();
  591. if(%this.selectMode)
  592. {
  593. //Due to a fluke in how this tracks, it overrides the current addres, so we'll
  594. //store it real fast
  595. %curAdd = AssetBrowser.dirHandler.currentAddress;
  596. //Disable these for this go
  597. AssetBrowser-->filterTree.addSelection(AssetBrowser-->filterTree.collectionsIdx);
  598. AssetBrowser-->filterTree.addSelection(AssetBrowser-->filterTree.creatorIdx);
  599. AssetBrowser-->filterTree.hideSelection();
  600. AssetBrowser-->filterTree.clearSelection();
  601. AssetBrowser.dirHandler.currentAddress = %curAdd;
  602. }
  603. %this.dirHandler.loadFolders("data", %dataItem);
  604. %this.loadCollectionSets();
  605. %this.loadTags();
  606. if (!%this.selectMode)
  607. %this.loadCreatorClasses();
  608. //If set to, show core
  609. if(EditorSettings.value("Assets/Browser/showCoreModule", false) == 1)
  610. {
  611. %coreItem = AssetBrowser-->filterTree.insertItem(AssetBrowser-->filterTree.modulesIdx, "core");
  612. %this.dirHandler.loadFolders("core", %coreItem);
  613. }
  614. //If set to, show tools
  615. if(EditorSettings.value("Assets/Browser/showToolsModule", false) == 1)
  616. {
  617. %toolsItem = AssetBrowser-->filterTree.insertItem(AssetBrowser-->filterTree.modulesIdx, "tools");
  618. %this.dirHandler.loadFolders("tools", %toolsItem);
  619. }
  620. AssetBrowser-->filterTree.buildVisibleTree(true);
  621. //Remove any modules that have no assets if we have that filter on
  622. if(%this.onlyShowModulesWithAssets)
  623. {
  624. %modulesList = ModuleDatabase.findModules();
  625. for(%i=0; %i < getWordCount(%modulesList); %i++)
  626. {
  627. %moduleName = getWord(%modulesList, %i).ModuleId;
  628. %moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName);
  629. if(AssetBrowser-->filterTree.isParentItem(%moduleItemId) == false)
  630. AssetBrowser-->filterTree.removeItem(%moduleItemId);
  631. }
  632. }
  633. //special handling for selections
  634. if(AssetBrowser.newModuleId !$= "")
  635. {
  636. AssetBrowser-->filterTree.clearSelection();
  637. %newModuleItem = AssetBrowser-->filterTree.findItemByName(AssetBrowser.newModuleId);
  638. AssetBrowser-->filterTree.selectItem(%newModuleItem);
  639. AssetBrowser.newModuleId = "";
  640. }
  641. AssetBrowser.dirHandler.expandTreeToAddress(AssetBrowser.dirHandler.currentAddress);
  642. %selectedItem = AssetBrowser.dirHandler.getFolderTreeItemFromAddress(AssetBrowser.dirHandler.currentAddress);
  643. AssetBrowser-->filterTree.scrollVisibleByObjectId(%selectedItem);
  644. AssetBrowser-->filterTree.buildVisibleTree(true);
  645. AssetBrowser.refresh();
  646. }
  647. function AssetBrowser::updateSelection( %this, %asset, %moduleName )
  648. {
  649. //If we had an existing selected assetDef, clear the reference
  650. if(isObject(AssetBrowser.selectedAssetDef))
  651. AssetDatabase.releaseAsset(AssetBrowser.selectedAssetDef.getAssetId());
  652. //AssetBrowser.selectedMaterial = %asset;
  653. AssetBrowser.selectedAsset = %moduleName@":"@%asset;
  654. //If it's got slashes, it's a path so it's actually a folder item, not an asset
  655. if(strstr(%moduleName, "/") != -1)
  656. return;
  657. //Check if this is an actual assetId, or if it's just a programmatic reference
  658. //like what we use for the creator entries
  659. if(AssetDatabase.isDeclaredAsset(AssetBrowser.selectedAsset))
  660. {
  661. //Looks good, it's an asset so we'll select the definition while we're at it
  662. AssetBrowser.selectedAssetDef = AssetDatabase.acquireAsset(AssetBrowser.selectedAsset);
  663. }
  664. }
  665. function AssetBrowser::loadCollectionSets(%this)
  666. {
  667. //Process any datablocks and populate their lists categories as tags as well
  668. %collectionsItem = AssetBrowser-->filterTree.collectionsIdx;
  669. %collectionsCount = AssetBrowserCollectionSets.value("CollectionSetCount", 0);
  670. for ( %i = 0; %i < %collectionsCount; %i++ )
  671. {
  672. %collection = AssetBrowserCollectionSets.value("Collection"@%i, "");
  673. %collectionName = getField(%collection, 0);
  674. %collectionTerm = getField(%collection, 1);
  675. AssetBrowser-->filterTree.insertItem(%collectionsItem, %collectionName, %collectionTerm);
  676. }
  677. }
  678. function AssetBrowser::setCollectionSetActive(%this, %collectionSet)
  679. {
  680. AssetBrowserSearchFilter.setText(%collectionSet);
  681. AssetBrowserSearchFilter.onReturn();
  682. }
  683. function AssetBrowser::loadTags(%this)
  684. {
  685. //Process any datablocks and populate their lists categories as tags as well
  686. %dataGroup = "DataBlockGroup";
  687. %tagItem = AssetBrowser-->filterTree.tagsIdx;
  688. for ( %i = 0; %i < %dataGroup.getCount(); %i++ )
  689. {
  690. %obj = %dataGroup.getObject(%i);
  691. // echo ("Obj: " @ %obj.getName() @ " - " @ %obj.category );
  692. if ( %obj.category $= "" && %obj.category == 0 )
  693. continue;
  694. %tagChildItem = AssetBrowser-->filterTree.findChildItemByName(%tagItem, %obj.category);
  695. if(%tagChildItem == 0)
  696. {
  697. //Didn't already exist, so register it in
  698. AssetBrowser-->filterTree.insertItem(%tagItem, %obj.category);
  699. }
  700. }
  701. }
  702. function AssetBrowser::setTagActive(%this, %tag)
  703. {
  704. %found = false;
  705. for(%i=0; %i < AssetSearchTerms.count(); %i++)
  706. {
  707. %action = AssetSearchTerms.getKey(%i);
  708. %word = AssetSearchTerms.getValue(%i);
  709. if(%action $= "tag" && %word $= %tag)
  710. {
  711. //If we found it, we just remove it from our list, toggling it off
  712. AssetSearchTerms.erase(%i);
  713. %found = true;
  714. }
  715. }
  716. //If we didn't find it, we're going to add it into our list
  717. if(!%found)
  718. {
  719. AssetSearchTerms.add("tag", %tag);
  720. }
  721. %this.updateSearchTextFromFilter();
  722. %this.rebuildAssetArray();
  723. }
  724. //
  725. //needs to be deleted with the persistence manager and needs to be blanked out of the matmanager
  726. //also need to update instances... i guess which is the tricky part....
  727. function AssetBrowser::showDeleteDialog( %this )
  728. {
  729. %material = AssetBrowser.selectedAsset;
  730. %secondFilter = "MaterialFilterMappedArray";
  731. %secondFilterName = "Mapped";
  732. for( %i = 0; %i < MaterialFilterUnmappedArray.count(); %i++ )
  733. {
  734. if( MaterialFilterUnmappedArray.getValue(%i) $= %material )
  735. {
  736. %secondFilter = "MaterialFilterUnmappedArray";
  737. %secondFilterName = "Unmapped";
  738. break;
  739. }
  740. }
  741. if( isObject( %material ) )
  742. {
  743. toolsMessageBoxYesNoCancel("Delete Material?",
  744. "Are you sure you want to delete<br><br>" @ %material.getName() @ "<br><br> Material deletion won't take affect until the engine is quit.",
  745. "AssetBrowser.deleteMaterial( " @ %material @ ", " @ %secondFilter @ ", " @ %secondFilterName @" );",
  746. "",
  747. "" );
  748. }
  749. }
  750. function AssetBrowser::deleteMaterial( %this, %materialName, %secondFilter, %secondFilterName )
  751. {
  752. if( !isObject( %materialName ) )
  753. return;
  754. for( %i = 0; %i <= MaterialFilterAllArray.countValue( %materialName ); %i++)
  755. {
  756. %index = MaterialFilterAllArray.getIndexFromValue( %materialName );
  757. MaterialFilterAllArray.erase( %index );
  758. }
  759. MaterialFilterAllArrayCheckbox.setText("All ( " @ MaterialFilterAllArray.count() - 1 @ " ) ");
  760. %checkbox = %secondFilter @ "Checkbox";
  761. for( %k = 0; %k <= %secondFilter.countValue( %materialName ); %k++)
  762. {
  763. %index = %secondFilter.getIndexFromValue( %materialName );
  764. %secondFilter.erase( %index );
  765. }
  766. %checkbox.setText( %secondFilterName @ " ( " @ %secondFilter.count() - 1 @ " ) ");
  767. for( %i = 0; %materialName.getFieldValue("materialTag" @ %i) !$= ""; %i++ )
  768. {
  769. %materialTag = %materialName.getFieldValue("materialTag" @ %i);
  770. for( %j = AssetBrowser.staticFilterObjects; %j < AssetBrowser-->filterArray.getCount() ; %j++ )
  771. {
  772. if( %materialTag $= AssetBrowser-->filterArray.getObject(%j).getObject(0).filter )
  773. {
  774. %count = getWord( AssetBrowser-->filterArray.getObject(%j).getObject(0).getText(), 2 );
  775. %count--;
  776. AssetBrowser-->filterArray.getObject(%j).getObject(0).setText( %materialTag @ " ( "@ %count @ " )");
  777. }
  778. }
  779. }
  780. UnlistedMaterials.add( "unlistedMaterials", %materialName );
  781. if( %materialName.getFilename() !$= "" &&
  782. %materialName.getFilename() !$= "tools/gui/AssetBrowser.ed.gui" &&
  783. %materialName.getFilename() !$= "tools/materialEditor/scripts/materialEditor.ed." @ $TorqueScriptFileExtension )
  784. {
  785. AssetBrowserPerMan.removeObjectFromFile(%materialName);
  786. AssetBrowserPerMan.saveDirty();
  787. }
  788. AssetBrowser.refresh();
  789. }
  790. function AssetBrowser::toggleTagFilterPopup(%this)
  791. {
  792. if(TagFilterWindow.visible)
  793. TagFilterWindow.visible = false;
  794. else
  795. TagFilterWindow.visible = true;
  796. return;
  797. %assetQuery = new AssetQuery();
  798. %numAssetsFound = AssetDatabase.findAllAssets(%assetQuery);
  799. for( %i=0; %i < %numAssetsFound; %i++)
  800. {
  801. %assetId = %assetQuery.getAsset(%i);
  802. //first, get the asset's module, as our major categories
  803. %module = AssetDatabase.getAssetModule(%assetId);
  804. %moduleName = %module.moduleId;
  805. //check that we don't re-add it
  806. %moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName);
  807. if(%moduleItemId == -1 || %moduleItemId == 0)
  808. %moduleItemId = AssetBrowser-->filterTree.insertItem(1, %module.moduleId, "", "", 1, 2);
  809. //now, add the asset's category
  810. %assetType = AssetDatabase.getAssetCategory(%assetId);
  811. // TODO?
  812. %text = "";
  813. %var = "";
  814. %cmd = "";
  815. %textLength = strlen(%text);
  816. // end todo
  817. %checkBox = new GuiCheckBoxCtrl()
  818. {
  819. canSaveDynamicFields = "0";
  820. isContainer = "0";
  821. Profile = "ToolsGuiCheckBoxListProfile";
  822. HorizSizing = "right";
  823. VertSizing = "bottom";
  824. Position = "0 0";
  825. Extent = (%textLength * 4) @ " 18";
  826. MinExtent = "8 2";
  827. canSave = "1";
  828. Visible = "1";
  829. Variable = %var;
  830. tooltipprofile = "ToolsGuiToolTipProfile";
  831. hovertime = "1000";
  832. text = %text;
  833. groupNum = "-1";
  834. buttonType = "ToggleButton";
  835. useMouseEvents = "0";
  836. useInactiveState = "0";
  837. Command = %cmd;
  838. };
  839. TagFilterList.add(%checkBox);
  840. }
  841. }
  842. function AssetBrowser::changeAsset(%this)
  843. {
  844. %targetObject = %this.fieldTargetObject;
  845. %inspectorObject = "";
  846. if(isObject(%this.fieldTargetObject) && %this.fieldTargetObject.isInNamespaceHierarchy("GuiInspector"))
  847. {
  848. %inspectorObject = %this.fieldTargetObject;
  849. if(%inspectorObject.getNumInspectObjects() != 0)
  850. {
  851. %targetObject = %inspectorObject.getInspectObject();
  852. %inspectorObject.setObjectField(%this.fieldTargetName, %this.selectedAsset);
  853. }
  854. else if(startsWith(%this.fieldTargetName, "$"))
  855. {
  856. //we're targeting a variable directly, so deal with that then
  857. %cmd = %this.fieldTargetName @ "=\"" @ %this.selectedAsset @ "\";";
  858. }
  859. }
  860. else if(isObject(%this.fieldTargetObject))
  861. {
  862. //alright, we've selectd an asset for a field, so time to set it!
  863. if(%this.fieldTargetName $= "")
  864. %cmd = %targetObject @ ".apply(\""@ %this.selectedAsset @ "\");";
  865. else
  866. %cmd = %targetObject @ "." @ %this.fieldTargetName @ "=\"" @ %this.selectedAsset @ "\";";
  867. //echo("Changing asset via the " @ %cmd @ " command");
  868. }
  869. else if(startsWith(%this.fieldTargetName, "$"))
  870. {
  871. //we're targeting a variable directly, so deal with that then
  872. %cmd = %this.fieldTargetName @ "=\"" @ %this.selectedAsset @ "\";";
  873. }
  874. eval(%cmd);
  875. //Force update our object with the field change
  876. if(isObject(%targetObject))
  877. {
  878. if(%this.fieldTargetObject.isInNamespaceHierarchy("GuiInspector"))
  879. %this.fieldTargetObject.refresh();
  880. else
  881. %targetObject.inspectPostApply();
  882. }
  883. //Flag us as dirty for editing purposes
  884. EWorldEditor.setSceneAsDirty();
  885. }
  886. function AssetBrowser::reImportAsset(%this)
  887. {
  888. //Find out what type it is
  889. %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
  890. %assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId);
  891. if(%assetType $= "ShapeAsset" || %assetType $= "ImageAsset" || %assetType $= "SoundAsset")
  892. {
  893. AssetBrowser.isAssetReImport = true;
  894. AssetBrowser.reImportingAssetId = EditAssetPopup.assetId;
  895. %reimportingPath = %assetDef.originalFilePath;
  896. if(%reimportingPath $= "" || !isFile(%reimportingPath))
  897. {
  898. //if we have no defined original file path, attempt to re-import the
  899. //current loosefile
  900. if(%assetType $= "ShapeAsset")
  901. %reimportingPath = %assetDef.getShapePath();
  902. else if(%assetType $= "ImageAsset")
  903. %reimportingPath = %assetDef.getImagePath();
  904. else if(%assetType $= "SoundAsset")
  905. %reimportingPath = %assetDef.getSoundPath();
  906. }
  907. //first, double-check we have an originating file. if we don't then we need to basically go out looking for it
  908. if(!isFile(%reimportingPath))
  909. {
  910. //if(%assetType $= "ImageAsset")
  911. // %filters = "";
  912. //TODO
  913. %currentFile = "";
  914. %dlg = new OpenFileDialog()
  915. {
  916. Filters = "(All Files (*.*)|*.*|";
  917. DefaultFile = %currentFile;
  918. ChangePath = false;
  919. MustExist = true;
  920. MultipleFiles = false;
  921. forceRelativePath = false;
  922. };
  923. if ( %dlg.Execute() )
  924. {
  925. %reimportingPath = %dlg.FileName;
  926. }
  927. %dlg.delete();
  928. }
  929. AssetBrowser.onBeginDropFiles();
  930. AssetBrowser.onDropFile(%reimportingPath);
  931. AssetBrowser.onEndDropFiles();
  932. %module = AssetDatabase.getAssetModule(EditAssetPopup.assetId);
  933. //get the selected module data
  934. ImportAssetModuleList.setText(%module.ModuleId);
  935. }
  936. }
  937. //
  938. //
  939. // RMB context popups
  940. function AssetBrowserPreviewButton::onRightClick(%this)
  941. {
  942. AssetBrowser.selectedAssetPreview = %this;
  943. EditAssetPopup.assetId = %this.moduleName @ ":" @ %this.assetName;
  944. EditAssetPopup.assetType = %this.assetType;
  945. %assetType = %this.assetType;
  946. //Do some enabling/disabling of options depending on asset type
  947. EditAssetPopup.enableItem(0, true);
  948. EditAssetPopup.enableItem(9, true);
  949. //Is it an editable type?
  950. if(%assetType $= "ImageAsset" /*|| %assetType $= "GameObjectAsset"*/ || %assetType $= "CppAsset")
  951. {
  952. EditAssetPopup.enableItem(0, false);
  953. }
  954. //Is it an importable type?
  955. if(%assetType $= "GameObjectAsset" || %assetType $= "ComponentAsset" || %assetType $= "GUIAsset" || %assetType $= "LevelAsset"
  956. || %assetType $= "MaterialAsset" || %assetType $= "ParticleAsset" || %assetType $= "PostEffectAsset" || %assetType $= "ScriptAsset"
  957. || %assetType $= "StateMachineAsset")
  958. {
  959. EditAssetPopup.enableItem(9, false);
  960. }
  961. /*if(AssetDatabase.acquireAsset(EditAssetPopup.assetId))
  962. {
  963. %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
  964. if(%assetDef.originalFilePath $= "" || !isFile(%assetDef.originalFilePath))
  965. {
  966. //if we have no noted original import file path or it's invalid
  967. //we can't reimport either
  968. EditAssetPopup.enableItem(9, false);
  969. }
  970. AssetDatabase.releaseAsset(EditAssetPopup.assetId);
  971. }*/
  972. if(%assetType $= "LevelAsset")
  973. {
  974. EditLevelAssetPopup.showPopup(Canvas);
  975. }
  976. else if(%assetType $= "Folder")
  977. {
  978. EditFolderPopup.dirPath = %this.moduleName @ "/" @ %this.assetName;
  979. EditFolderPopup.showPopup(Canvas);
  980. }
  981. else if(%assetType $= "TerrainAsset")
  982. {
  983. EditTerrainAssetPopup.showPopup(Canvas);
  984. }
  985. else
  986. {
  987. EditAssetPopup.showPopup(Canvas);
  988. }
  989. if(%assetType $= "Folder")
  990. {
  991. EditAssetPopup.assetId = %this.moduleName @ "/" @ %this.assetName;
  992. }
  993. }
  994. //function AssetListPanel::onRightMouseDown(%this)
  995. function AssetListPanelInputs::onRightMouseDown(%this)
  996. {
  997. AddNewAssetPopup.showPopup(Canvas);
  998. }
  999. function AssetBrowserFilterTree::onRightMouseDown(%this, %itemId)
  1000. {
  1001. %count = %this.getSelectedItemsCount();
  1002. %itemText = %this.getItemText(%itemId);
  1003. %parentItem = %this.getParentItem(%itemId);
  1004. if(%parentItem == %this.tagsIdx)
  1005. {
  1006. }
  1007. else if(%parentItem == %this.collectionsIdx)
  1008. {
  1009. EditCollectionSets.showPopup(Canvas);
  1010. AssetBrowser.selectedCollectionSet = %itemText;
  1011. }
  1012. else if(%parentItem == %this.creatorIdx)
  1013. {
  1014. }
  1015. else
  1016. {
  1017. if( %this.getSelectedItemsCount() > 0 && (%itemText !$= "data" && %itemText !$="core" && %itemText !$= "tools"))
  1018. {
  1019. //AddNewAssetPopup.showPopup(Canvas);
  1020. //We have something clicked, so figure out if it's a sub-filter or a module filter, then push the correct
  1021. //popup menu
  1022. %parentItem = %this.getParentItem(%itemId);
  1023. if(%this.getItemText(%parentItem) $= "data") //if it's a data module, continue
  1024. {
  1025. //find out if it's a folder or a module!
  1026. if(ModuleDatabase.findModule(%itemText))
  1027. {
  1028. //yep, module, push the all-inclusive popup
  1029. EditModulePopup.showPopup(Canvas);
  1030. //also set the module value for creation info
  1031. AssetBrowser.selectedModule = %itemText;
  1032. }
  1033. else
  1034. {
  1035. EditNonModulePopup.showPopup(Canvas);
  1036. EditNonModulePopup.targetFolder = %itemText;
  1037. }
  1038. }
  1039. else
  1040. {
  1041. EditFolderPopup.showPopup(Canvas);
  1042. EditFolderPopup.assetType = "Folder";
  1043. }
  1044. }
  1045. else if(%itemText $= "data")
  1046. {
  1047. AddNewModulePopup.showPopup(Canvas);
  1048. }
  1049. else if(%itemText $= "tools")
  1050. {
  1051. AddNewToolPopup.showPopup(Canvas);
  1052. }
  1053. }
  1054. }
  1055. //
  1056. //
  1057. //
  1058. function AssetBrowser::openAssetSettings(%this)
  1059. {
  1060. ESettingsWindow.toggleEditorSettings();
  1061. %assetEditIndex = ESettingsWindowList.findTextIndex("Asset Editing");
  1062. ESettingsWindowList.setSelectedRow( %assetEditIndex );
  1063. }
  1064. function ESettingsWindow::getAssetManagementSettings(%this)
  1065. {
  1066. SettingsInspector.startGroup("Modules");
  1067. SettingsInspector.addSettingsField("AssetManagement/Modules/coreModulePath", "Core Module Path", "string", "");
  1068. SettingsInspector.addSettingsField("AssetManagement/Modules/gameDataModulePath", "Game Data Module Path", "string", "");
  1069. SettingsInspector.addSettingsField("AssetManagement/Modules/moduleExtension", "Module Extension", "string", "");
  1070. %moduleList = ModuleDatabase.findModules(true);
  1071. %moduleList = strreplace(%moduleList, " ", ",");
  1072. SettingsInspector.addSettingsField("AssetManagement/Modules/DefaultModule", "Default Module", "list", %moduleList);
  1073. SettingsInspector.endGroup();
  1074. SettingsInspector.startGroup("Assets");
  1075. SettingsInspector.addSettingsField("AssetManagement/Assets/assetExtension", "Asset Extension", "string", "");
  1076. SettingsInspector.addSettingsField("AssetManagement/Assets/datablockCaching", "Cache Datablocks", "bool", "");
  1077. //SettingsInspector.addSettingsField("AssetManagement/Assets/moduleExtension", "Module Extension", "string", "");
  1078. SettingsInspector.endGroup();
  1079. }
  1080. function ESettingsWindow::getAssetEditingSettings(%this)
  1081. {
  1082. ImportAssetWindow::reloadImportOptionConfigs();
  1083. //First, get our list of modules
  1084. %moduleList = ModuleDatabase.findModules();
  1085. %formattedModuleList = "";
  1086. %count = getWordCount(%moduleList);
  1087. for(%i=0; %i < %count; %i++)
  1088. {
  1089. %module = getWord(%moduleList, %i);
  1090. if(%module.group !$= "Tools" && %module.group !$= "Core")
  1091. {
  1092. if(%formattedModuleList $= "")
  1093. %formattedModuleList = %module.moduleId;
  1094. else
  1095. %formattedModuleList = %formattedModuleList @ "," @ %module.moduleId;
  1096. }
  1097. }
  1098. SettingsInspector.startGroup("Asset Creation");
  1099. SettingsInspector.addSettingsField("Assets/New/defaultModule", "Default Module", "list", "Default Module for new assets to be created into", %formattedModuleList);
  1100. SettingsInspector.addSettingsField("Assets/New/alwaysPromptModuleTarget", "Always Prompt Target Module", "bool", "If off, use the default module");
  1101. SettingsInspector.endGroup();
  1102. %formattedConfigList = "";
  1103. for(%i=0; %i < ImportAssetWindow.importConfigsList.Count(); %i++)
  1104. {
  1105. %configName = ImportAssetWindow.importConfigsList.getKey(%i);
  1106. %formattedConfigList = %i == 0 ? %configName : %formattedConfigList @ "," @ %configName;
  1107. }
  1108. SettingsInspector.startGroup("Assets Importing");
  1109. SettingsInspector.addField("Edit Import Configs", "Edit Asset Import Configs", "button", "Open Asset Import Config Editor", "", "Canvas.pushDialog(AssetImportConfigEditor);");
  1110. SettingsInspector.addSettingsField("Assets/AssetImporDefaultConfig", "Default Asset Import Config", "list", "", %formattedConfigList);
  1111. SettingsInspector.addSettingsField("Assets/AutoImport", "Automatically Import using default config", "bool", "If on, the asset importing process" @
  1112. "will attempt to automatically import any inbound assets"@
  1113. "using the default config, without prompting the import window."@
  1114. "The window will still display if any issues are detected", "");
  1115. SettingsInspector.addSettingsField("Assets/AutoImportLooseFiles", "Automatically Import Loose Files", "bool", "If on, will automatically import unassociated loose files in assets when navigating the Asset Browser.", "");
  1116. SettingsInspector.endGroup();
  1117. SettingsInspector.startGroup("Asset Browser");
  1118. SettingsInspector.addSettingsField("Assets/Browser/showCoreModule", "Show Core Module in Asset Browser", "bool", "");
  1119. SettingsInspector.addSettingsField("Assets/Browser/showToolsModule", "Show Tools Module in Asset Browser", "bool", "");
  1120. SettingsInspector.addSettingsField("Assets/Browser/showOnlyPopulatedModule", "Show Only Modules with Assets in Asset Browser", "bool", "");
  1121. SettingsInspector.addSettingsField("Assets/Browser/showFolders", "Show Folders in Tiles view in Asset Browser", "bool", "");
  1122. SettingsInspector.addSettingsField("Assets/Browser/showEmptyFolders", "Show Empty Folders in Tiles view in Asset Browser", "bool", "");
  1123. SettingsInspector.addSettingsField("Assets/Browser/showLooseFiles", "Show Loose Files when viewing in Asset Browser", "bool", "");
  1124. SettingsInspector.addSettingsField("AssetManagement/Assets/promptOnRename", "Prompt on Rename", "bool", "");
  1125. SettingsInspector.addSettingsField("Assets/Browser/doubleClickAction", "Double Click Action", "list", "Dictates what sort of action double clicking on an asset in the Browser will invoke", "Edit Asset,Spawn Asset");
  1126. SettingsInspector.addSettingsField("AssetManagement/Assets/closeBrowserOnDragAction", "Close Browser on Drag Action", "bool", "If on, the Asset Browser will automatically close after dragging an asset from it to the editor interface.");
  1127. SettingsInspector.endGroup();
  1128. }
  1129. //
  1130. //
  1131. //
  1132. function AssetBrowser::showVisibiltyOptions(%this)
  1133. {
  1134. BrowserVisibilityPopup.showPopup(Canvas);
  1135. }
  1136. function AssetBrowser::saveCurrentFiltersAsCollection(%this)
  1137. {
  1138. %colSetName = CreateNewCollectionSetCtrl-->collectionSetName.getText();
  1139. if(%colSetName $= "")
  1140. {
  1141. error("Collection Sets require a name!");
  1142. }
  1143. %collectionsCount = AssetBrowserCollectionSets.value("CollectionSetCount", 0);
  1144. %collectionsCount += 1;
  1145. AssetBrowserCollectionSets.setValue("CollectionSetCount", %collectionsCount);
  1146. %collection = %colSetName TAB AssetBrowserSearchFilter.getText();
  1147. AssetBrowserCollectionSets.setValue("Collection"@%collectionsCount-1, %collection);
  1148. %success = AssetBrowserCollectionSets.write();
  1149. AssetBrowser.loadDirectories();
  1150. }
  1151. function AssetBrowser::deleteCollectionSet(%this)
  1152. {
  1153. %collectionsCount = AssetBrowserCollectionSets.value("CollectionSetCount", 0);
  1154. %tempCollectionListCount = 0;
  1155. %found = false;
  1156. for ( %i = 0; %i < %collectionsCount; %i++ )
  1157. {
  1158. %collection = AssetBrowserCollectionSets.value("Collection"@%i, "");
  1159. %collectionName = getField(%collection, 0);
  1160. %collectionTerm = getField(%collection, 1);
  1161. if(AssetBrowser.selectedCollectionSet !$= %collectionName)
  1162. {
  1163. %tempCollectionList[%tempCollectionListCount] = %collection;
  1164. %tempCollectionListCount++;
  1165. }
  1166. }
  1167. AssetBrowserCollectionSets.setValue("CollectionSetCount", %tempCollectionListCount);
  1168. for(%i=0; %i < %collectionsCount; %i++)
  1169. {
  1170. if(%i < %tempCollectionListCount)
  1171. AssetBrowserCollectionSets.setValue("Collection"@%i, %tempCollectionList[%i]);
  1172. else
  1173. AssetBrowserCollectionSets.remove("Collection"@%i);
  1174. }
  1175. AssetBrowserCollectionSets.write();
  1176. %this.loadDirectories();
  1177. }
  1178. function AssetBrowser::refreshPreviews(%this)
  1179. {
  1180. AssetBrowserFilterTree.onSelect(AssetBrowser.selectedItem);
  1181. }
  1182. function AssetBrowserFilterTree::onSelect(%this, %itemId)
  1183. {
  1184. if(%itemId == 1)
  1185. //can't select root
  1186. return;
  1187. //process special cases
  1188. %parentItem = %this.getParentItem(%itemId);
  1189. if(%parentItem == %this.tagsIdx)
  1190. {
  1191. //we selected a tag, so deal with that
  1192. AssetBrowser.setTagActive(%this.getItemText(%itemId));
  1193. }
  1194. else if(%parentItem == %this.collectionsIdx)
  1195. {
  1196. //A collection set was selected
  1197. AssetBrowser.setCollectionSetActive(%this.getItemValue(%itemId));
  1198. }
  1199. else if(%parentItem == %this.creatorIdx)
  1200. {
  1201. %name = %this.getItemText(%itemId);
  1202. AssetBrowser.dirHandler.currentAddress = "Creator/" @ %name;
  1203. AssetBrowser.rebuildAssetArray();
  1204. AssetBrowser.refresh();
  1205. }
  1206. else
  1207. {
  1208. //Make sure we have an actual module selected!
  1209. %parentId = %this.getParentItem(%itemId);
  1210. %name = %this.getItemText(%itemId);
  1211. %breadcrumbPath = %this.getItemValue(%itemId);
  1212. if(%breadcrumbPath !$= "")
  1213. %breadcrumbPath = %breadcrumbPath @ "/" @ %this.getItemText(%itemId);
  1214. else
  1215. %breadcrumbPath = %this.getItemText(%itemId);
  1216. if(%breadcrumbPath $= "")
  1217. %breadcrumbPath = AssetBrowser.dirHandler.currentAddress;
  1218. AssetBrowser.navigateTo(%breadcrumbPath);
  1219. }
  1220. }
  1221. function AssetBrowserFilterTree::hasAsParent(%this, %itemId, %text)
  1222. {
  1223. %parentId = %this.getParentItem(%itemId);
  1224. while(%parentId != 0)
  1225. {
  1226. %parentText = %this.getItemText(%parentId);
  1227. if(%parentText $= %text)
  1228. return true;
  1229. %parentId = %this.getParentItem(%parentId);
  1230. }
  1231. return false;
  1232. }
  1233. function AssetBrowser::rebuildAssetArray(%this)
  1234. {
  1235. if(!%this.previewArrayDirty)
  1236. {
  1237. %this.previewArrayDirty = true;
  1238. cancel(%this.pendingRebuild);
  1239. %this.pendingRebuild = %this.schedule(16, "doRebuildAssetArray");
  1240. }
  1241. }
  1242. function AssetBrowser::doRebuildAssetArray(%this)
  1243. {
  1244. if(!%this.previewArrayDirty)
  1245. return;
  1246. %breadcrumbPath = AssetBrowser.dirHandler.currentAddress;
  1247. // we have to empty out the list; so when we create new guicontrols, these dont linger
  1248. AssetBrowser-->assetList.deleteAllObjects();
  1249. AssetPreviewArray.empty();
  1250. if(isObject($AssetBrowser::AssetArray))
  1251. $AssetBrowser::AssetArray.delete();
  1252. $AssetBrowser::AssetArray = new ArrayObject();
  1253. //First, Query for our assets
  1254. %assetQuery = new AssetQuery();
  1255. %numAssetsFound = AssetDatabase.findAllAssets(%assetQuery);
  1256. %finalAssetCount = 0;
  1257. //Add folders
  1258. if(EditorSettings.value("Assets/Browser/showFolders", true) == true)
  1259. {
  1260. %folders = getDirectoryList(%breadcrumbPath);
  1261. for(%f=0; %f < getFieldCount(%folders); %f++)
  1262. {
  1263. %folderName = getField(%folders, %f);
  1264. %searchActive = AssetSearchTerms.count() != 0;
  1265. if(%searchActive)
  1266. {
  1267. if(matchesSearch(%folderName, "Folder", ""))
  1268. {
  1269. $AssetBrowser::AssetArray.add( %breadcrumbPath, "Folder" TAB %folderName );
  1270. continue;
  1271. }
  1272. }
  1273. else
  1274. {
  1275. //got it.
  1276. if(%folderName $= "shaderCache" || %folderName $= "cache" || %folderName $= ".git")
  1277. continue;
  1278. if(!%this.coreModulesFilter && %folderName $= "core" && %breadcrumbPath $= "")
  1279. continue;
  1280. if(!%this.toolsModulesFilter && %folderName $= "tools" && %breadcrumbPath $= "")
  1281. continue;
  1282. $AssetBrowser::AssetArray.add( %breadcrumbPath, "Folder" TAB %folderName );
  1283. }
  1284. }
  1285. }
  1286. //now, we'll iterate through, and find the assets that are in this module, and this category
  1287. for( %i=0; %i < %numAssetsFound; %i++)
  1288. {
  1289. %assetId = %assetQuery.getAsset(%i);
  1290. %assetPath = makeRelativePath(AssetDatabase.getAssetFilePath(%assetId));
  1291. %assetBasePath = filePath(%assetPath);
  1292. //clean up the path
  1293. %assetBasePath = strreplace(%assetBasePath, "//", "/");
  1294. %searchActive = AssetSearchTerms.count() != 0;
  1295. if(%assetBasePath $= %breadcrumbPath || (%searchActive && startsWith(%assetBasePath,%breadcrumbPath)))
  1296. {
  1297. //first, get the asset's module, as our major categories
  1298. %module = AssetDatabase.getAssetModule(%assetId);
  1299. %moduleName = %module.moduleId;
  1300. //it's good, so test that the category is right!
  1301. %assetType = AssetDatabase.getAssetCategory(%assetId);
  1302. if(%assetType $= "")
  1303. {
  1304. %assetType = AssetDatabase.getAssetType(%assetId);
  1305. }
  1306. //stop adding after previewsPerPage is hit
  1307. %assetName = AssetDatabase.getAssetName(%assetId);
  1308. if(%searchActive)
  1309. {
  1310. if(matchesSearch(%assetName, %assetType))
  1311. {
  1312. $AssetBrowser::AssetArray.add( %moduleName, %assetId);
  1313. if(%assetType !$= "Folder")
  1314. %finalAssetCount++;
  1315. continue;
  1316. }
  1317. }
  1318. else
  1319. {
  1320. if(AssetBrowser.assetTypeFilter !$= "")
  1321. {
  1322. %filtersCount = getWordCount(AssetBrowser.assetTypeFilter);
  1323. for(%fltrIdx = 0; %fltrIdx < %filtersCount; %fltrIdx++)
  1324. {
  1325. %fltr = getWord(AssetBrowser.assetTypeFilter, %fltrIdx);
  1326. if(%fltr $= %assetType)
  1327. {
  1328. $AssetBrowser::AssetArray.add( %moduleName, %assetId );
  1329. if(%assetType !$= "Folder")
  1330. %finalAssetCount++;
  1331. }
  1332. }
  1333. }
  1334. else
  1335. {
  1336. //got it.
  1337. $AssetBrowser::AssetArray.add( %moduleName, %assetId );
  1338. if(%assetType !$= "Folder")
  1339. %finalAssetCount++;
  1340. }
  1341. }
  1342. }
  1343. }
  1344. //Add Non-Asset Scripted Objects. Datablock, etc based
  1345. %hasDBFilter = true;
  1346. if(AssetBrowser.assetTypeFilter !$= "")
  1347. {
  1348. %hasDBFilter = false;
  1349. %filterCount = getWordCount(AssetBrowser.assetTypeFilter);
  1350. for(%fltrIdx = 0; %fltrIdx < %filterCount; %fltrIdx++)
  1351. {
  1352. %fltr = getWord(AssetBrowser.assetTypeFilter, %fltrIdx);
  1353. if(%fltr $= "Datablock" || %fltr $= "Datablocks")
  1354. {
  1355. %hasDBFilter = true;
  1356. break;
  1357. }
  1358. }
  1359. }
  1360. if(%hasDBFilter && %breadcrumbPath !$= "" && isDirectory(%breadcrumbPath))
  1361. {
  1362. %category = getWord( %breadcrumbPath, 1 );
  1363. %dataGroup = "DataBlockGroup";
  1364. for ( %i = 0; %i < %dataGroup.getCount(); %i++ )
  1365. {
  1366. %obj = %dataGroup.getObject(%i);
  1367. // echo ("Obj: " @ %obj.getName() @ " - " @ %obj.category );
  1368. //if ( %obj.category $= "" && %obj.category == 0 )
  1369. // continue;
  1370. %dbFilename = %obj.getFileName();
  1371. %dbFilePath = filePath(%dbFilename);
  1372. %searchActive = AssetSearchTerms.count() != 0;
  1373. if(%searchActive)
  1374. {
  1375. if(startsWith(%dbFilePath, %breadcrumbPath))
  1376. {
  1377. %dbName = %obj.getName();
  1378. if(matchesSearch(%dbName, "Datablock"))
  1379. {
  1380. $AssetBrowser::AssetArray.add( %dbFilename, "Datablock" TAB %dbName );
  1381. }
  1382. }
  1383. }
  1384. else if(%dbFilePath $= %breadcrumbPath)
  1385. {
  1386. %dbName = %obj.getName();
  1387. $AssetBrowser::AssetArray.add( %dbFilename, "Datablock" TAB %dbName );
  1388. /*%catItem = AssetBrowser-->filterTree.findItemByName(%obj.category);
  1389. if(%catItem == 0)
  1390. AssetBrowser-->filterTree.insertItem(%scriptedItem, %obj.category, "scripted");*/
  1391. /*%ctrl = %this.findIconCtrl( %obj.category );
  1392. if ( %ctrl == -1 )
  1393. {
  1394. %this.addFolderIcon( %obj.category );
  1395. }*/
  1396. }
  1397. }
  1398. %this.getLooseFilesInDir();
  1399. %looseFiles = ABLooseFileArray.count();
  1400. for( %i=0; %i < %looseFiles; %i++)
  1401. {
  1402. %looseFileFullPath = ABLooseFileArray.getKey(%i);
  1403. %looseFilePath = filePath(%looseFileFullPath);
  1404. %looseFileName = fileName(%looseFileFullPath);
  1405. %looseFileExt = fileExt(%looseFileFullPath);
  1406. $AssetBrowser::AssetArray.add( %looseFilePath, "LooseFile" TAB %looseFileName );
  1407. }
  1408. //Prefabs
  1409. %expr = "*.prefab";
  1410. %fullPrefabPath = findFirstFile( %breadcrumbPath @ "/" @ %expr );
  1411. while ( %fullPrefabPath !$= "" )
  1412. {
  1413. %prefabPath = filePath(%fullPrefabPath);
  1414. %prefabName = fileName(%fullPrefabPath);
  1415. %searchActive = AssetSearchTerms.count() != 0;
  1416. if(%searchActive)
  1417. {
  1418. if(startsWith(%prefabPath, %breadcrumbPath))
  1419. {
  1420. if(matchesSearch(%prefabName, "Prefab"))
  1421. {
  1422. $AssetBrowser::AssetArray.add( %prefabPath, "Prefab" TAB %prefabName );
  1423. }
  1424. }
  1425. }
  1426. else if(%prefabPath $= %breadcrumbPath)
  1427. {
  1428. $AssetBrowser::AssetArray.add( %prefabPath, "Prefab" TAB %prefabName );
  1429. }
  1430. %fullPrefabPath = findNextFile( %breadcrumbPath @ "/" @ %expr );
  1431. }
  1432. //C++ files
  1433. %cppPattern = %breadcrumbPath @ "/" @ "*.cpp";
  1434. for (%fullCppPath = findFirstFile(%cppPattern); %fullCppPath !$= ""; %fullCppPath = findNextFile(%cppPattern))
  1435. {
  1436. %cppPath = filePath(%fullCppPath);
  1437. %cppName = fileName(%fullCppPath);
  1438. %searchActive = AssetSearchTerms.count() != 0;
  1439. if(%searchActive)
  1440. {
  1441. if(startsWith(%cppPath, %breadcrumbPath))
  1442. {
  1443. if(matchesSearch(%cppName, "Cpp"))
  1444. {
  1445. $AssetBrowser::AssetArray.add( %cppPath, "Cpp" TAB %cppName );
  1446. }
  1447. }
  1448. }
  1449. else if(%cppPath $= %breadcrumbPath)
  1450. {
  1451. $AssetBrowser::AssetArray.add( %cppPath, "Cpp" TAB %cppName );
  1452. }
  1453. }
  1454. //C++ Header files
  1455. %cppPattern = %breadcrumbPath @ "/" @ "*.h";
  1456. for (%fullCppPath = findFirstFile(%cppPattern); %fullCppPath !$= ""; %fullCppPath = findNextFile(%cppPattern))
  1457. {
  1458. %cppPath = filePath(%fullCppPath);
  1459. %cppName = fileName(%fullCppPath);
  1460. %searchActive = AssetSearchTerms.count() != 0;
  1461. if(%searchActive)
  1462. {
  1463. if(startsWith(%cppPath, %breadcrumbPath))
  1464. {
  1465. if(matchesSearch(%cppName, "Cpp"))
  1466. {
  1467. $AssetBrowser::AssetArray.add( %cppPath, "Cpp" TAB %cppName );
  1468. }
  1469. }
  1470. }
  1471. else if(%cppPath $= %breadcrumbPath)
  1472. {
  1473. $AssetBrowser::AssetArray.add( %cppPath, "Cpp" TAB %cppName );
  1474. }
  1475. }
  1476. //script files
  1477. %tscriptPattern = %breadcrumbPath @ "/" @ "*.tscript";
  1478. for (%fullScriptPath = findFirstFile(%tscriptPattern); %fullScriptPath !$= ""; %fullScriptPath = findNextFile(%tscriptPattern))
  1479. {
  1480. //If it's associated to an asset, we'll want to do extra checks
  1481. %assetQuery = new AssetQuery();
  1482. %foundAssets = AssetDatabase.findAssetLooseFile(%assetQuery, %fullScriptPath);
  1483. if(%foundAssets != 0)
  1484. {
  1485. %doSkip = false;
  1486. %count = %assetQuery.getCount();
  1487. for(%i=0; %i < %count; %i++)
  1488. {
  1489. %assetId = %assetQuery.getAsset(%i);
  1490. %foundAssetType = AssetDatabase.getAssetType(%assetId);
  1491. if(%foundAssetType !$= "ScriptAsset" && %foundAssetType !$= "GUIAsset")
  1492. {
  1493. %doSkip = true;
  1494. break;
  1495. }
  1496. }
  1497. if(%doSkip)
  1498. continue;
  1499. }
  1500. %tscriptPath = filePath(%fullScriptPath);
  1501. %tscriptName = fileName(%fullScriptPath);
  1502. %searchActive = AssetSearchTerms.count() != 0;
  1503. if(%searchActive)
  1504. {
  1505. if(startsWith(%tscriptPath, %breadcrumbPath))
  1506. {
  1507. if(matchesSearch(%tscriptName, "tscript"))
  1508. {
  1509. $AssetBrowser::AssetArray.add( %tscriptPath, "tscript" TAB %tscriptName );
  1510. }
  1511. }
  1512. }
  1513. else if(%tscriptPath $= %breadcrumbPath)
  1514. {
  1515. $AssetBrowser::AssetArray.add( %tscriptPath, "tscript" TAB %tscriptName );
  1516. }
  1517. }
  1518. }
  1519. //If we've selected into the Creator section, we have special handling for that
  1520. if(startsWith(%breadcrumbPath, "Creator"))
  1521. {
  1522. //One of the creator folders was selected
  1523. %creatorGroup = AssetBrowserFilterTree.getItemText(AssetBrowserFilterTree.getSelectedItem(0));
  1524. if(%creatorGroup $= "Creator")
  1525. {
  1526. //add folders for the groups
  1527. %placeholderVar = "";
  1528. }
  1529. else
  1530. {
  1531. for ( %i = 0; %i < AssetBrowser.creatorClassArray.count(); %i++ )
  1532. {
  1533. %group = AssetBrowser.creatorClassArray.getKey( %i );
  1534. //Do some filter logic do skip out of groups if we're in the wrong editor mode for it
  1535. %creatorEditorFilter = "WorldEditor";
  1536. if(GuiEditorIsActive())
  1537. {
  1538. %creatorEditorFilter = "GuiEditor";
  1539. }
  1540. %creatorGroupIndex = AssetBrowserCreatorGroupsList.getIndexFromValue(%group);
  1541. %creatorGroupKey = AssetBrowserCreatorGroupsList.getKey(%creatorGroupIndex);
  1542. if ( %group $= %creatorGroup && %creatorGroupKey $= %creatorEditorFilter )
  1543. {
  1544. %creatorObj = AssetBrowser.creatorClassArray.getValue( %i );
  1545. %class = %creatorObj.val[0];
  1546. %name = %creatorObj.val[1];
  1547. %func = %creatorObj.val[2];
  1548. %searchActive = AssetSearchTerms.count() != 0;
  1549. if(%searchActive && !matchesSearch(%name, "Creator"))
  1550. continue;
  1551. $AssetBrowser::AssetArray.add( %name, "Creator" TAB %creatorObj );
  1552. }
  1553. }
  1554. }
  1555. }
  1556. for(%i=0; %i < $AssetBrowser::AssetArray.count(); %i++)
  1557. AssetBrowser.buildAssetPreview( $AssetBrowser::AssetArray.getValue(%i), $AssetBrowser::AssetArray.getKey(%i) );
  1558. //Queue population of any non-Type Card preview images
  1559. AssetBrowser.schedule(32, "populatePreviewImages");
  1560. AssetBrowser_FooterText.text = %finalAssetCount @ " Assets";
  1561. %activeTypeFilterList = "";
  1562. if(AssetBrowser.assetTypeFilter $= "")
  1563. {
  1564. if(!AssetTypeListPopup.isItemChecked(0))
  1565. {
  1566. for(%f=1; %f < AssetFilterTypeList.Count(); %f++)
  1567. {
  1568. %isChecked = AssetTypeListPopup.isItemChecked(%f+1);
  1569. if(%isChecked)
  1570. {
  1571. %filterTypeName = AssetFilterTypeList.getKey(%f);
  1572. if(%activeTypeFilterList $= "")
  1573. %activeTypeFilterList = %filterTypeName;
  1574. else
  1575. %activeTypeFilterList = %activeTypeFilterList @ ", " @ %filterTypeName;
  1576. }
  1577. }
  1578. }
  1579. }
  1580. else
  1581. {
  1582. %activeTypeFilterList = AssetBrowser.assetTypeFilter;
  1583. }
  1584. if(%activeTypeFilterList !$= "")
  1585. AssetBrowser_FooterText.text = AssetBrowser_FooterText.text @ " | Active Type Filters: " @ %activeTypeFilterList;
  1586. %this.previewArrayDirty = false;
  1587. }
  1588. //
  1589. //
  1590. // Search
  1591. function AssetBrowser::updateSearchTextFromFilter(%this)
  1592. {
  1593. AssetSearchTerms.sortk();
  1594. //Update the displayed search text!
  1595. %newSearchPhrase = "";
  1596. %currentAction = "";
  1597. %actionCount = 0;
  1598. for(%i=0; %i < AssetSearchTerms.count(); %i++)
  1599. {
  1600. %action = AssetSearchTerms.getKey(%i);
  1601. %word = AssetSearchTerms.getValue(%i);
  1602. if(%action !$= %currentAction)
  1603. {
  1604. if(%actionCount != 0)
  1605. {
  1606. if(%action !$= "")
  1607. %newSearchPhrase = %newSearchPhrase @ ";" @ %action @ ":" @ %word;
  1608. else
  1609. %newSearchPhrase = %newSearchPhrase @ ";" @ %word;
  1610. }
  1611. else
  1612. {
  1613. if(%action !$= "")
  1614. %newSearchPhrase = %action @ ":" @ %word;
  1615. else
  1616. %newSearchPhrase = %word;
  1617. }
  1618. %actionCount++;
  1619. }
  1620. else
  1621. {
  1622. %newSearchPhrase = %newSearchPhrase @ "," @ %word;
  1623. }
  1624. %currentAction = %action;
  1625. }
  1626. AssetBrowserSearchFilter.setText(%newSearchPhrase);
  1627. }
  1628. function AssetBrowser::processSearchFilter(%this)
  1629. {
  1630. AssetSearchTerms.empty();
  1631. %searchText = AssetBrowserSearchFilter.getText();
  1632. %termCount = getTokenCount(%searchText, ";");
  1633. for(%s=0; %s < %termCount; %s++)
  1634. {
  1635. %term = getToken(%searchText, ";", %s);
  1636. %phraseCount = getTokenCount(%term, ":");
  1637. if(%phraseCount == 2)
  1638. {
  1639. //action/words split
  1640. %action = getToken(%term, ":", 0);
  1641. %words = getToken(%term, ":", 1);
  1642. }
  1643. else
  1644. {
  1645. %action = "";
  1646. %words = getToken(%term, ":", 0);
  1647. }
  1648. %wordCount = getTokenCount(%words, ",");
  1649. for(%w=0; %w < %wordCount; %w++)
  1650. {
  1651. %word = getToken(%words, ",", %w);
  1652. AssetSearchTerms.add(%action, %word);
  1653. }
  1654. }
  1655. }
  1656. //Takes an item and compares it against the parsed search language
  1657. //This is written to be inclusive, rather than exclusive
  1658. function matchesSearch(%assetName, %assetType)
  1659. {
  1660. if(AssetSearchTerms.count() == 0)
  1661. return true;
  1662. %matchTags = false;
  1663. %matchType = false;
  1664. %matchName = false;
  1665. %needsTag = false;
  1666. %needsType = false;
  1667. %needsName = false;
  1668. for(%i=0; %i < AssetSearchTerms.count(); %i++)
  1669. {
  1670. %action = AssetSearchTerms.getKey(%i);
  1671. %word = AssetSearchTerms.getValue(%i);
  1672. if(%action $= "tag" && %matchTags == false)
  1673. {
  1674. %needsTag = true;
  1675. if(%assetType $= "Datablock")
  1676. {
  1677. if(%assetName.category $= %word)
  1678. %matchTags = true;
  1679. }
  1680. else
  1681. {
  1682. if(strstr(strlwr(%assetName.tags), strlwr(%word)) != -1)
  1683. %matchTags = true;
  1684. }
  1685. }
  1686. else if(%action $= "type" && %matchType == false)
  1687. {
  1688. %needsType = true;
  1689. if(%assetType $= %word)
  1690. %matchType = true;
  1691. }
  1692. else if(%action $= "" && %matchName == false)
  1693. {
  1694. %needsName = true;
  1695. if(strstr(strlwr(%assetName), strlwr(%word)) != -1)
  1696. %matchName = true;
  1697. }
  1698. }
  1699. if(((%needsTag && %matchTags) || !%needsTag) &&
  1700. ((%needsType && %matchType) || !%needsType) &&
  1701. ((%needsName && %matchName) || !%needsName))
  1702. return true;
  1703. else
  1704. return false;
  1705. }
  1706. //
  1707. //
  1708. // Search Filters
  1709. function AssetBrowserSearchFilterTxt::onWake( %this )
  1710. {
  1711. /*%filter = %this.treeView.getFilterText();
  1712. if( %filter $= "" )
  1713. %this.setText( "\c2Filter..." );
  1714. else
  1715. %this.setText( %filter );*/
  1716. }
  1717. function AssetBrowserSearchFilterTxt::onGainFirstResponder( %this )
  1718. {
  1719. %this.selectAllText();
  1720. }
  1721. // When Enter is pressed in the filter text control, pass along the text of the control
  1722. // as the treeview's filter.
  1723. function AssetBrowserFolderSearchFilter::onReturn( %this )
  1724. {
  1725. %text = %this.getText();
  1726. if( %text $= "" )
  1727. %this.reset();
  1728. AssetBrowser.refresh();
  1729. }
  1730. function AssetBrowserFolderSearchFilter::onEdited(%this)
  1731. {
  1732. if(AssetBrowserFolderSearchFilter.getText() $= "")
  1733. {
  1734. AssetBrowser-->folderSearchBtn.setBitmap("tools/gui/images/stencilIcons/zoom.png");
  1735. }
  1736. else
  1737. {
  1738. AssetBrowser-->folderSearchBtn.setBitmap("tools/gui/images/stencilIcons/cross.png");
  1739. }
  1740. }
  1741. function AssetBrowserSearchFilter::onEdited(%this)
  1742. {
  1743. AssetBrowserSearchFilter.updateButton();
  1744. }
  1745. function AssetBrowserSearchFilter::onReturn( %this )
  1746. {
  1747. %text = %this.getText();
  1748. if( %text $= "" )
  1749. %this.reset();
  1750. AssetBrowserSearchFilter.updateButton();
  1751. AssetBrowser.processSearchFilter();
  1752. AssetBrowser.rebuildAssetArray();
  1753. }
  1754. function AssetBrowserSearchFilter::updateButton(%this)
  1755. {
  1756. if(%this.getText() $= "")
  1757. {
  1758. AssetBrowser-->assetSearchBtn.setBitmap("tools/gui/images/stencilIcons/zoom.png");
  1759. }
  1760. else
  1761. {
  1762. AssetBrowser-->assetSearchBtn.setBitmap("tools/gui/images/stencilIcons/cross.png");
  1763. }
  1764. }
  1765. function AssetBrowserFolderSearchFilter::reset( %this )
  1766. {
  1767. %this.setText( "" );
  1768. AssetBrowser-->folderSearchBtn.setBitmap("tools/gui/images/stencilIcons/zoom.png");
  1769. //AssetBrowser.refresh();
  1770. }
  1771. function AssetBrowserSearchFilter::reset( %this )
  1772. {
  1773. %this.setText( "" );
  1774. AssetBrowser-->assetSearchBtn.setBitmap("tools/gui/images/stencilIcons/zoom.png");
  1775. //AssetBrowser.rebuildAssetArray();
  1776. }
  1777. function AssetBrowserFolderSearchBtn::onClick( %this )
  1778. {
  1779. AssetBrowserFolderSearchFilter.reset();
  1780. AssetBrowser.refresh();
  1781. }
  1782. function AssetBrowserAssetSearchBtn::onClick( %this )
  1783. {
  1784. AssetBrowserSearchFilter.reset();
  1785. AssetBrowser.processSearchFilter();
  1786. AssetBrowser.rebuildAssetArray();
  1787. }
  1788. //
  1789. //
  1790. // Navigation
  1791. function AssetBrowser::navigateTo(%this, %address, %historyNav)
  1792. {
  1793. //Sanitize
  1794. if(startsWith(%address, "/"))
  1795. %address = strreplace(%address, "/", "");
  1796. //Don't bother navigating if it's to the place we already are
  1797. if(%this.dirHandler.currentAddress !$= %address)
  1798. {
  1799. %this.dirHandler.navigateTo(%address, %historyNav);
  1800. //%this.updateNavigationBreadcrumb(%address);
  1801. %this.lastValidNavPath = %address;
  1802. %this-->navPath.setText(%address);
  1803. %module = %this.dirHandler.getModuleFromAddress(%address);
  1804. if(%module !$= "")
  1805. {
  1806. //legit module, so set it as current target
  1807. %this.SelectedModule = %module.moduleId;
  1808. }
  1809. if(%this.hasLooseFilesInDir())
  1810. {
  1811. if(EditorSettings.value("Assets/AutoImportLooseFiles", false) && EditorSettings.value("Assets/AutoImport", false))
  1812. {
  1813. AssetBrowser.autoImportSimpleLooseFiles();
  1814. }
  1815. else
  1816. {
  1817. %this-->AutoImportAssetButton.visible = true;
  1818. }
  1819. }
  1820. else
  1821. {
  1822. %this-->AutoImportAssetButton.visible = false;
  1823. }
  1824. }
  1825. %this.rebuildAssetArray();
  1826. %this.refresh();
  1827. }
  1828. function AssetBrowser::navigateHistoryForward(%this)
  1829. {
  1830. %this.dirHandler.navigateHistoryForward();
  1831. %this.updateNavigationBreadcrumb();
  1832. %address = %this.dirHandler.currentAddress;
  1833. %module = AssetBrowser.dirHandler.getModuleFromAddress(%address);
  1834. if(%module !$= "")
  1835. {
  1836. //legit module, so set it as current target
  1837. %this.SelectedModule = %module.moduleId;
  1838. }
  1839. %this.lastValidNavPath = %address;
  1840. %this-->navPath.setText(%address);
  1841. %this.rebuildAssetArray();
  1842. }
  1843. function AssetBrowser::navigateHistoryBack(%this)
  1844. {
  1845. %this.dirHandler.navigateHistoryBack();
  1846. %this.updateNavigationBreadcrumb();
  1847. %address = %this.dirHandler.currentAddress;
  1848. %module = %this.dirHandler.getModuleFromAddress(%address);
  1849. if(%module !$= "")
  1850. {
  1851. //legit module, so set it as current target
  1852. %this.SelectedModule = %module.moduleId;
  1853. }
  1854. %this.lastValidNavPath = %address;
  1855. %this-->navPath.setText(%address);
  1856. %this.rebuildAssetArray();
  1857. }
  1858. function AssetBrowser::updateNavigationBreadcrumb(%this, %address)
  1859. {
  1860. //clear the breadcrumb bar
  1861. AssetBrowser_BreadcrumbBar.clear();
  1862. //break down the address
  1863. %folderCount = getTokenCount(%address, "/");
  1864. %rebuiltPath = "";
  1865. for(%f=0; %f < %folderCount; %f++)
  1866. {
  1867. %folderName = getToken(%address, "/", %f);
  1868. %rebuiltPath = %f == 0 ? %folderName : %rebuiltPath @ "/" @ %folderName;
  1869. %folderNavButton = new GuiButtonCtrl()
  1870. {
  1871. profile = ToolsGuiButtonProfile;
  1872. text = %folderName;
  1873. command = "AssetBrowser.navigateTo(\"" @ %rebuiltPath @ "\");";
  1874. extent = "100" SPC AssetBrowser_BreadcrumbBar.extent.y;
  1875. };
  1876. AssetBrowser_BreadcrumbBar.add(%folderNavButton);
  1877. if(%f != %folderCount-1)
  1878. {
  1879. %folderSpacerButton = new GuiBitmapButtonCtrl()
  1880. {
  1881. profile = ToolsGuiButtonProfile;
  1882. bitmapAsset = "ToolsModule:rightArrowWhite_image";
  1883. bitmapMode = "Centered";
  1884. extent = "25" SPC AssetBrowser_BreadcrumbBar.extent.y;
  1885. //command = "AssetBrowser.navigateTo(\"" @ %rebuiltPath @ "\");";
  1886. };
  1887. AssetBrowser_BreadcrumbBar.add(%folderSpacerButton);
  1888. }
  1889. }
  1890. //refresh the nav buttons to display the history
  1891. %backButtonHistory = "";
  1892. for(%i=0; %i < AssetBrowser.dirHandler.prevHistoryList.Count(); %i++)
  1893. {
  1894. %prevAddress = AssetBrowser.dirHandler.prevHistoryList.getKey(%i);
  1895. %backButtonHistory = %i==0 ? %prevAddress @ "\n" : %backButtonHistory @ %prevAddress @ "\n";
  1896. }
  1897. AssetBrowser_NavigateBackBtn.tooltip = %backButtonHistory;
  1898. %foreButtonHistory = "";
  1899. for(%i=0; %i < AssetBrowser.dirHandler.foreHistoryList.Count(); %i++)
  1900. {
  1901. %prevAddress = AssetBrowser.dirHandler.foreHistoryList.getKey(%i);
  1902. %foreButtonHistory = %i==0 ? %prevAddress @ "\n" : %foreButtonHistory @ %prevAddress @ "\n";
  1903. }
  1904. AssetBrowser_NavigateForwardBtn.tooltip = %foreButtonHistory;
  1905. }
  1906. function assetBrowserNavPath::onReturn(%this)
  1907. {
  1908. %newPath = %this.getText();
  1909. if(isDirectory(%newPath))
  1910. {
  1911. AssetBrowser.lastValidNavPath = %newPath;
  1912. AssetBrowser.navigateTo(%newPath);
  1913. }
  1914. else
  1915. {
  1916. %this.setText(AssetBrowser.lastValidNavPath);
  1917. AssetBrowser.navigateTo(AssetBrowser.lastValidNavPath);
  1918. }
  1919. }
  1920. //
  1921. //
  1922. //
  1923. function AssetBrowser::reloadModules(%this)
  1924. {
  1925. ModuleDatabase.unloadGroup("Game");
  1926. %modulesList = ModuleDatabase.findModules();
  1927. %count = getWordCount(%modulesList);
  1928. for(%i=0; %i < %count; %i++)
  1929. {
  1930. %moduleId = getWord(%modulesList, %i).ModuleId;
  1931. ModuleDatabase.unloadExplicit(%moduleId);
  1932. }
  1933. ModuleDatabase.scanModules();
  1934. %modulesList = ModuleDatabase.findModules();
  1935. %count = getWordCount(%modulesList);
  1936. for(%i=0; %i < %count; %i++)
  1937. {
  1938. %moduleId = getWord(%modulesList, %i).ModuleId;
  1939. ModuleDatabase.loadExplicit(%moduleId);
  1940. }
  1941. //ModuleDatabase.loadGroup("Game");
  1942. }
  1943. //
  1944. //
  1945. //
  1946. function AssetBrowser::toggleFolderCollapseButton(%this)
  1947. {
  1948. %this.folderPanelState = !%this.folderPanelState;
  1949. //If we're collapsing
  1950. if(!%this.folderPanelState)
  1951. {
  1952. //Store the original
  1953. %this.folderPanelSplit = AssetBrowser_MainSplit.splitPoint.x;
  1954. //collapse it
  1955. AssetBrowser_MainSplit.setSplitPoint(AssetBrowser_MainSplit.splitterSize SPC AssetBrowser_MainSplit.splitPoint.y);
  1956. }
  1957. else
  1958. {
  1959. //restore the original
  1960. AssetBrowser_MainSplit.setSplitPoint(%this.folderPanelSplit SPC AssetBrowser_MainSplit.splitPoint.y);
  1961. }
  1962. }
  1963. //
  1964. //
  1965. // Drag n drop
  1966. function AssetBrowserPreviewButton::onMouseDragged(%this)
  1967. {
  1968. %payload = %this.clone();
  1969. %payload.position = "0 0";
  1970. //%payload.class = "AssetPreviewControl";
  1971. %xOffset = getWord( %payload.extent, 0 ) / 2;
  1972. %yOffset = getWord( %payload.extent, 1 ) / 2;
  1973. // Compute the initial position of the GuiDragAndDrop control on the cavas based on the current
  1974. // mouse cursor position.
  1975. %cursorpos = Canvas.getCursorPos();
  1976. %xPos = getWord( %cursorpos, 0 ) - %xOffset;
  1977. %yPos = getWord( %cursorpos, 1 ) - %yOffset;
  1978. if(!isObject(EditorDragAndDropLayer))
  1979. {
  1980. new GuiControl(EditorDragAndDropLayer)
  1981. {
  1982. position = "0 0";
  1983. extent = Canvas.extent;
  1984. };
  1985. }
  1986. // Create the drag control.
  1987. %ctrl = new GuiDragAndDropControl()
  1988. {
  1989. canSaveDynamicFields = "0";
  1990. Profile = "ToolsGuiSolidDefaultProfile";
  1991. HorizSizing = "right";
  1992. VertSizing = "bottom";
  1993. Position = %xPos SPC %yPos;
  1994. extent = %payload.extent;
  1995. MinExtent = "4 4";
  1996. canSave = "1";
  1997. Visible = "1";
  1998. hovertime = "1000";
  1999. // Let the GuiDragAndDropControl delete itself on mouse-up. When the drag is aborted,
  2000. // this not only deletes the drag control but also our payload.
  2001. deleteOnMouseUp = true;
  2002. useWholeCanvas = true;
  2003. // To differentiate drags, use the namespace hierarchy to classify them.
  2004. // This will allow a color swatch drag to tell itself apart from a file drag, for example.
  2005. class = "AssetPreviewControlType_AssetDrop";
  2006. };
  2007. // Add the temporary color swatch to the drag control as the payload.
  2008. %ctrl.add( %payload );
  2009. // Start drag by adding the drag control to the canvas and then calling startDragging().
  2010. //Canvas.getContent().add( %ctrl );
  2011. EditorDragAndDropLayer.add(%ctrl);
  2012. Canvas.pushDialog(EditorDragAndDropLayer);
  2013. %ctrl.startDragging( %xOffset, %yOffset );
  2014. Canvas.repaint();
  2015. }
  2016. function AssetBrowserPreviewButton::onControlDragCancelled(%this)
  2017. {
  2018. Canvas.popDialog(EditorDragAndDropLayer);
  2019. }
  2020. function AssetBrowserPreviewButton::onControlDropped( %this, %payload, %position )
  2021. {
  2022. Canvas.popDialog(EditorDragAndDropLayer);
  2023. if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
  2024. return;
  2025. // If dropped on same button whence we came from,
  2026. // do nothing.
  2027. if( %payload.dragSourceControl == %this )
  2028. return;
  2029. %assetType = %payload.assetType;
  2030. %assetName = %payload.assetName;
  2031. %moduleName = %payload.moduleName;
  2032. %targetAssetName = %this.assetName;
  2033. %targetAssetType = %this.assetType;
  2034. %targetModuleName = %this.moduleName;
  2035. if( %payload.dragSourceControl.class $= "AssetPreviewButton" && %targetAssetType $= "Folder")
  2036. {
  2037. %destination = %targetModuleName @ "/" @ %targetAssetName;
  2038. if(%assetType $= "Folder")
  2039. {
  2040. %originFolder = %moduleName @ "/" @ %assetName;
  2041. %destination = %destination @ "/" @ %assetName;
  2042. //Do any cleanup required given the type
  2043. if(AssetBrowser.isMethod("moveFolder"))
  2044. eval(AssetBrowser @ ".moveFolder(\""@%originFolder@"\",\""@%destination@"\");");
  2045. }
  2046. else
  2047. {
  2048. %assetId = %moduleName @ ":" @ %assetName;
  2049. %assetDef = AssetDatabase.acquireAsset(%assetId);
  2050. %assetType = AssetDatabase.getAssetType(%assetId);
  2051. //Do any cleanup required given the type
  2052. if(AssetBrowser.isMethod("move"@%assetType))
  2053. {
  2054. %command = AssetBrowser @ ".move" @ %assetType @ "(" @ %assetDef @ ",\"" @ %destination @ "\");";
  2055. eval(AssetBrowser @ ".move" @ %assetType @ "(" @ %assetDef @ ",\"" @ %destination @ "\");");
  2056. }
  2057. }
  2058. AssetBrowser.refresh();
  2059. }
  2060. }
  2061. function EWorldEditor::onControlDropped( %this, %payload, %position )
  2062. {
  2063. Canvas.popDialog(EditorDragAndDropLayer);
  2064. // Make sure this is a color swatch drag operation.
  2065. if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
  2066. return;
  2067. // If dropped on same button whence we came from,
  2068. // do nothing.
  2069. if( %payload.dragSourceControl == %this )
  2070. return;
  2071. %assetType = %payload.assetType;
  2072. %pos = ObjectCreator.getCreateObjectPosition(); //LocalClientConnection.camera.position;
  2073. %module = %payload.moduleName;
  2074. %asset = %payload.assetName;
  2075. if(AssetBrowser.isMethod("on" @ %assetType @ "EditorDropped"))
  2076. {
  2077. if(%assetType $= "Datablock")
  2078. {
  2079. %buildCommand = AssetBrowser @ ".on" @ %assetType @ "EditorDropped(" @ %asset @ ",\"" @ %pos @ "\");";
  2080. }
  2081. else if(%assetType $= "Prefab")
  2082. {
  2083. %buildCommand = AssetBrowser @ ".on" @ %assetType @ "EditorDropped(\"" @ %module @ "/" @ %asset @ "\",\"" @ %pos @ "\");";
  2084. }
  2085. else if(%assetType $= "Creator")
  2086. {
  2087. %buildCommand = AssetBrowser @ ".on" @ %assetType @ "EditorDropped(" @ %module @ ",\"" @ %pos @ "\");";
  2088. }
  2089. else
  2090. {
  2091. %assetDef = AssetDatabase.acquireAsset(%module @ ":" @ %asset);
  2092. %buildCommand = AssetBrowser @ ".on" @ %assetType @ "EditorDropped(" @ %assetDef @ ",\"" @ %pos @ "\");";
  2093. }
  2094. eval(%buildCommand);
  2095. if(EditorSettings.value("AssetManagement/Assets/closeBrowserOnDragAction", false))
  2096. {
  2097. AssetBrowser.hideDialog();
  2098. }
  2099. }
  2100. EWorldEditor.isDirty = true;
  2101. }
  2102. function GuiEditor::onControlDropped(%this, %payload, %position)
  2103. {
  2104. Canvas.popDialog(EditorDragAndDropLayer);
  2105. // Make sure we have the right kind of D&D.
  2106. if( !%payload.parentGroup.isInNamespaceHierarchy( "GuiDragAndDropControlType_GuiControl" ) &&
  2107. !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ))
  2108. return;
  2109. if( %payload.dragSourceControl == %this )
  2110. return;
  2111. %pos = %payload.getGlobalPosition();
  2112. %x = getWord(%pos, 0);
  2113. %y = getWord(%pos, 1);
  2114. if(%payload.assetType !$= "Creator")
  2115. {
  2116. //dealing with an actual asset, so build the assetName
  2117. %assetId = %payload.moduleName @ ":" @ %payload.assetName;
  2118. %assetType = AssetDatabase.getAssetType(%assetId);
  2119. if(AssetBrowser.isMethod("on" @ %assetType @ "GUIEditorDropped"))
  2120. {
  2121. %module = %payload.moduleName;
  2122. %asset = %payload.assetName;
  2123. %assetDef = AssetDatabase.acquireAsset(%module @ ":" @ %asset);
  2124. %buildCommand = AssetBrowser @ ".on" @ %assetType @ "GUIEditorDropped(" @ %assetDef @ ",\"" @ %pos @ "\");";
  2125. eval(%buildCommand);
  2126. }
  2127. else
  2128. {
  2129. //fallback example
  2130. if(%assetType $= "ImageAsset")
  2131. {
  2132. %cmd = "return new guiBitmapCtrl();";
  2133. %ctrl = eval( %cmd );
  2134. %ctrl.bitmap = %assetId;
  2135. }
  2136. }
  2137. }
  2138. else
  2139. {
  2140. %className = %payload.assetName;
  2141. if(%payload.altCommand !$= "")
  2142. {
  2143. %cmd = %payload.altCommand;
  2144. }
  2145. else
  2146. {
  2147. %cmd = "return new " @ %className @ "();";
  2148. }
  2149. %ctrl = eval( %cmd );
  2150. }
  2151. %this.addNewCtrl(%ctrl);
  2152. %ctrl.setPositionGlobal(%x, %y);
  2153. %this.setFirstResponder();
  2154. if(EditorSettings.value("AssetManagement/Assets/closeBrowserOnDragAction", false))
  2155. {
  2156. AssetBrowser.hideDialog();
  2157. }
  2158. }
  2159. function AssetBrowserFilterTree::onControlDropped( %this, %payload, %position )
  2160. {
  2161. Canvas.popDialog(EditorDragAndDropLayer);
  2162. if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
  2163. return;
  2164. %assetType = %payload.assetType;
  2165. %assetName = %payload.assetName;
  2166. %moduleName = %payload.moduleName;
  2167. %item = %this.getItemAtPosition(%position);
  2168. %parent = %this.getParentItem(%item);
  2169. if(%item != 1)
  2170. {
  2171. //we're a folder entry, cool
  2172. %path = %this.getItemValue(%item) @ "/" @ %this.getItemText(%item);
  2173. if(%path !$= AssetBrowser.dirHandler.CurrentAddress)
  2174. {
  2175. //we're trying to move the asset to a different module!
  2176. //toolsMessageBoxYesNo( "Move Asset", "Do you wish to move asset " @ %assetName @ " to " @ %path @ "?",
  2177. // "AssetBrowser.moveAsset(\""@ %moduleName @ ":" @ %assetName @"\", \""@%path@"\");", "");
  2178. if(%assetType $= "Folder")
  2179. {
  2180. %originFolder = %moduleName @ "/" @ %assetName;
  2181. %path = %path @ "/" @ %assetName;
  2182. //Do any cleanup required given the type
  2183. if(AssetBrowser.isMethod("moveFolder"))
  2184. {
  2185. eval(AssetBrowser @ ".moveFolder(\""@%originFolder@"\",\""@%path@"\");");
  2186. AssetBrowser.refresh();
  2187. }
  2188. }
  2189. else
  2190. {
  2191. %assetId = %moduleName @ ":" @ %assetName;
  2192. %assetDef = AssetDatabase.acquireAsset(%assetId);
  2193. %assetType = AssetDatabase.getAssetType(%assetId);
  2194. //Do any cleanup required given the type
  2195. if(AssetBrowser.isMethod("move"@%assetType))
  2196. {
  2197. %command = AssetBrowser @ ".move" @ %assetType @ "(" @ %assetDef @ ",\"" @ %path @ "\");";
  2198. eval(AssetBrowser @ ".move" @ %assetType @ "(" @ %assetDef @ ",\"" @ %path @ "\");");
  2199. AssetBrowser.refresh();
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. function AssetBrowserFilterTree::onDragDropped( %this )
  2206. {
  2207. }
  2208. function AssetBrowser::hasLooseFilesInDir(%this)
  2209. {
  2210. if(!isDirectory(%this.dirHandler.currentAddress))
  2211. return false;
  2212. //First, wipe out any files inside the folder first
  2213. %file = findFirstFileMultiExpr( %this.dirHandler.currentAddress @ "/*.*", false);
  2214. %aq = new AssetQuery();
  2215. while( %file !$= "" )
  2216. {
  2217. if(!strIsMatchExpr("*.asset.taml", %file) && !strIsMatchExpr("*.taml", %file) && !strIsMatchExpr("*.cached.dts", %file))
  2218. {
  2219. %assetsFound = AssetDatabase.findAssetLooseFile(%aq, %file);
  2220. if(%assetsFound == 0)
  2221. {
  2222. %ext = fileExt(%file);
  2223. if(isShapeFormat(%ext) || isImageFormat(%ext) || isSoundFormat(%ext))
  2224. {
  2225. %aq.delete();
  2226. return true;
  2227. }
  2228. }
  2229. }
  2230. %file = findNextFileMultiExpr( %this.dirHandler.currentAddress @ "/*.*" );
  2231. }
  2232. %aq.delete();
  2233. return false;
  2234. }
  2235. function AssetBrowser::autoImportSimpleLooseFiles(%this)
  2236. {
  2237. %importer = new AssetImporter();
  2238. //First, wipe out any files inside the folder first
  2239. %file = findFirstFileMultiExpr( %this.dirHandler.currentAddress @ "/*.*", false);
  2240. %aq = new AssetQuery();
  2241. while( %file !$= "" )
  2242. {
  2243. if(!strIsMatchExpr("*.asset.taml", %file) && !strIsMatchExpr("*.taml", %file) && !strIsMatchExpr("*.cached.dts", %file)
  2244. && !strIsMatchExpr("*.cs", %file) && !strIsMatchExpr("*.tscript", %file) && !strIsMatchExpr("*.module", %file))
  2245. {
  2246. %aq.clear();
  2247. %assetsFound = AssetDatabase.findAssetLooseFile(%aq, %file);
  2248. if(%assetsFound == 0)
  2249. {
  2250. %ext = fileExt(%file);
  2251. if(isShapeFormat(%ext) || isImageFormat(%ext) || isSoundFormat(%ext))
  2252. {
  2253. %assetId = %importer.autoImportFile(%file);
  2254. }
  2255. }
  2256. }
  2257. %file = findNextFileMultiExpr( %this.dirHandler.currentAddress @ "/*.*" );
  2258. }
  2259. %aq.delete();
  2260. %importer.delete();
  2261. %this.refresh();
  2262. }
  2263. function AssetBrowser::getLooseFilesInDir(%this)
  2264. {
  2265. if(!isObject(ABLooseFileArray))
  2266. new ArrayObject(ABLooseFileArray);
  2267. ABLooseFileArray.empty();
  2268. %showLooseFiles = EditorSettings.value("Assets/Browser/showLooseFiles", false);
  2269. if(%showLooseFiles == false)
  2270. return;
  2271. //First, wipe out any files inside the folder first
  2272. %file = findFirstFileMultiExpr( %this.dirHandler.currentAddress @ "/*.*", false);
  2273. %aq = new AssetQuery();
  2274. while( %file !$= "" )
  2275. {
  2276. if(!strIsMatchExpr("*.asset.taml", %file) && !strIsMatchExpr("*.taml", %file) && !strIsMatchExpr("*.cached.dts", %file))
  2277. {
  2278. %assetsFound = AssetDatabase.findAssetLooseFile(%aq, %file);
  2279. if(%assetsFound == 0)
  2280. {
  2281. ABLooseFileArray.add(%file);
  2282. }
  2283. }
  2284. %file = findNextFileMultiExpr( %this.dirHandler.currentAddress @ "/*.*" );
  2285. }
  2286. %aq.delete();
  2287. return false;
  2288. }
  2289. //
  2290. //
  2291. function AssetBrowser::importLooseFiles(%this)
  2292. {
  2293. echo("Adding loose files at directory " @ %this.dirHandler.currentAddress);
  2294. LooseFileAuditWindow.showDialog(%this.dirHandler.currentAddress);
  2295. }
  2296. // -----------------------------------------------------------------------------
  2297. function getAssetPreviewImage(%asset)
  2298. {
  2299. if(isFile(%asset))
  2300. {
  2301. %aq = new AssetQuery();
  2302. %assetsFound = AssetDatabase.findAssetLooseFile(%aq, %asset);
  2303. if(%assetsFound != 0)
  2304. {
  2305. %asset = %aq.getAsset(0);
  2306. }
  2307. else
  2308. {
  2309. %previewPath = %asset;
  2310. }
  2311. %aq.delete();
  2312. }
  2313. if(AssetDatabase.isDeclaredAsset(%asset))
  2314. {
  2315. %moduleName = AssetDatabase.getAssetModule(%asset).ModuleId;
  2316. %assetName = AssetDatabase.getAssetName(%asset);
  2317. %previewAssetName = "ToolsModule:" @ %moduleName @ "_" @ %assetName @ "_PreviewImage";
  2318. if(AssetDatabase.isDeclaredAsset(%previewAssetName))
  2319. {
  2320. %previewDef = AssetDatabase.acquireAsset(%previewAssetName);
  2321. %previewPath = %previewDef.getImagePath();
  2322. AssetDatabase.releaseAsset(%previewAssetName);
  2323. }
  2324. else
  2325. {
  2326. %previewPath = %asset;
  2327. }
  2328. }
  2329. else
  2330. {
  2331. %previewPath = %asset;
  2332. }
  2333. if(%previewPath $= "")
  2334. %previewPath = "ToolsModule:unknownImage_image";
  2335. return %previewPath;
  2336. }
  2337. // -----------------------------------------------------------------------------
  2338. function AssetBrowserWindow::dockPanel(%this)
  2339. {
  2340. if(%this.docked == true)
  2341. return;
  2342. %this.resizing = true;
  2343. %this.docked = true;
  2344. %this.canCollapse = "0";
  2345. %this.canMove = "0";
  2346. %this.resizeWidth = "0";
  2347. AssetBrowserWindow_UnDockBtn.Visible = "1";
  2348. AssetBrowserWindow_DockBtn.Visible = "0";
  2349. EditorGui.updateSideBar();
  2350. }
  2351. function AssetBrowserWindow::releasePanel(%this)
  2352. {
  2353. if(%this.docked == false)
  2354. return;
  2355. %this.canCollapse = "1";
  2356. %this.canMove = "1";
  2357. %this.resizeWidth = "1";
  2358. AssetBrowserWindow_UnDockBtn.Visible = "0";
  2359. AssetBrowserWindow_DockBtn.Visible = "1";
  2360. // Let's do a small resize so it's visually clear we're "undocking"
  2361. %position = %this.position.x + 6 SPC %this.position.y - 6;
  2362. %extent = %this.extent.x SPC %this.extent.y;
  2363. %this.resize(%position.x, %position.y, %extent.x, %extent.y);
  2364. %this.docked = false;
  2365. %this.resizing = false;
  2366. EditorGui.updateSideBar();
  2367. }
  2368. function AssetBrowserWindow::onResize(%this, %posX, %posY, %width, %height)
  2369. {
  2370. if (%width>%height)
  2371. AssetBrowser-->assetList.fillRowFirst = true;
  2372. else
  2373. AssetBrowser-->assetList.fillRowFirst = false;
  2374. AssetBrowser.rebuildAssetArray();
  2375. }