/
ParticleEditor.cpp
1623 lines (1274 loc) · 59 KB
/
ParticleEditor.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
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "ParticleEditor.h"
#include "i18n.h"
#include "imainframe.h"
#include "iuimanager.h"
#include "iparticles.h"
#include "iparticlestage.h"
#include "igame.h"
#include "itextstream.h"
#include "wxutil/FileChooser.h"
#include "wxutil/dialog/MessageBox.h"
#include "wxutil/dialog/Dialog.h"
#include "wxutil/EntryAbortedException.h"
#include <wx/button.h>
#include <wx/spinctrl.h>
#include <wx/sizer.h>
#include <wx/splitter.h>
#include <wx/textctrl.h>
#include <wx/panel.h>
#include <wx/checkbox.h>
#include <wx/slider.h>
#include <wx/radiobut.h>
#include <wx/stattext.h>
#include <wx/notebook.h>
#include "os/fs.h"
#include "os/file.h"
#include "os/path.h"
#include "util/ScopedBoolLock.h"
#include "string/predicate.h"
namespace ui
{
using namespace particles;
// CONSTANTS
namespace
{
const char* const DIALOG_TITLE = N_("Particle Editor");
const std::string RKEY_ROOT = "user/ui/particleEditor/";
const std::string RKEY_SPLIT_POS = RKEY_ROOT + "splitPos";
const std::string RKEY_WINDOW_STATE = RKEY_ROOT + "window";
const std::string RKEY_RECENT_PATH = RKEY_ROOT + "recentSavePath";
const std::string EDIT_SUFFIX = "___editor";
}
namespace
{
// Columns for the def list
struct DefColumns :
public wxutil::TreeModel::ColumnRecord
{
DefColumns() :
name(add(wxutil::TreeModel::Column::String))
{}
wxutil::TreeModel::Column name;
};
DefColumns& DEF_COLS() { static DefColumns _i; return _i; }
// Columns for the stages list
struct StageColumns :
public wxutil::TreeModel::ColumnRecord
{
StageColumns() :
name(add(wxutil::TreeModel::Column::String)),
index(add(wxutil::TreeModel::Column::Integer)),
visible(add(wxutil::TreeModel::Column::Boolean))
{}
wxutil::TreeModel::Column name;
wxutil::TreeModel::Column index;
wxutil::TreeModel::Column visible;
};
StageColumns& STAGE_COLS() { static StageColumns _i; return _i; }
}
ParticleEditor::ParticleEditor() :
DialogBase(DIALOG_TITLE),
_defList(new wxutil::TreeModel(DEF_COLS(), true)),
_defView(NULL),
_stageList(new wxutil::TreeModel(STAGE_COLS(), true)),
_stageView(NULL),
_callbacksDisabled(false),
_saveInProgress(false)
{
loadNamedPanel(this, "ParticleEditorMainPanel");
// Wire up the close button
findNamedObject<wxButton>(this, "ParticleEditorCloseButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onClose), NULL, this);
findNamedObject<wxButton>(this, "ParticleEditorNewDefButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onNewParticle), NULL, this);
findNamedObject<wxButton>(this, "ParticleEditorSaveDefButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onSaveParticle), NULL, this);
findNamedObject<wxButton>(this, "ParticleEditorCopyDefButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onCloneCurrentParticle), NULL, this);
// Set up the preview
wxPanel* previewPanel = findNamedObject<wxPanel>(this, "ParticleEditorPreviewPanel");
_preview.reset(new wxutil::ParticlePreview(previewPanel));
previewPanel->GetSizer()->Add(_preview->getWidget(), 1, wxEXPAND);
// Set the default size of the window
FitToScreen(0.6f, 0.6f);
// Setup the splitter and preview
wxSplitterWindow* splitter = findNamedObject<wxSplitterWindow>(this, "ParticleEditorSplitter");
splitter->SetSashPosition(GetSize().GetWidth() * 0.6f);
splitter->SetMinimumPaneSize(10); // disallow unsplitting
setupParticleDefList();
setupParticleStageList();
setupSettingsPages();
Layout();
Fit();
// Connect the window position tracker
_windowPosition.loadFromPath(RKEY_WINDOW_STATE);
_windowPosition.connect(this);
_windowPosition.applyPosition();
_panedPosition.connect(splitter);
_panedPosition.loadFromPath(RKEY_SPLIT_POS);
CenterOnParent();
// Fire the selection changed signal to initialise the sensitivity
handleDefSelChanged();
handleStageSelChanged();
}
bool ParticleEditor::_onDeleteEvent()
{
if (!promptUserToSaveChanges(false)) return true; // action not allowed or cancelled
// Pass to base class, which defaults to "ok, let's close"
return DialogBase::_onDeleteEvent();
}
void ParticleEditor::setupParticleDefList()
{
wxPanel* panel = findNamedObject<wxPanel>(this, "ParticleEditorDefinitionView");
_defView = wxutil::TreeView::CreateWithModel(panel, _defList.get(), wxDV_NO_HEADER);
panel->GetSizer()->Add(_defView, 1, wxEXPAND);
// Single text column
_defView->AppendTextColumn(_("Particle"), DEF_COLS().name.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE);
// Apply full-text search to the column
_defView->AddSearchColumn(DEF_COLS().name);
populateParticleDefList();
// Connect up the selection changed callback
_defView->Connect(wxEVT_DATAVIEW_SELECTION_CHANGED,
wxDataViewEventHandler(ParticleEditor::_onDefSelChanged), NULL, this);
}
void ParticleEditor::populateParticleDefList()
{
_selectedDefIter = wxDataViewItem();
_defList->Clear();
// Create and use a ParticlesVisitor to populate the list
GlobalParticlesManager().forEachParticleDef([&] (const IParticleDef& particle)
{
// Add the Def name to the list store
wxutil::TreeModel::Row row = _defList->AddItem();
row[DEF_COLS().name] = particle.getName();
row.SendItemAdded();
});
}
void ParticleEditor::selectParticleDef(const std::string& particleDefName)
{
wxDataViewItem found = _defList->FindString(particleDefName, DEF_COLS().name);
if (found.IsOk())
{
_defView->Select(found);
handleDefSelChanged();
}
}
void ParticleEditor::setupParticleStageList()
{
wxPanel* panel = findNamedObject<wxPanel>(this, "ParticleEditorStageView");
_stageView = wxutil::TreeView::CreateWithModel(panel, _stageList.get(), wxDV_NO_HEADER);
panel->GetSizer()->Add(_stageView, 1, wxEXPAND);
// Single text column
_stageView->AppendTextColumn(_("Stage"), DEF_COLS().name.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE);
// Connect up the selection changed callback
_stageView->Connect(wxEVT_DATAVIEW_SELECTION_CHANGED,
wxDataViewEventHandler(ParticleEditor::_onStageSelChanged), NULL, this);
// Connect the stage control buttons
findNamedObject<wxButton>(this, "ParticleEditorAddStageButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onAddStage), NULL, this);
findNamedObject<wxButton>(this, "ParticleEditorRemoveStageButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onRemoveStage), NULL, this);
findNamedObject<wxButton>(this, "ParticleEditorToggleStageButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onToggleStage), NULL, this);
findNamedObject<wxButton>(this, "ParticleEditorMoveUpStageButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onMoveUpStage), NULL, this);
findNamedObject<wxButton>(this, "ParticleEditorMoveDownStageButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onMoveDownStage), NULL, this);
findNamedObject<wxButton>(this, "ParticleEditorDuplicateStageButton")->Connect(
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onDuplicateStage), NULL, this);
}
wxSpinCtrlDouble* ParticleEditor::convertToSpinCtrlDouble(wxSpinCtrl* spinCtrlToReplace, double min, double max, double increment, int digits)
{
wxSpinCtrlDouble* spinCtrlDouble = new wxSpinCtrlDouble(spinCtrlToReplace->GetParent(), wxID_ANY);
spinCtrlDouble->SetRange(min, max);
spinCtrlDouble->SetDigits(digits);
spinCtrlDouble->SetIncrement(increment);
spinCtrlDouble->SetMaxSize(wxSize(70, -1));
wxString name = spinCtrlToReplace->GetName();
spinCtrlToReplace->GetContainingSizer()->Replace(spinCtrlToReplace, spinCtrlDouble);
spinCtrlToReplace->Destroy();
spinCtrlDouble->SetName(name);
spinCtrlDouble->GetContainingSizer()->Layout();
return spinCtrlDouble;
}
wxSpinCtrlDouble* ParticleEditor::convertToSpinCtrlDouble(const std::string& name, double min, double max, double increment, int digits)
{
return convertToSpinCtrlDouble(findNamedObject<wxSpinCtrl>(this, name), min, max, increment, digits);
}
void ParticleEditor::setupSettingsPages()
{
// Depth Hack
wxSpinCtrlDouble* depthHack = convertToSpinCtrlDouble(
findNamedObject<wxSpinCtrl>(this, "ParticleEditorDepthHack"),
0, 999, 0.1, 2);
depthHack->Connect(wxEVT_SPINCTRLDOUBLE,
wxSpinDoubleEventHandler(ParticleEditor::_onDepthHackChanged), NULL, this);
// SHADER
findNamedObject<wxTextCtrl>(this, "ParticleEditorStageShader")->Connect(
wxEVT_TEXT, wxCommandEventHandler(ParticleEditor::_onShaderControlsChanged), NULL, this);
findNamedObject<wxTextCtrl>(this, "ParticleEditorStageColour")->Connect(
wxEVT_TEXT, wxCommandEventHandler(ParticleEditor::_onShaderControlsChanged), NULL, this);
findNamedObject<wxTextCtrl>(this, "ParticleEditorStageFadeColour")->Connect(
wxEVT_TEXT, wxCommandEventHandler(ParticleEditor::_onShaderControlsChanged), NULL, this);
findNamedObject<wxCheckBox>(this, "ParticleEditorStageUseEntityColour")->Connect(
wxEVT_CHECKBOX, wxCommandEventHandler(ParticleEditor::_onShaderControlsChanged), NULL, this);
convertToSpinCtrlDouble("ParticleEditorStageFadeInFrac", 0, 1, 0.01, 2);
convertToSpinCtrlDouble("ParticleEditorStageFadeOutFrac", 0, 1, 0.01, 2);
convertToSpinCtrlDouble("ParticleEditorStageFadeIdxFrac", 0, 1, 0.01, 2);
convertToSpinCtrlDouble("ParticleEditorStageAnimRate", 0, 600, 0.1, 2);
connectSpinner("ParticleEditorStageFadeInFrac", &ParticleEditor::_onShaderControlsChanged);
connectSpinner("ParticleEditorStageFadeOutFrac", &ParticleEditor::_onShaderControlsChanged);
connectSpinner("ParticleEditorStageFadeIdxFrac", &ParticleEditor::_onShaderControlsChanged);
connectSpinner("ParticleEditorStageAnimFrames", &ParticleEditor::_onShaderControlsChanged);
connectSpinner("ParticleEditorStageAnimRate", &ParticleEditor::_onShaderControlsChanged);
// COUNT
convertToSpinCtrlDouble("ParticleEditorStageDuration", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageBunching", 0, 1, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageTimeOffset", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageDeadTime", 0, 999, 0.1, 2);
connectSpinner("ParticleEditorStageCount", &ParticleEditor::_onCountTimeControlsChanged);
connectSpinner("ParticleEditorStageDuration", &ParticleEditor::_onCountTimeControlsChanged);
connectSpinner("ParticleEditorStageBunching", &ParticleEditor::_onCountTimeControlsChanged);
connectSpinner("ParticleEditorStageCycles", &ParticleEditor::_onCountTimeControlsChanged);
connectSpinner("ParticleEditorStageTimeOffset", &ParticleEditor::_onCountTimeControlsChanged);
connectSpinner("ParticleEditorStageDeadTime", &ParticleEditor::_onCountTimeControlsChanged);
// DISTRIBUTION
findNamedObject<wxRadioButton>(this, "ParticleEditorStageShapeRect")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDistributionControlsChanged), NULL, this);
findNamedObject<wxRadioButton>(this, "ParticleEditorStageShapeCyl")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDistributionControlsChanged), NULL, this);
findNamedObject<wxRadioButton>(this, "ParticleEditorStageSpherical")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDistributionControlsChanged), NULL, this);
convertToSpinCtrlDouble("ParticleEditorStageXSize", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageYSize", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageZSize", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageRingSize", 0, 999, 0.1, 2);
connectSpinner("ParticleEditorStageXSize", &ParticleEditor::_onDistributionControlsChanged);
connectSpinner("ParticleEditorStageYSize", &ParticleEditor::_onDistributionControlsChanged);
connectSpinner("ParticleEditorStageZSize", &ParticleEditor::_onDistributionControlsChanged);
connectSpinner("ParticleEditorStageRingSize", &ParticleEditor::_onDistributionControlsChanged);
findNamedObject<wxTextCtrl>(this, "ParticleEditorStageOffset")->Connect(
wxEVT_TEXT, wxCommandEventHandler(ParticleEditor::_onDistributionControlsChanged), NULL, this);
findNamedObject<wxCheckBox>(this, "ParticleEditorStageRandomDist")->Connect(
wxEVT_CHECKBOX, wxCommandEventHandler(ParticleEditor::_onDistributionControlsChanged), NULL, this);
// DIRECTION / ORIENTATION
findNamedObject<wxRadioButton>(this, "ParticleEditorStageCone")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDirectionControlsChanged), NULL, this);
findNamedObject<wxRadioButton>(this, "ParticleEditorStageOutward")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDirectionControlsChanged), NULL, this);
convertToSpinCtrlDouble("ParticleEditorStageConeAngle", 0, 180, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageUpwardBias", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageAimedTime", 0, 60, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageInitialAngle", 0, 359, 0.1, 2);
connectSpinner("ParticleEditorStageConeAngle", &ParticleEditor::_onDirectionControlsChanged);
connectSpinner("ParticleEditorStageUpwardBias", &ParticleEditor::_onDirectionControlsChanged);
findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientView")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDirectionControlsChanged), NULL, this);
findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientAimed")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDirectionControlsChanged), NULL, this);
findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientX")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDirectionControlsChanged), NULL, this);
findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientY")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDirectionControlsChanged), NULL, this);
findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientZ")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onDirectionControlsChanged), NULL, this);
connectSpinner("ParticleEditorStageTrails", &ParticleEditor::_onDirectionControlsChanged);
connectSpinner("ParticleEditorStageAimedTime", &ParticleEditor::_onDirectionControlsChanged);
connectSpinner("ParticleEditorStageInitialAngle", &ParticleEditor::_onDirectionControlsChanged);
// SIZE / SPEED / ASPECT
convertToSpinCtrlDouble("ParticleEditorStageSpeedFrom", -500, 500, 0.5, 1);
convertToSpinCtrlDouble("ParticleEditorStageSpeedTo", -500, 500, 0.5, 1);
convertToSpinCtrlDouble("ParticleEditorStageSizeFrom", 0, 500, 0.5, 1);
convertToSpinCtrlDouble("ParticleEditorStageSizeTo", 0, 500, 0.5, 1);
convertToSpinCtrlDouble("ParticleEditorStageRotationSpeedFrom", 0, 500, 0.5, 1);
convertToSpinCtrlDouble("ParticleEditorStageRotationSpeedTo", 0, 500, 0.5, 1);
convertToSpinCtrlDouble("ParticleEditorStageAspectFrom", 0, 500, 0.5, 1);
convertToSpinCtrlDouble("ParticleEditorStageAspectTo", 0, 500, 0.5, 1);
convertToSpinCtrlDouble("ParticleEditorStageGravity", -999, 999, 0.1, 1);
convertToSpinCtrlDouble("ParticleEditorStageBoundsExpansion", 0, 2500, 0.1, 2);
connectSpinner("ParticleEditorStageSpeedFrom", &ParticleEditor::_onSizeControlsChanged);
connectSpinner("ParticleEditorStageSpeedTo", &ParticleEditor::_onSizeControlsChanged);
connectSpinner("ParticleEditorStageSizeFrom", &ParticleEditor::_onSizeControlsChanged);
connectSpinner("ParticleEditorStageSizeTo", &ParticleEditor::_onSizeControlsChanged);
connectSpinner("ParticleEditorStageRotationSpeedFrom", &ParticleEditor::_onSizeControlsChanged);
connectSpinner("ParticleEditorStageRotationSpeedTo", &ParticleEditor::_onSizeControlsChanged);
connectSpinner("ParticleEditorStageAspectFrom", &ParticleEditor::_onSizeControlsChanged);
connectSpinner("ParticleEditorStageAspectTo", &ParticleEditor::_onSizeControlsChanged);
connectSpinner("ParticleEditorStageGravity", &ParticleEditor::_onSizeControlsChanged);
connectSpinner("ParticleEditorStageBoundsExpansion", &ParticleEditor::_onSizeControlsChanged);
findNamedObject<wxCheckBox>(this, "ParticleEditorStageUseWorldGravity")->Connect(
wxEVT_CHECKBOX, wxCommandEventHandler(ParticleEditor::_onSizeControlsChanged), NULL, this);
// PATH
findNamedObject<wxRadioButton>(this, "ParticleEditorStagePathStandard")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onPathControlsChanged), NULL, this);
findNamedObject<wxRadioButton>(this, "ParticleEditorStagePathFlies")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onPathControlsChanged), NULL, this);
findNamedObject<wxRadioButton>(this, "ParticleEditorStagePathHelix")->Connect(
wxEVT_RADIOBUTTON, wxCommandEventHandler(ParticleEditor::_onPathControlsChanged), NULL, this);
convertToSpinCtrlDouble("ParticleEditorStageRadialSpeed", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageAxialSpeed", 0, 200, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageSphereRadius", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageCylSizeX", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageCylSizeY", 0, 999, 0.1, 2);
convertToSpinCtrlDouble("ParticleEditorStageCylSizeZ", 0, 999, 0.1, 2);
connectSpinner("ParticleEditorStageRadialSpeed", &ParticleEditor::_onPathControlsChanged);
connectSpinner("ParticleEditorStageAxialSpeed", &ParticleEditor::_onPathControlsChanged);
connectSpinner("ParticleEditorStageSphereRadius", &ParticleEditor::_onPathControlsChanged);
connectSpinner("ParticleEditorStageCylSizeX", &ParticleEditor::_onPathControlsChanged);
connectSpinner("ParticleEditorStageCylSizeY", &ParticleEditor::_onPathControlsChanged);
connectSpinner("ParticleEditorStageCylSizeZ", &ParticleEditor::_onPathControlsChanged);
}
void ParticleEditor::_onShaderControlsChanged(wxCommandEvent& ev)
{
if (_callbacksDisabled || !_currentDef || !_selectedStageIter.IsOk()) return;
IStageDef& stage = _currentDef->getStage(getSelectedStageIndex());
std::string material = findNamedObject<wxTextCtrl>(this, "ParticleEditorStageShader")->GetValue().ToStdString();
// Only assign a new material if it has actually changed, otherwise the whole particle gets re-shuffled
if (material != stage.getMaterialName())
{
stage.setMaterialName(material);
}
stage.setColour(string::convert<Vector4>(
findNamedObject<wxTextCtrl>(this, "ParticleEditorStageColour")->GetValue().ToStdString()));
stage.setUseEntityColour(findNamedObject<wxCheckBox>(this, "ParticleEditorStageUseEntityColour")->GetValue());
stage.setFadeColour(string::convert<Vector4>(
findNamedObject<wxTextCtrl>(this, "ParticleEditorStageFadeColour")->GetValue().ToStdString()));
stage.setFadeInFraction(getSpinButtonValueAsFloat("ParticleEditorStageFadeInFrac"));
stage.setFadeOutFraction(getSpinButtonValueAsFloat("ParticleEditorStageFadeOutFrac"));
stage.setFadeIndexFraction(getSpinButtonValueAsFloat("ParticleEditorStageFadeIdxFrac"));
stage.setAnimationFrames(getSpinButtonValueAsInt("ParticleEditorStageAnimFrames"));
stage.setAnimationRate(getSpinButtonValueAsFloat("ParticleEditorStageAnimRate"));
}
void ParticleEditor::_onCountTimeControlsChanged(wxCommandEvent& ev)
{
if (_callbacksDisabled || !_currentDef || !_selectedStageIter.IsOk()) return;
IStageDef& stage = _currentDef->getStage(getSelectedStageIndex());
stage.setCount(getSpinButtonValueAsInt("ParticleEditorStageCount"));
stage.setDuration(getSpinButtonValueAsFloat("ParticleEditorStageDuration"));
stage.setBunching(getSpinButtonValueAsFloat("ParticleEditorStageBunching"));
stage.setCycles(getSpinButtonValueAsInt("ParticleEditorStageCycles"));
stage.setTimeOffset(getSpinButtonValueAsFloat("ParticleEditorStageTimeOffset"));
stage.setDeadTime(getSpinButtonValueAsFloat("ParticleEditorStageDeadTime"));
}
void ParticleEditor::_onDistributionControlsChanged(wxCommandEvent& ev)
{
if (_callbacksDisabled || !_currentDef || !_selectedStageIter.IsOk()) return;
IStageDef& stage = _currentDef->getStage(getSelectedStageIndex());
if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageShapeRect")->GetValue())
{
stage.setDistributionType(IStageDef::DISTRIBUTION_RECT);
}
else if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageShapeCyl")->GetValue())
{
stage.setDistributionType(IStageDef::DISTRIBUTION_CYLINDER);
}
else if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageSpherical")->GetValue())
{
stage.setDistributionType(IStageDef::DISTRIBUTION_SPHERE);
}
bool useRingSize = stage.getDistributionType() != IStageDef::DISTRIBUTION_RECT;
findNamedObject<wxWindow>(this, "ParticleEditorStageRingSize")->Enable(useRingSize);
findNamedObject<wxSlider>(this, "ParticleEditorStageRingSizeSlider")->Enable(useRingSize);
findNamedObject<wxStaticText>(this, "ParticleEditorStageRingSizeLabel")->Enable(useRingSize);
stage.setDistributionParm(0, getSpinButtonValueAsFloat("ParticleEditorStageXSize"));
stage.setDistributionParm(1, getSpinButtonValueAsFloat("ParticleEditorStageYSize"));
stage.setDistributionParm(2, getSpinButtonValueAsFloat("ParticleEditorStageZSize"));
stage.setDistributionParm(3, getSpinButtonValueAsFloat("ParticleEditorStageRingSize"));
stage.setOffset(string::convert<Vector3>(
findNamedObject<wxTextCtrl>(this, "ParticleEditorStageOffset")->GetValue().ToStdString()));
stage.setRandomDistribution(
findNamedObject<wxCheckBox>(this, "ParticleEditorStageRandomDist")->GetValue());
}
void ParticleEditor::_onDirectionControlsChanged(wxCommandEvent& ev)
{
if (_callbacksDisabled || !_currentDef || !_selectedStageIter.IsOk()) return;
IStageDef& stage = _currentDef->getStage(getSelectedStageIndex());
if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageCone")->GetValue())
{
stage.setDirectionType(IStageDef::DIRECTION_CONE);
stage.setDirectionParm(0, getSpinButtonValueAsFloat("ParticleEditorStageConeAngle"));
}
else if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageOutward")->GetValue())
{
stage.setDirectionType(IStageDef::DIRECTION_OUTWARD);
stage.setDirectionParm(0, getSpinButtonValueAsFloat("ParticleEditorStageUpwardBias"));
}
findNamedObject<wxStaticText>(this, "ParticleEditorStageConeAngleLabel")->Enable(
stage.getDirectionType() == IStageDef::DIRECTION_CONE);
findNamedObject<wxWindow>(this, "ParticleEditorStageConeAngle")->Enable(
stage.getDirectionType() == IStageDef::DIRECTION_CONE);
findNamedObject<wxSlider>(this, "ParticleEditorStageConeAngleSlider")->Enable(
stage.getDirectionType() == IStageDef::DIRECTION_CONE);
findNamedObject<wxStaticText>(this, "ParticleEditorStageUpwardBiasLabel")->Enable(
stage.getDirectionType() == IStageDef::DIRECTION_OUTWARD);
findNamedObject<wxWindow>(this, "ParticleEditorStageUpwardBias")->Enable(
stage.getDirectionType() == IStageDef::DIRECTION_OUTWARD);
findNamedObject<wxSlider>(this, "ParticleEditorStageUpwardBiasSlider")->Enable(
stage.getDirectionType() == IStageDef::DIRECTION_OUTWARD);
if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientView")->GetValue())
{
stage.setOrientationType(IStageDef::ORIENTATION_VIEW);
}
else if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientAimed")->GetValue())
{
stage.setOrientationType(IStageDef::ORIENTATION_AIMED);
stage.setOrientationParm(0, getSpinButtonValueAsInt("ParticleEditorStageTrails"));
stage.setOrientationParm(1, getSpinButtonValueAsFloat("ParticleEditorStageAimedTime"));
}
else if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientX")->GetValue())
{
stage.setOrientationType(IStageDef::ORIENTATION_X);
}
else if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientY")->GetValue())
{
stage.setOrientationType(IStageDef::ORIENTATION_Y);
}
else if (findNamedObject<wxRadioButton>(this, "ParticleEditorStageOrientZ")->GetValue())
{
stage.setOrientationType(IStageDef::ORIENTATION_Z);
}
findNamedObject<wxWindow>(this, "ParticleEditorStageTrails")->Enable(
stage.getOrientationType() == IStageDef::ORIENTATION_AIMED);
findNamedObject<wxWindow>(this, "ParticleEditorStageTrailsSlider")->Enable(
stage.getOrientationType() == IStageDef::ORIENTATION_AIMED);
findNamedObject<wxWindow>(this, "ParticleEditorStageTrailsLabel")->Enable(
stage.getOrientationType() == IStageDef::ORIENTATION_AIMED);
findNamedObject<wxWindow>(this, "ParticleEditorStageAimedTime")->Enable(
stage.getOrientationType() == IStageDef::ORIENTATION_AIMED);
findNamedObject<wxWindow>(this, "ParticleEditorStageAimedTimeSlider")->Enable(
stage.getOrientationType() == IStageDef::ORIENTATION_AIMED);
findNamedObject<wxWindow>(this, "ParticleEditorStageTimeLabel")->Enable(
stage.getOrientationType() == IStageDef::ORIENTATION_AIMED);
stage.setInitialAngle(getSpinButtonValueAsFloat("ParticleEditorStageInitialAngle"));
}
void ParticleEditor::_onSizeControlsChanged(wxCommandEvent& ev)
{
if (_callbacksDisabled || !_currentDef || !_selectedStageIter.IsOk()) return;
IStageDef& stage = _currentDef->getStage(getSelectedStageIndex());
stage.getSize().setFrom(getSpinButtonValueAsFloat("ParticleEditorStageSizeFrom"));
stage.getSize().setTo(getSpinButtonValueAsFloat("ParticleEditorStageSizeTo"));
stage.getSpeed().setFrom(getSpinButtonValueAsFloat("ParticleEditorStageSpeedFrom"));
stage.getSpeed().setTo(getSpinButtonValueAsFloat("ParticleEditorStageSpeedTo"));
stage.getRotationSpeed().setFrom(getSpinButtonValueAsFloat("ParticleEditorStageRotationSpeedFrom"));
stage.getRotationSpeed().setTo(getSpinButtonValueAsFloat("ParticleEditorStageRotationSpeedTo"));
stage.getAspect().setFrom(getSpinButtonValueAsFloat("ParticleEditorStageAspectFrom"));
stage.getAspect().setTo(getSpinButtonValueAsFloat("ParticleEditorStageAspectTo"));
stage.setGravity(getSpinButtonValueAsFloat("ParticleEditorStageGravity"));
stage.setWorldGravityFlag(
findNamedObject<wxCheckBox>(this, "ParticleEditorStageUseWorldGravity")->GetValue());
stage.setBoundsExpansion(getSpinButtonValueAsFloat("ParticleEditorStageBoundsExpansion"));
}
void ParticleEditor::_onPathControlsChanged(wxCommandEvent& ev)
{
if (_callbacksDisabled || !_currentDef || !_selectedStageIter.IsOk()) return;
IStageDef& stage = _currentDef->getStage(getSelectedStageIndex());
if (findNamedObject<wxRadioButton>(this, "ParticleEditorStagePathStandard")->GetValue())
{
stage.setCustomPathType(IStageDef::PATH_STANDARD);
}
else if (findNamedObject<wxRadioButton>(this, "ParticleEditorStagePathFlies")->GetValue())
{
stage.setCustomPathType(IStageDef::PATH_FLIES);
stage.setCustomPathParm(0, getSpinButtonValueAsFloat("ParticleEditorStageRadialSpeed"));
stage.setCustomPathParm(1, getSpinButtonValueAsFloat("ParticleEditorStageAxialSpeed"));
stage.setCustomPathParm(2, getSpinButtonValueAsFloat("ParticleEditorStageSphereRadius"));
}
else if (findNamedObject<wxRadioButton>(this, "ParticleEditorStagePathHelix")->GetValue())
{
stage.setCustomPathType(IStageDef::PATH_HELIX);
stage.setCustomPathParm(0, getSpinButtonValueAsFloat("ParticleEditorStageCylSizeX"));
stage.setCustomPathParm(1, getSpinButtonValueAsFloat("ParticleEditorStageCylSizeY"));
stage.setCustomPathParm(2, getSpinButtonValueAsFloat("ParticleEditorStageCylSizeZ"));
stage.setCustomPathParm(3, getSpinButtonValueAsFloat("ParticleEditorStageRadialSpeed"));
stage.setCustomPathParm(4, getSpinButtonValueAsFloat("ParticleEditorStageAxialSpeed"));
}
updatePathWidgetSensitivity();
}
void ParticleEditor::_onDepthHackChanged(wxSpinDoubleEvent& ev)
{
if (_callbacksDisabled || !_currentDef) return;
_currentDef->setDepthHack(getSpinButtonValueAsFloat("ParticleEditorDepthHack"));
}
void ParticleEditor::updatePathWidgetSensitivity()
{
IStageDef& stage = _currentDef->getStage(getSelectedStageIndex());
// Sensitivity
bool useAnySpinner = stage.getCustomPathType() != IStageDef::PATH_STANDARD;
bool useFlies = stage.getCustomPathType() == IStageDef::PATH_FLIES;
findNamedObject<wxWindow>(this, "ParticleEditorStageRadialSpeedLabel")->Enable(useAnySpinner);
findNamedObject<wxWindow>(this, "ParticleEditorStageAxialSpeedLabel")->Enable(useAnySpinner);
findNamedObject<wxWindow>(this, "ParticleEditorStageRadialSpeed")->Enable(useAnySpinner);
findNamedObject<wxWindow>(this, "ParticleEditorStageRadialSpeedSlider")->Enable(useAnySpinner);
findNamedObject<wxWindow>(this, "ParticleEditorStageAxialSpeed")->Enable(useAnySpinner);
findNamedObject<wxWindow>(this, "ParticleEditorStageAxialSpeedSlider")->Enable(useAnySpinner);
findNamedObject<wxWindow>(this, "ParticleEditorStageSphereRadiusLabel")->Enable(useAnySpinner && useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageSphereRadius")->Enable(useAnySpinner && useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageSphereRadiusSlider")->Enable(useAnySpinner && useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageCylSizeXLabel")->Enable(useAnySpinner && !useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageCylSizeYLabel")->Enable(useAnySpinner && !useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageCylSizeZLabel")->Enable(useAnySpinner && !useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageCylSizeX")->Enable(useAnySpinner && !useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageCylSizeY")->Enable(useAnySpinner && !useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageCylSizeZ")->Enable(useAnySpinner && !useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageCylSizeXSlider")->Enable(useAnySpinner && !useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageCylSizeYSlider")->Enable(useAnySpinner && !useFlies);
findNamedObject<wxWindow>(this, "ParticleEditorStageCylSizeZSlider")->Enable(useAnySpinner && !useFlies);
}
void ParticleEditor::connectSpinner(const std::string& name, MemberMethod func)
{
wxWindow* spinctrl = findNamedObject<wxWindow>(this, name);
// By convention, the sliders carry the same name plus a "Slider" suffix
wxSlider* slider = tryGetNamedObject<wxSlider>(this, name + "Slider");
// Function object to update the spinctrl
std::function<void(double value)> updateSpinCtrl;
if (dynamic_cast<wxSpinCtrl*>(spinctrl) != NULL)
{
wxSpinCtrl* spin = static_cast<wxSpinCtrl*>(spinctrl);
// Regular integer-valued spinctrl
spinctrl->Bind(wxEVT_SPINCTRL, [=] (wxSpinEvent& ev)
{
(this->*func)(ev);
// Update slider when spinctrl is changing
if (slider != NULL)
{
slider->SetValue(spin->GetValue());
}
});
if (slider != NULL)
{
// Slider needs to have the same range as the spinner
slider->SetRange(spin->GetMin(), spin->GetMax());
}
updateSpinCtrl = [=] (double value)
{
spin->SetValue(value);
};
}
else if (dynamic_cast<wxSpinCtrlDouble*>(spinctrl) != NULL)
{
wxSpinCtrlDouble* spin = static_cast<wxSpinCtrlDouble*>(spinctrl);
int sliderFactor = static_cast<int>(1 / spin->GetIncrement());
// Float-valued spinctrl
spinctrl->Bind(wxEVT_SPINCTRLDOUBLE, [=] (wxSpinDoubleEvent& ev)
{
(this->*func)(ev);
// Update slider when spinctrl is changing
if (slider != NULL)
{
slider->SetValue(static_cast<int>(spin->GetValue() * sliderFactor));
}
});
if (slider != NULL)
{
// Slider needs to have the same range as the spinner, proportionally
slider->SetRange(spin->GetMin() * sliderFactor, spin->GetMax() * sliderFactor);
}
updateSpinCtrl = [=] (double value)
{
spin->SetValue(value / sliderFactor);
};
}
if (slider != NULL)
{
slider->Bind(wxEVT_SCROLL_CHANGED, [=] (wxScrollEvent& ev)
{
(this->*func)(ev);
// Update spinctrl when slider changes
updateSpinCtrl(slider->GetValue());
ev.Skip();
});
slider->Bind(wxEVT_SCROLL_THUMBTRACK, [=] (wxScrollEvent& ev)
{
(this->*func)(ev);
// Update spinctrl when slider changes
updateSpinCtrl(slider->GetValue());
ev.Skip();
});
}
}
float ParticleEditor::getSpinButtonValueAsFloat(const std::string& widgetName)
{
wxSpinCtrlDouble* sb = findNamedObject<wxSpinCtrlDouble>(this, widgetName);
return static_cast<float>(sb->GetValue());
}
int ParticleEditor::getSpinButtonValueAsInt(const std::string& widgetName)
{
wxSpinCtrl* sb = findNamedObject<wxSpinCtrl>(this, widgetName);
return sb->GetValue();
}
void ParticleEditor::activateEditPanels()
{
findNamedObject<wxStaticText>(this, "ParticleEditorStageLabel")->Enable(true);
findNamedObject<wxStaticText>(this, "ParticleEditorStageSettingsLabel")->Enable(true);
activateSettingsEditPanels();
}
void ParticleEditor::deactivateEditPanels()
{
findNamedObject<wxStaticText>(this, "ParticleEditorStageLabel")->Enable(false);
findNamedObject<wxPanel>(this, "ParticleEditorStagePanel")->Enable(false);
deactivateSettingsEditPanels();
}
void ParticleEditor::activateSettingsEditPanels()
{
findNamedObject<wxPanel>(this, "ParticleEditorStagePanel")->Enable(true);
findNamedObject<wxNotebook>(this, "ParticleEditorSettingsNotebook")->Enable(true);
}
void ParticleEditor::deactivateSettingsEditPanels()
{
findNamedObject<wxStaticText>(this, "ParticleEditorStageSettingsLabel")->Enable(false);
findNamedObject<wxNotebook>(this, "ParticleEditorSettingsNotebook")->Enable(false);
}
std::size_t ParticleEditor::getSelectedStageIndex()
{
// Get the selection and store it
wxDataViewItem item = _stageView->GetSelection();
if (item.IsOk())
{
wxutil::TreeModel::Row row(item, *_stageList);
int value = row[STAGE_COLS().index].getInteger();
if (value < 0)
{
throw std::logic_error("Invalid stage index stored in model.");
}
return value;
}
throw std::logic_error("Nothing selected, cannot get selected stage index.");
}
void ParticleEditor::selectStage(std::size_t index)
{
wxDataViewItem item = _stageList->FindInteger(index, STAGE_COLS().index);
_stageView->Select(item);
handleStageSelChanged();
}
void ParticleEditor::setSaveButtonsSensitivity(bool sensitive)
{
findNamedObject<wxButton>(this, "ParticleEditorSaveDefButton")->Enable(sensitive);
findNamedObject<wxButton>(this, "ParticleEditorCopyDefButton")->Enable(sensitive);
}
std::string ParticleEditor::getParticleNameFromIter(const wxDataViewItem& item)
{
if (!item.IsOk())
{
return "";
}
else
{
wxutil::TreeModel::Row row(item, *_defList);
return row[DEF_COLS().name];
}
}
void ParticleEditor::_onDefSelChanged(wxDataViewEvent& ev)
{
handleDefSelChanged();
}
void ParticleEditor::handleDefSelChanged()
{
// Get the selection and store it
wxDataViewItem item = _defView->GetSelection();
if (!promptUserToSaveChanges())
{
// Revert the selection (re-enter this function) and cancel the operation
_defView->Select(_selectedDefIter);
return;
}
if (_selectedDefIter.IsOk() && item.IsOk() && _selectedDefIter == item)
{
return; // nothing to do so far
}
// Selected particle changed, free the existing edit particle
releaseEditParticle();
// Store new selection
_selectedDefIter = item;
if (_selectedDefIter.IsOk())
{
// Copy the particle def and set it up for editing
setupEditParticle();
activateEditPanels();
setSaveButtonsSensitivity(true);
// Load particle data
updateWidgetsFromParticle();
}
else
{
_preview->setParticle("");
_stageView->UnselectAll();
_selectedStageIter = wxDataViewItem();
_stageList->Clear();
deactivateEditPanels();
setSaveButtonsSensitivity(false);
}
}
void ParticleEditor::_onStageSelChanged(wxDataViewEvent& ev)
{
handleStageSelChanged();
}
void ParticleEditor::handleStageSelChanged()
{
// Get the selection and store it
wxDataViewItem item = _stageView->GetSelection();
if (_selectedStageIter && item.IsOk() && _selectedStageIter == item)
{
return; // nothing to do so far
}
_selectedStageIter = item;
bool isStageSelected = false;
if (_selectedStageIter)
{
activateSettingsEditPanels();
// Activate delete, move and toggle buttons
isStageSelected = true;
wxutil::TreeModel::Row row(_selectedStageIter, *_stageList);
std::size_t index = row[STAGE_COLS().index].getInteger();
findNamedObject<wxButton>(this, "ParticleEditorMoveUpStageButton")->Enable(index > 0);
findNamedObject<wxButton>(this, "ParticleEditorMoveDownStageButton")->Enable(index < _currentDef->getNumStages() - 1);
}
else
{
// No valid selection
deactivateSettingsEditPanels();
// Deactivate delete, move and toggle buttons
isStageSelected = false;
findNamedObject<wxButton>(this, "ParticleEditorMoveUpStageButton")->Enable(false);
findNamedObject<wxButton>(this, "ParticleEditorMoveDownStageButton")->Enable(false);
}
findNamedObject<wxButton>(this, "ParticleEditorRemoveStageButton")->Enable(isStageSelected);
findNamedObject<wxButton>(this, "ParticleEditorToggleStageButton")->Enable(isStageSelected);
findNamedObject<wxButton>(this, "ParticleEditorDuplicateStageButton")->Enable(isStageSelected);
// Reload the current stage data
updateWidgetsFromStage();
}
void ParticleEditor::_onAddStage(wxCommandEvent& ev)
{
if (!_currentDef) return;
// Add a new stage at the end of the list
std::size_t newStage = _currentDef->addParticleStage();
reloadStageList();
selectStage(newStage);
}
void ParticleEditor::_onRemoveStage(wxCommandEvent& ev)
{
if (!_currentDef || !_selectedStageIter.IsOk()) return;
_currentDef->removeParticleStage(getSelectedStageIndex());
reloadStageList();
}
void ParticleEditor::_onToggleStage(wxCommandEvent& ev)
{
if (!_currentDef || !_selectedStageIter.IsOk()) return;
std::size_t index = getSelectedStageIndex();
IStageDef& stage = _currentDef->getStage(index);
stage.setVisible(!stage.isVisible());
reloadStageList();
selectStage(index);
}
void ParticleEditor::_onMoveUpStage(wxCommandEvent& ev)
{
if (!_currentDef) return;
std::size_t selIndex = getSelectedStageIndex();
assert(selIndex > 0);
_currentDef->swapParticleStages(selIndex, selIndex - 1);
reloadStageList();
selectStage(selIndex - 1);
}
void ParticleEditor::_onMoveDownStage(wxCommandEvent& ev)
{
if (!_currentDef) return;
std::size_t selIndex = getSelectedStageIndex();
assert(_currentDef->getNumStages() > 0 && selIndex < _currentDef->getNumStages() - 1);
_currentDef->swapParticleStages(selIndex, selIndex + 1);
reloadStageList();
selectStage(selIndex + 1);
}
void ParticleEditor::_onDuplicateStage(wxCommandEvent& ev)
{
if (!_currentDef) return;
std::size_t srcStageIndex = getSelectedStageIndex();
std::size_t newStageIndex = _currentDef->addParticleStage();
IStageDef& srcStage = _currentDef->getStage(srcStageIndex);
IStageDef& newStage = _currentDef->getStage(newStageIndex);
newStage.copyFrom(srcStage);