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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_survey_questions.h"
#include "ienginevgui.h"
#include "tf_match_description.h"
#ifdef CLIENT_DLL
#include "tf_gc_client.h"
#include "vgui_controls/RadioButton.h"
#include "iclientmode.h"
#include <vgui_controls/AnimationController.h>
#include "game/client/iviewport.h"
#include "tf_hud_mainmenuoverride.h"
#include "tf_gamerules.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Purpose: Criteria function for competitive inquiry survey
// Only include casual matches
//-----------------------------------------------------------------------------
bool CompetitiveInquiry( const CMsgGC_Match_Result& msgMatchResult, uint32 nPlayerIndex )
{
const IMatchGroupDescription* pMatchDesc = GetMatchGroupDescription( (EMatchGroup) msgMatchResult.match_group() );
if ( pMatchDesc )
{
// Only show this in Casual 12v12
return pMatchDesc->m_eMatchGroup == k_nMatchGroup_Casual_12v12;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Criteria function for casual inquiry survey
// Only include competitive matches
//-----------------------------------------------------------------------------
bool CasualInquiry( const CMsgGC_Match_Result& msgMatchResult, uint32 nPlayerIndex )
{
const IMatchGroupDescription* pMatchDesc = GetMatchGroupDescription( ( EMatchGroup )msgMatchResult.match_group() );
if ( pMatchDesc )
{
// Only show this in Competitive 6v6
return pMatchDesc->m_eMatchGroup == k_nMatchGroup_Ladder_6v6;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: The actual definition of the survey questions
//-----------------------------------------------------------------------------
// Survey Enum Help Text String Weight Criteria Function Active
const SurveyQuestion_t g_SurveyQuestions[SurveyQuestionType_ARRAYSIZE] = { { QUESTION_MATCH_QUALITY, "MatchQuality", 1.f, NULL, true },
{ QUESTION_MAP_QUALITY, "MapQuality", 1.f, NULL, true },
{ QUESTION_COMP_INQUIRY, "CompetitiveInquiry", 1.f, &CompetitiveInquiry, true },
{ QUESTION_CASUAL_INQUIRY, "CasualInquiry", 1.f, &CasualInquiry, true } };
#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: Figure out which survey panel to make
//-----------------------------------------------------------------------------
CSurveyQuestionPanel* CreateSurveyQuestionPanel( Panel* pParent, const CMsgGCSurveyRequest& msgSurveyQuestion )
{
CSurveyQuestionPanel* pSurveyPanel = NULL;
Assert( msgSurveyQuestion.has_question_type() );
switch( msgSurveyQuestion.question_type() )
{
case QUESTION_MATCH_QUALITY:
pSurveyPanel = new CMatchQualitySurvey( pParent, msgSurveyQuestion );
break;
case QUESTION_MAP_QUALITY:
pSurveyPanel = new CMapQualitySurvey( pParent, msgSurveyQuestion );
break;
case QUESTION_COMP_INQUIRY:
pSurveyPanel = new CCompInquirySurvey( pParent, msgSurveyQuestion );
break;
case QUESTION_CASUAL_INQUIRY:
pSurveyPanel = new CCasualInquirySurvey( pParent, msgSurveyQuestion );
break;
default:
Assert( !"Unhandled survey question type!" );
}
return pSurveyPanel;
}
CSurveyQuestionPanel::CSurveyQuestionPanel( Panel* pParent, CMsgGCSurveyRequest msgSurveyQuestion )
: EditablePanel( pParent, "Survey" )
, m_msgRequest( msgSurveyQuestion )
, m_bResponded( false )
{
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ClientScheme.res", "ClientScheme");
SetScheme(scheme);
SetProportional( true );
ListenForGameEvent( "server_spawn" );
ListenForGameEvent( "client_disconnect" );
ListenForGameEvent( "client_beginconnect" );
}
CSurveyQuestionPanel::~CSurveyQuestionPanel()
{
if ( !m_bResponded )
{
GTFGCClientSystem()->SendSurveyResponse( SEEN_BUT_UNANSWERED_SURVEY_QUESTION );
m_bResponded = true;
}
GTFGCClientSystem()->ClearSurveyRequest();
}
void CSurveyQuestionPanel::OnCommand( const char *command )
{
if ( FStrEq( command, "close" ) )
{
if ( !m_bResponded )
{
GTFGCClientSystem()->SendSurveyResponse( SEEN_AND_DISMISSED_SURVEY_QUESTION );
m_bResponded = true;
}
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( GetParent(), "SurveyHideSequence", false );
return;
}
else if ( FStrEq( command, "submit" ) )
{
if ( !m_bResponded )
{
Submit();
m_bResponded = true;
}
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( GetParent(), "SurveySubmitSequence", false );
return;
}
else if ( FStrEq( command, "delete" ) )
{
MarkForDeletion();
return;
}
BaseClass::OnCommand( command );
}
void CSurveyQuestionPanel::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetProportional( true );
LoadControlSettings( GetResFile() );
InvalidateLayout( true );
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( GetParent(), "SurveyShowSequence", false );
}
void CSurveyQuestionPanel::FireGameEvent( IGameEvent *event )
{
const char *pEventName = event->GetName();
// They left/changed servers. Consider the survey abandoned
if ( !Q_stricmp( pEventName, "client_disconnect" ) ||
!Q_stricmp( pEventName, "client_beginconnect" ) ||
!Q_stricmp( pEventName, "server_spawn" ) )
{
MarkForDeletion();
}
}
CMultipleChoiceSurveyQuestionPanel::CMultipleChoiceSurveyQuestionPanel( Panel* pParent, CMsgGCSurveyRequest msgSurveyQuestion, uint16 nSurveyResponses )
: CSurveyQuestionPanel( pParent, msgSurveyQuestion )
{
m_nSurveyResponses = nSurveyResponses;
}
//-----------------------------------------------------------------------------
// Purpose: Get the labels under the radio buttons to highlight
//-----------------------------------------------------------------------------
void CMultipleChoiceSurveyQuestionPanel::Think()
{
// We need to be on top of absolutely everything. Clicking on another
// popup will move it on top of us, and that cannot be!
MoveToFront();
bool bAnySelected = false;
// Radio buttons aren't cool and can ONLY have their labels to the right.
// This panel has extra labels under the radio labels that we want to highlight
// so set the label's FG colors to the radio buttons FG colors.
for( int i = 0; i < m_nSurveyResponses; ++i )
{
RadioButton* pRadioButton = FindControl< RadioButton >( CFmtStr( "Radio%d", i ), true );
Panel* pRadioLabel = FindChildByName( CFmtStr( "Radio%dLabel", i ), true );
if ( pRadioButton && pRadioLabel )
{
pRadioLabel->SetFgColor( pRadioButton->GetFgColor() );
bAnySelected = bAnySelected || pRadioButton->IsSelected();
}
}
Panel* pSubmitButton = FindChildByName( "SubmitButton", true );
if ( pSubmitButton )
{
pSubmitButton->SetEnabled( bAnySelected );
}
}
void CMultipleChoiceSurveyQuestionPanel::Submit()
{
// Figure out which radio button is checked, and use that as our response
for( int i = 0; i < m_nSurveyResponses; ++i )
{
RadioButton* pRadioButton = FindControl< RadioButton >( CFmtStr( "Radio%d", i ), true );
if ( pRadioButton && pRadioButton->IsSelected() )
{
GTFGCClientSystem()->SendSurveyResponse( i );
return;
}
}
}
void CMapQualitySurvey::PerformLayout()
{
const MapDef_t* pMapDef = NULL;
if ( TFGameRules() )
{
pMapDef = GetItemSchema()->GetMasterMapDefByName ( TFGameRules()->MapName() );
}
else
{
pMapDef = GetItemSchema()->GetMasterMapDefByIndex( RandomInt( 1, GetItemSchema()->GetMapCount() - 1 ) );
}
Assert( pMapDef );
if ( !pMapDef )
return;
EditablePanel* pMapChoice = FindControl< EditablePanel >( "QuestionContainer", true );
if ( pMapChoice )
{
// Label text
pMapChoice->SetDialogVariable( "mapname", g_pVGuiLocalize->Find( pMapDef->pszMapNameLocKey ) );
}
}
#ifdef STAGING_ONLY
CON_COMMAND( test_survey, "Creates a test survey" )
{
if( args.ArgC() < 2 )
return;
int nDefIndex = atoi( args[1] );
if ( nDefIndex < 0 || nDefIndex >= SurveyQuestionType_ARRAYSIZE )
return;
CMsgGCSurveyRequest msgSurvey;
msgSurvey.set_match_id( 0 );
msgSurvey.set_question_type( (SurveyQuestionType)nDefIndex );
Panel* pSurvey = CreateSurveyQuestionPanel( NULL, msgSurvey );
IViewPortPanel *pMMOverride = ( gViewPortInterface->FindPanelByName( PANEL_MAINMENUOVERRIDE ) );
pSurvey->SetParent( (CHudMainMenuOverride*)pMMOverride );
}
#endif
#endif
|