main.tscript 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 initializeRoadEditor()
  23. {
  24. echo( " - Initializing Road and Path Editor" );
  25. exec( "./roadEditor." @ $TorqueScriptFileExtension );
  26. exec( "./RoadEditorGui.gui" );
  27. exec( "./RoadEditorToolbar.gui");
  28. exec( "./roadEditorGui." @ $TorqueScriptFileExtension );
  29. // Add ourselves to EditorGui, where all the other tools reside
  30. RoadEditorGui.setVisible( false );
  31. RoadEditorOptionsWindow.setVisible( false );
  32. RoadEditorTreeWindow.setVisible( false );
  33. MainSceneTabPanel.add( RoadEditorGui );
  34. MainSceneTabPanel.add( RoadEditorOptionsWindow );
  35. MainSceneTabPanel.add( RoadEditorTreeWindow );
  36. new ScriptObject( RoadEditorPlugin )
  37. {
  38. superClass = "EditorPlugin";
  39. editorGui = RoadEditorGui;
  40. };
  41. %map = new ActionMap();
  42. %map.bindCmd( keyboard, "backspace", "RoadEditorGui.onDeleteKey();", "" );
  43. %map.bindCmd( keyboard, "1", "RoadEditorGui.prepSelectionMode();", "" );
  44. %map.bindCmd( keyboard, "2", "ToolsPaletteArray->RoadEditorMoveMode.performClick();", "" );
  45. %map.bindCmd( keyboard, "4", "ToolsPaletteArray->RoadEditorScaleMode.performClick();", "" );
  46. %map.bindCmd( keyboard, "5", "ToolsPaletteArray->RoadEditorAddRoadMode.performClick();", "" );
  47. %map.bindCmd( keyboard, "=", "ToolsPaletteArray->RoadEditorInsertPointMode.performClick();", "" );
  48. %map.bindCmd( keyboard, "numpadadd", "ToolsPaletteArray->RoadEditorInsertPointMode.performClick();", "" );
  49. %map.bindCmd( keyboard, "-", "ToolsPaletteArray->RoadEditorRemovePointMode.performClick();", "" );
  50. %map.bindCmd( keyboard, "numpadminus", "ToolsPaletteArray->RoadEditorRemovePointMode.performClick();", "" );
  51. %map.bindCmd( keyboard, "z", "RoadEditorShowSplineBtn.performClick();", "" );
  52. %map.bindCmd( keyboard, "x", "RoadEditorWireframeBtn.performClick();", "" );
  53. %map.bindCmd( keyboard, "v", "RoadEditorShowRoadBtn.performClick();", "" );
  54. RoadEditorPlugin.map = %map;
  55. RoadEditorPlugin.initSettings();
  56. }
  57. function destroyRoadEditor()
  58. {
  59. }
  60. function RoadEditorPlugin::onWorldEditorStartup( %this )
  61. {
  62. // Add ourselves to the window menu.
  63. %accel = EditorGui.addToEditorsMenu( "Road and Path Editor", "", RoadEditorPlugin );
  64. // Add ourselves to the ToolsToolbar
  65. %tooltip = "Road Editor (" @ %accel @ ")";
  66. EditorGui.addToToolsToolbar( "RoadEditorPlugin", "RoadEditorPalette", "ToolsModule:road_path_editor_n_image", %tooltip );
  67. //connect editor windows
  68. GuiWindowCtrl::attach( RoadEditorOptionsWindow, RoadEditorTreeWindow);
  69. // Add ourselves to the Editor Settings window
  70. exec( "./RoadEditorSettingsTab.gui" );
  71. //ESettingsWindow.addTabPage( ERoadEditorSettingsPage );
  72. ESettingsWindow.addEditorSettingsPage("RoadEditor", "Decal Road Editor");
  73. }
  74. function RoadEditorPlugin::onActivated( %this )
  75. {
  76. %this.readSettings();
  77. ToolsPaletteArray->RoadEditorAddRoadMode.performClick();
  78. EditorGui.bringToFront( RoadEditorGui );
  79. RoadEditorGui.setVisible( true );
  80. RoadEditorGui.makeFirstResponder( true );
  81. EditorGuiToolbarStack.remove( EWorldEditorToolbar );
  82. EditorGuiToolbarStack.add( RoadEditorToolbar );
  83. RoadEditorOptionsWindow.setVisible( true );
  84. RoadEditorTreeWindow.setVisible( true );
  85. RoadTreeView.open(ServerDecalRoadSet,true);
  86. %this.map.push();
  87. // Set the status bar here until all tool have been hooked up
  88. EditorGuiStatusBar.setInfo("Decal Road Editor.");
  89. EditorGuiStatusBar.setSelection("");
  90. Parent::onActivated(%this);
  91. }
  92. function RoadEditorPlugin::onDeactivated( %this )
  93. {
  94. %this.writeSettings();
  95. RoadEditorGui.setVisible( false );
  96. EditorGuiToolbarStack.add( EWorldEditorToolbar );
  97. EditorGuiToolbarStack.remove( RoadEditorToolbar );
  98. RoadEditorOptionsWindow.setVisible( false );
  99. RoadEditorTreeWindow.setVisible( false );
  100. %this.map.pop();
  101. Parent::onDeactivated(%this);
  102. }
  103. function RoadEditorPlugin::onEditMenuSelect( %this, %editMenu )
  104. {
  105. %hasSelection = false;
  106. if( isObject( RoadEditorGui.road ) )
  107. %hasSelection = true;
  108. %editMenu.enableItem( 3, false ); // Cut
  109. %editMenu.enableItem( 4, false ); // Copy
  110. %editMenu.enableItem( 5, false ); // Paste
  111. %editMenu.enableItem( 6, %hasSelection ); // Delete
  112. %editMenu.enableItem( 8, false ); // Deselect
  113. }
  114. function RoadEditorPlugin::handleDelete( %this )
  115. {
  116. RoadEditorGui.onDeleteKey();
  117. }
  118. function RoadEditorPlugin::handleEscape( %this )
  119. {
  120. return RoadEditorGui.onEscapePressed();
  121. }
  122. function RoadEditorPlugin::isDirty( %this )
  123. {
  124. return RoadEditorGui.isDirty;
  125. }
  126. function RoadEditorPlugin::onSaveMission( %this, %missionFile )
  127. {
  128. if( RoadEditorGui.isDirty )
  129. {
  130. getScene(0).save( %missionFile );
  131. RoadEditorGui.isDirty = false;
  132. }
  133. }
  134. function RoadEditorPlugin::setEditorFunction( %this )
  135. {
  136. %terrainExists = parseMissionGroup( "TerrainBlock" );
  137. if( %terrainExists == false )
  138. toolsMessageBoxYesNoCancel("No Terrain","Would you like to create a New Terrain?", "AssetBrowser.setupCreateNewAsset(\"TerrainAsset\", AssetBrowser.selectedModule, createTerrainBlock);");
  139. return %terrainExists;
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Settings
  143. //-----------------------------------------------------------------------------
  144. function RoadEditorPlugin::initSettings( %this )
  145. {
  146. EditorSettings.beginGroup( "RoadEditor", true );
  147. EditorSettings.setDefaultValue( "DefaultWidth", "10" );
  148. EditorSettings.setDefaultValue( "HoverSplineColor", "255 0 0 255" );
  149. EditorSettings.setDefaultValue( "SelectedSplineColor", "0 255 0 255" );
  150. EditorSettings.setDefaultValue( "HoverNodeColor", "255 255 255 255" ); //<-- Not currently used
  151. EditorSettings.setDefaultValue( "MaterialName", "DefaultDecalRoadMaterial" );
  152. EditorSettings.endGroup();
  153. }
  154. function RoadEditorPlugin::readSettings( %this )
  155. {
  156. EditorSettings.beginGroup( "RoadEditor", true );
  157. RoadEditorGui.DefaultWidth = EditorSettings.value("DefaultWidth");
  158. RoadEditorGui.HoverSplineColor = EditorSettings.value("HoverSplineColor");
  159. RoadEditorGui.SelectedSplineColor = EditorSettings.value("SelectedSplineColor");
  160. RoadEditorGui.HoverNodeColor = EditorSettings.value("HoverNodeColor");
  161. RoadEditorGui.materialName = EditorSettings.value("MaterialName");
  162. EditorSettings.endGroup();
  163. }
  164. function RoadEditorPlugin::writeSettings( %this )
  165. {
  166. EditorSettings.beginGroup( "RoadEditor", true );
  167. EditorSettings.setValue( "DefaultWidth", RoadEditorGui.DefaultWidth );
  168. EditorSettings.setValue( "HoverSplineColor", RoadEditorGui.HoverSplineColor );
  169. EditorSettings.setValue( "SelectedSplineColor", RoadEditorGui.SelectedSplineColor );
  170. EditorSettings.setValue( "HoverNodeColor", RoadEditorGui.HoverNodeColor );
  171. EditorSettings.setValue( "MaterialName", RoadEditorGui.materialName );
  172. EditorSettings.endGroup();
  173. }