Plugin.tscript 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) - Violent Tulip
  4. //-----------------------------------------------------------------------------
  5. new ScriptObject( VPathEditorPlugin )
  6. {
  7. SuperClass = "EditorPlugin";
  8. };
  9. //-----------------------------------------------------------------------------
  10. function VPathEditorPlugin::onWorldEditorStartup( %this )
  11. {
  12. //----------------------------------------------------------------------
  13. //
  14. // Editor Init
  15. //
  16. //----------------------------------------------------------------------
  17. EditorGui.add( EVPathEditor );
  18. EVPathEditor.setVisible( false );
  19. %this.EditorMap = new ActionMap();
  20. %this.EditorMap.bindCmd( keyboard, "backspace", "EVPathEditor.onDeleteKey();", "" );
  21. %this.EditorMap.bindCmd( keyboard, "delete", "EVPathEditor.onDeleteKey();", "" );
  22. %this.EditorMap.bindCmd( keyboard, "1", "EVPathEditorSelectButton.performClick();", "" );
  23. %this.EditorMap.bindCmd( keyboard, "2", "EVPathEditorMoveButton.performClick();", "" );
  24. %this.EditorMap.bindCmd( keyboard, "3", "EVPathEditorRotateButton.performClick();", "" );
  25. %this.EditorMap.bindCmd( keyboard, "4", "EVPathEditorScaleButton.performClick();", "" );
  26. //----------------------------------------------------------------------
  27. //
  28. // Editor Toggles
  29. //
  30. //----------------------------------------------------------------------
  31. // Add ourselves to the window menu.
  32. %accel = EditorGui.addToEditorsMenu( "Verve Path Editor", "", VPathEditorPlugin );
  33. // Add ourselves to the ToolsToolbar
  34. %tooltip = "Verve Path Editor (" @ %accel @ ")";
  35. EditorGui.addToToolsToolbar( "VPathEditorPlugin", "VPathEditorPalette", "ToolsModule:btn_VMovie_n_image", %tooltip );
  36. // Find and Store the Button.
  37. %this.ToolbarButton = ToolsToolbarArray.findObjectByInternalName( "VPathEditorPalette", false );
  38. // Extend Width.
  39. %extent = EWToolsToolbar.getExtent();
  40. EWToolsToolbar.setExtent( ( getWord( %extent, 0 ) + 32 ) SPC getWord( %extent, 1 ) );
  41. //----------------------------------------------------------------------
  42. //
  43. // Initialise Toolbar
  44. //
  45. //----------------------------------------------------------------------
  46. if ( !isObject( VPathEditorToolbar ) )
  47. {
  48. exec( "~/VPathEditor/GUI/VPathEditorToolbar.gui" );
  49. }
  50. // Add Toolbar.
  51. //EditorGuiToolbar.add( VPathEditorToolbar );
  52. // Populate Type Menu.
  53. VPathEditorToolbarPathTypeMenu.clear();
  54. VPathEditorToolbarPathTypeMenu.add( "BEZIER", 0 );
  55. VPathEditorToolbarPathTypeMenu.add( "LINEAR", 1 );
  56. VPathEditorToolbarPathTypeMenu.setFirstSelected();
  57. //----------------------------------------------------------------------
  58. //
  59. // Initialise Editor Palette
  60. //
  61. //----------------------------------------------------------------------
  62. if ( !isObject( VPathEditorPalette ) )
  63. {
  64. exec( "~/VPathEditor/GUI/VPathEditorPalette.gui" );
  65. }
  66. // Use Existing Group Number + 1.
  67. %groupNum = ToolsPaletteArray.getObject( ToolsPaletteArray.getCount() - 1 ).GroupNum + 1;
  68. %paletteGroup = VPathEditorPalette;
  69. while ( VPathEditorPalette.getCount() > 0 )
  70. {
  71. // Fetch Button.
  72. %paletteButton = %paletteGroup.getObject( 0 );
  73. // Setup.
  74. %paletteButton.Visible = false;
  75. %paletteButton.GroupNum = %groupNum;
  76. %paletteButton.PaletteName = VPathEditorPalette;
  77. // Add To Palette Array.
  78. ToolsPaletteArray.addGuiControl( %paletteButton );
  79. }
  80. //----------------------------------------------------------------------
  81. //
  82. // Initialise Library
  83. //
  84. //----------------------------------------------------------------------
  85. ObjectCreator.registerMissionObject( "VPath", "VPath", "", "Level" );
  86. }
  87. //EditorGui.setEditor(\"VPathEditorPlugin\");
  88. function VPathEditorPlugin::onActivated( %this )
  89. {
  90. if ( !isObject( EVPathEditor ) )
  91. {
  92. return;
  93. }
  94. // Display Editor.
  95. EVPathEditor.setVisible( true );
  96. EVPathEditor.makeFirstResponder( true );
  97. EditorGui.bringToFront( EVPathEditor );
  98. EditorGuiToolbarStack.remove( EWorldEditorToolbar );
  99. EditorGuiToolbarStack.add( VPathEditorToolbar );
  100. VPathTreeView.open( GetServerPathSet(), true );
  101. // Sync Gizmo.
  102. %this.syncGizmo();
  103. // Enable Map.
  104. %this.EditorMap.push();
  105. // Valid Selection?
  106. if ( EWorldEditor.getSelectionSize() )
  107. {
  108. %selection = EWorldEditor.getSelectedObject( 0 );
  109. if ( isObject( %selection ) && %selection.isMemberOfClass( "VPath" ) )
  110. {
  111. // Select Object.
  112. EVPathEditor.setSelection( %selection );
  113. }
  114. }
  115. // Parent Call.
  116. Parent::onActivated( %this );
  117. }
  118. function VPathEditorPlugin::onDeactivated( %this )
  119. {
  120. // Hide Editor.
  121. EVPathEditor.setVisible( false );
  122. EditorGuiToolbarStack.add( EWorldEditorToolbar );
  123. EditorGuiToolbarStack.remove( VPathEditorToolbar );
  124. // Disable Map.
  125. %this.EditorMap.pop();
  126. // Parent Call.
  127. Parent::onDeactivated( %this );
  128. }
  129. function VPathEditorPlugin::isDirty( %this )
  130. {
  131. return EVPathEditor.isDirty;
  132. }
  133. function VPathEditorPlugin::clearDirty( %this )
  134. {
  135. EVPathEditor.isDirty = false;
  136. }
  137. function VPathEditorPlugin::syncGizmo( %this )
  138. {
  139. switch$( GlobalGizmoProfile.Mode )
  140. {
  141. case "None" : EVPathEditorSelectButton.performClick();
  142. case "Move" : EVPathEditorMoveButton.performClick();
  143. case "Rotate" : EVPathEditorRotateButton.performClick();
  144. case "Scale" : EVPathEditorScaleButton.performClick();
  145. }
  146. }