main.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. //---------------------------------------------------------------------------------------------
  23. // Path to the folder that contains the editors we will load.
  24. //---------------------------------------------------------------------------------------------
  25. $Tools::resourcePath = "tools/";
  26. // These must be loaded first, in this order, before anything else is loaded
  27. $Tools::loadFirst = "editorClasses base worldEditor";
  28. //---------------------------------------------------------------------------------------------
  29. // Object that holds the simObject id that the materialEditor uses to interpret its material list
  30. //---------------------------------------------------------------------------------------------
  31. $Tools::materialEditorList = "";
  32. //---------------------------------------------------------------------------------------------
  33. // Tools Package.
  34. //---------------------------------------------------------------------------------------------
  35. package Tools
  36. {
  37. function loadKeybindings()
  38. {
  39. Parent::loadKeybindings();
  40. }
  41. // Start-up.
  42. function onStart()
  43. {
  44. Parent::onStart();
  45. new Settings(EditorSettings) { file = "tools/settings.xml"; };
  46. EditorSettings.read();
  47. echo( " % - Initializing Tools" );
  48. // Default file path when saving from the editor (such as prefabs)
  49. if ($Pref::WorldEditor::LastPath $= "")
  50. {
  51. $Pref::WorldEditor::LastPath = getMainDotCsDir();
  52. }
  53. // Common GUI stuff.
  54. exec( "./gui/cursors.ed.cs" );
  55. exec( "./gui/profiles.ed.cs" );
  56. exec( "./editorClasses/gui/panels/navPanelProfiles.ed.cs" );
  57. // Make sure we get editor profiles before any GUI's
  58. // BUG: these dialogs are needed earlier in the init sequence, and should be moved to
  59. // common, along with the guiProfiles they depend on.
  60. exec( "./gui/guiDialogs.ed.cs" );
  61. //%toggle = $Scripts::ignoreDSOs;
  62. //$Scripts::ignoreDSOs = true;
  63. $ignoredDatablockSet = new SimSet();
  64. // fill the list of editors
  65. $editors[count] = getWordCount( $Tools::loadFirst );
  66. for ( %i = 0; %i < $editors[count]; %i++ )
  67. {
  68. $editors[%i] = getWord( $Tools::loadFirst, %i );
  69. }
  70. %pattern = $Tools::resourcePath @ "/*/main.cs";
  71. %folder = findFirstFile( %pattern );
  72. if ( %folder $= "")
  73. {
  74. // if we have absolutely no matches for main.cs, we look for main.cs.dso
  75. %pattern = $Tools::resourcePath @ "/*/main.cs.dso";
  76. %folder = findFirstFile( %pattern );
  77. }
  78. while ( %folder !$= "" )
  79. {
  80. if( filePath( %folder ) !$= "tools" ) // Skip the actual 'tools' folder...we want the children
  81. {
  82. %folder = filePath( %folder );
  83. %editor = fileName( %folder );
  84. if ( IsDirectory( %folder ) )
  85. {
  86. // Yes, this sucks and should be done better
  87. if ( strstr( $Tools::loadFirst, %editor ) == -1 )
  88. {
  89. $editors[$editors[count]] = %editor;
  90. $editors[count]++;
  91. }
  92. }
  93. }
  94. %folder = findNextFile( %pattern );
  95. }
  96. // initialize every editor
  97. new SimSet( EditorPluginSet );
  98. %count = $editors[count];
  99. for ( %i = 0; %i < %count; %i++ )
  100. {
  101. exec( "./" @ $editors[%i] @ "/main.cs" );
  102. %initializeFunction = "initialize" @ $editors[%i];
  103. if( isFunction( %initializeFunction ) )
  104. call( %initializeFunction );
  105. }
  106. // Popuplate the default SimObject icons that
  107. // are used by the various editors.
  108. EditorIconRegistry::loadFromPath( "tools/classIcons/" );
  109. // Load up the tools resources. All the editors are initialized at this point, so
  110. // resources can override, redefine, or add functionality.
  111. Tools::LoadResources( $Tools::resourcePath );
  112. //$Scripts::ignoreDSOs = %toggle;
  113. }
  114. function startToolTime(%tool)
  115. {
  116. if($toolDataToolCount $= "")
  117. $toolDataToolCount = 0;
  118. if($toolDataToolEntry[%tool] !$= "true")
  119. {
  120. $toolDataToolEntry[%tool] = "true";
  121. $toolDataToolList[$toolDataToolCount] = %tool;
  122. $toolDataToolCount++;
  123. $toolDataClickCount[%tool] = 0;
  124. }
  125. $toolDataStartTime[%tool] = getSimTime();
  126. $toolDataClickCount[%tool]++;
  127. }
  128. function endToolTime(%tool)
  129. {
  130. %startTime = 0;
  131. if($toolDataStartTime[%tool] !$= "")
  132. %startTime = $toolDataStartTime[%tool];
  133. if($toolDataTotalTime[%tool] $= "")
  134. $toolDataTotalTime[%tool] = 0;
  135. $toolDataTotalTime[%tool] += getSimTime() - %startTime;
  136. }
  137. function dumpToolData()
  138. {
  139. %count = $toolDataToolCount;
  140. for(%i=0; %i<%count; %i++)
  141. {
  142. %tool = $toolDataToolList[%i];
  143. %totalTime = $toolDataTotalTime[%tool];
  144. if(%totalTime $= "")
  145. %totalTime = 0;
  146. %clickCount = $toolDataClickCount[%tool];
  147. echo("---");
  148. echo("Tool: " @ %tool);
  149. echo("Time (seconds): " @ %totalTime / 1000);
  150. echo("Activated: " @ %clickCount);
  151. echo("---");
  152. }
  153. }
  154. // Shutdown.
  155. function onExit()
  156. {
  157. if( EditorGui.isInitialized )
  158. EditorGui.shutdown();
  159. // Free all the icon images in the registry.
  160. EditorIconRegistry::clear();
  161. // Save any Layouts we might be using
  162. //GuiFormManager::SaveLayout(LevelBuilder, Default, User);
  163. %count = $editors[count];
  164. for (%i = 0; %i < %count; %i++)
  165. {
  166. %destroyFunction = "destroy" @ $editors[%i];
  167. if( isFunction( %destroyFunction ) )
  168. call( %destroyFunction );
  169. }
  170. // Call Parent.
  171. Parent::onExit();
  172. // write out our settings xml file
  173. EditorSettings.write();
  174. }
  175. };
  176. function Tools::LoadResources( %path )
  177. {
  178. %resourcesPath = %path @ "resources/";
  179. %resourcesList = getDirectoryList( %resourcesPath );
  180. %wordCount = getFieldCount( %resourcesList );
  181. for( %i = 0; %i < %wordCount; %i++ )
  182. {
  183. %resource = GetField( %resourcesList, %i );
  184. if( isFile( %resourcesPath @ %resource @ "/resourceDatabase.cs") )
  185. ResourceObject::load( %path, %resource );
  186. }
  187. }
  188. //-----------------------------------------------------------------------------
  189. // Activate Package.
  190. //-----------------------------------------------------------------------------
  191. activatePackage(Tools);