init.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. // The common module provides basic client functionality
  55. initBaseClient();
  56. // Use our prefs to configure our Canvas/Window
  57. configureCanvas();
  58. // Load up the Game GUI
  59. exec("art/gui/playGui.gui");
  60. // Load up the shell GUIs
  61. if($platform !$= "xenon") // Use the unified shell instead
  62. exec("art/gui/mainMenuGui.gui");
  63. exec("art/gui/StartupGui.gui");
  64. // Gui scripts
  65. exec("scripts/gui/playGui.cs");
  66. exec("scripts/gui/startupGui.cs");
  67. // Client scripts
  68. exec("./missionDownload.cs");
  69. exec("./serverConnection.cs");
  70. // Default player key bindings
  71. exec("./default.bind.cs");
  72. if (isFile("./config.cs"))
  73. exec("./config.cs");
  74. loadMaterials();
  75. // Really shouldn't be starting the networking unless we are
  76. // going to connect to a remote server, or host a multi-player
  77. // game.
  78. setNetPort(0);
  79. // Copy saved script prefs into C++ code.
  80. setDefaultFov( $pref::Player::defaultFov );
  81. setZoomSpeed( $pref::Player::zoomSpeed );
  82. if( isFile( "./audioData.cs" ) )
  83. exec( "./audioData.cs" );
  84. // Start up the main menu... this is separated out into a
  85. // method for easier mod override.
  86. if ($startWorldEditor || $startGUIEditor) {
  87. // Editor GUI's will start up in the primary main.cs once
  88. // engine is initialized.
  89. return;
  90. }
  91. // Connect to server if requested.
  92. if ($JoinGameAddress !$= "") {
  93. // If we are instantly connecting to an address, load the
  94. // loading GUI then attempt the connect.
  95. loadLoadingGui();
  96. connect($JoinGameAddress, "", $Pref::Player::Name);
  97. }
  98. else {
  99. // Otherwise go to the splash screen.
  100. Canvas.setCursor("DefaultCursor");
  101. loadStartup();
  102. }
  103. }
  104. //-----------------------------------------------------------------------------
  105. function loadMainMenu()
  106. {
  107. // Startup the client with the Main menu...
  108. if (isObject( MainMenuGui ))
  109. Canvas.setContent( MainMenuGui );
  110. else if (isObject( UnifiedMainMenuGui ))
  111. Canvas.setContent( UnifiedMainMenuGui );
  112. Canvas.setCursor("DefaultCursor");
  113. // first check if we have a level file to load
  114. if ($levelToLoad !$= "")
  115. {
  116. %levelFile = "levels/";
  117. %ext = getSubStr($levelToLoad, strlen($levelToLoad) - 3, 3);
  118. if(%ext !$= "mis")
  119. %levelFile = %levelFile @ $levelToLoad @ ".mis";
  120. else
  121. %levelFile = %levelFile @ $levelToLoad;
  122. // Clear out the $levelToLoad so we don't attempt to load the level again
  123. // later on.
  124. $levelToLoad = "";
  125. // let's make sure the file exists
  126. %file = findFirstFile(%levelFile);
  127. if(%file !$= "")
  128. createAndConnectToLocalServer( "SinglePlayer", %file );
  129. }
  130. }
  131. function loadLoadingGui()
  132. {
  133. Canvas.setContent("LoadingGui");
  134. LoadingProgress.setValue(1);
  135. LoadingProgressTxt.setValue("WAITING FOR SERVER");
  136. Canvas.repaint();
  137. }