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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Disconnect prompt to warn leavers of penalty they will incur
//
// $NoKeywords: $
//=============================================================================
#include "cbase.h"
#include "tf_hud_disconnect_prompt.h"
#include "econ_controls.h"
#include "tf_gc_client.h"
#include "tf_gamerules.h"
using namespace vgui;
CTFDisconnectConfirmDialog::CTFDisconnectConfirmDialog(
const char *pTitle,
const char *pTextKey,
const char *pConfirmBtnText,
const char *pCancelBtnText,
GenericConfirmDialogCallback callback,
vgui::Panel *pParent
) : CTFGenericConfirmDialog( pTitle, pTextKey, pConfirmBtnText, pCancelBtnText, callback, pParent )
{
m_eAbandonStatus = GTFGCClientSystem()->GetCurrentServerAbandonStatus();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const char *CTFDisconnectConfirmDialog::GetResFile()
{
switch ( m_eAbandonStatus )
{
case k_EAbandonGameStatus_Safe:
return "Resource/UI/econ/ConfirmDialogAbandonSafe.res";
case k_EAbandonGameStatus_AbandonWithoutPenalty:
return "Resource/UI/econ/ConfirmDialogAbandonNoPenalty.res";
case k_EAbandonGameStatus_AbandonWithPenalty:
return "Resource/UI/econ/ConfirmDialogAbandonPenalty.res";
}
return "Resource/UI/econ/ConfirmDialogOptOut.res";
}
void CTFDisconnectConfirmDialog::SetReason( eDisconnectReason reason )
{
m_eReason = reason;
}
void CTFDisconnectConfirmDialog::OnCommand( const char *command )
{
if( FStrEq( command, "confirm" ) )
{
// Check this before disconnecting
if ( GTFGCClientSystem()->BExitMatchmakingAfterDisconnect() )
{
GTFGCClientSystem()->EndMatchmaking( true );
}
engine->DisconnectInternal();
int nCount = m_confirmCommands.Count();
for( int i=0; i<nCount; ++i )
{
engine->ClientCmd_Unrestricted( m_confirmCommands[i] );
}
}
else if( FStrEq( command, "cancel" ) )
{
int nCount = m_cancelCommands.Count();
for( int i=0; i<nCount; ++i )
{
engine->ClientCmd_Unrestricted( m_cancelCommands[i] );
}
}
// This will clean us up if we get a cancel or confirm command
BaseClass::OnCommand( command );
}
void CTFDisconnectConfirmDialog::AddConfirmCommand( const char *command )
{
m_confirmCommands.AddToTail( command );
}
void CTFDisconnectConfirmDialog::AddCancelCommand( const char *command )
{
m_cancelCommands.AddToTail( command );
}
//
// Extern Helper to Build Dialog
CTFDisconnectConfirmDialog *BuildDisconnectConfirmDialog ()
{
EAbandonGameStatus eAbandonStatus = GTFGCClientSystem()->GetCurrentServerAbandonStatus();
const char* pszTitle = NULL;
const char* pszBody = NULL;
const char* pszConfirm = NULL;
switch ( eAbandonStatus )
{
case k_EAbandonGameStatus_Safe:
pszTitle = "#TF_MM_Disconnect_Title";
pszBody = "#TF_MM_Disconnect";
pszConfirm = "#TF_MM_Rejoin_Leave";
break;
case k_EAbandonGameStatus_AbandonWithoutPenalty:
pszTitle = "#TF_MM_Abandon_Title";
pszBody = "#TF_MM_Abandon_NoPenalty";
pszConfirm = "#TF_MM_Rejoin_Leave";
break;
case k_EAbandonGameStatus_AbandonWithPenalty:
pszTitle = "#TF_MM_Abandon_Title";
pszBody = ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() ) ? "TF_MM_Abandon_Ban" : "#TF_MM_Abandon";
pszConfirm = "#TF_MM_Rejoin_Abandon";
break;
}
CTFDisconnectConfirmDialog *pDialog = vgui::SETUP_PANEL( new CTFDisconnectConfirmDialog(
pszTitle,
pszBody,
pszConfirm,
"#TF_MM_Rejoin_Stay",
NULL,
NULL ) );
return pDialog;
}
// sent from quit and disconnect attempts
CON_COMMAND( cl_disconnect_prompt, "Prompt about disconnect" )
{
CTFDisconnectConfirmDialog *pDialog = vgui::SETUP_PANEL( new CTFDisconnectConfirmDialog( "#TF_MM_Abandon_Title",
"#TF_MM_Abandon",
"#TF_Coach_Yes",
"#TF_Coach_No",
NULL,
NULL ) );
if ( pDialog )
{
pDialog->Show();
}
}
bool HandleDisconnectAttempt()
{
// !FIXME! We could show different messages depending on the abandon status
if( engine->IsInGame() && GameRules() && GameRules()->ShouldConfirmOnDisconnect() &&
GTFGCClientSystem()->GetCurrentServerAbandonStatus() == k_EAbandonGameStatus_AbandonWithPenalty )
{
CTFDisconnectConfirmDialog *pDialog = vgui::SETUP_PANEL( new CTFDisconnectConfirmDialog( "#TF_MM_Abandon_Title",
"#TF_MM_Abandon",
"#TF_Coach_Yes",
"#TF_Coach_No",
NULL,
NULL ) );
if ( pDialog )
{
pDialog->Show();
}
// The disconnect was handled by us. Stop the engine from handling it.
return true;
}
// We're not changing the disconnect behavior in any way. Let the engine take care of it.
return false;
}
//-----------------------------------------------------------------------------
// CTFRejoinConfirmDialog
//-----------------------------------------------------------------------------
CTFRejoinConfirmDialog::CTFRejoinConfirmDialog(
const char *pTitle,
const char *pTextKey,
const char *pConfirmBtnText,
const char *pCancelBtnText,
GenericConfirmDialogCallback callback,
vgui::Panel *pParent
) : CTFGenericConfirmDialog( pTitle, pTextKey, pConfirmBtnText, pCancelBtnText, callback, pParent )
{
m_eAbandonStatus = GTFGCClientSystem()->GetAssignedMatchAbandonStatus();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const char *CTFRejoinConfirmDialog::GetResFile()
{
switch ( m_eAbandonStatus )
{
case k_EAbandonGameStatus_Safe:
return "Resource/UI/econ/ConfirmDialogAbandonSafe.res";
case k_EAbandonGameStatus_AbandonWithoutPenalty:
return "Resource/UI/econ/ConfirmDialogAbandonNoPenalty.res";
case k_EAbandonGameStatus_AbandonWithPenalty:
return "Resource/UI/econ/ConfirmDialogAbandonPenalty.res";
}
return "Resource/UI/econ/ConfirmDialogOptOut.res";
}
//-----------------------------------------------------------------------------
void CTFRejoinConfirmDialog::CloseRejoinWindow()
{
FinishUp();
}
|