init.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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/defaultGameProfiles.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 GUIs
  63. exec("art/gui/playGui.gui");
  64. exec("art/gui/chatHud.gui");
  65. exec("art/gui/playerList.gui");
  66. exec("art/gui/hudlessGui.gui");
  67. // Load up the shell GUIs
  68. exec("art/gui/mainMenuGui.gui");
  69. exec("art/gui/joinServerDlg.gui");
  70. exec("art/gui/endGameGui.gui");
  71. exec("art/gui/StartupGui.gui");
  72. exec("art/gui/chooseLevelDlg.gui");
  73. exec("art/gui/loadingGui.gui");
  74. exec("art/gui/optionsDlg.gui");
  75. exec("art/gui/remapDlg.gui");
  76. // Gui scripts
  77. exec("./playerList.cs");
  78. exec("./chatHud.cs");
  79. exec("./messageHud.cs");
  80. exec("scripts/gui/playGui.cs");
  81. exec("scripts/gui/startupGui.cs");
  82. exec("scripts/gui/chooseLevelDlg.cs");
  83. exec("scripts/gui/loadingGui.cs");
  84. exec("scripts/gui/optionsDlg.cs");
  85. // Client scripts
  86. exec("./client.cs");
  87. exec("./game.cs");
  88. exec("./missionDownload.cs");
  89. exec("./serverConnection.cs");
  90. // Load useful Materials
  91. exec("./shaders.cs");
  92. // Default player key bindings
  93. exec("./default.bind.cs");
  94. if (isFile("./config.cs"))
  95. exec("./config.cs");
  96. loadMaterials();
  97. // Really shouldn't be starting the networking unless we are
  98. // going to connect to a remote server, or host a multi-player
  99. // game.
  100. setNetPort(0);
  101. // Copy saved script prefs into C++ code.
  102. setDefaultFov( $pref::Player::defaultFov );
  103. setZoomSpeed( $pref::Player::zoomSpeed );
  104. if( isScriptFile( expandFilename("./audioData.cs") ) )
  105. exec( "./audioData.cs" );
  106. // Start up the main menu... this is separated out into a
  107. // method for easier mod override.
  108. if ($startWorldEditor || $startGUIEditor) {
  109. // Editor GUI's will start up in the primary main.cs once
  110. // engine is initialized.
  111. return;
  112. }
  113. // Connect to server if requested.
  114. if ($JoinGameAddress !$= "") {
  115. // If we are instantly connecting to an address, load the
  116. // loading GUI then attempt the connect.
  117. loadLoadingGui();
  118. connect($JoinGameAddress, "", $Pref::Player::Name);
  119. }
  120. else {
  121. // Otherwise go to the splash screen.
  122. Canvas.setCursor("DefaultCursor");
  123. loadStartup();
  124. }
  125. }
  126. //-----------------------------------------------------------------------------
  127. function loadMainMenu()
  128. {
  129. // Startup the client with the Main menu...
  130. if (isObject( MainMenuGui ))
  131. Canvas.setContent( MainMenuGui );
  132. Canvas.setCursor("DefaultCursor");
  133. // first check if we have a level file to load
  134. if ($levelToLoad !$= "")
  135. {
  136. %levelFile = "levels/";
  137. %ext = getSubStr($levelToLoad, strlen($levelToLoad) - 3, 3);
  138. if(%ext !$= "mis")
  139. %levelFile = %levelFile @ $levelToLoad @ ".mis";
  140. else
  141. %levelFile = %levelFile @ $levelToLoad;
  142. // Clear out the $levelToLoad so we don't attempt to load the level again
  143. // later on.
  144. $levelToLoad = "";
  145. // let's make sure the file exists
  146. %file = findFirstFile(%levelFile);
  147. if(%file !$= "")
  148. createAndConnectToLocalServer( "SinglePlayer", %file );
  149. }
  150. }
  151. function loadLoadingGui(%displayText)
  152. {
  153. Canvas.setContent("LoadingGui");
  154. LoadingProgress.setValue(1);
  155. if (%displayText !$= "")
  156. {
  157. LoadingProgressTxt.setValue(%displayText);
  158. }
  159. else
  160. {
  161. LoadingProgressTxt.setValue("WAITING FOR SERVER");
  162. }
  163. Canvas.repaint();
  164. }