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.

405 lines
10 KiB

  1. //========= Copyright � 1996-2005, 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. // vgui panel includes
  15. #include <vgui_controls/Panel.h>
  16. #include <vgui/ISurface.h>
  17. #include <keyvalues.h>
  18. #include <vgui/Cursor.h>
  19. #include <vgui/IScheme.h>
  20. #include <vgui/IVGui.h>
  21. #include <vgui/ILocalize.h>
  22. #include <vgui/vgui.h>
  23. // client dll/engine defines
  24. #include "hud.h"
  25. #include <voice_status.h>
  26. // cstrike specific dialogs
  27. #include "clientmode_csnormal.h"
  28. #include "IGameUIFuncs.h"
  29. // viewport definitions
  30. #include <baseviewport.h>
  31. #include "counterstrikeviewport.h"
  32. #include "cs_gamerules.h"
  33. // #include "c_user_message_register.h"
  34. #include "vguicenterprint.h"
  35. #include "text_message.h"
  36. #include "teammenu_scaleform.h"
  37. #include "chooseclass_scaleform.h"
  38. #include "Scaleform/HUD/sfhudinfopanel.h"
  39. #include "Scaleform/HUD/sfhudwinpanel.h"
  40. #include "Scaleform/loadingscreen_scaleform.h"
  41. #if defined( CSTRIKE15 )
  42. #include "basepanel.h"
  43. #endif
  44. static void OpenPanelWithCheck( const char *panelToOpen, const char *panelToCheck )
  45. {
  46. IViewPortPanel *checkPanel = GetViewPortInterface()->FindPanelByName( panelToCheck );
  47. if ( !checkPanel || !checkPanel->IsVisible() )
  48. {
  49. GetViewPortInterface()->ShowPanel( panelToOpen, true );
  50. }
  51. }
  52. void PrintBuyTimeOverMessage( void )
  53. {
  54. CHudElement *pElement = GetHud().FindElement( "SFHudInfoPanel" );
  55. if ( pElement )
  56. {
  57. char strBuyTime[16];
  58. int nBuyTime = ( int )CSGameRules()->GetBuyTimeLength();
  59. Q_snprintf( strBuyTime, sizeof( strBuyTime ), "%d", nBuyTime );
  60. wchar_t buffer[128];
  61. wchar_t buytime[16];
  62. g_pVGuiLocalize->ConvertANSIToUnicode( strBuyTime, buytime, sizeof( buytime ) );
  63. if ( nBuyTime == 0 )
  64. g_pVGuiLocalize->ConstructString( buffer, sizeof( buffer ), g_pVGuiLocalize->Find( "#SFUI_BuyMenu_YoureOutOfTime" ), 0 );
  65. else
  66. g_pVGuiLocalize->ConstructString( buffer, sizeof( buffer ), g_pVGuiLocalize->Find( "#SFUI_BuyMenu_OutOfTime" ), 1, buytime );
  67. ((SFHudInfoPanel *)pElement)->SetPriorityText( buffer );
  68. }
  69. }
  70. CON_COMMAND_F( teammenu, "Show team selection window", FCVAR_SERVER_CAN_EXECUTE )
  71. {
  72. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  73. if( pPlayer && pPlayer->CanShowTeamMenu() )
  74. {
  75. ( ( CounterStrikeViewport * )GetViewPortInterface() )->SetChoseTeamAndClass( true );
  76. GetViewPortInterface()->ShowPanel( PANEL_TEAM, true );
  77. }
  78. }
  79. CON_COMMAND_F( buymenu, "Show or hide main buy menu", FCVAR_SERVER_CAN_EXECUTE )
  80. {
  81. bool bShowIt = true;
  82. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  83. if ( args.ArgC() == 2 )
  84. {
  85. bShowIt = atoi( args[ 1 ] ) == 1;
  86. }
  87. if( pPlayer && bShowIt )
  88. {
  89. if ( pPlayer->m_lifeState != LIFE_ALIVE && pPlayer->State_Get() != STATE_ACTIVE )
  90. return;
  91. extern ConVar mp_buy_anywhere;
  92. extern ConVar mp_buy_during_immunity;
  93. static ConVarRef sv_buy_status_override_ref( "sv_buy_status_override" );
  94. // UNUSED: int nGuardianTeam = CSGameRules()->IsHostageRescueMap() ? TEAM_TERRORIST : TEAM_CT;
  95. if ( CSGameRules()->IsPlayingCooperativeGametype() )
  96. {
  97. if ( CSGameRules()->IsWarmupPeriod() == false &&
  98. CSGameRules()->m_flGuardianBuyUntilTime < gpGlobals->curtime )
  99. {
  100. int nTeam = CSGameRules()->IsHostageRescueMap() ? TEAM_TERRORIST : TEAM_CT;
  101. int iBuyStatus = sv_buy_status_override_ref.GetInt();
  102. if ( iBuyStatus > 0 && (( nTeam == TEAM_CT && iBuyStatus != 1 ) || ( nTeam == TEAM_TERRORIST && iBuyStatus != 2 )) )
  103. GetCenterPrint()->Print( "#SFUI_BuyMenu_CantBuy" );
  104. else
  105. GetCenterPrint()->Print( "#SFUI_BuyMenu_CantBuyTilNextWave" );
  106. }
  107. else
  108. {
  109. CSGameRules()->OpenBuyMenu( pPlayer->GetUserID() );
  110. }
  111. }
  112. else if ( CSGameRules()->IsPlayingCoopMission() && sv_buy_status_override_ref.GetInt() == 3 )
  113. {
  114. GetCenterPrint()->Print( "#SFUI_BuyMenu_CantBuy" );
  115. }
  116. else if ( !pPlayer->IsInBuyPeriod() )
  117. {
  118. PrintBuyTimeOverMessage();
  119. }
  120. else if ( !pPlayer->IsInBuyZone() )
  121. {
  122. GetCenterPrint()->Print( "#SFUI_BuyMenu_NotInBuyZone" );
  123. }
  124. else
  125. {
  126. CSGameRules()->OpenBuyMenu( pPlayer->GetUserID() );
  127. }
  128. }
  129. else if( pPlayer && !bShowIt )
  130. {
  131. // Hide the menu
  132. CSGameRules()->CloseBuyMenu( pPlayer->GetUserID() );
  133. }
  134. }
  135. //CON_COMMAND_F( spec_help, "Show spectator help screen", FCVAR_CLIENTCMD_CAN_EXECUTE )
  136. //{
  137. // if ( GetViewPortInterface() )
  138. // GetViewPortInterface()->ShowPanel( PANEL_INFO, true );
  139. //}
  140. CON_COMMAND_F( spec_menu, "Activates spectator menu", FCVAR_CLIENTCMD_CAN_EXECUTE )
  141. {
  142. bool bShowIt = true;
  143. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  144. if ( pPlayer && !pPlayer->IsObserver() )
  145. return;
  146. if ( args.ArgC() == 2 )
  147. {
  148. bShowIt = atoi( args[ 1 ] ) == 1;
  149. }
  150. if ( GetViewPortInterface() )
  151. GetViewPortInterface()->ShowPanel( PANEL_SPECMENU, bShowIt );
  152. }
  153. CON_COMMAND_F( spec_gui, "Shows or hides the spectator bar", FCVAR_CLIENTCMD_CAN_EXECUTE )
  154. {
  155. bool bShowIt = true;
  156. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  157. if ( pPlayer && !pPlayer->IsObserver() )
  158. return;
  159. if ( args.ArgC() == 2 )
  160. {
  161. bShowIt = atoi( args[ 1 ] ) == 1;
  162. }
  163. if ( bShowIt && GetViewPortInterface() && GetViewPortInterface()->GetActivePanel() )
  164. {
  165. // if the team screen is up, it takes precedence - don't show the spectator GUI
  166. if ( !V_strcmp( GetViewPortInterface()->GetActivePanel()->GetName(), PANEL_TEAM ) )
  167. return;
  168. }
  169. if ( GetViewPortInterface() )
  170. GetViewPortInterface()->ShowPanel( PANEL_SPECGUI, bShowIt );
  171. }
  172. CON_COMMAND_F( togglescores, "Toggles score panel", FCVAR_CLIENTCMD_CAN_EXECUTE )
  173. {
  174. if ( !GetViewPortInterface() )
  175. return;
  176. IViewPortPanel *scoreboard = GetViewPortInterface()->FindPanelByName( PANEL_SCOREBOARD );
  177. if ( !scoreboard )
  178. return;
  179. if ( scoreboard->IsVisible() )
  180. {
  181. GetViewPortInterface()->ShowPanel( scoreboard, false );
  182. GetClientVoiceMgr()->StopSquelchMode();
  183. }
  184. else
  185. {
  186. // Disallow bringing the Scoreboard up while we are paused
  187. if ( BasePanel() && BasePanel()->IsScaleformPauseMenuActive() )
  188. return;
  189. GetViewPortInterface()->ShowPanel( scoreboard, true );
  190. }
  191. }
  192. CON_COMMAND_F( hidescores, "Forcibly hide score panel", FCVAR_CLIENTCMD_CAN_EXECUTE )
  193. {
  194. if ( !GetViewPortInterface() )
  195. return;
  196. IViewPortPanel *scoreboard = GetViewPortInterface()->FindPanelByName( PANEL_SCOREBOARD );
  197. if ( !scoreboard )
  198. return;
  199. if ( scoreboard->IsVisible() )
  200. {
  201. GetViewPortInterface()->ShowPanel( scoreboard, false );
  202. GetClientVoiceMgr()->StopSquelchMode();
  203. }
  204. }
  205. //-----------------------------------------------------------------------------
  206. // Purpose: called when the VGUI subsystem starts up
  207. // Creates the sub panels and initialises them
  208. //-----------------------------------------------------------------------------
  209. void CounterStrikeViewport::Start( IGameUIFuncs *pGameUIFuncs, IGameEventManager2 * pGameEventManager )
  210. {
  211. BaseClass::Start( pGameUIFuncs, pGameEventManager );
  212. SetChoseTeamAndClass( false );
  213. }
  214. void CounterStrikeViewport::ApplySchemeSettings( vgui::IScheme *pScheme )
  215. {
  216. BaseClass::ApplySchemeSettings( pScheme );
  217. ListenForGameEvent( "cs_win_panel_match" );
  218. GetHud().InitColors( pScheme );
  219. SetPaintBackgroundEnabled( false );
  220. }
  221. IViewPortPanel* CounterStrikeViewport::CreatePanelByName( const char *szPanelName )
  222. {
  223. IViewPortPanel* newpanel = NULL;
  224. // overwrite MOD specific panel creation
  225. if ( Q_strcmp( PANEL_TEAM, szPanelName ) == 0 )
  226. {
  227. newpanel = new CCSTeamMenuScaleform( this );
  228. }
  229. else
  230. {
  231. // create a generic base panel, don't add twice
  232. newpanel = BaseClass::CreatePanelByName( szPanelName );
  233. }
  234. return newpanel;
  235. }
  236. void CounterStrikeViewport::CreateDefaultPanels( void )
  237. {
  238. AddNewPanel( CreatePanelByName( PANEL_TEAM ), "PANEL_TEAM" );
  239. AddNewPanel( CreatePanelByName( PANEL_BUY ), "PANEL_BUY" );
  240. BaseClass::CreateDefaultPanels();
  241. }
  242. int CounterStrikeViewport::GetDeathMessageStartHeight( void )
  243. {
  244. int x = YRES( 2 );
  245. return x;
  246. }
  247. void CounterStrikeViewport::FireGameEvent( IGameEvent * event )
  248. {
  249. const char * type = event->GetName();
  250. if ( Q_strcmp( type, "game_newmap" ) == 0 || Q_strcmp( type, "cs_win_panel_match" ) == 0 )
  251. {
  252. SetChoseTeamAndClass( false );
  253. }
  254. BaseClass::FireGameEvent( event );
  255. }
  256. void CounterStrikeViewport::UpdateAllPanels( void )
  257. {
  258. bool bSomethingIsVisible = false;
  259. ACTIVE_SPLITSCREEN_PLAYER_GUARD_VGUI( vgui::ipanel()->GetMessageContextId( GetVPanel() ) );
  260. for ( int i = 0; i < m_UnorderedPanels.Count(); ++i )
  261. {
  262. IViewPortPanel *p = m_UnorderedPanels[i];
  263. if ( p->IsVisible() )
  264. {
  265. bSomethingIsVisible = true;
  266. p->Update();
  267. if ( m_pActivePanel == NULL )
  268. {
  269. // if a visible panel exists, then there should be an activePanel.
  270. m_pActivePanel = p;
  271. }
  272. }
  273. }
  274. // see if we need to show a special ui instead of the hud
  275. // [jason] Do not rearrange viewport panels while the Pause menu is opened - it takes precedence over all viewports
  276. if ( !bSomethingIsVisible && !BasePanel()->IsScaleformPauseMenuActive() )
  277. {
  278. C_CSPlayer *pCSPlayer = C_CSPlayer::GetLocalCSPlayer();
  279. const char* UIToShow = NULL;
  280. if ( !pCSPlayer )
  281. {
  282. UIToShow = PANEL_SPECGUI;
  283. }
  284. else if ( pCSPlayer->GetObserverMode() != OBS_MODE_NONE )
  285. {
  286. if ( pCSPlayer->State_Get() != STATE_PICKINGTEAM && ( pCSPlayer->GetTeamNumber() == TEAM_UNASSIGNED ) && !pCSPlayer->IsHLTV() )
  287. {
  288. // not a member of a team and not a spectator. show the team select screen.
  289. if ( !CLoadingScreenScaleform::IsOpen() &&
  290. ( (GetActivePanel() && !V_strcmp( GetActivePanel()->GetName(), PANEL_TEAM )) || !GetActivePanel() ) )
  291. {
  292. // don't show the team panel if the team panel is already up
  293. UIToShow = PANEL_TEAM;
  294. }
  295. }
  296. else
  297. {
  298. SFHudWinPanel * pWinPanel = GET_HUDELEMENT( SFHudWinPanel );
  299. if ( pWinPanel && !pWinPanel->IsVisible() )
  300. {
  301. UIToShow = PANEL_SPECGUI;
  302. }
  303. }
  304. }
  305. if ( UIToShow )
  306. {
  307. ShowPanel( UIToShow, true );
  308. }
  309. }
  310. }
  311. /*
  312. ==========================
  313. HUD_ChatInputPosition
  314. Sets the location of the input for chat text
  315. ==========================
  316. */
  317. //MIKETODO: positioning of chat text ( and other engine output )
  318. /*
  319. #include "Exports.h"
  320. void CL_DLLEXPORT HUD_ChatInputPosition( int *x, int *y )
  321. {
  322. RecClChatInputPosition( x, y );
  323. if ( GetViewPortInterface() )
  324. {
  325. GetViewPortInterface()->ChatInputPosition( x, y );
  326. }
  327. }
  328. EXPOSE_SINGLE_INTERFACE( CounterStrikeViewport, IClientVGUI, CLIENTVGUI_INTERFACE_VERSION );
  329. */