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.

322 lines
8.0 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. // cstrike specific dialogs
  28. #include "cstriketextwindow.h"
  29. #include "cstriketeammenu.h"
  30. #include "cstrikeclassmenu.h"
  31. #include "cstrikebuymenu.h"
  32. #include "cstrikebuyequipmenu.h"
  33. #include "cstrikespectatorgui.h"
  34. #include "cstrikeclientscoreboard.h"
  35. #include "clientmode_csnormal.h"
  36. #include "IGameUIFuncs.h"
  37. // viewport definitions
  38. #include <baseviewport.h>
  39. #include "counterstrikeviewport.h"
  40. #include "cs_gamerules.h"
  41. // #include "c_user_message_register.h"
  42. #include "vguicenterprint.h"
  43. #include "text_message.h"
  44. static void OpenPanelWithCheck( const char *panelToOpen, const char *panelToCheck )
  45. {
  46. IViewPortPanel *checkPanel = gViewPortInterface->FindPanelByName( panelToCheck );
  47. if ( !checkPanel || !checkPanel->IsVisible() )
  48. {
  49. gViewPortInterface->ShowPanel( panelToOpen, true );
  50. }
  51. }
  52. CON_COMMAND( buyequip, "Show equipment buy menu" )
  53. {
  54. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  55. if( pPlayer && pPlayer->m_lifeState == LIFE_ALIVE && pPlayer->State_Get() == STATE_ACTIVE )
  56. {
  57. if( !pPlayer->IsInBuyZone() )
  58. {
  59. internalCenterPrint->Print( "#Cstrike_NotInBuyZone" );
  60. }
  61. else if( CSGameRules()->IsBuyTimeElapsed() )
  62. {
  63. char strBuyTime[16];
  64. Q_snprintf( strBuyTime, sizeof( strBuyTime ), "%d", (int)CSGameRules()->GetBuyTimeLength() );
  65. wchar_t buffer[128];
  66. wchar_t buytime[16];
  67. g_pVGuiLocalize->ConvertANSIToUnicode( strBuyTime, buytime, sizeof(buytime) );
  68. g_pVGuiLocalize->ConstructString( buffer, sizeof(buffer), g_pVGuiLocalize->Find("#Cstrike_TitlesTXT_Cant_buy"), 1, buytime );
  69. internalCenterPrint->Print( buffer );
  70. }
  71. else
  72. {
  73. if( pPlayer->GetTeamNumber() == TEAM_CT )
  74. {
  75. OpenPanelWithCheck( PANEL_BUY_EQUIP_CT, PANEL_BUY_CT );
  76. }
  77. else if( pPlayer->GetTeamNumber() == TEAM_TERRORIST )
  78. {
  79. OpenPanelWithCheck( PANEL_BUY_EQUIP_TER, PANEL_BUY_TER );
  80. }
  81. }
  82. }
  83. }
  84. CON_COMMAND( buymenu, "Show main buy menu" )
  85. {
  86. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  87. if( pPlayer )
  88. {
  89. if ( pPlayer->m_lifeState != LIFE_ALIVE && pPlayer->State_Get() != STATE_ACTIVE )
  90. return;
  91. if( !pPlayer->IsInBuyZone() )
  92. {
  93. internalCenterPrint->Print( "#Cstrike_NotInBuyZone" );
  94. }
  95. else if( CSGameRules()->IsBuyTimeElapsed() )
  96. {
  97. char strBuyTime[16];
  98. Q_snprintf( strBuyTime, sizeof( strBuyTime ), "%d", (int)CSGameRules()->GetBuyTimeLength() );
  99. wchar_t buffer[128];
  100. wchar_t buytime[16];
  101. g_pVGuiLocalize->ConvertANSIToUnicode( strBuyTime, buytime, sizeof(buytime) );
  102. g_pVGuiLocalize->ConstructString( buffer, sizeof(buffer), g_pVGuiLocalize->Find("#Cstrike_TitlesTXT_Cant_buy"), 1, buytime );
  103. internalCenterPrint->Print( buffer );
  104. }
  105. else
  106. {
  107. if( pPlayer->GetTeamNumber() == TEAM_CT )
  108. {
  109. OpenPanelWithCheck( PANEL_BUY_CT, PANEL_BUY_EQUIP_CT );
  110. }
  111. else if( pPlayer->GetTeamNumber() == TEAM_TERRORIST )
  112. {
  113. OpenPanelWithCheck( PANEL_BUY_TER, PANEL_BUY_EQUIP_TER );
  114. }
  115. }
  116. }
  117. }
  118. CON_COMMAND( chooseteam, "Choose a new team" )
  119. {
  120. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  121. if ( pPlayer && pPlayer->CanShowTeamMenu() )
  122. {
  123. gViewPortInterface->ShowPanel( PANEL_TEAM, true );
  124. }
  125. }
  126. CON_COMMAND_F( spec_help, "Show spectator help screen", FCVAR_CLIENTCMD_CAN_EXECUTE)
  127. {
  128. if ( gViewPortInterface )
  129. gViewPortInterface->ShowPanel( PANEL_INFO, true );
  130. }
  131. CON_COMMAND_F( spec_menu, "Activates spectator menu", FCVAR_CLIENTCMD_CAN_EXECUTE)
  132. {
  133. bool bShowIt = true;
  134. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  135. if ( pPlayer && !pPlayer->IsObserver() )
  136. return;
  137. if ( args.ArgC() == 2 )
  138. {
  139. bShowIt = atoi( args[ 1 ] ) == 1;
  140. }
  141. if ( gViewPortInterface )
  142. gViewPortInterface->ShowPanel( PANEL_SPECMENU, bShowIt );
  143. }
  144. CON_COMMAND_F( togglescores, "Toggles score panel", FCVAR_CLIENTCMD_CAN_EXECUTE)
  145. {
  146. if ( !gViewPortInterface )
  147. return;
  148. IViewPortPanel *scoreboard = gViewPortInterface->FindPanelByName( PANEL_SCOREBOARD );
  149. if ( !scoreboard )
  150. return;
  151. if ( scoreboard->IsVisible() )
  152. {
  153. gViewPortInterface->ShowPanel( scoreboard, false );
  154. GetClientVoiceMgr()->StopSquelchMode();
  155. }
  156. else
  157. {
  158. gViewPortInterface->ShowPanel( scoreboard, true );
  159. }
  160. }
  161. //-----------------------------------------------------------------------------
  162. // Purpose: called when the VGUI subsystem starts up
  163. // Creates the sub panels and initialises them
  164. //-----------------------------------------------------------------------------
  165. void CounterStrikeViewport::Start( IGameUIFuncs *pGameUIFuncs, IGameEventManager2 * pGameEventManager )
  166. {
  167. BaseClass::Start( pGameUIFuncs, pGameEventManager );
  168. }
  169. void CounterStrikeViewport::ApplySchemeSettings( vgui::IScheme *pScheme )
  170. {
  171. BaseClass::ApplySchemeSettings( pScheme );
  172. gHUD.InitColors( pScheme );
  173. SetPaintBackgroundEnabled( false );
  174. }
  175. IViewPortPanel* CounterStrikeViewport::CreatePanelByName(const char *szPanelName)
  176. {
  177. IViewPortPanel* newpanel = NULL;
  178. // overwrite MOD specific panel creation
  179. if ( Q_strcmp(PANEL_SCOREBOARD, szPanelName) == 0)
  180. {
  181. newpanel = new CCSClientScoreBoardDialog( this );
  182. }
  183. else if ( Q_strcmp(PANEL_SPECGUI, szPanelName) == 0 )
  184. {
  185. newpanel = new CCSSpectatorGUI( this );
  186. }
  187. else if ( Q_strcmp(PANEL_CLASS_CT, szPanelName) == 0 )
  188. {
  189. newpanel = new CClassMenu_CT( this );
  190. }
  191. else if ( Q_strcmp(PANEL_CLASS_TER, szPanelName) == 0 )
  192. {
  193. newpanel = new CClassMenu_TER( this );
  194. }
  195. else if ( Q_strcmp(PANEL_BUY_CT, szPanelName) == 0 )
  196. {
  197. newpanel = new CCSBuyMenu_CT( this );
  198. }
  199. else if ( Q_strcmp(PANEL_BUY_TER, szPanelName) == 0 )
  200. {
  201. newpanel = new CCSBuyMenu_TER( this );
  202. }
  203. else if ( Q_strcmp(PANEL_BUY_EQUIP_CT, szPanelName) == 0 )
  204. {
  205. newpanel = new CCSBuyEquipMenu_CT( this );
  206. }
  207. else if ( Q_strcmp(PANEL_BUY_EQUIP_TER, szPanelName) == 0 )
  208. {
  209. newpanel = new CCSBuyEquipMenu_TER( this );
  210. }
  211. else if ( Q_strcmp(PANEL_TEAM, szPanelName) == 0 )
  212. {
  213. newpanel = new CCSTeamMenu( this );
  214. }
  215. else if ( Q_strcmp(PANEL_INFO, szPanelName) == 0 )
  216. {
  217. newpanel = new CCSTextWindow( this );
  218. }
  219. else
  220. {
  221. // create a generic base panel, don't add twice
  222. newpanel = BaseClass::CreatePanelByName( szPanelName );
  223. }
  224. return newpanel;
  225. }
  226. void CounterStrikeViewport::CreateDefaultPanels( void )
  227. {
  228. AddNewPanel( CreatePanelByName( PANEL_TEAM ), "PANEL_TEAM" );
  229. AddNewPanel( CreatePanelByName( PANEL_CLASS_CT ), "PANEL_CLASS_CT" );
  230. AddNewPanel( CreatePanelByName( PANEL_CLASS_TER ), "PANEL_CLASS_TER" );
  231. AddNewPanel( CreatePanelByName( PANEL_BUY_CT ), "PANEL_BUY_CT" );
  232. AddNewPanel( CreatePanelByName( PANEL_BUY_TER ), "PANEL_BUY_TER" );
  233. AddNewPanel( CreatePanelByName( PANEL_BUY_EQUIP_CT ), "PANEL_BUY_EQUIP_CT" );
  234. AddNewPanel( CreatePanelByName( PANEL_BUY_EQUIP_TER ), "PANEL_BUY_EQUIP_TER" );
  235. BaseClass::CreateDefaultPanels();
  236. }
  237. int CounterStrikeViewport::GetDeathMessageStartHeight( void )
  238. {
  239. int x = YRES(2);
  240. if ( g_pSpectatorGUI && g_pSpectatorGUI->IsVisible() )
  241. {
  242. x += g_pSpectatorGUI->GetTopBarHeight();
  243. }
  244. return x;
  245. }
  246. /*
  247. ==========================
  248. HUD_ChatInputPosition
  249. Sets the location of the input for chat text
  250. ==========================
  251. */
  252. //MIKETODO: positioning of chat text (and other engine output)
  253. /*
  254. #include "Exports.h"
  255. void CL_DLLEXPORT HUD_ChatInputPosition( int *x, int *y )
  256. {
  257. RecClChatInputPosition( x, y );
  258. if ( gViewPortInterface )
  259. {
  260. gViewPortInterface->ChatInputPosition( x, y );
  261. }
  262. }
  263. EXPOSE_SINGLE_INTERFACE(CounterStrikeViewport, IClientVGUI, CLIENTVGUI_INTERFACE_VERSION);
  264. */