@@ -107,6 +107,7 @@ void ParticleNew::Start() {
107
107
108
108
fileSelection = -1 ;
109
109
fileName.Clear ();
110
+ name.Clear ();
110
111
errorText.Clear ();
111
112
dp = NULL ;
112
113
state = NAME;
@@ -198,6 +199,105 @@ bool ParticleNew::Draw() {
198
199
return accepted;
199
200
}
200
201
202
+ ParticleSelect::ParticleSelect ()
203
+ : comboParticleSel(-1 )
204
+ , comboParticle()
205
+ , name( " " )
206
+ , errorText( " " )
207
+ , dp( NULL )
208
+ , state(DONE)
209
+ {
210
+ }
211
+
212
+ void ParticleSelect::Start () {
213
+ comboParticle.Clear ();
214
+ for ( int i = 0 ; i < declManager->GetNumDecls ( DECL_PARTICLE ); i++ ) {
215
+ const idDecl *idp = declManager->DeclByIndex ( DECL_PARTICLE, i );
216
+ comboParticle.Append ( idp->GetName () );
217
+ }
218
+ comboParticleSel = 0 ;
219
+
220
+ name.Clear ();
221
+ errorText.Clear ();
222
+ dp = NULL ;
223
+ state = NAME;
224
+
225
+ ImGui::OpenPopup ( " Particle System Browser" );
226
+ }
227
+
228
+ bool ParticleSelect::Draw () {
229
+ if ( state == DONE ) {
230
+ return false ;
231
+ }
232
+
233
+ bool accepted = false ;
234
+ bool canceled = false ;
235
+
236
+ if ( ImGui::BeginPopupModal ( " Particle System Browser" , nullptr , ImGuiWindowFlags_AlwaysAutoResize ) ) {
237
+ ImGui::TextColored ( ImVec4 ( 1 , 0 , 0 , 1 ), errorText );
238
+
239
+ if ( ImGui::InputTextStr ( " Name" , &name ) ) {
240
+ // nop
241
+ }
242
+
243
+ if ( ImGui::BeginListBox ( " Particle Systems##prtSystemSelect" ) ) {
244
+ for ( int i = 0 ; i < comboParticle.Num (); i++ )
245
+ {
246
+ if ( name.Length () && comboParticle[i].Find ( name.c_str (), false ) == -1 ) {
247
+ continue ;
248
+ }
249
+
250
+ bool selected = ( i == comboParticleSel );
251
+
252
+ ImGui::PushID ( i );
253
+ if ( ImGui::Selectable ( comboParticle[i].c_str (), selected ) ) {
254
+ comboParticleSel = i;
255
+ name = comboParticle[comboParticleSel];
256
+ }
257
+ if ( selected ) {
258
+ ImGui::SetItemDefaultFocus ();
259
+ }
260
+ ImGui::PopID ();
261
+ }
262
+
263
+ ImGui::EndListBox ();
264
+ }
265
+
266
+ if ( ImGui::Button ( " OK" ) ) {
267
+ errorText.Clear ();
268
+
269
+ if ( name.IsEmpty () ) {
270
+ errorText += " Please enter a name or select a particle system from the list\n " ;
271
+ accepted = false ;
272
+ }
273
+
274
+ idDeclParticle *decl = static_cast <idDeclParticle*>( const_cast <idDecl*>( declManager->FindType ( DECL_PARTICLE, name.c_str (), false ) ) );
275
+ if ( !decl ) {
276
+ errorText += idStr::Format ( " Particle System %s does not exist. Please select a different particle system\n " , name.c_str () );
277
+ accepted = false ;
278
+ }
279
+
280
+ if ( errorText.IsEmpty () ) {
281
+ dp = decl;
282
+ state = DONE;
283
+
284
+ accepted = true ;
285
+ ImGui::CloseCurrentPopup ();
286
+ }
287
+ }
288
+ ImGui::SameLine ();
289
+ if ( ImGui::Button ( " Cancel" ) ) {
290
+ accepted = false ;
291
+ state = DONE;
292
+ ImGui::CloseCurrentPopup ();
293
+ }
294
+
295
+ ImGui::EndPopup ();
296
+ }
297
+
298
+ return accepted;
299
+ }
300
+
201
301
ParticleEditor& ParticleEditor::Instance ()
202
302
{
203
303
static ParticleEditor instance;
@@ -206,12 +306,12 @@ ParticleEditor& ParticleEditor::Instance()
206
306
207
307
ParticleEditor::ParticleEditor ()
208
308
: particleNewDlg()
309
+ , particleSelectDlg()
209
310
, colorDlg( " Color" )
210
311
, fadeColorDlg( " Fade Color" )
211
312
, entityColorDlg( " Entity Color" )
212
313
, particleDropDlg()
213
314
, materialDeclSelection(0 )
214
- , shouldPopulate(false )
215
315
{
216
316
isShown = false ;
217
317
}
@@ -220,7 +320,7 @@ void ParticleEditor::Draw()
220
320
{
221
321
int i, num;
222
322
bool showTool;
223
- bool clickedNew = false , openedParticleBrowser = false ;
323
+ bool clickedNew = false , clickedSelect = false ;
224
324
225
325
showTool = isShown;
226
326
@@ -238,8 +338,7 @@ void ParticleEditor::Draw()
238
338
239
339
if ( ImGui::MenuItem ( " Open.." , " Ctrl+O" ) )
240
340
{
241
- shouldPopulate = true ;
242
- openedParticleBrowser = true ;
341
+ clickedSelect = true ;
243
342
}
244
343
245
344
if ( ImGui::MenuItem ( " Save" , " Ctrl+S" ) )
@@ -262,51 +361,19 @@ void ParticleEditor::Draw()
262
361
}
263
362
264
363
if ( particleNewDlg.Draw () ) {
265
- idDeclParticle* dp = particleNewDlg.GetParticle ();
266
-
267
- if ( dp ) {
268
- comboParticleSel = comboParticle.Append ( dp->GetName () );
364
+ idDeclParticle *dp = particleNewDlg.GetParticle ();
269
365
270
- OnCbnSelchangeComboParticles ();
271
- }
366
+ SetCurParticle ( dp );
272
367
}
273
368
274
- if ( openedParticleBrowser )
275
- {
276
- ImGui::OpenPopup ( " Particle System Browser" );
369
+ if ( clickedSelect) {
370
+ particleSelectDlg.Start ();
277
371
}
278
372
279
- if ( ImGui::BeginPopup ( " Particle System Browser" ) )
280
- {
281
- if ( shouldPopulate ) {
282
- EnumParticles ();
283
- shouldPopulate = false ;
284
- }
285
- if ( comboParticle.Num () > 0 )
286
- {
287
- ImGui::Combo ( " Particle Systems" , &comboParticleSel, &StringListItemGetter, &comboParticle, comboParticle.Num () );
288
- if ( ImGui::Button ( " Select" ) )
289
- {
290
- idDeclParticle* newDecl = static_cast <idDeclParticle*>( const_cast <idDecl*>( declManager->FindType ( DECL_PARTICLE, comboParticle[comboParticleSel], false ) ) );
291
- if ( newDecl )
292
- {
293
- OnCbnSelchangeComboParticles ();
294
- }
295
- ImGui::CloseCurrentPopup ();
296
- }
297
- }
298
- else
299
- {
300
- ImGui::Text ( " There are no particle systems!" );
301
- }
302
-
303
- ImGui::SameLine ();
373
+ if ( particleSelectDlg.Draw () ) {
374
+ idDeclParticle *dp = particleSelectDlg.GetParticle ();
304
375
305
- if ( ImGui::Button ( " Close" ) )
306
- {
307
- ImGui::CloseCurrentPopup ();
308
- }
309
- ImGui::EndPopup ();
376
+ SetCurParticle ( dp );
310
377
}
311
378
312
379
ImGui::TextUnformatted ( inFileText.c_str () );
@@ -1016,19 +1083,18 @@ void ParticleEditor::OnBnClickedButtonUpdate() {
1016
1083
}
1017
1084
1018
1085
void ParticleEditor::SelectParticle ( const char *name ) {
1019
- int index = comboParticle.FindIndex ( name );
1020
- if ( index >= 0 ) {
1021
- comboParticleSel = index;
1022
- UpdateParticleData ();
1023
- }
1086
+ idDeclParticle *decl = static_cast <idDeclParticle*>( const_cast <idDecl*>( declManager->FindType ( DECL_PARTICLE, name, false ) ) );
1087
+
1088
+ SetCurParticle ( decl );
1089
+ }
1090
+
1091
+ void ParticleEditor::SetCurParticle ( idDeclParticle *dp ) {
1092
+ curParticle = dp;
1093
+ UpdateParticleData ();
1024
1094
}
1025
1095
1026
1096
idDeclParticle *ParticleEditor::GetCurParticle () {
1027
- int index = comboParticleSel;
1028
- if ( index < 0 ) {
1029
- return NULL ;
1030
- }
1031
- return static_cast <idDeclParticle *>( const_cast <idDecl *>( declManager->DeclByIndex ( DECL_PARTICLE, index ) ) );
1097
+ return curParticle;
1032
1098
}
1033
1099
1034
1100
void ParticleEditor::UpdateParticleData () {
@@ -1049,16 +1115,11 @@ void ParticleEditor::UpdateParticleData() {
1049
1115
}
1050
1116
listStagesSel = 0 ;
1051
1117
OnLbnSelchangeListStages ();
1052
- inFileText = idStr::Format ( " Particle file: %s " , idp->GetFileName () );
1118
+ inFileText = idStr::Format ( " %s (%s) " , idp-> GetName () , idp->GetFileName () );
1053
1119
1054
1120
SetParticleView ();
1055
1121
}
1056
1122
1057
- void ParticleEditor::OnCbnSelchangeComboParticles () {
1058
- UpdateParticleData ();
1059
- }
1060
-
1061
-
1062
1123
void ParticleEditor::OnCbnSelchangeComboPath () {
1063
1124
DlgVarsToCurStage ();
1064
1125
CurStageToDlgVars ();
@@ -1243,7 +1304,7 @@ void ParticleEditor::RemoveStageThink()
1243
1304
listStagesItemData.Remove ( index, newIndex );
1244
1305
listStagesSel = index;
1245
1306
idp->stages .RemoveIndex ( newIndex );
1246
- OnCbnSelchangeComboParticles ();
1307
+ UpdateParticleData ();
1247
1308
ShowCurrentStage ();
1248
1309
}
1249
1310
}
@@ -1476,16 +1537,6 @@ void ParticleEditor::OnBnClickedButtonSave() {
1476
1537
idp->Save ();
1477
1538
}
1478
1539
1479
- void ParticleEditor::EnumParticles () {
1480
- comboParticle.Clear ();
1481
- for ( int i = 0 ; i < declManager->GetNumDecls ( DECL_PARTICLE ); i++ ) {
1482
- const idDecl *idp = declManager->DeclByIndex ( DECL_PARTICLE, i );
1483
- comboParticle.Append ( idp->GetName () );
1484
- }
1485
- comboParticleSel = 0 ;
1486
- OnCbnSelchangeComboParticles ();
1487
- }
1488
-
1489
1540
/* void VectorCallBack(idQuat rotation) {
1490
1541
ParticleEditor::Instance().SetVectorControlUpdate( rotation );
1491
1542
}*/
@@ -1550,7 +1601,7 @@ void ParticleEditor::Reset()
1550
1601
sliderFadeFraction.SetRange ( 0 , 20 );
1551
1602
sliderFadeFraction.SetValueRange ( 0 .0f , 1 .0f );
1552
1603
1553
- EnumParticles ();
1604
+ UpdateParticleData ();
1554
1605
SetParticleView ();
1555
1606
1556
1607
buttonSaveParticleEntitiesEnabled = false ;
0 commit comments