forked from perilouswithadollarsign/cstrike15_src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticlebrowser.cpp
284 lines (224 loc) · 6.44 KB
/
particlebrowser.cpp
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
// ParticleBrowser.cpp : implementation file
//
#include "stdafx.h"
#include "ParticleBrowser.h"
#include "matsys_controls/particlepicker.h"
#include "matsys_controls/matsyscontrols.h"
#include "vgui_controls/TextEntry.h"
#include "vgui_controls/Splitter.h"
#include "vgui_controls/Button.h"
#include "KeyValues.h"
#include "vgui/KeyCode.h"
#include "texturesystem.h"
#include "HammerVGui.h"
static LPCTSTR pszIniSection = "Particle Browser";
// CParticleBrowser dialog
class CParticleBrowserPanel : public vgui::EditablePanel
{
public:
CParticleBrowserPanel( CParticleBrowser *pBrowser, const char *panelName, vgui::HScheme hScheme ) :
vgui::EditablePanel( NULL, panelName, hScheme )
{
m_pBrowser = pBrowser;
}
virtual void OnSizeChanged(int newWide, int newTall)
{
// call Panel and not EditablePanel OnSizeChanged.
Panel::OnSizeChanged(newWide, newTall);
}
virtual void OnCommand( const char *pCommand )
{
if ( Q_strcmp( pCommand, "OK" ) == 0 )
{
m_pBrowser->EndDialog( IDOK );
}
else if ( Q_strcmp( pCommand, "Cancel" ) == 0 )
{
m_pBrowser->EndDialog( IDCANCEL );
}
}
virtual void OnKeyCodeTyped(vgui::KeyCode code)
{
vgui::EditablePanel::OnKeyCodeTyped( code );
if ( code == KEY_ENTER )
{
m_pBrowser->EndDialog( IDOK );
}
else if ( code == KEY_ESCAPE )
{
m_pBrowser->EndDialog( IDCANCEL );
}
}
virtual void OnMessage(const KeyValues *params, vgui::VPANEL ifromPanel)
{
vgui::EditablePanel::OnMessage( params, ifromPanel );
if ( Q_strcmp( params->GetName(), "ParticleSystemSelectionChanged" ) == 0 )
{
m_pBrowser->UpdateStatusLine();
}
}
CParticleBrowser *m_pBrowser;
};
IMPLEMENT_DYNAMIC(CParticleBrowser, CDialog)
CParticleBrowser::CParticleBrowser(CWnd* pParent /*=NULL*/)
: CDialog(CParticleBrowser::IDD, pParent)
{
m_pPicker = new CParticlePicker( NULL );
m_pStatusLine = new vgui::TextEntry( NULL, "StatusLine" );
m_pButtonOK = new vgui::Button( NULL, "OpenButton", "OK" );
m_pButtonCancel = new vgui::Button( NULL, "CancelButton", "Cancel" );
}
CParticleBrowser::~CParticleBrowser()
{
// CDialog isn't going to clean up its vgui children
delete m_pPicker;
delete m_pStatusLine;
delete m_pButtonOK;
delete m_pButtonCancel;
}
void CParticleBrowser::SetParticleSysName( const char *pParticleSysName )
{
char pTempName[255];
strcpy( pTempName, pParticleSysName );
char * pSelectedParticleSys = strchr( pTempName, '/' );
if( pSelectedParticleSys)
{
pSelectedParticleSys += 1;
Q_FixSlashes( pSelectedParticleSys, '\\' );
}
m_pPicker->SelectParticleSys( pParticleSysName );
m_pPicker->SetInitialSelection( pSelectedParticleSys );
m_pStatusLine->SetText( pParticleSysName );
}
void CParticleBrowser::GetParticleSysName( char *pParticleName, int length )
{
m_pPicker->GetSelectedParticleSysName( pParticleName, length );
Q_FixSlashes( pParticleName, '/' );
}
void CParticleBrowser::UpdateStatusLine()
{
char szParticle[1024];
m_pPicker->GetSelectedParticleSysName( szParticle, sizeof(szParticle) );
m_pStatusLine->SetText( szParticle );
}
void CParticleBrowser::SaveLoadSettings( bool bSave )
{
CString str;
CRect rect;
CWinApp *pApp = AfxGetApp();
if ( bSave )
{
GetWindowRect(rect);
str.Format("%d %d %d %d", rect.left, rect.top, rect.right, rect.bottom);
pApp->WriteProfileString(pszIniSection, "Position", str);
pApp->WriteProfileString(pszIniSection, "Filter", m_pPicker->GetFilter() );
}
else
{
str = pApp->GetProfileString(pszIniSection, "Position");
if (!str.IsEmpty())
{
sscanf(str, "%d %d %d %d", &rect.left, &rect.top, &rect.right, &rect.bottom);
MoveWindow(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, FALSE);
Resize();
}
str = pApp->GetProfileString(pszIniSection, "Filter");
if (!str.IsEmpty())
{
m_pPicker->SetFilter( str );
}
}
}
void CParticleBrowser::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
void CParticleBrowser::Resize()
{
// reposition controls
CRect rect;
GetClientRect(&rect);
m_VGuiWindow.MoveWindow( rect );
m_pPicker->SetBounds( 0,0, rect.Width(), rect.Height() - 32 );
m_pButtonCancel->SetPos( 8, rect.Height() - 30 );
m_pButtonOK->SetPos( 84, rect.Height() - 30 );
m_pStatusLine->SetBounds( 160, rect.Height() - 30, max( 100, rect.Width() - 166 ), 24 );
}
void CParticleBrowser::OnSize(UINT nType, int cx, int cy)
{
if (nType == SIZE_MINIMIZED || !IsWindow(m_VGuiWindow.m_hWnd) )
{
CDialog::OnSize(nType, cx, cy);
return;
}
Resize();
CDialog::OnSize(nType, cx, cy);
}
BOOL CParticleBrowser::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
BEGIN_MESSAGE_MAP(CParticleBrowser, CDialog)
ON_WM_SIZE()
ON_WM_DESTROY()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
BOOL CParticleBrowser::PreTranslateMessage( MSG* pMsg )
{
// don't filter dialog message
return CWnd::PreTranslateMessage( pMsg );
}
BOOL CParticleBrowser::OnInitDialog()
{
CDialog::OnInitDialog();
m_VGuiWindow.Create( NULL, _T("ParticleViewer"), WS_VISIBLE|WS_CHILD, CRect(0,0,100,100), this, IDD_PARTICLE_BROWSER );
vgui::EditablePanel *pMainPanel = new CParticleBrowserPanel( this, "ParticleBrowerPanel", HammerVGui()->GetHammerScheme() );
m_VGuiWindow.SetParentWindow( &m_VGuiWindow );
m_VGuiWindow.SetMainPanel( pMainPanel );
pMainPanel->MakePopup( false, false );
m_VGuiWindow.SetRepaintInterval( 75 );
m_pPicker->SetParent( pMainPanel );
m_pPicker->AddActionSignalTarget( pMainPanel );
m_pButtonOK->SetParent( pMainPanel );
m_pButtonOK->AddActionSignalTarget( pMainPanel );
m_pButtonOK->SetCommand( "OK" );
m_pButtonCancel->SetParent( pMainPanel );
m_pButtonCancel->AddActionSignalTarget( pMainPanel );
m_pButtonCancel->SetCommand( "Cancel" );
m_pStatusLine->SetParent( pMainPanel );
m_pStatusLine->SetEditable( false );
SaveLoadSettings( false ); // load
m_pPicker->Activate();
return TRUE;
}
void CParticleBrowser::OnDestroy()
{
SaveLoadSettings( true ); // save
// model browser destoys our default cube map, reload it
g_Textures.RebindDefaultCubeMap();
CDialog::OnDestroy();
}
void CParticleBrowser::Show()
{
if (m_pPicker)
{
m_pPicker->SetVisible( true );
}
if (m_pStatusLine)
m_pStatusLine->SetVisible( true );
if (m_pButtonOK)
m_pButtonOK->SetVisible( true );
if (m_pButtonCancel)
m_pButtonCancel->SetVisible( true );
}
void CParticleBrowser::Hide()
{
if (m_pPicker)
m_pPicker->SetVisible( false );
if (m_pStatusLine)
m_pStatusLine->SetVisible( false );
if (m_pButtonOK)
m_pButtonOK->SetVisible( false );
if (m_pButtonCancel)
m_pButtonCancel->SetVisible( false );
}