decalEditorGui.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. function DecalEditorGui::onWake( %this )
  23. {
  24. }
  25. function DecalEditorGui::onSelectInstance( %this, %decalId, %lookupName )
  26. {
  27. if( DecalEditorGui.selDecalInstanceId == %decalId )
  28. return;
  29. // Lets remember the new Id
  30. DecalEditorGui.selDecalInstanceId = %decalId;
  31. DecalEditorTreeView.clearSelection();
  32. %name = %decalId SPC %lookupName;
  33. %item = DecalEditorTreeView.findItemByName( %name );
  34. DecalEditorTreeView.selectItem( %item );
  35. DecalEditorGui.syncNodeDetails();
  36. }
  37. function DecalEditorGui::onCreateInstance( %this, %decalId, %lookupName )
  38. {
  39. // Lets remember the new Id
  40. DecalEditorGui.selDecalInstanceId = %decalId;
  41. // Add the new instance to the node tree
  42. DecalEditorTreeView.addNodeTree( %decalId, %lookupName );
  43. DecalEditorTreeView.clearSelection();
  44. %name = %decalId SPC %lookupName;
  45. %item = DecalEditorTreeView.findItemByName( %name );
  46. DecalEditorTreeView.selectItem( %item );
  47. DecalEditorGui.syncNodeDetails();
  48. }
  49. function DecalEditorGui::onDeleteInstance( %this, %decalId, %lookupName )
  50. {
  51. if( %decalId == DecalEditorGui.selDecalInstanceId )
  52. DecalEditorGui.selDecalInstanceId = -1;
  53. %id = DecalEditorTreeView.findItemByName( %decalId SPC %lookupName );
  54. DecalEditorTreeView.removeItem(%id);
  55. }
  56. function DecalEditorGui::editNodeDetails( %this )
  57. {
  58. %decalId = DecalEditorGui.selDecalInstanceId;
  59. if( %decalId == -1 )
  60. return;
  61. %nodeDetails = DecalEditorDetailContainer-->nodePosition.getText();
  62. %nodeDetails = %nodeDetails @ " " @ DecalEditorDetailContainer-->nodeTangent.getText();
  63. %nodeDetails = %nodeDetails @ " " @ DecalEditorDetailContainer-->nodeSize.getText();
  64. if( getWordCount(%nodeDetails) == 7 )
  65. DecalEditorGui.doEditNodeDetails( %decalId, %nodeDetails, false );
  66. }
  67. // Stores the information when the gizmo is first used
  68. function DecalEditorGui::prepGizmoTransform( %this, %decalId, %nodeDetails )
  69. {
  70. DecalEditorGui.gizmoDetails = %nodeDetails;
  71. }
  72. // Activated in onMouseUp while gizmo is dirty
  73. function DecalEditorGui::completeGizmoTransform( %this, %decalId, %nodeDetails )
  74. {
  75. DecalEditorGui.doEditNodeDetails( %decalId, %nodeDetails, true );
  76. }
  77. function DecalEditorGui::onSleep( %this )
  78. {
  79. }
  80. function DecalEditorGui::syncNodeDetails( %this )
  81. {
  82. %decalId = DecalEditorGui.selDecalInstanceId;
  83. if( %decalId == -1 )
  84. return;
  85. %lookupName = DecalEditorGui.getDecalLookupName( %decalId );
  86. DecalEditorGui.updateInstancePreview( %lookupName.material );
  87. DecalEditorDetailContainer-->instanceId.setText(%decalId @ " " @ %lookupName);
  88. %transformData = DecalEditorGui.getDecalTransform(%decalId);
  89. DecalEditorDetailContainer-->nodePosition.setText(getWords(%transformData, 0, 2));
  90. DecalEditorDetailContainer-->nodeTangent.setText(getWords(%transformData, 3, 5));
  91. DecalEditorDetailContainer-->nodeSize.setText(getWord(%transformData, 6));
  92. }
  93. function DecalEditorGui::paletteSync( %this, %mode )
  94. {
  95. %evalShortcut = "ToolsPaletteArray-->" @ %mode @ ".setStateOn(1);";
  96. eval(%evalShortcut);
  97. }
  98. function DecalDataList::onSelect( %this, %id, %text )
  99. {
  100. %obj = %this.getItemObject( %id );
  101. DecalEditorGui.currentDecalData = %obj;
  102. %itemNum = DecalDataList.getSelectedItem();
  103. if ( %itemNum == -1 )
  104. return;
  105. %data = DecalDataList.getItemObject( %itemNum );
  106. // Update the materialEditorList
  107. $Tools::materialEditorList = %data.getId();
  108. //Canvas.pushDialog( DecalEditDlg );
  109. DecalInspector.inspect( %data );
  110. DecalEditorGui.updateDecalPreview( %data.material );
  111. }
  112. function RetargetDecalButton::onClick( %this )
  113. {
  114. %id = DecalDataList.getSelectedItem();
  115. %datablock = DecalDataList.getItemText(%id );
  116. if( !isObject(%datablock) )
  117. {
  118. MessageBoxOK("Error", "A valid Decal Template must be selected.");
  119. return;
  120. }
  121. // This is the first place IODropdown is used. The # in the function passed replaced with the output
  122. // of the preset menu.
  123. IODropdown("Retarget Decal Instances",
  124. "Retarget DecalInstances from " @ %datablock.getName() @ " over to....",
  125. "decalDataSet",
  126. "DecalEditorGui.retargetDecalDatablock(" @ %datablock.getName() @ ", #);",
  127. "");
  128. DecalEditorGui.rebuildInstanceTree();
  129. }
  130. function NewDecalButton::onClick( %this )
  131. {
  132. %name = getUniqueName( "NewDecalData" );
  133. %str = "datablock DecalData( " @ %name @ " ) { Material = \"WarningMaterial\"; };";
  134. eval( %str );
  135. DecalPMan.setDirty( %name, $decalDataFile );
  136. if ( strchr(LibraryTabControl.text, "*") $= "" )
  137. LibraryTabControl.text = LibraryTabControl.text @ "*";
  138. DecalDataList.doMirror();
  139. %id = DecalDataList.findItemText( %name );
  140. DecalDataList.setSelected( %id, true );
  141. Canvas.pushDialog( DecalEditDlg );
  142. DecalInspector.inspect( %name );
  143. }
  144. function DeleteDecalButton::onClick( %this )
  145. {
  146. if( DecalEditorTabBook.getSelectedPage() == 0 ) // library
  147. {
  148. %id = DecalDataList.getSelectedItem();
  149. %datablock = DecalDataList.getItemText(%id );
  150. MessageBoxYesNoCancel("Delete Decal Datablock?",
  151. "Are you sure you want to delete<br><br>" @ %datablock @ "<br><br> Datablock deletion won't take affect until the engine is quit.",
  152. "DecalEditorGui.deleteSelectedDecalDatablock();",
  153. "",
  154. "" );
  155. }
  156. else // instances
  157. {
  158. DecalEditorGui.deleteSelectedDecal();
  159. }
  160. }
  161. // Intended for gui use. The undo/redo functionality for deletion of datablocks
  162. // will enable itself automatically after using this function.
  163. function DecalEditorGui::deleteSelectedDecalDatablock()
  164. {
  165. %id = DecalDataList.getSelectedItem();
  166. %datablock = DecalDataList.getItemText(%id );
  167. DecalEditorGui.deleteDecalDatablock( %datablock );
  168. if( %datablock.getFilename() !$= "" )
  169. {
  170. DecalPMan.removeDirty( %datablock );
  171. DecalPMan.removeObjectFromFile( %datablock );
  172. }
  173. DecalDataList.addFilteredItem( %datablock );
  174. }
  175. function DecalEditorTabBook::onTabSelected( %this, %text, %idx )
  176. {
  177. if( %idx == 0)
  178. {
  179. DecalPreviewWindow.text = "Template Properties";
  180. DecalEditorLibraryProperties.setVisible(true);
  181. DecalEditorTemplateProperties.setVisible(false);
  182. RetargetDecalButton.setVisible( true );
  183. SaveDecalsButton.setVisible( true );
  184. NewDecalButton.setVisible( true );
  185. DeleteDecalButton.tabSelected = %idx;
  186. }
  187. else
  188. {
  189. DecalPreviewWindow.text = "Instance Properties";
  190. RetargetDecalButton.setVisible( false );
  191. NewDecalButton.setVisible( false );
  192. SaveDecalsButton.setVisible( false );
  193. DeleteDecalButton.tabSelected = %idx;
  194. DecalEditorLibraryProperties.setVisible(false);
  195. DecalEditorTemplateProperties.setVisible(true);
  196. }
  197. }
  198. function DecalEditorTreeView::onDefineIcons()
  199. {
  200. %icons = "tools/gui/images/treeview/default:" @
  201. "tools/classIcons/decal:" @
  202. "tools/classIcons/decalNode:";
  203. DecalEditorTreeView.buildIconTable( %icons );
  204. }
  205. function DecalEditorTreeView::onSelect(%this, %id)
  206. {
  207. %instanceTag = getWord( DecalEditorTreeView.getItemText(%id), 1 );
  208. if( !isObject( %instanceTag ) )
  209. return;
  210. if( %instanceTag.getClassName() !$= "DecalData" )
  211. return;
  212. // Grab the id from the tree view
  213. %decalId = getWord( DecalEditorTreeView.getItemText(%id), 0 );
  214. if( DecalEditorGui.selDecalInstanceId == %decalId )
  215. return;
  216. // Set the curent decalinstances id
  217. DecalEditorGui.selDecalInstanceId = %decalId;
  218. DecalEditorGui.selectDecal(%decalId);
  219. DecalEditorGui.syncNodeDetails(%id);
  220. }
  221. // Creating per node in the instance tree
  222. function DecalEditorTreeView::addNodeTree(%this, %nodeName, %parentName)
  223. {
  224. // If my template isnt there...put it there
  225. if ( %this.findItemByName(%parentName) == 0 )
  226. {
  227. %rootId = %this.findItemByName("<root>");
  228. %this.insertItem( %rootId, %parentName, 0, "", 1, 1);
  229. }
  230. %nodeName = %nodeName SPC %parentName;
  231. %parentId = %this.findItemByName(%parentName);
  232. %id = %this.insertItem(%parentId, %nodeName, 0, "", 2);
  233. }
  234. function DecalInspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue )
  235. {
  236. if( %fieldName $= "Material" )
  237. DecalEditorGui.updateDecalPreview( %newValue );
  238. // Same work to do as for the regular WorldEditor Inspector.
  239. Inspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue );
  240. if (%oldValue != %newValue || %oldValue !$= %newValue)
  241. %this.setDirty(%object);
  242. }
  243. function DecalInspector::setDirty( %this, %object )
  244. {
  245. DecalPMan.setDirty( %object );
  246. if ( strchr(LibraryTabControl.text, "*") $= "" )
  247. LibraryTabControl.text = LibraryTabControl.text @ "*";
  248. }
  249. function DecalInspector::removeDirty()
  250. {
  251. if ( strchr(LibraryTabControl.text, "*") !$= "" )
  252. LibraryTabControl.text = stripChars(LibraryTabControl.text, "*");
  253. }
  254. function DecalEditorGui::updateDecalPreview( %this, %material )
  255. {
  256. if( isObject( %material ) )
  257. DecalPreviewWindow-->decalPreview.setBitmap( MaterialEditorGui.searchForTexture( %material.getId(), %material.diffuseMap[0]) );
  258. else
  259. DecalPreviewWindow-->decalPreview.setBitmap("tools/materialEditor/gui/unknownImage");
  260. }
  261. function DecalEditorGui::updateInstancePreview( %this, %material )
  262. {
  263. if( isObject( %material ) )
  264. DecalPreviewWindow-->instancePreview.setBitmap( MaterialEditorGui.searchForTexture( %material.getId(), %material.diffuseMap[0]) );
  265. else
  266. DecalPreviewWindow-->instancePreview.setBitmap("tools/materialEditor/gui/unknownImage");
  267. }
  268. function DecalEditorGui::rebuildInstanceTree( %this )
  269. {
  270. // Initialize the instance tree when the tab is selected
  271. DecalEditorTreeView.removeItem(0);
  272. %rootId = DecalEditorTreeView.insertItem(0, "<root>", 0, "");
  273. %count = DecalEditorGui.getDecalCount();
  274. for (%i = 0; %i < %count; %i++)
  275. {
  276. %name = DecalEditorGui.getDecalLookupName(%i);
  277. if( %name $= "invalid" )
  278. continue;
  279. DecalEditorTreeView.addNodeTree(%i, %name);
  280. }
  281. }