main.tscript 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 initializeDecalEditor()
  23. {
  24. echo(" % - Initializing Decal Editor");
  25. $decalDataFile = "data/managedDecalData." @ $TorqueScriptFileExtension;
  26. exec( "./decalEditor." @ $TorqueScriptFileExtension );
  27. exec( "./decalEditorGui.gui" );
  28. exec( "./decalEditorGui." @ $TorqueScriptFileExtension );
  29. exec( "./decalEditorActions." @ $TorqueScriptFileExtension );
  30. // Add ourselves to EditorGui, where all the other tools reside
  31. DecalEditorGui.setVisible( false );
  32. DecalPreviewWindow.setVisible( false );
  33. DecalEditorWindow.setVisible( false );
  34. MainSceneTabPanel.add( DecalEditorGui );
  35. MainSceneTabPanel.add( DecalEditorWindow );
  36. MainSceneTabPanel.add( DecalPreviewWindow );
  37. DecalEditorTabBook.selectPage( 0 );
  38. new ScriptObject( DecalEditorPlugin )
  39. {
  40. superClass = "EditorPlugin";
  41. editorGui = DecalEditorGui;
  42. };
  43. %map = new ActionMap();
  44. %map.bindCmd( keyboard, "5", "EDecalEditorAddDecalBtn.performClick();", "" );
  45. %map.bindCmd( keyboard, "1", "EDecalEditorSelectDecalBtn.performClick();", "" );
  46. %map.bindCmd( keyboard, "2", "EDecalEditorMoveDecalBtn.performClick();", "" );
  47. %map.bindCmd( keyboard, "3", "EDecalEditorRotateDecalBtn.performClick();", "" );
  48. %map.bindCmd( keyboard, "4", "EDecalEditorScaleDecalBtn.performClick();", "" );
  49. DecalEditorPlugin.map = %map;
  50. new PersistenceManager( DecalPMan );
  51. }
  52. function destroyDecalEditor()
  53. {
  54. }
  55. // JCF: helper for during development
  56. function reinitDecalEditor()
  57. {
  58. exec( "./main." @ $TorqueScriptFileExtension );
  59. exec( "./decalEditor." @ $TorqueScriptFileExtension );
  60. exec( "./decalEditorGui." @ $TorqueScriptFileExtension );
  61. }
  62. function DecalEditorPlugin::onWorldEditorStartup( %this )
  63. {
  64. // Add ourselves to the window menu.
  65. %accel = EditorGui.addToEditorsMenu( "Decal Editor", "", DecalEditorPlugin );
  66. // Add ourselves to the ToolsToolbar
  67. %tooltip = "Decal Editor (" @ %accel @ ")";
  68. EditorGui.addToToolsToolbar( "DecalEditorPlugin", "DecalEditorPalette", "ToolsModule:decal_editor_n_image", %tooltip );
  69. //connect editor windows
  70. GuiWindowCtrl::attach( DecalPreviewWindow, DecalEditorWindow );
  71. //set initial palette setting
  72. %this.paletteSelection = "AddDecalMode";
  73. }
  74. function EditorGui::SetDecalPalletBar()
  75. {
  76. //Clears the button pallete stack
  77. EWToolsPaletteWindow.setStackCtrl(ToolsPaletteArray); //legacy ctrl adhereance
  78. EWToolsPaletteWindow.clearButtons();
  79. EWToolsPaletteWindow.setActionMap(WorldEditorInspectorPlugin.map);
  80. //Adds a button to the pallete stack
  81. //Name Icon Click Command Tooltip text Keybind
  82. EWToolsPaletteWindow.addButton("SelectDecal", "ToolsModule:arrow_n_image", "DecalEditorGui.setMode(\"SelectDecalMode\");", "", "Select Decal", "1");
  83. EWToolsPaletteWindow.addButton("MoveDecal", "ToolsModule:move_point_n_image", "DecalEditorGui.setMode(\"MoveDecalMode\");", "", "Move Decal", "2");
  84. EWToolsPaletteWindow.addButton("RotateDecal", "ToolsModule:rotate_point_n_image", "DecalEditorGui.setMode(\"RotateDecalMode\");", "", "Rotate Decal", "3");
  85. EWToolsPaletteWindow.addButton("ScaleDecal", "ToolsModule:scale_point_n_image", "DecalEditorGui.setMode(\"ScaleDecalMode\");", "", "Scale Decal", "4");
  86. EWToolsPaletteWindow.addButton("AddDecal", "ToolsModule:add_decal_n_image", "DecalEditorGui.setMode(\"AddDecalMode\");", "", "Add Decal", "5");
  87. EWToolsPaletteWindow.refresh();
  88. }
  89. function DecalEditorPlugin::onActivated( %this )
  90. {
  91. EditorGui.bringToFront( DecalEditorGui );
  92. DecalEditorGui.setVisible( true );
  93. DecalEditorGui.makeFirstResponder( true );
  94. DecalPreviewWindow.setVisible( true );
  95. DecalEditorWindow.setVisible( true );
  96. %this.map.push();
  97. //WORKAROUND: due to the gizmo mode being stored on its profile (which may be shared),
  98. // we may end up with a mismatch between the editor mode and gizmo mode here.
  99. // Reset mode explicitly here to work around this.
  100. DecalEditorGui.setMode( DecalEditorGui.getMode() );
  101. // Set the current palette selection
  102. DecalEditorGui.paletteSync( %this.paletteSelection );
  103. // Store this on a dynamic field
  104. // in order to restore whatever setting
  105. // the user had before.
  106. %this.prevGizmoAlignment = GlobalGizmoProfile.alignment;
  107. // The DecalEditor always uses Object alignment.
  108. GlobalGizmoProfile.alignment = "Object";
  109. DecalEditorGui.rebuildInstanceTree();
  110. // These could perhaps be the node details like the shape editor
  111. //ShapeEdPropWindow.syncNodeDetails(-1);
  112. Parent::onActivated(%this);
  113. EditorGui.SetDecalPalletBar();
  114. }
  115. function DecalEditorPlugin::onDeactivated( %this )
  116. {
  117. DecalEditorGui.setVisible(false);
  118. DecalPreviewWindow.setVisible( false );
  119. DecalEditorWindow.setVisible( false );
  120. %this.map.pop();
  121. // Remember last palette selection
  122. %this.paletteSelection = DecalEditorGui.getMode();
  123. // Restore the previous Gizmo
  124. // alignment settings.
  125. GlobalGizmoProfile.alignment = %this.prevGizmoAlignment;
  126. Parent::onDeactivated(%this);
  127. }
  128. function DecalEditorPlugin::isDirty( %this )
  129. {
  130. %dirty = DecalPMan.hasDirty();
  131. %dirty |= decalManagerDirty();
  132. return %dirty;
  133. }
  134. function DecalEditorPlugin::onSaveMission( %this, %file )
  135. {
  136. DecalPMan.saveDirty();
  137. decalManagerSave( %file @ ".decals" );
  138. }
  139. function DecalEditorPlugin::onEditMenuSelect( %this, %editMenu )
  140. {
  141. %hasSelection = false;
  142. if ( DecalEditorGui.getSelectionCount() > 0 )
  143. %hasSelection = true;
  144. %editMenu.enableItem( 3, false ); // Cut
  145. %editMenu.enableItem( 4, false ); // Copy
  146. %editMenu.enableItem( 5, false ); // Paste
  147. %editMenu.enableItem( 6, %hasSelection ); // Delete
  148. %editMenu.enableItem( 8, false ); // Deselect
  149. // NOTE: If you want to implement Cut, Copy, Paste, or Deselect
  150. // for this editor simply enable the menu items when it is appropriate
  151. // and fill in the method stubs below.
  152. }
  153. function DecalEditorPlugin::handleDelete( %this )
  154. {
  155. DecalEditorGui.deleteSelectedDecal();
  156. }
  157. function DecalEditorPlugin::handleDeselect( %this )
  158. {
  159. }
  160. function DecalEditorPlugin::handleCut( %this )
  161. {
  162. }
  163. function DecalEditorPlugin::handleCopy( %this )
  164. {
  165. }
  166. function DecalEditorPlugin::handlePaste( %this )
  167. {
  168. }
  169. function DecalEditorPlugin::handleEscape( %this )
  170. {
  171. }