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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "vgui_controls/EditablePanel.h"
#include "vgui_controls/TextEntry.h"
#include "vgui/IInput.h"
#include "econ_item_system.h"
#include "econ_item_constants.h"
#include "econ_item_tools.h"
#include "econ_gcmessages.h"
#include "econ_item_inventory.h"
#include "tool_items.h"
#include "gift_wrap_tool.h"
#include "econ_ui.h"
#include "vgui/ISurface.h"
#include "econ_controls.h"
#include "confirm_dialog.h"
#include "gc_clientsystem.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
//-----------------------------------------------------------------------------
// Purpose: Confirm / abort tool application
//-----------------------------------------------------------------------------
class CConfirmGiftWrapDialog : public CBaseToolUsageDialog
{
DECLARE_CLASS_SIMPLE( CConfirmGiftWrapDialog, CBaseToolUsageDialog );
public:
CConfirmGiftWrapDialog( vgui::Panel *pParent, CEconItemView *pTool, CEconItemView *pToolSubject );
virtual void ApplySchemeSettings( vgui::IScheme *scheme );
virtual void Apply( void );
};
//-----------------------------------------------------------------------------
// Purpose: Completed wrapping dialog
//-----------------------------------------------------------------------------
class CWaitForGiftWrapDialog : public CGenericWaitingDialog
{
public:
CWaitForGiftWrapDialog( vgui::Panel *pParent ) : CGenericWaitingDialog( pParent )
{
}
protected:
virtual void OnTimeout()
{
// Play an exciting sound!
vgui::surface()->PlaySound( "misc/achievement_earned.wav" );
// Show them the result item.
InventoryManager()->ShowItemsPickedUp( true );
}
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CConfirmGiftWrapDialog::CConfirmGiftWrapDialog( vgui::Panel *parent, CEconItemView *pTool, CEconItemView *pToolSubject ) : CBaseToolUsageDialog( parent, "ConfirmApplyGiftWrapDialog", pTool, pToolSubject )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CConfirmGiftWrapDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
{
LoadControlSettings( "Resource/UI/econ/ConfirmApplyGiftWrapDialog.res" );
// We might want to change our label text to explicitly call out that we'll reset strange scores
// on gift wrap, but only if we're trying to use this gift wrap on a strange item that has scores
// that would be affected by it.
CEconItemView *pSubjectItemView = GetSubjectItem();
CExLabel *pTextLabel = dynamic_cast<CExLabel *>( FindChildByName( "ConfirmLabel" ) );
CExLabel *pTextLabelStrange = dynamic_cast<CExLabel *>( FindChildByName( "ConfirmLabelStrange" ) );
if ( pSubjectItemView && pTextLabel && pTextLabelStrange )
{
bool bHasNonZeroScore = false;
for ( int i = 0; i < GetKillEaterAttrCount(); i++ )
{
uint32 unScore;
if ( pSubjectItemView->FindAttribute( GetKillEaterAttr_Score( i ), &unScore ) && unScore > 0 )
{
bHasNonZeroScore = true;
break;
}
}
if ( bHasNonZeroScore )
{
pTextLabel->SetVisible( false );
pTextLabelStrange->SetVisible( true );
}
}
BaseClass::ApplySchemeSettings( pScheme );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CConfirmGiftWrapDialog::Apply( void )
{
// Tell the GC to wrap the subject item.
GCSDK::CGCMsg< MsgGCGiftWrapItem_t > msg( k_EMsgGCGiftWrapItem );
msg.Body().m_unToolItemID = m_pToolModelPanel->GetItem()->GetItemID();
msg.Body().m_unSubjectItemID = m_pSubjectModelPanel->GetItem()->GetItemID();
EconUI()->Gamestats_ItemTransaction( IE_ITEM_USED_TOOL, m_pSubjectModelPanel->GetItem(), "gift_wrap_item" );
GCClientSystem()->BSendMessage( msg );
vgui::surface()->PlaySound( "ui/item_gift_wrap_use.wav" );
ShowWaitingDialog( new CWaitForGiftWrapDialog( NULL ), "#ToolGiftWrapInProgress", true, false, 5.0f );
}
// Entry point from the UI.
void CEconTool_GiftWrap::OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const
{
CConfirmGiftWrapDialog *dialog = vgui::SETUP_PANEL( new CConfirmGiftWrapDialog( pParent, pTool, pSubject ) );
MakeModalAndBringToFront( dialog );
}
//-----------------------------------------------------------------------------
// Purpose: GC Msg handler to receive the server response that we've given an item.
//-----------------------------------------------------------------------------
class CGCGiftGivenResponse : public GCSDK::CGCClientJob
{
public:
CGCGiftGivenResponse( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CProtoBufMsg<CMsgDeliverGiftResponseGiver> msg( pNetPacket );
// Pop up a notification to confirm that the gift has been sent.
switch ( msg.Body().response_code() )
{
case k_EGCMsgResponseOK:
if ( msg.Body().has_receiver_account_name() )
{
KeyValues *pkv = new KeyValues( "GiftReceiverParams" );
KeyValuesAD kvad( pkv );
pkv->SetString( "receiver_account_name", msg.Body().receiver_account_name().c_str() );
ShowMessageBox( "#TF_DeliverGiftResultDialog_Title", "#TF_DeliverGiftResultDialog_Success_WithAccount", pkv, "#GameUI_OK" );
}
else
{
ShowMessageBox( "#TF_DeliverGiftResultDialog_Title", "#TF_DeliverGiftResultDialog_Success", "#GameUI_OK" );
}
break;
case k_EGCMsgResponseDenied:
ShowMessageBox( "#TF_DeliverGiftResultDialog_Title", "#TF_DeliverGiftResultDialog_VAC", "#GameUI_OK" );
break;
default:
ShowMessageBox( "#TF_DeliverGiftResultDialog_Title", "#TF_DeliverGiftResultDialog_Fail", "#GameUI_OK" );
break;
} // switch
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCGiftGivenResponse, "CGCGiftGivenResponse", k_EMsgGCDeliverGiftResponseGiver, GCSDK::k_EServerTypeGCClient );
//-----------------------------------------------------------------------------
// Purpose: GC Msg handler to receive the server response that we've received an item.
//-----------------------------------------------------------------------------
class CGCGiftReceivedResponse : public GCSDK::CGCClientJob
{
public:
CGCGiftReceivedResponse( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CGCMsg<MsgGCStandardResponse_t> msg( pNetPacket );
// If the receiver is online when the gift is sent, they will get this response.
InventoryManager()->GetLocalInventory()->NotifyHasNewItems();
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCGiftReceivedResponse, "CGCGiftReceivedResponse", k_EMsgGCDeliverGiftResponseReceiver, GCSDK::k_EServerTypeGCClient );
//-----------------------------------------------------------------------------
// Purpose: Completed unwrapping...
//-----------------------------------------------------------------------------
class CWaitForGiftUnwrapDialog : public CGenericWaitingDialog
{
public:
CWaitForGiftUnwrapDialog( vgui::Panel *pParent ) : CGenericWaitingDialog( pParent )
{
}
protected:
virtual void OnTimeout()
{
// Play an exciting sound!
vgui::surface()->PlaySound( "misc/achievement_earned.wav" );
// Show them the result item.
InventoryManager()->ShowItemsPickedUp( true );
}
};
static void UnwrapGiftConfirm( bool bConfirmed, void *pContext )
{
if ( bConfirmed )
{
vgui::surface()->PlaySound( "ui/item_gift_wrap_unwrap.wav" );
ShowWaitingDialog( new CWaitForGiftWrapDialog( NULL ), "#ToolGiftUnwrapInProgress", true, false, 5.0f );
CEconItemView *pItem = (CEconItemView*) pContext;
GCSDK::CGCMsg< MsgGCUnwrapGiftRequest_t > msg( k_EMsgGCUnwrapGiftRequest );
msg.Body().m_unItemID = pItem->GetItemID();
GCClientSystem()->BSendMessage( msg );
EconUI()->Gamestats_ItemTransaction( IE_ITEM_USED_TOOL, pItem, "unwrapped_gift" );
}
}
void PerformToolAction_UnwrapGift( vgui::Panel* pParent, CEconItemView *pGiftItem )
{
CTFGenericConfirmDialog *pDialog = ShowConfirmDialog( "#TF_UnwrapGift_Title", "#TF_UnwrapGift_Text",
"#GameUI_OK", "#Cancel",
&UnwrapGiftConfirm );
pDialog->AddStringToken( "item_name", pGiftItem->GetItemName() );
pDialog->SetContext( pGiftItem );
}
|