missionDownload.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. // Mission Loading & Mission Info
  24. // The mission loading server handshaking is handled by the
  25. // core/scripts/client/missingLoading.cs. This portion handles the interface
  26. // with the game GUI.
  27. //----------------------------------------------------------------------------
  28. //----------------------------------------------------------------------------
  29. // Loading Phases:
  30. // Phase 1: Download Datablocks
  31. // Phase 2: Download Ghost Objects
  32. // Phase 3: Scene Lighting
  33. //----------------------------------------------------------------------------
  34. // Phase 1
  35. //----------------------------------------------------------------------------
  36. function onMissionDownloadPhase1(%missionName, %musicTrack)
  37. {
  38. // Load the post effect presets for this mission.
  39. %path = "levels/" @ fileBase( %missionName ) @ $PostFXManager::fileExtension;
  40. if ( isScriptFile( %path ) )
  41. postFXManager::loadPresetHandler( %path );
  42. else
  43. PostFXManager::settingsApplyDefaultPreset();
  44. // Close and clear the message hud (in case it's open)
  45. if ( isObject( MessageHud ) )
  46. MessageHud.close();
  47. // Reset the loading progress controls:
  48. if ( !isObject( LoadingProgress ) )
  49. return;
  50. LoadingProgress.setValue(0);
  51. LoadingProgressTxt.setValue("LOADING DATABLOCKS");
  52. Canvas.repaint();
  53. }
  54. function onPhase1Progress(%progress)
  55. {
  56. if ( !isObject( LoadingProgress ) )
  57. return;
  58. LoadingProgress.setValue(%progress);
  59. Canvas.repaint(33);
  60. }
  61. function onPhase1Complete()
  62. {
  63. if ( !isObject( LoadingProgress ) )
  64. return;
  65. LoadingProgress.setValue( 1 );
  66. Canvas.repaint();
  67. }
  68. //----------------------------------------------------------------------------
  69. // Phase 2
  70. //----------------------------------------------------------------------------
  71. function onMissionDownloadPhase2()
  72. {
  73. if ( !isObject( LoadingProgress ) )
  74. return;
  75. LoadingProgress.setValue(0);
  76. LoadingProgressTxt.setValue("LOADING OBJECTS");
  77. Canvas.repaint();
  78. }
  79. function onPhase2Progress(%progress)
  80. {
  81. if ( !isObject( LoadingProgress ) )
  82. return;
  83. LoadingProgress.setValue(%progress);
  84. Canvas.repaint(33);
  85. }
  86. function onPhase2Complete()
  87. {
  88. if ( !isObject( LoadingProgress ) )
  89. return;
  90. LoadingProgress.setValue( 1 );
  91. Canvas.repaint();
  92. }
  93. function onFileChunkReceived(%fileName, %ofs, %size)
  94. {
  95. if ( !isObject( LoadingProgress ) )
  96. return;
  97. LoadingProgress.setValue(%ofs / %size);
  98. LoadingProgressTxt.setValue("Downloading " @ %fileName @ "...");
  99. }
  100. //----------------------------------------------------------------------------
  101. // Phase 3
  102. //----------------------------------------------------------------------------
  103. function onMissionDownloadPhase3()
  104. {
  105. if ( !isObject( LoadingProgress ) )
  106. return;
  107. LoadingProgress.setValue(0);
  108. LoadingProgressTxt.setValue("LIGHTING MISSION");
  109. Canvas.repaint();
  110. }
  111. function onPhase3Progress(%progress)
  112. {
  113. if ( !isObject( LoadingProgress ) )
  114. return;
  115. LoadingProgress.setValue(%progress);
  116. Canvas.repaint(33);
  117. }
  118. function onPhase3Complete()
  119. {
  120. $lightingMission = false;
  121. if ( !isObject( LoadingProgress ) )
  122. return;
  123. LoadingProgressTxt.setValue("STARTING MISSION");
  124. LoadingProgress.setValue( 1 );
  125. Canvas.repaint();
  126. }
  127. //----------------------------------------------------------------------------
  128. // Mission loading done!
  129. //----------------------------------------------------------------------------
  130. function onMissionDownloadComplete()
  131. {
  132. // Client will shortly be dropped into the game, so this is
  133. // good place for any last minute gui cleanup.
  134. }
  135. //------------------------------------------------------------------------------
  136. // Before downloading a mission, the server transmits the mission
  137. // information through these messages.
  138. //------------------------------------------------------------------------------
  139. addMessageCallback( 'MsgLoadInfo', handleLoadInfoMessage );
  140. addMessageCallback( 'MsgLoadDescripition', handleLoadDescriptionMessage );
  141. addMessageCallback( 'MsgLoadInfoDone', handleLoadInfoDoneMessage );
  142. addMessageCallback( 'MsgLoadFailed', handleLoadFailedMessage );
  143. //------------------------------------------------------------------------------
  144. function handleLoadInfoMessage( %msgType, %msgString, %mapName )
  145. {
  146. // Clear all of the loading info lines:
  147. for( %line = 0; %line < LoadingGui.qLineCount; %line++ )
  148. LoadingGui.qLine[%line] = "";
  149. LoadingGui.qLineCount = 0;
  150. }
  151. //------------------------------------------------------------------------------
  152. function handleLoadDescriptionMessage( %msgType, %msgString, %line )
  153. {
  154. LoadingGui.qLine[LoadingGui.qLineCount] = %line;
  155. LoadingGui.qLineCount++;
  156. // Gather up all the previous lines, append the current one
  157. // and stuff it into the control
  158. %text = "<spush><font:Arial:16>";
  159. for( %line = 0; %line < LoadingGui.qLineCount - 1; %line++ )
  160. %text = %text @ LoadingGui.qLine[%line] @ " ";
  161. %text = %text @ LoadingGui.qLine[%line] @ "<spop>";
  162. }
  163. //------------------------------------------------------------------------------
  164. function handleLoadInfoDoneMessage( %msgType, %msgString )
  165. {
  166. // This will get called after the last description line is sent.
  167. }
  168. //------------------------------------------------------------------------------
  169. function handleLoadFailedMessage( %msgType, %msgString )
  170. {
  171. MessageBoxOK( "Mission Load Failed", %msgString NL "Press OK to return to the Main Menu", "disconnect();" );
  172. }