main.tscript 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 EditorGui::SetRiverPalletBar()
  76. {
  77. //Clears the button pallete stack
  78. EWToolsPaletteWindow.setStackCtrl(ToolsPaletteArray); //legacy ctrl adhereance
  79. EWToolsPaletteWindow.clearButtons();
  80. EWToolsPaletteWindow.setActionMap(WorldEditorInspectorPlugin.map);
  81. //Adds a button to the pallete stack
  82. //Name Icon Click Command Tooltip text Keybind
  83. EWToolsPaletteWindow.addButton("Select", "ToolsModule:arrow_n_image", "RiverEditorGui.prepSelectionMode();", "", "Select River", "1");
  84. EWToolsPaletteWindow.addButton("MovePoint", "ToolsModule:move_point_n_image", "RiverEditorGui.setMode(\"RiverEditorMoveMode\");", "", "Move Point", "2");
  85. EWToolsPaletteWindow.addButton("RotatePoint", "ToolsModule:rotate_point_n_image", "RiverEditorGui.setMode(\"RiverEditorRotateMode\");", "", "Rotate Point", "3");
  86. EWToolsPaletteWindow.addButton("ScalePoint", "ToolsModule:scale_point_n_image", "RiverEditorGui.setMode(\"RiverEditorScaleMode\");", "", "Scale Point", "4");
  87. EWToolsPaletteWindow.addButton("AddRoad", "ToolsModule:add_road_path_n_image", "RiverEditorGui.setMode(\"RiverEditorAddRiverMode\");", "", "Add River", "5");
  88. EWToolsPaletteWindow.addButton("InsertPoint", "ToolsModule:add_point_n_image", "RiverEditorGui.setMode(\"RiverEditorInsertPointMode\");", "", "Insert Point", "+");
  89. EWToolsPaletteWindow.addButton("RemovePoint", "ToolsModule:subtract_point_n_image", "RiverEditorGui.setMode(\"RiverEditorRemovePointMode\");", "", "Remove Point", "-");
  90. EWToolsPaletteWindow.refresh();
  91. }
  92. function RiverEditorPlugin::onActivated( %this )
  93. {
  94. %this.readSettings();
  95. $River::EditorOpen = true;
  96. ToolsPaletteArray->RiverEditorAddRiverMode.performClick();
  97. EditorGui.bringToFront( RiverEditorGui );
  98. RiverEditorGui.setVisible(true);
  99. RiverEditorGui.makeFirstResponder( true );
  100. EditorGuiToolbarStack.remove( EWorldEditorToolbar );
  101. EditorGuiToolbarStack.add( RiverEditorToolbar );
  102. RiverEditorOptionsWindow.setVisible( true );
  103. RiverEditorTreeWindow.setVisible( true );
  104. RiverTreeView.open(ServerRiverSet,true);
  105. %this.map.push();
  106. // Store this on a dynamic field
  107. // in order to restore whatever setting
  108. // the user had before.
  109. %this.prevGizmoAlignment = GlobalGizmoProfile.alignment;
  110. // The DecalEditor always uses Object alignment.
  111. GlobalGizmoProfile.alignment = "Object";
  112. // Set the status bar here until all tool have been hooked up
  113. EditorGuiStatusBar.setInfo("River editor.");
  114. EditorGuiStatusBar.setSelection("");
  115. // Allow the Gui to setup.
  116. RiverEditorGui.onEditorActivated();
  117. Parent::onActivated(%this);
  118. EditorGui.SetRiverPalletBar();
  119. }
  120. function RiverEditorPlugin::onDeactivated( %this )
  121. {
  122. %this.writeSettings();
  123. $River::EditorOpen = false;
  124. RiverEditorGui.setVisible(false);
  125. EditorGuiToolbarStack.add( EWorldEditorToolbar );
  126. EditorGuiToolbarStack.remove( RiverEditorToolbar );
  127. RiverEditorOptionsWindow.setVisible( false );
  128. RiverEditorTreeWindow.setVisible( false );
  129. %this.map.pop();
  130. // Restore the previous Gizmo
  131. // alignment settings.
  132. GlobalGizmoProfile.alignment = %this.prevGizmoAlignment;
  133. // Allow the Gui to cleanup.
  134. RiverEditorGui.onEditorDeactivated();
  135. Parent::onDeactivated(%this);
  136. }
  137. function RiverEditorPlugin::onEditMenuSelect( %this, %editMenu )
  138. {
  139. %hasSelection = false;
  140. if( isObject( RiverEditorGui.river ) )
  141. %hasSelection = true;
  142. %editMenu.enableItem( 3, false ); // Cut
  143. %editMenu.enableItem( 4, false ); // Copy
  144. %editMenu.enableItem( 5, false ); // Paste
  145. %editMenu.enableItem( 6, %hasSelection ); // Delete
  146. %editMenu.enableItem( 8, false ); // Deselect
  147. }
  148. function RiverEditorPlugin::handleDelete( %this )
  149. {
  150. RiverEditorGui.deleteNode();
  151. }
  152. function RiverEditorPlugin::handleEscape( %this )
  153. {
  154. return RiverEditorGui.onEscapePressed();
  155. }
  156. function RiverEditorPlugin::isDirty( %this )
  157. {
  158. return RiverEditorGui.isDirty;
  159. }
  160. function RiverEditorPlugin::onSaveMission( %this, %missionFile )
  161. {
  162. if( RiverEditorGui.isDirty )
  163. {
  164. //Get our root scene, which would be the level
  165. getScene(0).save( %missionFile );
  166. RiverEditorGui.isDirty = false;
  167. }
  168. }
  169. //-----------------------------------------------------------------------------
  170. // Settings
  171. //-----------------------------------------------------------------------------
  172. function RiverEditorPlugin::initSettings( %this )
  173. {
  174. EditorSettings.beginGroup( "RiverEditor", true );
  175. EditorSettings.setDefaultValue( "DefaultWidth", "10" );
  176. EditorSettings.setDefaultValue( "DefaultDepth", "5" );
  177. EditorSettings.setDefaultValue( "DefaultNormal", "0 0 1" );
  178. EditorSettings.setDefaultValue( "HoverSplineColor", "255 0 0 255" );
  179. EditorSettings.setDefaultValue( "SelectedSplineColor", "0 255 0 255" );
  180. EditorSettings.setDefaultValue( "HoverNodeColor", "255 255 255 255" ); //<-- Not currently used
  181. EditorSettings.endGroup();
  182. }
  183. function RiverEditorPlugin::readSettings( %this )
  184. {
  185. EditorSettings.beginGroup( "RiverEditor", true );
  186. RiverEditorGui.DefaultWidth = EditorSettings.value("DefaultWidth");
  187. RiverEditorGui.DefaultDepth = EditorSettings.value("DefaultDepth");
  188. RiverEditorGui.DefaultNormal = EditorSettings.value("DefaultNormal");
  189. RiverEditorGui.HoverSplineColor = EditorSettings.value("HoverSplineColor");
  190. RiverEditorGui.SelectedSplineColor = EditorSettings.value("SelectedSplineColor");
  191. RiverEditorGui.HoverNodeColor = EditorSettings.value("HoverNodeColor");
  192. EditorSettings.endGroup();
  193. }
  194. function RiverEditorPlugin::writeSettings( %this )
  195. {
  196. EditorSettings.beginGroup( "RiverEditor", true );
  197. EditorSettings.setValue( "DefaultWidth", RiverEditorGui.DefaultWidth );
  198. EditorSettings.setValue( "DefaultDepth", RiverEditorGui.DefaultDepth );
  199. EditorSettings.setValue( "DefaultNormal", RiverEditorGui.DefaultNormal );
  200. EditorSettings.setValue( "HoverSplineColor", RiverEditorGui.HoverSplineColor );
  201. EditorSettings.setValue( "SelectedSplineColor", RiverEditorGui.SelectedSplineColor );
  202. EditorSettings.setValue( "HoverNodeColor", RiverEditorGui.HoverNodeColor );
  203. EditorSettings.endGroup();
  204. }