main.tscript 7.7 KB

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