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.

1392 lines
41 KiB

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