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.

5854 lines
168 KiB

  1. //===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "uigamedata.h"
  8. #if defined( _WIN32 ) && !defined( _GAMECONSOLE )
  9. #include "winlite.h"
  10. #endif
  11. #include <stdio.h>
  12. #include "threadtools.h"
  13. #include "basepanel.h"
  14. #include "engineinterface.h"
  15. #include "vguisystemmoduleloader.h"
  16. #include "vgui/IInput.h"
  17. #include "vgui/ILocalize.h"
  18. #include "vgui/IPanel.h"
  19. #include "vgui/ISurface.h"
  20. #include "vgui/ISystem.h"
  21. #include "vgui/IVGui.h"
  22. #include "filesystem.h"
  23. #include "gameconsole.h"
  24. #include "gameui_interface.h"
  25. #include <game/client/iviewport.h>
  26. using namespace vgui;
  27. #include "gameconsole.h"
  28. #include "modinfo.h"
  29. #include "IGameUIFuncs.h"
  30. #include "backgroundmenubutton.h"
  31. #include "vgui_controls/AnimationController.h"
  32. #include "vgui_controls/ImagePanel.h"
  33. #include "vgui_controls/Label.h"
  34. #include "vgui_controls/Menu.h"
  35. #include "vgui_controls/MenuItem.h"
  36. #include "vgui_controls/PHandle.h"
  37. #include "vgui_controls/MessageBox.h"
  38. #include "vgui_controls/QueryBox.h"
  39. #include "vgui_controls/ControllerMap.h"
  40. #include "tier0/icommandline.h"
  41. #include "tier1/convar.h"
  42. #include "newgamedialog.h"
  43. #include "bonusmapsdialog.h"
  44. #include "loadgamedialog.h"
  45. #include "savegamedialog.h"
  46. #include "optionsdialog.h"
  47. #include "createmultiplayergamedialog.h"
  48. #include "changegamedialog.h"
  49. #include "backgroundmenubutton.h"
  50. #include "playerlistdialog.h"
  51. #include "benchmarkdialog.h"
  52. #include "loadcommentarydialog.h"
  53. #include "bonusmapsdatabase.h"
  54. #include "engine/IEngineSound.h"
  55. #include "bitbuf.h"
  56. #include "tier1/fmtstr.h"
  57. #include "inputsystem/iinputsystem.h"
  58. #include "ixboxsystem.h"
  59. #include "optionssubaudio.h"
  60. #if defined( _X360 )
  61. #include "../common/xlast_csgo/csgo.spa.h"
  62. #endif
  63. #include "iachievementmgr.h"
  64. #include "customtabexplanationdialog.h"
  65. #include "loadingscreen_scaleform.h"
  66. // dgoodenough - limit this to X360 only
  67. // PS3_BUILDFIX
  68. #if defined( _X360 )
  69. #include "xbox/xbox_launch.h"
  70. #else
  71. #include "xbox/xboxstubs.h"
  72. #endif
  73. #if defined( _PS3)
  74. #include <sysutil/sysutil_userinfo.h>
  75. #endif
  76. #include "matchmaking/imatchframework.h"
  77. #include "matchmaking/mm_helpers.h"
  78. #include "tier1/utlstring.h"
  79. #include "steam/steam_api.h"
  80. #include "byteswap.h"
  81. #include "cdll_client_int.h"
  82. #include "gametypes.h"
  83. #include "game/client/IGameClientExports.h"
  84. #include "VGuiMatSurface/IMatSystemSurface.h"
  85. #include "cbase.h"
  86. #include "cs_shareddefs.h"
  87. #include "itempickup_scaleform.h"
  88. #include "checksum_sha1.h"
  89. #undef MessageBox // Windows helpfully #define's this to MessageBoxA, we're using vgui::MessageBox
  90. // memdbgon must be the last include file in a .cpp file!!!
  91. #include "tier0/memdbgon.h"
  92. #define MAIN_MENU_INDENT_X360 10
  93. ConVar vgui_message_dialog_modal( "vgui_message_dialog_modal", "1", FCVAR_ARCHIVE );
  94. ConVar ui_test_community_matchmaking( "ui_test_community_matchmaking", "0", FCVAR_DEVELOPMENTONLY );
  95. static CBaseModPanel *g_pBasePanel = NULL;
  96. static float g_flAnimationPadding = 0.01f;
  97. extern const char *COM_GetModDirectory( void );
  98. extern bool bSteamCommunityFriendsVersion;
  99. #ifdef _PS3
  100. static CellUserInfoUserStat s_userStat;
  101. #endif
  102. CGameMenuItem::CGameMenuItem(vgui::Menu *parent, const char *name) : BaseClass(parent, name, "GameMenuItem")
  103. {
  104. m_bRightAligned = false;
  105. }
  106. void CGameMenuItem::ApplySchemeSettings(IScheme *pScheme)
  107. {
  108. BaseClass::ApplySchemeSettings(pScheme);
  109. // make fully transparent
  110. SetFgColor(GetSchemeColor("MainMenu.TextColor", pScheme));
  111. SetBgColor(Color(0, 0, 0, 0));
  112. SetDefaultColor(GetSchemeColor("MainMenu.TextColor", pScheme), Color(0, 0, 0, 0));
  113. SetArmedColor(GetSchemeColor("MainMenu.ArmedTextColor", pScheme), Color(0, 0, 0, 0));
  114. SetDepressedColor(GetSchemeColor("MainMenu.DepressedTextColor", pScheme), Color(0, 0, 0, 0));
  115. SetContentAlignment(Label::a_west);
  116. SetBorder(NULL);
  117. SetDefaultBorder(NULL);
  118. SetDepressedBorder(NULL);
  119. SetKeyFocusBorder(NULL);
  120. vgui::HFont hMainMenuFont = pScheme->GetFont( "MainMenuFont", false);
  121. if ( hMainMenuFont )
  122. {
  123. SetFont( hMainMenuFont );
  124. }
  125. else
  126. {
  127. SetFont( pScheme->GetFont( "MenuLarge", false ) );
  128. }
  129. SetTextInset(0, 0);
  130. SetArmedSound("UI/buttonrollover.wav");
  131. SetDepressedSound("UI/buttonclick.wav");
  132. SetReleasedSound("UI/buttonclickrelease.wav");
  133. SetButtonActivationType(Button::ACTIVATE_ONPRESSED);
  134. if ( GameUI().IsConsoleUI() )
  135. {
  136. SetArmedColor(GetSchemeColor("MainMenu.ArmedTextColor", pScheme), GetSchemeColor("Button.ArmedBgColor", pScheme));
  137. SetTextInset( MAIN_MENU_INDENT_X360, 0 );
  138. }
  139. if (m_bRightAligned)
  140. {
  141. SetContentAlignment(Label::a_east);
  142. }
  143. }
  144. void CGameMenuItem::PaintBackground()
  145. {
  146. if ( !GameUI().IsConsoleUI() )
  147. {
  148. BaseClass::PaintBackground();
  149. }
  150. else
  151. {
  152. if ( !IsArmed() || !IsVisible() || GetParent()->GetAlpha() < 32 )
  153. return;
  154. int wide, tall;
  155. GetSize( wide, tall );
  156. DrawBoxFade( 0, 0, wide, tall, GetButtonBgColor(), 1.0f, 255, 0, true );
  157. DrawBoxFade( 2, 2, wide - 4, tall - 4, Color( 0, 0, 0, 96 ), 1.0f, 255, 0, true );
  158. }
  159. }
  160. void CGameMenuItem::SetRightAlignedText(bool state)
  161. {
  162. m_bRightAligned = state;
  163. }
  164. //-----------------------------------------------------------------------------
  165. // Purpose: General purpose 1 of N menu
  166. //-----------------------------------------------------------------------------
  167. class CGameMenu : public vgui::Menu
  168. {
  169. public:
  170. DECLARE_CLASS_SIMPLE( CGameMenu, vgui::Menu );
  171. CGameMenu(vgui::Panel *parent, const char *name) : BaseClass(parent, name)
  172. {
  173. if ( GameUI().IsConsoleUI() )
  174. {
  175. // shows graphic button hints
  176. m_pConsoleFooter = new CFooterPanel( parent, "MainMenuFooter" );
  177. int iFixedWidth = 245;
  178. // dgoodenough - limit this to X360 only
  179. // PS3_BUILDFIX
  180. #if defined( _X360 )
  181. // In low def we need a smaller highlight
  182. XVIDEO_MODE videoMode;
  183. XGetVideoMode( &videoMode );
  184. if ( !videoMode.fIsHiDef )
  185. {
  186. iFixedWidth = 240;
  187. }
  188. else
  189. {
  190. iFixedWidth = 350;
  191. }
  192. #endif
  193. SetFixedWidth( iFixedWidth );
  194. }
  195. else
  196. {
  197. m_pConsoleFooter = NULL;
  198. }
  199. }
  200. virtual void ApplySchemeSettings(IScheme *pScheme)
  201. {
  202. BaseClass::ApplySchemeSettings(pScheme);
  203. // make fully transparent
  204. SetMenuItemHeight(atoi(pScheme->GetResourceString("MainMenu.MenuItemHeight")));
  205. SetBgColor(Color(0, 0, 0, 0));
  206. SetBorder(NULL);
  207. }
  208. virtual void LayoutMenuBorder()
  209. {
  210. }
  211. virtual void SetVisible(bool state)
  212. {
  213. // force to be always visible
  214. BaseClass::SetVisible(true);
  215. // move us to the back instead of going invisible
  216. if (!state)
  217. {
  218. ipanel()->MoveToBack(GetVPanel());
  219. }
  220. }
  221. virtual int AddMenuItem(const char *itemName, const char *itemText, const char *command, Panel *target, KeyValues *userData = NULL)
  222. {
  223. MenuItem *item = new CGameMenuItem(this, itemName);
  224. item->AddActionSignalTarget(target);
  225. item->SetCommand(command);
  226. item->SetText(itemText);
  227. item->SetUserData(userData);
  228. return BaseClass::AddMenuItem(item);
  229. }
  230. virtual int AddMenuItem(const char *itemName, const char *itemText, KeyValues *command, Panel *target, KeyValues *userData = NULL)
  231. {
  232. CGameMenuItem *item = new CGameMenuItem(this, itemName);
  233. item->AddActionSignalTarget(target);
  234. item->SetCommand(command);
  235. item->SetText(itemText);
  236. item->SetRightAlignedText(true);
  237. item->SetUserData(userData);
  238. return BaseClass::AddMenuItem(item);
  239. }
  240. virtual void SetMenuItemBlinkingState( const char *itemName, bool state )
  241. {
  242. for (int i = 0; i < GetChildCount(); i++)
  243. {
  244. Panel *child = GetChild(i);
  245. MenuItem *menuItem = dynamic_cast<MenuItem *>(child);
  246. if (menuItem)
  247. {
  248. if ( Q_strcmp( menuItem->GetCommand()->GetString("command", ""), itemName ) == 0 )
  249. {
  250. menuItem->SetBlink( state );
  251. }
  252. }
  253. }
  254. InvalidateLayout();
  255. }
  256. virtual void OnCommand(const char *command)
  257. {
  258. if (!stricmp(command, "Open"))
  259. {
  260. MoveToFront();
  261. RequestFocus();
  262. }
  263. else
  264. {
  265. BaseClass::OnCommand(command);
  266. }
  267. }
  268. virtual void OnKeyCodePressed( KeyCode code )
  269. {
  270. if ( IsGameConsole() )
  271. {
  272. if ( GetAlpha() != 255 )
  273. {
  274. SetEnabled( false );
  275. // inhibit key activity during transitions
  276. return;
  277. }
  278. SetEnabled( true );
  279. if ( code == KEY_XBUTTON_B || code == KEY_XBUTTON_START )
  280. {
  281. if ( GameUI().IsInLevel() )
  282. {
  283. GetParent()->OnCommand( "ResumeGame" );
  284. }
  285. return;
  286. }
  287. }
  288. BaseClass::OnKeyCodePressed( code );
  289. // HACK: Allow F key bindings to operate even here
  290. if ( IsPC() && code >= KEY_F1 && code <= KEY_F12 )
  291. {
  292. // See if there is a binding for the FKey
  293. const char *binding = gameuifuncs->GetBindingForButtonCode( code );
  294. if ( binding && binding[0] )
  295. {
  296. // submit the entry as a console commmand
  297. char szCommand[256];
  298. Q_strncpy( szCommand, binding, sizeof( szCommand ) );
  299. engine->ClientCmd_Unrestricted( szCommand, true );
  300. }
  301. }
  302. }
  303. virtual void OnKillFocus()
  304. {
  305. BaseClass::OnKillFocus();
  306. // force us to the rear when we lose focus (so it looks like the menu is always on the background)
  307. surface()->MovePopupToBack(GetVPanel());
  308. }
  309. void ShowFooter( bool bShow )
  310. {
  311. if ( m_pConsoleFooter )
  312. {
  313. m_pConsoleFooter->SetVisible( bShow );
  314. }
  315. }
  316. void UpdateMenuItemState( bool isInGame, bool isMultiplayer )
  317. {
  318. bool isSteam = IsPC() && ( CommandLine()->FindParm("-steam") != 0 );
  319. bool bIsConsoleUI = GameUI().IsConsoleUI();
  320. // disabled save button if we're not in a game
  321. for (int i = 0; i < GetChildCount(); i++)
  322. {
  323. Panel *child = GetChild(i);
  324. MenuItem *menuItem = dynamic_cast<MenuItem *>(child);
  325. if (menuItem)
  326. {
  327. bool shouldBeVisible = true;
  328. // filter the visibility
  329. KeyValues *kv = menuItem->GetUserData();
  330. if (!kv)
  331. continue;
  332. if (!isInGame && kv->GetInt("OnlyInGame") )
  333. {
  334. shouldBeVisible = false;
  335. }
  336. if ( isInGame && kv->GetInt( "MainMenuOnly" ) )
  337. {
  338. shouldBeVisible = false;
  339. }
  340. else if (isMultiplayer && kv->GetInt("notmulti"))
  341. {
  342. shouldBeVisible = false;
  343. }
  344. else if (isInGame && !isMultiplayer && kv->GetInt("notsingle"))
  345. {
  346. shouldBeVisible = false;
  347. }
  348. else if (isSteam && kv->GetInt("notsteam"))
  349. {
  350. shouldBeVisible = false;
  351. }
  352. else if ( !bIsConsoleUI && kv->GetInt( "ConsoleOnly" ) )
  353. {
  354. shouldBeVisible = false;
  355. }
  356. else if ( bIsConsoleUI && kv->GetInt( "PCOnly" ) )
  357. {
  358. shouldBeVisible = false;
  359. }
  360. menuItem->SetVisible( shouldBeVisible );
  361. }
  362. }
  363. if ( !isInGame )
  364. {
  365. // Sort them into their original order
  366. for ( int j = 0; j < GetChildCount() - 2; j++ )
  367. {
  368. MoveMenuItem( j, j + 1 );
  369. }
  370. }
  371. else
  372. {
  373. // Sort them into their in game order
  374. for ( int i = 0; i < GetChildCount(); i++ )
  375. {
  376. for ( int j = i; j < GetChildCount() - 2; j++ )
  377. {
  378. int iID1 = GetMenuID( j );
  379. int iID2 = GetMenuID( j + 1 );
  380. MenuItem *menuItem1 = GetMenuItem( iID1 );
  381. MenuItem *menuItem2 = GetMenuItem( iID2 );
  382. KeyValues *kv1 = menuItem1->GetUserData();
  383. KeyValues *kv2 = menuItem2->GetUserData();
  384. if ( kv1->GetInt("InGameOrder") > kv2->GetInt("InGameOrder") )
  385. MoveMenuItem( iID2, iID1 );
  386. }
  387. }
  388. }
  389. InvalidateLayout();
  390. if ( m_pConsoleFooter )
  391. {
  392. // update the console footer
  393. const char *pHelpName;
  394. if ( !isInGame )
  395. pHelpName = "MainMenu";
  396. else
  397. pHelpName = "GameMenu";
  398. if ( !m_pConsoleFooter->GetHelpName() || V_stricmp( pHelpName, m_pConsoleFooter->GetHelpName() ) )
  399. {
  400. // game menu must re-establish its own help once it becomes re-active
  401. m_pConsoleFooter->SetHelpNameAndReset( pHelpName );
  402. m_pConsoleFooter->AddNewButtonLabel( "#GameUI_Action", "#GameUI_Icons_A_BUTTON" );
  403. if ( isInGame )
  404. {
  405. m_pConsoleFooter->AddNewButtonLabel( "#GameUI_Close", "#GameUI_Icons_B_BUTTON" );
  406. }
  407. }
  408. }
  409. }
  410. MESSAGE_FUNC_PTR( OnCursorEnteredMenuItem, "CursorEnteredMenuItem", VPanel);
  411. private:
  412. CFooterPanel *m_pConsoleFooter;
  413. };
  414. //-----------------------------------------------------------------------------
  415. // Purpose: Respond to cursor entering a menuItem.
  416. //-----------------------------------------------------------------------------
  417. void CGameMenu::OnCursorEnteredMenuItem(vgui::Panel* VPanel)
  418. {
  419. VPANEL menuItem = (VPANEL)VPanel;
  420. MenuItem *item = static_cast<MenuItem *>(ipanel()->GetPanel(menuItem, GetModuleName()));
  421. // [jason] Disable the cursor enter if the menu item is invisible and disabled
  422. if ( item && !item->IsEnabled() )
  423. return;
  424. KeyValues *pCommand = item->GetCommand();
  425. if ( !pCommand->GetFirstSubKey() )
  426. return;
  427. const char *pszCmd = pCommand->GetFirstSubKey()->GetString();
  428. if ( !pszCmd || !pszCmd[0] )
  429. return;
  430. BaseClass::OnCursorEnteredMenuItem( VPanel );
  431. }
  432. static CBackgroundMenuButton* CreateMenuButton( CBaseModPanel *parent, const char *panelName, const wchar_t *panelText )
  433. {
  434. CBackgroundMenuButton *pButton = new CBackgroundMenuButton( parent, panelName );
  435. pButton->SetProportional(true);
  436. pButton->SetCommand("OpenGameMenu");
  437. pButton->SetText(panelText);
  438. return pButton;
  439. }
  440. bool g_bIsCreatingNewGameMenuForPreFetching = false;
  441. //-----------------------------------------------------------------------------
  442. // Purpose: Constructor
  443. //-----------------------------------------------------------------------------
  444. CBaseModPanel::CBaseModPanel( const char *panelName ) : Panel(NULL, panelName )
  445. {
  446. g_pBasePanel = this;
  447. m_bLevelLoading = false;
  448. m_eBackgroundState = BACKGROUND_INITIAL;
  449. m_flTransitionStartTime = 0.0f;
  450. m_flTransitionEndTime = 0.0f;
  451. m_flFrameFadeInTime = 0.5f;
  452. m_bRenderingBackgroundTransition = false;
  453. m_bFadingInMenus = false;
  454. m_bEverActivated = false;
  455. m_iGameMenuInset = 24;
  456. m_bPlatformMenuInitialized = false;
  457. m_bHaveDarkenedBackground = false;
  458. m_bHaveDarkenedTitleText = true;
  459. m_bForceTitleTextUpdate = true;
  460. m_BackdropColor = Color(0, 0, 0, 128);
  461. m_pConsoleAnimationController = NULL;
  462. m_pConsoleControlSettings = NULL;
  463. m_bCopyFrameBuffer = false;
  464. m_bUseRenderTargetImage = false;
  465. m_ExitingFrameCount = 0;
  466. m_bXUIVisible = false;
  467. m_bUseMatchmaking = false;
  468. m_bRestartFromInvite = false;
  469. m_bRestartSameGame = false;
  470. m_bUserRefusedSignIn = false;
  471. m_bUserRefusedStorageDevice = false;
  472. m_bWaitingForUserSignIn = false;
  473. m_bReturnToMPGameMenuOnDisconnect = false;
  474. m_bForceQuitToDesktopOnDisconnect = false;
  475. #if !defined(NO_STEAM) && defined(_PS3)
  476. m_bStatsLoaded = false;
  477. #else
  478. m_bStatsLoaded = true;
  479. #endif
  480. m_bWaitingForStorageDeviceHandle = false;
  481. m_bNeedStorageDeviceHandle = false;
  482. m_bStorageBladeShown = false;
  483. m_iStorageID = XBX_INVALID_STORAGE_ID;
  484. m_pAsyncJob = NULL;
  485. m_pStorageDeviceValidatedNotify = NULL;
  486. m_bStartScreenPlayerSigninCompleted = false;
  487. m_bMainMenuShown = true;
  488. // [jason] Flags to enable/disable scaleform screens during the startup sequence (start screen, mainmenu)
  489. m_bForceStartScreen = false;
  490. m_bShowStartScreen = true;
  491. m_bScaleformMainMenuEnabled = true;
  492. m_bScaleformPauseMenuEnabled = true;
  493. m_bBypassStartScreen = false;
  494. m_iIntroMovieButtonPressed = -1;
  495. m_bIntroMovieWaitForButtonToClear = false;
  496. m_primaryUserId = -1;
  497. // any platforms that go straight to main menu, no start screen, should set this flag:
  498. if ( CommandLine()->FindParm( "-nostartscreen" ) ||
  499. IsPC() ||
  500. IsLinux() ||
  501. IsOSX() )
  502. {
  503. m_bBypassStartScreen = true;
  504. }
  505. // "map" parameter bypasses only the start screen, to get your directly into the level
  506. if ( CommandLine()->FindParm( "+map" ) )
  507. {
  508. m_bShowStartScreen = false;
  509. }
  510. // these options disable start screen as well as the front-end menus
  511. bool bNoScaleformFrontEnd = ( CommandLine()->FindParm( "-hijack" ) ) ||
  512. ( IsPlatformWindowsPC() && CommandLine()->FindParm( "-tools" ) ) ||
  513. ( CommandLine()->FindParm( "-no_scaleform_menu_on_boot" ) );
  514. if ( bNoScaleformFrontEnd )
  515. {
  516. m_bShowStartScreen = false;
  517. m_bScaleformMainMenuEnabled = false;
  518. }
  519. if ( GameUI().IsConsoleUI() )
  520. {
  521. m_pConsoleAnimationController = new AnimationController( this );
  522. m_pConsoleAnimationController->SetScriptFile( GetVPanel(), "scripts/GameUIAnimations.txt" );
  523. m_pConsoleAnimationController->SetAutoReloadScript( IsDebug() );
  524. m_pConsoleControlSettings = new KeyValues( "XboxDialogs.res" );
  525. if ( !m_pConsoleControlSettings->LoadFromFile( g_pFullFileSystem, "resource/UI/XboxDialogs.res", "GAME" ) )
  526. {
  527. Error( "Failed to load UI control settings!\n" );
  528. }
  529. }
  530. m_pGameMenuButtons.AddToTail( CreateMenuButton( this, "GameMenuButton", ModInfo().GetGameTitle() ) );
  531. m_pGameMenuButtons.AddToTail( CreateMenuButton( this, "GameMenuButton2", ModInfo().GetGameTitle2() ) );
  532. #ifdef CS_BETA
  533. if ( !ModInfo().NoCrosshair() ) // hack to not show the BETA for HL2 or HL1Port
  534. {
  535. m_pGameMenuButtons.AddToTail( CreateMenuButton( this, "BetaButton", L"BETA" ) );
  536. }
  537. #endif // CS_BETA
  538. m_pGameMenu = NULL;
  539. m_pGameLogo = NULL;
  540. // 2016-Apr-18 <vitaliy> -- this looks like a bunch of legacy code, we cannot run with any version of Steam Client, but the latest
  541. // if ( SteamClient() )
  542. // {
  543. // HSteamPipe steamPipe = SteamClient()->CreateSteamPipe();
  544. // ISteamUtils *pUtils = SteamClient()->GetISteamUtils( steamPipe, "SteamUtils002" );
  545. // if ( pUtils )
  546. // {
  547. bSteamCommunityFriendsVersion = true;
  548. // }
  549. //
  550. // SteamClient()->BReleaseSteamPipe( steamPipe );
  551. // }
  552. CreateGameMenu();
  553. CreateGameLogo();
  554. // Bonus maps menu blinks if something has been unlocked since the player last opened the menu
  555. // This is saved as persistant data, and here is where we check for that
  556. CheckBonusBlinkState();
  557. // start the menus fully transparent
  558. SetMenuAlpha( 0 );
  559. if ( GameUI().IsConsoleUI() )
  560. {
  561. // do any costly resource prefetching now....
  562. // force the new dialog to get all of its chapter pics
  563. g_bIsCreatingNewGameMenuForPreFetching = true;
  564. m_hNewGameDialog = new CNewGameDialog( this, false );
  565. m_hNewGameDialog->MarkForDeletion();
  566. g_bIsCreatingNewGameMenuForPreFetching = false;
  567. #if 0
  568. m_hOptionsDialog_Xbox = new COptionsDialogXbox( this );
  569. m_hOptionsDialog_Xbox->MarkForDeletion();
  570. m_hControllerDialog = new CControllerDialog( this );
  571. m_hControllerDialog->MarkForDeletion();
  572. #endif
  573. if ( !IsStartScreenEnabled() && !IsScaleformIntroMovieEnabled() && !m_bBypassStartScreen )
  574. {
  575. ArmFirstMenuItem();
  576. m_pConsoleAnimationController->StartAnimationSequence( "InitializeUILayout" );
  577. }
  578. }
  579. // Record data used for rich presence updates
  580. if ( IsGameConsole() )
  581. {
  582. //#if defined( CSTRIKE15 )
  583. m_bSinglePlayer = false;
  584. //#else
  585. // DWenger - Pulled this out for now to get things to compile for cs15
  586. /*
  587. // Get our active mod directory name
  588. const char *pGameName = CommandLine()->ParmValue( "-game", "hl2" );;
  589. // Set the game we're playing
  590. m_iGameID = CONTEXT_GAME_GAME_HALF_LIFE_2;
  591. m_bSinglePlayer = true;
  592. if ( Q_stristr( pGameName, "episodic" ) )
  593. {
  594. m_iGameID = CONTEXT_GAME_GAME_EPISODE_ONE;
  595. }
  596. else if ( Q_stristr( pGameName, "ep2" ) )
  597. {
  598. m_iGameID = CONTEXT_GAME_GAME_EPISODE_TWO;
  599. }
  600. else if ( Q_stristr( pGameName, "portal" ) )
  601. {
  602. m_iGameID = CONTEXT_GAME_GAME_PORTAL;
  603. }
  604. else if ( Q_stristr( pGameName, "tf" ) )
  605. {
  606. m_iGameID = CONTEXT_GAME_GAME_TEAM_FORTRESS;
  607. m_bSinglePlayer = false;
  608. }
  609. */
  610. //#endif // CSTRIKE15
  611. }
  612. m_pCodeVersionLabel = new Label( this, "CodeVersionLabel", "" );
  613. m_pContentVersionLabel = new Label( this, "ContentVersionLabel", "" );
  614. }
  615. //-----------------------------------------------------------------------------
  616. // Purpose: Xbox 360 - Get the console UI keyvalues to pass to LoadControlSettings()
  617. //-----------------------------------------------------------------------------
  618. KeyValues *CBaseModPanel::GetConsoleControlSettings( void )
  619. {
  620. return m_pConsoleControlSettings;
  621. }
  622. //-----------------------------------------------------------------------------
  623. // Purpose: Causes the first menu item to be armed
  624. //-----------------------------------------------------------------------------
  625. void CBaseModPanel::ArmFirstMenuItem( void )
  626. {
  627. UpdateGameMenus();
  628. // Arm the first item in the menu
  629. for ( int i = 0; i < m_pGameMenu->GetItemCount(); ++i )
  630. {
  631. if ( m_pGameMenu->GetMenuItem( i )->IsVisible() )
  632. {
  633. m_pGameMenu->SetCurrentlyHighlightedItem( i );
  634. break;
  635. }
  636. }
  637. }
  638. CBaseModPanel::~CBaseModPanel()
  639. {
  640. g_pBasePanel = NULL;
  641. }
  642. static char *g_rgValidCommands[] =
  643. {
  644. "OpenGameMenu",
  645. "OpenPlayerListDialog",
  646. "OpenNewGameDialog",
  647. "OpenLoadGameDialog",
  648. "OpenSaveGameDialog",
  649. "OpenCustomMapsDialog",
  650. "OpenOptionsDialog",
  651. "OpenBenchmarkDialog",
  652. "OpenServerBrowser",
  653. "OpenFriendsDialog",
  654. "OpenLoadDemoDialog",
  655. "OpenCreateMultiplayerGameDialog",
  656. "OpenCreateMultiplayerGameCommunity",
  657. "OpenChangeGameDialog",
  658. "OpenLoadCommentaryDialog",
  659. "Quit",
  660. "QuitNoConfirm",
  661. "ResumeGame",
  662. "Disconnect",
  663. "OpenCreateSinglePlayerGameDialog",
  664. "OpenCreateStartScreen",
  665. "ShowInvitePartyUI",
  666. "ShowJoinPartyUI",
  667. "ShowInviteFriendsUI",
  668. "ShowPlayerSelectionScoreboard",
  669. "OpenMotionCalibrationDialog",
  670. };
  671. static void CC_GameMenuCommand( const CCommand &args )
  672. {
  673. int c = args.ArgC();
  674. if ( c < 2 )
  675. {
  676. Msg( "Usage: gamemenucommand <commandname>\n" );
  677. return;
  678. }
  679. if ( !g_pBasePanel )
  680. {
  681. return;
  682. }
  683. vgui::ivgui()->PostMessage( g_pBasePanel->GetVPanel(), new KeyValues("Command", "command", args[1] ), NULL);
  684. }
  685. static bool UtlStringLessFunc( const CUtlString &lhs, const CUtlString &rhs )
  686. {
  687. return Q_stricmp( lhs.String(), rhs.String() ) < 0;
  688. }
  689. static int CC_GameMenuCompletionFunc( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] )
  690. {
  691. char const *cmdname = "gamemenucommand";
  692. char *substring = (char *)partial;
  693. if ( Q_strstr( partial, cmdname ) )
  694. {
  695. substring = (char *)partial + strlen( cmdname ) + 1;
  696. }
  697. int checklen = Q_strlen( substring );
  698. CUtlRBTree< CUtlString > symbols( 0, 0, UtlStringLessFunc );
  699. int i;
  700. int c = ARRAYSIZE( g_rgValidCommands );
  701. for ( i = 0; i < c; ++i )
  702. {
  703. if ( Q_strnicmp( g_rgValidCommands[ i ], substring, checklen ) )
  704. continue;
  705. CUtlString str;
  706. str = g_rgValidCommands[ i ];
  707. symbols.Insert( str );
  708. // Too many
  709. if ( symbols.Count() >= COMMAND_COMPLETION_MAXITEMS )
  710. break;
  711. }
  712. // Now fill in the results
  713. int slot = 0;
  714. for ( i = symbols.FirstInorder(); i != symbols.InvalidIndex(); i = symbols.NextInorder( i ) )
  715. {
  716. char const *name = symbols[ i ].String();
  717. char buf[ 512 ];
  718. Q_strncpy( buf, name, sizeof( buf ) );
  719. Q_strlower( buf );
  720. Q_snprintf( commands[ slot++ ], COMMAND_COMPLETION_ITEM_LENGTH, "%s %s",
  721. cmdname, buf );
  722. }
  723. return slot;
  724. }
  725. static ConCommand gamemenucommand( "gamemenucommand", CC_GameMenuCommand, "Issue game menu command.", 0, CC_GameMenuCompletionFunc );
  726. CON_COMMAND_F( quit_prompt, "Exit the engine.", FCVAR_NONE )
  727. {
  728. BasePanel()->OnCommand( "quittodesktop" );
  729. }
  730. //-----------------------------------------------------------------------------
  731. // Purpose: paints the main background image
  732. //-----------------------------------------------------------------------------
  733. void CBaseModPanel::PaintBackground()
  734. {
  735. if ( !GameUI().IsInLevel() || m_ExitingFrameCount )
  736. {
  737. // not in the game or loading dialog active or exiting, draw the ui background
  738. DrawBackgroundImage();
  739. }
  740. else if ( IsGameConsole() )
  741. {
  742. // only valid during loading from level to level
  743. m_bUseRenderTargetImage = false;
  744. }
  745. // [jason] Do not render the background alpha while Scaleform Menus are up
  746. if ( !BasePanel()->IsScaleformMainMenuActive() && !BasePanel()->IsScaleformPauseMenuActive() )
  747. {
  748. if ( m_flBackgroundFillAlpha )
  749. {
  750. int swide, stall;
  751. surface()->GetScreenSize(swide, stall);
  752. surface()->DrawSetColor(0, 0, 0, m_flBackgroundFillAlpha);
  753. surface()->DrawFilledRect(0, 0, swide, stall);
  754. }
  755. }
  756. }
  757. //-----------------------------------------------------------------------------
  758. // Updates which background state we should be in.
  759. //
  760. // NOTE: These states change at funny times and overlap. They CANNOT be
  761. // used to demarcate exact transitions.
  762. //-----------------------------------------------------------------------------
  763. void CBaseModPanel::UpdateBackgroundState()
  764. {
  765. if ( m_ExitingFrameCount )
  766. {
  767. // trumps all, an exiting state must own the screen image
  768. // cannot be stopped
  769. SetBackgroundRenderState( BACKGROUND_EXITING );
  770. }
  771. else if ( GameUI().IsInLevel() )
  772. {
  773. SetBackgroundRenderState( BACKGROUND_LEVEL );
  774. }
  775. else if ( /*GameUI().IsInBackgroundLevel() && */ !m_bLevelLoading )
  776. {
  777. // 360 guarantees a progress bar
  778. // level loading is truly completed when the progress bar is gone, then transition to main menu
  779. if ( IsPC() || ( IsGameConsole() && !CLoadingScreenScaleform::IsOpen() ) )
  780. {
  781. SetBackgroundRenderState( BACKGROUND_MAINMENU );
  782. }
  783. }
  784. else if ( m_bLevelLoading )
  785. {
  786. SetBackgroundRenderState( BACKGROUND_LOADING );
  787. }
  788. else if ( m_bEverActivated && m_bPlatformMenuInitialized )
  789. {
  790. SetBackgroundRenderState( BACKGROUND_DISCONNECTED );
  791. }
  792. if ( GameUI().IsConsoleUI() )
  793. {
  794. if ( !m_ExitingFrameCount && !m_bLevelLoading && !CLoadingScreenScaleform::IsOpen() && GameUI().IsInLevel() )
  795. {
  796. // paused
  797. if ( m_flBackgroundFillAlpha == 0.0f )
  798. m_flBackgroundFillAlpha = 120.0f;
  799. }
  800. else
  801. {
  802. m_flBackgroundFillAlpha = 0;
  803. }
  804. // console ui has completely different menu/dialog/fill/fading behavior
  805. return;
  806. }
  807. // don't evaluate the rest until we've initialized the menus
  808. if ( !m_bPlatformMenuInitialized )
  809. return;
  810. // check for background fill
  811. // fill over the top if we have any dialogs up
  812. int i;
  813. bool bHaveActiveDialogs = false;
  814. bool bIsInLevel = GameUI().IsInLevel();
  815. for ( i = 0; i < GetChildCount(); ++i )
  816. {
  817. VPANEL child = ipanel()->GetChild( GetVPanel(), i );
  818. if ( child
  819. && ipanel()->IsVisible( child )
  820. && ipanel()->IsPopup( child )
  821. && child != m_pGameMenu->GetVPanel() )
  822. {
  823. bHaveActiveDialogs = true;
  824. }
  825. }
  826. // see if the base gameui panel has dialogs hanging off it (engine stuff, console, bug reporter)
  827. VPANEL parent = GetVParent();
  828. for ( i = 0; i < ipanel()->GetChildCount( parent ); ++i )
  829. {
  830. VPANEL child = ipanel()->GetChild( parent, i );
  831. if ( child
  832. && ipanel()->IsVisible( child )
  833. && ipanel()->IsPopup( child )
  834. && child != GetVPanel() )
  835. {
  836. bHaveActiveDialogs = true;
  837. }
  838. }
  839. // check to see if we need to fade in the background fill
  840. bool bNeedDarkenedBackground = (bHaveActiveDialogs || bIsInLevel);
  841. if ( m_bHaveDarkenedBackground != bNeedDarkenedBackground )
  842. {
  843. // fade in faster than we fade out
  844. float targetAlpha, duration;
  845. if ( bNeedDarkenedBackground )
  846. {
  847. // fade in background tint
  848. targetAlpha = m_BackdropColor[3];
  849. duration = m_flFrameFadeInTime;
  850. }
  851. else
  852. {
  853. // fade out background tint
  854. targetAlpha = 0.0f;
  855. duration = 2.0f;
  856. }
  857. m_bHaveDarkenedBackground = bNeedDarkenedBackground;
  858. vgui::GetAnimationController()->RunAnimationCommand( this, "m_flBackgroundFillAlpha", targetAlpha, 0.0f, duration, AnimationController::INTERPOLATOR_LINEAR );
  859. }
  860. // check to see if the game title should be dimmed
  861. // don't transition on level change
  862. if ( m_bLevelLoading )
  863. return;
  864. bool bNeedDarkenedTitleText = bHaveActiveDialogs;
  865. if (m_bHaveDarkenedTitleText != bNeedDarkenedTitleText || m_bForceTitleTextUpdate)
  866. {
  867. float targetTitleAlpha, duration;
  868. if (bHaveActiveDialogs)
  869. {
  870. // fade out title text
  871. duration = m_flFrameFadeInTime;
  872. targetTitleAlpha = 32.0f;
  873. }
  874. else
  875. {
  876. // fade in title text
  877. duration = 2.0f;
  878. targetTitleAlpha = 255.0f;
  879. }
  880. if ( m_pGameLogo )
  881. {
  882. vgui::GetAnimationController()->RunAnimationCommand( m_pGameLogo, "alpha", targetTitleAlpha, 0.0f, duration, AnimationController::INTERPOLATOR_LINEAR );
  883. }
  884. // Msg( "animating title (%d => %d at time %.2f)\n", m_pGameMenuButton->GetAlpha(), (int)targetTitleAlpha, Plat_FloatTime());
  885. for ( i=0; i<m_pGameMenuButtons.Count(); ++i )
  886. {
  887. vgui::GetAnimationController()->RunAnimationCommand( m_pGameMenuButtons[i], "alpha", targetTitleAlpha, 0.0f, duration, AnimationController::INTERPOLATOR_LINEAR );
  888. }
  889. m_bHaveDarkenedTitleText = bNeedDarkenedTitleText;
  890. m_bForceTitleTextUpdate = false;
  891. }
  892. }
  893. //-----------------------------------------------------------------------------
  894. // Purpose: sets how the game background should render
  895. //-----------------------------------------------------------------------------
  896. void CBaseModPanel::SetBackgroundRenderState(EBackgroundState state)
  897. {
  898. if ( state == m_eBackgroundState )
  899. {
  900. return;
  901. }
  902. // apply state change transition
  903. float frametime = Plat_FloatTime();
  904. m_bRenderingBackgroundTransition = false;
  905. m_bFadingInMenus = false;
  906. if ( state == BACKGROUND_EXITING )
  907. {
  908. // hide the menus
  909. m_bCopyFrameBuffer = false;
  910. }
  911. else if ( state == BACKGROUND_DISCONNECTED || state == BACKGROUND_MAINMENU )
  912. {
  913. if ( m_bForceStartScreen )
  914. {
  915. m_bForceStartScreen = false;
  916. HandleOpenCreateStartScreen();
  917. }
  918. else
  919. {
  920. // [jason] Restore the Scaleform main menu when we return to Front End
  921. if ( m_eBackgroundState == BACKGROUND_LEVEL || m_eBackgroundState == BACKGROUND_LOADING )
  922. {
  923. if ( IsScaleformMainMenuEnabled() )
  924. {
  925. // Do not bring main menu up if we're planning to show the start screen as well!
  926. if ( !IsStartScreenEnabled() )
  927. {
  928. ShowMainMenu( false );
  929. ShowScaleformMainMenu( true );
  930. }
  931. }
  932. else
  933. {
  934. ShowMainMenu( true );
  935. }
  936. }
  937. // menu fading
  938. // make the menus visible
  939. m_bFadingInMenus = true;
  940. m_flFadeMenuStartTime = frametime;
  941. m_flFadeMenuEndTime = frametime + 3.0f;
  942. if ( state == BACKGROUND_MAINMENU )
  943. {
  944. // fade background into main menu
  945. m_bRenderingBackgroundTransition = true;
  946. m_flTransitionStartTime = frametime;
  947. m_flTransitionEndTime = frametime + 3.0f;
  948. }
  949. }
  950. }
  951. else if ( state == BACKGROUND_LOADING )
  952. {
  953. if ( GameUI().IsConsoleUI() )
  954. {
  955. RunAnimationWithCallback( this, "InstantHideMainMenu", new KeyValues( "LoadMap" ) );
  956. }
  957. // hide the menus
  958. SetMenuAlpha( 0 );
  959. // [jason] Ensure we hide the scaleform main menu at this point
  960. DismissMainMenuScreen();
  961. }
  962. else if ( state == BACKGROUND_LEVEL )
  963. {
  964. // show the menus
  965. SetMenuAlpha( 255 );
  966. }
  967. m_eBackgroundState = state;
  968. }
  969. void CBaseModPanel::StartExitingProcess()
  970. {
  971. // must let a non trivial number of screen swaps occur to stabilize image
  972. // ui runs in a constrained state, while shutdown is occurring
  973. m_flTransitionStartTime = Plat_FloatTime();
  974. m_flTransitionEndTime = m_flTransitionStartTime + 0.5f;
  975. m_ExitingFrameCount = 30;
  976. g_pInputSystem->DetachFromWindow();
  977. engine->StartXboxExitingProcess();
  978. }
  979. //-----------------------------------------------------------------------------
  980. // Purpose: Size should only change on first vgui frame after startup
  981. //-----------------------------------------------------------------------------
  982. void CBaseModPanel::OnSizeChanged( int newWide, int newTall )
  983. {
  984. // Recenter message dialogs
  985. m_MessageDialogHandler.PositionDialogs( newWide, newTall );
  986. }
  987. //-----------------------------------------------------------------------------
  988. // Purpose: notifications
  989. //-----------------------------------------------------------------------------
  990. void CBaseModPanel::OnLevelLoadingStarted( const char *levelName, bool bShowProgressDialog )
  991. {
  992. m_bLevelLoading = true;
  993. // $TODO: Figure out why this causes input lockup when we return to in-level
  994. // Dismiss any message boxes, options menus, help screens, etc if the level load is kicked off.
  995. // This covers cases of the map being loaded via the console window.
  996. DismissAllMainMenuScreens();
  997. if ( IsGameConsole() && m_eBackgroundState == BACKGROUND_LEVEL )
  998. {
  999. // already in a level going to another level
  1000. // frame buffer is about to be cleared, copy it off for ui backing purposes
  1001. m_bCopyFrameBuffer = true;
  1002. }
  1003. // kick off the scaleform screen load if it hasn't been opened yet
  1004. if ( !CLoadingScreenScaleform::IsOpen() )
  1005. {
  1006. if ( levelName )
  1007. {
  1008. if ( !levelName[0] )
  1009. {
  1010. levelName = engine->GetLevelNameShort();
  1011. }
  1012. char levelSettings[1024];
  1013. V_snprintf( levelSettings, ARRAYSIZE(levelSettings),
  1014. " Game { "
  1015. " type %s"
  1016. " mode %s"
  1017. " map %s"
  1018. " } "
  1019. ,
  1020. g_pGameTypes->GetGameTypeFromInt( g_pGameTypes->GetCurrentGameType() ),
  1021. g_pGameTypes->GetGameModeFromInt( g_pGameTypes->GetCurrentGameType(), g_pGameTypes->GetCurrentGameMode() ),
  1022. levelName
  1023. );
  1024. KeyValues *pSettings = KeyValues::FromString( "Settings", levelSettings );
  1025. KeyValues::AutoDelete autodelete( pSettings );
  1026. CLoadingScreenScaleform::LoadDialogForKeyValues( pSettings );
  1027. }
  1028. else
  1029. {
  1030. // If we don't have a valid level name yet, just open the loading screen and await further info
  1031. CLoadingScreenScaleform::LoadDialog( );
  1032. }
  1033. }
  1034. }
  1035. //-----------------------------------------------------------------------------
  1036. // Purpose: notification
  1037. //-----------------------------------------------------------------------------
  1038. void CBaseModPanel::OnLevelLoadingFinished()
  1039. {
  1040. // [jason] $FIXME: Switch back to Scaleform, unless we are still using vgui for Pause Menu
  1041. if ( m_bScaleformPauseMenuEnabled )
  1042. {
  1043. ShowMainMenu( false );
  1044. }
  1045. m_bLevelLoading = false;
  1046. UpdateRichPresenceInfo();
  1047. // clear game UI state from previous matches
  1048. if ( GetViewPortInterface() )
  1049. {
  1050. GetViewPortInterface()->ShowPanel( PANEL_ALL, false );
  1051. GetViewPortInterface()->UpdateAllPanels();
  1052. }
  1053. }
  1054. //-----------------------------------------------------------------------------
  1055. // Draws the background image.
  1056. //-----------------------------------------------------------------------------
  1057. void CBaseModPanel::DrawBackgroundImage()
  1058. {
  1059. // [jason] Only render background if the Scaleform main menu is inactive
  1060. if ( IsScaleformMainMenuEnabled() && IsScaleformMainMenuActive() )
  1061. return;
  1062. if ( IsGameConsole() && m_bCopyFrameBuffer )
  1063. {
  1064. // force the engine to do an image capture ONCE into this image's render target
  1065. char filename[MAX_PATH];
  1066. surface()->DrawGetTextureFile( m_iRenderTargetImageID, filename, sizeof( filename ) );
  1067. engine->CopyFrameBufferToMaterial( filename );
  1068. m_bCopyFrameBuffer = false;
  1069. m_bUseRenderTargetImage = true;
  1070. }
  1071. int wide, tall;
  1072. GetSize( wide, tall );
  1073. float frametime = Plat_FloatTime();
  1074. // a background transition has a running map underneath it, so fade image out
  1075. // otherwise, there is no map and the background image stays opaque
  1076. int alpha = 255;
  1077. if ( m_bRenderingBackgroundTransition )
  1078. {
  1079. // goes from [255..0]
  1080. alpha = (m_flTransitionEndTime - frametime) / (m_flTransitionEndTime - m_flTransitionStartTime) * 255;
  1081. alpha = clamp( alpha, 0, 255 );
  1082. }
  1083. // an exiting process needs to opaquely cover everything
  1084. if ( m_ExitingFrameCount )
  1085. {
  1086. // goes from [0..255]
  1087. alpha = (m_flTransitionEndTime - frametime) / (m_flTransitionEndTime - m_flTransitionStartTime) * 255;
  1088. alpha = 255 - clamp( alpha, 0, 255 );
  1089. }
  1090. int iImageID = m_iBackgroundImageID;
  1091. if ( IsGameConsole() )
  1092. {
  1093. if ( m_ExitingFrameCount )
  1094. {
  1095. if ( !m_bRestartSameGame )
  1096. {
  1097. iImageID = m_iProductImageID;
  1098. }
  1099. }
  1100. else if ( m_bUseRenderTargetImage )
  1101. {
  1102. // the render target image must be opaque, the alpha channel contents are unknown
  1103. // it is strictly an opaque background image and never used as an overlay
  1104. iImageID = m_iRenderTargetImageID;
  1105. alpha = 255;
  1106. }
  1107. }
  1108. surface()->DrawSetColor( 255, 255, 255, alpha );
  1109. surface()->DrawSetTexture( iImageID );
  1110. surface()->DrawTexturedRect( 0, 0, wide, tall );
  1111. if ( IsGameConsole() && m_ExitingFrameCount )
  1112. {
  1113. // Make invisible when going back to appchooser
  1114. #if defined( __clang__ )
  1115. m_pGameMenu->CGameMenu::BaseClass::SetVisible( false );
  1116. #else
  1117. m_pGameMenu->BaseClass::SetVisible( false );
  1118. #endif
  1119. IScheme *pScheme = vgui::scheme()->GetIScheme( vgui::scheme()->GetScheme( "SourceScheme" ) );
  1120. HFont hFont = pScheme->GetFont( "ChapterTitle" );
  1121. wchar_t *pString = g_pVGuiLocalize->Find( "#GameUI_Loading" );
  1122. int textWide, textTall;
  1123. surface()->GetTextSize( hFont, pString, textWide, textTall );
  1124. surface()->DrawSetTextPos( ( wide - textWide )/2, tall * 0.50f );
  1125. surface()->DrawSetTextFont( hFont );
  1126. surface()->DrawSetTextColor( 255, 255, 255, alpha );
  1127. surface()->DrawPrintText( pString, wcslen( pString ) );
  1128. }
  1129. // 360 always use the progress bar, TCR Requirement, and never this loading plaque
  1130. if ( IsPC() && ( m_bRenderingBackgroundTransition || m_eBackgroundState == BACKGROUND_LOADING ) )
  1131. {
  1132. // draw the loading image over the top
  1133. surface()->DrawSetColor(255, 255, 255, alpha);
  1134. surface()->DrawSetTexture(m_iLoadingImageID);
  1135. int twide, ttall;
  1136. surface()->DrawGetTextureSize(m_iLoadingImageID, twide, ttall);
  1137. surface()->DrawTexturedRect(wide - twide, tall - ttall, wide, tall);
  1138. }
  1139. // update the menu alpha
  1140. if ( !IsStartScreenEnabled() && !m_bBypassStartScreen && m_bFadingInMenus && !IsScaleformIntroMovieEnabled() )
  1141. {
  1142. if ( GameUI().IsConsoleUI() )
  1143. {
  1144. m_pConsoleAnimationController->StartAnimationSequence( "OpenMainMenu" );
  1145. m_bFadingInMenus = false;
  1146. }
  1147. else
  1148. {
  1149. // goes from [0..255]
  1150. alpha = (frametime - m_flFadeMenuStartTime) / (m_flFadeMenuEndTime - m_flFadeMenuStartTime) * 255;
  1151. alpha = clamp( alpha, 0, 255 );
  1152. m_pGameMenu->SetAlpha( alpha );
  1153. if ( alpha == 255 )
  1154. {
  1155. m_bFadingInMenus = false;
  1156. }
  1157. }
  1158. }
  1159. }
  1160. //-----------------------------------------------------------------------------
  1161. // Purpose:
  1162. //-----------------------------------------------------------------------------
  1163. void CBaseModPanel::CreateGameMenu()
  1164. {
  1165. // load settings from config file
  1166. KeyValues *datafile = new KeyValues("GameMenu");
  1167. datafile->UsesEscapeSequences( true ); // VGUI uses escape sequences
  1168. if (datafile->LoadFromFile( g_pFullFileSystem, "Resource/GameMenu.res" ) )
  1169. {
  1170. m_pGameMenu = RecursiveLoadGameMenu(datafile);
  1171. }
  1172. if ( !m_pGameMenu )
  1173. {
  1174. Error( "Could not load file Resource/GameMenu.res" );
  1175. }
  1176. else
  1177. {
  1178. // start invisible
  1179. SETUP_PANEL( m_pGameMenu );
  1180. m_pGameMenu->SetAlpha( 0 );
  1181. }
  1182. datafile->deleteThis();
  1183. }
  1184. //-----------------------------------------------------------------------------
  1185. // Purpose:
  1186. //-----------------------------------------------------------------------------
  1187. void CBaseModPanel::CreateGameLogo()
  1188. {
  1189. if ( ModInfo().UseGameLogo() )
  1190. {
  1191. m_pGameLogo = new CMainMenuGameLogo( this, "GameLogo" );
  1192. if ( m_pGameLogo )
  1193. {
  1194. SETUP_PANEL( m_pGameLogo );
  1195. m_pGameLogo->InvalidateLayout( true, true );
  1196. // start invisible
  1197. m_pGameLogo->SetAlpha( 0 );
  1198. }
  1199. }
  1200. else
  1201. {
  1202. m_pGameLogo = NULL;
  1203. }
  1204. }
  1205. void CBaseModPanel::CheckBonusBlinkState()
  1206. {
  1207. #ifdef _GAMECONSOLE
  1208. // On 360 if we have a storage device at this point and try to read the bonus data it can't find the bonus file!
  1209. return;
  1210. #endif
  1211. if ( BonusMapsDatabase()->GetBlink() )
  1212. {
  1213. if ( GameUI().IsConsoleUI() )
  1214. SetMenuItemBlinkingState( "OpenNewGameDialog", true ); // Consoles integrate bonus maps menu into the new game menu
  1215. else
  1216. SetMenuItemBlinkingState( "OpenBonusMapsDialog", true );
  1217. }
  1218. }
  1219. //-----------------------------------------------------------------------------
  1220. // Purpose: Checks to see if menu items need to be enabled/disabled
  1221. //-----------------------------------------------------------------------------
  1222. void CBaseModPanel::UpdateGameMenus()
  1223. {
  1224. // check our current state
  1225. bool isInGame = GameUI().IsInLevel();
  1226. bool isMulti = isInGame && (engine->GetMaxClients() > 1);
  1227. // iterate all the menu items
  1228. m_pGameMenu->UpdateMenuItemState( isInGame, isMulti );
  1229. // position the menu
  1230. InvalidateLayout();
  1231. m_pGameMenu->SetVisible( true );
  1232. }
  1233. //-----------------------------------------------------------------------------
  1234. // Purpose: sets up the game menu from the keyvalues
  1235. // the game menu is hierarchial, so this is recursive
  1236. //-----------------------------------------------------------------------------
  1237. CGameMenu *CBaseModPanel::RecursiveLoadGameMenu(KeyValues *datafile)
  1238. {
  1239. CGameMenu *menu = new CGameMenu(this, datafile->GetName());
  1240. // loop through all the data adding items to the menu
  1241. for (KeyValues *dat = datafile->GetFirstSubKey(); dat != NULL; dat = dat->GetNextKey())
  1242. {
  1243. const char *label = dat->GetString("label", "<unknown>");
  1244. const char *cmd = dat->GetString("command", NULL);
  1245. const char *name = dat->GetString("name", label);
  1246. if ( cmd && !Q_stricmp( cmd, "OpenFriendsDialog" ) && bSteamCommunityFriendsVersion )
  1247. continue;
  1248. menu->AddMenuItem(name, label, cmd, this, dat);
  1249. }
  1250. return menu;
  1251. }
  1252. //-----------------------------------------------------------------------------
  1253. // Purpose: Unlock all input, typically when sign-out occurs and we return to
  1254. // the start screen.
  1255. //-----------------------------------------------------------------------------
  1256. void CBaseModPanel::UnlockInput( void )
  1257. {
  1258. m_primaryUserId = -1;
  1259. #if defined( _GAMECONSOLE )
  1260. XBX_ResetUserIdSlots();
  1261. XBX_SetPrimaryUserId( XBX_INVALID_USER_ID );
  1262. XBX_SetPrimaryUserIsGuest( 0 );
  1263. XBX_SetNumGameUsers( 0 ); // users not selected yet
  1264. #endif
  1265. }
  1266. //-----------------------------------------------------------------------------
  1267. // Purpose: Lock input to the user who signed-in
  1268. //-----------------------------------------------------------------------------
  1269. void CBaseModPanel::LockInput( void )
  1270. {
  1271. #if defined( _GAMECONSOLE )
  1272. // Turn off all controllers
  1273. XBX_ClearUserIdSlots();
  1274. // Configure the game type and controller assignments
  1275. XBX_SetPrimaryUserId( m_primaryUserId );
  1276. XBX_SetPrimaryUserIsGuest( 0 );
  1277. // $TODO: handle guest account, and multiple user sign-in
  1278. XBX_SetUserId( 0, m_primaryUserId );
  1279. XBX_SetUserIsGuest( 0, 0 );
  1280. XBX_SetNumGameUsers( 1 );
  1281. #endif
  1282. }
  1283. //-----------------------------------------------------------------------------
  1284. // Purpose: Perform tasks required to transition from start screen to main menu
  1285. // via a user Start button -> Sign-in sequence
  1286. //-----------------------------------------------------------------------------
  1287. void CBaseModPanel::CompleteStartScreenSignIn( void )
  1288. {
  1289. // [jason] Lock input first, then dismiss start screen and start the main menu
  1290. LockInput();
  1291. m_bStartScreenPlayerSigninCompleted = false;
  1292. m_bWaitingForUserSignIn = false;
  1293. m_bUserRefusedSignIn = false;
  1294. DismissStartScreen();
  1295. m_bShowStartScreen = false;
  1296. #if defined( _GAMECONSOLE )
  1297. // Set the local player's name in the game.
  1298. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  1299. int userID = XBX_GetActiveUserId();
  1300. bool bValidUserName = false;
  1301. char* pUserName = NULL;
  1302. #if defined ( _X360 )
  1303. char szGamertag[MAX_PLAYER_NAME_LENGTH];
  1304. if (( userID != INVALID_USER_ID ) &&
  1305. ( XUserGetSigninState( userID ) != eXUserSigninState_NotSignedIn ))
  1306. {
  1307. if(XUserGetName( userID, szGamertag, MAX_PLAYER_NAME_LENGTH ) != ERROR_SUCCESS)
  1308. {
  1309. Error( "CompleteStartScreenSignIn: error getting Xbox 360 user name.\n" );
  1310. V_strncpy( szGamertag, "unknown", sizeof( szGamertag ) );
  1311. }
  1312. bValidUserName = true;
  1313. pUserName = szGamertag;
  1314. }
  1315. #elif defined ( _PS3 )
  1316. if ( userID != INVALID_USER_ID )
  1317. {
  1318. s_userStat.id = CELL_SYSUTIL_USERID_CURRENT;
  1319. if(cellUserInfoGetStat(CELL_SYSUTIL_USERID_CURRENT,&s_userStat) != CELL_USERINFO_RET_OK)
  1320. {
  1321. Error( "CompleteStartScreenSignIn: error getting PS3 user name.\n" );
  1322. V_strncpy( s_userStat.name, "unknown", CELL_USERINFO_USERNAME_SIZE );
  1323. }
  1324. bValidUserName = true;
  1325. pUserName = s_userStat.name;
  1326. }
  1327. #endif
  1328. if(bValidUserName)
  1329. {
  1330. ConVarRef cl_name( "name" );
  1331. cl_name.SetValue( pUserName );
  1332. }
  1333. #endif // _GAMECONSOLE
  1334. if ( IsScaleformMainMenuEnabled() )
  1335. {
  1336. // Display the scaleform main menu now
  1337. OnOpenCreateMainMenuScreen( );
  1338. }
  1339. else
  1340. {
  1341. // Otherwise, bring up the vgui main menu now
  1342. ShowMainMenu( true );
  1343. }
  1344. #if defined( _GAMECONSOLE )
  1345. // OnProfilesChanged triggers g_pPlayerManager->OnGameUsersChanged() which creates local players in matchmaking; this is called from CMatchFramework::Connect on PC only
  1346. // so we dont want to call g_pPlayerManager->OnGameUsersChanged() twice on PC but needs to be called once on GAMECONSOLE so we BroadcastEvent here only if defined _GAMECONSOLE
  1347. g_pMatchFramework->GetEventsSubscription()->BroadcastEvent( new KeyValues( "OnProfilesChanged", "numProfiles", (int) XBX_GetNumGameUsers() ) );
  1348. #endif
  1349. UpdateRichPresenceInfo();
  1350. }
  1351. //-----------------------------------------------------------------------------
  1352. // Purpose: update the taskbar a frame
  1353. //-----------------------------------------------------------------------------
  1354. // exposed here as non-constant so CEG can populate the value at DLL init time
  1355. static DWORD CEG_ALLOW_PROPER_TINT = 0xFEA4; // will override
  1356. CEG_NOINLINE DWORD InitUiAllowProperTintFlag( void )
  1357. {
  1358. CEG_GCV_PRE();
  1359. CEG_ALLOW_PROPER_TINT = CEG_GET_CONSTANT_VALUE( UiAllowProperTintFlag );
  1360. CEG_GCV_POST();
  1361. return CEG_ALLOW_PROPER_TINT;
  1362. }
  1363. int CBaseModPanel::CheckForAnyKeyPressed( bool bCheckKeyboard )
  1364. {
  1365. // a macro to make the code below a little cleaner and easier to read
  1366. #define TEST_BUTTON( x ) \
  1367. do {\
  1368. ButtonCode_t button = ( x );\
  1369. if ( g_pInputSystem->IsButtonDown( button ) )\
  1370. {\
  1371. return button;\
  1372. }\
  1373. } while( false )
  1374. for ( int i = 0; i < XUSER_MAX_COUNT; i++ )
  1375. {
  1376. TEST_BUTTON( ButtonCodeToJoystickButtonCode( KEY_XBUTTON_START, i ) );
  1377. TEST_BUTTON( ButtonCodeToJoystickButtonCode( KEY_XBUTTON_BACK, i ) );
  1378. TEST_BUTTON( ButtonCodeToJoystickButtonCode( KEY_XBUTTON_A, i ) );
  1379. TEST_BUTTON( ButtonCodeToJoystickButtonCode( KEY_XBUTTON_B, i ) );
  1380. TEST_BUTTON( ButtonCodeToJoystickButtonCode( KEY_XBUTTON_X, i ) );
  1381. TEST_BUTTON( ButtonCodeToJoystickButtonCode( KEY_XBUTTON_Y, i ) );
  1382. }
  1383. // Also, on PC/PS3, we allow the following keys to skip the Start Screen:
  1384. if ( bCheckKeyboard )
  1385. {
  1386. TEST_BUTTON( KEY_SPACE );
  1387. TEST_BUTTON( KEY_ENTER );
  1388. TEST_BUTTON( KEY_ESCAPE );
  1389. }
  1390. return -1;
  1391. }
  1392. void CBaseModPanel::RunFrame()
  1393. {
  1394. InvalidateLayout();
  1395. vgui::GetAnimationController()->UpdateAnimations( Plat_FloatTime() );
  1396. BaseModUI::CUIGameData::Get()->RunFrame();
  1397. // CEG checks failing = Really awful looking UI
  1398. if ( ~CEG_ALLOW_PROPER_TINT & ALLOW_PROPER_TINT_FLAG )
  1399. {
  1400. static ConVarRef sf_ui_tint_munge( "sf_ui_tint" );
  1401. sf_ui_tint_munge.SetValue( 0x10 );
  1402. }
  1403. // Tick all screens that need to update synchronously
  1404. UpdateLeaderboardsDialog();
  1405. UpdateLobbyScreen();
  1406. UpdateLobbyBrowser();
  1407. UpdateMainMenuScreen();
  1408. if ( IsScaleformIntroMovieEnabled() )
  1409. {
  1410. if ( m_bIntroMovieWaitForButtonToClear )
  1411. {
  1412. if ( !g_pInputSystem->IsButtonDown( ( ButtonCode_t ) m_iIntroMovieButtonPressed ) )
  1413. {
  1414. m_bIntroMovieWaitForButtonToClear = false;
  1415. m_iIntroMovieButtonPressed = -1;
  1416. }
  1417. }
  1418. else if ( m_iIntroMovieButtonPressed == -1 )
  1419. {
  1420. m_iIntroMovieButtonPressed = CheckForAnyKeyPressed( !IsX360() );
  1421. }
  1422. else if ( !g_pInputSystem->IsButtonDown( ( ButtonCode_t ) m_iIntroMovieButtonPressed ) )
  1423. {
  1424. DismissScaleformIntroMovie();
  1425. m_iIntroMovieButtonPressed = -1;
  1426. }
  1427. }
  1428. else if ( IsStartScreenEnabled() )
  1429. {
  1430. // If we're flagged to bypass the screen, just treat it as if sign-in naturally occurred
  1431. if ( m_bBypassStartScreen )
  1432. {
  1433. m_primaryUserId = 0;
  1434. CompleteStartScreenSignIn();
  1435. }
  1436. // Poll for button press to activate the game from Start Screen:
  1437. else if ( !m_bWaitingForUserSignIn && m_bStatsLoaded )
  1438. {
  1439. // If for any reason main menu has snuck in behind us, make sure it is put away
  1440. DismissMainMenuScreen();
  1441. bool bStartPressed = false;
  1442. bool bSignedIn = true;
  1443. int UserIdPressedStart = -1;
  1444. // Any joystick can press Start initially
  1445. for ( int i = 0; i < XUSER_MAX_COUNT && !bStartPressed; i++ )
  1446. {
  1447. if ( g_pInputSystem->IsButtonDown( ButtonCodeToJoystickButtonCode( KEY_XBUTTON_START, i ) ) ||
  1448. g_pInputSystem->IsButtonDown( ButtonCodeToJoystickButtonCode( KEY_XBUTTON_A, i ) ) )
  1449. {
  1450. #if defined( _X360 )
  1451. // If this user isn't signed in, we need to prompt them for it
  1452. uint state = XUserGetSigninState( i );
  1453. if ( state != eXUserSigninState_NotSignedIn )
  1454. {
  1455. m_primaryUserId = i;
  1456. }
  1457. else
  1458. {
  1459. bSignedIn = false;
  1460. }
  1461. #elif defined( _PS3 )
  1462. m_primaryUserId = i;
  1463. #endif
  1464. UserIdPressedStart = i;
  1465. bStartPressed = true;
  1466. }
  1467. }
  1468. // Also, on PC/PS3, we allow the following keys to skip the Start Screen:
  1469. if ( !bStartPressed && !IsX360() )
  1470. {
  1471. bStartPressed = ( g_pInputSystem->IsButtonDown( KEY_LBRACKET ) ||
  1472. g_pInputSystem->IsButtonDown( KEY_SPACE ) ||
  1473. g_pInputSystem->IsButtonDown( KEY_ENTER ) );
  1474. #ifdef _PS3
  1475. m_primaryUserId = 0;
  1476. UserIdPressedStart = 0;
  1477. #endif
  1478. }
  1479. #if !defined( _CERT )
  1480. // Skip the start screen when running test scripts
  1481. static ConVarRef testscript_running( "testscript_running");
  1482. if ( bSignedIn && testscript_running.GetBool() )
  1483. {
  1484. bStartPressed = true;
  1485. m_primaryUserId = 0;
  1486. UserIdPressedStart = 0;
  1487. }
  1488. #endif
  1489. if ( bStartPressed )
  1490. {
  1491. vgui::surface()->PlaySound( "UI\\buttonclick.wav" );
  1492. // FIXME: Eventually, we'll have the correct signin for all platforms, so switch over to it then
  1493. if ( !bSignedIn && IsX360() )
  1494. {
  1495. if ( UserIdPressedStart > -1 )
  1496. {
  1497. m_primaryUserId = UserIdPressedStart;
  1498. LockInput();
  1499. }
  1500. SignInFromStartScreen();
  1501. }
  1502. else
  1503. {
  1504. CompleteStartScreenSignIn();
  1505. }
  1506. }
  1507. }
  1508. // Handle the Start Screen sign-in completion on the next tick, so we have a frame to finish rendering the blade and Start Screen outro
  1509. if ( m_bStartScreenPlayerSigninCompleted )
  1510. {
  1511. CompleteStartScreenSignIn();
  1512. }
  1513. }
  1514. if ( GameUI().IsConsoleUI() )
  1515. {
  1516. // run the console ui animations
  1517. m_pConsoleAnimationController->UpdateAnimations( Plat_FloatTime() );
  1518. if ( IsGameConsole() && m_ExitingFrameCount && Plat_FloatTime() >= m_flTransitionEndTime )
  1519. {
  1520. if ( m_ExitingFrameCount > 1 )
  1521. {
  1522. m_ExitingFrameCount--;
  1523. if ( m_ExitingFrameCount == 1 )
  1524. {
  1525. // enough frames have transpired, send the single shot quit command
  1526. // If we kicked off this event from an invite, we need to properly setup the restart to account for that
  1527. if ( m_bRestartFromInvite )
  1528. {
  1529. engine->ClientCmd_Unrestricted( "quit_gameconsole invite" );
  1530. }
  1531. else if ( m_bRestartSameGame )
  1532. {
  1533. engine->ClientCmd_Unrestricted( "quit_gameconsole restart" );
  1534. }
  1535. else
  1536. {
  1537. // quits to appchooser
  1538. engine->ClientCmd_Unrestricted( "quit_gameconsole\n" );
  1539. }
  1540. }
  1541. }
  1542. }
  1543. }
  1544. UpdateBackgroundState();
  1545. if ( !m_bPlatformMenuInitialized )
  1546. {
  1547. // check to see if the platform is ready to load yet
  1548. if ( IsGameConsole() || g_VModuleLoader.IsPlatformReady() )
  1549. {
  1550. m_bPlatformMenuInitialized = true;
  1551. }
  1552. }
  1553. // Check to see if a pending async task has already finished
  1554. if ( m_pAsyncJob && !m_pAsyncJob->m_hThreadHandle )
  1555. {
  1556. m_pAsyncJob->Completed();
  1557. delete m_pAsyncJob;
  1558. m_pAsyncJob = NULL;
  1559. }
  1560. }
  1561. #if defined( PLATFORM_X360 )
  1562. static inline XUSER_CONTEXT CreateContextStruct( DWORD dwContextId, DWORD dwValue )
  1563. {
  1564. XUSER_CONTEXT xUserContext = { dwContextId, dwValue };
  1565. return xUserContext;
  1566. }
  1567. #endif
  1568. //-----------------------------------------------------------------------------
  1569. // Purpose: Tells XBox Live our user is in the current game's menu
  1570. //-----------------------------------------------------------------------------
  1571. void CBaseModPanel::UpdateRichPresenceInfo()
  1572. {
  1573. #if defined( _X360 )
  1574. // For all other users logged into this console (not primary), set to idle to satisfy cert
  1575. for( int i = 0; i < XUSER_MAX_COUNT; ++i )
  1576. {
  1577. XUSER_SIGNIN_STATE State = XUserGetSigninState( i );
  1578. if ( State != eXUserSigninState_NotSignedIn )
  1579. {
  1580. // Check if they are one of our active users
  1581. bool isActive = false;
  1582. for ( unsigned int k = 0; k < XBX_GetNumGameUsers(); ++ k )
  1583. {
  1584. if ( XBX_GetUserId( k ) == i )
  1585. {
  1586. isActive = true;
  1587. break;
  1588. }
  1589. }
  1590. if ( !isActive )
  1591. {
  1592. // Set rich presence as 'idle' for users logged in that can't participate.
  1593. //DevMsg( "Set presence to %d for user %d\n", CONTEXT_PRESENCE_IDLE, i );
  1594. if ( !xboxsystem->UserSetContext( i, CreateContextStruct( X_CONTEXT_PRESENCE, CONTEXT_PRESENCE_IDLE ), true ) )
  1595. {
  1596. Warning( "BasePanel: UserSetContext failed.\n" );
  1597. }
  1598. }
  1599. }
  1600. }
  1601. // If we're not in the level we set the presence to main menu
  1602. if ( !GameUI().IsInLevel() )
  1603. {
  1604. for ( unsigned int k = 0; k < XBX_GetNumGameUsers(); ++ k )
  1605. {
  1606. if ( XBX_GetUserIsGuest( k ) )
  1607. continue;
  1608. int iCtrlr = XBX_GetUserId( k );
  1609. // [jmh] When user is not in a level, they're either in main menu or in a team lobby
  1610. DWORD rpContext = InTeamLobby() ? CONTEXT_PRESENCE_LOBBY : CONTEXT_PRESENCE_MAINMENU;
  1611. //DevMsg( "Set presence to %d for user %d\n", rpContext, iCtrlr );
  1612. if ( !xboxsystem->UserSetContext( iCtrlr, CreateContextStruct( X_CONTEXT_PRESENCE, rpContext ), true ) )
  1613. {
  1614. Warning( "BasePanel: UserSetContext failed.\n" );
  1615. }
  1616. }
  1617. }
  1618. else if ( m_bSinglePlayer )
  1619. {
  1620. // We're in a single player so set the presence to single player for all active users
  1621. for ( unsigned int k = 0; k < XBX_GetNumGameUsers(); ++ k )
  1622. {
  1623. if ( XBX_GetUserIsGuest( k ) )
  1624. continue;
  1625. int iCtrlr = XBX_GetUserId( k );
  1626. //DevMsg( "Set presence to %d for user %d\n", CONTEXT_PRESENCE_SINGLEPLAYER, iCtrlr );
  1627. if ( !xboxsystem->UserSetContext( iCtrlr, CreateContextStruct( X_CONTEXT_PRESENCE, CONTEXT_PRESENCE_SINGLEPLAYER ), true ) )
  1628. {
  1629. Warning( "BasePanel: UserSetContext failed.\n" );
  1630. }
  1631. }
  1632. }
  1633. #endif // _X360
  1634. }
  1635. //-----------------------------------------------------------------------------
  1636. // Purpose: Lays out the position of the taskbar
  1637. //-----------------------------------------------------------------------------
  1638. void CBaseModPanel::PerformLayout()
  1639. {
  1640. BaseClass::PerformLayout();
  1641. // Get the screen size
  1642. int wide, tall;
  1643. vgui::surface()->GetScreenSize(wide, tall);
  1644. // Get the size of the menu
  1645. int menuWide, menuTall;
  1646. m_pGameMenu->GetSize( menuWide, menuTall );
  1647. int idealMenuY = m_iGameMenuPos.y;
  1648. if ( idealMenuY + menuTall + m_iGameMenuInset > tall )
  1649. {
  1650. idealMenuY = tall - menuTall - m_iGameMenuInset;
  1651. }
  1652. int yDiff = idealMenuY - m_iGameMenuPos.y;
  1653. for ( int i=0; i<m_pGameMenuButtons.Count(); ++i )
  1654. {
  1655. // Get the size of the logo text
  1656. //int textWide, textTall;
  1657. m_pGameMenuButtons[i]->SizeToContents();
  1658. //vgui::surface()->GetTextSize( m_pGameMenuButtons[i]->GetFont(), ModInfo().GetGameTitle(), textWide, textTall );
  1659. // place menu buttons above middle of screen
  1660. m_pGameMenuButtons[i]->SetPos(m_iGameTitlePos[i].x, m_iGameTitlePos[i].y + yDiff);
  1661. //m_pGameMenuButtons[i]->SetSize(textWide + 4, textTall + 4);
  1662. }
  1663. if ( m_pGameLogo )
  1664. {
  1665. // move the logo to sit right on top of the menu
  1666. m_pGameLogo->SetPos( m_iGameMenuPos.x + m_pGameLogo->GetOffsetX(), idealMenuY - m_pGameLogo->GetTall() + m_pGameLogo->GetOffsetY() );
  1667. }
  1668. // position self along middle of screen
  1669. if ( GameUI().IsConsoleUI() )
  1670. {
  1671. int posx, posy;
  1672. m_pGameMenu->GetPos( posx, posy );
  1673. m_iGameMenuPos.x = posx;
  1674. }
  1675. m_pGameMenu->SetPos(m_iGameMenuPos.x, idealMenuY);
  1676. UpdateGameMenus();
  1677. }
  1678. //-----------------------------------------------------------------------------
  1679. // Purpose: Loads scheme information
  1680. //-----------------------------------------------------------------------------
  1681. void CBaseModPanel::ApplySchemeSettings(IScheme *pScheme)
  1682. {
  1683. int i;
  1684. BaseClass::ApplySchemeSettings(pScheme);
  1685. m_iGameMenuInset = atoi(pScheme->GetResourceString("MainMenu.Inset"));
  1686. m_iGameMenuInset *= 2;
  1687. IScheme *pClientScheme = vgui::scheme()->GetIScheme( vgui::scheme()->GetScheme( "ClientScheme" ) );
  1688. CUtlVector< Color > buttonColor;
  1689. if ( pClientScheme )
  1690. {
  1691. m_iGameTitlePos.RemoveAll();
  1692. for ( i=0; i<m_pGameMenuButtons.Count(); ++i )
  1693. {
  1694. m_pGameMenuButtons[i]->SetFont(pClientScheme->GetFont("ClientTitleFont", true));
  1695. m_iGameTitlePos.AddToTail( coord() );
  1696. m_iGameTitlePos[i].x = atoi(pClientScheme->GetResourceString( CFmtStr( "Main.Title%d.X", i+1 ) ) );
  1697. m_iGameTitlePos[i].x = scheme()->GetProportionalScaledValue( m_iGameTitlePos[i].x );
  1698. m_iGameTitlePos[i].y = atoi(pClientScheme->GetResourceString( CFmtStr( "Main.Title%d.Y", i+1 ) ) );
  1699. m_iGameTitlePos[i].y = scheme()->GetProportionalScaledValue( m_iGameTitlePos[i].y );
  1700. if ( GameUI().IsConsoleUI() )
  1701. m_iGameTitlePos[i].x += MAIN_MENU_INDENT_X360;
  1702. buttonColor.AddToTail( pClientScheme->GetColor( CFmtStr( "Main.Title%d.Color", i+1 ), Color(255, 255, 255, 255)) );
  1703. }
  1704. #ifdef CS_BETA
  1705. if ( !ModInfo().NoCrosshair() ) // hack to not show the BETA for HL2 or HL1Port
  1706. {
  1707. m_pGameMenuButtons[m_pGameMenuButtons.Count()-1]->SetFont(pClientScheme->GetFont("BetaFont", true));
  1708. }
  1709. #endif // CS_BETA
  1710. m_iGameMenuPos.x = atoi(pClientScheme->GetResourceString("Main.Menu.X"));
  1711. m_iGameMenuPos.x = scheme()->GetProportionalScaledValue( m_iGameMenuPos.x );
  1712. m_iGameMenuPos.y = atoi(pClientScheme->GetResourceString("Main.Menu.Y"));
  1713. m_iGameMenuPos.y = scheme()->GetProportionalScaledValue( m_iGameMenuPos.y );
  1714. m_iGameMenuInset = atoi(pClientScheme->GetResourceString("Main.BottomBorder"));
  1715. m_iGameMenuInset = scheme()->GetProportionalScaledValue( m_iGameMenuInset );
  1716. }
  1717. else
  1718. {
  1719. for ( i=0; i<m_pGameMenuButtons.Count(); ++i )
  1720. {
  1721. m_pGameMenuButtons[i]->SetFont(pScheme->GetFont("TitleFont"));
  1722. buttonColor.AddToTail( Color( 255, 255, 255, 255 ) );
  1723. }
  1724. }
  1725. for ( i=0; i<m_pGameMenuButtons.Count(); ++i )
  1726. {
  1727. m_pGameMenuButtons[i]->SetDefaultColor(buttonColor[i], Color(0, 0, 0, 0));
  1728. m_pGameMenuButtons[i]->SetArmedColor(buttonColor[i], Color(0, 0, 0, 0));
  1729. m_pGameMenuButtons[i]->SetDepressedColor(buttonColor[i], Color(0, 0, 0, 0));
  1730. }
  1731. m_flFrameFadeInTime = atof(pScheme->GetResourceString("Frame.TransitionEffectTime"));
  1732. // work out current focus - find the topmost panel
  1733. SetBgColor(Color(0, 0, 0, 0));
  1734. m_BackdropColor = pScheme->GetColor("mainmenu.backdrop", Color(0, 0, 0, 128));
  1735. char filename[MAX_PATH];
  1736. if ( IsGameConsole() )
  1737. {
  1738. // 360 uses FullFrameFB1 RT for map to map transitioning
  1739. m_iRenderTargetImageID = surface()->CreateNewTextureID();
  1740. surface()->DrawSetTextureFile( m_iRenderTargetImageID, "console/rt_background", false, false );
  1741. }
  1742. int screenWide, screenTall;
  1743. surface()->GetScreenSize( screenWide, screenTall );
  1744. float aspectRatio = (float)screenWide/(float)screenTall;
  1745. bool bIsWidescreen = aspectRatio >= 1.5999f;
  1746. // work out which background image to use
  1747. if ( IsPC() || !IsGameConsole() )
  1748. {
  1749. // pc uses blurry backgrounds based on the background level
  1750. char background[MAX_PATH];
  1751. engine->GetMainMenuBackgroundName( background, sizeof(background) );
  1752. Q_snprintf( filename, sizeof( filename ), "console/%s%s", background, ( bIsWidescreen ? "_widescreen" : "" ) );
  1753. }
  1754. else
  1755. {
  1756. // 360 uses hi-res game specific backgrounds
  1757. char gameName[MAX_PATH];
  1758. const char *pGameDir = engine->GetGameDirectory();
  1759. V_FileBase( pGameDir, gameName, sizeof( gameName ) );
  1760. V_snprintf( filename, sizeof( filename ), "vgui/appchooser/background_%s%s", gameName, ( bIsWidescreen ? "_widescreen" : "" ) );
  1761. }
  1762. m_iBackgroundImageID = surface()->CreateNewTextureID();
  1763. surface()->DrawSetTextureFile( m_iBackgroundImageID, filename, false, false );
  1764. if ( IsGameConsole() )
  1765. {
  1766. // 360 uses a product image during application exit
  1767. V_snprintf( filename, sizeof( filename ), "vgui/appchooser/background_orange%s", ( bIsWidescreen ? "_widescreen" : "" ) );
  1768. m_iProductImageID = surface()->CreateNewTextureID();
  1769. surface()->DrawSetTextureFile( m_iProductImageID, filename, false, false );
  1770. }
  1771. if ( IsPC() )
  1772. {
  1773. // load the loading icon
  1774. m_iLoadingImageID = surface()->CreateNewTextureID();
  1775. surface()->DrawSetTextureFile( m_iLoadingImageID, "console/startup_loading", false, false );
  1776. }
  1777. // Load the version numers
  1778. LoadVersionNumbers();
  1779. }
  1780. //-----------------------------------------------------------------------------
  1781. // Purpose: message handler for platform menu; activates the selected module
  1782. //-----------------------------------------------------------------------------
  1783. void CBaseModPanel::OnActivateModule(int moduleIndex)
  1784. {
  1785. g_VModuleLoader.ActivateModule(moduleIndex);
  1786. }
  1787. void CBaseModPanel::CreateStartScreenIfNeeded( void )
  1788. {
  1789. // [jason] If we have Start Screen enabled, present it for the first time
  1790. if ( IsStartScreenEnabled() )
  1791. {
  1792. ShowMainMenu( false );
  1793. // We don't do this step if the platform doesn't use Start Screen to bind the default profile/controller
  1794. if ( !m_bBypassStartScreen )
  1795. {
  1796. // we're awaiting a start input to lock the controller and default profile
  1797. UnlockInput();
  1798. m_bStartScreenPlayerSigninCompleted = false;
  1799. OnOpenCreateStartScreen();
  1800. }
  1801. }
  1802. else
  1803. {
  1804. if ( GameUI().IsConsoleUI() )
  1805. {
  1806. ArmFirstMenuItem();
  1807. }
  1808. }
  1809. }
  1810. //-----------------------------------------------------------------------------
  1811. // Purpose: Animates menus on gameUI being shown
  1812. //-----------------------------------------------------------------------------
  1813. void CBaseModPanel::OnGameUIActivated()
  1814. {
  1815. // If the load failed, we're going to bail out here
  1816. if ( engine->MapLoadFailed() )
  1817. {
  1818. // Don't display this again until it happens again
  1819. engine->SetMapLoadFailed( false );
  1820. ShowMessageDialog( MD_LOAD_FAILED_WARNING );
  1821. }
  1822. if ( !m_bEverActivated )
  1823. {
  1824. // Layout the first time to avoid focus issues (setting menus visible will grab focus)
  1825. UpdateGameMenus();
  1826. m_bEverActivated = true;
  1827. #if defined( _GAMECONSOLE )
  1828. #pragma message( __FILE__ "(" __LINE__AS_STRING ") : warning custom: Slamming controller for xbox storage id to 0" )
  1829. // Open all active containers if we have a valid storage device
  1830. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  1831. if ( XBX_GetActiveUserId() != XBX_INVALID_USER_ID &&
  1832. XBX_GetStorageDeviceId( 0 ) != XBX_INVALID_STORAGE_ID &&
  1833. XBX_GetStorageDeviceId( 0 ) != XBX_STORAGE_DECLINED )
  1834. {
  1835. // Open user settings and save game container here
  1836. uint nRet = engine->OnStorageDeviceAttached( 0 );
  1837. if ( nRet != ERROR_SUCCESS )
  1838. {
  1839. // Invalidate the device
  1840. XBX_SetStorageDeviceId( XBX_GetActiveUserId(), XBX_INVALID_STORAGE_ID );
  1841. // FIXME: We don't know which device failed!
  1842. // Pop a dialog explaining that the user's data is corrupt
  1843. BasePanel()->ShowMessageDialog( MD_STORAGE_DEVICES_CORRUPT );
  1844. }
  1845. }
  1846. #if 0
  1847. // determine if we're starting up because of a cross-game invite
  1848. int fLaunchFlags = XboxLaunch()->GetLaunchFlags();
  1849. if ( fLaunchFlags & LF_INVITERESTART )
  1850. {
  1851. XNKID nSessionID;
  1852. XboxLaunch()->GetInviteSessionID( &nSessionID );
  1853. #pragma message( __FILE__ "(" __LINE__AS_STRING ") : warning custom: Leaving invite acceptance restart behavior broken" )
  1854. //matchmaking->JoinInviteSessionByID( nSessionID );
  1855. }
  1856. #endif
  1857. #endif
  1858. // Brute force check to open tf matchmaking ui.
  1859. if ( GameUI().IsConsoleUI() )
  1860. {
  1861. const char *pGame = engine->GetGameDirectory();
  1862. if ( !Q_stricmp( Q_UnqualifiedFileName( pGame ), "tf" ) )
  1863. {
  1864. m_bUseMatchmaking = true;
  1865. RunMenuCommand( "OpenMatchmakingBasePanel" );
  1866. }
  1867. }
  1868. }
  1869. if ( IsScaleformIntroMovieEnabled() )
  1870. {
  1871. CreateScaleformIntroMovie();
  1872. }
  1873. else
  1874. {
  1875. CreateStartScreenIfNeeded();
  1876. }
  1877. if ( GameUI().IsInLevel() )
  1878. {
  1879. if ( !m_bUseMatchmaking )
  1880. {
  1881. // Decouple the pause menu from the console - don't pause just because we're opening the console window
  1882. static ConVarRef cv_console_window_open( "console_window_open" );
  1883. if ( !IsPC() || !cv_console_window_open.GetBool() )
  1884. {
  1885. if (m_bScaleformPauseMenuEnabled)
  1886. {
  1887. OnOpenPauseMenu();
  1888. }
  1889. else
  1890. {
  1891. OnCommand( "OpenPauseMenu" );
  1892. }
  1893. }
  1894. }
  1895. else
  1896. {
  1897. RunMenuCommand( "OpenMatchmakingBasePanel" );
  1898. }
  1899. //if ( m_hAchievementsDialog.Get() )
  1900. //{
  1901. // // Achievement dialog refreshes it's data if the player looks at the pause menu
  1902. // m_hAchievementsDialog->OnCommand( "OnGameUIActivated" );
  1903. //}
  1904. }
  1905. else // not the pause menu, update presence
  1906. {
  1907. // [jason] Safety check: If we're not in level, be sure that the pause menu is hidden
  1908. if ( IsScaleformPauseMenuActive() )
  1909. {
  1910. DismissPauseMenu();
  1911. }
  1912. // [jason] If we are bringing the main menu UI up again (not start screen or loading) then ensure we have raised the main menu
  1913. if ( !m_bLevelLoading && !IsScaleformIntroMovieEnabled() &&
  1914. !IsStartScreenActive() &&
  1915. IsScaleformMainMenuEnabled() && !IsScaleformMainMenuActive() )
  1916. {
  1917. ShowMainMenu( false );
  1918. ShowScaleformMainMenu( true );
  1919. }
  1920. if ( IsGameConsole() )
  1921. {
  1922. UpdateRichPresenceInfo();
  1923. }
  1924. }
  1925. }
  1926. //-----------------------------------------------------------------------------
  1927. // Purpose: Determine if a menu command is bringing up vgui on top of Scaleform
  1928. //-----------------------------------------------------------------------------
  1929. static bool IsVguiCommandOverScaleform(const char *command)
  1930. {
  1931. // If Scaleform isn't enabled and active for front-end/in-game, then this doesn't require any special handling
  1932. if ( GameUI().IsInLevel() )
  1933. {
  1934. if ( !BasePanel()->IsScaleformPauseMenuEnabled() )
  1935. {
  1936. return false;
  1937. }
  1938. }
  1939. else
  1940. {
  1941. if ( !BasePanel()->IsScaleformMainMenuEnabled( ) )
  1942. {
  1943. return false;
  1944. }
  1945. }
  1946. // // [jason] $TODO: Remove these dialogs from the list, as they are adapted to Scaleform :)
  1947. if ( !Q_stricmp( command, "OpenOptionsDialog" ) )
  1948. return true;
  1949. return false;
  1950. }
  1951. void CBaseModPanel::RunSlottedMenuCommand( int slot, const char* command )
  1952. {
  1953. ACTIVE_SPLITSCREEN_PLAYER_GUARD( slot );
  1954. RunMenuCommand( command );
  1955. }
  1956. //-----------------------------------------------------------------------------
  1957. // Purpose: executes a menu command
  1958. //-----------------------------------------------------------------------------
  1959. void CBaseModPanel::RunMenuCommand(const char *command)
  1960. {
  1961. // [jason] Allow the root vgui panel to display, so we can see the dialog for this command
  1962. if ( IsVguiCommandOverScaleform( command ) )
  1963. {
  1964. if ( IsPC() )
  1965. {
  1966. // Ensure windows messages go to VGui correctly
  1967. g_pMatSystemSurface->EnableWindowsMessages( true );
  1968. }
  1969. ShowMainMenu( true );
  1970. }
  1971. STEAMWORKS_SELFCHECK_AMORTIZE( 11 );
  1972. if ( !Q_stricmp( command, "OpenGameMenu" ) )
  1973. {
  1974. if ( m_pGameMenu )
  1975. {
  1976. PostMessage( m_pGameMenu, new KeyValues("Command", "command", "Open") );
  1977. }
  1978. }
  1979. else if ( !Q_stricmp( command, "OpenPlayerListDialog" ) )
  1980. {
  1981. OnOpenPlayerListDialog();
  1982. }
  1983. else if ( !Q_stricmp( command, "OpenNewGameDialog" ) )
  1984. {
  1985. OnOpenNewGameDialog();
  1986. }
  1987. else if ( !Q_stricmp( command, "OpenLoadGameDialog" ) )
  1988. {
  1989. if ( !GameUI().IsConsoleUI() )
  1990. {
  1991. OnOpenLoadGameDialog();
  1992. }
  1993. else
  1994. {
  1995. OnOpenLoadGameDialog_Xbox();
  1996. }
  1997. }
  1998. else if ( !Q_stricmp( command, "OpenSaveGameDialog" ) )
  1999. {
  2000. if ( !GameUI().IsConsoleUI() )
  2001. {
  2002. OnOpenSaveGameDialog();
  2003. }
  2004. else
  2005. {
  2006. OnOpenSaveGameDialog_Xbox();
  2007. }
  2008. }
  2009. else if ( !Q_stricmp( command, "OpenBonusMapsDialog" ) )
  2010. {
  2011. OnOpenBonusMapsDialog();
  2012. }
  2013. else if ( !Q_stricmp( command, "OpenOptionsDialog" ) )
  2014. {
  2015. if ( !GameUI().IsConsoleUI() )
  2016. {
  2017. OnOpenOptionsDialog();
  2018. }
  2019. else
  2020. {
  2021. OnOpenOptionsDialog_Xbox();
  2022. }
  2023. }
  2024. else if ( !Q_stricmp( command, "OpenControllerDialog" ) )
  2025. {
  2026. OnOpenControllerDialog();
  2027. }
  2028. else if ( !Q_stricmp( command, "OpenMouseDialog" ) )
  2029. {
  2030. OnOpenMouseDialog();
  2031. }
  2032. else if ( !Q_stricmp( command, "OpenKeyboardDialog" ) )
  2033. {
  2034. OnOpenKeyboardDialog();
  2035. }
  2036. else if ( !Q_stricmp( command, "OpenMotionControllerMoveDialog" ) )
  2037. {
  2038. OnOpenMotionControllerMoveDialog();
  2039. }
  2040. else if ( !Q_stricmp( command, "OpenMotionControllerSharpshooterDialog" ) )
  2041. {
  2042. OnOpenMotionControllerSharpshooterDialog();
  2043. }
  2044. else if ( !Q_stricmp( command, "OpenMotionControllerDialog" ) )
  2045. {
  2046. OnOpenMotionControllerDialog();
  2047. }
  2048. else if ( !Q_stricmp( command, "OpenMotionCalibrationDialog" ) )
  2049. {
  2050. OnOpenMotionCalibrationDialog();
  2051. }
  2052. else if ( !Q_stricmp( command, "OpenVideoSettingsDialog" ) )
  2053. {
  2054. OnOpenVideoSettingsDialog();
  2055. }
  2056. else if ( !Q_stricmp( command, "OpenOptionsQueued" ) )
  2057. {
  2058. OnOpenOptionsQueued();
  2059. }
  2060. else if ( !Q_stricmp( command, "OpenAudioSettingsDialog" ) )
  2061. {
  2062. OnOpenAudioSettingsDialog();
  2063. }
  2064. else if ( !Q_stricmp( command, "OpenSettingsDialog" ) )
  2065. {
  2066. OnOpenSettingsDialog();
  2067. }
  2068. else if ( !Q_stricmp( command, "MakeGamePublic" ) )
  2069. {
  2070. OnMakeGamePublic();
  2071. }
  2072. else if ( !Q_stricmp( command, "OpenBenchmarkDialog" ) )
  2073. {
  2074. OnOpenBenchmarkDialog();
  2075. }
  2076. else if ( !Q_stricmp( command, "OpenServerBrowser" ) )
  2077. {
  2078. OnOpenServerBrowser();
  2079. }
  2080. else if ( !Q_stricmp( command, "CloseServerBrowser" ) )
  2081. {
  2082. OnCloseServerBrowser();
  2083. }
  2084. else if ( !Q_stricmp( command, "OpenCreateStartScreen" ) )
  2085. {
  2086. HandleOpenCreateStartScreen();
  2087. }
  2088. else if ( !V_stricmp( command, "RestoreTopLevelMenu" ) )
  2089. {
  2090. if ( GameUI().IsInLevel() )
  2091. {
  2092. RestorePauseMenu();
  2093. }
  2094. else
  2095. {
  2096. RestoreMainMenuScreen();
  2097. }
  2098. }
  2099. else if ( !V_stricmp( command, "FinishedIntroMovie" ) )
  2100. {
  2101. CreateStartScreenIfNeeded();
  2102. }
  2103. #if defined( _X360 )
  2104. else if ( !Q_stricmp( command, "ShowInvitePartyUI" ) )
  2105. {
  2106. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2107. if ( XShowPartyUI( XBX_GetActiveUserId() ) != ERROR_SUCCESS )
  2108. {
  2109. AssertMsg( false, "XBX_GetActiveUserId failed" );
  2110. }
  2111. }
  2112. else if ( !Q_stricmp( command, "ShowJoinPartyUI" ) )
  2113. {
  2114. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2115. if ( XShowCommunitySessionsUI( XBX_GetActiveUserId(), XSHOWCOMMUNITYSESSION_SHOWPARTY ) != ERROR_SUCCESS )
  2116. {
  2117. AssertMsg( false, "XShowCommunitySessionsUI failed" );
  2118. }
  2119. }
  2120. else if ( !Q_stricmp( command, "ShowInviteFriendsUI" ) )
  2121. {
  2122. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2123. if ( XShowFriendsUI( XBX_GetActiveUserId() ) != ERROR_SUCCESS )
  2124. {
  2125. AssertMsg( false, "XBX_GetActiveUserId failed" );
  2126. }
  2127. }
  2128. else if ( !Q_stricmp( command, "ShowLobbyUI" ) )
  2129. {
  2130. // Create the lobby UI, in this case we are launching it so we create it as the Host view
  2131. OnOpenCreateLobbyScreen( true );
  2132. }
  2133. else if ( !Q_stricmp( command, "ShowLobbyBrowser" ) )
  2134. {
  2135. OnOpenLobbyBrowserScreen( true );
  2136. }
  2137. #else // _X360
  2138. else if ( !Q_stricmp( command, "ShowInviteFriendsUI" ) )
  2139. {
  2140. #if !defined( _GAMECONSOLE ) && !defined( NO_STEAM ) // Steam overlay not available on console (PS3)
  2141. steamapicontext->SteamFriends()->ActivateGameOverlay( "LobbyInvite" );
  2142. #endif
  2143. }
  2144. else if ( !Q_stricmp( command, "ShowJoinPartyUI" ) )
  2145. {
  2146. OnOpenCreateLobbyScreen( true );
  2147. }
  2148. else if ( !Q_stricmp( command, "ShowLobbyUI" ) )
  2149. {
  2150. // Create the lobby UI, in this case we are launching it so we create it as the Host view
  2151. OnOpenCreateLobbyScreen( true );
  2152. }
  2153. #endif // !_X360
  2154. else if ( !Q_stricmp( command, "OpenCreateSinglePlayerGameDialog" ) || !Q_stricmp( command, "OpenCreateSinglePlayerGameDialog_AcceptNotConnectedToLive" ) )
  2155. {
  2156. if ( IsX360() )
  2157. {
  2158. //if ( !m_bHasConnectionToLive && !Q_stricmp( command, "OpenCreateSinglePlayerGameDialog" ) )
  2159. // ShowMessageDialog( MD_PROMPT_LEADERBOARD_LOST_CONNECTION_STARTING_SINGLEPLAYER );
  2160. //else
  2161. OnOpenCreateSingleplayerGameDialog( false );
  2162. }
  2163. else
  2164. {
  2165. OnOpenCreateSingleplayerGameDialog( false );
  2166. }
  2167. }
  2168. else if ( !Q_stricmp( command, "OpenLeaderboardsDialog" ) )
  2169. {
  2170. OnOpenLeaderboardsDialog();
  2171. }
  2172. else if ( !Q_stricmp( command, "OpenCallVoteDialog" ) )
  2173. {
  2174. OnOpenCallVoteDialog();
  2175. }
  2176. else if ( !V_stricmp( command, "OpenMarketplaceDialog" ) )
  2177. {
  2178. OnOpenMarketplace();
  2179. }
  2180. else if ( !V_stricmp( command, "OpenUpsellDialog" ) )
  2181. {
  2182. OnOpenUpsellDialog();
  2183. }
  2184. else if ( !V_stricmp( command, "PlayCreditsVideo" ) )
  2185. {
  2186. OnPlayCreditsVideo();
  2187. }
  2188. else if ( !V_stricmp( command, "RestoreMainMenu" ) )
  2189. {
  2190. RestoreMainMenuScreen();
  2191. }
  2192. else if ( !Q_stricmp( command, "CloseLeaderboardsDialog" ) )
  2193. {
  2194. CloseLeaderboardsDialog();
  2195. }
  2196. else if ( !Q_stricmp( command, "OpenFriendsDialog" ) )
  2197. {
  2198. OnOpenFriendsDialog();
  2199. }
  2200. else if ( !Q_stricmp( command, "OpenLoadDemoDialog" ) )
  2201. {
  2202. OnOpenDemoDialog();
  2203. }
  2204. else if ( !Q_stricmp( command, "OpenCreateMultiplayerGameDialog" ) )
  2205. {
  2206. if ( !ui_test_community_matchmaking.GetBool() )
  2207. OnOpenCreateMultiplayerGameDialog();
  2208. else
  2209. OnOpenCreateMultiplayerGameCommunity();
  2210. }
  2211. else if ( !Q_stricmp( command, "OpenCreateMultiplayerGameCommunity" ) )
  2212. {
  2213. OnOpenCreateMultiplayerGameCommunity();
  2214. }
  2215. else if ( !Q_stricmp( command, "OpenMedalsDialog" ) )
  2216. {
  2217. OnOpenMedalsDialog();
  2218. }
  2219. else if ( !Q_stricmp( command, "OpenStatsDialog" ) )
  2220. {
  2221. OnOpenStatsDialog();
  2222. }
  2223. else if ( !Q_stricmp( command, "CloseMedalsStatsDialog" ) )
  2224. {
  2225. CloseMedalsStatsDialog();
  2226. }
  2227. else if ( !Q_stricmp( command, "OpenChangeGameDialog" ) )
  2228. {
  2229. OnOpenChangeGameDialog();
  2230. }
  2231. else if ( !Q_stricmp( command, "OpenLoadCommentaryDialog" ) )
  2232. {
  2233. OnOpenLoadCommentaryDialog();
  2234. }
  2235. else if ( !Q_stricmp( command, "OpenLoadSingleplayerCommentaryDialog" ) )
  2236. {
  2237. OpenLoadSingleplayerCommentaryDialog();
  2238. }
  2239. else if ( !Q_stricmp( command, "OpenHowToPlayDialog" ) )
  2240. {
  2241. OnOpenHowToPlayDialog();
  2242. }
  2243. else if ( !Q_stricmp( command, "OpenAchievementsDialog" ) )
  2244. {
  2245. if ( IsPC() )
  2246. {
  2247. if ( !steamapicontext->SteamUser() || !steamapicontext->SteamUser()->BLoggedOn() )
  2248. {
  2249. vgui::MessageBox *pMessageBox = new vgui::MessageBox("#GameUI_Achievements_SteamRequired_Title", "#GameUI_Achievements_SteamRequired_Message");
  2250. pMessageBox->DoModal();
  2251. return;
  2252. }
  2253. OnOpenAchievementsDialog();
  2254. }
  2255. else
  2256. {
  2257. OnOpenAchievementsDialog_Xbox();
  2258. }
  2259. }
  2260. else if ( !Q_stricmp( command, "OpenCSAchievementsDialog" ) )
  2261. {
  2262. if ( IsPC() )
  2263. {
  2264. if ( !steamapicontext->SteamUser() || !steamapicontext->SteamUser()->BLoggedOn() )
  2265. {
  2266. vgui::MessageBox *pMessageBox = new vgui::MessageBox("#GameUI_Achievements_SteamRequired_Title", "#GameUI_Achievements_SteamRequired_Message", this );
  2267. pMessageBox->DoModal();
  2268. return;
  2269. }
  2270. OnOpenCSAchievementsDialog();
  2271. }
  2272. }
  2273. else if ( !Q_stricmp( command, "OpenAchievementsBlade" ) )
  2274. {
  2275. #if defined( _X360 )
  2276. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2277. int userID = XBX_GetActiveUserId();
  2278. XShowAchievementsUI( userID );
  2279. #endif
  2280. }
  2281. else if ( !Q_stricmp( command, "Quit" ) )
  2282. {
  2283. OnOpenQuitConfirmationDialog();
  2284. }
  2285. else if ( !Q_stricmp( command, "QuitToDesktop" ) )
  2286. {
  2287. OnOpenQuitConfirmationDialog( true );
  2288. }
  2289. else if ( !Q_stricmp( command, "QuitNoConfirm" ) )
  2290. {
  2291. if ( IsGameConsole() )
  2292. {
  2293. // start the shutdown process
  2294. StartExitingProcess();
  2295. }
  2296. else
  2297. {
  2298. // hide everything while we quit
  2299. SetVisible( false );
  2300. vgui::surface()->RestrictPaintToSinglePanel( GetVPanel() );
  2301. engine->ClientCmd_Unrestricted( "quit\n" );
  2302. }
  2303. }
  2304. else if ( !Q_stricmp( command, "QuitRestartNoConfirm" ) )
  2305. {
  2306. if ( IsGameConsole() )
  2307. {
  2308. // start the shutdown process
  2309. m_bRestartSameGame = true;
  2310. StartExitingProcess();
  2311. }
  2312. }
  2313. else if ( !Q_stricmp( command, "ResumeGame" ) )
  2314. {
  2315. GameUI().HideGameUI();
  2316. }
  2317. else if ( !Q_stricmp( command, "Disconnect" ) )
  2318. {
  2319. //if ( IsGameConsole() )
  2320. //{
  2321. OnOpenDisconnectConfirmationDialog();
  2322. //}
  2323. //else
  2324. //{
  2325. // engine->ClientCmd_Unrestricted( "disconnect" );
  2326. //}
  2327. }
  2328. else if ( !Q_stricmp( command, "DisconnectNoConfirm" ) )
  2329. {
  2330. // $FIXME(hpe) for now, just bail; uncomment the Convar if statements when we get that path working
  2331. engine->ClientCmd_Unrestricted( "disconnect" );
  2332. ConVarRef commentary( "commentary" );
  2333. //if ( commentary.IsValid() && commentary.GetBool() )
  2334. //{
  2335. // engine->ClientCmd_Unrestricted( "disconnect" );
  2336. //}
  2337. //else
  2338. //{
  2339. // Leave our current session, if we have one
  2340. // g_pMatchFramework->CloseSession();
  2341. //}
  2342. }
  2343. else if ( !Q_stricmp( command, "ReleaseModalWindow" ) )
  2344. {
  2345. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  2346. // [jason] $FIXME: If we had a modal vgui dialog active over Scaleform, we need to restore Scaleform afterwards
  2347. if ( IsScaleformMainMenuActive() || IsScaleformPauseMenuActive() )
  2348. {
  2349. m_MessageDialogHandler.CloseAllMessageDialogs();
  2350. NotifyVguiDialogClosed();
  2351. }
  2352. }
  2353. else if ( Q_stristr( command, "engine " ) ) // $$$REI Arbitrary console command execution from UI
  2354. {
  2355. const char *engineCMD = strstr( command, "engine " ) + strlen( "engine " );
  2356. if ( strlen( engineCMD ) > 0 )
  2357. {
  2358. engine->ClientCmd_Unrestricted( const_cast<char *>( engineCMD ) );
  2359. }
  2360. }
  2361. else if ( !Q_stricmp( command, "ShowSigninUI" ) )
  2362. {
  2363. m_bWaitingForUserSignIn = true;
  2364. xboxsystem->ShowSigninUI( 1, 0 ); // One user, no special flags
  2365. }
  2366. else if ( !Q_stricmp( command, "ShowDeviceSelector" ) )
  2367. {
  2368. OnChangeStorageDevice();
  2369. }
  2370. else if ( !Q_stricmp( command, "SignInDenied" ) )
  2371. {
  2372. // The user doesn't care, so re-send the command they wanted and mark that we want to skip checking
  2373. m_bUserRefusedSignIn = true;
  2374. if ( m_strPostPromptCommand.IsEmpty() == false )
  2375. {
  2376. OnCommand( m_strPostPromptCommand );
  2377. }
  2378. }
  2379. else if ( !Q_stricmp( command, "RequiredSignInDenied" ) )
  2380. {
  2381. m_strPostPromptCommand = "";
  2382. }
  2383. else if ( !Q_stricmp( command, "RequiredStorageDenied" ) )
  2384. {
  2385. m_strPostPromptCommand = "";
  2386. }
  2387. else if ( !Q_stricmp( command, "StorageDeviceDenied" ) )
  2388. {
  2389. // The user doesn't care, so re-send the command they wanted and mark that we want to skip checking
  2390. m_bUserRefusedStorageDevice = true;
  2391. IssuePostPromptCommand();
  2392. // Set us as declined
  2393. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2394. XBX_SetStorageDeviceId( XBX_GetActiveUserId(), XBX_STORAGE_DECLINED );
  2395. m_iStorageID = XBX_INVALID_STORAGE_ID;
  2396. if ( m_pStorageDeviceValidatedNotify )
  2397. {
  2398. *m_pStorageDeviceValidatedNotify = 2;
  2399. m_pStorageDeviceValidatedNotify = NULL;
  2400. }
  2401. }
  2402. else if ( !Q_stricmp( command, "clear_storage_deviceID" ) )
  2403. {
  2404. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2405. XBX_SetStorageDeviceId( XBX_GetActiveUserId(), XBX_STORAGE_DECLINED );
  2406. }
  2407. else if ( !Q_stricmp( command, "RestartWithNewLanguage" ) )
  2408. {
  2409. if ( !IsGameConsole() )
  2410. {
  2411. char szSteamURL[50];
  2412. char szAppId[50];
  2413. // hide everything while we quit
  2414. SetVisible( false );
  2415. vgui::surface()->RestrictPaintToSinglePanel( GetVPanel() );
  2416. engine->ClientCmd_Unrestricted( "quit\n" );
  2417. // Construct Steam URL. Pattern is steam://run/<appid>/<language>. (e.g. Ep1 In French ==> steam://run/380/french)
  2418. V_strcpy(szSteamURL, "steam://run/");
  2419. // dgoodenough - use Q_snprintf on PS3
  2420. // PS3_BUILDFIX
  2421. // @wge Fix for OSX too.
  2422. #if defined( _PS3 ) || defined( _OSX ) || defined (LINUX)
  2423. Q_snprintf( szAppId, 50, "%d", engine->GetAppID() );
  2424. szAppId[49] = 0;
  2425. #else
  2426. itoa( engine->GetAppID(), szAppId, 10 );
  2427. #endif
  2428. V_strcat( szSteamURL, szAppId, sizeof( szSteamURL ) );
  2429. V_strcat( szSteamURL, "/", sizeof( szSteamURL ) );
  2430. V_strcat( szSteamURL, COptionsSubAudio::GetUpdatedAudioLanguage(), sizeof( szSteamURL ) );
  2431. // Set Steam URL for re-launch in registry. Launcher will check this registry key and exec it in order to re-load the game in the proper language
  2432. // @wge HACK FIXME - Windows specific registry code.
  2433. #if !defined( _GAMECONSOLE ) && !defined( _OSX ) && !defined (LINUX)
  2434. HKEY hKey;
  2435. if ( IsPC() && RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Valve\\Source", NULL, KEY_WRITE, &hKey) == ERROR_SUCCESS )
  2436. {
  2437. RegSetValueEx( hKey, "Relaunch URL", 0, REG_SZ, (const unsigned char *)szSteamURL, sizeof( szSteamURL ) );
  2438. RegCloseKey(hKey);
  2439. }
  2440. #endif
  2441. }
  2442. }
  2443. else
  2444. {
  2445. BaseClass::OnCommand( command);
  2446. }
  2447. }
  2448. //-----------------------------------------------------------------------------
  2449. // Purpose: Queue a command to be run when XUI Closes
  2450. //-----------------------------------------------------------------------------
  2451. void CBaseModPanel::QueueCommand( const char *pCommand )
  2452. {
  2453. if ( m_bXUIVisible )
  2454. {
  2455. m_CommandQueue.AddToTail( CUtlString( pCommand ) );
  2456. }
  2457. else
  2458. {
  2459. OnCommand( pCommand );
  2460. }
  2461. }
  2462. //-----------------------------------------------------------------------------
  2463. // Purpose: Run all the commands in the queue
  2464. //-----------------------------------------------------------------------------
  2465. void CBaseModPanel::RunQueuedCommands()
  2466. {
  2467. for ( int i = 0; i < m_CommandQueue.Count(); ++i )
  2468. {
  2469. OnCommand( m_CommandQueue[i] );
  2470. }
  2471. ClearQueuedCommands();
  2472. }
  2473. //-----------------------------------------------------------------------------
  2474. // Purpose: Clear all queued commands
  2475. //-----------------------------------------------------------------------------
  2476. void CBaseModPanel::ClearQueuedCommands()
  2477. {
  2478. m_CommandQueue.Purge();
  2479. }
  2480. //-----------------------------------------------------------------------------
  2481. // Purpose: Whether this command should cause us to prompt the user if they're not signed in and do not have a storage device
  2482. //-----------------------------------------------------------------------------
  2483. bool CBaseModPanel::IsPromptableCommand( const char *command )
  2484. {
  2485. // Blech!
  2486. if ( !Q_stricmp( command, "OpenNewGameDialog" ) ||
  2487. !Q_stricmp( command, "OpenLoadGameDialog" ) ||
  2488. !Q_stricmp( command, "OpenSaveGameDialog" ) ||
  2489. !Q_stricmp( command, "OpenBonusMapsDialog" ) ||
  2490. !Q_stricmp( command, "OpenOptionsDialog" ) ||
  2491. !Q_stricmp( command, "OpenSettingsDialog" ) ||
  2492. !Q_stricmp( command, "OpenControllerDialog" ) ||
  2493. !Q_stricmp( command, "OpenMouseDialog" ) ||
  2494. !Q_stricmp( command, "OpenKeyboardDialog" ) ||
  2495. !Q_stricmp( command, "OpenMotionControllerMoveDialog" ) ||
  2496. !Q_stricmp( command, "OpenMotionControllerSharpshooterDialog" ) ||
  2497. !Q_stricmp( command, "OpenMotionControllerDialog" ) ||
  2498. !Q_stricmp( command, "OpenMotionCalibrationDialog" ) ||
  2499. !Q_stricmp( command, "OpenVideoSettingsDialog" ) ||
  2500. !Q_stricmp( command, "OpenOptionsQueued" ) ||
  2501. !Q_stricmp( command, "OpenAudioSettingsDialog" ) ||
  2502. !Q_stricmp( command, "OpenLoadCommentaryDialog" ) ||
  2503. !Q_stricmp( command, "OpenLoadSingleplayerCommentaryDialog" ) ||
  2504. !Q_stricmp( command, "OpenAchievementsDialog" ) ||
  2505. !Q_stricmp( command, "OpenCreateSinglePlayerGameDialog" ) )
  2506. {
  2507. return true;
  2508. }
  2509. return false;
  2510. }
  2511. #ifdef _WIN32
  2512. //-------------------------
  2513. // Purpose: Job wrapper
  2514. //-------------------------
  2515. static uintp PanelJobWrapperFn( void *pvContext )
  2516. {
  2517. CBaseModPanel::CAsyncJobContext *pAsync = reinterpret_cast< CBaseModPanel::CAsyncJobContext * >( pvContext );
  2518. float const flTimeStart = Plat_FloatTime();
  2519. pAsync->ExecuteAsync();
  2520. float const flElapsedTime = Plat_FloatTime() - flTimeStart;
  2521. if ( flElapsedTime < pAsync->m_flLeastExecuteTime )
  2522. {
  2523. ThreadSleep( ( pAsync->m_flLeastExecuteTime - flElapsedTime ) * 1000 );
  2524. }
  2525. ReleaseThreadHandle( ( ThreadHandle_t ) pAsync->m_hThreadHandle );
  2526. pAsync->m_hThreadHandle = NULL;
  2527. return 0;
  2528. }
  2529. #endif
  2530. //-----------------------------------------------------------------------------
  2531. // Purpose: Enqueues a job function to be called on a separate thread
  2532. //-----------------------------------------------------------------------------
  2533. void CBaseModPanel::ExecuteAsync( CAsyncJobContext *pAsync )
  2534. {
  2535. Assert( !m_pAsyncJob );
  2536. Assert( pAsync && !pAsync->m_hThreadHandle );
  2537. m_pAsyncJob = pAsync;
  2538. #ifdef _WIN32
  2539. ThreadHandle_t hHandle = CreateSimpleThread( PanelJobWrapperFn, reinterpret_cast< void * >( pAsync ) );
  2540. pAsync->m_hThreadHandle = hHandle;
  2541. #ifdef _GAMECONSOLE
  2542. ThreadSetAffinity( hHandle, XBOX_PROCESSOR_3 );
  2543. #endif
  2544. #else
  2545. pAsync->ExecuteAsync();
  2546. #endif
  2547. }
  2548. //-----------------------------------------------------------------------------
  2549. // Purpose: Whether this command requires the user be signed in
  2550. //-----------------------------------------------------------------------------
  2551. bool CBaseModPanel::CommandRequiresSignIn( const char *command )
  2552. {
  2553. // Blech again!
  2554. if ( !Q_stricmp( command, "OpenAchievementsDialog" ) ||
  2555. !Q_stricmp( command, "OpenLoadGameDialog" ) ||
  2556. !Q_stricmp( command, "OpenSaveGameDialog" ) ||
  2557. !Q_stricmp( command, "OpenRankingsDialog" ) )
  2558. return true;
  2559. return false;
  2560. }
  2561. //-----------------------------------------------------------------------------
  2562. // Purpose: Whether the command requires the user to have a valid storage device
  2563. //-----------------------------------------------------------------------------
  2564. bool CBaseModPanel::CommandRequiresStorageDevice( const char *command )
  2565. {
  2566. // Anything which touches the storage device must prompt
  2567. if ( !Q_stricmp( command, "OpenSaveGameDialog" ) ||
  2568. !Q_stricmp( command, "OpenLoadGameDialog" ) )
  2569. return true;
  2570. return false;
  2571. }
  2572. //-----------------------------------------------------------------------------
  2573. // Purpose: Whether the command requires the user to have a valid profile selected
  2574. //-----------------------------------------------------------------------------
  2575. bool CBaseModPanel::CommandRespectsSignInDenied( const char *command )
  2576. {
  2577. // Anything which touches the user profile must prompt
  2578. if ( !Q_stricmp( command, "OpenOptionsDialog" ) ||
  2579. !Q_stricmp( command, "OpenSettingsDialog" ) ||
  2580. !Q_stricmp( command, "OpenControllerDialog" ) ||
  2581. !Q_stricmp( command, "OpenMouseDialog" ) ||
  2582. !Q_stricmp( command, "OpenKeyboardDialog" ) ||
  2583. !Q_stricmp( command, "OpenMotionControllerMoveDialog" ) ||
  2584. !Q_stricmp( command, "OpenMotionControllerSharpshooterDialog" ) ||
  2585. !Q_stricmp( command, "OpenMotionControllerDialog" ) ||
  2586. !Q_stricmp( command, "OpenVideoSettingsDialog" ) ||
  2587. !Q_stricmp( command, "OpenOptionsQueued" ) ||
  2588. !Q_stricmp( command, "OpenAudioSettingsDialog" ) )
  2589. return true;
  2590. return false;
  2591. }
  2592. //-----------------------------------------------------------------------------
  2593. // Purpose: A storage device has been connected, update our settings and anything else
  2594. //-----------------------------------------------------------------------------
  2595. class CAsyncCtxOnDeviceAttached : public CBaseModPanel::CAsyncJobContext
  2596. {
  2597. public:
  2598. explicit CAsyncCtxOnDeviceAttached( int iController );
  2599. ~CAsyncCtxOnDeviceAttached();
  2600. virtual void ExecuteAsync();
  2601. virtual void Completed();
  2602. int GetController() { return m_iController; }
  2603. uint GetContainerOpenResult( void ) { return m_ContainerOpenResult; }
  2604. private:
  2605. int m_iController;
  2606. uint m_ContainerOpenResult;
  2607. };
  2608. CAsyncCtxOnDeviceAttached::CAsyncCtxOnDeviceAttached( int iController ) :
  2609. CBaseModPanel::CAsyncJobContext( 3.0f ), // Storage device info for at least 3 seconds
  2610. m_ContainerOpenResult( ERROR_SUCCESS ),
  2611. m_iController( iController )
  2612. {
  2613. BasePanel()->ShowMessageDialog( MD_CHECKING_STORAGE_DEVICE );
  2614. }
  2615. CAsyncCtxOnDeviceAttached::~CAsyncCtxOnDeviceAttached()
  2616. {
  2617. BasePanel()->CloseMessageDialog( 0 );
  2618. }
  2619. void CAsyncCtxOnDeviceAttached::ExecuteAsync()
  2620. {
  2621. // Asynchronously do the tasks that don't interact with the command buffer
  2622. // Open user settings and save game container here
  2623. m_ContainerOpenResult = engine->OnStorageDeviceAttached( GetController() );
  2624. if ( m_ContainerOpenResult != ERROR_SUCCESS )
  2625. return;
  2626. // Make the QOS system initialized for multiplayer games
  2627. if ( !ModInfo().IsSinglePlayerOnly() )
  2628. {
  2629. #if defined( _GAMECONSOLE )
  2630. #pragma message( __FILE__ "(" __LINE__AS_STRING ") : warning custom: This is just a best guess at the right replacement to get rotted code compiling" )
  2631. //( void ) matchmaking->GetQosWithLIVE();
  2632. g_pMatchFramework->GetMatchNetworkMsgController()->GetQOS();
  2633. #endif
  2634. }
  2635. }
  2636. void CAsyncCtxOnDeviceAttached::Completed()
  2637. {
  2638. BasePanel()->OnCompletedAsyncDeviceAttached( this );
  2639. }
  2640. void CBaseModPanel::OnDeviceAttached( void )
  2641. {
  2642. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2643. ExecuteAsync( new CAsyncCtxOnDeviceAttached( XBX_GetActiveUserId() ) );
  2644. }
  2645. void CBaseModPanel::OnCompletedAsyncDeviceAttached( CAsyncCtxOnDeviceAttached *job )
  2646. {
  2647. uint nRet = job->GetContainerOpenResult();
  2648. if ( nRet != ERROR_SUCCESS )
  2649. {
  2650. // Invalidate the device
  2651. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2652. XBX_SetStorageDeviceId( XBX_GetActiveUserId(), XBX_INVALID_STORAGE_ID );
  2653. // FIXME: We don't know which device failed!
  2654. // Pop a dialog explaining that the user's data is corrupt
  2655. BasePanel()->ShowMessageDialog( MD_STORAGE_DEVICES_CORRUPT );
  2656. }
  2657. // First part of the device checking completed asynchronously,
  2658. // perform the rest of duties that require to run on main thread.
  2659. engine->ReadConfiguration( -1, false );
  2660. engine->ExecuteClientCmd( "refreshplayerstats" );
  2661. BonusMapsDatabase()->ReadBonusMapSaveData();
  2662. if ( m_hSaveGameDialog_Xbox.Get() )
  2663. {
  2664. m_hSaveGameDialog_Xbox->OnCommand( "RefreshSaveGames" );
  2665. }
  2666. if ( m_hLoadGameDialog_Xbox.Get() )
  2667. {
  2668. m_hLoadGameDialog_Xbox->OnCommand( "RefreshSaveGames" );
  2669. }
  2670. if ( m_pStorageDeviceValidatedNotify )
  2671. {
  2672. *m_pStorageDeviceValidatedNotify = 1;
  2673. m_pStorageDeviceValidatedNotify = NULL;
  2674. }
  2675. // Finish their command
  2676. IssuePostPromptCommand();
  2677. }
  2678. //-----------------------------------------------------------------------------
  2679. // Purpose: FIXME: Only TF takes this path...
  2680. //-----------------------------------------------------------------------------
  2681. bool CBaseModPanel::ValidateStorageDevice( void )
  2682. {
  2683. if ( m_bUserRefusedStorageDevice == false )
  2684. {
  2685. #if defined( _GAMECONSOLE )
  2686. #pragma message( __FILE__ "(" __LINE__AS_STRING ") : warning custom: Slamming controller for xbox storage id to 0" )
  2687. if ( XBX_GetStorageDeviceId( 0 ) == XBX_INVALID_STORAGE_ID )
  2688. {
  2689. // Try to discover content on the user's storage devices
  2690. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2691. DWORD nFoundDevice = xboxsystem->DiscoverUserData( XBX_GetActiveUserId(), COM_GetModDirectory() );
  2692. if ( nFoundDevice == XBX_INVALID_STORAGE_ID )
  2693. {
  2694. // They don't have a device, so ask for one
  2695. ShowMessageDialog( MD_PROMPT_STORAGE_DEVICE );
  2696. return false;
  2697. }
  2698. else
  2699. {
  2700. // Take this device
  2701. XBX_SetStorageDeviceId( XBX_GetActiveUserId(), nFoundDevice );
  2702. OnDeviceAttached();
  2703. }
  2704. // Fall through
  2705. }
  2706. #endif
  2707. }
  2708. return true;
  2709. }
  2710. bool CBaseModPanel::ValidateStorageDevice( int *pStorageDeviceValidated )
  2711. {
  2712. if ( m_pStorageDeviceValidatedNotify )
  2713. {
  2714. if ( pStorageDeviceValidated != m_pStorageDeviceValidatedNotify )
  2715. {
  2716. *m_pStorageDeviceValidatedNotify = -1;
  2717. m_pStorageDeviceValidatedNotify = NULL;
  2718. }
  2719. else
  2720. {
  2721. return false;
  2722. }
  2723. }
  2724. if ( pStorageDeviceValidated )
  2725. {
  2726. if ( HandleStorageDeviceRequest( "" ) )
  2727. return true;
  2728. m_pStorageDeviceValidatedNotify = pStorageDeviceValidated;
  2729. return false;
  2730. }
  2731. return false;
  2732. }
  2733. //-----------------------------------------------------------------------------
  2734. // Purpose: Monitor commands for certain necessary cases
  2735. // Input : *command - What menu command we're policing
  2736. //-----------------------------------------------------------------------------
  2737. bool CBaseModPanel::HandleSignInRequest( const char *command )
  2738. {
  2739. // dgoodenough - limit this to X360
  2740. // PS3_BUILDFIX
  2741. // FIXME - do we want to have somehting here for PS3?
  2742. #if defined( _X360 )
  2743. // If we have a post-prompt command, we're coming back into the call from that prompt
  2744. bool bQueuedCall = ( m_strPostPromptCommand.IsEmpty() == false );
  2745. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2746. XUSER_SIGNIN_INFO info;
  2747. bool bValidUser = ( XUserGetSigninInfo( XBX_GetActiveUserId(), 0, &info ) == ERROR_SUCCESS );
  2748. if ( bValidUser )
  2749. return true;
  2750. // Queued command means we're returning from a prompt or blade
  2751. if ( bQueuedCall )
  2752. {
  2753. // Blade has returned with nothing
  2754. if ( m_bUserRefusedSignIn )
  2755. return true;
  2756. // User has not denied the storage device, so ask
  2757. ShowMessageDialog( MD_PROMPT_SIGNIN );
  2758. m_strPostPromptCommand = command;
  2759. // Do not run command
  2760. return false;
  2761. }
  2762. else
  2763. {
  2764. // If the user refused the sign-in and we respect that on this command, we're done
  2765. if ( m_bUserRefusedSignIn && CommandRespectsSignInDenied( command ) )
  2766. return true;
  2767. // If the message is required first, then do that instead
  2768. if ( CommandRequiresSignIn( command ) )
  2769. {
  2770. ShowMessageDialog( MD_PROMPT_SIGNIN_REQUIRED );
  2771. m_strPostPromptCommand = command;
  2772. return false;
  2773. }
  2774. // Pop a blade out
  2775. xboxsystem->ShowSigninUI( 1, 0 );
  2776. m_strPostPromptCommand = command;
  2777. m_bWaitingForUserSignIn = true;
  2778. m_bUserRefusedSignIn = false;
  2779. return false;
  2780. }
  2781. #endif // _GAMECONSOLE
  2782. return true;
  2783. }
  2784. //-----------------------------------------------------------------------------
  2785. // Purpose:
  2786. // Input : *command -
  2787. //-----------------------------------------------------------------------------
  2788. bool CBaseModPanel::HandleStorageDeviceRequest( const char *command )
  2789. {
  2790. // If we don't have a valid sign-in, then we do nothing!
  2791. if ( m_bUserRefusedSignIn )
  2792. return true;
  2793. // If we have a valid storage device, there's nothing to prompt for
  2794. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  2795. if ( XBX_GetStorageDeviceId( XBX_GetActiveUserId() ) != XBX_INVALID_STORAGE_ID && XBX_GetStorageDeviceId( XBX_GetActiveUserId() ) != XBX_STORAGE_DECLINED )
  2796. return true;
  2797. // If we have a post-prompt command, we're coming back into the call from that prompt
  2798. bool bQueuedCall = ( m_strPostPromptCommand.IsEmpty() == false );
  2799. // Are we returning from a prompt?
  2800. if ( bQueuedCall && m_bStorageBladeShown )
  2801. {
  2802. // User has declined
  2803. if ( m_bUserRefusedStorageDevice )
  2804. return true;
  2805. // Prompt them
  2806. ShowMessageDialog( MD_PROMPT_STORAGE_DEVICE );
  2807. m_strPostPromptCommand = command;
  2808. // Do not run the command
  2809. return false;
  2810. }
  2811. else
  2812. {
  2813. // If the user refused the sign-in and we respect that on this command, we're done
  2814. if ( m_bUserRefusedStorageDevice && CommandRespectsSignInDenied( command ) )
  2815. return true;
  2816. #if 0 // This attempts to find user data, but may not be cert-worthy even though it's a bit nicer for the user
  2817. // Attempt to automatically find a device
  2818. DWORD nFoundDevice = xboxsystem->DiscoverUserData( XBX_GetPrimaryUserId(), COM_GetModDirectory() );
  2819. if ( nFoundDevice != XBX_INVALID_STORAGE_ID )
  2820. {
  2821. // Take this device
  2822. XBX_SetStorageDeviceId( XBX_GetPrimaryUserId(), nFoundDevice );
  2823. OnDeviceAttached();
  2824. return true;
  2825. }
  2826. #endif //
  2827. // If the message is required first, then do that instead
  2828. if ( CommandRequiresStorageDevice( command ) )
  2829. {
  2830. ShowMessageDialog( MD_PROMPT_STORAGE_DEVICE_REQUIRED );
  2831. m_strPostPromptCommand = command;
  2832. return false;
  2833. }
  2834. // This is a misnomer of the first order!
  2835. OnChangeStorageDevice();
  2836. m_strPostPromptCommand = command;
  2837. m_bStorageBladeShown = true;
  2838. m_bUserRefusedStorageDevice = false;
  2839. return false;
  2840. }
  2841. return true;
  2842. }
  2843. //-----------------------------------------------------------------------------
  2844. // Purpose: Clear the command we've queued once it has succeeded in being called
  2845. //-----------------------------------------------------------------------------
  2846. void CBaseModPanel::ClearPostPromptCommand( const char *pCompletedCommand )
  2847. {
  2848. if ( !Q_stricmp( m_strPostPromptCommand, pCompletedCommand ) )
  2849. {
  2850. // All commands are executed, so stop holding this
  2851. m_strPostPromptCommand = "";
  2852. }
  2853. }
  2854. //-----------------------------------------------------------------------------
  2855. // Purpose: Issue our queued command to either the base panel or the matchmaking panel
  2856. //-----------------------------------------------------------------------------
  2857. void CBaseModPanel::IssuePostPromptCommand( void )
  2858. {
  2859. // The device is valid, so launch any pending commands
  2860. if ( m_strPostPromptCommand.IsEmpty() == false )
  2861. {
  2862. if ( m_bSinglePlayer )
  2863. {
  2864. OnCommand( m_strPostPromptCommand );
  2865. }
  2866. }
  2867. }
  2868. //-----------------------------------------------------------------------------
  2869. // Purpose: message handler for menu selections
  2870. //-----------------------------------------------------------------------------
  2871. void CBaseModPanel::OnCommand( const char *command )
  2872. {
  2873. if ( GameUI().IsConsoleUI() )
  2874. {
  2875. #if defined( _GAMECONSOLE )
  2876. // See if this is a command we need to intercept
  2877. if ( IsPromptableCommand( command ) )
  2878. {
  2879. // Handle the sign in case
  2880. if ( HandleSignInRequest( command ) == false )
  2881. return;
  2882. // Handle storage
  2883. if ( HandleStorageDeviceRequest( command ) == false )
  2884. return;
  2885. // If we fall through, we'll need to track this again
  2886. m_bStorageBladeShown = false;
  2887. // Fall through
  2888. }
  2889. #endif // _GAMECONSOLE
  2890. RunAnimationWithCallback( this, command, new KeyValues( "RunMenuCommand", "command", command ) );
  2891. // Clear our pending command if we just executed it
  2892. ClearPostPromptCommand( command );
  2893. }
  2894. else
  2895. {
  2896. RunMenuCommand( command );
  2897. }
  2898. }
  2899. //-----------------------------------------------------------------------------
  2900. // Purpose: runs an animation sequence, then calls a message mapped function
  2901. // when the animation is complete.
  2902. //-----------------------------------------------------------------------------
  2903. void CBaseModPanel::RunAnimationWithCallback( vgui::Panel *parent, const char *animName, KeyValues *msgFunc )
  2904. {
  2905. if ( !m_pConsoleAnimationController )
  2906. return;
  2907. m_pConsoleAnimationController->StartAnimationSequence( animName );
  2908. float sequenceLength = m_pConsoleAnimationController->GetAnimationSequenceLength( animName );
  2909. if ( sequenceLength )
  2910. {
  2911. sequenceLength += g_flAnimationPadding;
  2912. }
  2913. if ( parent && msgFunc )
  2914. {
  2915. PostMessage( parent, msgFunc, sequenceLength );
  2916. }
  2917. }
  2918. //-----------------------------------------------------------------------------
  2919. // Purpose: trinary choice query "save & quit", "quit", "cancel"
  2920. //-----------------------------------------------------------------------------
  2921. class CSaveBeforeQuitQueryDialog : public vgui::Frame
  2922. {
  2923. DECLARE_CLASS_SIMPLE( CSaveBeforeQuitQueryDialog, vgui::Frame );
  2924. public:
  2925. CSaveBeforeQuitQueryDialog(vgui::Panel *parent, const char *name) : BaseClass(parent, name)
  2926. {
  2927. LoadControlSettings("resource/SaveBeforeQuitDialog.res");
  2928. SetDeleteSelfOnClose(true);
  2929. SetSizeable(false);
  2930. }
  2931. void DoModal()
  2932. {
  2933. BaseClass::Activate();
  2934. vgui::input()->SetAppModalSurface(GetVPanel());
  2935. MoveToCenterOfScreen();
  2936. vgui::surface()->RestrictPaintToSinglePanel(GetVPanel());
  2937. GameUI().PreventEngineHideGameUI();
  2938. }
  2939. void OnKeyCodePressed(KeyCode code)
  2940. {
  2941. // ESC cancels
  2942. if ( code == KEY_ESCAPE )
  2943. {
  2944. Close();
  2945. }
  2946. else
  2947. {
  2948. BaseClass::OnKeyCodePressed(code);
  2949. }
  2950. }
  2951. virtual void OnCommand(const char *command)
  2952. {
  2953. if (!Q_stricmp(command, "Quit"))
  2954. {
  2955. PostMessage(GetVParent(), new KeyValues("Command", "command", "QuitNoConfirm"));
  2956. }
  2957. else if (!Q_stricmp(command, "SaveAndQuit"))
  2958. {
  2959. // find a new name to save
  2960. char saveName[128];
  2961. CSaveGameDialog::FindSaveSlot( saveName, sizeof(saveName) );
  2962. if ( saveName && saveName[ 0 ] )
  2963. {
  2964. // save the game
  2965. char sz[ 256 ];
  2966. Q_snprintf(sz, sizeof( sz ), "save %s\n", saveName );
  2967. engine->ClientCmd_Unrestricted( sz );
  2968. }
  2969. // quit
  2970. PostMessage(GetVParent(), new KeyValues("Command", "command", "QuitNoConfirm"));
  2971. }
  2972. else if (!Q_stricmp(command, "Cancel"))
  2973. {
  2974. Close();
  2975. }
  2976. else
  2977. {
  2978. BaseClass::OnCommand(command);
  2979. }
  2980. }
  2981. virtual void OnClose()
  2982. {
  2983. BaseClass::OnClose();
  2984. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  2985. GameUI().AllowEngineHideGameUI();
  2986. }
  2987. };
  2988. //-----------------------------------------------------------------------------
  2989. // Purpose: simple querybox that accepts escape
  2990. //-----------------------------------------------------------------------------
  2991. class CQuitQueryBox : public vgui::QueryBox
  2992. {
  2993. DECLARE_CLASS_SIMPLE( CQuitQueryBox, vgui::QueryBox );
  2994. public:
  2995. CQuitQueryBox(const char *title, const char *info, Panel *parent) : BaseClass( title, info, parent )
  2996. {
  2997. }
  2998. void DoModal( Frame* pFrameOver )
  2999. {
  3000. BaseClass::DoModal( pFrameOver );
  3001. vgui::surface()->RestrictPaintToSinglePanel(GetVPanel());
  3002. GameUI().PreventEngineHideGameUI();
  3003. }
  3004. void OnKeyCodePressed(KeyCode code)
  3005. {
  3006. // ESC cancels
  3007. if (code == KEY_ESCAPE)
  3008. {
  3009. Close();
  3010. }
  3011. else
  3012. {
  3013. BaseClass::OnKeyCodePressed(code);
  3014. }
  3015. }
  3016. virtual void OnClose()
  3017. {
  3018. BaseClass::OnClose();
  3019. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  3020. GameUI().AllowEngineHideGameUI();
  3021. }
  3022. };
  3023. //-----------------------------------------------------------------------------
  3024. // Purpose: asks user how they feel about quiting
  3025. //-----------------------------------------------------------------------------
  3026. void CBaseModPanel::OnOpenQuitConfirmationDialog( bool bForceToDesktop )
  3027. {
  3028. if ( GameUI().IsConsoleUI() )
  3029. {
  3030. if ( !GameUI().HasSavedThisMenuSession() && GameUI().IsInLevel() && engine->GetMaxClients() == 1 )
  3031. {
  3032. // single player, progress will be lost...
  3033. ShowMessageDialog( MD_SAVE_BEFORE_QUIT );
  3034. }
  3035. else
  3036. {
  3037. if ( m_bUseMatchmaking )
  3038. {
  3039. ShowMessageDialog( MD_QUIT_CONFIRMATION_TF );
  3040. }
  3041. else
  3042. {
  3043. ShowMessageDialog( MD_QUIT_CONFIRMATION );
  3044. }
  3045. }
  3046. return;
  3047. }
  3048. if ( GameUI().IsInLevel() && engine->GetMaxClients() == 1 )
  3049. {
  3050. // prompt for saving current game before quiting
  3051. CSaveBeforeQuitQueryDialog *box = new CSaveBeforeQuitQueryDialog(this, "SaveBeforeQuitQueryDialog");
  3052. box->DoModal();
  3053. }
  3054. else
  3055. {
  3056. // simple ok/cancel prompt
  3057. QueryBox *box = new CQuitQueryBox("#GameUI_QuitConfirmationTitle", "#GameUI_QuitConfirmationText", this);
  3058. box->SetOKButtonText("#GameUI_Quit");
  3059. box->SetOKCommand(new KeyValues("Command", "command", "QuitNoConfirm"));
  3060. box->SetCancelCommand(new KeyValues("Command", "command", "ReleaseModalWindow"));
  3061. box->AddActionSignalTarget(this);
  3062. box->DoModal();
  3063. }
  3064. }
  3065. //-----------------------------------------------------------------------------
  3066. // Purpose: asks user how they feel about disconnecting
  3067. //-----------------------------------------------------------------------------
  3068. void CBaseModPanel::OnOpenDisconnectConfirmationDialog()
  3069. {
  3070. // THis is for disconnecting from a multiplayer server
  3071. Assert( m_bUseMatchmaking );
  3072. Assert( IsGameConsole() );
  3073. if ( GameUI().IsConsoleUI() && GameUI().IsInLevel() )
  3074. {
  3075. if ( engine->GetLocalPlayer() == 1 )
  3076. {
  3077. ShowMessageDialog( MD_DISCONNECT_CONFIRMATION_HOST );
  3078. }
  3079. else
  3080. {
  3081. ShowMessageDialog( MD_DISCONNECT_CONFIRMATION );
  3082. }
  3083. }
  3084. }
  3085. //-----------------------------------------------------------------------------
  3086. // Purpose:
  3087. //-----------------------------------------------------------------------------
  3088. void CBaseModPanel::OnOpenNewGameDialog(const char *chapter )
  3089. {
  3090. if ( !m_hNewGameDialog.Get() )
  3091. {
  3092. m_hNewGameDialog = new CNewGameDialog(this, false);
  3093. PositionDialog( m_hNewGameDialog );
  3094. }
  3095. if ( chapter )
  3096. {
  3097. ((CNewGameDialog *)m_hNewGameDialog.Get())->SetSelectedChapter(chapter);
  3098. }
  3099. ((CNewGameDialog *)m_hNewGameDialog.Get())->SetCommentaryMode( false );
  3100. m_hNewGameDialog->Activate();
  3101. }
  3102. //-----------------------------------------------------------------------------
  3103. // Purpose:
  3104. //-----------------------------------------------------------------------------
  3105. void CBaseModPanel::OnOpenBonusMapsDialog( void )
  3106. {
  3107. if ( !m_hBonusMapsDialog.Get() )
  3108. {
  3109. m_hBonusMapsDialog = new CBonusMapsDialog(this);
  3110. PositionDialog( m_hBonusMapsDialog );
  3111. }
  3112. m_hBonusMapsDialog->Activate();
  3113. }
  3114. //-----------------------------------------------------------------------------
  3115. // Purpose:
  3116. //-----------------------------------------------------------------------------
  3117. void CBaseModPanel::OnOpenLoadGameDialog()
  3118. {
  3119. if ( !m_hLoadGameDialog.Get() )
  3120. {
  3121. m_hLoadGameDialog = new CLoadGameDialog(this);
  3122. PositionDialog( m_hLoadGameDialog );
  3123. }
  3124. m_hLoadGameDialog->Activate();
  3125. }
  3126. //-----------------------------------------------------------------------------
  3127. // Purpose:
  3128. //-----------------------------------------------------------------------------
  3129. void CBaseModPanel::OnOpenLoadGameDialog_Xbox()
  3130. {
  3131. if ( !m_hLoadGameDialog_Xbox.Get() )
  3132. {
  3133. m_hLoadGameDialog_Xbox = new CLoadGameDialogXbox(this);
  3134. PositionDialog( m_hLoadGameDialog_Xbox );
  3135. }
  3136. m_hLoadGameDialog_Xbox->Activate();
  3137. }
  3138. //-----------------------------------------------------------------------------
  3139. // Purpose:
  3140. //-----------------------------------------------------------------------------
  3141. void CBaseModPanel::OnOpenSaveGameDialog()
  3142. {
  3143. if ( !m_hSaveGameDialog.Get() )
  3144. {
  3145. m_hSaveGameDialog = new CSaveGameDialog(this);
  3146. PositionDialog( m_hSaveGameDialog );
  3147. }
  3148. m_hSaveGameDialog->Activate();
  3149. }
  3150. //-----------------------------------------------------------------------------
  3151. // Purpose:
  3152. //-----------------------------------------------------------------------------
  3153. void CBaseModPanel::OnOpenSaveGameDialog_Xbox()
  3154. {
  3155. if ( !m_hSaveGameDialog_Xbox.Get() )
  3156. {
  3157. m_hSaveGameDialog_Xbox = new CSaveGameDialogXbox(this);
  3158. PositionDialog( m_hSaveGameDialog_Xbox );
  3159. }
  3160. m_hSaveGameDialog_Xbox->Activate();
  3161. }
  3162. //-----------------------------------------------------------------------------
  3163. // Purpose:
  3164. //-----------------------------------------------------------------------------
  3165. void CBaseModPanel::OnOpenOptionsDialog()
  3166. {
  3167. if ( !m_hOptionsDialog.Get() )
  3168. {
  3169. m_hOptionsDialog = new COptionsDialog(this);
  3170. PositionDialog( m_hOptionsDialog );
  3171. }
  3172. m_hOptionsDialog->Activate();
  3173. }
  3174. //-----------------------------------------------------------------------------
  3175. // Purpose:
  3176. //-----------------------------------------------------------------------------
  3177. void CBaseModPanel::OnOpenSettingsDialog()
  3178. {
  3179. }
  3180. //-----------------------------------------------------------------------------
  3181. // Purpose:
  3182. //-----------------------------------------------------------------------------
  3183. void CBaseModPanel::OnOpenOptionsDialog_Xbox()
  3184. {
  3185. #if 0
  3186. if ( !m_hOptionsDialog_Xbox.Get() )
  3187. {
  3188. m_hOptionsDialog_Xbox = new COptionsDialogXbox( this );
  3189. PositionDialog( m_hOptionsDialog_Xbox );
  3190. }
  3191. m_hOptionsDialog_Xbox->Activate();
  3192. #endif
  3193. }
  3194. //-----------------------------------------------------------------------------
  3195. // Purpose: forces any changed options dialog settings to be applied immediately, if it's open
  3196. //-----------------------------------------------------------------------------
  3197. void CBaseModPanel::ApplyOptionsDialogSettings()
  3198. {
  3199. if (m_hOptionsDialog.Get())
  3200. {
  3201. m_hOptionsDialog->ApplyChanges();
  3202. }
  3203. }
  3204. //-----------------------------------------------------------------------------
  3205. // Purpose:
  3206. //-----------------------------------------------------------------------------
  3207. void CBaseModPanel::OnOpenControllerDialog()
  3208. {
  3209. }
  3210. //-----------------------------------------------------------------------------
  3211. // Purpose:
  3212. //-----------------------------------------------------------------------------
  3213. void CBaseModPanel::OnOpenMouseDialog()
  3214. {
  3215. }
  3216. //-----------------------------------------------------------------------------
  3217. // Purpose:
  3218. //-----------------------------------------------------------------------------
  3219. void CBaseModPanel::OnOpenKeyboardDialog()
  3220. {
  3221. }
  3222. //-----------------------------------------------------------------------------
  3223. // Purpose:
  3224. //-----------------------------------------------------------------------------
  3225. void CBaseModPanel::OnOpenMotionControllerDialog()
  3226. {
  3227. }
  3228. //-----------------------------------------------------------------------------
  3229. // Purpose:
  3230. //-----------------------------------------------------------------------------
  3231. void CBaseModPanel::OnOpenMotionControllerMoveDialog()
  3232. {
  3233. }
  3234. //-----------------------------------------------------------------------------
  3235. // Purpose:
  3236. //-----------------------------------------------------------------------------
  3237. void CBaseModPanel::OnOpenMotionControllerSharpshooterDialog()
  3238. {
  3239. }
  3240. //-----------------------------------------------------------------------------
  3241. // Purpose:
  3242. //-----------------------------------------------------------------------------
  3243. void CBaseModPanel::OnOpenMotionCalibrationDialog()
  3244. {
  3245. }
  3246. //-----------------------------------------------------------------------------
  3247. // Purpose:
  3248. //-----------------------------------------------------------------------------
  3249. void CBaseModPanel::OnOpenVideoSettingsDialog()
  3250. {
  3251. }
  3252. //-----------------------------------------------------------------------------
  3253. // Purpose:
  3254. //-----------------------------------------------------------------------------
  3255. void CBaseModPanel::OnOpenOptionsQueued()
  3256. {
  3257. }
  3258. //-----------------------------------------------------------------------------
  3259. // Purpose:
  3260. //-----------------------------------------------------------------------------
  3261. void CBaseModPanel::OnOpenAudioSettingsDialog()
  3262. {
  3263. }
  3264. //-----------------------------------------------------------------------------
  3265. // Purpose:
  3266. //-----------------------------------------------------------------------------
  3267. void CBaseModPanel::OnOpenBenchmarkDialog()
  3268. {
  3269. if (!m_hBenchmarkDialog.Get())
  3270. {
  3271. m_hBenchmarkDialog = new CBenchmarkDialog(this, "BenchmarkDialog");
  3272. PositionDialog( m_hBenchmarkDialog );
  3273. }
  3274. m_hBenchmarkDialog->Activate();
  3275. }
  3276. //-----------------------------------------------------------------------------
  3277. // Purpose:
  3278. //-----------------------------------------------------------------------------
  3279. void CBaseModPanel::OnCloseServerBrowser()
  3280. {
  3281. #if !defined(_GAMECONSOLE)
  3282. // HACK: Server browser is module index = 0, which may change if the list is reordered in the res file
  3283. if ( g_VModuleLoader.GetModuleCount() > 0 && g_VModuleLoader.IsModuleVisible(0) )
  3284. g_VModuleLoader.PostMessageToModule("Servers", new KeyValues( "RunModuleCommand", "command", "Close" ) );
  3285. #endif
  3286. }
  3287. //-----------------------------------------------------------------------------
  3288. // Purpose:
  3289. //-----------------------------------------------------------------------------
  3290. void CBaseModPanel::OnOpenFriendsDialog()
  3291. {
  3292. g_VModuleLoader.ActivateModule("Friends");
  3293. }
  3294. //-----------------------------------------------------------------------------
  3295. // Purpose:
  3296. //-----------------------------------------------------------------------------
  3297. void CBaseModPanel::OnOpenDemoDialog()
  3298. {
  3299. /* if ( !m_hDemoPlayerDialog.Get() )
  3300. {
  3301. m_hDemoPlayerDialog = new CDemoPlayerDialog(this);
  3302. PositionDialog( m_hDemoPlayerDialog );
  3303. }
  3304. m_hDemoPlayerDialog->Activate();*/
  3305. }
  3306. //-----------------------------------------------------------------------------
  3307. // Purpose:
  3308. //-----------------------------------------------------------------------------
  3309. void CBaseModPanel::OnOpenCreateMultiplayerGameDialog()
  3310. {
  3311. if (!m_hCreateMultiplayerGameDialog.Get())
  3312. {
  3313. m_hCreateMultiplayerGameDialog = new CCreateMultiplayerGameDialog(this);
  3314. PositionDialog(m_hCreateMultiplayerGameDialog);
  3315. }
  3316. m_hCreateMultiplayerGameDialog->Activate();
  3317. }
  3318. //-----------------------------------------------------------------------------
  3319. // Purpose:
  3320. //-----------------------------------------------------------------------------
  3321. void CBaseModPanel::OnOpenCreateMultiplayerGameCommunity()
  3322. {
  3323. //
  3324. }
  3325. //-----------------------------------------------------------------------------
  3326. // Purpose: Determine if the local player is part of a team multiplayer lobby
  3327. //-----------------------------------------------------------------------------
  3328. bool CBaseModPanel::InTeamLobby( void )
  3329. {
  3330. if ( g_pMatchFramework )
  3331. {
  3332. IMatchSession *pMatchSession = g_pMatchFramework->GetMatchSession();
  3333. if ( pMatchSession )
  3334. {
  3335. KeyValues *pSettings = pMatchSession->GetSessionSettings();
  3336. const char *pszNetflag = pSettings->GetString( "system/netflag", NULL );
  3337. if ( pszNetflag && !V_stricmp( pszNetflag, "teamlobby" ) )
  3338. return true;
  3339. }
  3340. }
  3341. return false;
  3342. }
  3343. //-----------------------------------------------------------------------------
  3344. // Purpose:
  3345. //-----------------------------------------------------------------------------
  3346. void CBaseModPanel::OnOpenMedalsDialog()
  3347. {
  3348. // Do nothing, unless we're in Cstrike with Scaleform
  3349. }
  3350. //-----------------------------------------------------------------------------
  3351. // Purpose:
  3352. //-----------------------------------------------------------------------------
  3353. void CBaseModPanel::OnOpenStatsDialog()
  3354. {
  3355. // Do nothing, unless we're in Cstrike with Scaleform
  3356. }
  3357. //-----------------------------------------------------------------------------
  3358. // Purpose:
  3359. //-----------------------------------------------------------------------------
  3360. void CBaseModPanel::CloseMedalsStatsDialog()
  3361. {
  3362. // Do nothing, unless we're in Cstrike with Scaleform
  3363. }
  3364. //-----------------------------------------------------------------------------
  3365. // Purpose:
  3366. //-----------------------------------------------------------------------------
  3367. void CBaseModPanel::OnOpenLeaderboardsDialog()
  3368. {
  3369. // Do nothing, unless we're in Cstrike with Scaleform
  3370. }
  3371. //-----------------------------------------------------------------------------
  3372. // Purpose:
  3373. //-----------------------------------------------------------------------------
  3374. void CBaseModPanel::OnOpenCallVoteDialog()
  3375. {
  3376. // Do nothing, unless we're in Cstrike with Scaleform
  3377. }
  3378. //-----------------------------------------------------------------------------
  3379. // Purpose:
  3380. //-----------------------------------------------------------------------------
  3381. void CBaseModPanel::OnOpenMarketplace()
  3382. {
  3383. // Do nothing, unless we're in Cstrike with Scaleform
  3384. }
  3385. //-----------------------------------------------------------------------------
  3386. // Purpose:
  3387. //-----------------------------------------------------------------------------
  3388. void CBaseModPanel::UpdateLeaderboardsDialog()
  3389. {
  3390. // Do nothing, unless we're in Cstrike with Scaleform
  3391. }
  3392. //-----------------------------------------------------------------------------
  3393. // Purpose:
  3394. //-----------------------------------------------------------------------------
  3395. void CBaseModPanel::CloseLeaderboardsDialog()
  3396. {
  3397. // Do nothing, unless we're in Cstrike with Scaleform
  3398. }
  3399. //-----------------------------------------------------------------------------
  3400. // Purpose:
  3401. //-----------------------------------------------------------------------------
  3402. void CBaseModPanel::OnOpenChangeGameDialog()
  3403. {
  3404. if (!m_hChangeGameDialog.Get())
  3405. {
  3406. m_hChangeGameDialog = new CChangeGameDialog(this);
  3407. PositionDialog(m_hChangeGameDialog);
  3408. }
  3409. m_hChangeGameDialog->Activate();
  3410. }
  3411. //-----------------------------------------------------------------------------
  3412. // Purpose: [jason] Default implementation (non-Scaleform) for Start Screen
  3413. //-----------------------------------------------------------------------------
  3414. void CBaseModPanel::OnOpenCreateStartScreen()
  3415. {
  3416. // $TODO: Should we create a vgui version of this screen for non-scaleform builds?
  3417. // Or just bypass it and do nothing, going straight to the main menu
  3418. m_bShowStartScreen = false;
  3419. ShowMainMenu(true);
  3420. }
  3421. //-----------------------------------------------------------------------------
  3422. // Purpose: Code called from opencreatestartscreen command and when signing out
  3423. //-----------------------------------------------------------------------------
  3424. void CBaseModPanel::HandleOpenCreateStartScreen()
  3425. {
  3426. // Be sure to close any previously opened modal Scaleform screens before we restore start screen
  3427. DismissAllMainMenuScreens();
  3428. // [jason] Brings up the actual start screen for re-binding the primary user controller, etc.
  3429. m_bShowStartScreen = true;
  3430. m_bStartScreenPlayerSigninCompleted = false;
  3431. m_bWaitingForUserSignIn = false;
  3432. OnOpenCreateStartScreen();
  3433. }
  3434. void CBaseModPanel::DismissAllMainMenuScreens( bool bHideMainMenuOnly )
  3435. {
  3436. NOTE_UNUSED( bHideMainMenuOnly );
  3437. // Overloaded in Cstrike15BasePanel to perform actual screen closes
  3438. }
  3439. //-----------------------------------------------------------------------------
  3440. // Purpose:
  3441. //-----------------------------------------------------------------------------
  3442. void CBaseModPanel::DismissStartScreen()
  3443. {
  3444. // Do nothing, only the scaleform version needs to actually dismiss this scene
  3445. }
  3446. //-----------------------------------------------------------------------------
  3447. // Purpose:
  3448. //-----------------------------------------------------------------------------
  3449. bool CBaseModPanel::IsStartScreenActive( void )
  3450. {
  3451. // Overloaded in Cstrike15BasePanel for Scaleform
  3452. return false;
  3453. }
  3454. //-----------------------------------------------------------------------------
  3455. // Purpose:
  3456. //-----------------------------------------------------------------------------
  3457. void CBaseModPanel::SignInFromStartScreen()
  3458. {
  3459. m_bWaitingForUserSignIn = true;
  3460. m_bUserRefusedSignIn = true;
  3461. xboxsystem->ShowSigninUI( 1, 0 ); // One user, no special flags
  3462. }
  3463. //-----------------------------------------------------------------------------
  3464. // Purpose:
  3465. //-----------------------------------------------------------------------------
  3466. void CBaseModPanel::NotifySignInCompleted(int userID)
  3467. {
  3468. // $TODO: sanity checks to verify that we have someone signed in, as needed
  3469. if ( IsStartScreenActive() && m_bWaitingForUserSignIn )
  3470. {
  3471. m_primaryUserId = userID;
  3472. m_bWaitingForUserSignIn = false;
  3473. m_bUserRefusedSignIn = false;
  3474. m_bStartScreenPlayerSigninCompleted = true;
  3475. }
  3476. }
  3477. //-----------------------------------------------------------------------------
  3478. // Purpose:
  3479. //-----------------------------------------------------------------------------
  3480. void CBaseModPanel::NotifySignInCancelled()
  3481. {
  3482. // $TODO: sanity checks to verify that we have someone signed in, as needed
  3483. if ( IsStartScreenActive() )
  3484. {
  3485. UnlockInput();
  3486. m_bWaitingForUserSignIn = false;
  3487. m_bStartScreenPlayerSigninCompleted = false;
  3488. }
  3489. }
  3490. //-----------------------------------------------------------------------------
  3491. // Purpose: [jason] Default implementation of the main menu
  3492. //-----------------------------------------------------------------------------
  3493. void CBaseModPanel::OnOpenCreateMainMenuScreen( void )
  3494. {
  3495. ShowMainMenu( true );
  3496. }
  3497. //-----------------------------------------------------------------------------
  3498. // Purpose:
  3499. //-----------------------------------------------------------------------------
  3500. void CBaseModPanel::DismissMainMenuScreen( void )
  3501. {
  3502. ShowMainMenu( false );
  3503. }
  3504. //-----------------------------------------------------------------------------
  3505. // Purpose:
  3506. //-----------------------------------------------------------------------------
  3507. void CBaseModPanel::RestoreMainMenuScreen( void )
  3508. {
  3509. ShowMainMenu( true );
  3510. }
  3511. //-----------------------------------------------------------------------------
  3512. // Purpose: Restore Scaleform main menu to shown, and hide the vgui main menu
  3513. //-----------------------------------------------------------------------------
  3514. void CBaseModPanel::NotifyVguiDialogClosed( void )
  3515. {
  3516. if ( GameUI().IsInLevel() )
  3517. {
  3518. if ( IsScaleformPauseMenuEnabled() && m_bMainMenuShown )
  3519. {
  3520. // Force the cursor to be under Scaleform control again
  3521. if ( IsPC() )
  3522. {
  3523. g_pMatSystemSurface->EnableWindowsMessages( false );
  3524. }
  3525. ShowMainMenu( false );
  3526. RestorePauseMenu();
  3527. }
  3528. }
  3529. else
  3530. {
  3531. if ( IsScaleformMainMenuEnabled() && m_bMainMenuShown )
  3532. {
  3533. ShowMainMenu( false );
  3534. RestoreMainMenuScreen();
  3535. }
  3536. }
  3537. }
  3538. //-----------------------------------------------------------------------------
  3539. // Purpose: Opens upsell dialog
  3540. //-----------------------------------------------------------------------------
  3541. void CBaseModPanel::OnOpenUpsellDialog( void )
  3542. {
  3543. /** Does nothing by default */
  3544. }
  3545. //-----------------------------------------------------------------------------
  3546. // Purpose: Plays the credits
  3547. //-----------------------------------------------------------------------------
  3548. void CBaseModPanel::OnPlayCreditsVideo()
  3549. {
  3550. engine->ClientCmd_Unrestricted( "playvideo credits" );
  3551. }
  3552. //-----------------------------------------------------------------------------
  3553. // Purpose:
  3554. //-----------------------------------------------------------------------------
  3555. void CBaseModPanel::ShowScaleformMainMenu( bool bShow )
  3556. {
  3557. /** Does nothing by default */
  3558. }
  3559. //-----------------------------------------------------------------------------
  3560. // Purpose:
  3561. //-----------------------------------------------------------------------------
  3562. bool CBaseModPanel::IsScaleformMainMenuActive( void )
  3563. {
  3564. return false;
  3565. }
  3566. //-----------------------------------------------------------------------------
  3567. // Purpose: Overridden if you want to use Scaleform to create the menu
  3568. //-----------------------------------------------------------------------------
  3569. void CBaseModPanel::OnOpenPauseMenu( void )
  3570. {
  3571. ShowMainMenu( true );
  3572. }
  3573. //-----------------------------------------------------------------------------
  3574. // Purpose: Overridden to clean up any non-vgui menu assets
  3575. //-----------------------------------------------------------------------------
  3576. void CBaseModPanel::DismissPauseMenu( void )
  3577. {
  3578. ShowMainMenu( false );
  3579. }
  3580. //-----------------------------------------------------------------------------
  3581. // Purpose: Overridden if you want to use Scaleform to create the menu
  3582. //-----------------------------------------------------------------------------
  3583. void CBaseModPanel::RestorePauseMenu( void )
  3584. {
  3585. ShowMainMenu( true );
  3586. }
  3587. //-----------------------------------------------------------------------------
  3588. // Purpose: To be overridden by Scaleform
  3589. //-----------------------------------------------------------------------------
  3590. void CBaseModPanel::ShowScaleformPauseMenu( bool bShow )
  3591. {
  3592. /** Does nothing by default */
  3593. }
  3594. //-----------------------------------------------------------------------------
  3595. // Purpose: To be overridden by Scaleform
  3596. //-----------------------------------------------------------------------------
  3597. bool CBaseModPanel::IsScaleformPauseMenuActive( void )
  3598. {
  3599. return false;
  3600. }
  3601. //-----------------------------------------------------------------------------
  3602. // Purpose: To be overridden by Scaleform
  3603. //-----------------------------------------------------------------------------
  3604. bool CBaseModPanel::IsScaleformPauseMenuVisible( void )
  3605. {
  3606. return false;
  3607. }
  3608. //-----------------------------------------------------------------------------
  3609. // Purpose: Change a private/friends match to a public one
  3610. //-----------------------------------------------------------------------------
  3611. void CBaseModPanel::OnMakeGamePublic( void )
  3612. {
  3613. IMatchSession *pMatchSession = g_pMatchFramework->GetMatchSession();
  3614. if ( !pMatchSession )
  3615. return;
  3616. // Check if this is already a public game
  3617. KeyValues* kv = pMatchSession->GetSessionSettings();
  3618. if ( kv )
  3619. {
  3620. char const *szAccess = kv->GetString( "system/access", NULL );
  3621. if ( szAccess )
  3622. {
  3623. if ( !Q_stricmp( "public", szAccess ) )
  3624. {
  3625. return;
  3626. }
  3627. }
  3628. }
  3629. // Update it to be public now
  3630. pMatchSession->UpdateSessionSettings( KeyValues::AutoDeleteInline( KeyValues::FromString(
  3631. "update",
  3632. " update { "
  3633. " system { "
  3634. " access public "
  3635. " } "
  3636. " } "
  3637. ) ) );
  3638. }
  3639. //-----------------------------------------------------------------------------
  3640. // Purpose:
  3641. //-----------------------------------------------------------------------------
  3642. void CBaseModPanel::OnOpenPlayerListDialog()
  3643. {
  3644. if (!m_hPlayerListDialog.Get())
  3645. {
  3646. m_hPlayerListDialog = new CPlayerListDialog(this);
  3647. PositionDialog(m_hPlayerListDialog);
  3648. }
  3649. m_hPlayerListDialog->Activate();
  3650. }
  3651. //-----------------------------------------------------------------------------
  3652. // Purpose:
  3653. //-----------------------------------------------------------------------------
  3654. void CBaseModPanel::OnOpenLoadCommentaryDialog()
  3655. {
  3656. if (!m_hPlayerListDialog.Get())
  3657. {
  3658. m_hLoadCommentaryDialog = new CLoadCommentaryDialog(this);
  3659. PositionDialog(m_hLoadCommentaryDialog);
  3660. }
  3661. m_hLoadCommentaryDialog->Activate();
  3662. }
  3663. //-----------------------------------------------------------------------------
  3664. // Purpose:
  3665. //-----------------------------------------------------------------------------
  3666. void CBaseModPanel::OpenLoadSingleplayerCommentaryDialog()
  3667. {
  3668. if ( !m_hNewGameDialog.Get() )
  3669. {
  3670. m_hNewGameDialog = new CNewGameDialog(this,true);
  3671. PositionDialog( m_hNewGameDialog );
  3672. }
  3673. ((CNewGameDialog *)m_hNewGameDialog.Get())->SetCommentaryMode( true );
  3674. m_hNewGameDialog->Activate();
  3675. }
  3676. void CBaseModPanel::OnOpenAchievementsDialog()
  3677. {
  3678. //if (!m_hAchievementsDialog.Get())
  3679. //{
  3680. // m_hAchievementsDialog = new CAchievementsDialog( this );
  3681. // PositionDialog(m_hAchievementsDialog);
  3682. //}
  3683. //m_hAchievementsDialog->Activate();
  3684. }
  3685. void CBaseModPanel::OnOpenCSAchievementsDialog()
  3686. {
  3687. if ( GameClientExports() )
  3688. {
  3689. int screenWide = 0;
  3690. int screenHeight = 0;
  3691. engine->GetScreenSize( screenWide, screenHeight );
  3692. // [smessick] For lower resolutions, open the Steam achievements instead of the CSS achievements screen.
  3693. if ( screenWide < GameClientExports()->GetAchievementsPanelMinWidth() )
  3694. {
  3695. ISteamFriends *friends = steamapicontext->SteamFriends();
  3696. if ( friends )
  3697. {
  3698. // Steam overlay not available on console (PS3)
  3699. #if !defined( _GAMECONSOLE ) && !defined( NO_STEAM )
  3700. friends->ActivateGameOverlay( "Achievements" );
  3701. #endif
  3702. }
  3703. }
  3704. else
  3705. {
  3706. // Display the CSS achievements screen.
  3707. GameClientExports()->CreateAchievementsPanel( this );
  3708. GameClientExports()->DisplayAchievementPanel();
  3709. }
  3710. }
  3711. }
  3712. void CBaseModPanel::OnOpenAchievementsDialog_Xbox()
  3713. {
  3714. #if 0
  3715. if (!m_hAchievementsDialog.Get())
  3716. {
  3717. m_hAchievementsDialog = new CAchievementsDialog_XBox( this );
  3718. PositionDialog(m_hAchievementsDialog);
  3719. }
  3720. m_hAchievementsDialog->Activate();
  3721. #else
  3722. AssertMsg( false, "Fixme" );
  3723. #endif
  3724. }
  3725. //-----------------------------------------------------------------------------
  3726. // Purpose: moves the game menu button to the right place on the taskbar
  3727. //-----------------------------------------------------------------------------
  3728. void CBaseModPanel::PositionDialog(vgui::PHandle dlg)
  3729. {
  3730. if (!dlg.Get())
  3731. return;
  3732. int x, y, ww, wt, wide, tall;
  3733. vgui::surface()->GetWorkspaceBounds( x, y, ww, wt );
  3734. dlg->GetSize(wide, tall);
  3735. // Center it, keeping requested size
  3736. dlg->SetPos(x + ((ww - wide) / 2), y + ((wt - tall) / 2));
  3737. }
  3738. //-----------------------------------------------------------------------------
  3739. // Purpose: Add an Xbox 360 message dialog to a dialog stack
  3740. //-----------------------------------------------------------------------------
  3741. void CBaseModPanel::ShowMessageDialog( const uint nType, vgui::Panel *pOwner )
  3742. {
  3743. if ( pOwner == NULL )
  3744. {
  3745. pOwner = this;
  3746. }
  3747. m_MessageDialogHandler.ShowMessageDialog( nType, pOwner );
  3748. }
  3749. //-----------------------------------------------------------------------------
  3750. // Purpose: Add an Xbox 360 message dialog to a dialog stack
  3751. //-----------------------------------------------------------------------------
  3752. void CBaseModPanel::CloseMessageDialog( const uint nType )
  3753. {
  3754. m_MessageDialogHandler.CloseMessageDialog( nType );
  3755. }
  3756. //-----------------------------------------------------------------------------
  3757. // Purpose: System notification from engine
  3758. //-----------------------------------------------------------------------------
  3759. void CBaseModPanel::SystemNotification( const int notification )
  3760. {
  3761. if ( notification == SYSTEMNOTIFY_USER_SIGNEDIN )
  3762. {
  3763. // dgoodenough - limit this to X360
  3764. // PS3_BUILDFIX
  3765. // FIXME - do we want to have somehting here for PS3?
  3766. #if defined( _X360 )
  3767. // See if it was the active user who signed in
  3768. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  3769. uint state = XUserGetSigninState( XBX_GetActiveUserId() );
  3770. if ( state != eXUserSigninState_NotSignedIn )
  3771. {
  3772. // Reset a bunch of state
  3773. m_bUserRefusedSignIn = false;
  3774. m_bUserRefusedStorageDevice = false;
  3775. m_bStorageBladeShown = false;
  3776. }
  3777. UpdateRichPresenceInfo();
  3778. #pragma message( __FILE__ "(" __LINE__AS_STRING ") : warning custom: Best guess at a fix for the two lines below to get rotted code compiling" )
  3779. //engine->GetAchievementMgr()->DownloadUserData();
  3780. //engine->GetAchievementMgr()->EnsureGlobalStateLoaded();
  3781. engine->GetAchievementMgr()->InitializeAchievements();
  3782. #endif
  3783. }
  3784. else if ( notification == SYSTEMNOTIFY_USER_SIGNEDOUT )
  3785. {
  3786. // dgoodenough - limit this to X360
  3787. // PS3_BUILDFIX
  3788. // FIXME - do we want to have somehting here for PS3?
  3789. #if defined( _X360 )
  3790. UpdateRichPresenceInfo();
  3791. // See if it was the active user who signed out
  3792. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  3793. uint state = XUserGetSigninState( XBX_GetActiveUserId() );
  3794. if ( state != eXUserSigninState_NotSignedIn )
  3795. {
  3796. return;
  3797. }
  3798. // Invalidate their storage ID
  3799. #pragma message( __FILE__ "(" __LINE__AS_STRING ") : warning custom: Slamming controller for xbox storage id to 0" )
  3800. engine->OnStorageDeviceDetached( 0 );
  3801. m_bUserRefusedStorageDevice = false;
  3802. m_bUserRefusedSignIn = false;
  3803. m_iStorageID = XBX_INVALID_STORAGE_ID;
  3804. engine->GetAchievementMgr()->InitializeAchievements();
  3805. m_MessageDialogHandler.CloseAllMessageDialogs();
  3806. #endif
  3807. if ( GameUI().IsInLevel() )
  3808. {
  3809. if ( m_pGameLogo )
  3810. {
  3811. m_pGameLogo->SetVisible( false );
  3812. }
  3813. // Hide the standard game menu
  3814. for ( int i = 0; i < m_pGameMenuButtons.Count(); ++i )
  3815. {
  3816. m_pGameMenuButtons[i]->SetVisible( false );
  3817. }
  3818. // Hide the BasePanel's button footer
  3819. m_pGameMenu->ShowFooter( false );
  3820. QueueCommand( "QuitNoConfirm" );
  3821. }
  3822. else
  3823. {
  3824. CloseBaseDialogs();
  3825. }
  3826. OnCommand( "OpenMainMenu" );
  3827. }
  3828. else if ( notification == SYSTEMNOTIFY_STORAGEDEVICES_CHANGED )
  3829. {
  3830. if ( m_hSaveGameDialog_Xbox.Get() )
  3831. m_hSaveGameDialog_Xbox->OnCommand( "RefreshSaveGames" );
  3832. if ( m_hLoadGameDialog_Xbox.Get() )
  3833. m_hLoadGameDialog_Xbox->OnCommand( "RefreshSaveGames" );
  3834. // FIXME: This code is incorrect, they do NOT need a storage device, it is only recommended that they do
  3835. if ( GameUI().IsInLevel() )
  3836. {
  3837. // They wanted to use a storage device and are already playing!
  3838. // They need a storage device now or we're quitting the game!
  3839. m_bNeedStorageDeviceHandle = true;
  3840. ShowMessageDialog( MD_STORAGE_DEVICES_NEEDED, this );
  3841. }
  3842. else
  3843. {
  3844. ShowMessageDialog( MD_STORAGE_DEVICES_CHANGED, this );
  3845. }
  3846. }
  3847. else if ( notification == SYSTEMNOTIFY_XUIOPENING )
  3848. {
  3849. m_bXUIVisible = true;
  3850. }
  3851. else if ( notification == SYSTEMNOTIFY_XUICLOSED )
  3852. {
  3853. m_bXUIVisible = false;
  3854. if ( m_bWaitingForStorageDeviceHandle )
  3855. {
  3856. DWORD ret = xboxsystem->GetOverlappedResult( m_hStorageDeviceChangeHandle, NULL, true );
  3857. if ( ret != ERROR_IO_INCOMPLETE )
  3858. {
  3859. // Done waiting
  3860. xboxsystem->ReleaseAsyncHandle( m_hStorageDeviceChangeHandle );
  3861. m_bWaitingForStorageDeviceHandle = false;
  3862. // If we selected something, validate it
  3863. if ( m_iStorageID != XBX_INVALID_STORAGE_ID )
  3864. {
  3865. // Check to see if there is enough room on this storage device
  3866. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  3867. if ( xboxsystem->DeviceCapacityAdequate( XBX_GetActiveUserId(), m_iStorageID, COM_GetModDirectory() ) == false )
  3868. {
  3869. ShowMessageDialog( MD_STORAGE_DEVICES_TOO_FULL, this );
  3870. m_bStorageBladeShown = false; // Show the blade again next time
  3871. m_strPostPromptCommand = ""; // Clear the buffer, we can't return
  3872. }
  3873. else
  3874. {
  3875. m_bNeedStorageDeviceHandle = false;
  3876. // Set the storage device
  3877. XBX_SetStorageDeviceId( XBX_GetActiveUserId(), m_iStorageID );
  3878. OnDeviceAttached();
  3879. }
  3880. }
  3881. else
  3882. {
  3883. if ( m_pStorageDeviceValidatedNotify )
  3884. {
  3885. *m_pStorageDeviceValidatedNotify = 2;
  3886. m_pStorageDeviceValidatedNotify = NULL;
  3887. }
  3888. else if ( m_bNeedStorageDeviceHandle )
  3889. {
  3890. // They didn't select a storage device!
  3891. // Remind them that they must pick one or the game will shut down
  3892. ShowMessageDialog( MD_STORAGE_DEVICES_NEEDED, this );
  3893. }
  3894. else
  3895. {
  3896. // Start off the command we queued up
  3897. IssuePostPromptCommand();
  3898. }
  3899. }
  3900. }
  3901. }
  3902. // If we're waiting for the user to sign in, and check if they selected a usable profile
  3903. if ( m_bWaitingForUserSignIn )
  3904. {
  3905. // Done waiting
  3906. m_bWaitingForUserSignIn = false;
  3907. m_bUserRefusedSignIn = false;
  3908. // The UI has closed, so go off and revalidate the state
  3909. if ( m_strPostPromptCommand.IsEmpty() == false )
  3910. {
  3911. // Run the command again
  3912. OnCommand( m_strPostPromptCommand );
  3913. }
  3914. }
  3915. RunQueuedCommands();
  3916. }
  3917. else if ( notification == SYSTEMNOTIFY_INVITE_SHUTDOWN )
  3918. {
  3919. // Quit the current game without confirmation
  3920. m_bRestartFromInvite = true;
  3921. m_bXUIVisible = true;
  3922. OnCommand( "QuitNoConfirm" );
  3923. }
  3924. }
  3925. //-----------------------------------------------------------------------------
  3926. // Purpose:
  3927. //-----------------------------------------------------------------------------
  3928. void CBaseModPanel::OnChangeStorageDevice( void )
  3929. {
  3930. if ( m_bWaitingForStorageDeviceHandle == false )
  3931. {
  3932. m_bWaitingForStorageDeviceHandle = true;
  3933. m_hStorageDeviceChangeHandle = xboxsystem->CreateAsyncHandle();
  3934. m_iStorageID = XBX_INVALID_STORAGE_ID;
  3935. ACTIVE_SPLITSCREEN_PLAYER_GUARD( GET_ACTIVE_SPLITSCREEN_SLOT() );
  3936. xboxsystem->ShowDeviceSelector( XBX_GetActiveUserId(), true, &m_iStorageID, &m_hStorageDeviceChangeHandle );
  3937. }
  3938. }
  3939. void CBaseModPanel::OnCreditsFinished( void )
  3940. {
  3941. if ( !IsGameConsole() )
  3942. {
  3943. // valid for 360 only
  3944. Assert( 0 );
  3945. return;
  3946. }
  3947. bool bExitToAppChooser = false;
  3948. if ( bExitToAppChooser )
  3949. {
  3950. // unknown state from engine, force to a compliant exiting state
  3951. // causes an complete exit out of the game back to the app launcher
  3952. SetVisible( true );
  3953. m_pGameMenu->SetAlpha( 0 );
  3954. StartExitingProcess();
  3955. }
  3956. else
  3957. {
  3958. // expecting to transition from the credits back to the background map
  3959. // prevent any possibility of using the last transition image
  3960. m_bUseRenderTargetImage = false;
  3961. }
  3962. }
  3963. //-----------------------------------------------------------------------------
  3964. // Purpose:
  3965. //-----------------------------------------------------------------------------
  3966. void CBaseModPanel::OnGameUIHidden()
  3967. {
  3968. // [jason] Dismiss Pause menu if we close it via ESC key, etc
  3969. if ( IsScaleformPauseMenuEnabled() && IsScaleformPauseMenuActive() )
  3970. {
  3971. DismissPauseMenu();
  3972. }
  3973. if ( m_hOptionsDialog.Get() )
  3974. {
  3975. PostMessage( m_hOptionsDialog.Get(), new KeyValues( "GameUIHidden" ) );
  3976. }
  3977. }
  3978. //-----------------------------------------------------------------------------
  3979. // Purpose: Sets the alpha of the menu panels
  3980. //-----------------------------------------------------------------------------
  3981. void CBaseModPanel::SetMenuAlpha(int alpha)
  3982. {
  3983. if ( GameUI().IsConsoleUI() )
  3984. {
  3985. // handled by animation, not code
  3986. return;
  3987. }
  3988. m_pGameMenu->SetAlpha(alpha);
  3989. if ( m_pGameLogo )
  3990. {
  3991. m_pGameLogo->SetAlpha( alpha );
  3992. }
  3993. for ( int i=0; i<m_pGameMenuButtons.Count(); ++i )
  3994. {
  3995. m_pGameMenuButtons[i]->SetAlpha(alpha);
  3996. }
  3997. m_bForceTitleTextUpdate = true;
  3998. }
  3999. //-----------------------------------------------------------------------------
  4000. // Purpose: starts the game
  4001. //-----------------------------------------------------------------------------
  4002. void CBaseModPanel::FadeToBlackAndRunEngineCommand( const char *engineCommand )
  4003. {
  4004. KeyValues *pKV = new KeyValues( "RunEngineCommand", "command", engineCommand );
  4005. // execute immediately, with no delay
  4006. PostMessage( this, pKV, 0 );
  4007. }
  4008. void CBaseModPanel::SetMenuItemBlinkingState( const char *itemName, bool state )
  4009. {
  4010. for (int i = 0; i < GetChildCount(); i++)
  4011. {
  4012. Panel *child = GetChild(i);
  4013. CGameMenu *pGameMenu = dynamic_cast<CGameMenu *>(child);
  4014. if ( pGameMenu )
  4015. {
  4016. pGameMenu->SetMenuItemBlinkingState( itemName, state );
  4017. }
  4018. }
  4019. }
  4020. //-----------------------------------------------------------------------------
  4021. // Purpose: runs an engine command, used for delays
  4022. //-----------------------------------------------------------------------------
  4023. void CBaseModPanel::RunEngineCommand(const char *command)
  4024. {
  4025. engine->ClientCmd_Unrestricted(command);
  4026. }
  4027. //-----------------------------------------------------------------------------
  4028. // Purpose: runs an animation to close a dialog and cleans up after close
  4029. //-----------------------------------------------------------------------------
  4030. void CBaseModPanel::RunCloseAnimation( const char *animName )
  4031. {
  4032. RunAnimationWithCallback( this, animName, new KeyValues( "FinishDialogClose" ) );
  4033. }
  4034. //-----------------------------------------------------------------------------
  4035. // Purpose: cleans up after a menu closes
  4036. //-----------------------------------------------------------------------------
  4037. void CBaseModPanel::FinishDialogClose( void )
  4038. {
  4039. }
  4040. //-----------------------------------------------------------------------------
  4041. // Purpose: Load the two version numbers (code and content) from file to
  4042. // display them on the main menu.
  4043. //-----------------------------------------------------------------------------
  4044. void CBaseModPanel::LoadVersionNumbers()
  4045. {
  4046. KeyValues *pVersionSettings = new KeyValues( "MainGameMenuScreen.res" );
  4047. if ( pVersionSettings->LoadFromFile( g_pFullFileSystem, "resource/MainGameMenuScreen.res" ) )
  4048. {
  4049. m_pCodeVersionLabel->ApplySettings( pVersionSettings->FindKey( "CodeVersionLabel" ) );
  4050. m_pContentVersionLabel->ApplySettings( pVersionSettings->FindKey( "ContentVersionLabel" ) );
  4051. }
  4052. const unsigned int bufferSize = 255;
  4053. const wchar_t *pInvalidVersionText = L"_ _ _ _ _ _";
  4054. // Load the code version number.
  4055. Assert( m_pCodeVersionLabel != NULL );
  4056. const char *codeVersionFileName = "resource\\css_code_version.txt";
  4057. const char *codeVersionFileNameOfficial = "resource\\css_code_version_local.txt";
  4058. wchar_t codeVersion[bufferSize];
  4059. codeVersion[0] = L'\0';
  4060. bool bSuccess = LoadVersionNumber( codeVersionFileName, codeVersionFileNameOfficial, codeVersion, bufferSize );
  4061. m_pCodeVersionLabel->SetText( bSuccess ? codeVersion : pInvalidVersionText );
  4062. // Load the content version number.
  4063. Assert( m_pContentVersionLabel != NULL );
  4064. const char *contentVersionFileName = "resource\\css_content_version.txt";
  4065. const char *contentVersionFileNameOfficial = "resource\\css_content_version_local.txt";
  4066. wchar_t contentVersion[bufferSize];
  4067. contentVersion[0] = L'\0';
  4068. bSuccess = LoadVersionNumber( contentVersionFileName, contentVersionFileNameOfficial, contentVersion, bufferSize );
  4069. m_pContentVersionLabel->SetText( bSuccess ? contentVersion : pInvalidVersionText );
  4070. }
  4071. //-----------------------------------------------------------------------------
  4072. // Purpose: Load a version number from the most recent of two files into the given buffer.
  4073. //-----------------------------------------------------------------------------
  4074. bool CBaseModPanel::LoadVersionNumber( const char *fileNameA, const char *fileNameB, wchar_t *pVersionBuffer, unsigned int versionBufferSizeBytes )
  4075. {
  4076. Assert( fileNameA != NULL );
  4077. Assert( fileNameB != NULL );
  4078. Assert( pVersionBuffer != NULL );
  4079. Assert( versionBufferSizeBytes > 0 );
  4080. const char *fileName = NULL;
  4081. long timeA = g_pFullFileSystem->GetFileTime( (char*)fileNameA );
  4082. long timeB = g_pFullFileSystem->GetFileTime( (char*)fileNameB );
  4083. if ( timeA == -1 || timeA <= timeB )
  4084. {
  4085. fileName = fileNameB;
  4086. }
  4087. else if ( timeB == -1 || timeB <= timeA )
  4088. {
  4089. fileName = fileNameA;
  4090. }
  4091. if ( !fileName )
  4092. {
  4093. Msg( "Error opening version files \"%s\" and \"%s\"\n", fileNameA, fileNameB );
  4094. return false;
  4095. }
  4096. FileHandle_t file = g_pFullFileSystem->Open( fileName, "rb" );
  4097. if ( !file )
  4098. {
  4099. Msg( "Error opening version file \"%s\"\n", fileName );
  4100. return false;
  4101. }
  4102. // Get the file and buffer sizes.
  4103. int fileSize = g_pFullFileSystem->Size( file );
  4104. int bufferSize = g_pFullFileSystem->GetOptimalReadSize( file, fileSize + sizeof(wchar_t) );
  4105. if ( fileSize == 0 ||
  4106. bufferSize == 0 )
  4107. {
  4108. Msg( "Invalid version file \"%s\"\n", fileName );
  4109. g_pFullFileSystem->Close( file );
  4110. return false;
  4111. }
  4112. // Read the file into the buffer.
  4113. wchar_t *memBlock = (wchar_t *)g_pFullFileSystem->AllocOptimalReadBuffer( file, bufferSize );
  4114. V_memset( memBlock, 0, bufferSize );
  4115. bool bReadOK = ( g_pFullFileSystem->ReadEx( memBlock, bufferSize, fileSize, file ) != 0 );
  4116. const unsigned int memBlockCount = bufferSize / sizeof(wchar_t);
  4117. // Close the file.
  4118. g_pFullFileSystem->Close( file );
  4119. if ( !bReadOK )
  4120. {
  4121. Msg( "Error reading version file \"%s\"\n", fileName );
  4122. g_pFullFileSystem->FreeOptimalReadBuffer( memBlock );
  4123. return false;
  4124. }
  4125. // Check the first character, make sure this a little-endian unicode file.
  4126. wchar_t *data = memBlock;
  4127. wchar_t signature = LittleShort( data[0] );
  4128. if ( !bReadOK || signature != 0xFEFF )
  4129. {
  4130. Msg( "Invalid non-unicode version file \"%s\"\n", fileName );
  4131. g_pFullFileSystem->FreeOptimalReadBuffer( memBlock );
  4132. return false;
  4133. }
  4134. // Ensure little-endian unicode reads correctly on all platforms.
  4135. CByteswap byteSwap;
  4136. byteSwap.SetTargetBigEndian( false );
  4137. byteSwap.SwapBufferToTargetEndian( data, data, memBlockCount );
  4138. // Remove unwanted characters from the beginning of the buffer.
  4139. wchar_t *pTextEnd = data + memBlockCount;
  4140. while ( data != pTextEnd )
  4141. {
  4142. if ( *data == L'\0' )
  4143. {
  4144. break;
  4145. }
  4146. else if ( iswalnum( *data ) != 0 ||
  4147. iswpunct( *data ) != 0 )
  4148. {
  4149. break;
  4150. }
  4151. ++data;
  4152. }
  4153. // Null terminate the version string.
  4154. wchar_t *pCur = data;
  4155. while ( pCur != pTextEnd )
  4156. {
  4157. if ( iswalnum( *pCur ) != 0 ||
  4158. iswpunct( *pCur ) != 0 ||
  4159. *pCur == L' ' )
  4160. {
  4161. ++pCur;
  4162. continue;
  4163. }
  4164. *pCur = L'\0';
  4165. break;
  4166. }
  4167. // Copy the contents of the file into the given text buffer.
  4168. V_wcsncpy( pVersionBuffer, data, versionBufferSizeBytes );
  4169. // Free the buffer.
  4170. g_pFullFileSystem->FreeOptimalReadBuffer( memBlock );
  4171. return true;
  4172. }
  4173. /*
  4174. //-----------------------------------------------------------------------------
  4175. // Purpose: xbox UI panel that displays button icons and help text for all menus
  4176. //-----------------------------------------------------------------------------
  4177. CFooterPanel::CFooterPanel( Panel *parent, const char *panelName ) : BaseClass( parent, panelName )
  4178. {
  4179. SetVisible( true );
  4180. SetAlpha( 0 );
  4181. m_pHelpName = NULL;
  4182. m_pSizingLabel = new vgui::Label( this, "SizingLabel", "" );
  4183. m_pSizingLabel->SetVisible( false );
  4184. m_nButtonGap = 32;
  4185. m_nButtonGapDefault = 32;
  4186. m_ButtonPinRight = 100;
  4187. m_FooterTall = 80;
  4188. int wide, tall;
  4189. surface()->GetScreenSize(wide, tall);
  4190. if ( tall <= 480 )
  4191. {
  4192. m_FooterTall = 60;
  4193. }
  4194. m_ButtonOffsetFromTop = 0;
  4195. m_ButtonSeparator = 4;
  4196. m_TextAdjust = 0;
  4197. m_bPaintBackground = false;
  4198. m_bCenterHorizontal = false;
  4199. m_szButtonFont[0] = '\0';
  4200. m_szTextFont[0] = '\0';
  4201. m_szFGColor[0] = '\0';
  4202. m_szBGColor[0] = '\0';
  4203. }
  4204. CFooterPanel::~CFooterPanel()
  4205. {
  4206. SetHelpNameAndReset( NULL );
  4207. delete m_pSizingLabel;
  4208. }
  4209. //-----------------------------------------------------------------------------
  4210. // Purpose: apply scheme settings
  4211. //-----------------------------------------------------------------------------
  4212. void CFooterPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  4213. {
  4214. BaseClass::ApplySchemeSettings( pScheme );
  4215. m_hButtonFont = pScheme->GetFont( ( m_szButtonFont[0] != '\0' ) ? m_szButtonFont : "GameUIButtons" );
  4216. m_hTextFont = pScheme->GetFont( ( m_szTextFont[0] != '\0' ) ? m_szTextFont : "MenuLarge" );
  4217. SetFgColor( pScheme->GetColor( m_szFGColor, Color( 255, 255, 255, 255 ) ) );
  4218. SetBgColor( pScheme->GetColor( m_szBGColor, Color( 0, 0, 0, 255 ) ) );
  4219. int x, y, w, h;
  4220. GetParent()->GetBounds( x, y, w, h );
  4221. SetBounds( x, h - m_FooterTall, w, m_FooterTall );
  4222. }
  4223. //-----------------------------------------------------------------------------
  4224. // Purpose: apply settings
  4225. //-----------------------------------------------------------------------------
  4226. void CFooterPanel::ApplySettings( KeyValues *inResourceData )
  4227. {
  4228. BaseClass::ApplySettings( inResourceData );
  4229. // gap between hints
  4230. m_nButtonGap = inResourceData->GetInt( "buttongap", 32 );
  4231. m_nButtonGapDefault = m_nButtonGap;
  4232. m_ButtonPinRight = inResourceData->GetInt( "button_pin_right", 100 );
  4233. m_FooterTall = inResourceData->GetInt( "tall", 80 );
  4234. m_ButtonOffsetFromTop = inResourceData->GetInt( "buttonoffsety", 0 );
  4235. m_ButtonSeparator = inResourceData->GetInt( "button_separator", 4 );
  4236. m_TextAdjust = inResourceData->GetInt( "textadjust", 0 );
  4237. m_bCenterHorizontal = ( inResourceData->GetInt( "center", 0 ) == 1 );
  4238. m_bPaintBackground = ( inResourceData->GetInt( "paintbackground", 0 ) == 1 );
  4239. // fonts for text and button
  4240. Q_strncpy( m_szTextFont, inResourceData->GetString( "fonttext", "MenuLarge" ), sizeof( m_szTextFont ) );
  4241. Q_strncpy( m_szButtonFont, inResourceData->GetString( "fontbutton", "GameUIButtons" ), sizeof( m_szButtonFont ) );
  4242. // fg and bg colors
  4243. Q_strncpy( m_szFGColor, inResourceData->GetString( "fgcolor", "White" ), sizeof( m_szFGColor ) );
  4244. Q_strncpy( m_szBGColor, inResourceData->GetString( "bgcolor", "Black" ), sizeof( m_szBGColor ) );
  4245. for ( KeyValues *pButton = inResourceData->GetFirstSubKey(); pButton != NULL; pButton = pButton->GetNextKey() )
  4246. {
  4247. const char *pName = pButton->GetName();
  4248. if ( !Q_stricmp( pName, "button" ) )
  4249. {
  4250. // Add a button to the footer
  4251. const char *pText = pButton->GetString( "text", "NULL" );
  4252. const char *pIcon = pButton->GetString( "icon", "NULL" );
  4253. AddNewButtonLabel( pText, pIcon );
  4254. }
  4255. }
  4256. InvalidateLayout( false, true ); // force ApplySchemeSettings to run
  4257. }
  4258. //-----------------------------------------------------------------------------
  4259. // Purpose: adds button icons and help text to the footer panel when activating a menu
  4260. //-----------------------------------------------------------------------------
  4261. void CFooterPanel::AddButtonsFromMap( vgui::Frame *pMenu )
  4262. {
  4263. SetHelpNameAndReset( pMenu->GetName() );
  4264. CControllerMap *pMap = dynamic_cast<CControllerMap*>( pMenu->FindChildByName( "ControllerMap" ) );
  4265. if ( pMap )
  4266. {
  4267. int buttonCt = pMap->NumButtons();
  4268. for ( int i = 0; i < buttonCt; ++i )
  4269. {
  4270. const char *pText = pMap->GetBindingText( i );
  4271. if ( pText )
  4272. {
  4273. AddNewButtonLabel( pText, pMap->GetBindingIcon( i ) );
  4274. }
  4275. }
  4276. }
  4277. }
  4278. void CFooterPanel::SetStandardDialogButtons()
  4279. {
  4280. SetHelpNameAndReset( "Dialog" );
  4281. AddNewButtonLabel( "#GameUI_Action", "#GameUI_Icons_A_BUTTON" );
  4282. AddNewButtonLabel( "#GameUI_Close", "#GameUI_Icons_B_BUTTON" );
  4283. }
  4284. //-----------------------------------------------------------------------------
  4285. // Purpose: Caller must tag the button layout. May support reserved names
  4286. // to provide stock help layouts trivially.
  4287. //-----------------------------------------------------------------------------
  4288. void CFooterPanel::SetHelpNameAndReset( const char *pName )
  4289. {
  4290. if ( m_pHelpName )
  4291. {
  4292. free( m_pHelpName );
  4293. m_pHelpName = NULL;
  4294. }
  4295. if ( pName )
  4296. {
  4297. m_pHelpName = strdup( pName );
  4298. }
  4299. ClearButtons();
  4300. }
  4301. //-----------------------------------------------------------------------------
  4302. // Purpose: Caller must tag the button layout
  4303. //-----------------------------------------------------------------------------
  4304. const char *CFooterPanel::GetHelpName()
  4305. {
  4306. return m_pHelpName;
  4307. }
  4308. void CFooterPanel::ClearButtons( void )
  4309. {
  4310. m_ButtonLabels.PurgeAndDeleteElements();
  4311. }
  4312. //-----------------------------------------------------------------------------
  4313. // Purpose: creates a new button label with icon and text
  4314. //-----------------------------------------------------------------------------
  4315. void CFooterPanel::AddNewButtonLabel( const char *text, const char *icon )
  4316. {
  4317. ButtonLabel_t *button = new ButtonLabel_t;
  4318. Q_strncpy( button->name, text, MAX_PATH );
  4319. button->bVisible = true;
  4320. // Button icons are a single character
  4321. wchar_t *pIcon = g_pVGuiLocalize->Find( icon );
  4322. if ( pIcon )
  4323. {
  4324. button->icon[0] = pIcon[0];
  4325. button->icon[1] = '\0';
  4326. }
  4327. else
  4328. {
  4329. button->icon[0] = '\0';
  4330. }
  4331. // Set the help text
  4332. wchar_t *pText = g_pVGuiLocalize->Find( text );
  4333. if ( pText )
  4334. {
  4335. wcsncpy( button->text, pText, wcslen( pText ) + 1 );
  4336. }
  4337. else
  4338. {
  4339. button->text[0] = '\0';
  4340. }
  4341. m_ButtonLabels.AddToTail( button );
  4342. }
  4343. //-----------------------------------------------------------------------------
  4344. // Purpose: Shows/Hides a button label
  4345. //-----------------------------------------------------------------------------
  4346. void CFooterPanel::ShowButtonLabel( const char *name, bool show )
  4347. {
  4348. for ( int i = 0; i < m_ButtonLabels.Count(); ++i )
  4349. {
  4350. if ( !Q_stricmp( m_ButtonLabels[ i ]->name, name ) )
  4351. {
  4352. m_ButtonLabels[ i ]->bVisible = show;
  4353. break;
  4354. }
  4355. }
  4356. }
  4357. //-----------------------------------------------------------------------------
  4358. // Purpose: Changes a button's text
  4359. //-----------------------------------------------------------------------------
  4360. void CFooterPanel::SetButtonText( const char *buttonName, const char *text )
  4361. {
  4362. for ( int i = 0; i < m_ButtonLabels.Count(); ++i )
  4363. {
  4364. if ( !Q_stricmp( m_ButtonLabels[ i ]->name, buttonName ) )
  4365. {
  4366. wchar_t *wtext = g_pVGuiLocalize->Find( text );
  4367. if ( text )
  4368. {
  4369. wcsncpy( m_ButtonLabels[ i ]->text, wtext, wcslen( wtext ) + 1 );
  4370. }
  4371. else
  4372. {
  4373. m_ButtonLabels[ i ]->text[ 0 ] = '\0';
  4374. }
  4375. break;
  4376. }
  4377. }
  4378. }
  4379. //-----------------------------------------------------------------------------
  4380. // Purpose: Footer panel background rendering
  4381. //-----------------------------------------------------------------------------
  4382. void CFooterPanel::PaintBackground( void )
  4383. {
  4384. if ( !m_bPaintBackground )
  4385. return;
  4386. BaseClass::PaintBackground();
  4387. }
  4388. //-----------------------------------------------------------------------------
  4389. // Purpose: Footer panel rendering
  4390. //-----------------------------------------------------------------------------
  4391. void CFooterPanel::Paint( void )
  4392. {
  4393. // inset from right edge
  4394. int wide = GetWide();
  4395. int right = wide - m_ButtonPinRight;
  4396. // center the text within the button
  4397. int buttonHeight = vgui::surface()->GetFontTall( m_hButtonFont );
  4398. int fontHeight = vgui::surface()->GetFontTall( m_hTextFont );
  4399. int textY = ( buttonHeight - fontHeight )/2 + m_TextAdjust;
  4400. if ( textY < 0 )
  4401. {
  4402. textY = 0;
  4403. }
  4404. int y = m_ButtonOffsetFromTop;
  4405. if ( !m_bCenterHorizontal )
  4406. {
  4407. // draw the buttons, right to left
  4408. int x = right;
  4409. for ( int i = 0; i < m_ButtonLabels.Count(); ++i )
  4410. {
  4411. ButtonLabel_t *pButton = m_ButtonLabels[i];
  4412. if ( !pButton->bVisible )
  4413. continue;
  4414. // Get the string length
  4415. m_pSizingLabel->SetFont( m_hTextFont );
  4416. m_pSizingLabel->SetText( pButton->text );
  4417. m_pSizingLabel->SizeToContents();
  4418. int iTextWidth = m_pSizingLabel->GetWide();
  4419. if ( iTextWidth == 0 )
  4420. x += m_nButtonGap; // There's no text, so remove the gap between buttons
  4421. else
  4422. x -= iTextWidth;
  4423. // Draw the string
  4424. vgui::surface()->DrawSetTextFont( m_hTextFont );
  4425. vgui::surface()->DrawSetTextColor( GetFgColor() );
  4426. vgui::surface()->DrawSetTextPos( x, y + textY );
  4427. vgui::surface()->DrawPrintText( pButton->text, wcslen( pButton->text ) );
  4428. // Draw the button
  4429. // back up button width and a little extra to leave a gap between button and text
  4430. x -= ( vgui::surface()->GetCharacterWidth( m_hButtonFont, pButton->icon[0] ) + m_ButtonSeparator );
  4431. vgui::surface()->DrawSetTextFont( m_hButtonFont );
  4432. vgui::surface()->DrawSetTextColor( 255, 255, 255, 255 );
  4433. vgui::surface()->DrawSetTextPos( x, y );
  4434. vgui::surface()->DrawPrintText( pButton->icon, 1 );
  4435. // back up to next string
  4436. x -= m_nButtonGap;
  4437. }
  4438. }
  4439. else
  4440. {
  4441. // center the buttons (as a group)
  4442. int x = wide / 2;
  4443. int totalWidth = 0;
  4444. int i = 0;
  4445. int nButtonCount = 0;
  4446. // need to loop through and figure out how wide our buttons and text are (with gaps between) so we can offset from the center
  4447. for ( i = 0; i < m_ButtonLabels.Count(); ++i )
  4448. {
  4449. ButtonLabel_t *pButton = m_ButtonLabels[i];
  4450. if ( !pButton->bVisible )
  4451. continue;
  4452. // Get the string length
  4453. m_pSizingLabel->SetFont( m_hTextFont );
  4454. m_pSizingLabel->SetText( pButton->text );
  4455. m_pSizingLabel->SizeToContents();
  4456. totalWidth += vgui::surface()->GetCharacterWidth( m_hButtonFont, pButton->icon[0] );
  4457. totalWidth += m_ButtonSeparator;
  4458. totalWidth += m_pSizingLabel->GetWide();
  4459. nButtonCount++; // keep track of how many active buttons we'll be drawing
  4460. }
  4461. totalWidth += ( nButtonCount - 1 ) * m_nButtonGap; // add in the gaps between the buttons
  4462. x -= ( totalWidth / 2 );
  4463. for ( i = 0; i < m_ButtonLabels.Count(); ++i )
  4464. {
  4465. ButtonLabel_t *pButton = m_ButtonLabels[i];
  4466. if ( !pButton->bVisible )
  4467. continue;
  4468. // Get the string length
  4469. m_pSizingLabel->SetFont( m_hTextFont );
  4470. m_pSizingLabel->SetText( pButton->text );
  4471. m_pSizingLabel->SizeToContents();
  4472. int iTextWidth = m_pSizingLabel->GetWide();
  4473. // Draw the icon
  4474. vgui::surface()->DrawSetTextFont( m_hButtonFont );
  4475. vgui::surface()->DrawSetTextColor( 255, 255, 255, 255 );
  4476. vgui::surface()->DrawSetTextPos( x, y );
  4477. vgui::surface()->DrawPrintText( pButton->icon, 1 );
  4478. x += vgui::surface()->GetCharacterWidth( m_hButtonFont, pButton->icon[0] ) + m_ButtonSeparator;
  4479. // Draw the string
  4480. vgui::surface()->DrawSetTextFont( m_hTextFont );
  4481. vgui::surface()->DrawSetTextColor( GetFgColor() );
  4482. vgui::surface()->DrawSetTextPos( x, y + textY );
  4483. vgui::surface()->DrawPrintText( pButton->text, wcslen( pButton->text ) );
  4484. x += iTextWidth + m_nButtonGap;
  4485. }
  4486. }
  4487. }
  4488. DECLARE_BUILD_FACTORY( CFooterPanel );
  4489. */
  4490. #ifdef _GAMECONSOLE
  4491. //-----------------------------------------------------------------------------
  4492. // Purpose: Reload the resource files on the Xbox 360
  4493. //-----------------------------------------------------------------------------
  4494. void CBaseModPanel::Reload_Resources( const CCommand &args )
  4495. {
  4496. m_pConsoleControlSettings->Clear();
  4497. m_pConsoleControlSettings->LoadFromFile( g_pFullFileSystem, "resource/UI/XboxDialogs.res" );
  4498. }
  4499. #endif
  4500. // X360TBD: Move into a separate module when completed
  4501. CMessageDialogHandler::CMessageDialogHandler()
  4502. {
  4503. m_iDialogStackTop = -1;
  4504. }
  4505. void CMessageDialogHandler::ShowMessageDialog( int nType, vgui::Panel *pOwner )
  4506. {
  4507. int iSimpleFrame = 0;
  4508. if ( ModInfo().IsSinglePlayerOnly() )
  4509. {
  4510. iSimpleFrame = MD_SIMPLEFRAME;
  4511. }
  4512. switch( nType )
  4513. {
  4514. case MD_SEARCHING_FOR_GAMES:
  4515. CreateMessageDialog( MD_CANCEL|MD_RESTRICTPAINT,
  4516. NULL,
  4517. "#TF_Dlg_SearchingForGames",
  4518. NULL,
  4519. "CancelOperation",
  4520. pOwner,
  4521. true );
  4522. break;
  4523. case MD_CREATING_GAME:
  4524. CreateMessageDialog( MD_RESTRICTPAINT,
  4525. NULL,
  4526. "#TF_Dlg_CreatingGame",
  4527. NULL,
  4528. NULL,
  4529. pOwner,
  4530. true );
  4531. break;
  4532. case MD_SESSION_SEARCH_FAILED:
  4533. CreateMessageDialog( MD_YESNO|MD_RESTRICTPAINT,
  4534. NULL,
  4535. "#TF_Dlg_NoGamesFound",
  4536. "ShowSessionOptionsDialog",
  4537. "ReturnToMainMenu",
  4538. pOwner );
  4539. break;
  4540. case MD_SESSION_CREATE_FAILED:
  4541. CreateMessageDialog( MD_OK,
  4542. NULL,
  4543. "#TF_Dlg_CreateFailed",
  4544. "ReturnToMainMenu",
  4545. NULL,
  4546. pOwner );
  4547. break;
  4548. case MD_SESSION_CONNECTING:
  4549. CreateMessageDialog( 0,
  4550. NULL,
  4551. "#TF_Dlg_Connecting",
  4552. NULL,
  4553. NULL,
  4554. pOwner,
  4555. true );
  4556. break;
  4557. case MD_SESSION_CONNECT_NOTAVAILABLE:
  4558. CreateMessageDialog( MD_OK,
  4559. NULL,
  4560. "#TF_Dlg_JoinRefused",
  4561. "ReturnToMainMenu",
  4562. NULL,
  4563. pOwner );
  4564. break;
  4565. case MD_SESSION_CONNECT_SESSIONFULL:
  4566. CreateMessageDialog( MD_OK,
  4567. NULL,
  4568. "#TF_Dlg_GameFull",
  4569. "ReturnToMainMenu",
  4570. NULL,
  4571. pOwner );
  4572. break;
  4573. case MD_SESSION_CONNECT_FAILED:
  4574. CreateMessageDialog( MD_OK,
  4575. NULL,
  4576. "#TF_Dlg_JoinFailed",
  4577. "ReturnToMainMenu",
  4578. NULL,
  4579. pOwner );
  4580. break;
  4581. case MD_LOST_HOST:
  4582. CreateMessageDialog( MD_OK|MD_RESTRICTPAINT,
  4583. NULL,
  4584. "#TF_Dlg_LostHost",
  4585. "ReturnToMainMenu",
  4586. NULL,
  4587. pOwner );
  4588. break;
  4589. case MD_LOST_SERVER:
  4590. CreateMessageDialog( MD_OK|MD_RESTRICTPAINT,
  4591. NULL,
  4592. "#TF_Dlg_LostServer",
  4593. "ReturnToMainMenu",
  4594. NULL,
  4595. pOwner );
  4596. break;
  4597. case MD_MODIFYING_SESSION:
  4598. CreateMessageDialog( MD_RESTRICTPAINT,
  4599. NULL,
  4600. "#TF_Dlg_ModifyingSession",
  4601. NULL,
  4602. NULL,
  4603. pOwner,
  4604. true );
  4605. break;
  4606. case MD_SAVE_BEFORE_QUIT:
  4607. CreateMessageDialog( MD_YESNO|iSimpleFrame|MD_RESTRICTPAINT,
  4608. "#GameUI_QuitConfirmationTitle",
  4609. "#GameUI_Console_QuitWarning",
  4610. "QuitNoConfirm",
  4611. "CloseQuitDialog_OpenMainMenu",
  4612. pOwner );
  4613. break;
  4614. case MD_QUIT_CONFIRMATION:
  4615. CreateMessageDialog( MD_YESNO|iSimpleFrame|MD_RESTRICTPAINT,
  4616. "#GameUI_QuitConfirmationTitle",
  4617. "#GameUI_QuitConfirmationText",
  4618. "QuitNoConfirm",
  4619. "CloseQuitDialog_OpenMainMenu",
  4620. pOwner );
  4621. break;
  4622. case MD_QUIT_CONFIRMATION_TF:
  4623. CreateMessageDialog( MD_YESNO|MD_RESTRICTPAINT,
  4624. "#GameUI_QuitConfirmationTitle",
  4625. "#GameUI_QuitConfirmationText",
  4626. "QuitNoConfirm",
  4627. "CloseQuitDialog_OpenMatchmakingMenu",
  4628. pOwner );
  4629. break;
  4630. case MD_DISCONNECT_CONFIRMATION:
  4631. CreateMessageDialog( MD_YESNO|MD_RESTRICTPAINT,
  4632. "",
  4633. "#GameUI_DisconnectConfirmationText",
  4634. "DisconnectNoConfirm",
  4635. "close_dialog",
  4636. pOwner );
  4637. break;
  4638. case MD_DISCONNECT_CONFIRMATION_HOST:
  4639. CreateMessageDialog( MD_YESNO|MD_RESTRICTPAINT,
  4640. "",
  4641. "#GameUI_DisconnectHostConfirmationText",
  4642. "DisconnectNoConfirm",
  4643. "close_dialog",
  4644. pOwner );
  4645. break;
  4646. case MD_KICK_CONFIRMATION:
  4647. CreateMessageDialog( MD_YESNO,
  4648. "",
  4649. "#TF_Dlg_ConfirmKick",
  4650. "KickPlayer",
  4651. "close_dialog",
  4652. pOwner );
  4653. break;
  4654. case MD_CLIENT_KICKED:
  4655. CreateMessageDialog( MD_OK|MD_RESTRICTPAINT,
  4656. "",
  4657. "#TF_Dlg_ClientKicked",
  4658. "close_dialog",
  4659. NULL,
  4660. pOwner );
  4661. break;
  4662. case MD_EXIT_SESSION_CONFIRMATION:
  4663. CreateMessageDialog( MD_YESNO,
  4664. "",
  4665. "#TF_Dlg_ExitSessionText",
  4666. "ReturnToMainMenu",
  4667. "close_dialog",
  4668. pOwner );
  4669. break;
  4670. case MD_STORAGE_DEVICES_NEEDED:
  4671. CreateMessageDialog( MD_YESNO|MD_WARNING|MD_COMMANDAFTERCLOSE|iSimpleFrame|MD_RESTRICTPAINT,
  4672. "#GameUI_Console_StorageRemovedTitle",
  4673. "#GameUI_Console_StorageNeededBody",
  4674. "ShowDeviceSelector",
  4675. "QuitNoConfirm",
  4676. pOwner );
  4677. break;
  4678. case MD_STORAGE_DEVICES_CHANGED:
  4679. CreateMessageDialog( MD_YESNO|MD_WARNING|MD_COMMANDAFTERCLOSE|iSimpleFrame|MD_RESTRICTPAINT,
  4680. "#GameUI_Console_StorageRemovedTitle",
  4681. "#GameUI_Console_StorageRemovedBody",
  4682. "ShowDeviceSelector",
  4683. "clear_storage_deviceID",
  4684. pOwner );
  4685. break;
  4686. case MD_STORAGE_DEVICES_TOO_FULL:
  4687. CreateMessageDialog( MD_YESNO|MD_WARNING|MD_COMMANDAFTERCLOSE|iSimpleFrame|MD_RESTRICTPAINT,
  4688. "#GameUI_Console_StorageTooFullTitle",
  4689. "#GameUI_Console_StorageTooFullBody",
  4690. "ShowDeviceSelector",
  4691. "StorageDeviceDenied",
  4692. pOwner );
  4693. break;
  4694. case MD_PROMPT_STORAGE_DEVICE:
  4695. CreateMessageDialog( MD_YESNO|MD_WARNING|MD_COMMANDAFTERCLOSE|iSimpleFrame|MD_RESTRICTPAINT,
  4696. "#GameUI_Console_NoStorageDeviceSelectedTitle",
  4697. "#GameUI_Console_NoStorageDeviceSelectedBody",
  4698. "ShowDeviceSelector",
  4699. "StorageDeviceDenied",
  4700. pOwner );
  4701. break;
  4702. case MD_PROMPT_STORAGE_DEVICE_REQUIRED:
  4703. CreateMessageDialog( MD_YESNO|MD_WARNING|MD_COMMANDAFTERCLOSE|MD_SIMPLEFRAME,
  4704. "#GameUI_Console_NoStorageDeviceSelectedTitle",
  4705. "#GameUI_Console_StorageDeviceRequiredBody",
  4706. "ShowDeviceSelector",
  4707. "RequiredStorageDenied",
  4708. pOwner );
  4709. break;
  4710. case MD_PROMPT_SIGNIN:
  4711. CreateMessageDialog( MD_YESNO|MD_WARNING|MD_COMMANDAFTERCLOSE|iSimpleFrame,
  4712. "#GameUI_Console_NoUserProfileSelectedTitle",
  4713. "#GameUI_Console_NoUserProfileSelectedBody",
  4714. "ShowSignInUI",
  4715. "SignInDenied",
  4716. pOwner );
  4717. break;
  4718. case MD_PROMPT_SIGNIN_REQUIRED:
  4719. CreateMessageDialog( MD_YESNO|MD_WARNING|MD_COMMANDAFTERCLOSE|iSimpleFrame,
  4720. "#GameUI_Console_NoUserProfileSelectedTitle",
  4721. "#GameUI_Console_UserProfileRequiredBody",
  4722. "ShowSignInUI",
  4723. "RequiredSignInDenied",
  4724. pOwner );
  4725. break;
  4726. case MD_NOT_ONLINE_ENABLED:
  4727. CreateMessageDialog( MD_YESNO|MD_WARNING,
  4728. "",
  4729. "#TF_Dlg_NotOnlineEnabled",
  4730. "ShowSigninUI",
  4731. "close_dialog",
  4732. pOwner );
  4733. break;
  4734. case MD_NOT_ONLINE_SIGNEDIN:
  4735. CreateMessageDialog( MD_YESNO|MD_WARNING,
  4736. "",
  4737. "#TF_Dlg_NotOnlineSignedIn",
  4738. "ShowSigninUI",
  4739. "close_dialog",
  4740. pOwner );
  4741. break;
  4742. case MD_DEFAULT_CONTROLS_CONFIRM:
  4743. CreateMessageDialog( MD_YESNO|MD_WARNING|iSimpleFrame|MD_RESTRICTPAINT,
  4744. "#GameUI_RestoreDefaults",
  4745. "#GameUI_ControllerSettingsText",
  4746. "DefaultControls",
  4747. "close_dialog",
  4748. pOwner );
  4749. break;
  4750. case MD_AUTOSAVE_EXPLANATION:
  4751. CreateMessageDialog( MD_OK|MD_WARNING|iSimpleFrame|MD_RESTRICTPAINT,
  4752. "#GameUI_ConfirmNewGame_Title",
  4753. "#GameUI_AutoSave_Console_Explanation",
  4754. "StartNewGameNoCommentaryExplanation",
  4755. NULL,
  4756. pOwner );
  4757. break;
  4758. case MD_COMMENTARY_EXPLANATION:
  4759. CreateMessageDialog( MD_OK|MD_WARNING|iSimpleFrame|MD_RESTRICTPAINT,
  4760. "#GameUI_CommentaryDialogTitle",
  4761. "#GAMEUI_Commentary_Console_Explanation",
  4762. "StartNewGameNoCommentaryExplanation",
  4763. NULL,
  4764. pOwner );
  4765. break;
  4766. case MD_COMMENTARY_EXPLANATION_MULTI:
  4767. CreateMessageDialog( MD_OK|MD_WARNING,
  4768. "#GameUI_CommentaryDialogTitle",
  4769. "#GAMEUI_Commentary_Console_Explanation",
  4770. "StartNewGameNoCommentaryExplanation",
  4771. NULL,
  4772. pOwner );
  4773. break;
  4774. case MD_COMMENTARY_CHAPTER_UNLOCK_EXPLANATION:
  4775. CreateMessageDialog( MD_OK|MD_WARNING|iSimpleFrame|MD_RESTRICTPAINT,
  4776. "#GameUI_CommentaryDialogTitle",
  4777. "#GameUI_CommentaryUnlock",
  4778. "close_dialog",
  4779. NULL,
  4780. pOwner );
  4781. break;
  4782. case MD_SAVE_BEFORE_LANGUAGE_CHANGE:
  4783. CreateMessageDialog( MD_YESNO|MD_WARNING|MD_SIMPLEFRAME|MD_COMMANDAFTERCLOSE|MD_RESTRICTPAINT,
  4784. "#GameUI_ChangeLanguageRestart_Title",
  4785. "#GameUI_ChangeLanguageRestart_Info",
  4786. "AcceptVocalsLanguageChange",
  4787. "CancelVocalsLanguageChange",
  4788. pOwner );
  4789. case MD_SAVE_BEFORE_NEW_GAME:
  4790. CreateMessageDialog( MD_OKCANCEL|MD_WARNING|iSimpleFrame|MD_COMMANDAFTERCLOSE|MD_RESTRICTPAINT,
  4791. "#GameUI_ConfirmNewGame_Title",
  4792. "#GameUI_NewGameWarning",
  4793. "StartNewGame",
  4794. "close_dialog",
  4795. pOwner );
  4796. break;
  4797. case MD_SAVE_BEFORE_LOAD:
  4798. CreateMessageDialog( MD_OKCANCEL|MD_WARNING|iSimpleFrame|MD_COMMANDAFTERCLOSE|MD_RESTRICTPAINT,
  4799. "#GameUI_ConfirmLoadGame_Title",
  4800. "#GameUI_LoadWarning",
  4801. "LoadGame",
  4802. "LoadGameCancelled",
  4803. pOwner );
  4804. break;
  4805. case MD_DELETE_SAVE_CONFIRM:
  4806. CreateMessageDialog( MD_OKCANCEL|MD_WARNING|iSimpleFrame|MD_COMMANDAFTERCLOSE,
  4807. "#GameUI_ConfirmDeleteSaveGame_Title",
  4808. "#GameUI_ConfirmDeleteSaveGame_Info",
  4809. "DeleteGame",
  4810. "DeleteGameCancelled",
  4811. pOwner );
  4812. break;
  4813. case MD_SAVE_OVERWRITE:
  4814. CreateMessageDialog( MD_OKCANCEL|MD_WARNING|iSimpleFrame|MD_COMMANDAFTERCLOSE,
  4815. "#GameUI_ConfirmOverwriteSaveGame_Title",
  4816. "#GameUI_ConfirmOverwriteSaveGame_Info",
  4817. "SaveGame",
  4818. "OverwriteGameCancelled",
  4819. pOwner );
  4820. break;
  4821. case MD_SAVING_WARNING:
  4822. CreateMessageDialog( MD_WARNING|iSimpleFrame|MD_COMMANDONFORCECLOSE,
  4823. "",
  4824. "#GameUI_SavingWarning",
  4825. "SaveSuccess",
  4826. NULL,
  4827. pOwner,
  4828. true);
  4829. break;
  4830. case MD_SAVE_COMPLETE:
  4831. CreateMessageDialog( MD_OK|iSimpleFrame|MD_COMMANDAFTERCLOSE,
  4832. "#GameUI_ConfirmOverwriteSaveGame_Title",
  4833. "#GameUI_GameSaved",
  4834. "CloseAndSelectResume",
  4835. NULL,
  4836. pOwner );
  4837. break;
  4838. case MD_LOAD_FAILED_WARNING:
  4839. CreateMessageDialog( MD_OK |MD_WARNING|iSimpleFrame,
  4840. "#GameUI_LoadFailed",
  4841. "#GameUI_LoadFailed_Description",
  4842. "close_dialog",
  4843. NULL,
  4844. pOwner );
  4845. break;
  4846. case MD_OPTION_CHANGE_FROM_X360_DASHBOARD:
  4847. CreateMessageDialog( MD_OK|iSimpleFrame|MD_RESTRICTPAINT,
  4848. "#GameUI_SettingChangeFromX360Dashboard_Title",
  4849. "#GameUI_SettingChangeFromX360Dashboard_Info",
  4850. "close_dialog",
  4851. NULL,
  4852. pOwner );
  4853. break;
  4854. case MD_STANDARD_SAMPLE:
  4855. CreateMessageDialog( MD_OK,
  4856. "Standard Dialog",
  4857. "This is a standard dialog",
  4858. "close_dialog",
  4859. NULL,
  4860. pOwner );
  4861. break;
  4862. case MD_WARNING_SAMPLE:
  4863. CreateMessageDialog( MD_OK | MD_WARNING,
  4864. "#GameUI_Dialog_Warning",
  4865. "This is a warning dialog",
  4866. "close_dialog",
  4867. NULL,
  4868. pOwner );
  4869. break;
  4870. case MD_ERROR_SAMPLE:
  4871. CreateMessageDialog( MD_OK | MD_ERROR,
  4872. "Error Dialog",
  4873. "This is an error dialog",
  4874. "close_dialog",
  4875. NULL,
  4876. pOwner );
  4877. break;
  4878. case MD_STORAGE_DEVICES_CORRUPT:
  4879. CreateMessageDialog( MD_OK | MD_WARNING | iSimpleFrame | MD_RESTRICTPAINT,
  4880. "",
  4881. "#GameUI_Console_FileCorrupt",
  4882. "close_dialog",
  4883. NULL,
  4884. pOwner );
  4885. break;
  4886. case MD_CHECKING_STORAGE_DEVICE:
  4887. CreateMessageDialog( iSimpleFrame | MD_RESTRICTPAINT,
  4888. NULL,
  4889. "#GameUI_Dlg_CheckingStorageDevice",
  4890. NULL,
  4891. NULL,
  4892. pOwner,
  4893. true );
  4894. break;
  4895. default:
  4896. break;
  4897. }
  4898. }
  4899. void CMessageDialogHandler::CloseAllMessageDialogs()
  4900. {
  4901. for ( int i = 0; i < MAX_MESSAGE_DIALOGS; ++i )
  4902. {
  4903. CMessageDialog *pDlg = m_hMessageDialogs[i];
  4904. if ( pDlg )
  4905. {
  4906. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  4907. if ( vgui_message_dialog_modal.GetBool() )
  4908. {
  4909. vgui::input()->ReleaseAppModalSurface();
  4910. }
  4911. pDlg->Close();
  4912. m_hMessageDialogs[i] = NULL;
  4913. }
  4914. }
  4915. }
  4916. void CMessageDialogHandler::CloseMessageDialog( const uint nType )
  4917. {
  4918. int nStackIdx = 0;
  4919. if ( nType & MD_WARNING )
  4920. {
  4921. nStackIdx = DIALOG_STACK_IDX_WARNING;
  4922. }
  4923. else if ( nType & MD_ERROR )
  4924. {
  4925. nStackIdx = DIALOG_STACK_IDX_ERROR;
  4926. }
  4927. CMessageDialog *pDlg = m_hMessageDialogs[nStackIdx];
  4928. if ( pDlg )
  4929. {
  4930. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  4931. if ( vgui_message_dialog_modal.GetBool() )
  4932. {
  4933. vgui::input()->ReleaseAppModalSurface();
  4934. }
  4935. pDlg->Close();
  4936. m_hMessageDialogs[nStackIdx] = NULL;
  4937. }
  4938. }
  4939. void CMessageDialogHandler::CreateMessageDialog( const uint nType, const char *pTitle, const char *pMsg, const char *pCmdA, const char *pCmdB, vgui::Panel *pCreator, bool bShowActivity /*= false*/ )
  4940. {
  4941. int nStackIdx = 0;
  4942. if ( nType & MD_WARNING )
  4943. {
  4944. nStackIdx = DIALOG_STACK_IDX_WARNING;
  4945. }
  4946. else if ( nType & MD_ERROR )
  4947. {
  4948. nStackIdx = DIALOG_STACK_IDX_ERROR;
  4949. }
  4950. // Can only show one dialog of each type at a time
  4951. if ( m_hMessageDialogs[nStackIdx].Get() )
  4952. {
  4953. Warning( "Tried to create two dialogs of type %d\n", nStackIdx );
  4954. return;
  4955. }
  4956. // Show the new dialog
  4957. m_hMessageDialogs[nStackIdx] = new CMessageDialog( BasePanel(), nType, pTitle, pMsg, pCmdA, pCmdB, pCreator, bShowActivity );
  4958. m_hMessageDialogs[nStackIdx]->SetControlSettingsKeys( BasePanel()->GetConsoleControlSettings()->FindKey( "MessageDialog.res" ) );
  4959. if ( nType & MD_RESTRICTPAINT )
  4960. {
  4961. vgui::surface()->RestrictPaintToSinglePanel( m_hMessageDialogs[nStackIdx]->GetVPanel() );
  4962. }
  4963. ActivateMessageDialog( nStackIdx );
  4964. }
  4965. //-----------------------------------------------------------------------------
  4966. // Purpose: Activate a new message dialog
  4967. //-----------------------------------------------------------------------------
  4968. void CMessageDialogHandler::ActivateMessageDialog( int nStackIdx )
  4969. {
  4970. int x, y, wide, tall;
  4971. vgui::surface()->GetWorkspaceBounds( x, y, wide, tall );
  4972. PositionDialog( m_hMessageDialogs[nStackIdx], wide, tall );
  4973. uint nType = m_hMessageDialogs[nStackIdx]->GetType();
  4974. if ( nType & MD_WARNING )
  4975. {
  4976. m_hMessageDialogs[nStackIdx]->SetZPos( 75 );
  4977. }
  4978. else if ( nType & MD_ERROR )
  4979. {
  4980. m_hMessageDialogs[nStackIdx]->SetZPos( 100 );
  4981. }
  4982. // Make sure the topmost item on the stack still has focus
  4983. int idx = MAX_MESSAGE_DIALOGS - 1;
  4984. for ( idx; idx >= nStackIdx; --idx )
  4985. {
  4986. CMessageDialog *pDialog = m_hMessageDialogs[idx];
  4987. if ( pDialog )
  4988. {
  4989. pDialog->Activate();
  4990. if ( vgui_message_dialog_modal.GetBool() )
  4991. {
  4992. vgui::input()->SetAppModalSurface( pDialog->GetVPanel() );
  4993. }
  4994. m_iDialogStackTop = idx;
  4995. break;
  4996. }
  4997. }
  4998. }
  4999. void CMessageDialogHandler::PositionDialogs( int wide, int tall )
  5000. {
  5001. for ( int i = 0; i < MAX_MESSAGE_DIALOGS; ++i )
  5002. {
  5003. if ( m_hMessageDialogs[i].Get() )
  5004. {
  5005. PositionDialog( m_hMessageDialogs[i], wide, tall );
  5006. }
  5007. }
  5008. }
  5009. void CMessageDialogHandler::PositionDialog( vgui::PHandle dlg, int wide, int tall )
  5010. {
  5011. int w, t;
  5012. dlg->GetSize(w, t);
  5013. dlg->SetPos( (wide - w) / 2, (tall - t) / 2 );
  5014. }
  5015. //-----------------------------------------------------------------------------
  5016. // Purpose: Editable panel that can replace the GameMenuButtons in CBaseModPanel
  5017. //-----------------------------------------------------------------------------
  5018. CMainMenuGameLogo::CMainMenuGameLogo( vgui::Panel *parent, const char *name ) : vgui::EditablePanel( parent, name )
  5019. {
  5020. m_nOffsetX = 0;
  5021. m_nOffsetY = 0;
  5022. }
  5023. //-----------------------------------------------------------------------------
  5024. // Purpose:
  5025. //-----------------------------------------------------------------------------
  5026. void CMainMenuGameLogo::ApplySettings( KeyValues *inResourceData )
  5027. {
  5028. BaseClass::ApplySettings( inResourceData );
  5029. m_nOffsetX = inResourceData->GetInt( "offsetX", 0 );
  5030. m_nOffsetY = inResourceData->GetInt( "offsetY", 0 );
  5031. }
  5032. //-----------------------------------------------------------------------------
  5033. // Purpose:
  5034. //-----------------------------------------------------------------------------
  5035. void CMainMenuGameLogo::ApplySchemeSettings( vgui::IScheme *pScheme )
  5036. {
  5037. BaseClass::ApplySchemeSettings( pScheme );
  5038. LoadControlSettings( "Resource/GameLogo.res" );
  5039. }
  5040. //-----------------------------------------------------------------------------
  5041. // Purpose:
  5042. //-----------------------------------------------------------------------------
  5043. void CBaseModPanel::CloseBaseDialogs( void )
  5044. {
  5045. if ( m_hNewGameDialog.Get() )
  5046. m_hNewGameDialog->Close();
  5047. if ( m_hBonusMapsDialog.Get() )
  5048. m_hBonusMapsDialog->Close();
  5049. if ( m_hLoadGameDialog_Xbox.Get() )
  5050. m_hLoadGameDialog_Xbox->Close();
  5051. if ( m_hSaveGameDialog_Xbox.Get() )
  5052. m_hSaveGameDialog_Xbox->Close();
  5053. if ( m_hLoadCommentaryDialog.Get() )
  5054. m_hLoadCommentaryDialog->Close();
  5055. if ( m_hCreateMultiplayerGameDialog.Get() )
  5056. m_hCreateMultiplayerGameDialog->Close();
  5057. }
  5058. #if !defined( CSTRIKE15 )
  5059. //-----------------------------------------------------------------------------
  5060. // Purpose: Console command to show the main menu
  5061. //-----------------------------------------------------------------------------
  5062. CON_COMMAND( show_main_menu, "Show the main menu" )
  5063. {
  5064. BasePanel()->ShowMainMenu( true );
  5065. }
  5066. //-----------------------------------------------------------------------------
  5067. // Purpose: Console command to hide the main menu
  5068. //-----------------------------------------------------------------------------
  5069. CON_COMMAND( hide_main_menu, "Hide the main menu" )
  5070. {
  5071. BasePanel()->ShowMainMenu( false );
  5072. }
  5073. #endif // !defined( CSTRIKE15 )
  5074. //Removed because these were used as an exploit to get to old VGUI panels and configure video options. Not relevant for end users anyways.
  5075. // -----------------------------------------------------------------------------
  5076. // Purpose: Console command to show the main menu
  5077. // -----------------------------------------------------------------------------
  5078. // CON_COMMAND( show_sf_main_menu, "Show the Scaleform main menu" )
  5079. // {
  5080. // BasePanel()->EnableScaleformMainMenu( true );
  5081. // BasePanel()->ShowMainMenu( false );
  5082. // BasePanel()->OnOpenCreateMainMenuScreen();
  5083. // }
  5084. //
  5085. //
  5086. // -----------------------------------------------------------------------------
  5087. // Purpose: Console command to hide the main menu
  5088. // -----------------------------------------------------------------------------
  5089. // CON_COMMAND( hide_sf_main_menu, "Hide the Scaleform main menu" )
  5090. // {
  5091. // BasePanel()->EnableScaleformMainMenu( false );
  5092. // BasePanel()->DismissMainMenuScreen();
  5093. // BasePanel()->ShowMainMenu( true );
  5094. // }
  5095. //-----------------------------------------------------------------------------
  5096. // Purpose: Show or hide the main menu
  5097. //-----------------------------------------------------------------------------
  5098. void CBaseModPanel::ShowMainMenu( bool bShow )
  5099. {
  5100. if (m_bMainMenuShown == bShow)
  5101. return;
  5102. SetVisible( bShow );
  5103. SetMenuAlpha( bShow ? 255 : 0 );
  5104. if ( m_pGameLogo )
  5105. {
  5106. m_pGameLogo->SetVisible( bShow );
  5107. }
  5108. if ( m_pGameMenu )
  5109. {
  5110. m_pGameMenu->ShowFooter( bShow );
  5111. m_pGameMenu->SetEnabled( bShow );
  5112. m_pGameMenu->SetVisible( bShow );
  5113. for ( int i = 0; i < m_pGameMenu->GetItemCount(); ++i )
  5114. {
  5115. m_pGameMenu->GetMenuItem( i )->SetEnabled( bShow );
  5116. m_pGameMenu->GetMenuItem( i )->SetVisible( bShow );
  5117. }
  5118. }
  5119. // Hide the standard game menu
  5120. for ( int i = 0; i < m_pGameMenuButtons.Count(); ++i )
  5121. {
  5122. m_pGameMenuButtons[i]->SetEnabled( bShow );
  5123. m_pGameMenuButtons[i]->SetVisible( bShow );
  5124. }
  5125. if ( bShow )
  5126. {
  5127. if ( GameUI().IsConsoleUI() )
  5128. {
  5129. ArmFirstMenuItem();
  5130. m_pConsoleAnimationController->StartAnimationSequence( "InitializeUILayout" );
  5131. m_pConsoleAnimationController->StartAnimationSequence( "OpenMainMenu" );
  5132. m_bFadingInMenus = false;
  5133. }
  5134. }
  5135. m_bMainMenuShown = bShow;
  5136. }
  5137. bool CBaseModPanel::LoadingProgressWantsIsolatedRender( bool bContextValid )
  5138. {
  5139. return CLoadingScreenScaleform::LoadingProgressWantsIsolatedRender( bContextValid );
  5140. }