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.

1386 lines
42 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=======================================================================================//
  7. #include "OptionsSubVideo.h"
  8. #include "CvarSlider.h"
  9. #include "EngineInterface.h"
  10. #include "BasePanel.h"
  11. #include "igameuifuncs.h"
  12. #include "modes.h"
  13. #include "materialsystem/materialsystem_config.h"
  14. #include "filesystem.h"
  15. #include "GameUI_Interface.h"
  16. #include "vgui_controls/CheckButton.h"
  17. #include "vgui_controls/ComboBox.h"
  18. #include "vgui_controls/Frame.h"
  19. #include "vgui_controls/QueryBox.h"
  20. #include "CvarToggleCheckButton.h"
  21. #include "tier1/KeyValues.h"
  22. #include "vgui/IInput.h"
  23. #include "vgui/ILocalize.h"
  24. #include "vgui/ISystem.h"
  25. #include "tier0/ICommandLine.h"
  26. #include "tier1/convar.h"
  27. #include "ModInfo.h"
  28. #include "inetchannelinfo.h"
  29. // memdbgon must be the last include file in a .cpp file!!!
  30. #include "tier0/memdbgon.h"
  31. using namespace vgui;
  32. //-----------------------------------------------------------------------------
  33. // Purpose: aspect ratio mappings (for normal/widescreen combo)
  34. //-----------------------------------------------------------------------------
  35. struct RatioToAspectMode_t
  36. {
  37. int anamorphic;
  38. float aspectRatio;
  39. };
  40. RatioToAspectMode_t g_RatioToAspectModes[] =
  41. {
  42. { 0, 4.0f / 3.0f },
  43. { 1, 16.0f / 9.0f },
  44. { 2, 16.0f / 10.0f },
  45. { 2, 1.0f },
  46. };
  47. struct AAMode_t
  48. {
  49. int m_nNumSamples;
  50. int m_nQualityLevel;
  51. };
  52. //-----------------------------------------------------------------------------
  53. // Purpose: list of valid dx levels
  54. //-----------------------------------------------------------------------------
  55. int g_DirectXLevels[] =
  56. {
  57. 70,
  58. 80,
  59. 81,
  60. 90,
  61. 95,
  62. };
  63. //-----------------------------------------------------------------------------
  64. // Purpose: returns the string name of a given dxlevel
  65. //-----------------------------------------------------------------------------
  66. void GetNameForDXLevel( int dxlevel, char *name, int bufferSize)
  67. {
  68. if( dxlevel == 95 )
  69. {
  70. Q_snprintf( name, bufferSize, "DirectX v9.0+" );
  71. }
  72. else
  73. {
  74. Q_snprintf( name, bufferSize, "DirectX v%.1f", dxlevel / 10.0f );
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose: returns the aspect ratio mode number for the given resolution
  79. //-----------------------------------------------------------------------------
  80. int GetScreenAspectMode( int width, int height )
  81. {
  82. float aspectRatio = (float)width / (float)height;
  83. // just find the closest ratio
  84. float closestAspectRatioDist = 99999.0f;
  85. int closestAnamorphic = 0;
  86. for (int i = 0; i < ARRAYSIZE(g_RatioToAspectModes); i++)
  87. {
  88. float dist = fabs( g_RatioToAspectModes[i].aspectRatio - aspectRatio );
  89. if (dist < closestAspectRatioDist)
  90. {
  91. closestAspectRatioDist = dist;
  92. closestAnamorphic = g_RatioToAspectModes[i].anamorphic;
  93. }
  94. }
  95. return closestAnamorphic;
  96. }
  97. //-----------------------------------------------------------------------------
  98. // Purpose: returns the string name of the specified resolution mode
  99. //-----------------------------------------------------------------------------
  100. void GetResolutionName( vmode_t *mode, char *sz, int sizeofsz )
  101. {
  102. int desktopWidth, desktopHeight;
  103. gameuifuncs->GetDesktopResolution( desktopWidth, desktopHeight );
  104. Q_snprintf( sz, sizeofsz, "%i x %i%s", mode->width, mode->height, ( mode->width == desktopWidth ) && ( mode->height == desktopHeight ) ? " (native)" : "" );
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Purpose: Gamma-adjust dialog
  108. //-----------------------------------------------------------------------------
  109. class CGammaDialog : public vgui::Frame
  110. {
  111. DECLARE_CLASS_SIMPLE( CGammaDialog, vgui::Frame );
  112. public:
  113. CGammaDialog( vgui::VPANEL hParent ) : BaseClass( NULL, "OptionsSubVideoGammaDlg" )
  114. {
  115. // parent is ignored, since we want look like we're steal focus from the parent (we'll become modal below)
  116. SetTitle("#GameUI_AdjustGamma_Title", true);
  117. SetSize( 400, 260 );
  118. SetDeleteSelfOnClose( true );
  119. m_pGammaSlider = new CCvarSlider( this, "Gamma", "#GameUI_Gamma", 1.6f, 2.6f, "mat_monitorgamma" );
  120. m_pGammaLabel = new Label( this, "Gamma label", "#GameUI_Gamma" );
  121. m_pGammaEntry = new TextEntry( this, "GammaEntry" );
  122. Button *ok = new Button( this, "OKButton", "#vgui_ok" );
  123. ok->SetCommand( new KeyValues("OK") );
  124. LoadControlSettings( "resource/OptionsSubVideoGammaDlg.res" );
  125. MoveToCenterOfScreen();
  126. SetSizeable( false );
  127. m_pGammaSlider->SetTickCaptions( "#GameUI_Light", "#GameUI_Dark" );
  128. }
  129. MESSAGE_FUNC_PTR( OnGammaChanged, "SliderMoved", panel )
  130. {
  131. if (panel == m_pGammaSlider)
  132. {
  133. m_pGammaSlider->ApplyChanges();
  134. }
  135. }
  136. virtual void Activate()
  137. {
  138. BaseClass::Activate();
  139. m_flOriginalGamma = m_pGammaSlider->GetValue();
  140. UpdateGammaLabel();
  141. }
  142. MESSAGE_FUNC( OnOK, "OK" )
  143. {
  144. // make the gamma stick
  145. m_flOriginalGamma = m_pGammaSlider->GetValue();
  146. Close();
  147. }
  148. virtual void OnClose()
  149. {
  150. // reset to the original gamma
  151. m_pGammaSlider->SetValue( m_flOriginalGamma );
  152. m_pGammaSlider->ApplyChanges();
  153. BaseClass::OnClose();
  154. }
  155. void OnKeyCodeTyped(KeyCode code)
  156. {
  157. // force ourselves to be closed if the escape key it pressed
  158. if (code == KEY_ESCAPE)
  159. {
  160. Close();
  161. }
  162. else
  163. {
  164. BaseClass::OnKeyCodeTyped(code);
  165. }
  166. }
  167. MESSAGE_FUNC_PTR( OnControlModified, "ControlModified", panel )
  168. {
  169. // the HasBeenModified() check is so that if the value is outside of the range of the
  170. // slider, it won't use the slider to determine the display value but leave the
  171. // real value that we determined in the constructor
  172. if (panel == m_pGammaSlider && m_pGammaSlider->HasBeenModified())
  173. {
  174. UpdateGammaLabel();
  175. }
  176. }
  177. MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel )
  178. {
  179. if (panel == m_pGammaEntry)
  180. {
  181. char buf[64];
  182. m_pGammaEntry->GetText(buf, 64);
  183. float fValue = (float) atof(buf);
  184. if (fValue >= 1.0)
  185. {
  186. m_pGammaSlider->SetSliderValue(fValue);
  187. PostActionSignal(new KeyValues("ApplyButtonEnable"));
  188. }
  189. }
  190. }
  191. void UpdateGammaLabel()
  192. {
  193. char buf[64];
  194. Q_snprintf(buf, sizeof( buf ), " %.1f", m_pGammaSlider->GetSliderValue());
  195. m_pGammaEntry->SetText(buf);
  196. }
  197. private:
  198. CCvarSlider *m_pGammaSlider;
  199. vgui::Label *m_pGammaLabel;
  200. vgui::TextEntry *m_pGammaEntry;
  201. float m_flOriginalGamma;
  202. };
  203. //-----------------------------------------------------------------------------
  204. // Purpose: advanced keyboard settings dialog
  205. //-----------------------------------------------------------------------------
  206. class COptionsSubVideoAdvancedDlg : public vgui::Frame
  207. {
  208. DECLARE_CLASS_SIMPLE( COptionsSubVideoAdvancedDlg, vgui::Frame );
  209. public:
  210. COptionsSubVideoAdvancedDlg( vgui::Panel *parent ) : BaseClass( parent , "OptionsSubVideoAdvancedDlg" )
  211. {
  212. SetTitle("#GameUI_VideoAdvanced_Title", true);
  213. SetSize( 260, 400 );
  214. m_pDXLevel = new ComboBox(this, "dxlabel", 6, false );
  215. const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
  216. KeyValues *pKeyValues = new KeyValues( "config" );
  217. materials->GetRecommendedConfigurationInfo( 0, pKeyValues );
  218. m_pDXLevel->DeleteAllItems();
  219. for (int i = 0; i < ARRAYSIZE(g_DirectXLevels); i++)
  220. {
  221. // don't allow choice of lower dxlevels than the default,
  222. // unless we're already at that lower level or have it forced
  223. if (!CommandLine()->CheckParm("-dxlevel") &&
  224. g_DirectXLevels[i] != config.dxSupportLevel &&
  225. g_DirectXLevels[i] < pKeyValues->GetInt("ConVar.mat_dxlevel"))
  226. continue;
  227. KeyValues *pTempKV = new KeyValues("config");
  228. if (g_DirectXLevels[i] == pKeyValues->GetInt("ConVar.mat_dxlevel")
  229. || materials->GetRecommendedConfigurationInfo( g_DirectXLevels[i], pTempKV ))
  230. {
  231. // add the configuration in the combo
  232. char szDXLevelName[64];
  233. GetNameForDXLevel( g_DirectXLevels[i], szDXLevelName, sizeof(szDXLevelName) );
  234. m_pDXLevel->AddItem( szDXLevelName, new KeyValues("dxlevel", "dxlevel", g_DirectXLevels[i]) );
  235. }
  236. pTempKV->deleteThis();
  237. }
  238. pKeyValues->deleteThis();
  239. m_pModelDetail = new ComboBox( this, "ModelDetail", 6, false );
  240. m_pModelDetail->AddItem("#gameui_low", NULL);
  241. m_pModelDetail->AddItem("#gameui_medium", NULL);
  242. m_pModelDetail->AddItem("#gameui_high", NULL);
  243. m_pTextureDetail = new ComboBox( this, "TextureDetail", 6, false );
  244. m_pTextureDetail->AddItem("#gameui_low", NULL);
  245. m_pTextureDetail->AddItem("#gameui_medium", NULL);
  246. m_pTextureDetail->AddItem("#gameui_high", NULL);
  247. m_pTextureDetail->AddItem("#gameui_ultra", NULL);
  248. // Build list of MSAA and CSAA modes, based upon those which are supported by the device
  249. //
  250. // The modes that we've seen in the wild to date are as follows (in perf order, fastest to slowest)
  251. //
  252. // 2x 4x 6x 8x 16x 8x 16xQ
  253. // Texture/Shader Samples 1 1 1 1 1 1 1
  254. // Stored Color/Z Samples 2 4 6 4 4 8 8
  255. // Coverage Samples 2 4 6 8 16 8 16
  256. // MSAA or CSAA M M M C C M C
  257. //
  258. // The CSAA modes are nVidia only (added in the G80 generation of GPUs)
  259. //
  260. m_nNumAAModes = 0;
  261. m_pAntialiasingMode = new ComboBox( this, "AntialiasingMode", 10, false );
  262. m_pAntialiasingMode->AddItem("#GameUI_None", NULL);
  263. m_nAAModes[m_nNumAAModes].m_nNumSamples = 1;
  264. m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
  265. m_nNumAAModes++;
  266. if ( materials->SupportsMSAAMode(2) )
  267. {
  268. m_pAntialiasingMode->AddItem("#GameUI_2X", NULL);
  269. m_nAAModes[m_nNumAAModes].m_nNumSamples = 2;
  270. m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
  271. m_nNumAAModes++;
  272. }
  273. if ( materials->SupportsMSAAMode(4) )
  274. {
  275. m_pAntialiasingMode->AddItem("#GameUI_4X", NULL);
  276. m_nAAModes[m_nNumAAModes].m_nNumSamples = 4;
  277. m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
  278. m_nNumAAModes++;
  279. }
  280. if ( materials->SupportsMSAAMode(6) )
  281. {
  282. m_pAntialiasingMode->AddItem("#GameUI_6X", NULL);
  283. m_nAAModes[m_nNumAAModes].m_nNumSamples = 6;
  284. m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
  285. m_nNumAAModes++;
  286. }
  287. if ( materials->SupportsCSAAMode(4, 2) ) // nVidia CSAA "8x"
  288. {
  289. m_pAntialiasingMode->AddItem("#GameUI_8X_CSAA", NULL);
  290. m_nAAModes[m_nNumAAModes].m_nNumSamples = 4;
  291. m_nAAModes[m_nNumAAModes].m_nQualityLevel = 2;
  292. m_nNumAAModes++;
  293. }
  294. if ( materials->SupportsCSAAMode(4, 4) ) // nVidia CSAA "16x"
  295. {
  296. m_pAntialiasingMode->AddItem("#GameUI_16X_CSAA", NULL);
  297. m_nAAModes[m_nNumAAModes].m_nNumSamples = 4;
  298. m_nAAModes[m_nNumAAModes].m_nQualityLevel = 4;
  299. m_nNumAAModes++;
  300. }
  301. if ( materials->SupportsMSAAMode(8) )
  302. {
  303. m_pAntialiasingMode->AddItem("#GameUI_8X", NULL);
  304. m_nAAModes[m_nNumAAModes].m_nNumSamples = 8;
  305. m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
  306. m_nNumAAModes++;
  307. }
  308. if ( materials->SupportsCSAAMode(8, 2) ) // nVidia CSAA "16xQ"
  309. {
  310. m_pAntialiasingMode->AddItem("#GameUI_16XQ_CSAA", NULL);
  311. m_nAAModes[m_nNumAAModes].m_nNumSamples = 8;
  312. m_nAAModes[m_nNumAAModes].m_nQualityLevel = 2;
  313. m_nNumAAModes++;
  314. }
  315. m_pFilteringMode = new ComboBox( this, "FilteringMode", 6, false );
  316. m_pFilteringMode->AddItem("#GameUI_Bilinear", NULL);
  317. m_pFilteringMode->AddItem("#GameUI_Trilinear", NULL);
  318. m_pFilteringMode->AddItem("#GameUI_Anisotropic2X", NULL);
  319. m_pFilteringMode->AddItem("#GameUI_Anisotropic4X", NULL);
  320. m_pFilteringMode->AddItem("#GameUI_Anisotropic8X", NULL);
  321. m_pFilteringMode->AddItem("#GameUI_Anisotropic16X", NULL);
  322. m_pShadowDetail = new ComboBox( this, "ShadowDetail", 6, false );
  323. m_pShadowDetail->AddItem("#gameui_low", NULL);
  324. m_pShadowDetail->AddItem("#gameui_medium", NULL);
  325. if ( g_pMaterialSystemHardwareConfig->SupportsShadowDepthTextures() )
  326. {
  327. m_pShadowDetail->AddItem("#gameui_high", NULL);
  328. }
  329. ConVarRef mat_dxlevel( "mat_dxlevel" );
  330. m_pHDR = new ComboBox( this, "HDR", 6, false );
  331. m_pHDR->AddItem("#GameUI_hdr_level0", NULL);
  332. m_pHDR->AddItem("#GameUI_hdr_level1", NULL);
  333. if ( materials->SupportsHDRMode( HDR_TYPE_INTEGER ) )
  334. {
  335. m_pHDR->AddItem("#GameUI_hdr_level2", NULL);
  336. }
  337. #if 0
  338. if ( materials->SupportsHDRMode( HDR_TYPE_FLOAT ) )
  339. {
  340. m_pHDR->AddItem("#GameUI_hdr_level3", NULL);
  341. }
  342. #endif
  343. m_pHDR->SetEnabled( mat_dxlevel.GetInt() >= 80 );
  344. m_pWaterDetail = new ComboBox( this, "WaterDetail", 6, false );
  345. m_pWaterDetail->AddItem("#gameui_noreflections", NULL);
  346. m_pWaterDetail->AddItem("#gameui_reflectonlyworld", NULL);
  347. m_pWaterDetail->AddItem("#gameui_reflectall", NULL);
  348. m_pVSync = new ComboBox( this, "VSync", 2, false );
  349. m_pVSync->AddItem("#gameui_disabled", NULL);
  350. m_pVSync->AddItem("#gameui_enabled", NULL);
  351. m_pShaderDetail = new ComboBox( this, "ShaderDetail", 6, false );
  352. m_pShaderDetail->AddItem("#gameui_low", NULL);
  353. m_pShaderDetail->AddItem("#gameui_high", NULL);
  354. m_pColorCorrection = new ComboBox( this, "ColorCorrection", 2, false );
  355. m_pColorCorrection->AddItem("#gameui_disabled", NULL);
  356. m_pColorCorrection->AddItem("#gameui_enabled", NULL);
  357. m_pMotionBlur = new ComboBox( this, "MotionBlur", 2, false );
  358. m_pMotionBlur->AddItem("#gameui_disabled", NULL);
  359. m_pMotionBlur->AddItem("#gameui_enabled", NULL);
  360. LoadControlSettings( "resource/OptionsSubVideoAdvancedDlg.res" );
  361. MoveToCenterOfScreen();
  362. SetSizeable( false );
  363. m_pDXLevel->SetEnabled(false);
  364. m_pColorCorrection->SetEnabled( mat_dxlevel.GetInt() >= 90 );
  365. m_pMotionBlur->SetEnabled( mat_dxlevel.GetInt() >= 90 );
  366. if ( g_pCVar->FindVar( "fov_desired" ) == NULL )
  367. {
  368. Panel *pFOV = FindChildByName( "FovSlider" );
  369. if ( pFOV )
  370. {
  371. pFOV->SetVisible( false );
  372. }
  373. pFOV = FindChildByName( "FovLabel" );
  374. if ( pFOV )
  375. {
  376. pFOV->SetVisible( false );
  377. }
  378. }
  379. MarkDefaultSettingsAsRecommended();
  380. m_bUseChanges = false;
  381. }
  382. virtual void Activate()
  383. {
  384. BaseClass::Activate();
  385. input()->SetAppModalSurface(GetVPanel());
  386. if (!m_bUseChanges)
  387. {
  388. // reset the data
  389. OnResetData();
  390. }
  391. }
  392. void SetComboItemAsRecommended( vgui::ComboBox *combo, int iItem )
  393. {
  394. // get the item text
  395. wchar_t text[512];
  396. combo->GetItemText(iItem, text, sizeof(text));
  397. // append the recommended flag
  398. wchar_t newText[512];
  399. Q_snwprintf( newText, sizeof(newText) / sizeof(wchar_t), L"%s *", text );
  400. // reset
  401. combo->UpdateItem(iItem, newText, NULL);
  402. }
  403. int FindMSAAMode( int nAASamples, int nAAQuality )
  404. {
  405. // Run through the AA Modes supported by the device
  406. for ( int nAAMode = 0; nAAMode < m_nNumAAModes; nAAMode++ )
  407. {
  408. // If we found the mode that matches what we're looking for, return the index
  409. if ( ( m_nAAModes[nAAMode].m_nNumSamples == nAASamples) && ( m_nAAModes[nAAMode].m_nQualityLevel == nAAQuality) )
  410. {
  411. return nAAMode;
  412. }
  413. }
  414. return 0; // Didn't find what we're looking for, so no AA
  415. }
  416. MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel )
  417. {
  418. if ( panel == m_pDXLevel && RequiresRestart() )
  419. {
  420. // notify the user that this will require a disconnect
  421. QueryBox *box = new QueryBox("#GameUI_SettingRequiresDisconnect_Title", "#GameUI_SettingRequiresDisconnect_Info");
  422. box->AddActionSignalTarget( this );
  423. box->SetCancelCommand(new KeyValues("ResetDXLevelCombo"));
  424. box->DoModal();
  425. }
  426. }
  427. MESSAGE_FUNC( OnGameUIHidden, "GameUIHidden" ) // called when the GameUI is hidden
  428. {
  429. Close();
  430. }
  431. MESSAGE_FUNC( ResetDXLevelCombo, "ResetDXLevelCombo" )
  432. {
  433. ConVarRef mat_dxlevel( "mat_dxlevel" );
  434. for (int i = 0; i < m_pDXLevel->GetItemCount(); i++)
  435. {
  436. KeyValues *kv = m_pDXLevel->GetItemUserData(i);
  437. if ( kv->GetInt("dxlevel") == mat_dxlevel.GetInt( ) )
  438. {
  439. m_pDXLevel->ActivateItem( i );
  440. break;
  441. }
  442. }
  443. // Reset HDR too
  444. if ( m_pHDR->IsEnabled() )
  445. {
  446. ConVarRef mat_hdr_level("mat_hdr_level");
  447. Assert( mat_hdr_level.IsValid() );
  448. m_pHDR->ActivateItem( clamp( mat_hdr_level.GetInt(), 0, 2 ) );
  449. }
  450. }
  451. MESSAGE_FUNC( OK_Confirmed, "OK_Confirmed" )
  452. {
  453. m_bUseChanges = true;
  454. Close();
  455. }
  456. void MarkDefaultSettingsAsRecommended()
  457. {
  458. // Pull in data from dxsupport.cfg database (includes fine-grained per-vendor/per-device config data)
  459. KeyValues *pKeyValues = new KeyValues( "config" );
  460. materials->GetRecommendedConfigurationInfo( 0, pKeyValues );
  461. // Read individual values from keyvalues which came from dxsupport.cfg database
  462. int nSkipLevels = pKeyValues->GetInt( "ConVar.mat_picmip", 0 );
  463. int nAnisotropicLevel = pKeyValues->GetInt( "ConVar.mat_forceaniso", 1 );
  464. int nForceTrilinear = pKeyValues->GetInt( "ConVar.mat_trilinear", 0 );
  465. int nAASamples = pKeyValues->GetInt( "ConVar.mat_antialias", 0 );
  466. int nAAQuality = pKeyValues->GetInt( "ConVar.mat_aaquality", 0 );
  467. int nRenderToTextureShadows = pKeyValues->GetInt( "ConVar.r_shadowrendertotexture", 0 );
  468. int nShadowDepthTextureShadows = pKeyValues->GetInt( "ConVar.r_flashlightdepthtexture", 0 );
  469. #ifndef _GAMECONSOLE
  470. int nWaterUseRealtimeReflection = pKeyValues->GetInt( "ConVar.r_waterforceexpensive", 0 );
  471. #endif
  472. int nWaterUseEntityReflection = pKeyValues->GetInt( "ConVar.r_waterforcereflectentities", 0 );
  473. int nMatVSync = pKeyValues->GetInt( "ConVar.mat_vsync", 0 );
  474. int nRootLOD = pKeyValues->GetInt( "ConVar.r_rootlod", 0 );
  475. int nReduceFillRate = pKeyValues->GetInt( "ConVar.mat_reducefillrate", 0 );
  476. int nDXLevel = pKeyValues->GetInt( "ConVar.mat_dxlevel", 0 );
  477. int nColorCorrection = pKeyValues->GetInt( "ConVar.mat_colorcorrection", 0 );
  478. int nMotionBlur = pKeyValues->GetInt( "ConVar.mat_motion_blur_enabled", 0 );
  479. // Only recommend a dxlevel if there is more than one available
  480. if ( m_pDXLevel->GetItemCount() > 1 )
  481. {
  482. for (int i = 0; i < m_pDXLevel->GetItemCount(); i++)
  483. {
  484. KeyValues *kv = m_pDXLevel->GetItemUserData(i);
  485. if (kv->GetInt("dxlevel") == pKeyValues->GetInt("ConVar.mat_dxlevel"))
  486. {
  487. SetComboItemAsRecommended( m_pDXLevel, i );
  488. break;
  489. }
  490. }
  491. }
  492. SetComboItemAsRecommended( m_pModelDetail, 2 - nRootLOD );
  493. SetComboItemAsRecommended( m_pTextureDetail, 2 - nSkipLevels );
  494. switch ( nAnisotropicLevel )
  495. {
  496. case 2:
  497. SetComboItemAsRecommended( m_pFilteringMode, 2 );
  498. break;
  499. case 4:
  500. SetComboItemAsRecommended( m_pFilteringMode, 3 );
  501. break;
  502. case 8:
  503. SetComboItemAsRecommended( m_pFilteringMode, 4 );
  504. break;
  505. case 16:
  506. SetComboItemAsRecommended( m_pFilteringMode, 5 );
  507. break;
  508. case 0:
  509. default:
  510. if ( nForceTrilinear != 0 )
  511. {
  512. SetComboItemAsRecommended( m_pFilteringMode, 1 );
  513. }
  514. else
  515. {
  516. SetComboItemAsRecommended( m_pFilteringMode, 0 );
  517. }
  518. break;
  519. }
  520. // Map desired mode to list item number
  521. int nMSAAMode = FindMSAAMode( nAASamples, nAAQuality );
  522. SetComboItemAsRecommended( m_pAntialiasingMode, nMSAAMode );
  523. if ( nShadowDepthTextureShadows )
  524. SetComboItemAsRecommended( m_pShadowDetail, 2 ); // Shadow depth mapping (in addition to RTT shadows)
  525. else if ( nRenderToTextureShadows )
  526. SetComboItemAsRecommended( m_pShadowDetail, 1 ); // RTT shadows
  527. else
  528. SetComboItemAsRecommended( m_pShadowDetail, 0 ); // Blobbies
  529. SetComboItemAsRecommended( m_pShaderDetail, nReduceFillRate ? 0 : 1 );
  530. #ifndef _GAMECONSOLE
  531. if ( nWaterUseRealtimeReflection )
  532. #endif
  533. {
  534. if ( nWaterUseEntityReflection )
  535. {
  536. SetComboItemAsRecommended( m_pWaterDetail, 2 );
  537. }
  538. else
  539. {
  540. SetComboItemAsRecommended( m_pWaterDetail, 1 );
  541. }
  542. }
  543. #ifndef _GAMECONSOLE
  544. else
  545. {
  546. SetComboItemAsRecommended( m_pWaterDetail, 0 );
  547. }
  548. #endif
  549. SetComboItemAsRecommended( m_pVSync, nMatVSync != 0 );
  550. SetComboItemAsRecommended( m_pHDR, nDXLevel >= 90 ? 2 : 0 );
  551. SetComboItemAsRecommended( m_pColorCorrection, nColorCorrection );
  552. SetComboItemAsRecommended( m_pMotionBlur, nMotionBlur );
  553. pKeyValues->deleteThis();
  554. }
  555. void ApplyChangesToConVar( const char *pConVarName, int value )
  556. {
  557. Assert( cvar->FindVar( pConVarName ) );
  558. char szCmd[256];
  559. Q_snprintf( szCmd, sizeof(szCmd), "%s %d\n", pConVarName, value );
  560. engine->ClientCmd_Unrestricted( szCmd );
  561. }
  562. virtual void ApplyChanges()
  563. {
  564. if (!m_bUseChanges)
  565. return;
  566. ApplyChangesToConVar( "mat_dxlevel", m_pDXLevel->GetActiveItemUserData()->GetInt("dxlevel") );
  567. ApplyChangesToConVar( "r_rootlod", 2 - m_pModelDetail->GetActiveItem());
  568. ApplyChangesToConVar( "mat_picmip", 2 - m_pTextureDetail->GetActiveItem());
  569. // reset everything tied to the filtering mode, then the switch sets the appropriate one
  570. ApplyChangesToConVar( "mat_trilinear", false );
  571. ApplyChangesToConVar( "mat_forceaniso", 1 );
  572. switch (m_pFilteringMode->GetActiveItem())
  573. {
  574. case 0:
  575. break;
  576. case 1:
  577. ApplyChangesToConVar( "mat_trilinear", true );
  578. break;
  579. case 2:
  580. ApplyChangesToConVar( "mat_forceaniso", 2 );
  581. break;
  582. case 3:
  583. ApplyChangesToConVar( "mat_forceaniso", 4 );
  584. break;
  585. case 4:
  586. ApplyChangesToConVar( "mat_forceaniso", 8 );
  587. break;
  588. case 5:
  589. ApplyChangesToConVar( "mat_forceaniso", 16 );
  590. break;
  591. }
  592. // Set the AA convars according to the menu item chosen
  593. int nActiveAAItem = m_pAntialiasingMode->GetActiveItem();
  594. ApplyChangesToConVar( "mat_antialias", m_nAAModes[nActiveAAItem].m_nNumSamples );
  595. ApplyChangesToConVar( "mat_aaquality", m_nAAModes[nActiveAAItem].m_nQualityLevel );
  596. if( m_pHDR->IsEnabled() )
  597. {
  598. ConVarRef mat_hdr_level("mat_hdr_level");
  599. Assert( mat_hdr_level.IsValid() );
  600. mat_hdr_level.SetValue(m_pHDR->GetActiveItem());
  601. }
  602. if ( m_pShadowDetail->GetActiveItem() == 0 ) // Blobby shadows
  603. {
  604. ApplyChangesToConVar( "r_shadowrendertotexture", 0 ); // Turn off RTT shadows
  605. ApplyChangesToConVar( "r_flashlightdepthtexture", 0 ); // Turn off shadow depth textures
  606. }
  607. else if ( m_pShadowDetail->GetActiveItem() == 1 ) // RTT shadows only
  608. {
  609. ApplyChangesToConVar( "r_shadowrendertotexture", 1 ); // Turn on RTT shadows
  610. ApplyChangesToConVar( "r_flashlightdepthtexture", 0 ); // Turn off shadow depth textures
  611. }
  612. else if ( m_pShadowDetail->GetActiveItem() == 2 ) // Shadow depth textures
  613. {
  614. ApplyChangesToConVar( "r_shadowrendertotexture", 1 ); // Turn on RTT shadows
  615. ApplyChangesToConVar( "r_flashlightdepthtexture", 1 ); // Turn on shadow depth textures
  616. }
  617. ApplyChangesToConVar( "mat_reducefillrate", ( m_pShaderDetail->GetActiveItem() > 0 ) ? 0 : 1 );
  618. switch ( m_pWaterDetail->GetActiveItem() )
  619. {
  620. default:
  621. case 0:
  622. #ifndef _GAMECONSOLE
  623. ApplyChangesToConVar( "r_waterforceexpensive", false );
  624. #endif
  625. ApplyChangesToConVar( "r_waterforcereflectentities", false );
  626. break;
  627. case 1:
  628. #ifndef _GAMECONSOLE
  629. ApplyChangesToConVar( "r_waterforceexpensive", true );
  630. #endif
  631. ApplyChangesToConVar( "r_waterforcereflectentities", false );
  632. break;
  633. case 2:
  634. #ifndef _GAMECONSOLE
  635. ApplyChangesToConVar( "r_waterforceexpensive", true );
  636. #endif
  637. ApplyChangesToConVar( "r_waterforcereflectentities", true );
  638. break;
  639. }
  640. ApplyChangesToConVar( "mat_vsync", m_pVSync->GetActiveItem() );
  641. ApplyChangesToConVar( "mat_colorcorrection", m_pColorCorrection->GetActiveItem() );
  642. ApplyChangesToConVar( "mat_motion_blur_enabled", m_pMotionBlur->GetActiveItem() );
  643. CCvarSlider *pFOV = (CCvarSlider *)FindChildByName( "FOVSlider" );
  644. if ( pFOV )
  645. {
  646. pFOV->ApplyChanges();
  647. }
  648. }
  649. virtual void OnResetData()
  650. {
  651. ConVarRef mat_dxlevel( "mat_dxlevel" );
  652. ConVarRef r_rootlod( "r_rootlod" );
  653. ConVarRef mat_picmip( "mat_picmip" );
  654. ConVarRef mat_trilinear( "mat_trilinear" );
  655. ConVarRef mat_forceaniso( "mat_forceaniso" );
  656. ConVarRef mat_antialias( "mat_antialias" );
  657. ConVarRef mat_aaquality( "mat_aaquality" );
  658. ConVarRef mat_vsync( "mat_vsync" );
  659. ConVarRef r_flashlightdepthtexture( "r_flashlightdepthtexture" );
  660. #ifndef _GAMECONSOLE
  661. ConVarRef r_waterforceexpensive( "r_waterforceexpensive" );
  662. #endif
  663. ConVarRef r_waterforcereflectentities( "r_waterforcereflectentities" );
  664. ConVarRef mat_reducefillrate("mat_reducefillrate" );
  665. ConVarRef mat_hdr_level( "mat_hdr_level" );
  666. ConVarRef mat_colorcorrection( "mat_colorcorrection" );
  667. ConVarRef mat_motion_blur_enabled( "mat_motion_blur_enabled" );
  668. ConVarRef r_shadowrendertotexture( "r_shadowrendertotexture" );
  669. ResetDXLevelCombo();
  670. m_pModelDetail->ActivateItem( 2 - clamp(r_rootlod.GetInt(), 0, 2) );
  671. m_pTextureDetail->ActivateItem( 2 - clamp(mat_picmip.GetInt(), -1, 2) );
  672. if ( r_flashlightdepthtexture.GetBool() ) // If we're doing flashlight shadow depth texturing...
  673. {
  674. r_shadowrendertotexture.SetValue( 1 ); // ...be sure render to texture shadows are also on
  675. m_pShadowDetail->ActivateItem( 2 );
  676. }
  677. else if ( r_shadowrendertotexture.GetBool() ) // RTT shadows, but not shadow depth texturing
  678. {
  679. m_pShadowDetail->ActivateItem( 1 );
  680. }
  681. else // Lowest shadow quality
  682. {
  683. m_pShadowDetail->ActivateItem( 0 );
  684. }
  685. m_pShaderDetail->ActivateItem( mat_reducefillrate.GetBool() ? 0 : 1 );
  686. m_pHDR->ActivateItem(clamp(mat_hdr_level.GetInt(), 0, 2));
  687. switch (mat_forceaniso.GetInt())
  688. {
  689. case 2:
  690. m_pFilteringMode->ActivateItem( 2 );
  691. break;
  692. case 4:
  693. m_pFilteringMode->ActivateItem( 3 );
  694. break;
  695. case 8:
  696. m_pFilteringMode->ActivateItem( 4 );
  697. break;
  698. case 16:
  699. m_pFilteringMode->ActivateItem( 5 );
  700. break;
  701. case 0:
  702. default:
  703. if (mat_trilinear.GetBool())
  704. {
  705. m_pFilteringMode->ActivateItem( 1 );
  706. }
  707. else
  708. {
  709. m_pFilteringMode->ActivateItem( 0 );
  710. }
  711. break;
  712. }
  713. // Map convar to item on AA drop-down
  714. int nAASamples = mat_antialias.GetInt();
  715. int nAAQuality = mat_aaquality.GetInt();
  716. int nMSAAMode = FindMSAAMode( nAASamples, nAAQuality );
  717. m_pAntialiasingMode->ActivateItem( nMSAAMode );
  718. #ifndef _GAMECONSOLE
  719. if ( r_waterforceexpensive.GetBool() )
  720. #endif
  721. {
  722. if ( r_waterforcereflectentities.GetBool() )
  723. {
  724. m_pWaterDetail->ActivateItem( 2 );
  725. }
  726. else
  727. {
  728. m_pWaterDetail->ActivateItem( 1 );
  729. }
  730. }
  731. #ifndef _GAMECONSOLE
  732. else
  733. {
  734. m_pWaterDetail->ActivateItem( 0 );
  735. }
  736. #endif
  737. m_pVSync->ActivateItem( mat_vsync.GetInt() );
  738. m_pColorCorrection->ActivateItem( mat_colorcorrection.GetInt() );
  739. m_pMotionBlur->ActivateItem( mat_motion_blur_enabled.GetInt() );
  740. // get current hardware dx support level
  741. char dxVer[64];
  742. GetNameForDXLevel( mat_dxlevel.GetInt(), dxVer, sizeof( dxVer ) );
  743. SetControlString("dxlabel", dxVer);
  744. // get installed version
  745. char szVersion[64];
  746. szVersion[0] = 0;
  747. system()->GetRegistryString( "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\DirectX\\Version", szVersion, sizeof(szVersion) );
  748. int os = 0, majorVersion = 0, minorVersion = 0, subVersion = 0;
  749. sscanf(szVersion, "%d.%d.%d.%d", &os, &majorVersion, &minorVersion, &subVersion);
  750. Q_snprintf(dxVer, sizeof(dxVer), "DirectX v%d.%d", majorVersion, minorVersion);
  751. SetControlString("dxinstalledlabel", dxVer);
  752. }
  753. virtual void OnCommand( const char *command )
  754. {
  755. if ( !stricmp(command, "OK") )
  756. {
  757. if ( RequiresRestart() )
  758. {
  759. // Bring up the confirmation dialog
  760. QueryBox *box = new QueryBox("#GameUI_SettingRequiresDisconnect_Title", "#GameUI_SettingRequiresDisconnect_Info");
  761. box->AddActionSignalTarget( this );
  762. box->SetOKCommand(new KeyValues("OK_Confirmed"));
  763. box->SetCancelCommand(new KeyValues("ResetDXLevelCombo"));
  764. box->DoModal();
  765. box->MoveToFront();
  766. return;
  767. }
  768. m_bUseChanges = true;
  769. Close();
  770. }
  771. else
  772. {
  773. BaseClass::OnCommand( command );
  774. }
  775. }
  776. void OnKeyCodeTyped(KeyCode code)
  777. {
  778. // force ourselves to be closed if the escape key it pressed
  779. if (code == KEY_ESCAPE)
  780. {
  781. Close();
  782. }
  783. else
  784. {
  785. BaseClass::OnKeyCodeTyped(code);
  786. }
  787. }
  788. bool RequiresRestart()
  789. {
  790. if ( GameUI().IsInLevel() )
  791. {
  792. if ( GameUI().IsInBackgroundLevel() )
  793. return false;
  794. if ( !GameUI().IsInMultiplayer() )
  795. return false;
  796. ConVarRef mat_dxlevel( "mat_dxlevel" );
  797. KeyValues *pUserData = m_pDXLevel->GetActiveItemUserData();
  798. Assert( pUserData );
  799. if ( pUserData && mat_dxlevel.GetInt() != pUserData->GetInt("dxlevel") )
  800. {
  801. return true;
  802. }
  803. // HDR changed?
  804. if ( m_pHDR->IsEnabled() )
  805. {
  806. ConVarRef mat_hdr_level("mat_hdr_level");
  807. Assert( mat_hdr_level.IsValid() );
  808. if ( mat_hdr_level.GetInt() != m_pHDR->GetActiveItem() )
  809. return true;
  810. }
  811. }
  812. return false;
  813. }
  814. private:
  815. bool m_bUseChanges;
  816. vgui::ComboBox *m_pModelDetail, *m_pTextureDetail, *m_pAntialiasingMode, *m_pFilteringMode;
  817. vgui::ComboBox *m_pShadowDetail, *m_pHDR, *m_pWaterDetail, *m_pVSync, *m_pShaderDetail;
  818. vgui::ComboBox *m_pColorCorrection;
  819. vgui::ComboBox *m_pMotionBlur;
  820. vgui::ComboBox *m_pDXLevel;
  821. int m_nNumAAModes;
  822. AAMode_t m_nAAModes[16];
  823. };
  824. //-----------------------------------------------------------------------------
  825. // Purpose:
  826. //-----------------------------------------------------------------------------
  827. COptionsSubVideo::COptionsSubVideo(vgui::Panel *parent) : PropertyPage(parent, NULL)
  828. {
  829. m_bRequireRestart = false;
  830. m_pGammaButton = new Button( this, "GammaButton", "#GameUI_AdjustGamma" );
  831. m_pGammaButton->SetCommand(new KeyValues("OpenGammaDialog"));
  832. m_pMode = new ComboBox(this, "Resolution", 8, false);
  833. m_pAspectRatio = new ComboBox( this, "AspectRatio", 6, false );
  834. m_pAdvanced = new Button( this, "AdvancedButton", "#GameUI_AdvancedEllipsis" );
  835. m_pAdvanced->SetCommand(new KeyValues("OpenAdvanced"));
  836. m_pBenchmark = new Button( this, "BenchmarkButton", "#GameUI_LaunchBenchmark" );
  837. m_pBenchmark->SetCommand(new KeyValues("LaunchBenchmark"));
  838. m_pThirdPartyCredits = new URLButton(this, "ThirdPartyVideoCredits", "#GameUI_ThirdPartyTechCredits");
  839. m_pThirdPartyCredits->SetCommand(new KeyValues("OpenThirdPartyVideoCreditsDialog"));
  840. char pszAspectName[3][64];
  841. wchar_t *unicodeText = g_pVGuiLocalize->Find("#GameUI_AspectNormal");
  842. g_pVGuiLocalize->ConvertUnicodeToANSI(unicodeText, pszAspectName[0], 32);
  843. unicodeText = g_pVGuiLocalize->Find("#GameUI_AspectWide16x9");
  844. g_pVGuiLocalize->ConvertUnicodeToANSI(unicodeText, pszAspectName[1], 32);
  845. unicodeText = g_pVGuiLocalize->Find("#GameUI_AspectWide16x10");
  846. g_pVGuiLocalize->ConvertUnicodeToANSI(unicodeText, pszAspectName[2], 32);
  847. int iNormalItemID = m_pAspectRatio->AddItem( pszAspectName[0], NULL );
  848. int i16x9ItemID = m_pAspectRatio->AddItem( pszAspectName[1], NULL );
  849. int i16x10ItemID = m_pAspectRatio->AddItem( pszAspectName[2], NULL );
  850. const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
  851. int iAspectMode = GetScreenAspectMode( config.m_VideoMode.m_Width, config.m_VideoMode.m_Height );
  852. switch ( iAspectMode )
  853. {
  854. default:
  855. case 0:
  856. m_pAspectRatio->ActivateItem( iNormalItemID );
  857. break;
  858. case 1:
  859. m_pAspectRatio->ActivateItem( i16x9ItemID );
  860. break;
  861. case 2:
  862. m_pAspectRatio->ActivateItem( i16x10ItemID );
  863. break;
  864. }
  865. m_pWindowed = new vgui::ComboBox( this, "DisplayModeCombo", 6, false );
  866. m_pWindowed->AddItem( "#GameUI_Fullscreen", NULL );
  867. m_pWindowed->AddItem( "#GameUI_Windowed", NULL );
  868. LoadControlSettings("Resource\\OptionsSubVideo.res");
  869. // Moved down here so we can set the Drop down's
  870. // menu state after the default (disabled) value is loaded
  871. PrepareResolutionList();
  872. // only show the benchmark button if they have the benchmark map
  873. if ( !g_pFullFileSystem->FileExists("maps/test_hardware.bsp") )
  874. {
  875. m_pBenchmark->SetVisible( false );
  876. }
  877. }
  878. //-----------------------------------------------------------------------------
  879. // Purpose: Generates resolution list
  880. //-----------------------------------------------------------------------------
  881. void COptionsSubVideo::PrepareResolutionList()
  882. {
  883. // get the currently selected resolution
  884. char sz[256];
  885. m_pMode->GetText(sz, 256);
  886. int currentWidth = 0, currentHeight = 0;
  887. sscanf( sz, "%i x %i", &currentWidth, &currentHeight );
  888. // Clean up before filling the info again.
  889. m_pMode->DeleteAllItems();
  890. m_pAspectRatio->SetItemEnabled(1, false);
  891. m_pAspectRatio->SetItemEnabled(2, false);
  892. // get full video mode list
  893. vmode_t *plist = NULL;
  894. int count = 0;
  895. gameuifuncs->GetVideoModes( &plist, &count );
  896. const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
  897. bool bWindowed = (m_pWindowed->GetActiveItem() > 0);
  898. int desktopWidth, desktopHeight;
  899. gameuifuncs->GetDesktopResolution( desktopWidth, desktopHeight );
  900. // iterate all the video modes adding them to the dropdown
  901. bool bFoundWidescreen = false;
  902. int selectedItemID = -1;
  903. for (int i = 0; i < count; i++, plist++)
  904. {
  905. char sz[ 256 ];
  906. GetResolutionName( plist, sz, sizeof( sz ) );
  907. // don't show modes bigger than the desktop for windowed mode
  908. if ( bWindowed && (plist->width > desktopWidth || plist->height > desktopHeight) )
  909. continue;
  910. int itemID = -1;
  911. int iAspectMode = GetScreenAspectMode( plist->width, plist->height );
  912. if ( iAspectMode > 0 )
  913. {
  914. m_pAspectRatio->SetItemEnabled( iAspectMode, true );
  915. bFoundWidescreen = true;
  916. }
  917. // filter the list for those matching the current aspect
  918. if ( iAspectMode == m_pAspectRatio->GetActiveItem() )
  919. {
  920. itemID = m_pMode->AddItem( sz, NULL);
  921. }
  922. // try and find the best match for the resolution to be selected
  923. if ( plist->width == currentWidth && plist->height == currentHeight )
  924. {
  925. selectedItemID = itemID;
  926. }
  927. else if ( selectedItemID == -1 && plist->width == config.m_VideoMode.m_Width && plist->height == config.m_VideoMode.m_Height )
  928. {
  929. selectedItemID = itemID;
  930. }
  931. }
  932. // disable ratio selection if we can't display widescreen.
  933. m_pAspectRatio->SetEnabled( bFoundWidescreen );
  934. m_nSelectedMode = selectedItemID;
  935. if ( selectedItemID != -1 )
  936. {
  937. m_pMode->ActivateItem( selectedItemID );
  938. }
  939. else
  940. {
  941. char sz[256];
  942. Q_snprintf( sz, ARRAYSIZE( sz ), "%d x %d", config.m_VideoMode.m_Width, config.m_VideoMode.m_Height );
  943. m_pMode->SetText( sz );
  944. }
  945. }
  946. //-----------------------------------------------------------------------------
  947. // Purpose:
  948. //-----------------------------------------------------------------------------
  949. COptionsSubVideo::~COptionsSubVideo()
  950. {
  951. if (m_hOptionsSubVideoAdvancedDlg.Get())
  952. {
  953. m_hOptionsSubVideoAdvancedDlg->MarkForDeletion();
  954. }
  955. }
  956. //-----------------------------------------------------------------------------
  957. // Purpose:
  958. //-----------------------------------------------------------------------------
  959. void COptionsSubVideo::OnResetData()
  960. {
  961. m_bRequireRestart = false;
  962. const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
  963. // reset UI elements
  964. m_pWindowed->ActivateItem(config.Windowed() ? 1 : 0);
  965. // reset gamma control
  966. m_pGammaButton->SetEnabled( !config.Windowed() );
  967. SetCurrentResolutionComboItem();
  968. }
  969. //-----------------------------------------------------------------------------
  970. // Purpose:
  971. //-----------------------------------------------------------------------------
  972. void COptionsSubVideo::SetCurrentResolutionComboItem()
  973. {
  974. vmode_t *plist = NULL;
  975. int count = 0;
  976. gameuifuncs->GetVideoModes( &plist, &count );
  977. const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
  978. int resolution = -1;
  979. for ( int i = 0; i < count; i++, plist++ )
  980. {
  981. if ( plist->width == config.m_VideoMode.m_Width &&
  982. plist->height == config.m_VideoMode.m_Height )
  983. {
  984. resolution = i;
  985. break;
  986. }
  987. }
  988. if (resolution != -1)
  989. {
  990. char sz[256];
  991. GetResolutionName( plist, sz, sizeof(sz) );
  992. m_pMode->SetText(sz);
  993. }
  994. }
  995. //-----------------------------------------------------------------------------
  996. // Purpose: restarts the game
  997. //-----------------------------------------------------------------------------
  998. void COptionsSubVideo::OnApplyChanges()
  999. {
  1000. if ( RequiresRestart() )
  1001. {
  1002. INetChannelInfo *nci = engine->GetNetChannelInfo();
  1003. if ( nci )
  1004. {
  1005. // Only retry if we're not running the server
  1006. const char *pAddr = nci->GetAddress();
  1007. if ( pAddr )
  1008. {
  1009. if ( Q_strncmp(pAddr,"127.0.0.1",9) && Q_strncmp(pAddr,"localhost",9) )
  1010. {
  1011. engine->ClientCmd_Unrestricted( "retry\n" );
  1012. }
  1013. else
  1014. {
  1015. engine->ClientCmd_Unrestricted( "disconnect\n" );
  1016. }
  1017. }
  1018. }
  1019. }
  1020. // apply advanced options
  1021. if (m_hOptionsSubVideoAdvancedDlg.Get())
  1022. {
  1023. m_hOptionsSubVideoAdvancedDlg->ApplyChanges();
  1024. }
  1025. // resolution
  1026. char sz[256];
  1027. if ( m_nSelectedMode == -1 )
  1028. {
  1029. m_pMode->GetText(sz, 256);
  1030. }
  1031. else
  1032. {
  1033. m_pMode->GetItemText( m_nSelectedMode, sz, 256 );
  1034. }
  1035. int width = 0, height = 0;
  1036. sscanf( sz, "%i x %i", &width, &height );
  1037. // windowed
  1038. bool windowed = (m_pWindowed->GetActiveItem() > 0) ? true : false;
  1039. // make sure there is a change
  1040. const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
  1041. if ( config.m_VideoMode.m_Width != width
  1042. || config.m_VideoMode.m_Height != height
  1043. || config.Windowed() != windowed)
  1044. {
  1045. // set mode
  1046. char szCmd[ 256 ];
  1047. Q_snprintf( szCmd, sizeof( szCmd ), "mat_setvideomode %i %i %i\n", width, height, windowed ? 1 : 0 );
  1048. engine->ClientCmd_Unrestricted( szCmd );
  1049. }
  1050. // apply changes
  1051. engine->ClientCmd_Unrestricted( "mat_savechanges\n" );
  1052. }
  1053. //-----------------------------------------------------------------------------
  1054. // Purpose:
  1055. //-----------------------------------------------------------------------------
  1056. void COptionsSubVideo::PerformLayout()
  1057. {
  1058. BaseClass::PerformLayout();
  1059. if ( m_pGammaButton )
  1060. {
  1061. const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
  1062. m_pGammaButton->SetEnabled( !config.Windowed() );
  1063. }
  1064. }
  1065. //-----------------------------------------------------------------------------
  1066. // Purpose: enables apply button on data changing
  1067. //-----------------------------------------------------------------------------
  1068. void COptionsSubVideo::OnTextChanged(Panel *pPanel, const char *pszText)
  1069. {
  1070. if (pPanel == m_pMode)
  1071. {
  1072. const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
  1073. m_nSelectedMode = m_pMode->GetActiveItem();
  1074. int w = 0, h = 0;
  1075. sscanf(pszText, "%i x %i", &w, &h);
  1076. if ( config.m_VideoMode.m_Width != w || config.m_VideoMode.m_Height != h )
  1077. {
  1078. OnDataChanged();
  1079. }
  1080. }
  1081. else if (pPanel == m_pAspectRatio)
  1082. {
  1083. PrepareResolutionList();
  1084. }
  1085. else if (pPanel == m_pWindowed)
  1086. {
  1087. PrepareResolutionList();
  1088. OnDataChanged();
  1089. }
  1090. }
  1091. //-----------------------------------------------------------------------------
  1092. // Purpose: enables apply button
  1093. //-----------------------------------------------------------------------------
  1094. void COptionsSubVideo::OnDataChanged()
  1095. {
  1096. PostActionSignal(new KeyValues("ApplyButtonEnable"));
  1097. }
  1098. //-----------------------------------------------------------------------------
  1099. // Purpose: Checks to see if the changes requires a restart to take effect
  1100. //-----------------------------------------------------------------------------
  1101. bool COptionsSubVideo::RequiresRestart()
  1102. {
  1103. if ( m_hOptionsSubVideoAdvancedDlg.Get()
  1104. && m_hOptionsSubVideoAdvancedDlg->RequiresRestart() )
  1105. {
  1106. return true;
  1107. }
  1108. // make sure there is a change
  1109. return m_bRequireRestart;
  1110. }
  1111. //-----------------------------------------------------------------------------
  1112. // Purpose: Opens advanced video mode options dialog
  1113. //-----------------------------------------------------------------------------
  1114. void COptionsSubVideo::OpenAdvanced()
  1115. {
  1116. if ( !m_hOptionsSubVideoAdvancedDlg.Get() )
  1117. {
  1118. m_hOptionsSubVideoAdvancedDlg = new COptionsSubVideoAdvancedDlg( BasePanel()->FindChildByName( "OptionsDialog" ) ); // we'll parent this to the OptionsDialog directly
  1119. }
  1120. m_hOptionsSubVideoAdvancedDlg->Activate();
  1121. }
  1122. vgui::DHANDLE<class CGammaDialog> COptionsSubVideo::m_hGammaDialog;
  1123. void OpenGammaDialog( VPANEL parent )
  1124. {
  1125. if ( !COptionsSubVideo::m_hGammaDialog.Get() )
  1126. {
  1127. COptionsSubVideo::m_hGammaDialog = new CGammaDialog( parent );
  1128. }
  1129. COptionsSubVideo::m_hGammaDialog->Activate();
  1130. }
  1131. //-----------------------------------------------------------------------------
  1132. // Purpose: Opens gamma-adjusting dialog
  1133. //-----------------------------------------------------------------------------
  1134. void COptionsSubVideo::OpenGammaDialog()
  1135. {
  1136. ::OpenGammaDialog( GetVParent() );
  1137. }
  1138. //-----------------------------------------------------------------------------
  1139. // Purpose: Opens benchmark dialog
  1140. //-----------------------------------------------------------------------------
  1141. void COptionsSubVideo::LaunchBenchmark()
  1142. {
  1143. #if defined( BASEPANEL_LEGACY_SOURCE1 )
  1144. BasePanel()->OnOpenBenchmarkDialog();
  1145. #endif
  1146. }
  1147. //-----------------------------------------------------------------------------
  1148. // Purpose: Open third party audio credits dialog
  1149. //-----------------------------------------------------------------------------
  1150. void COptionsSubVideo::OpenThirdPartyVideoCreditsDialog()
  1151. {
  1152. if (!m_OptionsSubVideoThirdPartyCreditsDlg.Get())
  1153. {
  1154. m_OptionsSubVideoThirdPartyCreditsDlg = new COptionsSubVideoThirdPartyCreditsDlg(GetVParent());
  1155. }
  1156. m_OptionsSubVideoThirdPartyCreditsDlg->Activate();
  1157. }
  1158. COptionsSubVideoThirdPartyCreditsDlg::COptionsSubVideoThirdPartyCreditsDlg( vgui::VPANEL hParent ) : BaseClass( NULL, NULL )
  1159. {
  1160. SetProportional( true );
  1161. // parent is ignored, since we want look like we're steal focus from the parent (we'll become modal below)
  1162. #ifdef GAMEUI_BASEMODPANEL_VGUI
  1163. SetScheme( GAMEUI_BASEMODPANEL_SCHEME );
  1164. #endif
  1165. SetTitle("#GameUI_ThirdPartyVideo_Title", true);
  1166. SetSize(
  1167. vgui::scheme()->GetProportionalScaledValueEx( GetScheme(), 500 ),
  1168. vgui::scheme()->GetProportionalScaledValueEx( GetScheme(), 200 ) );
  1169. MoveToCenterOfScreen();
  1170. SetSizeable( false );
  1171. SetDeleteSelfOnClose( true );
  1172. }
  1173. void COptionsSubVideoThirdPartyCreditsDlg::ApplySchemeSettings( IScheme *pScheme )
  1174. {
  1175. BaseClass::ApplySchemeSettings( pScheme );
  1176. LoadControlSettings( "resource/OptionsSubVideoThirdPartyDlg.res" );
  1177. }
  1178. void COptionsSubVideoThirdPartyCreditsDlg::Activate()
  1179. {
  1180. BaseClass::Activate();
  1181. input()->SetAppModalSurface(GetVPanel());
  1182. }
  1183. void COptionsSubVideoThirdPartyCreditsDlg::OnKeyCodeTyped(KeyCode code)
  1184. {
  1185. // force ourselves to be closed if the escape key it pressed
  1186. if (code == KEY_ESCAPE)
  1187. {
  1188. Close();
  1189. }
  1190. else
  1191. {
  1192. BaseClass::OnKeyCodeTyped(code);
  1193. }
  1194. }