main.tscript 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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." @ $TorqueScriptFileExtension );
  26. exec( "./RiverEditorGui.gui" );
  27. exec( "./RiverEditorToolbar.gui" );
  28. exec( "./riverEditorGui." @ $TorqueScriptFileExtension );
  29. // Add ourselves to EditorGui, where all the other tools reside
  30. RiverEditorGui.setVisible( false );
  31. RiverEditorOptionsWindow.setVisible( false );
  32. RiverEditorTreeWindow.setVisible( false );
  33. MainSceneTabPanel.add( RiverEditorGui );
  34. MainSceneTabPanel.add( RiverEditorOptionsWindow );
  35. MainSceneTabPanel.add( RiverEditorTreeWindow );
  36. new ScriptObject( RiverEditorPlugin )
  37. {
  38. superClass = "EditorPlugin";
  39. editorGui = RiverEditorGui;
  40. };
  41. %map = new ActionMap();
  42. %map.bindCmd( keyboard, "backspace", "RiverEditorGui.deleteNode();", "" );
  43. %map.bindCmd( keyboard, "1", "RiverEditorGui.prepSelectionMode();", "" );
  44. %map.bindCmd( keyboard, "2", "ToolsPaletteArray->RiverEditorMoveMode.performClick();", "" );
  45. %map.bindCmd( keyboard, "3", "ToolsPaletteArray->RiverEditorRotateMode.performClick();", "" );
  46. %map.bindCmd( keyboard, "4", "ToolsPaletteArray->RiverEditorScaleMode.performClick();", "" );
  47. %map.bindCmd( keyboard, "5", "ToolsPaletteArray->RiverEditorAddRiverMode.performClick();", "" );
  48. %map.bindCmd( keyboard, "=", "ToolsPaletteArray->RiverEditorInsertPointMode.performClick();", "" );
  49. %map.bindCmd( keyboard, "numpadadd", "ToolsPaletteArray->RiverEditorInsertPointMode.performClick();", "" );
  50. %map.bindCmd( keyboard, "-", "ToolsPaletteArray->RiverEditorRemovePointMode.performClick();", "" );
  51. %map.bindCmd( keyboard, "numpadminus", "ToolsPaletteArray->RiverEditorRemovePointMode.performClick();", "" );
  52. %map.bindCmd( keyboard, "z", "RiverEditorShowSplineBtn.performClick();", "" );
  53. %map.bindCmd( keyboard, "x", "RiverEditorWireframeBtn.performClick();", "" );
  54. %map.bindCmd( keyboard, "v", "RiverEditorShowRoadBtn.performClick();", "" );
  55. RiverEditorPlugin.map = %map;
  56. RiverEditorPlugin.initSettings();
  57. }
  58. function destroyRiverEditor()
  59. {
  60. }
  61. function RiverEditorPlugin::onWorldEditorStartup( %this )
  62. {
  63. // Add ourselves to the window menu.
  64. %accel = EditorGui.addToEditorsMenu( "River Editor", "", RiverEditorPlugin );
  65. // Add ourselves to the ToolsToolbar
  66. %tooltip = "River Editor (" @ %accel @ ")";
  67. EditorGui.addToToolsToolbar( "RiverEditorPlugin", "RiverEditorPalette", "ToolsModule:river_editor_n_image", %tooltip );
  68. //connect editor windows
  69. GuiWindowCtrl::attach( RiverEditorOptionsWindow, RiverEditorTreeWindow);
  70. // Add ourselves to the Editor Settings window
  71. exec( "./RiverEditorSettingsTab.gui" );
  72. //ESettingsWindow.addTabPage( ERiverEditorSettingsPage );
  73. ESettingsWindow.addEditorSettingsPage("RiverEditor", "River Editor");
  74. }
  75. function RiverEditorPlugin::onActivated( %this )
  76. {
  77. %this.readSettings();
  78. $River::EditorOpen = true;
  79. ToolsPaletteArray->RiverEditorAddRiverMode.performClick();
  80. EditorGui.bringToFront( RiverEditorGui );
  81. RiverEditorGui.setVisible(true);
  82. RiverEditorGui.makeFirstResponder( true );
  83. EditorGuiToolbarStack.remove( EWorldEditorToolbar );
  84. EditorGuiToolbarStack.add( RiverEditorToolbar );
  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. EditorGuiToolbarStack.add( EWorldEditorToolbar );
  108. EditorGuiToolbarStack.remove( RiverEditorToolbar );
  109. RiverEditorOptionsWindow.setVisible( false );
  110. RiverEditorTreeWindow.setVisible( false );
  111. %this.map.pop();
  112. // Restore the previous Gizmo
  113. // alignment settings.
  114. GlobalGizmoProfile.alignment = %this.prevGizmoAlignment;
  115. // Allow the Gui to cleanup.
  116. RiverEditorGui.onEditorDeactivated();
  117. Parent::onDeactivated(%this);
  118. }
  119. function RiverEditorPlugin::onEditMenuSelect( %this, %editMenu )
  120. {
  121. %hasSelection = false;
  122. if( isObject( RiverEditorGui.river ) )
  123. %hasSelection = true;
  124. %editMenu.enableItem( 3, false ); // Cut
  125. %editMenu.enableItem( 4, false ); // Copy
  126. %editMenu.enableItem( 5, false ); // Paste
  127. %editMenu.enableItem( 6, %hasSelection ); // Delete
  128. %editMenu.enableItem( 8, false ); // Deselect
  129. }
  130. function RiverEditorPlugin::handleDelete( %this )
  131. {
  132. RiverEditorGui.deleteNode();
  133. }
  134. function RiverEditorPlugin::handleEscape( %this )
  135. {
  136. return RiverEditorGui.onEscapePressed();
  137. }
  138. function RiverEditorPlugin::isDirty( %this )
  139. {
  140. return RiverEditorGui.isDirty;
  141. }
  142. function RiverEditorPlugin::onSaveMission( %this, %missionFile )
  143. {
  144. if( RiverEditorGui.isDirty )
  145. {
  146. //Get our root scene, which would be the level
  147. getScene(0).save( %missionFile );
  148. RiverEditorGui.isDirty = false;
  149. }
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Settings
  153. //-----------------------------------------------------------------------------
  154. function RiverEditorPlugin::initSettings( %this )
  155. {
  156. EditorSettings.beginGroup( "RiverEditor", true );
  157. EditorSettings.setDefaultValue( "DefaultWidth", "10" );
  158. EditorSettings.setDefaultValue( "DefaultDepth", "5" );
  159. EditorSettings.setDefaultValue( "DefaultNormal", "0 0 1" );
  160. EditorSettings.setDefaultValue( "HoverSplineColor", "255 0 0 255" );
  161. EditorSettings.setDefaultValue( "SelectedSplineColor", "0 255 0 255" );
  162. EditorSettings.setDefaultValue( "HoverNodeColor", "255 255 255 255" ); //<-- Not currently used
  163. EditorSettings.endGroup();
  164. }
  165. function RiverEditorPlugin::readSettings( %this )
  166. {
  167. EditorSettings.beginGroup( "RiverEditor", true );
  168. RiverEditorGui.DefaultWidth = EditorSettings.value("DefaultWidth");
  169. RiverEditorGui.DefaultDepth = EditorSettings.value("DefaultDepth");
  170. RiverEditorGui.DefaultNormal = EditorSettings.value("DefaultNormal");
  171. RiverEditorGui.HoverSplineColor = EditorSettings.value("HoverSplineColor");
  172. RiverEditorGui.SelectedSplineColor = EditorSettings.value("SelectedSplineColor");
  173. RiverEditorGui.HoverNodeColor = EditorSettings.value("HoverNodeColor");
  174. EditorSettings.endGroup();
  175. }
  176. function RiverEditorPlugin::writeSettings( %this )
  177. {
  178. EditorSettings.beginGroup( "RiverEditor", true );
  179. EditorSettings.setValue( "DefaultWidth", RiverEditorGui.DefaultWidth );
  180. EditorSettings.setValue( "DefaultDepth", RiverEditorGui.DefaultDepth );
  181. EditorSettings.setValue( "DefaultNormal", RiverEditorGui.DefaultNormal );
  182. EditorSettings.setValue( "HoverSplineColor", RiverEditorGui.HoverSplineColor );
  183. EditorSettings.setValue( "SelectedSplineColor", RiverEditorGui.SelectedSplineColor );
  184. EditorSettings.setValue( "HoverNodeColor", RiverEditorGui.HoverNodeColor );
  185. EditorSettings.endGroup();
  186. }