main.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 physicsToggleSimulation()
  23. {
  24. %isEnabled = physicsSimulationEnabled();
  25. if ( %isEnabled )
  26. {
  27. physicsStateText.setText( "Simulation is paused." );
  28. physicsStopSimulation( "client" );
  29. physicsStopSimulation( "server" );
  30. }
  31. else
  32. {
  33. physicsStateText.setText( "Simulation is unpaused." );
  34. physicsStartSimulation( "client" );
  35. physicsStartSimulation( "server" );
  36. }
  37. }
  38. function initializePhysicsTools()
  39. {
  40. echo( " % - Initializing Physics Tools" );
  41. if ( !physicsPluginPresent() )
  42. {
  43. echo( "No physics plugin exists." );
  44. return;
  45. }
  46. globalactionmap.bindCmd( keyboard, "alt t", "physicsToggleSimulation();", "" );
  47. globalactionmap.bindCmd( keyboard, "alt r", "physicsRestoreState();", "" );
  48. new ScriptObject( PhysicsEditorPlugin )
  49. {
  50. superClass = "EditorPlugin";
  51. editorGui = EWorldEditor;
  52. };
  53. }
  54. function destroyPhysicsTools()
  55. {
  56. }
  57. function PhysicsEditorPlugin::onWorldEditorStartup( %this )
  58. {
  59. new PopupMenu( PhysicsToolsMenu )
  60. {
  61. superClass = "MenuBuilder";
  62. //class = "PhysXToolsMenu";
  63. barTitle = "Physics";
  64. item[0] = "Start Simulation" TAB "Ctrl-Alt P" TAB "physicsStartSimulation( \"client\" );physicsStartSimulation( \"server\" );";
  65. //item[1] = "Stop Simulation" TAB "" TAB "physicsSetTimeScale( 0 );";
  66. item[1] = "-";
  67. item[2] = "Speed 25%" TAB "" TAB "physicsSetTimeScale( 0.25 );";
  68. item[3] = "Speed 50%" TAB "" TAB "physicsSetTimeScale( 0.5 );";
  69. item[4] = "Speed 100%" TAB "" TAB "physicsSetTimeScale( 1.0 );";
  70. item[5] = "-";
  71. item[6] = "Reload NXBs" TAB "" TAB "";
  72. };
  73. // Add our menu.
  74. EditorGui.menuBar.insert( PhysicsToolsMenu, EditorGui.menuBar.dynamicItemInsertPos );
  75. // Add ourselves to the window menu.
  76. //EditorGui.addToWindowMenu( "Road and Path Editor", "", "RoadEditor" );
  77. }
  78. function PhysicsToolsMenu::onMenuSelect(%this)
  79. {
  80. %isEnabled = physicsSimulationEnabled();
  81. %itemText = !%isEnabled ? "Start Simulation" : "Pause Simulation";
  82. %itemCommand = !%isEnabled ? "physicsStartSimulation( \"client\" );physicsStartSimulation( \"server\" );" : "physicsStopSimulation( \"client\" );physicsStopSimulation( \"server\" );";
  83. %this.setItemName( 0, %itemText );
  84. %this.setItemCommand( 0, %itemCommand );
  85. }
  86. function PhysicsEditorPlugin::onEditorWake( %this )
  87. {
  88. // Disable physics when entering
  89. // the editor. Will be re-enabled
  90. // when the editor is closed.
  91. physicsStopSimulation( "client" );
  92. physicsStopSimulation( "server" );
  93. physicsRestoreState();
  94. }
  95. function PhysicsEditorPlugin::onEditorSleep( %this )
  96. {
  97. physicsStoreState();
  98. %currentTimeScale = physicsGetTimeScale();
  99. if ( %currentTimeScale == 0.0 )
  100. physicsSetTimeScale( 1.0 );
  101. physicsStartSimulation( "client" );
  102. physicsStartSimulation( "server" );
  103. }