Team Fortress 2 Source Code as on 22/4/2020
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.

532 lines
16 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "client_pch.h"
  8. #include <vgui/ISystem.h>
  9. #include <vgui/ISurface.h>
  10. #include <vgui/IVGui.h>
  11. #include <KeyValues.h>
  12. #include <vgui_controls/BuildGroup.h>
  13. #include <vgui_controls/Tooltip.h>
  14. #include <vgui_controls/TextImage.h>
  15. #include <vgui_controls/CheckButton.h>
  16. #include <vgui_controls/Label.h>
  17. #include <vgui_controls/PropertySheet.h>
  18. #include <vgui_controls/ProgressBar.h>
  19. #include <vgui_controls/Slider.h>
  20. #include <vgui_controls/Controls.h>
  21. #include <vgui_controls/TextEntry.h>
  22. #include <vgui/IInput.h>
  23. #include "cl_foguipanel.h"
  24. // memdbgon must be the last include file in a .cpp file!!!
  25. #include "tier0/memdbgon.h"
  26. using namespace vgui;
  27. //-----------------------------------------------------------------------------
  28. // CFogUIPanel
  29. //-----------------------------------------------------------------------------
  30. CFogUIPanel *g_pFogUI = NULL;
  31. void CFogUIPanel::InstallFogUI( vgui::Panel *parent )
  32. {
  33. if ( g_pFogUI )
  34. return;
  35. g_pFogUI = new CFogUIPanel( parent );
  36. Assert( g_pFogUI );
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose: Constructor
  40. //-----------------------------------------------------------------------------
  41. CFogUIPanel::CFogUIPanel( vgui::Panel *parent ) : vgui::Frame( parent, "FogUIPanel" )
  42. {
  43. SetTitle( "FogUI", true );
  44. m_pFogOverride = new vgui::CheckButton( this, "FogOverride", "FogOverride" );
  45. //
  46. // World
  47. //
  48. m_pFogEnable = new vgui::CheckButton( this, "FogEnable", "FogEnable" );
  49. m_pFogEnable->SetSelected( true );
  50. // FogStart
  51. m_pFogStart = new vgui::Slider( this, "FogStart" );
  52. m_pFogStart->SetRange( -10000, 30000 );
  53. m_pFogStart->SetValue( 1 );
  54. m_pFogStart->AddActionSignalTarget( this );
  55. m_pFogStart->SetDragOnRepositionNob( true );
  56. m_pFogStartText = new vgui::TextEntry( this, "FogStartText" );
  57. m_pFogStartText->SendNewLine( true );
  58. m_pFogStartText->SetCatchEnterKey( true );
  59. // FogEnd
  60. m_pFogEnd = new vgui::Slider( this, "FogEnd" );
  61. m_pFogEnd->SetRange( -10000, 30000 );
  62. m_pFogEnd->SetValue( 1 );
  63. m_pFogEnd->AddActionSignalTarget( this );
  64. m_pFogEnd->SetDragOnRepositionNob( true );
  65. m_pFogEndText = new vgui::TextEntry( this, "FogEndText" );
  66. m_pFogEndText->SendNewLine( true );
  67. m_pFogEndText->SetCatchEnterKey( true );
  68. // Red
  69. m_pFogColorRed = new vgui::Slider( this, "FogColorRed" );
  70. m_pFogColorRed->SetRange( 1, 255 );
  71. m_pFogColorRed->SetValue( 1 );
  72. m_pFogColorRed->AddActionSignalTarget( this );
  73. m_pFogColorRed->SetDragOnRepositionNob( true );
  74. m_pFogColorRedText = new vgui::TextEntry( this, "FogColorRedText" );
  75. m_pFogColorRedText->SendNewLine( true );
  76. m_pFogColorRedText->SetCatchEnterKey( true );
  77. // Green
  78. m_pFogColorGreen = new vgui::Slider( this, "FogColorGreen" );
  79. m_pFogColorGreen->SetRange( 1, 255 );
  80. m_pFogColorGreen->SetValue( 1 );
  81. m_pFogColorGreen->AddActionSignalTarget( this );
  82. m_pFogColorGreen->SetDragOnRepositionNob( true );
  83. m_pFogColorGreenText = new vgui::TextEntry( this, "FogColorGreenText" );
  84. m_pFogColorGreenText->SendNewLine( true );
  85. m_pFogColorGreenText->SetCatchEnterKey( true );
  86. // Blue
  87. m_pFogColorBlue = new vgui::Slider( this, "FogColorBlue" );
  88. m_pFogColorBlue->SetRange( 1, 255 );
  89. m_pFogColorBlue->SetValue( 1 );
  90. m_pFogColorBlue->AddActionSignalTarget( this );
  91. m_pFogColorBlue->SetDragOnRepositionNob( true );
  92. m_pFogColorBlueText = new vgui::TextEntry( this, "FogColorBlueText" );
  93. m_pFogColorBlueText->SendNewLine( true );
  94. m_pFogColorBlueText->SetCatchEnterKey( true );
  95. //
  96. // Skybox
  97. //
  98. m_pFogEnableSky = new vgui::CheckButton( this, "FogEnableSky", "FogEnableSky" );
  99. m_pFogEnableSky->SetSelected( true );
  100. // Start
  101. m_pFogStartSky = new vgui::Slider( this, "FogStartSky" );
  102. m_pFogStartSky->SetRange( -10000, 30000 );
  103. m_pFogStartSky->SetValue( 1 );
  104. m_pFogStartSky->AddActionSignalTarget( this );
  105. m_pFogStartSky->SetDragOnRepositionNob( true );
  106. m_pFogStartTextSky = new vgui::TextEntry( this, "FogStartTextSky" );
  107. m_pFogStartTextSky->SendNewLine( true );
  108. m_pFogStartTextSky->SetCatchEnterKey( true );
  109. // End
  110. m_pFogEndSky = new vgui::Slider( this, "FogEndSky" );
  111. m_pFogEndSky->SetRange( -10000, 30000 );
  112. m_pFogEndSky->SetValue( 1 );
  113. m_pFogEndSky->AddActionSignalTarget( this );
  114. m_pFogEndSky->SetDragOnRepositionNob( true );
  115. m_pFogEndTextSky = new vgui::TextEntry( this, "FogEndTextSky" );
  116. m_pFogEndTextSky->SendNewLine( true );
  117. m_pFogEndTextSky->SetCatchEnterKey( true );
  118. // Red
  119. m_pFogColorRedSky = new vgui::Slider( this, "FogColorRedSky" );
  120. m_pFogColorRedSky->SetRange( 1, 255 );
  121. m_pFogColorRedSky->SetValue( 1 );
  122. m_pFogColorRedSky->AddActionSignalTarget( this );
  123. m_pFogColorRedSky->SetDragOnRepositionNob( true );
  124. m_pFogColorRedTextSky = new vgui::TextEntry( this, "FogColorRedTextSky" );
  125. m_pFogColorRedTextSky->SendNewLine( true );
  126. m_pFogColorRedTextSky->SetCatchEnterKey( true );
  127. // Green
  128. m_pFogColorGreenSky = new vgui::Slider( this, "FogColorGreenSky" );
  129. m_pFogColorGreenSky->SetRange( 1, 255 );
  130. m_pFogColorGreenSky->SetValue( 1 );
  131. m_pFogColorGreenSky->AddActionSignalTarget( this );
  132. m_pFogColorGreenSky->SetDragOnRepositionNob( true );
  133. m_pFogColorGreenTextSky = new vgui::TextEntry( this, "FogColorGreenTextSky" );
  134. m_pFogColorGreenTextSky->SendNewLine( true );
  135. m_pFogColorGreenTextSky->SetCatchEnterKey( true );
  136. // Blue
  137. m_pFogColorBlueSky = new vgui::Slider( this, "FogColorBlueSky" );
  138. m_pFogColorBlueSky->SetRange( 1, 255 );
  139. m_pFogColorBlueSky->SetValue( 1 );
  140. m_pFogColorBlueSky->AddActionSignalTarget( this );
  141. m_pFogColorBlueSky->SetDragOnRepositionNob( true );
  142. m_pFogColorBlueTextSky = new vgui::TextEntry( this, "FogColorBlueTextSky" );
  143. m_pFogColorBlueTextSky->SendNewLine( true );
  144. m_pFogColorBlueTextSky->SetCatchEnterKey( true );
  145. //
  146. // Far Z
  147. //
  148. m_pFarZOverride = new vgui::CheckButton( this, "FarZOverride", "FarZOverride" );
  149. m_pFarZOverride->SetSelected( false );
  150. m_pFarZ = new vgui::Slider( this, "FarZ" );
  151. m_pFarZ->SetRange( 1, 30000 );
  152. m_pFarZ->SetValue( 30000 );
  153. m_pFarZ->AddActionSignalTarget( this );
  154. m_pFarZ->SetDragOnRepositionNob( true );
  155. m_pFarZText = new vgui::TextEntry( this, "FarZText" );
  156. m_pFarZText->SendNewLine( true );
  157. m_pFarZText->SetCatchEnterKey( true );
  158. m_pFarZText->SetText( va( "%i", m_pFarZ->GetValue() ) );
  159. // TODO:
  160. // - fog_maxdensity
  161. // - fog_maxdensityskybox
  162. // - fog_fogvolue
  163. // - r_pixelfog?
  164. vgui::ivgui()->AddTickSignal( GetVPanel(), 0 );
  165. LoadControlSettings("Resource\\FogUIPanel.res");
  166. SetVisible( false );
  167. SetSizeable( false );
  168. SetMoveable( true );
  169. }
  170. //-----------------------------------------------------------------------------
  171. // Purpose:
  172. //-----------------------------------------------------------------------------
  173. CFogUIPanel::~CFogUIPanel()
  174. {
  175. }
  176. //-----------------------------------------------------------------------------
  177. // Purpose:
  178. //-----------------------------------------------------------------------------
  179. void CFogUIPanel::OnTick()
  180. {
  181. BaseClass::OnTick();
  182. if ( !IsVisible() )
  183. return;
  184. bool bEnabled = m_pFogOverride->IsSelected();
  185. bool bFogEnabled = ( m_pFogEnable->IsSelected() && m_pFogOverride->IsSelected() );
  186. m_pFogEnable->SetEnabled( bEnabled );
  187. m_pFogStart->SetEnabled( bFogEnabled );
  188. m_pFogEnd->SetEnabled( bFogEnabled);
  189. m_pFogStartText->SetEnabled( bFogEnabled );
  190. m_pFogEndText->SetEnabled( bFogEnabled );
  191. m_pFogColorRed->SetEnabled( bFogEnabled );
  192. m_pFogColorRedText->SetEnabled( bFogEnabled );
  193. m_pFogColorGreen->SetEnabled( bFogEnabled );
  194. m_pFogColorGreenText->SetEnabled( bFogEnabled );
  195. m_pFogColorBlue->SetEnabled( bFogEnabled );
  196. m_pFogColorBlueText->SetEnabled( bFogEnabled );
  197. bool bFogSkyEnabled = ( m_pFogEnableSky->IsSelected() && m_pFogOverride->IsSelected() );
  198. m_pFogEnableSky->SetEnabled( bEnabled );
  199. m_pFogStartSky->SetEnabled( bFogSkyEnabled );
  200. m_pFogEndSky->SetEnabled( bFogSkyEnabled);
  201. m_pFogStartTextSky->SetEnabled( bFogSkyEnabled );
  202. m_pFogEndTextSky->SetEnabled( bFogSkyEnabled );
  203. m_pFogColorRedSky->SetEnabled( bFogSkyEnabled);
  204. m_pFogColorRedTextSky->SetEnabled( bFogSkyEnabled);
  205. m_pFogColorGreenSky->SetEnabled( bFogSkyEnabled );
  206. m_pFogColorGreenTextSky->SetEnabled( bFogSkyEnabled );
  207. m_pFogColorBlueSky->SetEnabled( bFogSkyEnabled );
  208. m_pFogColorBlueTextSky->SetEnabled( bFogSkyEnabled );
  209. bool bFarZEnabled = ( m_pFarZOverride->IsSelected() && m_pFogOverride->IsSelected() );
  210. m_pFarZOverride->SetEnabled( bEnabled );
  211. m_pFarZ->SetEnabled( bFarZEnabled );
  212. m_pFarZText->SetEnabled( bFarZEnabled );
  213. }
  214. //-----------------------------------------------------------------------------
  215. // Purpose: Commands
  216. //-----------------------------------------------------------------------------
  217. void CFogUIPanel::OnCommand( const char *command )
  218. {
  219. if ( !Q_strcasecmp( command, "FogOverride" ) )
  220. {
  221. if ( m_pFogOverride->IsSelected() == true )
  222. {
  223. Cbuf_AddText( "fog_override 1\n" );
  224. }
  225. else
  226. {
  227. Cbuf_AddText( "fog_override 0\n" );
  228. }
  229. }
  230. else if ( !Q_strcasecmp( command, "FogEnable" ) )
  231. {
  232. if ( m_pFogEnable->IsSelected() == true )
  233. {
  234. Cbuf_AddText( "fog_enable 1\n" );
  235. }
  236. else
  237. {
  238. Cbuf_AddText( "fog_enable 0\n" );
  239. }
  240. }
  241. else if ( !Q_strcasecmp( command, "FogEnableSky" ) )
  242. {
  243. if ( m_pFogEnableSky->IsSelected() == true )
  244. {
  245. Cbuf_AddText( "fog_enableskybox 1\n" );
  246. }
  247. else
  248. {
  249. Cbuf_AddText( "fog_enableskybox 0\n" );
  250. }
  251. }
  252. else if ( !Q_strcasecmp( command, "FarZOverride" ) )
  253. {
  254. if ( m_pFarZOverride->IsSelected() == true )
  255. {
  256. //m_pFarZText->SetText( va( "%i", m_pFarZ->GetValue() ) );
  257. Cbuf_AddText( va( "r_farz %i\n", m_pFarZ->GetValue() ) );
  258. }
  259. else
  260. {
  261. Cbuf_AddText( "r_farz -1\n" );
  262. }
  263. }
  264. else
  265. {
  266. BaseClass::OnCommand( command );
  267. }
  268. }
  269. //-----------------------------------------------------------------------------
  270. // Purpose: Text
  271. //-----------------------------------------------------------------------------
  272. void CFogUIPanel::OnTextNewLine( KeyValues *data )
  273. {
  274. Panel *pPanel = reinterpret_cast<vgui::Panel *>( data->GetPtr("panel") );
  275. if ( !pPanel )
  276. {
  277. return;
  278. }
  279. vgui::TextEntry *pTextEntry = dynamic_cast<vgui::TextEntry *>( pPanel );
  280. if ( !pTextEntry )
  281. {
  282. return;
  283. }
  284. // World
  285. if ( pTextEntry == m_pFogStartText || pTextEntry == m_pFogStartTextSky )
  286. {
  287. UpdateFogStartSlider();
  288. return;
  289. }
  290. if ( pTextEntry == m_pFogEndText || pTextEntry == m_pFogEndTextSky )
  291. {
  292. UpdateFogEndSlider();
  293. return;
  294. }
  295. if ( pTextEntry == m_pFogColorRedText || pTextEntry == m_pFogColorRedTextSky )
  296. {
  297. UpdateFogColorRedSlider();
  298. return;
  299. }
  300. if ( pTextEntry == m_pFogColorGreenText || pTextEntry == m_pFogColorGreenTextSky )
  301. {
  302. UpdateFogColorGreenSlider();
  303. return;
  304. }
  305. if ( pTextEntry == m_pFogColorBlueText || pTextEntry == m_pFogColorBlueTextSky )
  306. {
  307. UpdateFogColorBlueSlider();
  308. return;
  309. }
  310. if ( pTextEntry == m_pFarZText )
  311. {
  312. UpdateFarZSlider();
  313. return;
  314. }
  315. }
  316. //-----------------------------------------------------------------------------
  317. // Purpose: Text
  318. //-----------------------------------------------------------------------------
  319. void CFogUIPanel::OnTextKillFocus( KeyValues *data )
  320. {
  321. Panel *pPanel = reinterpret_cast<vgui::Panel *>( data->GetPtr("panel") );
  322. if ( !pPanel )
  323. {
  324. return;
  325. }
  326. vgui::TextEntry *pTextEntry = dynamic_cast<vgui::TextEntry *>( pPanel );
  327. if ( !pTextEntry )
  328. {
  329. return;
  330. }
  331. // World
  332. if ( pTextEntry == m_pFogStartText || pTextEntry == m_pFogStartTextSky )
  333. {
  334. UpdateFogStartSlider();
  335. return;
  336. }
  337. if ( pTextEntry == m_pFogEndText || pTextEntry == m_pFogEndTextSky )
  338. {
  339. UpdateFogEndSlider();
  340. return;
  341. }
  342. if ( pTextEntry == m_pFogColorRedText || pTextEntry == m_pFogColorRedTextSky )
  343. {
  344. UpdateFogColorRedSlider();
  345. return;
  346. }
  347. if ( pTextEntry == m_pFogColorGreenText || pTextEntry == m_pFogColorGreenTextSky )
  348. {
  349. UpdateFogColorGreenSlider();
  350. return;
  351. }
  352. if ( pTextEntry == m_pFogColorBlueText || pTextEntry == m_pFogColorBlueTextSky )
  353. {
  354. UpdateFogColorBlueSlider();
  355. return;
  356. }
  357. if ( pTextEntry == m_pFarZText )
  358. {
  359. UpdateFarZSlider();
  360. return;
  361. }
  362. }
  363. //-----------------------------------------------------------------------------
  364. // Purpose: Messages
  365. //-----------------------------------------------------------------------------
  366. void CFogUIPanel::OnMessage( const KeyValues *params, VPANEL fromPanel )
  367. {
  368. BaseClass::OnMessage( params, fromPanel );
  369. if ( !Q_strcmp( "SliderMoved", params->GetName() ) )
  370. {
  371. // World
  372. if ( fromPanel == m_pFogStart->GetVPanel() )
  373. {
  374. Cbuf_AddText( va( "fog_start %i\n", m_pFogStart->GetValue() ) );
  375. m_pFogStartText->SetText( va( "%i", m_pFogStart->GetValue() ) );
  376. }
  377. if ( fromPanel == m_pFogEnd->GetVPanel() )
  378. {
  379. Cbuf_AddText( va( "fog_end %i\n", m_pFogEnd->GetValue() ) );
  380. m_pFogEndText->SetText( va( "%i", m_pFogEnd->GetValue() ) );
  381. }
  382. if ( fromPanel == m_pFogColorRed->GetVPanel() )
  383. {
  384. m_pFogColorRedText->SetText( va( "%i", m_pFogColorRed->GetValue() ) );
  385. UpdateFogColors();
  386. }
  387. if ( fromPanel == m_pFogColorGreen->GetVPanel() )
  388. {
  389. m_pFogColorGreenText->SetText( va( "%i", m_pFogColorGreen->GetValue() ) );
  390. UpdateFogColors();
  391. }
  392. if ( fromPanel == m_pFogColorBlue->GetVPanel() )
  393. {
  394. m_pFogColorBlueText->SetText( va( "%i", m_pFogColorBlue->GetValue() ) );
  395. UpdateFogColors();
  396. }
  397. // Skybox
  398. if ( fromPanel == m_pFogStartSky->GetVPanel() )
  399. {
  400. Cbuf_AddText( va( "fog_startskybox %i\n", m_pFogStartSky->GetValue() ) );
  401. m_pFogStartTextSky->SetText( va( "%i", m_pFogStartSky->GetValue() ) );
  402. }
  403. if ( fromPanel == m_pFogEndSky->GetVPanel() )
  404. {
  405. Cbuf_AddText( va( "fog_endskybox %i\n", m_pFogEndSky->GetValue() ) );
  406. m_pFogEndTextSky->SetText( va( "%i", m_pFogEndSky->GetValue() ) );
  407. }
  408. if ( fromPanel == m_pFogColorRedSky->GetVPanel() )
  409. {
  410. m_pFogColorRedTextSky->SetText( va( "%i", m_pFogColorRedSky->GetValue() ) );
  411. UpdateFogColors();
  412. }
  413. if ( fromPanel == m_pFogColorGreenSky->GetVPanel() )
  414. {
  415. m_pFogColorGreenTextSky->SetText( va( "%i", m_pFogColorGreenSky->GetValue() ) );
  416. UpdateFogColors();
  417. }
  418. if ( fromPanel == m_pFogColorBlueSky->GetVPanel() )
  419. {
  420. m_pFogColorBlueTextSky->SetText( va( "%i", m_pFogColorBlueSky->GetValue() ) );
  421. UpdateFogColors();
  422. }
  423. // FarZ
  424. if ( fromPanel == m_pFarZ->GetVPanel() )
  425. {
  426. Cbuf_AddText( va( "r_farz %i\n", m_pFarZ->GetValue() ) );
  427. m_pFarZText->SetText( va( "%i", m_pFarZ->GetValue() ) );
  428. }
  429. }
  430. }
  431. //-----------------------------------------------------------------------------
  432. // Purpose: Update Sliders
  433. //-----------------------------------------------------------------------------
  434. void CFogUIPanel::UpdateFogStartSlider()
  435. {
  436. m_pFogStart->SetValue( m_pFogStartText->GetValueAsInt() );
  437. m_pFogStartSky->SetValue( m_pFogStartTextSky->GetValueAsInt() );
  438. }
  439. void CFogUIPanel::UpdateFogEndSlider()
  440. {
  441. m_pFogEnd->SetValue( m_pFogEndText->GetValueAsInt() );
  442. m_pFogEndSky->SetValue( m_pFogEndTextSky->GetValueAsInt() );
  443. }
  444. void CFogUIPanel::UpdateFogColorRedSlider()
  445. {
  446. m_pFogColorRed->SetValue( m_pFogColorRedText->GetValueAsInt() );
  447. m_pFogColorRedSky->SetValue( m_pFogColorRedTextSky->GetValueAsInt() );
  448. }
  449. void CFogUIPanel::UpdateFogColorGreenSlider()
  450. {
  451. m_pFogColorGreen->SetValue( m_pFogColorGreenText->GetValueAsInt() );
  452. m_pFogColorGreenSky->SetValue( m_pFogColorGreenTextSky->GetValueAsInt() );
  453. }
  454. void CFogUIPanel::UpdateFogColorBlueSlider()
  455. {
  456. m_pFogColorBlue->SetValue( m_pFogColorBlueText->GetValueAsInt() );
  457. m_pFogColorBlueSky->SetValue( m_pFogColorBlueTextSky->GetValueAsInt() );
  458. }
  459. void CFogUIPanel::UpdateFarZSlider()
  460. {
  461. m_pFarZ->SetValue( m_pFarZText->GetValueAsInt() );
  462. }
  463. //-----------------------------------------------------------------------------
  464. // Purpose: Update Colors
  465. //-----------------------------------------------------------------------------
  466. void CFogUIPanel::UpdateFogColors()
  467. {
  468. int iRed = m_pFogColorRed->GetValue();
  469. int iGreen = m_pFogColorGreen->GetValue();
  470. int iBlue = m_pFogColorBlue->GetValue();
  471. Cbuf_AddText( va( "fog_color %i %i %i\n", iRed, iGreen, iBlue ) );
  472. int iRedSky = m_pFogColorRedSky->GetValue();
  473. int iGreenSky = m_pFogColorGreenSky->GetValue();
  474. int iBlueSky = m_pFogColorBlueSky->GetValue();
  475. Cbuf_AddText( va( "fog_colorskybox %i %i %i\n", iRedSky, iGreenSky, iBlueSky ) );
  476. }
  477. //-----------------------------------------------------------------------------
  478. // Purpose:
  479. //-----------------------------------------------------------------------------
  480. void FogUI_f()
  481. {
  482. if ( !g_pFogUI )
  483. return;
  484. if ( g_pFogUI->IsVisible() )
  485. {
  486. g_pFogUI->Close();
  487. }
  488. else
  489. {
  490. g_pFogUI->Activate();
  491. }
  492. }
  493. static ConCommand fogui( "fogui", FogUI_f, "Show/hide fog control UI.", FCVAR_DONTRECORD );