main.cs 7.8 KB

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