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.

195 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Client DLL VGUI2 Viewport
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "cbase.h"
  14. #pragma warning( disable : 4800 ) // disable forcing int to bool performance warning
  15. // VGUI panel includes
  16. #include <vgui_controls/Panel.h>
  17. #include <vgui/ISurface.h>
  18. #include <KeyValues.h>
  19. #include <vgui/Cursor.h>
  20. #include <vgui/IScheme.h>
  21. #include <vgui/IVGui.h>
  22. #include <vgui/ILocalize.h>
  23. #include <vgui/VGUI.h>
  24. // client dll/engine defines
  25. #include "hud.h"
  26. #include <voice_status.h>
  27. #include "dodteammenu.h"
  28. #include "dodclassmenu.h"
  29. #include "dodclientscoreboard.h"
  30. #include "dodspectatorgui.h"
  31. #include "dodtextwindow.h"
  32. #include "dodmenubackground.h"
  33. #include "dodoverview.h"
  34. #include "IGameUIFuncs.h"
  35. // viewport definitions
  36. #include <baseviewport.h>
  37. #include "dodviewport.h"
  38. #include "vguicenterprint.h"
  39. #include "text_message.h"
  40. #include "c_dod_player.h"
  41. CON_COMMAND_F( changeteam, "Choose a new team", FCVAR_SERVER_CAN_EXECUTE|FCVAR_CLIENTCMD_CAN_EXECUTE )
  42. {
  43. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  44. if ( pPlayer && pPlayer->CanShowTeamMenu() )
  45. {
  46. gViewPortInterface->ShowPanel( PANEL_TEAM, true );
  47. }
  48. }
  49. CON_COMMAND_F( changeclass, "Choose a new class", FCVAR_SERVER_CAN_EXECUTE|FCVAR_CLIENTCMD_CAN_EXECUTE )
  50. {
  51. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  52. if ( pPlayer && pPlayer->CanShowClassMenu())
  53. {
  54. switch( pPlayer->GetTeamNumber() )
  55. {
  56. case TEAM_ALLIES:
  57. gViewPortInterface->ShowPanel( PANEL_CLASS_ALLIES, true );
  58. break;
  59. case TEAM_AXIS:
  60. gViewPortInterface->ShowPanel( PANEL_CLASS_AXIS, true );
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. }
  67. CON_COMMAND_F( spec_menu, "Activates spectator menu", FCVAR_SERVER_CAN_EXECUTE|FCVAR_CLIENTCMD_CAN_EXECUTE)
  68. {
  69. bool bShowIt = true;
  70. if ( args.ArgC() == 2 )
  71. {
  72. bShowIt = atoi( args[ 1 ] ) == 1;
  73. }
  74. if ( gViewPortInterface )
  75. {
  76. gViewPortInterface->ShowPanel( PANEL_SPECMENU, bShowIt );
  77. }
  78. }
  79. CON_COMMAND_F( togglescores, "Toggles score panel", FCVAR_SERVER_CAN_EXECUTE|FCVAR_CLIENTCMD_CAN_EXECUTE)
  80. {
  81. if ( !gViewPortInterface )
  82. return;
  83. IViewPortPanel *scoreboard = gViewPortInterface->FindPanelByName( PANEL_SCOREBOARD );
  84. if ( !scoreboard )
  85. return;
  86. if ( scoreboard->IsVisible() )
  87. {
  88. gViewPortInterface->ShowPanel( scoreboard, false );
  89. GetClientVoiceMgr()->StopSquelchMode();
  90. }
  91. else
  92. {
  93. gViewPortInterface->ShowPanel( scoreboard, true );
  94. }
  95. }
  96. void DODViewport::ApplySchemeSettings( vgui::IScheme *pScheme )
  97. {
  98. BaseClass::ApplySchemeSettings( pScheme );
  99. gHUD.InitColors( pScheme );
  100. SetPaintBackgroundEnabled( false );
  101. }
  102. IViewPortPanel* DODViewport::CreatePanelByName(const char *szPanelName)
  103. {
  104. IViewPortPanel* newpanel = NULL;
  105. // overwrite MOD specific panel creation
  106. if ( Q_strcmp(PANEL_TEAM, szPanelName) == 0 )
  107. {
  108. newpanel = new CDODTeamMenu( this );
  109. }
  110. else if ( Q_strcmp(PANEL_CLASS_ALLIES, szPanelName) == 0 )
  111. {
  112. newpanel = new CDODClassMenu_Allies( this );
  113. }
  114. else if ( Q_strcmp(PANEL_CLASS_AXIS, szPanelName) == 0 )
  115. {
  116. newpanel = new CDODClassMenu_Axis( this );
  117. }
  118. else if ( Q_strcmp(PANEL_SCOREBOARD, szPanelName) == 0)
  119. {
  120. newpanel = new CDODClientScoreBoardDialog( this );
  121. }
  122. else if ( Q_strcmp(PANEL_SPECGUI, szPanelName) == 0 )
  123. {
  124. newpanel = new CDODSpectatorGUI( this );
  125. }
  126. else if ( Q_strcmp(PANEL_INFO, szPanelName) == 0 )
  127. {
  128. newpanel = new CDODTextWindow( this );
  129. }
  130. else
  131. {
  132. // create a generic base panel, don't add twice
  133. newpanel = BaseClass::CreatePanelByName( szPanelName );
  134. }
  135. return newpanel;
  136. }
  137. void DODViewport::CreateDefaultPanels( void )
  138. {
  139. AddNewPanel( CreatePanelByName( PANEL_TEAM ), "PANEL_TEAM" );
  140. AddNewPanel( CreatePanelByName( PANEL_CLASS_ALLIES ), "PANEL_CLASS_ALLIES" );
  141. AddNewPanel( CreatePanelByName( PANEL_CLASS_AXIS ), "PANEL_CLASS_AXIS" );
  142. BaseClass::CreateDefaultPanels();
  143. }
  144. int DODViewport::GetDeathMessageStartHeight( void )
  145. {
  146. int y = YRES(5);
  147. if ( g_pSpectatorGUI && g_pSpectatorGUI->IsVisible() )
  148. {
  149. y = g_pSpectatorGUI->GetTopBarHeight() + YRES(5);
  150. }
  151. if ( g_pMapOverview && g_pMapOverview->IsVisible() )
  152. {
  153. if ( g_pMapOverview->GetMode() == CMapOverview::MAP_MODE_INSET )
  154. {
  155. int map_x, map_y, map_w, map_h;
  156. g_pMapOverview->GetBounds( map_x, map_y, map_w, map_h );
  157. y = map_y + map_h + YRES(5);
  158. }
  159. }
  160. return y;
  161. }