main.tscript 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 initializeConvexEditor()
  23. {
  24. echo(" % - Initializing Sketch Tool");
  25. exec( "./convexEditor." @ $TorqueScriptFileExtension );
  26. exec( "./convexEditorGui.gui" );
  27. exec( "./convexEditorToolbar.ed.gui" );
  28. exec( "./convexEditorGui." @ $TorqueScriptFileExtension );
  29. exec( "./convexEditorSidebarGui.gui" );
  30. ConvexEditorGui.setVisible( false );
  31. ConvexEditorOptionsWindow.setVisible( false );
  32. ConvexEditorTreeWindow.setVisible( false );
  33. ConvexEditorOptionsWindow.setVisible( false );
  34. MainSceneTabPanel.add( ConvexEditorGui );
  35. MainSceneTabPanel.add( ConvexEditorOptionsWindow );
  36. MainSceneTabPanel.add( ConvexEditorTreeWindow );
  37. MainSceneTabPanel.add( ConvexEditorOptionsWindow );
  38. new ScriptObject( ConvexEditorPlugin )
  39. {
  40. superClass = "EditorPlugin";
  41. editorGui = ConvexEditorGui;
  42. };
  43. // Note that we use the WorldEditor's Toolbar.
  44. %map = new ActionMap();
  45. %map.bindCmd( keyboard, "1", "ConvexEditorNoneModeBtn.performClick();", "" ); // Select
  46. %map.bindCmd( keyboard, "2", "ConvexEditorMoveModeBtn.performClick();", "" ); // Move
  47. %map.bindCmd( keyboard, "3", "ConvexEditorRotateModeBtn.performClick();", "" );// Rotate
  48. %map.bindCmd( keyboard, "4", "ConvexEditorScaleModeBtn.performClick();", "" ); // Scale
  49. ConvexEditorPlugin.map = %map;
  50. ConvexEditorPlugin.initSettings();
  51. }
  52. function ConvexEditorPlugin::onWorldEditorStartup( %this )
  53. {
  54. // Add ourselves to the window menu.
  55. %accel = EditorGui.addToEditorsMenu( "Sketch Tool", "", ConvexEditorPlugin );
  56. // Add ourselves to the ToolsToolbar
  57. %tooltip = "Sketch Tool (" @ %accel @ ")";
  58. EditorGui.addToToolsToolbar( "ConvexEditorPlugin", "ConvexEditorPalette", "ToolsModule:convex_editor_btn_n_image", %tooltip );
  59. //connect editor windows
  60. GuiWindowCtrl::attach( ConvexEditorOptionsWindow, ConvexEditorTreeWindow);
  61. // Allocate our special menu.
  62. // It will be added/removed when this editor is activated/deactivated.
  63. if ( !isObject( ConvexActionsMenu ) )
  64. {
  65. singleton PopupMenu( ConvexActionsMenu )
  66. {
  67. superClass = "MenuBuilder";
  68. barTitle = "Sketch";
  69. Item[0] = "Hollow Selected Shape" TAB "" TAB "ConvexEditorGui.hollowSelection();";
  70. item[1] = "Recenter Selected Shape" TAB "" TAB "ConvexEditorGui.recenterSelection();";
  71. };
  72. }
  73. %this.popupMenu = ConvexActionsMenu;
  74. exec( "./convexEditorSettingsTab.ed.gui" );
  75. //ESettingsWindow.addTabPage( EConvexEditorSettingsPage );
  76. ESettingsWindow.addEditorSettingsPage("ConvexEditor", "Convex Editor");
  77. }
  78. function ConvexEditorPlugin::onActivated( %this )
  79. {
  80. %this.readSettings();
  81. EditorGui.bringToFront( ConvexEditorGui );
  82. ConvexEditorGui.setVisible( true );
  83. EditorGuiToolbarStack.remove( EWorldEditorToolbar );
  84. EditorGuiToolbarStack.add( ConvexEditorToolbar );
  85. ConvexEditorOptionsWindow.setVisible( true );
  86. ConvexEditorGui.makeFirstResponder( true );
  87. %this.map.push();
  88. // Set the status bar here until all tool have been hooked up
  89. EditorGuiStatusBar.setInfo( "Sketch Tool." );
  90. EditorGuiStatusBar.setSelection( "" );
  91. // Add our menu.
  92. EditorGui.menuBar.insert( ConvexActionsMenu, EditorGui.menuBar.dynamicItemInsertPos );
  93. // Sync the pallete button state with the gizmo mode.
  94. %mode = GlobalGizmoProfile.mode;
  95. switch$ (%mode)
  96. {
  97. case "None":
  98. ConvexEditorNoneModeBtn.performClick();
  99. case "Move":
  100. ConvexEditorMoveModeBtn.performClick();
  101. case "Rotate":
  102. ConvexEditorRotateModeBtn.performClick();
  103. case "Scale":
  104. ConvexEditorScaleModeBtn.performClick();
  105. }
  106. EWorldEditor.UseGridSnap = EditorSettings.value("WorldEditor/Tools/UseGridSnap");
  107. CESnapOptions-->objectGridSnapBtn.setStateOn( EWorldEditor.UseGridSnap );
  108. %this.setGridSnap( EWorldEditor.UseGridSnap );
  109. Parent::onActivated( %this );
  110. EditorGui.SetStandardPalletBar();
  111. }
  112. function ConvexEditorPlugin::onDeactivated( %this )
  113. {
  114. %this.writeSettings();
  115. ConvexEditorGui.setVisible( false );
  116. EditorGuiToolbarStack.add( EWorldEditorToolbar );
  117. EditorGuiToolbarStack.remove( ConvexEditorToolbar );
  118. ConvexEditorTreeWindow.setVisible( false );
  119. ConvexEditorOptionsWindow.setVisible( false );
  120. %this.map.pop();
  121. // Remove our menu.
  122. EditorGui.menuBar.remove( ConvexActionsMenu );
  123. Parent::onDeactivated( %this );
  124. }
  125. function ConvexEditorPlugin::onEditMenuSelect( %this, %editMenu )
  126. {
  127. %hasSelection = false;
  128. if ( ConvexEditorGui.hasSelection() )
  129. %hasSelection = true;
  130. %editMenu.enableItem( 3, false ); // Cut
  131. %editMenu.enableItem( 4, false ); // Copy
  132. %editMenu.enableItem( 5, false ); // Paste
  133. %editMenu.enableItem( 6, %hasSelection ); // Delete
  134. %editMenu.enableItem( 8, %hasSelection ); // Deselect
  135. }
  136. function ConvexEditorPlugin::handleDelete( %this )
  137. {
  138. ConvexEditorGui.handleDelete();
  139. }
  140. function ConvexEditorPlugin::handleDeselect( %this )
  141. {
  142. ConvexEditorGui.handleDeselect();
  143. }
  144. function ConvexEditorPlugin::handleCut( %this )
  145. {
  146. //WorldEditorInspectorPlugin.handleCut();
  147. }
  148. function ConvexEditorPlugin::handleCopy( %this )
  149. {
  150. //WorldEditorInspectorPlugin.handleCopy();
  151. }
  152. function ConvexEditorPlugin::handlePaste( %this )
  153. {
  154. //WorldEditorInspectorPlugin.handlePaste();
  155. }
  156. function ConvexEditorPlugin::isDirty( %this )
  157. {
  158. return ConvexEditorGui.isDirty;
  159. }
  160. function ConvexEditorPlugin::onSaveMission( %this, %missionFile )
  161. {
  162. if( ConvexEditorGui.isDirty )
  163. {
  164. getScene(0).save( %missionFile );
  165. ConvexEditorGui.isDirty = false;
  166. }
  167. }
  168. //-----------------------------------------------------------------------------
  169. // Settings
  170. //-----------------------------------------------------------------------------
  171. function ConvexEditorPlugin::initSettings( %this )
  172. {
  173. EditorSettings.beginGroup( "ConvexEditor", true );
  174. EditorSettings.setDefaultValue( "MaterialName", "Prototyping:WallOrange" );
  175. EditorSettings.endGroup();
  176. }
  177. function ESettingsWindow::getConvexEditorSettings(%this)
  178. {
  179. SettingsInspector.startGroup("General");
  180. SettingsInspector.addSettingsField("ConvexEditor/MaterialName", "Default Material Asset Name", "TypeMaterialAssetId", "");
  181. SettingsInspector.endGroup();
  182. }
  183. function ConvexEditorPlugin::readSettings( %this )
  184. {
  185. EditorSettings.beginGroup( "ConvexEditor", true );
  186. ConvexEditorGui.materialName = EditorSettings.value("MaterialName");
  187. EditorSettings.endGroup();
  188. }
  189. function ConvexEditorPlugin::writeSettings( %this )
  190. {
  191. EditorSettings.beginGroup( "ConvexEditor", true );
  192. EditorSettings.setValue( "MaterialName", ConvexEditorGui.materialName );
  193. EditorSettings.endGroup();
  194. }