assetBrowser.tscript 84 KB

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