init.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. // Variables used by client scripts & code. The ones marked with (c)
  24. // are accessed from code. Variables preceeded by Pref:: are client
  25. // preferences and stored automatically in the ~/client/prefs.cs file
  26. // in between sessions.
  27. //
  28. // (c) Client::MissionFile Mission file name
  29. // ( ) Client::Password Password for server join
  30. // (?) Pref::Player::CurrentFOV
  31. // (?) Pref::Player::DefaultFov
  32. // ( ) Pref::Input::KeyboardTurnSpeed
  33. // (c) pref::Master[n] List of master servers
  34. // (c) pref::Net::RegionMask
  35. // (c) pref::Client::ServerFavoriteCount
  36. // (c) pref::Client::ServerFavorite[FavoriteCount]
  37. // .. Many more prefs... need to finish this off
  38. // Moves, not finished with this either...
  39. // (c) firstPerson
  40. // $mv*Action...
  41. //-----------------------------------------------------------------------------
  42. // These are variables used to control the shell scripts and
  43. // can be overriden by mods:
  44. //-----------------------------------------------------------------------------
  45. //-----------------------------------------------------------------------------
  46. function initClient()
  47. {
  48. echo("\n--------- Initializing " @ $appName @ ": Client Scripts ---------");
  49. // Make sure this variable reflects the correct state.
  50. $Server::Dedicated = false;
  51. // Game information used to query the master server
  52. $Client::GameTypeQuery = $appName;
  53. $Client::MissionTypeQuery = "Any";
  54. // These should be game specific GuiProfiles. Custom profiles are saved out
  55. // from the Gui Editor. Either of these may override any that already exist.
  56. exec("art/gui/gameProfiles.cs");
  57. exec("art/gui/customProfiles.cs");
  58. // The common module provides basic client functionality
  59. initBaseClient();
  60. // Use our prefs to configure our Canvas/Window
  61. configureCanvas();
  62. // Load up the Game GUI
  63. exec("art/gui/playGui.gui");
  64. // Load up the shell GUIs
  65. exec("art/gui/mainMenuGui.gui");
  66. exec("art/gui/StartupGui.gui");
  67. exec("art/gui/chooseLevelDlg.gui");
  68. exec("art/gui/loadingGui.gui");
  69. exec("art/gui/optionsDlg.gui");
  70. exec("art/gui/remapDlg.gui");
  71. // Gui scripts
  72. exec("scripts/gui/playGui.cs");
  73. exec("scripts/gui/startupGui.cs");
  74. exec("scripts/gui/chooseLevelDlg.cs");
  75. exec("scripts/gui/loadingGui.cs");
  76. exec("scripts/gui/optionsDlg.cs");
  77. // Client scripts
  78. exec("./missionDownload.cs");
  79. exec("./serverConnection.cs");
  80. // Default player key bindings
  81. exec("./default.bind.cs");
  82. if (isFile("./config.cs"))
  83. exec("./config.cs");
  84. loadMaterials();
  85. // Really shouldn't be starting the networking unless we are
  86. // going to connect to a remote server, or host a multi-player
  87. // game.
  88. setNetPort(0);
  89. // Copy saved script prefs into C++ code.
  90. setDefaultFov( $pref::Player::defaultFov );
  91. setZoomSpeed( $pref::Player::zoomSpeed );
  92. if( isScriptFile( expandFilename("./audioData.cs") ) )
  93. exec( "./audioData.cs" );
  94. // Start up the main menu... this is separated out into a
  95. // method for easier mod override.
  96. if ($startWorldEditor || $startGUIEditor) {
  97. // Editor GUI's will start up in the primary main.cs once
  98. // engine is initialized.
  99. return;
  100. }
  101. // Connect to server if requested.
  102. if ($JoinGameAddress !$= "") {
  103. // If we are instantly connecting to an address, load the
  104. // loading GUI then attempt the connect.
  105. loadLoadingGui();
  106. connect($JoinGameAddress, "", $Pref::Player::Name);
  107. }
  108. else {
  109. // Otherwise go to the splash screen.
  110. Canvas.setCursor("DefaultCursor");
  111. loadStartup();
  112. }
  113. }
  114. //-----------------------------------------------------------------------------
  115. function loadMainMenu()
  116. {
  117. // Startup the client with the Main menu...
  118. if (isObject( MainMenuGui ))
  119. Canvas.setContent( MainMenuGui );
  120. Canvas.setCursor("DefaultCursor");
  121. // first check if we have a level file to load
  122. if ($levelToLoad !$= "")
  123. {
  124. %levelFile = "levels/";
  125. %ext = getSubStr($levelToLoad, strlen($levelToLoad) - 3, 3);
  126. if(%ext !$= "mis")
  127. %levelFile = %levelFile @ $levelToLoad @ ".mis";
  128. else
  129. %levelFile = %levelFile @ $levelToLoad;
  130. // Clear out the $levelToLoad so we don't attempt to load the level again
  131. // later on.
  132. $levelToLoad = "";
  133. // let's make sure the file exists
  134. %file = findFirstFile(%levelFile);
  135. if(%file !$= "")
  136. createAndConnectToLocalServer( "SinglePlayer", %file );
  137. }
  138. }
  139. function loadLoadingGui()
  140. {
  141. Canvas.setContent("LoadingGui");
  142. LoadingProgress.setValue(1);
  143. LoadingProgressTxt.setValue("WAITING FOR SERVER");
  144. Canvas.repaint();
  145. }