missionmainmenu.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. class MissionMainMenu extends MissionBase
  2. {
  3. private UIScriptedMenu m_mainmenu;
  4. private CreditsMenu m_CreditsMenu;
  5. private ref DayZIntroScenePC m_IntroScenePC;
  6. private ref DayZIntroSceneXbox m_IntroSceneXbox;
  7. bool m_NoCutscene;
  8. override void OnInit()
  9. {
  10. if (!m_NoCutscene)
  11. {
  12. CreateIntroScene();
  13. }
  14. if (!m_mainmenu)
  15. {
  16. #ifdef PLATFORM_CONSOLE
  17. if ( g_Game.GetGameState() != DayZGameState.PARTY )
  18. {
  19. m_mainmenu = UIScriptedMenu.Cast( g_Game.GetUIManager().EnterScriptedMenu( MENU_TITLE_SCREEN, null ) );
  20. }
  21. #else
  22. m_mainmenu = UIScriptedMenu.Cast( g_Game.GetUIManager().EnterScriptedMenu( MENU_MAIN, null ) );
  23. #endif
  24. }
  25. GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  26. }
  27. override void Reset()
  28. {
  29. #ifdef PLATFORM_CONSOLE
  30. delete m_IntroSceneXbox;
  31. #else
  32. delete m_IntroScenePC;
  33. #endif
  34. CreateIntroScene();
  35. }
  36. DayZIntroScenePC GetIntroScenePC()
  37. {
  38. #ifdef PLATFORM_CONSOLE
  39. Error("missionMainMenu->GetIntroScenePC on PLATFORM_CONSOLE is not implemented!");
  40. return null;
  41. #else
  42. return m_IntroScenePC;
  43. #endif
  44. }
  45. DayZIntroSceneXbox GetIntroSceneXbox()
  46. {
  47. #ifdef PLATFORM_CONSOLE
  48. return m_IntroSceneXbox;
  49. #else
  50. Error("missionMainMenu->GetIntroScenePC on PLATFORM_PC is not implemented!");
  51. return null;
  52. #endif
  53. }
  54. void CreateIntroScene()
  55. {
  56. #ifdef PLATFORM_CONSOLE
  57. m_IntroSceneXbox = new DayZIntroSceneXbox;
  58. #else
  59. m_IntroScenePC = new DayZIntroScenePC;
  60. #endif
  61. }
  62. override void UpdateInputDevicesAvailability()
  63. {
  64. super.UpdateInputDevicesAvailability();
  65. g_Game.GetInput().UpdateConnectedInputDeviceList();
  66. g_Game.UpdateInputDeviceDisconnectWarning();
  67. }
  68. override void OnMissionStart()
  69. {
  70. g_Game.GetUIManager().ShowUICursor(true);
  71. g_Game.SetMissionState(DayZGame.MISSION_STATE_MAINMENU);
  72. m_DynamicMusicPlayer.SetCategory(EDynamicMusicPlayerCategory.MENU, true);
  73. g_Game.LoadingHide(true);
  74. ProgressAsync.DestroyAllPendingProgresses();
  75. }
  76. override void OnMissionFinish()
  77. {
  78. if ( m_mainmenu )
  79. m_mainmenu.Cleanup();
  80. GetGame().GetUIManager().CloseAll();
  81. m_mainmenu = NULL;
  82. m_IntroScenePC = null;
  83. m_IntroSceneXbox = null;
  84. m_CreditsMenu = null;
  85. #ifndef FEATURE_CURSOR
  86. g_Game.GetUIManager().ShowUICursor(false);
  87. #endif
  88. }
  89. override void OnUpdate(float timeslice)
  90. {
  91. super.OnUpdate(timeslice);
  92. #ifdef DIAG_DEVELOPER
  93. UpdateInputDeviceDiag();
  94. #endif
  95. if ( g_Game.IsLoading() )
  96. {
  97. return;
  98. }
  99. if (m_IntroScenePC)
  100. {
  101. m_IntroScenePC.Update();
  102. }
  103. }
  104. void OnMenuEnter(int menu_id)
  105. {
  106. switch (menu_id)
  107. {
  108. case MENU_CREDITS:
  109. {
  110. m_CreditsMenu = CreditsMenu.Cast(GetGame().GetUIManager().GetMenu());
  111. }
  112. }
  113. }
  114. void OnInputDeviceChanged(int device)
  115. {
  116. if (m_CreditsMenu)
  117. {
  118. m_CreditsMenu.UpdateInfoPanelText(device);
  119. }
  120. }
  121. int SortedInsert( array<int> list, int number )
  122. {
  123. int find_number = number;
  124. int index_min = 0;
  125. int index_max = list.Count() - 1;
  126. int target_index = Math.Floor( index_max / 2 );
  127. if ( index_max == -1 )
  128. {
  129. list.Insert( number );
  130. return 0;
  131. }
  132. while ( true )
  133. {
  134. int target_value = list[target_index];
  135. if ( find_number == target_value || ((index_max - index_min) <= 1) )
  136. {
  137. for ( int i = index_min; i <= index_max; i++ )
  138. {
  139. if ( find_number <= list[i] )
  140. {
  141. list.InsertAt( find_number, i );
  142. return i;
  143. }
  144. }
  145. index_max++;
  146. list.InsertAt( find_number, index_max );
  147. return target_index;
  148. }
  149. else if ( find_number < target_value )
  150. {
  151. index_max = target_index;
  152. target_index = Math.Floor( target_index / 2 );
  153. }
  154. else if ( find_number > target_value )
  155. {
  156. index_min = target_index;
  157. target_index += Math.Floor( (index_max - index_min) / 2 );
  158. }
  159. }
  160. return target_index;
  161. }
  162. //!
  163. //! DEPRECATED
  164. //!
  165. private AbstractWave m_MenuMusic;
  166. void PlayMusic()
  167. {
  168. if ( !m_MenuMusic )
  169. {
  170. SoundParams soundParams = new SoundParams( "Music_Menu_SoundSet" );
  171. SoundObjectBuilder soundBuilder = new SoundObjectBuilder( soundParams );
  172. SoundObject soundObject = soundBuilder.BuildSoundObject();
  173. soundObject.SetKind( WaveKind.WAVEMUSIC );
  174. m_MenuMusic = GetGame().GetSoundScene().Play2D(soundObject, soundBuilder);
  175. m_MenuMusic.Loop( true );
  176. m_MenuMusic.Play();
  177. }
  178. }
  179. void StopMusic()
  180. {
  181. if ( m_MenuMusic )
  182. m_MenuMusic.Stop();
  183. }
  184. AbstractWave GetMenuMusic()
  185. {
  186. return m_MenuMusic;
  187. }
  188. }