summaryrefslogtreecommitdiff
path: root/game/client/dod/dod_hud_restartround.cpp
blob: 5d50f7310089ed2abcab1526000fc4bec2eef531 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#include "cbase.h"
#include "hud.h"
#include "hudelement.h"
#include "hud_macros.h"
#include "iclientmode.h"
#include "vgui_controls/AnimationController.h"
#include "vgui_controls/Label.h"
#include "vgui/ILocalize.h"
#include "vgui/ISurface.h"
#include "text_message.h"
#include "dod_gamerules.h"

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

//-----------------------------------------------------------------------------
// Purpose: Displays current ammunition level
//-----------------------------------------------------------------------------
class CDODRestartRoundLabel : public vgui::Panel, public CHudElement
{
	DECLARE_CLASS_SIMPLE( CDODRestartRoundLabel, vgui::Panel );

public:
	CDODRestartRoundLabel( const char *pElementName );
	virtual void Reset();

	virtual void PerformLayout();

protected:
	virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
	virtual void OnThink();

private:
	vgui::HFont m_hFont;
	Color		m_bgColor;

	vgui::Label *m_pRestartLabel;	// "Round will restart in 0:00"

	vgui::Label *m_pBackground;

	CPanelAnimationVarAliasType( int, m_iTextX, "text_xpos", "8", "proportional_int" );
	CPanelAnimationVarAliasType( int, m_iTextY, "text_ypos", "8", "proportional_int" );

	float m_flLastRestartTime;
};

DECLARE_HUDELEMENT( CDODRestartRoundLabel );

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CDODRestartRoundLabel::CDODRestartRoundLabel( const char *pElementName ) : BaseClass(NULL, "RestartRoundLabel"), CHudElement( pElementName )
{
	vgui::Panel *pParent = g_pClientMode->GetViewport();
	SetParent( pParent );
	SetVisible( false );
	SetAlpha( 0 );

	m_pBackground = new vgui::Label( this, "Background", "" );

	wchar_t labelText[128];
	g_pVGuiLocalize->ConstructString( labelText, sizeof(labelText), g_pVGuiLocalize->Find( "#clan_game_restart" ), 2, L"0", L"00" );

	m_pRestartLabel = new vgui::Label( this, "restartroundlabel", labelText );
	m_pRestartLabel->SetPaintBackgroundEnabled( false );
	m_pRestartLabel->SetPaintBorderEnabled( false );
	m_pRestartLabel->SizeToContents();
	m_pRestartLabel->SetContentAlignment( vgui::Label::a_west );
	m_pRestartLabel->SetFgColor( GetFgColor() );

	m_flLastRestartTime = 0;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDODRestartRoundLabel::Reset()
{
	g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "RestartRoundLabelHide" );

	m_flLastRestartTime = 0;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDODRestartRoundLabel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
	BaseClass::ApplySchemeSettings( pScheme );

	SetFgColor( Color(0,0,0,0) );
	m_hFont = pScheme->GetFont( "HudHintText", true );

	m_pBackground->SetBgColor( GetSchemeColor("HintMessageBg", pScheme) );
	m_pBackground->SetPaintBackgroundType( 2 );

	SetAlpha( 0 );
}

//-----------------------------------------------------------------------------
// Purpose: Resizes the label
//-----------------------------------------------------------------------------
void CDODRestartRoundLabel::PerformLayout()
{
	BaseClass::PerformLayout();

	int wide, tall;
	GetSize( wide, tall );

	// find the widest line
	int labelWide = m_pRestartLabel->GetWide();

	// find the total height
	int fontTall = vgui::surface()->GetFontTall( m_hFont );
	int labelTall = fontTall;

	labelWide += m_iTextX*2;
	labelTall += m_iTextY*2;

	m_pBackground->SetBounds( 0, 0, labelWide, labelTall );

	int xOffset = (labelWide - m_pRestartLabel->GetWide())/2;
	m_pRestartLabel->SetPos( 0 + xOffset, 0 + m_iTextY );
}

//-----------------------------------------------------------------------------
// Purpose: Updates the label color each frame
//-----------------------------------------------------------------------------
void CDODRestartRoundLabel::OnThink()
{
	float flRoundRestartTime = DODGameRules()->GetRoundRestartTime();

	if( flRoundRestartTime != m_flLastRestartTime )
	{
		if( flRoundRestartTime > 0 )
		{
			g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "RestartRoundLabelShow" );
		}
		m_flLastRestartTime = flRoundRestartTime;
	}

	if( GetAlpha() > 0 )
	{
		wchar_t minutes[4];
		wchar_t seconds[4];

		int iSecondsRemaining = (int)( flRoundRestartTime - gpGlobals->curtime );

		iSecondsRemaining = MAX( 0, iSecondsRemaining );

		_snwprintf ( minutes, sizeof(minutes)/sizeof(wchar_t), L"%d", (iSecondsRemaining / 60) );
		_snwprintf ( seconds, sizeof(seconds)/sizeof(wchar_t), L"%02d", (iSecondsRemaining % 60) );

		wchar_t labelText[128];
		g_pVGuiLocalize->ConstructString( labelText, sizeof(labelText), g_pVGuiLocalize->Find( "#clan_game_restart" ), 2, minutes, seconds );

		m_pRestartLabel->SetText( labelText );
		m_pRestartLabel->SizeToContents();
		//InvalidateLayout();
	}

	m_pBackground->SetFgColor(GetFgColor());
	m_pRestartLabel->SetFgColor(GetFgColor());
}