Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1524 lines
46 KiB

  1. //===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Implements all the functions exported by the GameUI dll
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #if !defined( _GAMECONSOLE ) && !defined( _OSX ) & !defined (LINUX)
  8. #include <windows.h>
  9. #endif
  10. #include "cbase.h"
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <stdio.h>
  14. // dgoodenough - io.h and direct.h don't exist on PS3
  15. // PS3_BUILDFIX
  16. // @wge Fix for OSX too.
  17. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  18. #include <io.h>
  19. #endif
  20. #include <tier0/dbg.h>
  21. // @wge Fix for OSX too.
  22. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  23. #include <direct.h>
  24. #endif
  25. #ifdef SendMessage
  26. #undef SendMessage
  27. #endif
  28. #include "filesystem.h"
  29. #include "gameui_interface.h"
  30. #include "sys_utils.h"
  31. #include "string.h"
  32. #include "tier0/icommandline.h"
  33. // interface to engine
  34. #include "engineinterface.h"
  35. #include "vguisystemmoduleloader.h"
  36. #include "bitmap/tgaloader.h"
  37. #include "gameconsole.h"
  38. #include "cdkeyentrydialog.h"
  39. #include "modinfo.h"
  40. #include "game/client/IGameClientExports.h"
  41. #include "materialsystem/imaterialsystem.h"
  42. #include "matchmaking/imatchframework.h"
  43. #include "ixboxsystem.h"
  44. #include "iachievementmgr.h"
  45. #include "IGameUIFuncs.h"
  46. #include "ienginevgui.h"
  47. #include "gameconsole.h"
  48. // vgui2 interface
  49. // note that GameUI project uses ..\vgui2\include, not ..\utils\vgui\include
  50. #include "vgui/Cursor.h"
  51. #include "tier1/keyvalues.h"
  52. #include "vgui/ILocalize.h"
  53. #include "vgui/IPanel.h"
  54. #include "vgui/IScheme.h"
  55. #include "vgui/IVGui.h"
  56. #include "vgui/ISystem.h"
  57. #include "vgui/ISurface.h"
  58. #include "vgui_controls/Menu.h"
  59. #include "vgui_controls/PHandle.h"
  60. #include "tier3/tier3.h"
  61. #include "matsys_controls/matsyscontrols.h"
  62. #include "steam/steam_api.h"
  63. #include "protocol.h"
  64. #include "loadingscreen_scaleform.h"
  65. #include "GameUI/IGameUI.h"
  66. #include "inputsystem/iinputsystem.h"
  67. #include "cstrike15_item_inventory.h"
  68. #ifdef PANORAMA_ENABLE
  69. #include "panorama/controls/panel2d.h"
  70. #include "panorama/iuiengine.h"
  71. #include "panorama/localization/ilocalize.h"
  72. #include "panorama/panorama.h"
  73. #include "panorama/source2/ipanoramaui.h"
  74. enum PanoramaEngineViewPriority_t
  75. {
  76. PANORAMA_ENGINE_VIEW_PRIORITY_DEFAULT = 1000,
  77. // Room for game-specific views here
  78. PANORAMA_ENGINE_VIEW_PRIORITY_CONSOLE = 2000
  79. };
  80. DEFINE_PANORAMA_EVENT( CSGOLoadProgressChanged );
  81. enum PanoramaGameViewPriority_t
  82. {
  83. PANORAMA_GAME_VIEW_PRIORITY_HUD = PANORAMA_ENGINE_VIEW_PRIORITY_DEFAULT,
  84. PANORAMA_GAME_VIEW_PRIORITY_MAINMENU,
  85. PANORAMA_GAME_VIEW_PRIORITY_LOADINGSCREEN,
  86. PANORAMA_GAME_VIEW_PRIORITY_PAUSEMENU
  87. };
  88. #endif
  89. #if defined( SWARM_DLL )
  90. #include "swarm/basemodpanel.h"
  91. #include "swarm/basemodui.h"
  92. typedef BaseModUI::CBaseModPanel UI_BASEMOD_PANEL_CLASS;
  93. inline UI_BASEMOD_PANEL_CLASS & GetUiBaseModPanelClass() { return UI_BASEMOD_PANEL_CLASS::GetSingleton(); }
  94. inline UI_BASEMOD_PANEL_CLASS & ConstructUiBaseModPanelClass() { return * new UI_BASEMOD_PANEL_CLASS(); }
  95. class IMatchExtSwarm *g_pMatchExtSwarm = NULL;
  96. #elif defined( PORTAL2_UITEST_DLL )
  97. #include "portal2uitest/basemodpanel.h"
  98. #include "portal2uitest/basemodui.h"
  99. typedef BaseModUI::CBaseModPanel UI_BASEMOD_PANEL_CLASS;
  100. inline UI_BASEMOD_PANEL_CLASS & GetUiBaseModPanelClass() { return UI_BASEMOD_PANEL_CLASS::GetSingleton(); }
  101. inline UI_BASEMOD_PANEL_CLASS & ConstructUiBaseModPanelClass() { return * new UI_BASEMOD_PANEL_CLASS(); }
  102. IMatchExtPortal2 g_MatchExtPortal2;
  103. class IMatchExtPortal2 *g_pMatchExtPortal2 = &g_MatchExtPortal2;
  104. #elif defined( CSTRIKE15 )
  105. #include "basepanel.h"
  106. #include "../gameui/cstrike15/cstrike15basepanel.h"
  107. #include "../Scaleform/messagebox_scaleform.h"
  108. typedef CBaseModPanel UI_BASEMOD_PANEL_CLASS;
  109. inline UI_BASEMOD_PANEL_CLASS & GetUiBaseModPanelClass() { return *BasePanel(); }
  110. inline UI_BASEMOD_PANEL_CLASS & ConstructUiBaseModPanelClass() { return *BasePanelSingleton(); }
  111. #else
  112. #include "BasePanel.h"
  113. typedef CBasePanel UI_BASEMOD_PANEL_CLASS;
  114. inline UI_BASEMOD_PANEL_CLASS & GetUiBaseModPanelClass() { return *BasePanel(); }
  115. inline UI_BASEMOD_PANEL_CLASS & ConstructUiBaseModPanelClass() { return *BasePanelSingleton(); }
  116. #endif
  117. // dgoodenough - select correct stub header based on current console
  118. // PS3_BUILDFIX
  119. #if defined( _PS3 )
  120. #include "ps3/ps3_win32stubs.h"
  121. #include <cell/sysmodule.h>
  122. #endif
  123. #if defined( _X360 )
  124. #include "xbox/xbox_win32stubs.h"
  125. #endif
  126. #include "tier0/dbg.h"
  127. #include "engine/IEngineSound.h"
  128. #include "gameui_util.h"
  129. // memdbgon must be the last include file in a .cpp file!!!
  130. #include "tier0/memdbgon.h"
  131. IEngineVGui *enginevguifuncs = NULL;
  132. // dgoodenough - xonline only exists on the 360. All uses of xonline have had their
  133. // protection changed like this one
  134. // PS3_BUILDFIX
  135. // FIXME we will have to put in something for Playstation Home.
  136. #if defined( _X360 )
  137. IXOnline *xonline = NULL; // 360 only
  138. #elif defined( _PS3 )
  139. IPS3SaveRestoreToUI *ps3saveuiapi = NULL;
  140. #endif
  141. vgui::ISurface *enginesurfacefuncs = NULL;
  142. IAchievementMgr *achievementmgr = NULL;
  143. class CGameUI;
  144. CGameUI *g_pGameUI = NULL;
  145. vgui::VPANEL g_hLoadingBackgroundDialog = NULL;
  146. static CGameUI g_GameUI;
  147. #if defined( INCLUDE_SCALEFORM )
  148. IScaleformUI* ScaleformUI()
  149. {
  150. return g_pScaleformUI;
  151. }
  152. #endif
  153. static IGameClientExports *g_pGameClientExports = NULL;
  154. IGameClientExports *GameClientExports()
  155. {
  156. return g_pGameClientExports;
  157. }
  158. //-----------------------------------------------------------------------------
  159. // Purpose: singleton accessor
  160. //-----------------------------------------------------------------------------
  161. CGameUI &GameUI()
  162. {
  163. return g_GameUI;
  164. }
  165. //-----------------------------------------------------------------------------
  166. // Purpose: hack function to give the module loader access to the main panel handle
  167. // only used in VguiSystemModuleLoader
  168. //-----------------------------------------------------------------------------
  169. vgui::VPANEL GetGameUIBasePanel()
  170. {
  171. return GetUiBaseModPanelClass().GetVPanel();
  172. }
  173. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CGameUI, IGameUI, GAMEUI_INTERFACE_VERSION, g_GameUI);
  174. //-----------------------------------------------------------------------------
  175. // Purpose: Constructor
  176. //-----------------------------------------------------------------------------
  177. CGameUI::CGameUI()
  178. {
  179. g_pGameUI = this;
  180. m_bTryingToLoadFriends = false;
  181. m_iFriendsLoadPauseFrames = 0;
  182. m_iGameIP = 0;
  183. m_iGameConnectionPort = 0;
  184. m_iGameQueryPort = 0;
  185. m_bActivatedUI = false;
  186. m_szPreviousStatusText[0] = 0;
  187. m_bIsConsoleUI = false;
  188. m_bHasSavedThisMenuSession = false;
  189. m_bOpenProgressOnStart = false;
  190. m_iPlayGameStartupSound = 0;
  191. m_nBackgroundMusicGUID = 0;
  192. m_bBackgroundMusicDesired = false;
  193. m_nBackgroundMusicVersion = RandomInt( 1, MAX_BACKGROUND_MUSIC );
  194. m_flBackgroundMusicStopTime = -1.0;
  195. m_pMusicExtension = NULL;
  196. m_pPreviewMusicExtension = NULL;
  197. m_flMainMenuMusicVolume = -1;
  198. m_flMasterMusicVolume = -1;
  199. m_flQuestAudioTimeEnd = 0;
  200. m_flMasterMusicVolumeSavedForMissionAudio = -1;
  201. m_flMenuMusicVolumeSavedForMissionAudio = -1;
  202. m_nQuestAudioGUID = 0;
  203. }
  204. //-----------------------------------------------------------------------------
  205. // Purpose: Destructor
  206. //-----------------------------------------------------------------------------
  207. CGameUI::~CGameUI()
  208. {
  209. g_pGameUI = NULL;
  210. }
  211. //-----------------------------------------------------------------------------
  212. // Purpose: Initialization
  213. //-----------------------------------------------------------------------------
  214. void CGameUI::Initialize( CreateInterfaceFn factory )
  215. {
  216. MEM_ALLOC_CREDIT();
  217. ConnectTier1Libraries( &factory, 1 );
  218. ConnectTier2Libraries( &factory, 1 );
  219. ConVar_Register( FCVAR_CLIENTDLL );
  220. ConnectTier3Libraries( &factory, 1 );
  221. enginesound = (IEngineSound *)factory(IENGINESOUND_CLIENT_INTERFACE_VERSION, NULL);
  222. engine = (IVEngineClient *)factory( VENGINE_CLIENT_INTERFACE_VERSION, NULL );
  223. #if defined( BINK_VIDEO )
  224. bik = (IBik*)factory( BIK_INTERFACE_VERSION, NULL );
  225. #endif
  226. #ifdef _PS3
  227. ps3saveuiapi = (IPS3SaveRestoreToUI*)factory( IPS3SAVEUIAPI_VERSION_STRING, NULL );
  228. cellSysmoduleLoadModule( CELL_SYSMODULE_SYSUTIL_USERINFO );
  229. #endif
  230. #ifndef _GAMECONSOLE
  231. SteamAPI_InitSafe();
  232. steamapicontext->Init();
  233. #endif
  234. CGameUIConVarRef var( "gameui_xbox" );
  235. m_bIsConsoleUI = var.IsValid() && var.GetBool();
  236. vgui::VGui_InitInterfacesList( "GameUI", &factory, 1 );
  237. vgui::VGui_InitMatSysInterfacesList( "GameUI", &factory, 1 );
  238. // load localization file
  239. #if !defined( CSTRIKE15 )
  240. g_pVGuiLocalize->AddFile( "Resource/gameui_%language%.txt", "GAME", true );
  241. #endif
  242. // load mod info
  243. ModInfo().LoadCurrentGameInfo();
  244. // load localization file for kb_act.lst
  245. g_pVGuiLocalize->AddFile( "Resource/valve_%language%.txt", "GAME", true );
  246. bool bFailed = false;
  247. enginevguifuncs = (IEngineVGui *)factory( VENGINE_VGUI_VERSION, NULL );
  248. enginesurfacefuncs = (vgui::ISurface *)factory(VGUI_SURFACE_INTERFACE_VERSION, NULL);
  249. gameuifuncs = (IGameUIFuncs *)factory( VENGINE_GAMEUIFUNCS_VERSION, NULL );
  250. xboxsystem = (IXboxSystem *)factory( XBOXSYSTEM_INTERFACE_VERSION, NULL );
  251. // dgoodenough - xonline only exists on the 360.
  252. // PS3_BUILDFIX
  253. #ifdef _X360
  254. xonline = (IXOnline *)factory( XONLINE_INTERFACE_VERSION, NULL );
  255. #endif
  256. #ifdef SWARM_DLL
  257. g_pMatchExtSwarm = ( IMatchExtSwarm * ) factory( IMATCHEXT_SWARM_INTERFACE, NULL );
  258. #endif
  259. bFailed = !enginesurfacefuncs || !gameuifuncs || !enginevguifuncs ||
  260. !xboxsystem ||
  261. // dgoodenough - xonline only exists on the 360.
  262. // PS3_BUILDFIX
  263. #ifdef _X360
  264. !xonline ||
  265. #endif
  266. #ifdef SWARM_DLL
  267. !g_pMatchExtSwarm ||
  268. #endif
  269. !g_pMatchFramework;
  270. #ifdef PANORAMA_ENABLE
  271. panorama::IUIEngine *pPanoramaUIEngine = g_pPanoramaUIEngine->AccessUIEngine();
  272. Assert( pPanoramaUIEngine );
  273. if ( !pPanoramaUIEngine )
  274. {
  275. bFailed = true;
  276. }
  277. else
  278. {
  279. ConnectPanoramaUIEngine( pPanoramaUIEngine );
  280. }
  281. if (!CommandLine()->CheckParm("-nopanorama"))
  282. {
  283. FOR_EACH_VEC(m_arrUiComponents, i)
  284. {
  285. m_arrUiComponents[i]->InstallPanoramaBindings();
  286. }
  287. }
  288. #endif
  289. if ( bFailed )
  290. {
  291. Error( "CGameUI::Initialize() failed to get necessary interfaces\n" );
  292. }
  293. // setup base panel
  294. UI_BASEMOD_PANEL_CLASS& factoryBasePanel = ConstructUiBaseModPanelClass(); // explicit singleton instantiation
  295. factoryBasePanel.SetBounds( 0, 0, 640, 480 );
  296. factoryBasePanel.SetPaintBorderEnabled( false );
  297. factoryBasePanel.SetPaintBackgroundEnabled( true );
  298. factoryBasePanel.SetPaintEnabled( true );
  299. factoryBasePanel.SetVisible( true );
  300. factoryBasePanel.SetMouseInputEnabled( IsPC() );
  301. // factoryBasePanel.SetKeyBoardInputEnabled( IsPC() );
  302. factoryBasePanel.SetKeyBoardInputEnabled( true );
  303. vgui::VPANEL rootpanel = enginevguifuncs->GetPanel( PANEL_GAMEUIDLL );
  304. factoryBasePanel.SetParent( rootpanel );
  305. }
  306. void CGameUI::PostInit()
  307. {
  308. if ( IsGameConsole() )
  309. {
  310. enginesound->PrecacheSound( "UI/buttonrollover.wav", true, true );
  311. enginesound->PrecacheSound( "UI/buttonclick.wav", true, true );
  312. enginesound->PrecacheSound( "UI/buttonclickrelease.wav", true, true );
  313. enginesound->PrecacheSound( "player/suit_denydevice.wav", true, true );
  314. enginesound->PrecacheSound( "UI/menu_accept.wav", true, true );
  315. enginesound->PrecacheSound( "UI/menu_focus.wav", true, true );
  316. enginesound->PrecacheSound( "UI/menu_invalid.wav", true, true );
  317. enginesound->PrecacheSound( "UI/menu_back.wav", true, true );
  318. }
  319. #ifdef SWARM_DLL
  320. // to know once client dlls have been loaded
  321. BaseModUI::CUIGameData::Get()->OnGameUIPostInit();
  322. #endif
  323. }
  324. //-----------------------------------------------------------------------------
  325. // Purpose: Sets the specified panel as the background panel for the loading
  326. // dialog. If NULL, default background is used. If you set a panel,
  327. // it should be full-screen with an opaque background, and must be a VGUI popup.
  328. //-----------------------------------------------------------------------------
  329. void CGameUI::SetLoadingBackgroundDialog( vgui::VPANEL panel )
  330. {
  331. g_hLoadingBackgroundDialog = panel;
  332. }
  333. //-----------------------------------------------------------------------------
  334. // Purpose: connects to client interfaces
  335. //-----------------------------------------------------------------------------
  336. void CGameUI::Connect( CreateInterfaceFn gameFactory )
  337. {
  338. g_pGameClientExports = (IGameClientExports *)gameFactory(GAMECLIENTEXPORTS_INTERFACE_VERSION, NULL);
  339. #if defined( INCLUDE_SCALEFORM )
  340. g_pScaleformUI = ( IScaleformUI* ) gameFactory( SCALEFORMUI_INTERFACE_VERSION, NULL );
  341. #endif
  342. achievementmgr = engine->GetAchievementMgr();
  343. if (!g_pGameClientExports)
  344. {
  345. Error("CGameUI::Initialize() failed to get necessary interfaces\n");
  346. }
  347. m_GameFactory = gameFactory;
  348. }
  349. //-----------------------------------------------------------------------------
  350. // Purpose: Callback function; sends platform Shutdown message to specified window
  351. //-----------------------------------------------------------------------------
  352. int __stdcall SendShutdownMsgFunc(WHANDLE hwnd, int lparam)
  353. {
  354. Sys_PostMessage(hwnd, Sys_RegisterWindowMessage("ShutdownValvePlatform"), 0, 1);
  355. return 1;
  356. }
  357. //-----------------------------------------------------------------------------
  358. // Purpose: Searches for GameStartup*.mp3 files in the sound/ui folder and plays one
  359. //-----------------------------------------------------------------------------
  360. void CGameUI::PlayGameStartupSound()
  361. {
  362. #if defined( LEFT4DEAD ) || defined( CSTRIKE15 )
  363. // CS15 not using this path. using Portal 2 style MP3 looping
  364. // L4D not using this path, L4D UI now handling with background menu movies
  365. return;
  366. #endif
  367. if ( IsGameConsole() )
  368. return;
  369. if ( CommandLine()->FindParm( "-nostartupsound" ) )
  370. return;
  371. FileFindHandle_t fh;
  372. CUtlVector<char *> fileNames;
  373. char path[ 512 ];
  374. Q_snprintf( path, sizeof( path ), "sound/ui/gamestartup*.mp3" );
  375. Q_FixSlashes( path );
  376. char const *fn = g_pFullFileSystem->FindFirstEx( path, "MOD", &fh );
  377. if ( fn )
  378. {
  379. do
  380. {
  381. char ext[ 10 ];
  382. Q_ExtractFileExtension( fn, ext, sizeof( ext ) );
  383. if ( !Q_stricmp( ext, "mp3" ) )
  384. {
  385. char temp[ 512 ];
  386. Q_snprintf( temp, sizeof( temp ), "ui/%s", fn );
  387. char *found = new char[ strlen( temp ) + 1 ];
  388. Q_strncpy( found, temp, strlen( temp ) + 1 );
  389. Q_FixSlashes( found );
  390. fileNames.AddToTail( found );
  391. }
  392. fn = g_pFullFileSystem->FindNext( fh );
  393. } while ( fn );
  394. g_pFullFileSystem->FindClose( fh );
  395. }
  396. // did we find any?
  397. if ( fileNames.Count() > 0 )
  398. {
  399. // dgoodenough - SystemTime is absent on PS3, just select first file for now
  400. // PS3_BUILDFIX
  401. // FIXME - we need to find some sort of entropy here and select based on that.
  402. // @wge Fix for OSX too.
  403. #if defined( _PS3 ) || defined( _OSX ) || defined (LINUX)
  404. int index = 0;
  405. #else
  406. SYSTEMTIME SystemTime;
  407. GetSystemTime( &SystemTime );
  408. int index = SystemTime.wMilliseconds % fileNames.Count();
  409. #endif
  410. if ( fileNames.IsValidIndex( index ) && fileNames[index] )
  411. {
  412. char found[ 512 ];
  413. // escape chars "*#" make it stream, and be affected by snd_musicvolume
  414. Q_snprintf( found, sizeof( found ), "play *#%s", fileNames[index] );
  415. engine->ClientCmd_Unrestricted( found );
  416. }
  417. fileNames.PurgeAndDeleteElements();
  418. }
  419. }
  420. //-----------------------------------------------------------------------------
  421. // Purpose: Called to setup the game UI
  422. //-----------------------------------------------------------------------------
  423. void CGameUI::Start()
  424. {
  425. // determine Steam location for configuration
  426. if ( !FindPlatformDirectory( m_szPlatformDir, sizeof( m_szPlatformDir ) ) )
  427. return;
  428. if ( IsPC() )
  429. {
  430. // setup config file directory
  431. char szConfigDir[512];
  432. Q_strncpy( szConfigDir, m_szPlatformDir, sizeof( szConfigDir ) );
  433. Q_strncat( szConfigDir, "config", sizeof( szConfigDir ), COPY_ALL_CHARACTERS );
  434. Msg( "Steam config directory: %s\n", szConfigDir );
  435. g_pFullFileSystem->AddSearchPath(szConfigDir, "CONFIG");
  436. g_pFullFileSystem->CreateDirHierarchy("", "CONFIG");
  437. // user dialog configuration
  438. vgui::system()->SetUserConfigFile("InGameDialogConfig.vdf", "CONFIG");
  439. g_pFullFileSystem->AddSearchPath( "platform", "PLATFORM" );
  440. }
  441. // localization
  442. g_pVGuiLocalize->AddFile( "Resource/platform_%language%.txt");
  443. g_pVGuiLocalize->AddFile( "Resource/vgui_%language%.txt");
  444. // dgoodenough - This should not be necessary.
  445. // PS3_BUILDFIX
  446. // FIXME - I have no idea why I need to remove this. SYS_NO_ERROR is defined in sys_utils.h
  447. // which is included at the top of this file. It compiles fine, proving the definition is good.
  448. // However it throws a link time error against SYS_NO_ERROR. This is *declared* in sys_utils.cpp
  449. // which is the same place that Sys_SetLastError(...) is declared. Why then does one of these
  450. // throw a link time error, when the other does not? Probably a GCC quirk, since MSVC has no
  451. // problem with it. In any case, Sys_SetLastError(...) does nothing on PS3, so removing the
  452. // call to it here is harmless.
  453. #if !defined( _PS3 )
  454. Sys_SetLastError( SYS_NO_ERROR );
  455. #endif
  456. // ********************************************************************
  457. // The following is commented out to keep intro music from playing
  458. // before the intro movie:
  459. //
  460. //// Delay playing the startup music until two frames
  461. //// this allows cbuf commands that occur on the first frame that may start a map
  462. //m_iPlayGameStartupSound = 2;
  463. //SetBackgroundMusicDesired( true );
  464. // ********************************************************************
  465. if ( IsPC() )
  466. {
  467. // now we are set up to check every frame to see if we can friends/server browser
  468. m_bTryingToLoadFriends = true;
  469. m_iFriendsLoadPauseFrames = 1;
  470. }
  471. }
  472. //-----------------------------------------------------------------------------
  473. // Purpose: Validates the user has a cdkey in the registry
  474. //-----------------------------------------------------------------------------
  475. void CGameUI::ValidateCDKey()
  476. {
  477. }
  478. //-----------------------------------------------------------------------------
  479. // Purpose: Finds which directory the platform resides in
  480. // Output : Returns true on success, false on failure.
  481. //-----------------------------------------------------------------------------
  482. bool CGameUI::FindPlatformDirectory(char *platformDir, int bufferSize)
  483. {
  484. platformDir[0] = '\0';
  485. if ( platformDir[0] == '\0' )
  486. {
  487. // we're not under steam, so setup using path relative to game
  488. if ( IsPC() )
  489. {
  490. #ifdef WIN32
  491. if ( ::GetModuleFileName( ( HINSTANCE )GetModuleHandle( NULL ), platformDir, bufferSize ) )
  492. #else
  493. if ( getcwd( platformDir, bufferSize ) )
  494. #endif
  495. {
  496. #ifdef WIN32
  497. V_StripFilename( platformDir ); // GetModuleFileName returns the exe as well as path
  498. #endif
  499. V_AppendSlash( platformDir, bufferSize );
  500. Q_strncat(platformDir, "platform", bufferSize, COPY_ALL_CHARACTERS );
  501. V_AppendSlash( platformDir, bufferSize );
  502. return true;
  503. }
  504. }
  505. else
  506. {
  507. // xbox fetches the platform path from exisiting platform search path
  508. // path to executeable is not correct for xbox remote configuration
  509. if ( g_pFullFileSystem->GetSearchPath( "PLATFORM", false, platformDir, bufferSize ) )
  510. {
  511. char *pSeperator = strchr( platformDir, ';' );
  512. if ( pSeperator )
  513. *pSeperator = '\0';
  514. return true;
  515. }
  516. }
  517. Error( "Unable to determine platform directory\n" );
  518. return false;
  519. }
  520. return (platformDir[0] != 0);
  521. }
  522. //-----------------------------------------------------------------------------
  523. // Purpose: Called to Shutdown the game UI system
  524. //-----------------------------------------------------------------------------
  525. void CGameUI::Shutdown()
  526. {
  527. #ifdef _PS3
  528. cellSysmoduleUnloadModule( CELL_SYSMODULE_SYSUTIL_USERINFO );
  529. #endif
  530. // notify all the modules of Shutdown
  531. g_VModuleLoader.ShutdownPlatformModules();
  532. // unload the modules them from memory
  533. g_VModuleLoader.UnloadPlatformModules();
  534. ModInfo().FreeModInfo();
  535. steamapicontext->Clear();
  536. #ifndef _GAMECONSOLE
  537. // SteamAPI_Shutdown(); << Steam shutdown is controlled by engine
  538. #endif
  539. ConVar_Unregister();
  540. DisconnectTier3Libraries();
  541. DisconnectTier2Libraries();
  542. DisconnectTier1Libraries();
  543. }
  544. //-----------------------------------------------------------------------------
  545. // Purpose: just wraps an engine call to activate the gameUI
  546. //-----------------------------------------------------------------------------
  547. void CGameUI::ActivateGameUI()
  548. {
  549. engine->ExecuteClientCmd("gameui_activate");
  550. // Lock the UI to a particular player
  551. SetGameUIActiveSplitScreenPlayerSlot( engine->GetActiveSplitScreenPlayerSlot() );
  552. }
  553. //-----------------------------------------------------------------------------
  554. // Purpose: just wraps an engine call to hide the gameUI
  555. //-----------------------------------------------------------------------------
  556. void CGameUI::HideGameUI()
  557. {
  558. engine->ExecuteClientCmd("gameui_hide");
  559. GameConsole().HideImmediately();
  560. }
  561. //-----------------------------------------------------------------------------
  562. // Purpose: Toggle allowing the engine to hide the game UI with the escape key
  563. //-----------------------------------------------------------------------------
  564. void CGameUI::PreventEngineHideGameUI()
  565. {
  566. engine->ExecuteClientCmd("gameui_preventescape");
  567. }
  568. //-----------------------------------------------------------------------------
  569. // Purpose: Toggle allowing the engine to hide the game UI with the escape key
  570. //-----------------------------------------------------------------------------
  571. void CGameUI::AllowEngineHideGameUI()
  572. {
  573. engine->ExecuteClientCmd("gameui_allowescape");
  574. }
  575. //-----------------------------------------------------------------------------
  576. // Purpose: Activate the game UI
  577. //-----------------------------------------------------------------------------
  578. void CGameUI::OnGameUIActivated()
  579. {
  580. bool bWasActive = m_bActivatedUI;
  581. m_bActivatedUI = true;
  582. // Lock the UI to a particular player
  583. if ( !bWasActive )
  584. {
  585. SetGameUIActiveSplitScreenPlayerSlot( engine->GetActiveSplitScreenPlayerSlot() );
  586. }
  587. // pause the server in case it is pausable
  588. engine->ClientCmd_Unrestricted( "setpause nomsg" );
  589. SetSavedThisMenuSession( false );
  590. UI_BASEMOD_PANEL_CLASS &ui = GetUiBaseModPanelClass();
  591. bool bNeedActivation = true;
  592. if ( ui.IsVisible() )
  593. {
  594. // Already visible, maybe don't need activation
  595. if ( !IsInLevel() && IsInBackgroundLevel() )
  596. bNeedActivation = false;
  597. }
  598. if ( bNeedActivation )
  599. {
  600. GetUiBaseModPanelClass().OnGameUIActivated();
  601. }
  602. }
  603. //-----------------------------------------------------------------------------
  604. // Purpose: Hides the game ui, in whatever state it's in
  605. //-----------------------------------------------------------------------------
  606. void CGameUI::OnGameUIHidden()
  607. {
  608. bool bWasActive = m_bActivatedUI;
  609. m_bActivatedUI = false;
  610. // unpause the game when leaving the UI
  611. engine->ClientCmd_Unrestricted( "unpause nomsg" );
  612. GetUiBaseModPanelClass().OnGameUIHidden();
  613. // Restore to default
  614. if ( bWasActive )
  615. {
  616. SetGameUIActiveSplitScreenPlayerSlot( 0 );
  617. }
  618. }
  619. //-----------------------------------------------------------------------------
  620. // Purpose: paints all the vgui elements
  621. //-----------------------------------------------------------------------------
  622. void CGameUI::RunFrame()
  623. {
  624. if ( IsGameConsole() && m_bOpenProgressOnStart )
  625. {
  626. StartProgressBar();
  627. m_bOpenProgressOnStart = false;
  628. }
  629. int wide, tall;
  630. #if defined( TOOLFRAMEWORK_VGUI_REFACTOR )
  631. // resize the background panel to the screen size
  632. vgui::VPANEL clientDllPanel = enginevguifuncs->GetPanel( PANEL_ROOT );
  633. int x, y;
  634. vgui::ipanel()->GetPos( clientDllPanel, x, y );
  635. vgui::ipanel()->GetSize( clientDllPanel, wide, tall );
  636. staticPanel->SetBounds( x, y, wide,tall );
  637. #else
  638. vgui::surface()->GetScreenSize(wide, tall);
  639. GetUiBaseModPanelClass().SetSize(wide, tall);
  640. #endif
  641. // Run frames
  642. g_VModuleLoader.RunFrame();
  643. GetUiBaseModPanelClass().RunFrame();
  644. FOR_EACH_VEC( m_arrUiComponents, i )
  645. {
  646. m_arrUiComponents[ i ]->Tick();
  647. }
  648. // Play the start-up music the first time we run frame
  649. if ( m_iPlayGameStartupSound > 0 )
  650. {
  651. m_iPlayGameStartupSound--;
  652. }
  653. else
  654. {
  655. UpdateBackgroundMusic();
  656. }
  657. if ( IsPC() && m_bTryingToLoadFriends && m_iFriendsLoadPauseFrames-- < 1 )
  658. {
  659. // we got the mutex, so load Friends/Serverbrowser
  660. // clear the loading flag
  661. m_bTryingToLoadFriends = false;
  662. g_VModuleLoader.LoadPlatformModules(&m_GameFactory, 1, false);
  663. // notify the game of our game name
  664. const char *fullGamePath = engine->GetGameDirectory();
  665. const char *pathSep = strrchr( fullGamePath, '/' );
  666. if ( !pathSep )
  667. {
  668. pathSep = strrchr( fullGamePath, '\\' );
  669. }
  670. if ( pathSep )
  671. {
  672. KeyValues *pKV = new KeyValues("ActiveGameName" );
  673. pKV->SetString( "name", pathSep + 1 );
  674. pKV->SetInt( "appid", engine->GetAppID() );
  675. KeyValues *modinfo = new KeyValues("ModInfo");
  676. if ( modinfo->LoadFromFile( g_pFullFileSystem, "gameinfo.txt" ) )
  677. {
  678. pKV->SetString( "game", modinfo->GetString( "game", "" ) );
  679. }
  680. modinfo->deleteThis();
  681. g_VModuleLoader.PostMessageToAllModules( pKV );
  682. }
  683. // notify the ui of a game connect if we're already in a game
  684. if (m_iGameIP)
  685. {
  686. SendConnectedToGameMessage();
  687. }
  688. }
  689. }
  690. //-----------------------------------------------------------------------------
  691. // Purpose: Called when the game connects to a server
  692. //-----------------------------------------------------------------------------
  693. void CGameUI::OLD_OnConnectToServer(const char *game, int IP, int port)
  694. {
  695. // Nobody should use this anymore because the query port and the connection port can be different.
  696. // Use OnConnectToServer2 instead.
  697. Assert( false );
  698. OnConnectToServer2( game, IP, port, port );
  699. }
  700. //-----------------------------------------------------------------------------
  701. // Purpose: Called when the game connects to a server
  702. //-----------------------------------------------------------------------------
  703. void CGameUI::OnConnectToServer2(const char *game, int IP, int connectionPort, int queryPort)
  704. {
  705. m_iGameIP = IP;
  706. m_iGameConnectionPort = connectionPort;
  707. m_iGameQueryPort = queryPort;
  708. SendConnectedToGameMessage();
  709. }
  710. void CGameUI::SendConnectedToGameMessage()
  711. {
  712. MEM_ALLOC_CREDIT();
  713. KeyValues *kv = new KeyValues( "ConnectedToGame" );
  714. kv->SetInt( "ip", m_iGameIP );
  715. kv->SetInt( "connectionport", m_iGameConnectionPort );
  716. kv->SetInt( "queryport", m_iGameQueryPort );
  717. g_VModuleLoader.PostMessageToAllModules( kv );
  718. }
  719. //-----------------------------------------------------------------------------
  720. // Purpose: Called when the game disconnects from a server
  721. //-----------------------------------------------------------------------------
  722. void CGameUI::OnDisconnectFromServer( uint8 eSteamLoginFailure )
  723. {
  724. m_iGameIP = 0;
  725. m_iGameConnectionPort = 0;
  726. m_iGameQueryPort = 0;
  727. if ( g_hLoadingBackgroundDialog )
  728. {
  729. vgui::ivgui()->PostMessage( g_hLoadingBackgroundDialog, new KeyValues("DisconnectedFromGame"), NULL );
  730. }
  731. IGameEvent *event = gameeventmanager->CreateEvent( "client_disconnect" );
  732. if ( event )
  733. {
  734. gameeventmanager->FireEventClientSide( event );
  735. }
  736. g_VModuleLoader.PostMessageToAllModules(new KeyValues("DisconnectedFromGame"));
  737. if ( eSteamLoginFailure == STEAMLOGINFAILURE_NOSTEAMLOGIN )
  738. {
  739. CLoadingScreenScaleform::DisplayNoSteamConnectionError();
  740. }
  741. else if ( eSteamLoginFailure == STEAMLOGINFAILURE_VACBANNED )
  742. {
  743. CLoadingScreenScaleform::DisplayVACBannedError();
  744. }
  745. else if ( eSteamLoginFailure == STEAMLOGINFAILURE_LOGGED_IN_ELSEWHERE )
  746. {
  747. CLoadingScreenScaleform::DisplayLoggedInElsewhereError();
  748. }
  749. }
  750. //-----------------------------------------------------------------------------
  751. // Purpose: activates the loading dialog on level load start
  752. //-----------------------------------------------------------------------------
  753. void CGameUI::OnLevelLoadingStarted( const char *levelName, bool bShowProgressDialog )
  754. {
  755. GameUI().HideGameUI();
  756. char mapName[MAX_PATH];
  757. V_strcpy_safe( mapName, levelName ? levelName : "" );
  758. V_FixSlashes( mapName, '/' );
  759. g_VModuleLoader.PostMessageToAllModules( new KeyValues( "LoadingStarted" ) );
  760. GetUiBaseModPanelClass().OnLevelLoadingStarted( mapName, bShowProgressDialog );
  761. if ( bShowProgressDialog )
  762. {
  763. StartProgressBar();
  764. }
  765. // Don't play the start game sound if this happens before we get to the first frame
  766. m_iPlayGameStartupSound = 0;
  767. }
  768. extern ConVar devCheatSkipInputLocking;
  769. //-----------------------------------------------------------------------------
  770. // Purpose: closes any level load dialog
  771. //-----------------------------------------------------------------------------
  772. void CGameUI::OnLevelLoadingFinished(bool bError, const char *failureReason, const char *extendedReason)
  773. {
  774. StopProgressBar( bError, failureReason, extendedReason );
  775. #if defined( WIN32 )
  776. if ( g_pScaleformUI && !devCheatSkipInputLocking.GetBool() )
  777. {
  778. if( g_pInputSystem->GetCurrentInputDevice( ) == INPUT_DEVICE_NONE )
  779. {
  780. g_pInputSystem->SetCurrentInputDevice( INPUT_DEVICE_KEYBOARD_MOUSE );
  781. ConVarRef var( "joystick" );
  782. if( var.IsValid( ) )
  783. var.SetValue( 0 );
  784. }
  785. }
  786. #endif
  787. // notify all the modules
  788. g_VModuleLoader.PostMessageToAllModules( new KeyValues( "LoadingFinished" ) );
  789. GetUiBaseModPanelClass().OnLevelLoadingFinished();
  790. HideLoadingBackgroundDialog();
  791. #if defined( PORTAL )
  792. Warning( "HACK: Forcing all of gameui to hide on level load for portal. For some reason it stays open for us and it's annoying. Especially on xbox where it steals our controller focus.\n" );
  793. HideGameUI();
  794. #endif
  795. #if defined( DOTA_DLL )
  796. // Similar story for DOTA.
  797. HideGameUI();
  798. #endif
  799. #if defined ( CSTRIKE_DLL )
  800. // ditto cstrike
  801. HideGameUI();
  802. #endif
  803. }
  804. //-----------------------------------------------------------------------------
  805. // Purpose: Updates progress bar
  806. // Output : Returns true if screen should be redrawn
  807. //-----------------------------------------------------------------------------
  808. bool CGameUI::UpdateProgressBar(float progress, const char *statusText, bool showDialog )
  809. {
  810. // if either the progress bar or the status text changes, redraw the screen
  811. bool bRedraw = false;
  812. if ( ContinueProgressBar( progress, showDialog ) )
  813. {
  814. bRedraw = true;
  815. }
  816. if ( SetProgressBarStatusText( statusText, showDialog ) )
  817. {
  818. bRedraw = true;
  819. }
  820. return bRedraw;
  821. }
  822. //-----------------------------------------------------------------------------
  823. // Purpose: Updates progress bar
  824. // Output : Returns true if screen should be redrawn
  825. //-----------------------------------------------------------------------------
  826. bool CGameUI::UpdateSecondaryProgressBar(float progress, const wchar_t *desc )
  827. {
  828. // if either the progress bar or the status text changes, redraw the screen
  829. SetSecondaryProgressBar( progress );
  830. SetSecondaryProgressBarText( desc );
  831. return true;
  832. }
  833. //-----------------------------------------------------------------------------
  834. // Purpose:
  835. //-----------------------------------------------------------------------------
  836. void CGameUI::SetProgressLevelName( const char *levelName )
  837. {
  838. MEM_ALLOC_CREDIT();
  839. if ( g_hLoadingBackgroundDialog )
  840. {
  841. KeyValues *pKV = new KeyValues( "ProgressLevelName" );
  842. pKV->SetString( "levelName", levelName );
  843. vgui::ivgui()->PostMessage( g_hLoadingBackgroundDialog, pKV, NULL );
  844. }
  845. }
  846. //-----------------------------------------------------------------------------
  847. // Purpose:
  848. //-----------------------------------------------------------------------------
  849. void CGameUI::StartProgressBar()
  850. {
  851. // open a loading dialog
  852. m_szPreviousStatusText[0] = 0;
  853. CLoadingScreenScaleform::SetProgressPoint( 0.0f );
  854. CLoadingScreenScaleform::Open();
  855. }
  856. //-----------------------------------------------------------------------------
  857. // Purpose: returns true if the screen should be updated
  858. //-----------------------------------------------------------------------------
  859. bool CGameUI::ContinueProgressBar( float progressFraction, bool showDialog )
  860. {
  861. CLoadingScreenScaleform::Activate();
  862. return CLoadingScreenScaleform::SetProgressPoint( progressFraction, showDialog );
  863. }
  864. //-----------------------------------------------------------------------------
  865. // Purpose: stops progress bar, displays error if necessary
  866. //-----------------------------------------------------------------------------
  867. void CGameUI::StopProgressBar(bool bError, const char *failureReason, const char *extendedReason)
  868. {
  869. if ( IsInLevel() )
  870. {
  871. CLoadingScreenScaleform::FinishLoading();
  872. }
  873. else
  874. {
  875. CLoadingScreenScaleform::CloseLoadingScreen();
  876. }
  877. // CStrike15 handles error messages elsewhere. (ClientModeCSFullscreen::OnEvent)
  878. #if !defined( CSTRIKE15 )
  879. if ( !IsGameConsole() && bError )
  880. {
  881. ShowMessageDialog( extendedReason, failureReason );
  882. }
  883. #endif
  884. }
  885. //-----------------------------------------------------------------------------
  886. // Purpose: sets loading info text
  887. //-----------------------------------------------------------------------------
  888. bool CGameUI::SetProgressBarStatusText(const char *statusText, bool showDialog )
  889. {
  890. if (!statusText)
  891. return false;
  892. if (!stricmp(statusText, m_szPreviousStatusText))
  893. return false;
  894. CLoadingScreenScaleform::SetStatusText( statusText, showDialog );
  895. Q_strncpy(m_szPreviousStatusText, statusText, sizeof(m_szPreviousStatusText));
  896. return true;
  897. }
  898. //-----------------------------------------------------------------------------
  899. // Purpose:
  900. //-----------------------------------------------------------------------------
  901. void CGameUI::SetSecondaryProgressBar(float progress /* range [0..1] */)
  902. {
  903. CLoadingScreenScaleform::SetSecondaryProgress( progress );
  904. }
  905. //-----------------------------------------------------------------------------
  906. // Purpose:
  907. //-----------------------------------------------------------------------------
  908. void CGameUI::SetSecondaryProgressBarText( const wchar_t *desc )
  909. {
  910. if (!desc)
  911. return;
  912. CLoadingScreenScaleform::SetSecondaryProgressText( desc );
  913. }
  914. //-----------------------------------------------------------------------------
  915. // Purpose: Returns prev settings
  916. //-----------------------------------------------------------------------------
  917. bool CGameUI::SetShowProgressText( bool show )
  918. {
  919. return CLoadingScreenScaleform::SetShowProgressText( show );
  920. }
  921. //-----------------------------------------------------------------------------
  922. // Purpose: returns true if we're currently playing the game
  923. //-----------------------------------------------------------------------------
  924. bool CGameUI::IsInLevel()
  925. {
  926. const char *levelName = engine->GetLevelName();
  927. if (levelName && levelName[0] && !engine->IsLevelMainMenuBackground())
  928. {
  929. return true;
  930. }
  931. return false;
  932. }
  933. //-----------------------------------------------------------------------------
  934. // Purpose: returns true if we're at the main menu and a background level is loaded
  935. //-----------------------------------------------------------------------------
  936. bool CGameUI::IsInBackgroundLevel()
  937. {
  938. const char *levelName = engine->GetLevelName();
  939. if (levelName && levelName[0] && engine->IsLevelMainMenuBackground())
  940. {
  941. return true;
  942. }
  943. return false;
  944. }
  945. //-----------------------------------------------------------------------------
  946. // Purpose: returns true if we're in a multiplayer game
  947. //-----------------------------------------------------------------------------
  948. bool CGameUI::IsInMultiplayer()
  949. {
  950. return (IsInLevel() && engine->GetMaxClients() > 1);
  951. }
  952. //-----------------------------------------------------------------------------
  953. // Purpose: returns true if we're console ui
  954. //-----------------------------------------------------------------------------
  955. bool CGameUI::IsConsoleUI()
  956. {
  957. return m_bIsConsoleUI;
  958. }
  959. //-----------------------------------------------------------------------------
  960. // Purpose: returns true if we've saved without closing the menu
  961. //-----------------------------------------------------------------------------
  962. bool CGameUI::HasSavedThisMenuSession()
  963. {
  964. return m_bHasSavedThisMenuSession;
  965. }
  966. void CGameUI::SetSavedThisMenuSession( bool bState )
  967. {
  968. m_bHasSavedThisMenuSession = bState;
  969. }
  970. //-----------------------------------------------------------------------------
  971. // Purpose: Makes the loading background dialog visible, if one has been set
  972. //-----------------------------------------------------------------------------
  973. void CGameUI::ShowLoadingBackgroundDialog()
  974. {
  975. if ( g_hLoadingBackgroundDialog )
  976. {
  977. vgui::VPANEL panel = GetUiBaseModPanelClass().GetVPanel();
  978. vgui::ipanel()->SetParent( g_hLoadingBackgroundDialog, panel );
  979. vgui::ipanel()->MoveToFront( g_hLoadingBackgroundDialog );
  980. }
  981. }
  982. //-----------------------------------------------------------------------------
  983. // Purpose: Hides the loading background dialog, if one has been set
  984. //-----------------------------------------------------------------------------
  985. void CGameUI::HideLoadingBackgroundDialog()
  986. {
  987. if ( g_hLoadingBackgroundDialog )
  988. {
  989. if ( engine->IsInGame() )
  990. {
  991. vgui::ivgui()->PostMessage( g_hLoadingBackgroundDialog, new KeyValues( "LoadedIntoGame" ), NULL );
  992. }
  993. else
  994. {
  995. vgui::ipanel()->SetVisible( g_hLoadingBackgroundDialog, false );
  996. vgui::ipanel()->MoveToBack( g_hLoadingBackgroundDialog );
  997. }
  998. vgui::ivgui()->PostMessage( g_hLoadingBackgroundDialog, new KeyValues("HideAsLoadingPanel"), NULL );
  999. }
  1000. }
  1001. //-----------------------------------------------------------------------------
  1002. // Purpose: Returns whether a loading background dialog has been set
  1003. //-----------------------------------------------------------------------------
  1004. bool CGameUI::HasLoadingBackgroundDialog()
  1005. {
  1006. return ( NULL != g_hLoadingBackgroundDialog );
  1007. }
  1008. //-----------------------------------------------------------------------------
  1009. // Purpose: Xbox 360 calls from engine to GameUI
  1010. //-----------------------------------------------------------------------------
  1011. void CGameUI::ShowMessageDialog( const uint nType, vgui::Panel *pOwner )
  1012. {
  1013. BasePanel()->ShowMessageDialog( nType, pOwner );
  1014. }
  1015. void CGameUI::ShowMessageDialog( const char* messageID, const char* titleID )
  1016. {
  1017. #if defined( CSTRIKE15 )
  1018. ( ( CCStrike15BasePanel* )BasePanel() )->OnOpenMessageBox( titleID, messageID, "#SFUI_Legend_Ok", MESSAGEBOX_FLAG_OK, NULL, NULL );
  1019. #endif
  1020. }
  1021. void CGameUI::CreateCommandMsgBox( const char* pszTitle, const char* pszMessage, bool showOk, bool showCancel, const char* okCommand, const char* cancelCommand, const char* closedCommand, const char* pszLegend )
  1022. {
  1023. #if defined( CSTRIKE15 )
  1024. ( ( CCStrike15BasePanel* )BasePanel() )->CreateCommandMsgBox( pszTitle, pszMessage, showOk, showCancel, okCommand, cancelCommand, closedCommand, pszLegend );
  1025. #endif
  1026. }
  1027. void CGameUI::CreateCommandMsgBoxInSlot( ECommandMsgBoxSlot slot, const char* pszTitle, const char* pszMessage, bool showOk, bool showCancel, const char* okCommand, const char* cancelCommand, const char* closedCommand, const char* pszLegend )
  1028. {
  1029. #if defined( CSTRIKE15 )
  1030. ( ( CCStrike15BasePanel* )BasePanel() )->CreateCommandMsgBoxInSlot( slot, pszTitle, pszMessage, showOk, showCancel, okCommand, cancelCommand, closedCommand, pszLegend );
  1031. #endif
  1032. }
  1033. //-----------------------------------------------------------------------------
  1034. void CGameUI::NeedConnectionProblemWaitScreen()
  1035. {
  1036. #ifdef SWARM_DLL
  1037. BaseModUI::CUIGameData::Get()->NeedConnectionProblemWaitScreen();
  1038. #endif
  1039. }
  1040. void CGameUI::ShowPasswordUI( char const *pchCurrentPW )
  1041. {
  1042. #ifdef SWARM_DLL
  1043. BaseModUI::CUIGameData::Get()->ShowPasswordUI( pchCurrentPW );
  1044. #endif
  1045. }
  1046. //-----------------------------------------------------------------------------
  1047. void CGameUI::SetProgressOnStart()
  1048. {
  1049. m_bOpenProgressOnStart = true;
  1050. }
  1051. #if defined( _GAMECONSOLE ) && defined( _DEMO )
  1052. void CGameUI::OnDemoTimeout()
  1053. {
  1054. GetUiBaseModPanelClass().OnDemoTimeout();
  1055. }
  1056. #endif
  1057. bool CGameUI::IsPlayingFullScreenVideo()
  1058. {
  1059. return false;
  1060. }
  1061. bool CGameUI::IsTransitionEffectEnabled()
  1062. {
  1063. return false;
  1064. }
  1065. void CGameUI::StartLoadingScreenForCommand( const char* command )
  1066. {
  1067. CLoadingScreenScaleform::LoadDialogForCommand( command );
  1068. }
  1069. void CGameUI::StartLoadingScreenForKeyValues( KeyValues* keyValues )
  1070. {
  1071. CLoadingScreenScaleform::LoadDialogForKeyValues( keyValues );
  1072. }
  1073. bool CGameUI::IsBackgroundMusicPlaying( void )
  1074. {
  1075. if ( m_nBackgroundMusicGUID == 0 )
  1076. {
  1077. return false;
  1078. }
  1079. return enginesound->IsSoundStillPlaying( m_nBackgroundMusicGUID );
  1080. }
  1081. void CGameUI::ReleaseBackgroundMusic( void )
  1082. {
  1083. if ( m_nBackgroundMusicGUID == 0 )
  1084. return;
  1085. enginesound->StopSoundByGuid( m_nBackgroundMusicGUID, true );
  1086. #if defined( _GAMECONSOLE )
  1087. char nMusicKit[128];
  1088. V_snprintf( nMusicKit, 128, "music/%03i/%s", m_nBackgroundMusicVersion, BACKGROUND_MUSIC_FILENAME );
  1089. //release this to save on memory
  1090. enginesound->UnloadSound( nMusicKit );
  1091. #endif
  1092. m_nBackgroundMusicGUID = 0;
  1093. }
  1094. //The way to loop an MP3 is just to constantly check if it is playing and restart it otherwise
  1095. #define MENUMUSIC_FADETIME 1.34
  1096. void CGameUI::UpdateBackgroundMusic( void )
  1097. {
  1098. if ( m_bBackgroundMusicDesired && !enginesound->GetPreventSound() )
  1099. {
  1100. const char * pNewMusicExtension = "";
  1101. CSteamID steamIDForPlayer = steamapicontext->SteamUser()->GetSteamID();
  1102. CEconItemView *pItemData = CSInventoryManager()->GetItemInLoadoutForTeam( 0, LOADOUT_POSITION_MUSICKIT, &steamIDForPlayer );
  1103. uint32 unMusicID = 0;
  1104. bool bIsPreview = false;
  1105. if ( m_pPreviewMusicExtension && m_pPreviewMusicExtension[0] )
  1106. {
  1107. pNewMusicExtension = m_pPreviewMusicExtension;
  1108. bIsPreview = true;
  1109. }
  1110. else if ( pItemData && pItemData->IsValid() )
  1111. {
  1112. static const CEconItemAttributeDefinition *pAttr_MusicID = GetItemSchema()->GetAttributeDefinitionByName( "music id" );
  1113. if ( pItemData->FindAttribute( pAttr_MusicID, &unMusicID ) )
  1114. {
  1115. const CEconMusicDefinition *pMusicDef = GetItemSchema()->GetMusicDefinition( unMusicID );
  1116. if ( pMusicDef )
  1117. pNewMusicExtension = pMusicDef->GetName();
  1118. }
  1119. }
  1120. if ( !IsBackgroundMusicPlaying() && !enginesound->IsMoviePlaying() )
  1121. {
  1122. m_flBackgroundMusicStopTime = -1.0;
  1123. char sMusicKit[128];
  1124. m_pMusicExtension = pNewMusicExtension;
  1125. if ( !StringIsEmpty( m_pMusicExtension ) && ( unMusicID > 1 || bIsPreview ) )
  1126. {
  1127. V_sprintf_safe( sMusicKit, "music/%s/%s", m_pMusicExtension, BACKGROUND_MUSIC_FILENAME );
  1128. }
  1129. else
  1130. {
  1131. m_nBackgroundMusicVersion++;
  1132. if ( m_nBackgroundMusicVersion == 1 )
  1133. {
  1134. V_sprintf_safe( sMusicKit, "music/valve_csgo_02/%s", BACKGROUND_MUSIC_FILENAME );
  1135. }
  1136. else
  1137. {
  1138. m_nBackgroundMusicVersion = 0;
  1139. V_sprintf_safe( sMusicKit, "music/valve_csgo_01/%s", BACKGROUND_MUSIC_FILENAME );
  1140. }
  1141. }
  1142. m_nBackgroundMusicGUID = enginesound->EmitAmbientSound( sMusicKit, 1.0 );
  1143. }
  1144. else if ( !FStrEq( pNewMusicExtension, m_pMusicExtension ) )
  1145. {
  1146. ReleaseBackgroundMusic();
  1147. }
  1148. else if( ( m_flBackgroundMusicStopTime > -1.0 ) )
  1149. {
  1150. float flDelta = gpGlobals->curtime - m_flBackgroundMusicStopTime;
  1151. float flFadeAmount = 1.0 - ( flDelta / MENUMUSIC_FADETIME );
  1152. enginesound->SetVolumeByGuid( m_nBackgroundMusicGUID, flFadeAmount );
  1153. if( flFadeAmount < .05 )
  1154. {
  1155. SetBackgroundMusicDesired( false );
  1156. }
  1157. }
  1158. if ( m_nQuestAudioGUID && ( m_flQuestAudioTimeEnd < gpGlobals->curtime ) ) // resume main menu music after quest audio is complete
  1159. {
  1160. // SetBackgroundMusicDesired( true );
  1161. static ConVarRef snd_musicvolume( "snd_musicvolume" );
  1162. static ConVarRef snd_menumusic_volume( "snd_menumusic_volume" );
  1163. snd_musicvolume.SetValue( m_flMasterMusicVolumeSavedForMissionAudio );
  1164. snd_menumusic_volume.SetValue( m_flMenuMusicVolumeSavedForMissionAudio );
  1165. m_flQuestAudioTimeEnd = 0;
  1166. m_nQuestAudioGUID = 0;
  1167. }
  1168. }
  1169. // else if ( m_pAudioFile && m_pAudioFile[ 0 ] )
  1170. // {
  1171. // if ( !IsBackgroundMusicPlaying() )
  1172. // {
  1173. // m_nBackgroundMusicGUID = enginesound->EmitAmbientSound( m_pAudioFile, 1.0 );
  1174. // }
  1175. // }
  1176. else
  1177. {
  1178. ReleaseBackgroundMusic();
  1179. }
  1180. }
  1181. void CGameUI::StartBackgroundMusicFade( void )
  1182. {
  1183. m_flBackgroundMusicStopTime = gpGlobals->curtime;
  1184. }
  1185. void CGameUI::SetBackgroundMusicDesired( bool bPlayMusic )
  1186. {
  1187. m_bBackgroundMusicDesired = bPlayMusic;
  1188. }
  1189. bool CGameUI::LoadingProgressWantsIsolatedRender( bool bContextValid )
  1190. {
  1191. return GetUiBaseModPanelClass().LoadingProgressWantsIsolatedRender( bContextValid );
  1192. }
  1193. void CGameUI::RestoreTopLevelMenu()
  1194. {
  1195. BasePanel()->PostMessage( BasePanel(), new KeyValues( "RunMenuCommand", "command", "RestoreTopLevelMenu" ) );
  1196. }
  1197. void CGameUI::SetPreviewBackgroundMusic( const char * pchPreviewMusicPrefix )
  1198. {
  1199. static ConVarRef snd_menumusic_volume("snd_menumusic_volume");
  1200. static ConVarRef snd_musicvolume("snd_musicvolume");
  1201. // if we're previewing music, store the current volumes and set them to default.
  1202. if ( pchPreviewMusicPrefix && pchPreviewMusicPrefix[0] )
  1203. {
  1204. m_flMainMenuMusicVolume = snd_menumusic_volume.GetFloat();
  1205. m_flMasterMusicVolume = snd_musicvolume.GetFloat();
  1206. snd_menumusic_volume.SetValue( snd_menumusic_volume.GetDefault() );
  1207. snd_musicvolume.SetValue( snd_musicvolume.GetDefault() );
  1208. }
  1209. else
  1210. {
  1211. if ( m_flMainMenuMusicVolume != -1 ) // stored music is not -1 so we are previewing
  1212. {
  1213. snd_menumusic_volume.SetValue( m_flMainMenuMusicVolume );
  1214. snd_musicvolume.SetValue( m_flMasterMusicVolume );
  1215. }
  1216. m_flMainMenuMusicVolume = -1;
  1217. m_flMasterMusicVolume = -1;
  1218. }
  1219. m_pPreviewMusicExtension = pchPreviewMusicPrefix;
  1220. ReleaseBackgroundMusic(); // Even when we preview the musickit we have, we still want to restart the track.
  1221. }
  1222. void CGameUI::PlayQuestAudio( const char * pchAudioFile )
  1223. {
  1224. #define MAINMENU_QUEST_AUDIO_MASTER_VOLUME 1.0
  1225. #define MAINMENU_QUEST_AUDIO_MENUMUSIC_VOLUME 0.01
  1226. if ( !pchAudioFile || !pchAudioFile[0] )
  1227. return;
  1228. if ( m_nQuestAudioGUID )
  1229. return;
  1230. m_flQuestAudioTimeEnd = gpGlobals->curtime + enginesound->GetSoundDuration( pchAudioFile );
  1231. // SetBackgroundMusicDesired( false );
  1232. static ConVarRef snd_musicvolume( "snd_musicvolume" );
  1233. m_flMasterMusicVolumeSavedForMissionAudio = snd_musicvolume.GetFloat();
  1234. if ( ( snd_musicvolume.GetFloat() < MAINMENU_QUEST_AUDIO_MASTER_VOLUME ) )
  1235. {
  1236. snd_musicvolume.SetValue( ( float )MAINMENU_QUEST_AUDIO_MASTER_VOLUME );
  1237. }
  1238. static ConVarRef snd_menumusic_volume("snd_menumusic_volume");
  1239. m_flMenuMusicVolumeSavedForMissionAudio = snd_menumusic_volume.GetFloat();
  1240. if ( ( snd_menumusic_volume.GetFloat() > MAINMENU_QUEST_AUDIO_MENUMUSIC_VOLUME ) )
  1241. {
  1242. snd_menumusic_volume.SetValue( ( float )MAINMENU_QUEST_AUDIO_MENUMUSIC_VOLUME );
  1243. }
  1244. m_nQuestAudioGUID = enginesound->EmitAmbientSound( pchAudioFile, 1.0 );
  1245. if (m_nQuestAudioGUID == 0)
  1246. {
  1247. // Playing music failed for some reason so immediately set the music volume
  1248. // back to its initial value.
  1249. snd_musicvolume.SetValue( m_flMasterMusicVolumeSavedForMissionAudio );
  1250. snd_menumusic_volume.SetValue( m_flMenuMusicVolumeSavedForMissionAudio );
  1251. m_flQuestAudioTimeEnd = gpGlobals->curtime;
  1252. }
  1253. }
  1254. void CGameUI::StopQuestAudio( void )
  1255. {
  1256. enginesound->StopSoundByGuid( m_nQuestAudioGUID, true );
  1257. if ( m_flQuestAudioTimeEnd )
  1258. m_flQuestAudioTimeEnd = gpGlobals->curtime;
  1259. }
  1260. bool CGameUI::IsQuestAudioPlaying( void )
  1261. {
  1262. return ( ( m_nQuestAudioGUID != 0 ) ? true : false );
  1263. }