inspector.ed.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. // Functionality that allows all editor inspectors to share certain functionality.
  23. //---------------------------------------------------------------------------------------------
  24. function EditorInspectorBase::onAdd( %this )
  25. {
  26. if( !isObject( EditorInspectorBaseDatablockFieldPopup ) )
  27. new PopupMenu( EditorInspectorBaseDatablockFieldPopup )
  28. {
  29. superClass = "MenuBuilder";
  30. isPopup = true;
  31. item[ 0 ] = "Edit Datablock" TAB "" TAB "DatablockEditorPlugin.openDatablock( %this.inspectorField.getData() );";
  32. Item[ 1 ] = "Jump to Definition in Torsion" TAB "" TAB "EditorOpenDeclarationInTorsion( %this.inspectorField.getData() );";
  33. item[ 2 ] = "Inspect Object" TAB "" TAB "inspectObject( %this.inspectorField.getData() );";
  34. item[ 3 ] = "-";
  35. item[ 4 ] = "Copy Value" TAB "" TAB "setClipboard( %this.inspectorField.getData() );";
  36. item[ 5 ] = "Paste Value" TAB "" TAB "%this.inspectorField.apply( getClipboard() );";
  37. item[ 6 ] = "Reset to Default" TAB "" TAB "%this.inspectorField.reset();";
  38. inspectorField = -1;
  39. };
  40. if( !isObject( EditorInspectorBaseFieldPopup ) )
  41. new PopupMenu( EditorInspectorBaseFieldPopup )
  42. {
  43. superClass = "MenuBuilder";
  44. isPopup = true;
  45. item[ 0 ] = "Inspect Object" TAB "" TAB "inspectObject( %this.inspectorField.getData() );";
  46. Item[ 1 ] = "Jump to Definition in Torsion" TAB "" TAB "EditorOpenDeclarationInTorsion( %this.inspectorField.getData() );";
  47. item[ 2 ] = "-";
  48. item[ 3 ] = "Copy Value" TAB "" TAB "setClipboard( %this.inspectorField.getData() );";
  49. item[ 4 ] = "Paste Value" TAB "" TAB "%this.inspectorField.apply( getClipboard() );";
  50. item[ 5 ] = "Reset to Default" TAB "" TAB "%this.inspectorField.reset();";
  51. inspectorField = -1;
  52. };
  53. if( !isObject( EditorInspectorBaseFileFieldPopup ) )
  54. new PopupMenu( EditorInspectorBaseFileFieldPopup )
  55. {
  56. superClass = "MenuBuilder";
  57. isPopup = true;
  58. item[ 0 ] = "Open File" TAB "" TAB "openFile( %this.filePath );";
  59. item[ 1 ] = "Open Folder" TAB "" TAB "openFolder( %this.folderPath );";
  60. item[ 2 ] = "-";
  61. item[ 3 ] = "Copy Value" TAB "" TAB "setClipboard( %this.inspectorField.getData() );";
  62. item[ 4 ] = "Paste Value" TAB "" TAB "%this.inspectorField.apply( getClipboard() );";
  63. item[ 5 ] = "Reset to Default" TAB "" TAB "%this.inspectorField.reset();";
  64. inspectorField = -1;
  65. folderPath = "";
  66. filePath = "";
  67. };
  68. if( !isObject( EditorInspectorBaseShapeFieldPopup ) )
  69. new PopupMenu( EditorInspectorBaseShapeFieldPopup )
  70. {
  71. superClass = "MenuBuilder";
  72. isPopup = true;
  73. item[ 0 ] = "Edit Shape" TAB "" TAB "ShapeEditorPlugin.openShape( %this.inspectorField.getData() );";
  74. item[ 1 ] = "-";
  75. item[ 2 ] = "Open File" TAB "" TAB "openFile( %this.filePath );";
  76. item[ 3 ] = "Open Folder" TAB "" TAB "openFolder( %this.folderPath );";
  77. item[ 4 ] = "-";
  78. item[ 5 ] = "Copy Value" TAB "" TAB "setClipboard( %this.inspectorField.getData() );";
  79. item[ 6 ] = "Paste Value" TAB "" TAB "%this.inspectorField.apply( getClipboard() );";
  80. item[ 7 ] = "Reset to Default" TAB "" TAB "%this.inspectorField.reset();";
  81. inspectorField = -1;
  82. folderPath = "";
  83. filePath = "";
  84. };
  85. if( !isObject( EditorInspectorBaseProfileFieldPopup ) )
  86. new PopupMenu( EditorInspectorBaseProfileFieldPopup )
  87. {
  88. superClass = "MenuBuilder";
  89. isPopup = true;
  90. item[ 0 ] = "Edit Profile" TAB "" TAB "if( !GuiEditorIsActive() ) toggleGuiEditor( true ); GuiEditor.editProfile( %this.inspectorField.getData() );";
  91. item[ 1 ] = "Jump to Definition in Torsion" TAB "" TAB "EditorOpenDeclarationInTorsion( %this.inspectorField.getData() );";
  92. item[ 2 ] = "Inspect Object" TAB "" TAB "inspectObject( %this.inspectorField.getData() );";
  93. item[ 3 ] = "-";
  94. item[ 4 ] = "Copy Value" TAB "" TAB "setClipboard( %this.inspectorField.getData() );";
  95. item[ 5 ] = "Paste Value" TAB "" TAB "%this.inspectorField.apply( getClipboard() );";
  96. item[ 6 ] = "Reset to Default" TAB "" TAB "%this.inspectorField.reset();";
  97. inspectorField = -1;
  98. folderPath = "";
  99. filePath = "";
  100. };
  101. }
  102. //---------------------------------------------------------------------------------------------
  103. function EditorInspectorBase::onFieldRightClick( %this, %field )
  104. {
  105. %obj = %this.getInspectObject();
  106. %fieldValue = %field.getData();
  107. %inspectIndex = -1;
  108. %openFileIndex = -1;
  109. %openFolderIndex = -1;
  110. // Find out if this is a TypeFilename field referring to a shape file.
  111. %isShapeFilenameField = false;
  112. if( %field.getInspectedFieldName() $= "shapeName" )
  113. {
  114. %isShapeFilenameField =
  115. %obj.isMemberOfClass( "PhysicsShape" ) ||
  116. %obj.isMemberOfClass( "TSStatic" );
  117. }
  118. else if( %field.getInspectedFieldName() $= "shapeFile" )
  119. {
  120. %isShapeFilenameField =
  121. %obj.isMemberOfClass( "ShapeBaseData" ) ||
  122. %obj.isMemberOfClass( "ShapeBaseImageData" ) ||
  123. %obj.isMemberOfClass( "ForestItemData" ) ||
  124. %obj.isMemberOfClass( "WheeledVehicleTire" ) ||
  125. %obj.isMemberOfClass( "fxShapeReplicator" ) ||
  126. %obj.isMemberOfClass( "RenderShapeExample" ) ||
  127. %obj.isMemberOfClass( "DebrisData" );
  128. }
  129. // Select the popup.
  130. if( %isShapeFilenameField )
  131. {
  132. %popup = EditorInspectorBaseShapeFieldPopup;
  133. %openFileIndex = 2;
  134. %openFolderIndex = 3;
  135. }
  136. else if( EditorInspectorBase::isFileTypeField( %field ) )
  137. {
  138. %popup = EditorInspectorBaseFileFieldPopup;
  139. %openFileIndex = 0;
  140. %openFolderIndex = 1;
  141. }
  142. else
  143. {
  144. switch$( %field.getClassName() )
  145. {
  146. case "GuiInspectorCustomField":
  147. if( %field.getInspectedFieldName() !$= "parentGroup" )
  148. return;
  149. case "GuiInspectorTypeGuiProfile":
  150. %popup = EditorInspectorBaseProfileFieldPopup;
  151. %popup.enableItem( 0, isObject( %fieldValue ) );
  152. %inspectIndex = 2;
  153. %jumpToIndex = 1;
  154. case "GuiInspectorDatablockField" or
  155. "GuiInspectorTypeSFXDescriptionName" or
  156. "GuiInspectorTypeSFXEnvironmentName" or
  157. "GuiInspectorTypeSFXTrackName" or
  158. "GuiInspectorTypeSFXAmbienceName" or
  159. "GuiInspectorTypeSFXSourceName":
  160. %popup = EditorInspectorBaseDatablockFieldPopup;
  161. %popup.enableItem( 0, isObject( %fieldValue ) );
  162. %inspectIndex = 2;
  163. %jumpToIndex = 1;
  164. default:
  165. %popup = EditorInspectorBaseFieldPopup;
  166. %inspectIndex = 0;
  167. %jumpToIndex = 1;
  168. }
  169. }
  170. if( %inspectIndex != -1 )
  171. {
  172. %isObject = false;
  173. if( EditorInspectorBase::isObjectTypeField( %field ) )
  174. %isObject = isObject( %fieldValue );
  175. %popup.enableItem( %inspectIndex, %isObject );
  176. %popup.enableItem( %jumpToIndex, %isObject );
  177. }
  178. if( %openFileIndex != -1 || %openFolderIndex != -1 )
  179. {
  180. %fullPath = EditorInspectorBase::getFullFilePath( %field );
  181. %popup.filePath = %fullPath;
  182. %popup.folderPath = filePath( %fullPath );
  183. if( %openFileIndex != -1 )
  184. %popup.enableItem( 0, isFile( %fullPath ) );
  185. if( %openFolderIndex != -1 )
  186. %popup.enableItem( 1, isDirectory( %popup.folderPath ) );
  187. }
  188. %popup.inspectorField = %field;
  189. %popup.showPopup( Canvas );
  190. }
  191. //---------------------------------------------------------------------------------------------
  192. function EditorInspectorBase::isObjectTypeField( %field )
  193. {
  194. // Inspector field types that refer to objects.
  195. switch$( %field.getClassName() )
  196. {
  197. case "GuiInspectorDatablockField" or
  198. "GuiInspectorTypeSFXDescriptionName" or
  199. "GuiInspectorTypeSFXEnvironmentName" or
  200. "GuiInspectorTypeSFXTrackName" or
  201. "GuiInspectorTypeSFXAmbienceName" or
  202. "GuiInspectorTypeSFXSourceName" or
  203. "GuiInspectorTypeGuiProfile":
  204. return true;
  205. }
  206. // Other console types that refer to objects.
  207. switch$( %field.getInspectedFieldType() )
  208. {
  209. case "TypeSimObject" or
  210. "TypeSimObjectName" or
  211. "TypeMaterialName" or
  212. "TypeCubemapName" or
  213. "TypeGuiProfile":
  214. return true;
  215. }
  216. return false;
  217. }
  218. //---------------------------------------------------------------------------------------------
  219. function EditorInspectorBase::isFileTypeField( %field )
  220. {
  221. return %field.isMemberOfClass( "GuiInspectorTypeFileName" );
  222. }
  223. //---------------------------------------------------------------------------------------------
  224. function EditorInspectorBase::getFullFilePath( %field )
  225. {
  226. %fileName = %field.getData();
  227. %inspector = %field.getInspector();
  228. %object = %inspector.getInspectObject();
  229. if( %object.isMemberOfClass( "Material" ) )
  230. {
  231. // Image filenames in materials are relative to the material's file.
  232. %objectPath = filePath( makeFullPath( %object.getFilename(), getMainDotCsDir() ) );
  233. return makeFullPath( %fileName, %objectPath );
  234. }
  235. else
  236. return makeFullPath( %fileName, getMainDotCsDir() );
  237. }