Plugin.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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( "Path Editor", "", VPathEditorPlugin );
  33. // Add ourselves to the ToolsToolbar
  34. %tooltip = "Path Editor (" @ %accel @ ")";
  35. EditorGui.addToToolsToolbar( "VPathEditorPlugin", "VPathEditorPalette", expandFilename( "tools/VPathEditor/GUI/Images/btn_Palette" ), %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 ) + 33 ) 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. EWCreatorWindow.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. VPathEditorToolbar.setVisible( true );
  99. VPathTreeView.open( GetServerPathSet(), true );
  100. // Sync Gizmo.
  101. %this.syncGizmo();
  102. // Enable Map.
  103. %this.EditorMap.push();
  104. // Valid Selection?
  105. if ( EWorldEditor.getSelectionSize() )
  106. {
  107. %selection = EWorldEditor.getSelectedObject( 0 );
  108. if ( isObject( %selection ) && %selection.isMemberOfClass( "VPath" ) )
  109. {
  110. // Select Object.
  111. EVPathEditor.setSelection( %selection );
  112. }
  113. }
  114. // Parent Call.
  115. Parent::onActivated( %this );
  116. }
  117. function VPathEditorPlugin::onDeactivated( %this )
  118. {
  119. // Hide Editor.
  120. EVPathEditor.setVisible( false );
  121. VPathEditorToolbar.setVisible( false );
  122. // Disable Map.
  123. %this.EditorMap.pop();
  124. // Parent Call.
  125. Parent::onDeactivated( %this );
  126. }
  127. function VPathEditorPlugin::isDirty( %this )
  128. {
  129. return EVPathEditor.isDirty;
  130. }
  131. function VPathEditorPlugin::clearDirty( %this )
  132. {
  133. EVPathEditor.isDirty = false;
  134. }
  135. function VPathEditorPlugin::syncGizmo( %this )
  136. {
  137. switch$( GlobalGizmoProfile.Mode )
  138. {
  139. case "None" : EVPathEditorSelectButton.performClick();
  140. case "Move" : EVPathEditorMoveButton.performClick();
  141. case "Rotate" : EVPathEditorRotateButton.performClick();
  142. case "Scale" : EVPathEditorScaleButton.performClick();
  143. }
  144. }