summaryrefslogtreecommitdiff
path: root/game/client/tf/tf_hud_arena_notification.cpp
blob: eef39faa3a50f28bf4a7abcaf3e8aa69f05bbbc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================

#include "cbase.h"
#include "hud.h"
#include "hudelement.h"
#include "c_tf_player.h"
#include "iclientmode.h"
#include "ienginevgui.h"
#include <vgui/ILocalize.h>
#include <vgui/ISurface.h>
#include <vgui/IVGui.h>
#include <vgui_controls/Label.h>
#include <vgui_controls/EditablePanel.h>
#include "tf_imagepanel.h"
#include "tf_gamerules.h"
#include "c_tf_team.h"
#include "tf_hud_freezepanel.h"
#include "tf_hud_teamswitch.h"
#include "hud_chat.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

using namespace vgui;

extern ConVar tf_arena_preround_time;

#define TF_ARENA_NOTIFICATION_HIDETIME tf_arena_preround_time.GetFloat();

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class CHudArenaNotification : public CHudElement, public EditablePanel
{
	DECLARE_CLASS_SIMPLE( CHudArenaNotification, EditablePanel );

public:
	CHudArenaNotification( const char *pElementName );

	virtual void	Init( void );
	virtual void	OnTick( void );
	virtual void	LevelInit( void );
	virtual void	ApplySchemeSettings( IScheme *scheme );
	virtual bool	ShouldDraw( void );
	virtual void	SetVisible( bool state );

	virtual void	FireGameEvent( IGameEvent * event );
	void			SetupSwitchPanel( int iNotification );

private:
	Label			*m_pBalanceLabel;
	float			m_flHideAt;
	CHudTeamSwitch		*m_pTeamSwitchPanel;
};

DECLARE_HUDELEMENT( CHudArenaNotification );

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CHudArenaNotification::CHudArenaNotification( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudArenaNotification" )
{
	Panel *pParent = g_pClientMode->GetViewport();
	SetParent( pParent );

	SetHiddenBits( HIDEHUD_MISCSTATUS );

	m_flHideAt = 0;
	vgui::ivgui()->AddTickSignal( GetVPanel(), 100 );
	m_pTeamSwitchPanel = NULL;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHudArenaNotification::Init( void )
{
	// listen for events
	ListenForGameEvent( "arena_player_notification" );
	ListenForGameEvent( "arena_match_maxstreak" );
	ListenForGameEvent( "arena_round_start" );

	SetVisible( false );
	CHudElement::Init();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHudArenaNotification::FireGameEvent( IGameEvent * event )
{
	const char *pEventName = event->GetName();

	if ( Q_strcmp( "arena_player_notification", pEventName ) == 0 )
	{
		int iPlayer = event->GetInt( "player" );
		int iNotification = event->GetInt( "message" );
		C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

		if ( pPlayer && iPlayer == pPlayer->entindex() )
		{
			SetupSwitchPanel( iNotification );
			m_flHideAt = gpGlobals->curtime + TF_ARENA_NOTIFICATION_HIDETIME;
			SetVisible( true );

			if ( m_pTeamSwitchPanel == NULL )
			{
				m_pTeamSwitchPanel = GET_HUDELEMENT( CHudTeamSwitch );
			}
		}
	}
	else if ( Q_strcmp( "arena_match_maxstreak", pEventName ) == 0 )
	{
		int iTeam = event->GetInt( "team" );
		int iStreak = event->GetInt( "streak" );

		C_TFTeam *pTeam = GetGlobalTFTeam( iTeam );

		if ( !pTeam )
			return;

		CBaseHudChat *hudChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat );

		wchar_t wStreak[6];
		_snwprintf( wStreak, ARRAYSIZE( wStreak ), L"%i", iStreak );

		wchar_t wszLocalized[100];
		g_pVGuiLocalize->ConstructString_safe( wszLocalized, g_pVGuiLocalize->Find( "#TF_Arena_MaxStreak" ), 2, pTeam->Get_Localized_Name(), wStreak );
		

		char szLocalized[100];
		g_pVGuiLocalize->ConvertUnicodeToANSI( wszLocalized, szLocalized, sizeof(szLocalized) );

		hudChat->ChatPrintf( 0, CHAT_FILTER_NONE, "%c%s", COLOR_NORMAL, szLocalized );
	}
	else if ( Q_strcmp( "arena_round_start", pEventName ) == 0 )
	{
		C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

		if ( pPlayer )
		{
			pPlayer->EmitSound( "Ambient.Siren" );
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  :  - 
//-----------------------------------------------------------------------------
void CHudArenaNotification::OnTick( void )
{
	if ( IsVisible() == true )
	{
		if ( m_flHideAt == 9999  )
		{
			C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

			if ( pPlayer && pPlayer->GetTeamNumber() > LAST_SHARED_TEAM )
			{
				if ( tf_arena_use_queue.GetBool() || TFGameRules()->State_Get() != GR_STATE_PREGAME )
				{
					m_flHideAt = 0.1f;
				}
			}
		}

		if ( ( m_flHideAt && m_flHideAt < gpGlobals->curtime ) || ( m_pTeamSwitchPanel && m_pTeamSwitchPanel->ShouldDraw() == true ) || TFGameRules()->InStalemate() == true || TFGameRules()->IsInArenaMode() == false )
		{
			SetVisible( false );
			m_flHideAt = 0;
		}
	}
	else
	{
		if ( TFGameRules() && TFGameRules()->IsInArenaMode() == true )
		{
			if ( TFGameRules()->State_Get() == GR_STATE_PREGAME )
			{
				SetupSwitchPanel( TF_ARENA_NOTIFICATION_NOPLAYERS );
				m_flHideAt = 9999;
				SetVisible( true );
			}
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHudArenaNotification::SetVisible( bool state )
{
	int iRenderGroup = gHUD.LookupRenderGroupIndexByName( "arena_target_id" );

	if ( state == true )
	{
		gHUD.LockRenderGroup( iRenderGroup );
	}
	else
	{
		gHUD.UnlockRenderGroup( iRenderGroup );
	}

	BaseClass::SetVisible( state );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHudArenaNotification::LevelInit( void )
{
	m_flHideAt = 0;
	SetVisible( false );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CHudArenaNotification::ShouldDraw( void )
{
	return ( IsVisible() );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHudArenaNotification::ApplySchemeSettings( IScheme *pScheme )
{
	// load control settings...
	LoadControlSettings( "resource/UI/HudArenaNotification.res" );

	BaseClass::ApplySchemeSettings( pScheme );

	m_pBalanceLabel = dynamic_cast<Label *>( FindChildByName("BalanceLabel") );

	SetVisible( false );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHudArenaNotification::SetupSwitchPanel( int iNotification )
{
	if ( m_pBalanceLabel )
	{
		SetDialogVariable( "notificationtip", g_pVGuiLocalize->Find( "#TF_Arena_ProTip" ) );

		if ( iNotification == TF_ARENA_NOTIFICATION_CAREFUL )
		{
			m_pBalanceLabel->SetText( g_pVGuiLocalize->Find( "#TF_Arena_Careful" ) );
		}
		else if ( iNotification == TF_ARENA_NOTIFICATION_SITOUT )
		{
			m_pBalanceLabel->SetText( g_pVGuiLocalize->Find( "#TF_Arena_SitOut" ) );
		}
		else if ( iNotification == TF_ARENA_NOTIFICATION_NOPLAYERS )
		{
			m_pBalanceLabel->SetText( g_pVGuiLocalize->Find( "#TF_Arena_Welcome" ) );
			SetDialogVariable( "notificationtip", g_pVGuiLocalize->Find( "#TF_Arena_NoPlayers" ) );
		}
	}
}

//----------------------------------------------------------------------------------------------------------------
// Receive the PlayerIgnitedInv user message and send out a clientside event for achievements to hook.
void __MsgFunc_HudArenaNotify( bf_read &msg )
{
	int iPlayerIndex = (int) msg.ReadByte();
	int iNotification = (int) msg.ReadByte();

	IGameEvent *event = gameeventmanager->CreateEvent( "arena_player_notification" );

	if ( event )
	{
		event->SetInt( "player", iPlayerIndex );
		event->SetInt( "message", iNotification );
		gameeventmanager->FireEventClientSide( event );
	}
}