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
296
297
298
299
300
301
302
303
304
305
306
|
//========= 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 "vgui//ILocalize.h"
#include "econ_item_system.h"
#include "econ_item_constants.h"
#include "econ_gcmessages.h"
#include "econ_item_inventory.h"
#include "econ_item_tools.h"
#include "tool_items.h"
#include "rename_tool_ui.h"
#include "econ_ui.h"
#include "gc_clientsystem.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
CNameToolUsageDialog::CNameToolUsageDialog( vgui::Panel *pParent, const char* pszName, CEconItemView *pTool, CEconItemView *pToolSubject, bool bDescription )
: CBaseToolUsageDialog( pParent, pszName, pTool, pToolSubject )
{
m_bDescription = bDescription;
}
int CNameToolUsageDialog::GetMaxLength()
{
if ( m_bDescription )
return MAX_ITEM_CUSTOM_DESC_LENGTH;
else
return MAX_ITEM_CUSTOM_NAME_LENGTH;
}
int CNameToolUsageDialog::GetMaxDBSize()
{
if ( m_bDescription )
return MAX_ITEM_CUSTOM_DESC_DATABASE_SIZE;
else
return MAX_ITEM_CUSTOM_NAME_DATABASE_SIZE;
}
void CEconTool_NameTag::OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const
{
CRequestNameDialog *dialog = vgui::SETUP_PANEL( new CRequestNameDialog( pParent, "ItemRenameDialog", pTool, pSubject, false ) );
MakeModalAndBringToFront( dialog );
}
//-----------------------------------------------------------------------------
CRequestNameDialog::CRequestNameDialog( vgui::Panel *parent, const char* pszName, CEconItemView *pTool, CEconItemView *pToolSubject, bool bDescription ) :
CNameToolUsageDialog( parent, pszName, pTool, pToolSubject, bDescription )
{
m_pCustomNameEntry = new vgui::TextEntry( this, "CustomNameEntry" );
m_bDescription = bDescription;
}
//-----------------------------------------------------------------------------
void CRequestNameDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
{
LoadControlSettings( "resource/UI/ItemRenameDialog.res" );
BaseClass::ApplySchemeSettings( pScheme );
m_pOldNameLabel = dynamic_cast<vgui::Label *>( FindChildByName( "OldItemNameDescLabel" ) );
if ( m_pOldNameLabel )
{
if ( m_bDescription )
m_pOldNameLabel->SetText( g_pVGuiLocalize->Find( "#ToolItemRenameOldItemDesc" ) );
else
m_pOldNameLabel->SetText( g_pVGuiLocalize->Find( "#ToolItemRenameOldItemName" ) );
}
m_pNewNameLabel = dynamic_cast<vgui::Label *>( FindChildByName( "NewItemNameDescLabel" ) );
if ( m_pNewNameLabel )
{
if ( m_bDescription )
m_pNewNameLabel->SetText( g_pVGuiLocalize->Find( "#ToolItemRenameNewItemDesc" ) );
else
m_pNewNameLabel->SetText( g_pVGuiLocalize->Find( "#ToolItemRenameNewItemName" ) );
}
m_pOldName = dynamic_cast<vgui::Label *>( FindChildByName( "OldItemNameLabel" ) );
if ( m_pOldName )
{
if ( m_bDescription )
{
CEconItem *pSOCData = m_pSubjectModelPanel->GetItem()->GetSOCData();
if ( pSOCData && pSOCData->GetCustomDesc() )
m_pOldName->SetText( pSOCData->GetCustomDesc() );
else
m_pOldName->SetText( m_pSubjectModelPanel->GetItem()->GetStaticData()->GetItemDesc() );
}
else
{
CEconItem *pSOCData = m_pSubjectModelPanel->GetItem()->GetSOCData();
if ( pSOCData && pSOCData->GetCustomName() )
m_pOldName->SetText( pSOCData->GetCustomName() );
else
m_pOldName->SetText( m_pSubjectModelPanel->GetItem()->GetStaticData()->GetItemBaseName() );
}
}
CExButton *pOKButton = dynamic_cast< CExButton* >( FindChildByName( "OkButton" ) );
if ( pOKButton )
{
if ( m_bDescription )
pOKButton->SetText( "#CraftDescribeOk" );
}
m_pCustomNameEntry->SetMaximumCharCount( GetMaxLength() );
m_pCustomNameEntry->SetAllowNonAsciiCharacters( true );
}
//-----------------------------------------------------------------------------
void CRequestNameDialog::MoveToFront()
{
BaseClass::MoveToFront();
// do this after MoveToFront so we can force the text box to have focus instead
// of the dialog itself
m_pCustomNameEntry->RequestFocus();
}
//-----------------------------------------------------------------------------
void CRequestNameDialog::Apply( void )
{
const int maxNameLength = MAX_ITEM_CUSTOM_DESC_LENGTH + 1;
wchar_t inputName[ maxNameLength ];
m_pCustomNameEntry->GetText( inputName, sizeof(inputName) );
// pop up modal confirmation dialog
CConfirmNameDialog *dialog = vgui::SETUP_PANEL( new CConfirmNameDialog( GetParent(), "ItemRenameConfirmationDialog", m_pToolModelPanel->GetItem(), m_pSubjectModelPanel->GetItem(), inputName, m_bDescription ) );
MakeModalAndBringToFront( dialog );
}
//-----------------------------------------------------------------------------
// Purpose: Gives focus back to the name entry field after the mouse enters a
// item model panel
//-----------------------------------------------------------------------------
void CRequestNameDialog::OnItemPanelEntered( vgui::Panel *panel )
{
CItemModelPanel *pItemPanel = dynamic_cast < CItemModelPanel * > ( panel );
if ( pItemPanel && IsVisible() )
{
// The item panel is going to try and steal our focus. Steal it back!
m_pCustomNameEntry->RequestFocus();
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
CConfirmNameDialog::CConfirmNameDialog( vgui::Panel *parent, const char* pszName, CEconItemView *pTool, CEconItemView *pToolSubject, const wchar_t *name, bool bDescription ) :
CNameToolUsageDialog( parent, pszName, pTool, pToolSubject, bDescription )
{
Q_wcsncpy( m_name, name, sizeof(m_name) );
m_bDescription = bDescription;
}
//-----------------------------------------------------------------------------
//
// We're going to want to flesh this out to trim off leading/training spaces, etc
//
bool CConfirmNameDialog::IsNameValid( void ) const
{
// legal names are 1 or more alphanumeric values (only)
const wchar_t *c = m_name;
int length = 0;
while( *c )
{
// no leading spaces
if ( length == 0 && *c == ' ' )
return false;
++c;
++length;
}
// no trailing spaces
if ( length > 0 && m_name[length-1] == ' ' )
return false;
return (length > 0);
}
//-----------------------------------------------------------------------------
void CConfirmNameDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
{
if ( !IsNameValid() )
{
// pop up bad name dialog
LoadControlSettings( "resource/UI/ItemRenameInvalidDialog.res" );
}
else
{
// pop up "are you sure" dialog
LoadControlSettings( "resource/UI/ItemRenameConfirmationDialog.res" );
}
// Set our dialog name, but pre & post pend it with quotes
wchar_t tmpname[ MAX_ITEM_CUSTOM_DESC_LENGTH+3 ];
V_wcscpy_safe( tmpname, L"\"" );
V_wcscat_safe( tmpname, m_name );
V_wcscat_safe( tmpname, L"\"" );
SetDialogVariable( "name", tmpname );
BaseClass::ApplySchemeSettings( pScheme );
}
//-----------------------------------------------------------------------------
void CConfirmNameDialog::Apply( void )
{
// the GC stores 8-bit chars, so convert Unicode name to UTF8
char* utf8Name = new char[ GetMaxDBSize() ];
int count = V_UnicodeToUTF8( m_name, utf8Name, GetMaxDBSize() );
if ( count > GetMaxDBSize() )
{
// the encoded name exceeds the GC's storage limit
return;
}
if ( m_pSubjectModelPanel->GetItem()->GetItemID() != INVALID_ITEM_ID )
{
// Name has been confirmed - send message to GC to apply name to item
GCSDK::CGCMsg< MsgGCNameItem_t > msg( k_EMsgGCNameItem );
msg.Body().m_unToolItemID = m_pToolModelPanel->GetItem()->GetItemID();
msg.Body().m_unSubjectItemID = m_pSubjectModelPanel->GetItem()->GetItemID();
msg.AddStrData( utf8Name );
GCClientSystem()->BSendMessage( msg );
}
else
{
// Name has been confirmed - send message to GC to apply name to item
GCSDK::CGCMsg< MsgGCNameBaseItem_t > msg( k_EMsgGCNameBaseItem );
msg.Body().m_unToolItemID = m_pToolModelPanel->GetItem()->GetItemID();
msg.Body().m_unBaseItemDefinitionID = m_pSubjectModelPanel->GetItem()->GetStaticData()->GetDefinitionIndex();
msg.AddStrData( utf8Name );
GCClientSystem()->BSendMessage( msg );
}
if ( m_bDescription )
EconUI()->Gamestats_ItemTransaction( IE_ITEM_USED_TOOL, m_pToolModelPanel->GetItem(), "redescription_item" );
else
EconUI()->Gamestats_ItemTransaction( IE_ITEM_USED_TOOL, m_pToolModelPanel->GetItem(), "renamed_item" );
delete []utf8Name;
}
//-----------------------------------------------------------------------------
void CConfirmNameDialog::OnCommand( const char *command )
{
BaseClass::OnCommand( command );
if ( !Q_stricmp( command, "backfrominvalid" ) )
{
// Re-open the name dialog
CRequestNameDialog *dialog = vgui::SETUP_PANEL( new CRequestNameDialog( GetParent(), "ItemRenameDialog", m_pToolModelPanel->GetItem(), m_pSubjectModelPanel->GetItem(), m_bDescription ) );
MakeModalAndBringToFront( dialog );
}
}
//-----------------------------------------------------------------------------
// Purpose: GC Msg handler to receive the name base item response
//-----------------------------------------------------------------------------
class CGCNameBaseItemResponse : public GCSDK::CGCClientJob
{
public:
CGCNameBaseItemResponse( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CGCMsg<MsgGCStandardResponse_t> msg( pNetPacket );
InventoryManager()->ShowItemsPickedUp( true );
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCNameBaseItemResponse, "CGCNameBaseItemResponse", k_EMsgGCNameBaseItemResponse, GCSDK::k_EServerTypeGCClient );
//-----------------------------------------------------------------------------
// Purpose: UI Hook for applying a new description to items.
//-----------------------------------------------------------------------------
void CEconTool_DescTag::OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const
{
CRequestNameDialog *dialog = vgui::SETUP_PANEL( new CRequestNameDialog( pParent, "ItemRenameDialog", pTool, pSubject, true ) );
MakeModalAndBringToFront( dialog );
}
|