/
StimEditor.cpp
630 lines (514 loc) · 22.4 KB
/
StimEditor.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
#include "StimEditor.h"
#include "string/split.h"
#include "string/convert.h"
#include "i18n.h"
#include "SREntity.h"
#include <wx/menu.h>
#include <wx/checkbox.h>
#include <wx/spinctrl.h>
#include <wx/bmpcbox.h>
#include <wx/sizer.h>
#include "wxutil/ChoiceHelper.h"
#include "wxutil/menu/IconTextMenuItem.h"
namespace ui
{
StimEditor::StimEditor(wxWindow* mainPanel, StimTypes& stimTypes) :
ClassEditor(mainPanel, stimTypes),
_mainPanel(mainPanel)
{
setupPage();
// Setup the context menu items and connect them to the callbacks
createContextMenu();
update();
}
void StimEditor::setupPage()
{
wxPanel* listPanel = findNamedObject<wxPanel>(_mainPanel, "SREditorStimList");
createListView(listPanel);
setupEditPanel();
#ifdef USE_BMP_COMBO_BOX
_addType = findNamedObject<wxBitmapComboBox>(_mainPanel, "StimTypeComboBox");
#else
{
// Type selector box
wxControl* typeBox = findNamedObject<wxControl>(_mainPanel, "StimTypeComboBox");
// Replace the bitmap combo with an ordinary one
wxComboBox* combo = new wxComboBox(typeBox->GetParent(), wxID_ANY);
typeBox->GetContainingSizer()->Prepend(combo, 1, wxEXPAND | wxRIGHT, 6);
typeBox->Destroy();
_addType = combo;
_addType->SetName("StimTypeComboBox");
}
#endif
_addType->Bind(wxEVT_COMBOBOX, std::bind(&StimEditor::onAddTypeSelect, this, std::placeholders::_1));
auto addButton = findNamedObject<wxButton>(_mainPanel, "AddStimButton");
auto removeButton = findNamedObject<wxButton>(_mainPanel, "RemoveStimButton");
addButton->Bind(wxEVT_BUTTON, std::bind(&StimEditor::onAddSR, this, std::placeholders::_1));
removeButton->Bind(wxEVT_BUTTON, std::bind(&StimEditor::onRemoveSR, this, std::placeholders::_1));
reloadStimTypes();
}
void StimEditor::reloadStimTypes()
{
if (_stimTypes.getStimMap().empty())
{
_stimTypes.reload();
}
_stimTypes.populateComboBox(_addType);
_stimTypes.populateComboBox(_type);
}
void StimEditor::setEntity(const SREntityPtr& entity)
{
// Pass the call to the base class
ClassEditor::setEntity(entity);
if (entity)
{
wxutil::TreeModel::Ptr stimStore = _entity->getStimStore();
_list->AssociateModel(stimStore.get());
// Trigger column width reevaluation
stimStore->ItemChanged(stimStore->GetRoot());
}
else
{
// wxWidgets 3.0.0 crashes when associating a NULL model, so use a dummy model
// to release the old one
wxutil::TreeModel* dummyStore = new wxutil::TreeModel(SREntity::getColumns(), true);
_list->AssociateModel(dummyStore);
}
}
void StimEditor::setupEditPanel()
{
#ifdef USE_BMP_COMBO_BOX
// Type Selector
_type = findNamedObject<wxBitmapComboBox>(_mainPanel, "StimEditorTypeCombo");
#else
// Response property section
wxControl* typeBox = findNamedObject<wxControl>(_mainPanel, "StimEditorTypeCombo");
// Replace the bitmap combo with an ordinary one
wxComboBox* combo = new wxComboBox(typeBox->GetParent(), wxID_ANY);
typeBox->GetContainingSizer()->Add(combo, 1, wxEXPAND);
typeBox->Destroy();
_type = combo;
_type->SetName("StimEditorTypeCombo");
#endif
_stimTypes.populateComboBox(_type);
_type->Connect(wxEVT_COMBOBOX, wxCommandEventHandler(StimEditor::onStimTypeSelect), NULL, this);
_propertyWidgets.active = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorActive");
// Timer Time
_propertyWidgets.timer.toggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorActivationTimer");
_propertyWidgets.timer.entryHBox = findNamedObject<wxPanel>(_mainPanel, "StimEditorActivationTimerPanel");
_propertyWidgets.timer.hour = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorAcivationTimerHour");
_propertyWidgets.timer.minute = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorAcivationTimerMinute");
_propertyWidgets.timer.second = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorAcivationTimerSecond");
_propertyWidgets.timer.millisecond = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorAcivationTimerMS");
// Timer type
_propertyWidgets.timer.typeToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorTimerRestarts");
_propertyWidgets.timer.reloadHBox = findNamedObject<wxPanel>(_mainPanel, "StimEditorTimerRestartPanel");
_propertyWidgets.timer.reloadEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorTimerReloadsTimes");
_propertyWidgets.timer.reloadEntry->SetMinClientSize(wxSize(_propertyWidgets.timer.reloadEntry->GetCharWidth() * 9, -1));
_propertyWidgets.timer.reloadToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorTimerReloads");
_propertyWidgets.timer.waitToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorTimerWaitsForStart");
// Time Interval
_propertyWidgets.timeIntToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorTimeInterval");
_propertyWidgets.timeIntEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorTimeIntervalValue");
_propertyWidgets.timeUnitLabel = findNamedObject<wxStaticText>(_mainPanel, "StimEditorTimeIntervalUnitLabel");
// Duration
_propertyWidgets.durationToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorDuration");
_propertyWidgets.durationEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorDurationValue");
_propertyWidgets.durationUnitLabel = findNamedObject<wxStaticText>(_mainPanel, "StimEditorDurationUnitLabel");
// Radius / Use Bounds
_propertyWidgets.radiusToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorRadius");
_propertyWidgets.radiusEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorRadiusValue");
_propertyWidgets.useBounds = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorRadiusUseBounds");
// Final Radius
_propertyWidgets.finalRadiusToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorRadiusChangesOverTime");
_propertyWidgets.finalRadiusEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorRadiusChangesOverTimeValue");
// Magnitude
_propertyWidgets.magnToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorMagnitude");
_propertyWidgets.magnEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorMagnitudeValue");
// Falloff exponent
_propertyWidgets.falloffToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorMagnitudeFalloff");
wxPanel* falloffPanel = findNamedObject<wxPanel>(_mainPanel, "StimEditorMagnitudePanel");
_propertyWidgets.falloffEntry = new wxSpinCtrlDouble(falloffPanel, wxID_ANY);
_propertyWidgets.falloffEntry->SetRange(-10, +10);
_propertyWidgets.falloffEntry->SetIncrement(0.1);
_propertyWidgets.falloffEntry->SetValue(0);
_propertyWidgets.falloffEntry->SetMinClientSize(wxSize(7*_propertyWidgets.falloffEntry->GetCharWidth(), -1));
falloffPanel->GetSizer()->Add(_propertyWidgets.falloffEntry, 2);
// Max fire count
_propertyWidgets.maxFireCountToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorMaxFireCount");
_propertyWidgets.maxFireCountEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorMaxFireCountValue");
// Chance variable
_propertyWidgets.chanceToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorChance");
wxPanel* chancePanel = findNamedObject<wxPanel>(_mainPanel, "StimEditorChanceValuePanel");
_propertyWidgets.chanceEntry = new wxSpinCtrlDouble(chancePanel, wxID_ANY);
_propertyWidgets.chanceEntry->SetRange(0.0, 1.0);
_propertyWidgets.chanceEntry->SetIncrement(0.01);
_propertyWidgets.chanceEntry->SetValue(0);
chancePanel->GetSizer()->Add(_propertyWidgets.chanceEntry, 1);
// Velocity variable
_propertyWidgets.velocityToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorVelocity");
_propertyWidgets.velocityEntry = findNamedObject<wxTextCtrl>(_mainPanel, "StimEditorVelocityValue");
// Bounds mins and maxs
_propertyWidgets.bounds.toggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorBounds");
_propertyWidgets.bounds.panel = findNamedObject<wxPanel>(_mainPanel, "StimEditorBoundsPanel");
_propertyWidgets.bounds.minEntry = findNamedObject<wxTextCtrl>(_mainPanel, "StimEditorBoundsMinValue");
_propertyWidgets.bounds.maxEntry = findNamedObject<wxTextCtrl>(_mainPanel, "StimEditorBoundsMaxValue");
_propertyWidgets.bounds.minEntry->SetMinClientSize(wxSize(100, -1));
_propertyWidgets.bounds.maxEntry->SetMinClientSize(wxSize(100, -1));
// Associae the entry fields to stim property keys
connectSpinButton(_propertyWidgets.radiusEntry, "radius");
connectSpinButton(_propertyWidgets.finalRadiusEntry, "radius_final");
connectSpinButton(_propertyWidgets.timeIntEntry, "time_interval");
connectSpinButton(_propertyWidgets.magnEntry, "magnitude");
connectSpinButton(_propertyWidgets.falloffEntry, "falloffexponent");
connectSpinButton(_propertyWidgets.chanceEntry, "chance");
connectSpinButton(_propertyWidgets.maxFireCountEntry, "max_fire_count");
connectSpinButton(_propertyWidgets.durationEntry, "duration");
connectSpinButton(_propertyWidgets.timer.reloadEntry, "timer_reload");
// These four don't have a direct entity key associated
connectSpinButton(_propertyWidgets.timer.hour, "");
connectSpinButton(_propertyWidgets.timer.minute, "");
connectSpinButton(_propertyWidgets.timer.second, "");
connectSpinButton(_propertyWidgets.timer.millisecond, "");
// Connect text entries
connectEntry(_propertyWidgets.velocityEntry, "velocity");
connectEntry(_propertyWidgets.bounds.minEntry, "bounds_mins");
connectEntry(_propertyWidgets.bounds.maxEntry, "bounds_maxs");
// Connect the checkboxes
connectCheckButton(_propertyWidgets.active);
connectCheckButton(_propertyWidgets.useBounds);
connectCheckButton(_propertyWidgets.radiusToggle);
connectCheckButton(_propertyWidgets.finalRadiusToggle);
connectCheckButton(_propertyWidgets.timeIntToggle);
connectCheckButton(_propertyWidgets.magnToggle);
connectCheckButton(_propertyWidgets.falloffToggle);
connectCheckButton(_propertyWidgets.timer.typeToggle);
connectCheckButton(_propertyWidgets.chanceToggle);
connectCheckButton(_propertyWidgets.maxFireCountToggle);
connectCheckButton(_propertyWidgets.durationToggle);
connectCheckButton(_propertyWidgets.timer.toggle);
connectCheckButton(_propertyWidgets.timer.reloadToggle);
connectCheckButton(_propertyWidgets.timer.waitToggle);
connectCheckButton(_propertyWidgets.velocityToggle);
connectCheckButton(_propertyWidgets.bounds.toggle);
}
std::string StimEditor::getTimerString()
{
std::string hour = string::to_string(_propertyWidgets.timer.hour->GetValue());
std::string minute = string::to_string(_propertyWidgets.timer.minute->GetValue());
std::string second = string::to_string(_propertyWidgets.timer.second->GetValue());
std::string ms = string::to_string(_propertyWidgets.timer.millisecond->GetValue());
return hour + ":" + minute + ":" + second + ":" + ms;
}
void StimEditor::spinButtonChanged(wxSpinCtrl* ctrl)
{
// Pass the call to the base class
ClassEditor::spinButtonChanged(ctrl);
// These four time entries are not in the SpinButtonMap, treat them separately
if (ctrl == _propertyWidgets.timer.hour ||
ctrl == _propertyWidgets.timer.minute ||
ctrl == _propertyWidgets.timer.second ||
ctrl == _propertyWidgets.timer.millisecond)
{
setProperty("timer_time", getTimerString());
}
}
void StimEditor::checkBoxToggled(wxCheckBox* toggleButton)
{
bool active = toggleButton->GetValue();
if (toggleButton == _propertyWidgets.active)
{
setProperty("state", active ? "1" : "0");
}
else if (toggleButton == _propertyWidgets.useBounds)
{
setProperty("use_bounds", active ? "1" : "");
}
else if (toggleButton == _propertyWidgets.timer.typeToggle)
{
setProperty("timer_type", active ? "RELOAD" : "");
}
else if (toggleButton == _propertyWidgets.radiusToggle)
{
setProperty("radius", active ? "10" : "");
// Clear final radius if disabled
if (!active)
{
setProperty("radius_final", "");
}
}
else if (toggleButton == _propertyWidgets.finalRadiusToggle)
{
setProperty("radius_final", active ? "10" : "");
}
else if (toggleButton == _propertyWidgets.magnToggle)
{
setProperty("magnitude", active ? "10" : "");
}
else if (toggleButton == _propertyWidgets.maxFireCountToggle)
{
setProperty("max_fire_count", active ? "10" : "");
}
else if (toggleButton == _propertyWidgets.falloffToggle)
{
setProperty("falloffexponent", active ? "1" : "");
}
else if (toggleButton == _propertyWidgets.timeIntToggle)
{
setProperty("time_interval", active ? "1000" : "");
}
else if (toggleButton == _propertyWidgets.chanceToggle)
{
std::string entryText = string::to_string(_propertyWidgets.chanceEntry->GetValue());
setProperty("chance", active ? entryText : "");
}
else if (toggleButton == _propertyWidgets.velocityToggle)
{
std::string entryText = _propertyWidgets.velocityEntry->GetValue().ToStdString();
// Enter a default value for the entry text, if it's empty up till now.
if (active)
{
entryText += (entryText.empty()) ? "0 0 100" : "";
}
else
{
entryText = "";
}
setProperty("velocity", entryText);
}
else if (toggleButton == _propertyWidgets.bounds.toggle)
{
std::string entryText = _propertyWidgets.bounds.minEntry->GetValue().ToStdString();
// Enter a default value for the entry text, if it's empty up till now.
if (active)
{
entryText += (entryText.empty()) ? "-10 -10 -10" : "";
}
else
{
entryText = "";
}
setProperty("bounds_mins", entryText);
entryText = _propertyWidgets.bounds.maxEntry->GetValue().ToStdString();
// Enter a default value for the entry text, if it's empty up till now.
if (active)
{
entryText += (entryText.empty()) ? "10 10 10" : "";
}
else
{
entryText = "";
}
setProperty("bounds_maxs", entryText);
}
else if (toggleButton == _propertyWidgets.durationToggle)
{
setProperty("duration", active ? "1000" : "");
// Clear final radius if disabled
if (!active)
{
setProperty("radius_final", "");
}
}
else if (toggleButton == _propertyWidgets.timer.toggle)
{
std::string timerStr = getTimerString();
setProperty("timer_time", active ? timerStr : "");
}
else if (toggleButton == _propertyWidgets.timer.reloadToggle)
{
setProperty("timer_reload", active ? "1" : "");
}
else if (toggleButton == _propertyWidgets.timer.waitToggle)
{
setProperty("timer_waitforstart", active ? "1" : "");
}
}
void StimEditor::openSRListContextMenu()
{
_list->PopupMenu(_contextMenu.menu.get());
}
void StimEditor::addSR()
{
if (_entity == NULL) return;
// Create a new StimResponse object
int id = _entity->add();
// Get a reference to the newly allocated object
StimResponse& sr = _entity->get(id);
sr.set("class", "S");
// Get the selected stim type name from the combo box
std::string name = getStimTypeIdFromSelector(_addType);
sr.set("type", (!name.empty()) ? name : _stimTypes.getFirstName());
sr.set("state", "1");
// Update the list stores AFTER the type has been set
_entity->updateListStores();
// Select the newly created stim
selectId(id);
}
// Create the context menus
void StimEditor::createContextMenu()
{
// Menu widgets (is not packed, hence create a shared_ptr)
_contextMenu.menu.reset(new wxMenu);
_contextMenu.enable =
_contextMenu.menu->Append(new wxutil::IconTextMenuItem(_("Activate"), "sr_stim.png"));
_contextMenu.disable =
_contextMenu.menu->Append(new wxutil::IconTextMenuItem(_("Deactivate"), "sr_stim_inactive.png"));
_contextMenu.duplicate =
_contextMenu.menu->Append(new wxutil::StockIconTextMenuItem(_("Duplicate"), wxART_COPY));
_contextMenu.remove =
_contextMenu.menu->Append(new wxutil::StockIconTextMenuItem(_("Delete"), wxART_DELETE));
// Connect up the signals
_contextMenu.menu->Connect(_contextMenu.remove->GetId(), wxEVT_MENU,
wxCommandEventHandler(StimEditor::onContextMenuDelete), NULL, this);
_contextMenu.menu->Connect(_contextMenu.enable->GetId(), wxEVT_MENU,
wxCommandEventHandler(StimEditor::onContextMenuEnable), NULL, this);
_contextMenu.menu->Connect(_contextMenu.disable->GetId(), wxEVT_MENU,
wxCommandEventHandler(StimEditor::onContextMenuDisable), NULL, this);
_contextMenu.menu->Connect(_contextMenu.duplicate->GetId(), wxEVT_MENU,
wxCommandEventHandler(StimEditor::onContextMenuDuplicate), NULL, this);
}
void StimEditor::update()
{
_updatesDisabled = true; // avoid unwanted callbacks
wxPanel* mainPanel = findNamedObject<wxPanel>(_mainPanel, "SREditorStimPanel");
int id = getIdFromSelection();
if (id > 0)
{
// Update all the widgets
mainPanel->Enable(true);
StimResponse& sr = _entity->get(id);
std::string typeToFind = sr.get("type");
// Get the iter into the liststore pointing at the correct STIM_YYYY type
wxutil::ChoiceHelper::SelectComboItemByStoredString(_type, typeToFind);
// Active
_propertyWidgets.active->SetValue(sr.get("state") == "1");
// Use Radius
bool useRadius = (sr.get("radius") != "");
_propertyWidgets.radiusToggle->SetValue(useRadius);
_propertyWidgets.radiusEntry->SetValue(string::convert<int>(sr.get("radius")));
_propertyWidgets.radiusEntry->Enable(useRadius);
// Use Bounds
_propertyWidgets.useBounds->SetValue(sr.get("use_bounds") == "1" && useRadius);
_propertyWidgets.useBounds->Enable(useRadius);
// Use Duration
bool useDuration = (sr.get("duration") != "");
_propertyWidgets.durationToggle->SetValue(useDuration);
_propertyWidgets.durationEntry->SetValue(string::convert<int>(sr.get("duration")));
_propertyWidgets.durationEntry->Enable(useDuration);
_propertyWidgets.durationUnitLabel->Enable(useDuration);
// Use Time interval
bool useTimeInterval = (sr.get("time_interval") != "");
_propertyWidgets.timeIntToggle->SetValue(useTimeInterval);
_propertyWidgets.timeIntEntry->SetValue(string::convert<int>(sr.get("time_interval")));
_propertyWidgets.timeIntEntry->Enable(useTimeInterval);
_propertyWidgets.timeUnitLabel->Enable(useTimeInterval);
// Use Final radius (duration must be enabled for this to work)
bool useFinalRadius = (sr.get("radius_final") != "");
_propertyWidgets.finalRadiusToggle->SetValue(useFinalRadius && useDuration);
_propertyWidgets.finalRadiusEntry->SetValue(string::convert<int>(sr.get("radius_final")));
_propertyWidgets.finalRadiusToggle->Enable(useRadius && useDuration);
_propertyWidgets.finalRadiusEntry->Enable(useFinalRadius && useDuration && useRadius);
// Timer time
bool useTimerTime = !sr.get("timer_time").empty();
_propertyWidgets.timer.toggle->SetValue(useTimerTime);
_propertyWidgets.timer.toggle->Enable(true);
_propertyWidgets.timer.entryHBox->Enable(useTimerTime);
// Split the property string and distribute the parts into the entry fields
std::vector<std::string> parts;
std::string timerTime = sr.get("timer_time");
string::split(parts, timerTime, ":");
std::string hour = (parts.size() > 0) ? parts[0] : "";
std::string minute = (parts.size() > 1) ? parts[1] : "";
std::string second = (parts.size() > 2) ? parts[2] : "";
std::string ms = (parts.size() > 3) ? parts[3] : "";
_propertyWidgets.timer.hour->SetValue(string::convert<int>(hour));
_propertyWidgets.timer.minute->SetValue(string::convert<int>(minute));
_propertyWidgets.timer.second->SetValue(string::convert<int>(second));
_propertyWidgets.timer.millisecond->SetValue(string::convert<int>(ms));
_propertyWidgets.timer.waitToggle->SetValue(
useTimerTime && sr.get("timer_waitforstart") == "1"
);
_propertyWidgets.timer.waitToggle->Enable(useTimerTime);
// Timer Type
bool useTimerType = sr.get("timer_type") == "RELOAD" && useTimerTime;
_propertyWidgets.timer.typeToggle->SetValue(useTimerType);
_propertyWidgets.timer.typeToggle->Enable(useTimerTime);
bool userTimerReload = useTimerType && !sr.get("timer_reload").empty();
_propertyWidgets.timer.reloadToggle->SetValue(userTimerReload);
_propertyWidgets.timer.reloadToggle->Enable(useTimerType);
_propertyWidgets.timer.reloadEntry->SetValue(string::convert<int>(sr.get("timer_reload")));
_propertyWidgets.timer.reloadHBox->Enable(userTimerReload);
// Use Magnitude
bool useMagnitude = (sr.get("magnitude") != "");
_propertyWidgets.magnToggle->SetValue(useMagnitude);
_propertyWidgets.magnEntry->SetValue(string::convert<int>(sr.get("magnitude")));
_propertyWidgets.magnEntry->Enable(useMagnitude);
// Use falloff exponent widgets
bool useFalloff = (sr.get("falloffexponent") != "");
_propertyWidgets.falloffToggle->SetValue(useFalloff);
_propertyWidgets.falloffEntry->SetValue(string::convert<double>(sr.get("falloffexponent")));
_propertyWidgets.falloffToggle->Enable(useMagnitude);
_propertyWidgets.falloffEntry->Enable(useMagnitude && useFalloff);
// Use Chance
bool useChance = (sr.get("chance") != "");
_propertyWidgets.chanceToggle->SetValue(useChance);
_propertyWidgets.chanceEntry->SetValue(string::convert<double>(sr.get("chance")));
_propertyWidgets.chanceEntry->Enable(useChance);
// Use Max Fire Count
bool useMaxFireCount = (sr.get("max_fire_count") != "");
_propertyWidgets.maxFireCountToggle->SetValue(useMaxFireCount);
_propertyWidgets.maxFireCountEntry->SetValue(string::convert<int>(sr.get("max_fire_count")));
_propertyWidgets.maxFireCountEntry->Enable(useMaxFireCount);
// Use Velocity
bool useVelocity = (sr.get("velocity") != "");
_propertyWidgets.velocityToggle->SetValue(useVelocity);
_propertyWidgets.velocityEntry->SetValue(sr.get("velocity"));
_propertyWidgets.velocityEntry->Enable(useVelocity);
// Use Bounds mins/max
bool useBoundsMinMax = (sr.get("bounds_mins") != "");
_propertyWidgets.bounds.toggle->SetValue(useBoundsMinMax);
_propertyWidgets.bounds.minEntry->SetValue(sr.get("bounds_mins"));
_propertyWidgets.bounds.maxEntry->SetValue(sr.get("bounds_maxs"));
_propertyWidgets.bounds.panel->Enable(useBoundsMinMax);
// Disable the editing of inherited properties completely
if (sr.inherited())
{
mainPanel->Enable(false);
}
// If there is anything selected, the duplicate item is always active
_contextMenu.menu->Enable(_contextMenu.duplicate->GetId(), true);
// Update the delete context menu item
_contextMenu.menu->Enable(_contextMenu.remove->GetId(), !sr.inherited());
// Update the "enable/disable" menu items
bool state = sr.get("state") == "1";
_contextMenu.menu->Enable(_contextMenu.enable->GetId(), !state);
_contextMenu.menu->Enable(_contextMenu.disable->GetId(), state);
}
else
{
mainPanel->Enable(false);
// Disable the "non-Add" context menu items
_contextMenu.menu->Enable(_contextMenu.remove->GetId(), false);
_contextMenu.menu->Enable(_contextMenu.enable->GetId(), false);
_contextMenu.menu->Enable(_contextMenu.disable->GetId(), false);
_contextMenu.menu->Enable(_contextMenu.duplicate->GetId(), false);
}
_updatesDisabled = false;
}
void StimEditor::selectionChanged()
{
update();
}
// Delete context menu items activated
void StimEditor::onContextMenuDelete(wxCommandEvent& ev)
{
// Delete the selected stim from the list
removeSR();
}
// Delete context menu items activated
void StimEditor::onContextMenuAdd(wxCommandEvent& ev)
{
addSR();
}
} // namespace ui