summaryrefslogtreecommitdiff
path: root/gameui/matchmaking/basedialog.cpp
blob: be65718b995286cbaeea194f05a21ab38aaef4b4 (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
285
286
287
288
289
290
291
292
293
294
295
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: All matchmaking dialogs inherit from this
//
//=============================================================================//

#include "vgui_controls/Label.h"
#include "GameUI_Interface.h"
#include "KeyValues.h"
#include "basedialog.h"
#include "BasePanel.h"
#include "matchmakingbasepanel.h"

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

//---------------------------------------------------------
// CBaseDialog
//---------------------------------------------------------
CBaseDialog::CBaseDialog( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
{
	SetTitleBarVisible( false );
	SetCloseButtonVisible( false );
	SetSizeable( false );

	m_pParent = pParent;
	m_Menu.SetParent( this );

	m_pTitle = new vgui::Label( this, "DialogTitle", "" );
	m_pFooterInfo = NULL;
	
	m_nBorderWidth = 0;
	m_nButtonGap = -1;
}

CBaseDialog::~CBaseDialog()
{
	delete m_pTitle;

	if ( m_pFooterInfo )
	{
		m_pFooterInfo->deleteThis();
	}
}

//---------------------------------------------------------
// Purpose: Activate the dialog
//---------------------------------------------------------
void CBaseDialog::Activate( void )
{
	BaseClass::Activate();

	InvalidateLayout( false, false );
}

//---------------------------------------------------------
// Purpose: Set the title and menu positions
//---------------------------------------------------------
void CBaseDialog::PerformLayout( void )
{
	BaseClass::PerformLayout();

	m_pTitle->SizeToContents();

	int menux, menuy;
	m_Menu.GetPos( menux, menuy );

	int autoWide = m_Menu.GetWide() + m_nBorderWidth * 2;
	int autoTall = menuy + m_Menu.GetTall() + m_nBorderWidth;
	autoWide = max( autoWide, GetWide() );
	autoTall = max( autoTall, GetTall() );

	SetSize( autoWide, autoTall );

	if ( m_pFooterInfo && m_pParent )
	{
		CMatchmakingBasePanel *pBasePanel = dynamic_cast< CMatchmakingBasePanel* >( m_pParent );
		if ( pBasePanel )
		{
			// the base panel is our parent
			pBasePanel->SetFooterButtons( this, m_pFooterInfo, m_nButtonGap );
		}
	}

	if ( m_Menu.GetActiveItemIndex() == -1 )
	{
		m_Menu.SetFocus( 0 );
	}
}

//---------------------------------------------------------
// Purpose: Setup sizes and positions
//---------------------------------------------------------
void CBaseDialog::ApplySettings( KeyValues *inResourceData )
{
	BaseClass::ApplySettings( inResourceData );

	m_nBorderWidth	= inResourceData->GetInt( "borderwidth", 0 );

	KeyValues *pFooter = inResourceData->FindKey( "Footer" );
	if ( pFooter )
	{
		m_pFooterInfo = pFooter->MakeCopy();
	}

	m_nButtonGap = inResourceData->GetInt( "footer_buttongap", -1 );
}

//---------------------------------------------------------
// Purpose: Setup colors and fonts
//---------------------------------------------------------
void CBaseDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
{
	BaseClass::ApplySchemeSettings( pScheme );

	SetPaintBackgroundType( 2 );

	m_pTitle->SetFgColor( pScheme->GetColor( "MatchmakingDialogTitleColor", Color( 200, 184, 151, 255 ) ) );

	char szResourceName[MAX_PATH];
	Q_snprintf( szResourceName, sizeof( szResourceName ), "%s.res", GetName() );
	KeyValues *pKeys = BasePanel()->GetConsoleControlSettings()->FindKey( szResourceName );
	LoadControlSettings( "NULL", NULL, pKeys );
}

//-----------------------------------------------------------------
// Purpose: Set the resource file to load this dialog's settings
//-----------------------------------------------------------------
void CBaseDialog::OnClose()
{
	// Hide the rather ugly fade out
	SetAlpha( 0 );
	BaseClass::OnClose();
}

//-----------------------------------------------------------------
// Purpose: Change properties of a menu item
//-----------------------------------------------------------------
void CBaseDialog::OverrideMenuItem( KeyValues *pKeys )
{
	// Do nothing
}

//-----------------------------------------------------------------
// Purpose: Swap the order of two menu items
//-----------------------------------------------------------------
void CBaseDialog::SwapMenuItems( int iOne, int iTwo )
{
	// Do nothing
}

//-----------------------------------------------------------------
// Purpose: Send key presses to the dialog's menu
//-----------------------------------------------------------------
void CBaseDialog::OnKeyCodePressed( vgui::KeyCode code )
{
	if ( code == KEY_XBUTTON_START )
	{
		m_KeyRepeat.Reset();
		if ( GameUI().IsInLevel() )
		{
			m_pParent->OnCommand( "ResumeGame" );
		}
		return;
	}

	m_KeyRepeat.KeyDown( code );

	// Send down to the menu
	if ( !m_Menu.HandleKeyCode( code ) )
	{
		if ( code == KEY_XBUTTON_B )
		{
			OnCommand( "DialogClosing" );
			SetDeleteSelfOnClose( true );
		}
		else
		{
			BaseClass::OnKeyCodePressed( code );
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseDialog::OnKeyCodeReleased( vgui::KeyCode code )
{
	m_KeyRepeat.KeyUp( code );

	BaseClass::OnKeyCodeReleased( code );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseDialog::HandleKeyRepeated( vgui::KeyCode code )
{
	m_Menu.HandleKeyCode( code );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseDialog::OnThink()
{
	vgui::KeyCode code = m_KeyRepeat.KeyRepeated();
	if ( code )
	{
		if ( HasFocus() )
		{
			HandleKeyRepeated( code );
		}
		else
		{
			// This can happen because of the slight delay after selecting a 
			// menu option and the resulting action. The selection caused the
			// key repeater to be reset, but the player can press a movement
			// key before the action occurs, leaving us with a key repeating
			// on this dialog even though it no longer has focus.
			m_KeyRepeat.Reset();
		}
	}

	BaseClass::OnThink();
}

//-----------------------------------------------------------------
// Purpose: Forward commands to the matchmaking base panel
//-----------------------------------------------------------------
void CBaseDialog::OnCommand( const char *pCommand )
{
	m_KeyRepeat.Reset();
	m_pParent->OnCommand( pCommand );
}


//---------------------------------------------------------------------
// Helper object to display the map picture and descriptive text
//---------------------------------------------------------------------
CScenarioInfoPanel::CScenarioInfoPanel( vgui::Panel *parent, const char *pName ) : BaseClass( parent, pName )
{
	m_pMapImage = new vgui::ImagePanel( this, "MapImage" );
	m_pTitle = new CPropertyLabel( this, "Title", "" );
	m_pSubtitle = new CPropertyLabel( this, "Subtitle", "" );

	m_pDescOne = new CPropertyLabel( this, "DescOne", "" );
	m_pDescTwo = new CPropertyLabel( this, "DescTwo", "" );
	m_pDescThree = new CPropertyLabel( this, "DescThree", "" );

	m_pValueTwo = new CPropertyLabel( this, "ValueTwo", "" );
	m_pValueThree = new CPropertyLabel( this, "ValueThree", "" );
}
CScenarioInfoPanel::~CScenarioInfoPanel()
{
	delete m_pMapImage;
	delete m_pTitle;
	delete m_pSubtitle;
	delete m_pDescOne;
	delete m_pDescTwo;
	delete m_pDescThree;
	delete m_pValueTwo;
	delete m_pValueThree;
}

void CScenarioInfoPanel::PerformLayout( void )
{
	BaseClass::PerformLayout();
}

void CScenarioInfoPanel::ApplySettings( KeyValues *pResourceData )
{
	BaseClass::ApplySettings( pResourceData );
}

void CScenarioInfoPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
	BaseClass::ApplySchemeSettings( pScheme );

	Color fontColor = pScheme->GetColor( "MatchmakingDialogTitleColor", Color( 0, 0, 0, 255 ) );
	m_pTitle->SetFgColor( fontColor );
	m_pSubtitle->SetFgColor( fontColor );
	m_pDescOne->SetFgColor( fontColor );
	m_pDescTwo->SetFgColor( fontColor );
	m_pDescThree->SetFgColor( fontColor );
	m_pValueTwo->SetFgColor( fontColor );
	m_pValueThree->SetFgColor( fontColor );

	SetPaintBackgroundType( 2 );

	KeyValues *pKeys = BasePanel()->GetConsoleControlSettings()->FindKey( "ScenarioInfoPanel.res" );
	ApplySettings( pKeys );
}

DECLARE_BUILD_FACTORY( CScenarioInfoPanel );