main.cs 9.3 KB

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