main.cs 7.1 KB

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