@@ -79,14 +79,133 @@ bool RangeSlider::Draw( const char *label, float itemWidth, float sliderWidth )
79
79
return changed;
80
80
}
81
81
82
+ ParticleNew::ParticleNew ()
83
+ : fileSelection(-1 )
84
+ , prtFiles()
85
+ , fileName( " " )
86
+ , name( " " )
87
+ , errorText( " " )
88
+ , dp( NULL )
89
+ , state(DONE)
90
+ {
91
+ }
92
+
93
+ void ParticleNew::Start () {
94
+ prtFiles.Clear ();
95
+
96
+ idFileList* files = fileSystem->ListFiles ( " particles" , " .prt" , true , true );
97
+ for ( int i = 0 ; i < files->GetNumFiles (); i++ )
98
+ {
99
+ idStr file = files->GetFile ( i );
100
+
101
+ file.StripPath ();
102
+ file.StripFileExtension ();
103
+
104
+ prtFiles.Append ( file );
105
+ }
106
+ fileSystem->FreeFileList ( files );
107
+
108
+ fileSelection = -1 ;
109
+ fileName.Clear ();
110
+ errorText.Clear ();
111
+ dp = NULL ;
112
+ state = NAME;
113
+
114
+ ImGui::OpenPopup ( " New Particle System" );
115
+ }
116
+
117
+ bool ParticleNew::Draw () {
118
+ if ( state == DONE ) {
119
+ return false ;
120
+ }
121
+
122
+ bool accepted = false ;
123
+ bool canceled = false ;
124
+
125
+ if ( ImGui::BeginPopupModal ( " New Particle System" , nullptr , ImGuiWindowFlags_AlwaysAutoResize ) ) {
126
+ ImGui::TextColored ( ImVec4 ( 1 , 0 , 0 , 1 ), errorText );
127
+
128
+ if ( ImGui::InputTextStr ( " File Name" , &fileName ) ) {
129
+ // nop
130
+ }
131
+
132
+ if ( ImGui::BeginListBox ( " Files##prtFileSelect" ) ) {
133
+ for ( int i = 0 ; i < prtFiles.Num (); i++ )
134
+ {
135
+ if ( fileName.Length () && prtFiles[i].Find ( fileName.c_str (), false ) == -1 ) {
136
+ continue ;
137
+ }
138
+
139
+ bool selected = ( i == fileSelection );
140
+
141
+ ImGui::PushID ( i );
142
+ if ( ImGui::Selectable ( prtFiles[i].c_str (), selected ) ) {
143
+ fileSelection = i;
144
+ fileName = prtFiles[fileSelection];
145
+ }
146
+ if ( selected ) {
147
+ ImGui::SetItemDefaultFocus ();
148
+ }
149
+ ImGui::PopID ();
150
+ }
151
+
152
+ ImGui::EndListBox ();
153
+ }
154
+
155
+ if ( ImGui::InputTextStr ( " Name" , &name ) ) {
156
+ // nop
157
+ }
158
+
159
+ if ( ImGui::Button ( " OK" ) ) {
160
+ errorText.Clear ();
161
+
162
+ if ( name.IsEmpty () ) {
163
+ errorText += " Please enter a name\n " ;
164
+ accepted = false ;
165
+ }
166
+
167
+ idDeclParticle *newDecl = static_cast <idDeclParticle*>( const_cast <idDecl*>( declManager->FindType ( DECL_PARTICLE, name.c_str (), false ) ) );
168
+ if ( newDecl ) {
169
+ errorText += idStr::Format ( " Particle System %s already exists in %s. Please select a different name\n " , name.c_str (), newDecl->GetFileName () );
170
+ accepted = false ;
171
+ }
172
+
173
+ if ( errorText.IsEmpty () ) {
174
+ idStr fullName;
175
+
176
+ fullName = " particles/" ;
177
+ fullName += fileName;
178
+ fullName += " .prt" ;
179
+
180
+ // create it
181
+ dp = static_cast <idDeclParticle*>( declManager->CreateNewDecl ( DECL_PARTICLE, name.c_str (), fullName.c_str () ) );
182
+ state = DONE;
183
+
184
+ accepted = true ;
185
+ ImGui::CloseCurrentPopup ();
186
+ }
187
+ }
188
+ ImGui::SameLine ();
189
+ if ( ImGui::Button ( " Cancel" ) ) {
190
+ accepted = false ;
191
+ state = DONE;
192
+ ImGui::CloseCurrentPopup ();
193
+ }
194
+
195
+ ImGui::EndPopup ();
196
+ }
197
+
198
+ return accepted;
199
+ }
200
+
82
201
ParticleEditor& ParticleEditor::Instance ()
83
202
{
84
203
static ParticleEditor instance;
85
204
return instance;
86
205
}
87
206
88
207
ParticleEditor::ParticleEditor ()
89
- : fileSelection( 0 )
208
+ : particleNewDlg( )
90
209
, colorDlg( " Color" )
91
210
, fadeColorDlg( " Fade Color" )
92
211
, entityColorDlg( " Entity Color" )
@@ -138,68 +257,18 @@ void ParticleEditor::Draw()
138
257
ImGui::EndMenuBar ();
139
258
}
140
259
141
- if ( clickedNew )
142
- {
143
- ImGui::OpenPopup ( " New Particle System" );
260
+ if ( clickedNew ) {
261
+ particleNewDlg.Start ();
144
262
}
145
263
146
- if ( ImGui::BeginPopupModal ( " New Particle System" ) )
147
- {
148
- if ( prtFiles.Num () == 0 )
149
- {
150
- idFileList* files = fileSystem->ListFiles ( " particles" , " .prt" , true , true );
151
- for ( int i = 0 ; i < files->GetNumFiles (); i++ )
152
- {
153
- prtFiles.Append ( files->GetFile ( i ) );
154
- }
155
- fileSystem->FreeFileList ( files );
156
- }
157
-
158
- ImGui::BeginListBox ( " ##prtFileSelect" );
159
- for ( int i = 0 ; i < prtFiles.Num (); i++ )
160
- {
161
- if ( ImGui::ListBox ( " Files" , &fileSelection, StringListItemGetter, &prtFiles, prtFiles.Num () ) )
162
- {
163
- fileName = prtFiles[fileSelection];
164
- }
165
- }
166
- ImGui::EndListBox ();
167
-
168
- ImGui::SameLine ();
169
- ImGui::SmallButton ( " New File" );
170
-
171
- ImGui::InputTextStr ( " Particle System Name" , &fileName );
172
- if ( ImGui::Button ( " Create" ) )
173
- {
174
- idStr prtName = fileName;
175
- prtName.StripPath ();
176
- prtName.StripFileExtension ();
264
+ if ( particleNewDlg.Draw () ) {
265
+ idDeclParticle* dp = particleNewDlg.GetParticle ();
177
266
178
- if ( !prtName.IsEmpty () )
179
- {
180
- idDeclParticle *newDecl = static_cast <idDeclParticle*>( const_cast <idDecl*>( declManager->FindType ( DECL_PARTICLE, prtName.c_str (), false ) ) );
181
- if ( !newDecl )
182
- {
183
- // create it
184
- newDecl = static_cast <idDeclParticle*>( declManager->CreateNewDecl ( DECL_PARTICLE, prtName.c_str (), fileName.c_str () ) );
185
- }
267
+ if ( dp ) {
268
+ comboParticleSel = comboParticle.Append ( dp->GetName () );
186
269
187
- comboParticleSel = comboParticle.Append ( prtName );
188
-
189
- OnCbnSelchangeComboParticles ();
190
-
191
- ImGui::CloseCurrentPopup ();
192
- }
193
- }
194
-
195
- ImGui::SameLine ();
196
- if ( ImGui::Button ( " Close" ) )
197
- {
198
- prtFiles.Clear ();
199
- ImGui::CloseCurrentPopup ();
270
+ OnCbnSelchangeComboParticles ();
200
271
}
201
-
202
- ImGui::EndPopup ();
203
272
}
204
273
205
274
if ( openedParticleBrowser )
0 commit comments