decalEditorGui.tscript 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------
  23. function DecalEditorGui::onWake(%this)
  24. {
  25. %fixedWindow = DecalEditorWindow;
  26. %fluidWindow = DecalPreviewWindow;
  27. if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1)
  28. {
  29. // Let's dock the side panel to the right side
  30. %this.docked = false;
  31. %this.resizing = true;
  32. %this.dockSidePanel();
  33. }
  34. else
  35. {
  36. // Let's release the side panel so it can be moved
  37. %this.docked = true;
  38. %this.resizing = false;
  39. %this.releaseSidePanel();
  40. }
  41. }
  42. function DecalEditorGui::maxSize(%this, %window)
  43. {
  44. // Resize the windows to the max height
  45. // and force these to the right side if set
  46. if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1 && %this.resizing == true)
  47. {
  48. // prevent onResize after a resize
  49. %this.resizing = false;
  50. %fixedWindow = DecalEditorWindow;
  51. %fluidWindow = DecalPreviewWindow;
  52. %offset = -1; // tweak the vertical offset so that it aligns neatly
  53. %top = EditorGuiToolbar.extent.y + %offset;
  54. %bottom = %top + 59;
  55. %maxHeight = Canvas.extent.y - %top - %bottom;
  56. // --- Fixed window (top) ------------------------------------------------
  57. // put it back if it moved
  58. %fixedWindow.position.x = Canvas.extent.x - %fixedWindow.extent.x;
  59. %fixedWindow.position.y = %top;
  60. // don't go beyond the canvas
  61. if(%fixedWindow.extent.y > %maxHeight)
  62. %fixedWindow.extent.y = %maxHeight - %fluidWindow.extent.y;
  63. %position = %fixedWindow.position.x SPC %fixedWindow.position.y;
  64. %extent = %window.extent.x SPC %fixedWindow.extent.y;
  65. %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  66. // --- Fluid window (bottom) ---------------------------------------------
  67. // position is relative to the top window
  68. %position = %fixedWindow.position.x SPC %fixedWindow.extent.y + %top;
  69. %extent = %window.extent.x SPC Canvas.extent.y - %fixedWindow.extent.y - %bottom;
  70. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  71. // --- AssetBrowser window ----------------------------------------------
  72. if(isObject(AssetBrowserWindow))
  73. {
  74. // Only resize the AssetBrowser if it's docked
  75. if(AssetBrowserWindow.docked == true)
  76. {
  77. // The width is relative to the sidepanel
  78. %browserWidth = Canvas.extent.x - %extent.x;
  79. %browserHeight = AssetBrowserWindow.extent.y;
  80. %browserPosY = Canvas.extent.y - AssetBrowserWindow.extent.y - 33;
  81. AssetBrowserWindow.resize(0, %browserPosY, %browserWidth, %browserHeight);
  82. }
  83. }
  84. // --- Windowed Console --------------------------------------------------
  85. if(isObject(windowConsoleControl))
  86. {
  87. // Only resize the AssetBrowser if it's docked
  88. if(windowConsoleControl.docked == true)
  89. {
  90. // The width is relative to the sidepanel
  91. %consoleWidth = Canvas.extent.x - %extent.x;
  92. %consoleHeight = windowConsoleControl.extent.y;
  93. %consolePosY = Canvas.extent.y - windowConsoleControl.extent.y - 33;
  94. windowConsoleControl.resize(0, %consolePosY, %consoleWidth, %consoleHeight);
  95. }
  96. }
  97. }
  98. }
  99. function DecalEditorWindow::onMouseDragged(%this)
  100. {
  101. %parent = DecalEditorGui;
  102. if(%parent.panelHidden == true)
  103. {
  104. %parent.showSidePanel();
  105. }
  106. if(%parent.resizing == false && %parent.docked == true)
  107. {
  108. %parent.resizing = true;
  109. %parent.maxSize(%this);
  110. }
  111. }
  112. function DecalPreviewWindow::onMouseDragged(%this)
  113. {
  114. %parent = DecalEditorGui;
  115. if(%parent.panelHidden == true)
  116. {
  117. %parent.showSidePanel();
  118. }
  119. if(%parent.resizing == false && %parent.docked == true)
  120. {
  121. %parent.resizing = true;
  122. %parent.maxSize(%this);
  123. }
  124. }
  125. function DecalEditorGui::onResize(%this, %newPosition, %newExtent)
  126. {
  127. // Window to focus on (mostly the fluid window)
  128. %window = DecalPreviewWindow;
  129. if(%window.panelHidden == true)
  130. {
  131. %window.showSidePanel();
  132. }
  133. if(%this.resizing == false && %this.docked == true)
  134. {
  135. // Only resize once
  136. %this.resizing = true;
  137. %this.maxSize(%window);
  138. }
  139. }
  140. function DecalEditorGui::dockSidePanel()
  141. {
  142. %parent = DecalEditorGui;
  143. %fixedWindow = DecalEditorWindow;
  144. %fluidWindow = DecalPreviewWindow;
  145. if(%parent.docked == true)
  146. return;
  147. // Move and resize the window(s)
  148. %parent.resizing = true;
  149. %parent.maxSize(%fluidWindow);
  150. %parent.docked = true;
  151. %fluidWindow.onMouseDragged();
  152. // Lock the windows in place
  153. %fixedWindow.canCollapse = "0";
  154. %fixedWindow.canMove = "0";
  155. %fluidWindow.canCollapse = "0";
  156. %fluidWindow.canMove = "0";
  157. DecalEditorGui_UnDockBtn.Visible = "1";
  158. DecalEditorGui_DockBtn.Visible = "0";
  159. DecalEditorGui_showBtn.Visible = "0";
  160. DecalEditorGui_hideBtn.Visible = "1";
  161. }
  162. function DecalEditorGui::releaseSidePanel()
  163. {
  164. %parent = DecalEditorGui;
  165. %fixedWindow = DecalEditorWindow;
  166. %fluidWindow = DecalPreviewWindow;
  167. if(%parent.docked == false)
  168. return;
  169. // Unlock the windows so that be moved
  170. %fixedWindow.canCollapse = "1";
  171. %fixedWindow.canMove = "1";
  172. %fluidWindow.canCollapse = "1";
  173. %fluidWindow.canMove = "1";
  174. DecalEditorGui_UnDockBtn.Visible = "0";
  175. DecalEditorGui_DockBtn.Visible = "1";
  176. DecalEditorGui_showBtn.Visible = "0";
  177. DecalEditorGui_hideBtn.Visible = "0";
  178. // Let's do a small resize so it's visually clear we're undocking
  179. %position = %fixedWindow.position.x - 6 SPC %fixedWindow.position.y + 6;
  180. %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y;
  181. %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  182. %position = %fluidWindow.position.x - 6 SPC %fluidWindow.position.y + 6;
  183. %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y - 12;
  184. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  185. %parent.docked = false;
  186. %parent.resizing = false;
  187. }
  188. function DecalEditorGui::hideSidePanel()
  189. {
  190. %parent = DecalEditorGui;
  191. %fixedWindow = DecalEditorWindow;
  192. %fluidWindow = DecalPreviewWindow;
  193. DecalEditorGui_showBtn.Visible = "1";
  194. DecalEditorGui_hideBtn.Visible = "0";
  195. // hide the content of the panels
  196. %fixedWindow.titleText = %fixedWindow.text;
  197. %fluidWindow.titleText = %fluidWindow.text;
  198. %fixedWindow.text = "";
  199. DecalEditorTabBook.Visible = "0";
  200. %fluidWindow.text = "";
  201. DecalEditorTemplateProperties.Visible = "0";
  202. DecalEditorLibraryProperties.Visible = "0";
  203. // Let's do a resize so that the panel is collapsed to the side
  204. %position = Canvas.extent.x - 24 SPC %fixedWindow.position.y;
  205. %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y;
  206. %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  207. %position = Canvas.extent.x - 24 SPC %fluidWindow.position.y;
  208. %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y;
  209. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  210. %parent.panelHidden = true;
  211. }
  212. function DecalEditorGui::showSidePanel()
  213. {
  214. %parent = DecalEditorGui;
  215. %fixedWindow = DecalEditorWindow;
  216. %fluidWindow = DecalPreviewWindow;
  217. DecalEditorGui_showBtn.Visible = "0";
  218. DecalEditorGui_hideBtn.Visible = "1";
  219. // show the content of the panels
  220. %fixedWindow.text = %fixedWindow.titleText;
  221. DecalEditorTabBook.Visible = "1";
  222. %fluidWindow.text = %fluidWindow.titleText;
  223. DecalEditorTemplateProperties.Visible = "1";
  224. DecalEditorLibraryProperties.Visible = "1";
  225. %parent.resizing = true;
  226. %parent.maxSize(%fluidWindow);
  227. %parent.panelHidden = false;
  228. }
  229. //-----------------------------------------------------------------------------
  230. function DecalEditorGui::onSelectInstance( %this, %decalId, %lookupName )
  231. {
  232. if( DecalEditorGui.selDecalInstanceId == %decalId )
  233. return;
  234. // Lets remember the new Id
  235. DecalEditorGui.selDecalInstanceId = %decalId;
  236. DecalEditorTreeView.clearSelection();
  237. %name = %decalId SPC %lookupName;
  238. %item = DecalEditorTreeView.findItemByName( %name );
  239. DecalEditorTreeView.selectItem( %item );
  240. DecalEditorGui.syncNodeDetails();
  241. }
  242. function DecalEditorGui::onCreateInstance( %this, %decalId, %lookupName )
  243. {
  244. // Lets remember the new Id
  245. DecalEditorGui.selDecalInstanceId = %decalId;
  246. // Add the new instance to the node tree
  247. DecalEditorTreeView.addNodeTree( %decalId, %lookupName );
  248. DecalEditorTreeView.clearSelection();
  249. %name = %decalId SPC %lookupName;
  250. %item = DecalEditorTreeView.findItemByName( %name );
  251. DecalEditorTreeView.selectItem( %item );
  252. DecalEditorGui.syncNodeDetails();
  253. }
  254. function DecalEditorGui::onDeleteInstance( %this, %decalId, %lookupName )
  255. {
  256. if( %decalId == DecalEditorGui.selDecalInstanceId )
  257. DecalEditorGui.selDecalInstanceId = -1;
  258. %id = DecalEditorTreeView.findItemByName( %decalId SPC %lookupName );
  259. DecalEditorTreeView.removeItem(%id);
  260. }
  261. function DecalEditorGui::editNodeDetails( %this )
  262. {
  263. %decalId = DecalEditorGui.selDecalInstanceId;
  264. if( %decalId == -1 )
  265. return;
  266. %nodeDetails = DecalEditorDetailContainer-->nodePosition.getText();
  267. %nodeDetails = %nodeDetails @ " " @ DecalEditorDetailContainer-->nodeTangent.getText();
  268. %nodeDetails = %nodeDetails @ " " @ DecalEditorDetailContainer-->nodeSize.getText();
  269. if( getWordCount(%nodeDetails) == 7 )
  270. DecalEditorGui.doEditNodeDetails( %decalId, %nodeDetails, false );
  271. }
  272. // Stores the information when the gizmo is first used
  273. function DecalEditorGui::prepGizmoTransform( %this, %decalId, %nodeDetails )
  274. {
  275. DecalEditorGui.gizmoDetails = %nodeDetails;
  276. }
  277. // Activated in onMouseUp while gizmo is dirty
  278. function DecalEditorGui::completeGizmoTransform( %this, %decalId, %nodeDetails )
  279. {
  280. DecalEditorGui.doEditNodeDetails( %decalId, %nodeDetails, true );
  281. }
  282. function DecalEditorGui::onSleep( %this )
  283. {
  284. }
  285. function DecalEditorGui::syncNodeDetails( %this )
  286. {
  287. %decalId = DecalEditorGui.selDecalInstanceId;
  288. if( %decalId == -1 )
  289. return;
  290. %lookupName = DecalEditorGui.getDecalLookupName( %decalId );
  291. DecalEditorGui.updateInstancePreview( %lookupName.materialAsset );
  292. DecalEditorDetailContainer-->instanceId.setText(%decalId @ " " @ %lookupName);
  293. %transformData = DecalEditorGui.getDecalTransform(%decalId);
  294. DecalEditorDetailContainer-->nodePosition.setText(getWords(%transformData, 0, 2));
  295. DecalEditorDetailContainer-->nodeTangent.setText(getWords(%transformData, 3, 5));
  296. DecalEditorDetailContainer-->nodeSize.setText(getWord(%transformData, 6));
  297. }
  298. function DecalEditorGui::paletteSync( %this, %mode )
  299. {
  300. %evalShortcut = "ToolsPaletteArray-->" @ %mode @ ".setStateOn(1);";
  301. eval(%evalShortcut);
  302. }
  303. function DecalDataList::onSelect( %this, %id, %text )
  304. {
  305. %obj = %this.getItemObject( %id );
  306. DecalEditorGui.currentDecalData = %obj;
  307. %itemNum = DecalDataList.getSelectedItem();
  308. if ( %itemNum == -1 )
  309. return;
  310. %data = DecalDataList.getItemObject( %itemNum );
  311. // Update the materialEditorList
  312. $Tools::materialEditorList = %data.getId();
  313. //Canvas.pushDialog( DecalEditDlg );
  314. DecalInspector.inspect( %data );
  315. DecalEditorGui.updateDecalPreview( %data.materialAsset );
  316. }
  317. function RetargetDecalButton::onClick( %this )
  318. {
  319. %id = DecalDataList.getSelectedItem();
  320. %datablock = DecalDataList.getItemText(%id );
  321. if( !isObject(%datablock) )
  322. {
  323. toolsMessageBoxOK("Error", "A valid Decal Template must be selected.");
  324. return;
  325. }
  326. // This is the first place IODropdown is used. The # in the function passed replaced with the output
  327. // of the preset menu.
  328. IODropdown("Retarget Decal Instances",
  329. "Retarget DecalInstances from " @ %datablock.getName() @ " over to....",
  330. "decalDataSet",
  331. "DecalEditorGui.retargetDecalDatablock(" @ %datablock.getName() @ ", #);",
  332. "");
  333. DecalEditorGui.rebuildInstanceTree();
  334. }
  335. function NewDecalButton::onClick( %this )
  336. {
  337. AssetBrowser_SelectModule.showDialog("DecalEditorGui.pickedNewDecalTargetModule");
  338. AssetBrowser_SelectModuleWindow.selectWindow();
  339. }
  340. function DecalEditorGui::pickedNewDecalTargetModule(%this, %module)
  341. {
  342. %moduleDef = ModuleDatabase.findModule(%module);
  343. $decalDataFile = %moduleDef.ModulePath @ "/scripts/managedData/managedDecalData." @ $TorqueScriptFileExtension;
  344. if(!isDirectory(filePath($decalDataFile)))
  345. {
  346. AssetBrowser.dirHandler.createFolder(filePath($decalDataFile));
  347. }
  348. %name = getUniqueName( "NewDecalData" );
  349. %str = "datablock DecalData( " @ %name @ " ) { Material = \"WarningMaterial\"; };";
  350. eval( %str );
  351. DecalPMan.setDirty( %name, $decalDataFile );
  352. if ( strchr(LibraryTabControl.text, "*") $= "" )
  353. LibraryTabControl.text = LibraryTabControl.text @ "*";
  354. DecalDataList.doMirror();
  355. %id = DecalDataList.findItemText( %name );
  356. DecalDataList.setSelected( %id, true );
  357. Canvas.pushDialog( DecalEditDlg );
  358. DecalInspector.inspect( %name );
  359. }
  360. function DeleteDecalButton::onClick( %this )
  361. {
  362. if( DecalEditorTabBook.getSelectedPage() == 0 ) // library
  363. {
  364. %id = DecalDataList.getSelectedItem();
  365. %datablock = DecalDataList.getItemText(%id );
  366. toolsMessageBoxYesNoCancel("Delete Decal Datablock?",
  367. "Are you sure you want to delete<br><br>" @ %datablock @ "<br><br> Datablock deletion won't take affect until the engine is quit.",
  368. "DecalEditorGui.deleteSelectedDecalDatablock();",
  369. "",
  370. "" );
  371. }
  372. else // instances
  373. {
  374. DecalEditorGui.deleteSelectedDecal();
  375. }
  376. }
  377. // Intended for gui use. The undo/redo functionality for deletion of datablocks
  378. // will enable itself automatically after using this function.
  379. function DecalEditorGui::deleteSelectedDecalDatablock()
  380. {
  381. %id = DecalDataList.getSelectedItem();
  382. %datablock = DecalDataList.getItemText(%id );
  383. DecalEditorGui.deleteDecalDatablock( %datablock );
  384. if( %datablock.getFilename() !$= "" )
  385. {
  386. DecalPMan.removeDirty( %datablock );
  387. DecalPMan.removeObjectFromFile( %datablock );
  388. }
  389. DecalDataList.addFilteredItem( %datablock );
  390. }
  391. function DecalEditorTabBook::onTabSelected( %this, %text, %idx )
  392. {
  393. if( %idx == 0)
  394. {
  395. DecalPreviewWindow.text = ":: Decal Editor - Template Properties";
  396. DecalEditorLibraryProperties.setVisible(true);
  397. DecalEditorTemplateProperties.setVisible(false);
  398. RetargetDecalButton.setVisible( true );
  399. SaveDecalsButton.setVisible( true );
  400. NewDecalButton.setVisible( true );
  401. DeleteDecalButton.tabSelected = %idx;
  402. }
  403. else
  404. {
  405. DecalPreviewWindow.text = ":: Decal Editor - Instance Properties";
  406. RetargetDecalButton.setVisible( false );
  407. NewDecalButton.setVisible( false );
  408. SaveDecalsButton.setVisible( false );
  409. DeleteDecalButton.tabSelected = %idx;
  410. DecalEditorLibraryProperties.setVisible(false);
  411. DecalEditorTemplateProperties.setVisible(true);
  412. }
  413. }
  414. function DecalEditorTreeView::onDefineIcons()
  415. {
  416. %icons = "tools/gui/images/treeview/default:" @
  417. "tools/classIcons/decal:" @
  418. "tools/classIcons/decalNode:";
  419. DecalEditorTreeView.buildIconTable( %icons );
  420. }
  421. function DecalEditorTreeView::onSelect(%this, %id)
  422. {
  423. %instanceTag = getWord( DecalEditorTreeView.getItemText(%id), 1 );
  424. if( !isObject( %instanceTag ) )
  425. return;
  426. if( %instanceTag.getClassName() !$= "DecalData" )
  427. return;
  428. // Grab the id from the tree view
  429. %decalId = getWord( DecalEditorTreeView.getItemText(%id), 0 );
  430. if( DecalEditorGui.selDecalInstanceId == %decalId )
  431. return;
  432. // Set the curent decalinstances id
  433. DecalEditorGui.selDecalInstanceId = %decalId;
  434. DecalEditorGui.selectDecal(%decalId);
  435. DecalEditorGui.syncNodeDetails(%id);
  436. }
  437. // Creating per node in the instance tree
  438. function DecalEditorTreeView::addNodeTree(%this, %nodeName, %parentName)
  439. {
  440. // If my template isnt there...put it there
  441. if ( %this.findItemByName(%parentName) == 0 )
  442. {
  443. %rootId = %this.findItemByName("<root>");
  444. %this.insertItem( %rootId, %parentName, 0, "", 1, 1);
  445. }
  446. %nodeName = %nodeName SPC %parentName;
  447. %parentId = %this.findItemByName(%parentName);
  448. %id = %this.insertItem(%parentId, %nodeName, 0, "", 2);
  449. }
  450. function DecalInspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue )
  451. {
  452. if( %fieldName $= "Material" || %fieldName $= "MaterialAsset")
  453. DecalEditorGui.updateDecalPreview( %newValue );
  454. // Same work to do as for the regular WorldEditor Inspector.
  455. Inspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue );
  456. if (%oldValue != %newValue || %oldValue !$= %newValue)
  457. %this.setDirty(%object);
  458. }
  459. function DecalInspector::setDirty( %this, %object )
  460. {
  461. DecalPMan.setDirty( %object );
  462. if ( strchr(LibraryTabControl.text, "*") $= "" )
  463. LibraryTabControl.text = LibraryTabControl.text @ "*";
  464. }
  465. function DecalInspector::removeDirty()
  466. {
  467. if ( strchr(LibraryTabControl.text, "*") !$= "" )
  468. LibraryTabControl.text = stripChars(LibraryTabControl.text, "*");
  469. }
  470. function DecalEditorGui::updateDecalPreview( %this, %material )
  471. {
  472. %previewImage = "";
  473. if( isObject( %material ) )
  474. {
  475. %previewImage = %material.getDiffuseMap(0);
  476. }
  477. else
  478. {
  479. if(AssetDatabase.isDeclaredAsset(%material))
  480. {
  481. %previewImage = %material;
  482. }
  483. }
  484. DecalPreviewWindow-->decalPreview.setBitmap( getAssetPreviewImage(%previewImage) );
  485. }
  486. function DecalEditorGui::updateInstancePreview( %this, %material )
  487. {
  488. %previewImage = "";
  489. if( isObject( %material ) )
  490. {
  491. %previewImage = %material.getDiffuseMap(0);
  492. }
  493. else
  494. {
  495. if(AssetDatabase.isDeclaredAsset(%material))
  496. {
  497. %previewImage = %material;
  498. }
  499. }
  500. DecalPreviewWindow-->instancePreview.setBitmap( getAssetPreviewImage(%previewImage) );
  501. }
  502. function DecalEditorGui::rebuildInstanceTree( %this )
  503. {
  504. // Initialize the instance tree when the tab is selected
  505. DecalEditorTreeView.removeItem(0);
  506. %rootId = DecalEditorTreeView.insertItem(0, "<root>", 0, "");
  507. %count = DecalEditorGui.getDecalCount();
  508. for (%i = 0; %i < %count; %i++)
  509. {
  510. %name = DecalEditorGui.getDecalLookupName(%i);
  511. if( %name $= "invalid" )
  512. continue;
  513. DecalEditorTreeView.addNodeTree(%i, %name);
  514. }
  515. }