main.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 = "art/decals/managedDecalData.cs";
  26. exec( "./decalEditor.cs" );
  27. exec( "./decalEditorGui.gui" );
  28. exec( "./decalEditorGui.cs" );
  29. exec( "./decalEditorActions.cs" );
  30. // Add ourselves to EditorGui, where all the other tools reside
  31. DecalEditorGui.setVisible( false );
  32. DecalPreviewWindow.setVisible( false );
  33. DecalEditorWindow.setVisible( false );
  34. EditorGui.add( DecalEditorGui );
  35. EditorGui.add( DecalEditorWindow );
  36. EditorGui.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.cs" );
  59. exec( "./decalEditor.cs" );
  60. exec( "./decalEditorGui.cs" );
  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", expandFilename("tools/decalEditor/decal-editor"), %tooltip );
  69. //connect editor windows
  70. GuiWindowCtrl::attach( DecalPreviewWindow, DecalEditorWindow );
  71. //set initial palette setting
  72. %this.paletteSelection = "AddDecalMode";
  73. }
  74. function DecalEditorPlugin::onActivated( %this )
  75. {
  76. EditorGui.bringToFront( DecalEditorGui );
  77. DecalEditorGui.setVisible( true );
  78. DecalEditorGui.makeFirstResponder( true );
  79. DecalPreviewWindow.setVisible( true );
  80. DecalEditorWindow.setVisible( true );
  81. %this.map.push();
  82. //WORKAROUND: due to the gizmo mode being stored on its profile (which may be shared),
  83. // we may end up with a mismatch between the editor mode and gizmo mode here.
  84. // Reset mode explicitly here to work around this.
  85. DecalEditorGui.setMode( DecalEditorGui.getMode() );
  86. // Set the current palette selection
  87. DecalEditorGui.paletteSync( %this.paletteSelection );
  88. // Store this on a dynamic field
  89. // in order to restore whatever setting
  90. // the user had before.
  91. %this.prevGizmoAlignment = GlobalGizmoProfile.alignment;
  92. // The DecalEditor always uses Object alignment.
  93. GlobalGizmoProfile.alignment = "Object";
  94. DecalEditorGui.rebuildInstanceTree();
  95. // These could perhaps be the node details like the shape editor
  96. //ShapeEdPropWindow.syncNodeDetails(-1);
  97. Parent::onActivated(%this);
  98. }
  99. function DecalEditorPlugin::onDeactivated( %this )
  100. {
  101. DecalEditorGui.setVisible(false);
  102. DecalPreviewWindow.setVisible( false );
  103. DecalEditorWindow.setVisible( false );
  104. %this.map.pop();
  105. // Remember last palette selection
  106. %this.paletteSelection = DecalEditorGui.getMode();
  107. // Restore the previous Gizmo
  108. // alignment settings.
  109. GlobalGizmoProfile.alignment = %this.prevGizmoAlignment;
  110. Parent::onDeactivated(%this);
  111. }
  112. function DecalEditorPlugin::isDirty( %this )
  113. {
  114. %dirty = DecalPMan.hasDirty();
  115. %dirty |= decalManagerDirty();
  116. return %dirty;
  117. }
  118. function DecalEditorPlugin::onSaveMission( %this, %file )
  119. {
  120. DecalPMan.saveDirty();
  121. decalManagerSave( %file @ ".decals" );
  122. }
  123. function DecalEditorPlugin::onEditMenuSelect( %this, %editMenu )
  124. {
  125. %hasSelection = false;
  126. if ( DecalEditorGui.getSelectionCount() > 0 )
  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, false ); // Deselect
  133. // NOTE: If you want to implement Cut, Copy, Paste, or Deselect
  134. // for this editor simply enable the menu items when it is appropriate
  135. // and fill in the method stubs below.
  136. }
  137. function DecalEditorPlugin::handleDelete( %this )
  138. {
  139. DecalEditorGui.deleteSelectedDecal();
  140. }
  141. function DecalEditorPlugin::handleDeselect( %this )
  142. {
  143. }
  144. function DecalEditorPlugin::handleCut( %this )
  145. {
  146. }
  147. function DecalEditorPlugin::handleCopy( %this )
  148. {
  149. }
  150. function DecalEditorPlugin::handlePaste( %this )
  151. {
  152. }
  153. function DecalEditorPlugin::handleEscape( %this )
  154. {
  155. }