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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "attachments_window.h"
#include "ControlPanel.h"
#include "ViewerSettings.h"
#include "StudioModel.h"
#include "MatSysWin.h"
#define IDC_ATTACHMENT_LIST (IDC_ATTACHMENT_WINDOW_FIRST+0)
#define IDC_ATTACHMENT_LIST_BONES (IDC_ATTACHMENT_WINDOW_FIRST+1)
#define IDC_ATTACHMENT_TRANSLATION (IDC_ATTACHMENT_WINDOW_FIRST+2)
#define IDC_ATTACHMENT_ROTATION (IDC_ATTACHMENT_WINDOW_FIRST+3)
#define IDC_ATTACHMENT_QC_STRING (IDC_ATTACHMENT_WINDOW_FIRST+4)
CAttachmentsWindow::CAttachmentsWindow( ControlPanel* pParent ) : mxWindow( pParent, 0, 0, 0, 0 )
{
m_pControlPanel = pParent;
g_viewerSettings.m_iEditAttachment = -1;
}
void CAttachmentsWindow::Init( )
{
int left, top;
left = 5;
top = 0;
// Attachment selection list
new mxLabel( this, left + 3, top + 4, 60, 18, "Attachment" );
m_cAttachmentList = new mxListBox( this, left, top + 20, 260, 100, IDC_ATTACHMENT_LIST );
m_cAttachmentList->add ("None");
m_cAttachmentList->select (0);
mxToolTip::add (m_cAttachmentList, "Select an attachment to modify");
left = 280;
new mxLabel( this, left + 3, top + 4, 60, 18, "Attach To Bone" );
m_cBoneList = new mxListBox( this, left, top + 20, 260, 100, IDC_ATTACHMENT_LIST_BONES );
m_cBoneList->add ("None");
m_cBoneList->select( 0 );
mxToolTip::add( m_cBoneList, "Select a bone to attach to" );
left = 5;
top = 120;
new mxLabel( this, left + 3, top + 4, 60, 18, "Translation" );
m_cTranslation = new mxLineEdit2( this, left + 70, top, 90, 25, "10 20 30", IDC_ATTACHMENT_TRANSLATION );
left = 170;
top = 120;
new mxLabel( this, left + 3, top + 4, 60, 18, "Rotation" );
m_cRotation = new mxLineEdit2( this, left + 70, top, 90, 25, "0 90 180", IDC_ATTACHMENT_ROTATION );
top = 145;
left = 5;
new mxLabel( this, left, top, 60, 18, "QC String" );
m_cQCString = new mxLineEdit2( this, left + 70, top, 400, 25, "$attachment \"controlpanel0_ur\" \"Vgui\" -22 -15 4 rotate 0 0 0", IDC_ATTACHMENT_QC_STRING );
}
void CAttachmentsWindow::OnLoadModel()
{
int iPrevEdit = g_viewerSettings.m_iEditAttachment;
PopulateBoneList();
PopulateAttachmentsList();
if ( iPrevEdit >= 0 && iPrevEdit < m_cAttachmentList->getItemCount())
{
m_cAttachmentList->select( iPrevEdit + 1 );
}
g_viewerSettings.m_iEditAttachment = iPrevEdit;
UpdateStrings();
}
void CAttachmentsWindow::OnTabSelected()
{
// for now, keep selection
// g_viewerSettings.m_iEditAttachment = m_cAttachmentList->getSelectedIndex() - 1;
}
void CAttachmentsWindow::OnTabUnselected()
{
// for now, keep selection
// g_viewerSettings.m_iEditAttachment = -1;
}
void CAttachmentsWindow::PopulateAttachmentsList()
{
m_cAttachmentList->removeAll();
m_cAttachmentList->add( "(none)" );
if ( g_pStudioModel )
{
CStudioHdr* pHdr = g_pStudioModel->GetStudioHdr();
if (pHdr->GetNumAttachments())
{
for ( int i = 0; i < pHdr->GetNumAttachments(); i++ )
{
m_cAttachmentList->add ( pHdr->pAttachment(i).pszName() );
}
m_cAttachmentList->select (0);
OnSelChangeAttachmentList();
return;
}
}
m_cAttachmentList->select (0);
}
void CAttachmentsWindow::PopulateBoneList()
{
m_cBoneList->removeAll();
if ( g_pStudioModel )
{
CStudioHdr* pHdr = g_pStudioModel->GetStudioHdr();
if (pHdr->numbones())
{
for ( int i = 0; i < pHdr->numbones(); i++ )
{
m_cBoneList->add ( pHdr->pBone(i)->pszName() );
}
m_cBoneList->select (0);
return;
}
}
m_cBoneList->add( "None" );
m_cBoneList->select (0);
}
int CAttachmentsWindow::handleEvent (mxEvent *event)
{
MDLCACHE_CRITICAL_SECTION_( g_pMDLCache );
if ( !g_pStudioModel )
return 0;
CStudioHdr* pHdr = g_pStudioModel->GetStudioHdr();
switch( event->action )
{
case IDC_ATTACHMENT_LIST:
{
OnSelChangeAttachmentList();
}
break;
case IDC_ATTACHMENT_LIST_BONES:
{
int iAttachment = g_viewerSettings.m_iEditAttachment;
int iBone = m_cBoneList->getSelectedIndex();
if ( iAttachment >= 0 &&
iAttachment < pHdr->GetNumAttachments() &&
iBone >= 0 &&
iBone < pHdr->numbones() )
{
pHdr->SetAttachmentBone( iAttachment, iBone );
UpdateStrings();
}
}
break;
case IDC_ATTACHMENT_TRANSLATION:
{
int iAttachment = g_viewerSettings.m_iEditAttachment;
if ( iAttachment >= 0 &&
iAttachment < pHdr->GetNumAttachments() )
{
mstudioattachment_t &pAttachment = (mstudioattachment_t &)pHdr->pAttachment( iAttachment );
Vector vTrans( 0, 0, 0 );
char curText[512];
m_cTranslation->getText( curText, sizeof( curText ) );
sscanf( curText, "%f %f %f", &vTrans.x, &vTrans.y, &vTrans.z );
pAttachment.local[0][3] = vTrans.x;
pAttachment.local[1][3] = vTrans.y;
pAttachment.local[2][3] = vTrans.z;
UpdateStrings( true, false, false );
}
}
break;
case IDC_ATTACHMENT_ROTATION:
{
int iAttachment = g_viewerSettings.m_iEditAttachment;
if ( iAttachment >= 0 &&
iAttachment < pHdr->GetNumAttachments() )
{
mstudioattachment_t &pAttachment = (mstudioattachment_t &)pHdr->pAttachment( iAttachment );
QAngle vRotation( 0, 0, 0 );
char curText[512];
m_cRotation->getText( curText, sizeof( curText ) );
sscanf( curText, "%f %f %f", &vRotation.x, &vRotation.y, &vRotation.z );
Vector vTrans = GetCurrentTranslation();
AngleMatrix( vRotation, vTrans, pAttachment.local );
UpdateStrings( true, false, false );
}
}
break;
default:
return 0;
}
return 1;
}
void CAttachmentsWindow::OnSelChangeAttachmentList()
{
CStudioHdr *pStudioHdr = g_pStudioModel ? g_pStudioModel->GetStudioHdr() : NULL;
if ( !pStudioHdr )
return;
int iAttachment = m_cAttachmentList->getSelectedIndex() - 1;
if ( iAttachment >= 0 && iAttachment < pStudioHdr->GetNumAttachments() )
{
g_viewerSettings.m_iEditAttachment = iAttachment;
// Init the bone list index.
int iBone = g_pStudioModel->GetStudioHdr()->GetAttachmentBone( iAttachment );
m_cBoneList->select( iBone );
}
else
{
g_viewerSettings.m_iEditAttachment = -1;
}
UpdateStrings();
}
Vector CAttachmentsWindow::GetCurrentTranslation()
{
CStudioHdr *pStudioHdr = g_pStudioModel ? g_pStudioModel->GetStudioHdr() : NULL;
int iAttachment = m_cAttachmentList->getSelectedIndex() - 1;
if ( pStudioHdr && iAttachment >= 0 && iAttachment < pStudioHdr->GetNumAttachments() )
{
mstudioattachment_t &pAttachment = (mstudioattachment_t &)pStudioHdr->pAttachment( iAttachment );
return Vector( pAttachment.local[0][3],
pAttachment.local[1][3],
pAttachment.local[2][3] );
}
else
{
return vec3_origin;
}
}
Vector CAttachmentsWindow::GetCurrentRotation()
{
CStudioHdr *pStudioHdr = g_pStudioModel ? g_pStudioModel->GetStudioHdr() : NULL;
int iAttachment = m_cAttachmentList->getSelectedIndex() - 1;
if ( pStudioHdr && iAttachment >= 0 && iAttachment < pStudioHdr->GetNumAttachments() )
{
mstudioattachment_t &pAttachment = (mstudioattachment_t &)pStudioHdr->pAttachment( iAttachment );
float angles[3];
MatrixAngles( pAttachment.local, angles );
return Vector( angles[0], angles[1], angles[2] );
}
else
{
return vec3_origin;
}
}
void CAttachmentsWindow::UpdateStrings( bool bUpdateQC, bool bUpdateTranslation, bool bUpdateRotation )
{
char str[1024];
int iAttachment = -1;
CStudioHdr* pHdr = NULL;
if ( g_pStudioModel )
{
pHdr = g_pStudioModel->GetStudioHdr();
iAttachment = m_cAttachmentList->getSelectedIndex() - 1;
if ( iAttachment < 0 || iAttachment >= pHdr->GetNumAttachments() )
iAttachment = -1;
}
if ( iAttachment == -1 )
{
m_cTranslation->setText( "(none)" );
m_cRotation->setText( "(none)" );
m_cQCString->setText( "(none)" );
}
else
{
mstudioattachment_t &pAttachment = (mstudioattachment_t &)pHdr->pAttachment( iAttachment );
int iBone= pHdr->GetAttachmentBone( iAttachment );
Vector vTranslation = GetCurrentTranslation();
Vector vRotation = GetCurrentRotation();
if ( bUpdateQC )
{
sprintf( str, "$attachment \"%s\" \"%s\" %.2f %.2f %.2f rotate %.0f %.0f %.0f",
pAttachment.pszName(),
pHdr->pBone( iBone )->pszName(),
VectorExpand( vTranslation ),
VectorExpand( vRotation ) );
m_cQCString->setText( str );
}
if ( bUpdateTranslation )
{
sprintf( str, "%.2f %.2f %.2f", VectorExpand( vTranslation ) );
m_cTranslation->setText( str );
}
if ( bUpdateRotation )
{
sprintf( str, "%.0f %.0f %.0f", VectorExpand( vRotation ) );
m_cRotation->setText( str );
}
}
}
|