main.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 initializeRiverEditor()
  23. {
  24. echo(" % - Initializing River Editor");
  25. exec( "./riverEditor.cs" );
  26. exec( "./RiverEditorGui.gui" );
  27. exec( "./RiverEditorToolbar.gui" );
  28. exec( "./riverEditorGui.cs" );
  29. // Add ourselves to EditorGui, where all the other tools reside
  30. RiverEditorGui.setVisible( false );
  31. RiverEditorToolbar.setVisible(false);
  32. RiverEditorOptionsWindow.setVisible( false );
  33. RiverEditorTreeWindow.setVisible( false );
  34. EditorGui.add( RiverEditorGui );
  35. EditorGui.add( RiverEditorToolbar );
  36. EditorGui.add( RiverEditorOptionsWindow );
  37. EditorGui.add( RiverEditorTreeWindow );
  38. new ScriptObject( RiverEditorPlugin )
  39. {
  40. superClass = "EditorPlugin";
  41. editorGui = RiverEditorGui;
  42. };
  43. %map = new ActionMap();
  44. %map.bindCmd( keyboard, "backspace", "RiverEditorGui.deleteNode();", "" );
  45. %map.bindCmd( keyboard, "1", "RiverEditorGui.prepSelectionMode();", "" );
  46. %map.bindCmd( keyboard, "2", "ToolsPaletteArray->RiverEditorMoveMode.performClick();", "" );
  47. %map.bindCmd( keyboard, "3", "ToolsPaletteArray->RiverEditorRotateMode.performClick();", "" );
  48. %map.bindCmd( keyboard, "4", "ToolsPaletteArray->RiverEditorScaleMode.performClick();", "" );
  49. %map.bindCmd( keyboard, "5", "ToolsPaletteArray->RiverEditorAddRiverMode.performClick();", "" );
  50. %map.bindCmd( keyboard, "=", "ToolsPaletteArray->RiverEditorInsertPointMode.performClick();", "" );
  51. %map.bindCmd( keyboard, "numpadadd", "ToolsPaletteArray->RiverEditorInsertPointMode.performClick();", "" );
  52. %map.bindCmd( keyboard, "-", "ToolsPaletteArray->RiverEditorRemovePointMode.performClick();", "" );
  53. %map.bindCmd( keyboard, "numpadminus", "ToolsPaletteArray->RiverEditorRemovePointMode.performClick();", "" );
  54. %map.bindCmd( keyboard, "z", "RiverEditorShowSplineBtn.performClick();", "" );
  55. %map.bindCmd( keyboard, "x", "RiverEditorWireframeBtn.performClick();", "" );
  56. %map.bindCmd( keyboard, "v", "RiverEditorShowRoadBtn.performClick();", "" );
  57. RiverEditorPlugin.map = %map;
  58. RiverEditorPlugin.initSettings();
  59. }
  60. function destroyRiverEditor()
  61. {
  62. }
  63. function RiverEditorPlugin::onWorldEditorStartup( %this )
  64. {
  65. // Add ourselves to the window menu.
  66. %accel = EditorGui.addToEditorsMenu( "River Editor", "", RiverEditorPlugin );
  67. // Add ourselves to the ToolsToolbar
  68. %tooltip = "River Editor (" @ %accel @ ")";
  69. EditorGui.addToToolsToolbar( "RiverEditorPlugin", "RiverEditorPalette", expandFilename("tools/worldEditor/images/toolbar/river-editor"), %tooltip );
  70. //connect editor windows
  71. GuiWindowCtrl::attach( RiverEditorOptionsWindow, RiverEditorTreeWindow);
  72. // Add ourselves to the Editor Settings window
  73. exec( "./RiverEditorSettingsTab.gui" );
  74. ESettingsWindow.addTabPage( ERiverEditorSettingsPage );
  75. }
  76. function RiverEditorPlugin::onActivated( %this )
  77. {
  78. %this.readSettings();
  79. $River::EditorOpen = true;
  80. ToolsPaletteArray->RiverEditorAddRiverMode.performClick();
  81. EditorGui.bringToFront( RiverEditorGui );
  82. RiverEditorGui.setVisible(true);
  83. RiverEditorGui.makeFirstResponder( true );
  84. RiverEditorToolbar.setVisible(true);
  85. RiverEditorOptionsWindow.setVisible( true );
  86. RiverEditorTreeWindow.setVisible( true );
  87. RiverTreeView.open(ServerRiverSet,true);
  88. %this.map.push();
  89. // Store this on a dynamic field
  90. // in order to restore whatever setting
  91. // the user had before.
  92. %this.prevGizmoAlignment = GlobalGizmoProfile.alignment;
  93. // The DecalEditor always uses Object alignment.
  94. GlobalGizmoProfile.alignment = "Object";
  95. // Set the status bar here until all tool have been hooked up
  96. EditorGuiStatusBar.setInfo("River editor.");
  97. EditorGuiStatusBar.setSelection("");
  98. // Allow the Gui to setup.
  99. RiverEditorGui.onEditorActivated();
  100. Parent::onActivated(%this);
  101. }
  102. function RiverEditorPlugin::onDeactivated( %this )
  103. {
  104. %this.writeSettings();
  105. $River::EditorOpen = false;
  106. RiverEditorGui.setVisible(false);
  107. RiverEditorToolbar.setVisible(false);
  108. RiverEditorOptionsWindow.setVisible( false );
  109. RiverEditorTreeWindow.setVisible( false );
  110. %this.map.pop();
  111. // Restore the previous Gizmo
  112. // alignment settings.
  113. GlobalGizmoProfile.alignment = %this.prevGizmoAlignment;
  114. // Allow the Gui to cleanup.
  115. RiverEditorGui.onEditorDeactivated();
  116. Parent::onDeactivated(%this);
  117. }
  118. function RiverEditorPlugin::onEditMenuSelect( %this, %editMenu )
  119. {
  120. %hasSelection = false;
  121. if( isObject( RiverEditorGui.river ) )
  122. %hasSelection = true;
  123. %editMenu.enableItem( 3, false ); // Cut
  124. %editMenu.enableItem( 4, false ); // Copy
  125. %editMenu.enableItem( 5, false ); // Paste
  126. %editMenu.enableItem( 6, %hasSelection ); // Delete
  127. %editMenu.enableItem( 8, false ); // Deselect
  128. }
  129. function RiverEditorPlugin::handleDelete( %this )
  130. {
  131. RiverEditorGui.deleteNode();
  132. }
  133. function RiverEditorPlugin::handleEscape( %this )
  134. {
  135. return RiverEditorGui.onEscapePressed();
  136. }
  137. function RiverEditorPlugin::isDirty( %this )
  138. {
  139. return RiverEditorGui.isDirty;
  140. }
  141. function RiverEditorPlugin::onSaveMission( %this, %missionFile )
  142. {
  143. if( RiverEditorGui.isDirty )
  144. {
  145. MissionGroup.save( %missionFile );
  146. RiverEditorGui.isDirty = false;
  147. }
  148. }
  149. //-----------------------------------------------------------------------------
  150. // Settings
  151. //-----------------------------------------------------------------------------
  152. function RiverEditorPlugin::initSettings( %this )
  153. {
  154. EditorSettings.beginGroup( "RiverEditor", true );
  155. EditorSettings.setDefaultValue( "DefaultWidth", "10" );
  156. EditorSettings.setDefaultValue( "DefaultDepth", "5" );
  157. EditorSettings.setDefaultValue( "DefaultNormal", "0 0 1" );
  158. EditorSettings.setDefaultValue( "HoverSplineColor", "255 0 0 255" );
  159. EditorSettings.setDefaultValue( "SelectedSplineColor", "0 255 0 255" );
  160. EditorSettings.setDefaultValue( "HoverNodeColor", "255 255 255 255" ); //<-- Not currently used
  161. EditorSettings.endGroup();
  162. }
  163. function RiverEditorPlugin::readSettings( %this )
  164. {
  165. EditorSettings.beginGroup( "RiverEditor", true );
  166. RiverEditorGui.DefaultWidth = EditorSettings.value("DefaultWidth");
  167. RiverEditorGui.DefaultDepth = EditorSettings.value("DefaultDepth");
  168. RiverEditorGui.DefaultNormal = EditorSettings.value("DefaultNormal");
  169. RiverEditorGui.HoverSplineColor = EditorSettings.value("HoverSplineColor");
  170. RiverEditorGui.SelectedSplineColor = EditorSettings.value("SelectedSplineColor");
  171. RiverEditorGui.HoverNodeColor = EditorSettings.value("HoverNodeColor");
  172. EditorSettings.endGroup();
  173. }
  174. function RiverEditorPlugin::writeSettings( %this )
  175. {
  176. EditorSettings.beginGroup( "RiverEditor", true );
  177. EditorSettings.setValue( "DefaultWidth", RiverEditorGui.DefaultWidth );
  178. EditorSettings.setValue( "DefaultDepth", RiverEditorGui.DefaultDepth );
  179. EditorSettings.setValue( "DefaultNormal", RiverEditorGui.DefaultNormal );
  180. EditorSettings.setValue( "HoverSplineColor", RiverEditorGui.HoverSplineColor );
  181. EditorSettings.setValue( "SelectedSplineColor", RiverEditorGui.SelectedSplineColor );
  182. EditorSettings.setValue( "HoverNodeColor", RiverEditorGui.HoverNodeColor );
  183. EditorSettings.endGroup();
  184. }