main.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. // Initialization and shutdown code for particle editor plugin.
  23. //---------------------------------------------------------------------------------------------
  24. function initializeParticleEditor()
  25. {
  26. echo( " % - Initializing Particle Editor" );
  27. exec( "./ParticleEditor.ed.gui" );
  28. exec( "./particleEditor.ed.cs" );
  29. exec( "./particleEditorUndo.ed.cs" );
  30. exec( "./particleEmitterEditor.ed.cs" );
  31. exec( "./particleParticleEditor.ed.cs" );
  32. PE_Window.setVisible( false );
  33. EditorGui.add( PE_Window );
  34. new ScriptObject( ParticleEditorPlugin )
  35. {
  36. superClass = "WorldEditorPlugin";
  37. editorGui = EWorldEditor;
  38. };
  39. %map = new ActionMap();
  40. %map.bindCmd( keyboard, "1", "EWorldEditorNoneModeBtn.performClick();", "" ); // Select
  41. %map.bindCmd( keyboard, "2", "EWorldEditorMoveModeBtn.performClick();", "" ); // Move
  42. %map.bindCmd( keyboard, "3", "EWorldEditorRotateModeBtn.performClick();", "" ); // Rotate
  43. %map.bindCmd( keyboard, "4", "EWorldEditorScaleModeBtn.performClick();", "" ); // Scale
  44. ParticleEditorPlugin.map = %map;
  45. new ScriptObject( ParticleEditor );
  46. new PersistenceManager( PE_EmitterSaver );
  47. new PersistenceManager( PE_ParticleSaver );
  48. new SimSet( PE_UnlistedParticles );
  49. new SimSet( PE_UnlistedEmitters );
  50. }
  51. //---------------------------------------------------------------------------------------------
  52. function destroyParticleEditor()
  53. {
  54. }
  55. //=============================================================================================
  56. // ParticleEditorPlugin.
  57. //=============================================================================================
  58. //---------------------------------------------------------------------------------------------
  59. function ParticleEditorPlugin::onWorldEditorStartup( %this )
  60. {
  61. // Add ourselves to the window menu.
  62. %accel = EditorGui.addToEditorsMenu( "Particle Editor", "", ParticleEditorPlugin );
  63. // Add ourselves to the ToolsToolbar
  64. %tooltip = "Particle Editor (" @ %accel @ ")";
  65. EditorGui.addToToolsToolbar( "ParticleEditorPlugin", "ParticleEditorPalette", expandFilename("tools/worldEditor/images/toolbar/particleeditor"), %tooltip );
  66. }
  67. //---------------------------------------------------------------------------------------------
  68. function ParticleEditorPlugin::onActivated( %this )
  69. {
  70. if( !ParticleEditor.isInitialized )
  71. {
  72. ParticleEditor.initEditor();
  73. ParticleEditor.isInitialized = true;
  74. }
  75. EditorGui-->WorldEditorToolbar.setVisible( true );
  76. EditorGui.bringToFront( PE_Window);
  77. PE_Window.setVisible( true );
  78. PE_Window.makeFirstResponder( true );
  79. %this.map.push();
  80. ParticleEditor.resetEmitterNode();
  81. // Set the status bar here
  82. EditorGuiStatusBar.setInfo( "Particle editor." );
  83. EditorGuiStatusBar.setSelection( "" );
  84. Parent::onActivated( %this );
  85. }
  86. //---------------------------------------------------------------------------------------------
  87. function ParticleEditorPlugin::onDeactivated( %this )
  88. {
  89. EditorGui-->WorldEditorToolbar.setVisible( false );
  90. PE_Window.setVisible( false );
  91. if( isObject( $ParticleEditor::emitterNode) )
  92. $ParticleEditor::emitterNode.delete();
  93. %this.map.pop();
  94. Parent::onDeactivated( %this );
  95. }
  96. //---------------------------------------------------------------------------------------------
  97. function ParticleEditorPlugin::onExitMission( %this )
  98. {
  99. // Force Particle Editor to re-initialize.
  100. ParticleEditor.isInitialized = false;
  101. Parent::onExitMission( %this );
  102. }
  103. //---------------------------------------------------------------------------------------------
  104. function ParticleEditorPlugin::initSettings( %this )
  105. {
  106. EditorSettings.beginGroup( "ParticleEditor", true );
  107. EditorSettings.setDefaultValue( "selectedTab", 0 );
  108. EditorSettings.endGroup();
  109. }
  110. //---------------------------------------------------------------------------------------------
  111. function ParticleEditorPlugin::readSettings( %this )
  112. {
  113. EditorSettings.beginGroup( "ParticleEditor", true );
  114. %selectedEmitter = EditorSettings.value( "selectedEmitter" );
  115. if( isObject( %selectedEmitter ) )
  116. PEE_EmitterSelector.setSelected( %selectedEmitter.getId() );
  117. %selectedParticle = EditorSettings.value( "selectedParticle" );
  118. if( isObject( %selectedParticle ) )
  119. PEP_ParticleSelector.setSelected( %selectedParticle.getId() );
  120. PE_TabBook.selectPage( EditorSettings.value( "selectedPage" ) );
  121. EditorSettings.endGroup();
  122. }
  123. //---------------------------------------------------------------------------------------------
  124. function ParticleEditorPlugin::writeSettings( %this )
  125. {
  126. EditorSettings.beginGroup( "ParticleEditor", true );
  127. EditorSettings.setValue( "selectedEmitter", PEE_EmitterSelector.getText() );
  128. EditorSettings.setValue( "selectedParticle", PEP_ParticleSelector.getText() );
  129. EditorSettings.setValue( "selectedTab", PE_TabBook.getSelectedPage() );
  130. EditorSettings.endGroup();
  131. }