Debian Codegraph @

plugins/dm.stimresponse/StimEditor.cpp

raw
1 #include "StimEditor.h"
2
3 #include "string/split.h"
4 #include "string/convert.h"
5
6 #include "i18n.h"
7 #include "SREntity.h"
8
9 #include <wx/menu.h>
10 #include <wx/checkbox.h>
11 #include <wx/spinctrl.h>
12 #include <wx/bmpcbox.h>
13 #include <wx/sizer.h>
14 #include <wx/button.h>
15
16 #include "wxutil/ChoiceHelper.h"
17 #include "wxutil/menu/IconTextMenuItem.h"
18
19 namespace ui
20 {
21
22 StimEditor::StimEditor(wxWindow* mainPanel, StimTypes& stimTypes) :
23 ClassEditor(mainPanel, stimTypes),
24 _mainPanel(mainPanel)
25 {
26 setupPage();
27
28 // Setup the context menu items and connect them to the callbacks
29 createContextMenu();
30
31 update();
32 }
33
34 void StimEditor::setupPage()
35 {
36 wxPanel* listPanel = findNamedObject<wxPanel>(_mainPanel, "SREditorStimList");
37 createListView(listPanel);
38
39 setupEditPanel();
40
41 #ifdef USE_BMP_COMBO_BOX
42 _addType = findNamedObject<wxBitmapComboBox>(_mainPanel, "StimTypeComboBox");
43 #else
44 {
45 // Type selector box
46 wxControl* typeBox = findNamedObject<wxControl>(_mainPanel, "StimTypeComboBox");
47
48 // Replace the bitmap combo with an ordinary one
49 wxComboBox* combo = new wxComboBox(typeBox->GetParent(), wxID_ANY);
50 typeBox->GetContainingSizer()->Prepend(combo, 1, wxEXPAND | wxRIGHT, 6);
51 typeBox->Destroy();
52
53 _addType = combo;
54 _addType->SetName("StimTypeComboBox");
55 }
56 #endif
57
58 _addType->Bind(wxEVT_COMBOBOX, std::bind(&StimEditor::onAddTypeSelect, this, std::placeholders::_1));
59
60 auto addButton = findNamedObject<wxButton>(_mainPanel, "AddStimButton");
61 auto removeButton = findNamedObject<wxButton>(_mainPanel, "RemoveStimButton");
62
63 addButton->Bind(wxEVT_BUTTON, std::bind(&StimEditor::onAddSR, this, std::placeholders::_1));
64 removeButton->Bind(wxEVT_BUTTON, std::bind(&StimEditor::onRemoveSR, this, std::placeholders::_1));
65
66 reloadStimTypes();
67 }
68
69 void StimEditor::reloadStimTypes()
70 {
71 if (_stimTypes.getStimMap().empty())
72 {
73 _stimTypes.reload();
74 }
75
76 _stimTypes.populateComboBox(_addType);
77 _stimTypes.populateComboBox(_type);
78 }
79
80 void StimEditor::setEntity(const SREntityPtr& entity)
81 {
82 // Pass the call to the base class
83 ClassEditor::setEntity(entity);
84
85 if (entity)
86 {
87 wxutil::TreeModel::Ptr stimStore = _entity->getStimStore();
88 _list->AssociateModel(stimStore.get());
89
90 // Trigger column width reevaluation
91 stimStore->ItemChanged(stimStore->GetRoot());
92 }
93 else
94 {
95 // wxWidgets 3.0.0 crashes when associating a NULL model, so use a dummy model
96 // to release the old one
97 wxutil::TreeModel* dummyStore = new wxutil::TreeModel(SREntity::getColumns(), true);
98 _list->AssociateModel(dummyStore);
99 }
100 }
101
102 void StimEditor::setupEditPanel()
103 {
104 #ifdef USE_BMP_COMBO_BOX
105 // Type Selector
106 _type = findNamedObject<wxBitmapComboBox>(_mainPanel, "StimEditorTypeCombo");
107 #else
108 // Response property section
109 wxControl* typeBox = findNamedObject<wxControl>(_mainPanel, "StimEditorTypeCombo");
110
111 // Replace the bitmap combo with an ordinary one
112 wxComboBox* combo = new wxComboBox(typeBox->GetParent(), wxID_ANY);
113 typeBox->GetContainingSizer()->Add(combo, 1, wxEXPAND);
114 typeBox->Destroy();
115
116 _type = combo;
117 _type->SetName("StimEditorTypeCombo");
118 #endif
119
120 _stimTypes.populateComboBox(_type);
121 _type->Connect(wxEVT_COMBOBOX, wxCommandEventHandler(StimEditor::onStimTypeSelect), nullptr, this);
122
123 _propertyWidgets.active = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorActive");
124
125 // Timer Time
126 _propertyWidgets.timer.toggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorActivationTimer");
127 _propertyWidgets.timer.entryHBox = findNamedObject<wxPanel>(_mainPanel, "StimEditorActivationTimerPanel");
128
129 _propertyWidgets.timer.hour = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorAcivationTimerHour");
130 _propertyWidgets.timer.minute = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorAcivationTimerMinute");
131 _propertyWidgets.timer.second = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorAcivationTimerSecond");
132 _propertyWidgets.timer.millisecond = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorAcivationTimerMS");
133
134 // Timer type
135 _propertyWidgets.timer.typeToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorTimerRestarts");
136 _propertyWidgets.timer.reloadHBox = findNamedObject<wxPanel>(_mainPanel, "StimEditorTimerRestartPanel");
137
138 _propertyWidgets.timer.reloadEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorTimerReloadsTimes");
139 _propertyWidgets.timer.reloadEntry->SetMinClientSize(wxSize(_propertyWidgets.timer.reloadEntry->GetCharWidth() * 9, -1));
140
141 _propertyWidgets.timer.reloadToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorTimerReloads");
142
143 _propertyWidgets.timer.waitToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorTimerWaitsForStart");
144
145 // Time Interval
146 _propertyWidgets.timeIntToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorTimeInterval");
147 _propertyWidgets.timeIntEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorTimeIntervalValue");
148 _propertyWidgets.timeUnitLabel = findNamedObject<wxStaticText>(_mainPanel, "StimEditorTimeIntervalUnitLabel");
149
150 // Duration
151 _propertyWidgets.durationToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorDuration");
152 _propertyWidgets.durationEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorDurationValue");
153 _propertyWidgets.durationUnitLabel = findNamedObject<wxStaticText>(_mainPanel, "StimEditorDurationUnitLabel");
154
155 // Radius / Use Bounds
156 _propertyWidgets.radiusToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorRadius");
157 _propertyWidgets.radiusEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorRadiusValue");
158 _propertyWidgets.useBounds = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorRadiusUseBounds");
159
160 // Final Radius
161 _propertyWidgets.finalRadiusToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorRadiusChangesOverTime");
162 _propertyWidgets.finalRadiusEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorRadiusChangesOverTimeValue");
163
164 // Magnitude
165 _propertyWidgets.magnToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorMagnitude");
166 _propertyWidgets.magnEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorMagnitudeValue");
167
168 // Falloff exponent
169 _propertyWidgets.falloffToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorMagnitudeFalloff");
170
171 wxPanel* falloffPanel = findNamedObject<wxPanel>(_mainPanel, "StimEditorMagnitudePanel");
172
173 _propertyWidgets.falloffEntry = new wxSpinCtrlDouble(falloffPanel, wxID_ANY);
174 _propertyWidgets.falloffEntry->SetRange(-10, +10);
175 _propertyWidgets.falloffEntry->SetIncrement(0.1);
176 _propertyWidgets.falloffEntry->SetValue(0);
177 _propertyWidgets.falloffEntry->SetMinClientSize(wxSize(7*_propertyWidgets.falloffEntry->GetCharWidth(), -1));
178
179 falloffPanel->GetSizer()->Add(_propertyWidgets.falloffEntry, 2);
180
181 // Max fire count
182 _propertyWidgets.maxFireCountToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorMaxFireCount");
183 _propertyWidgets.maxFireCountEntry = findNamedObject<wxSpinCtrl>(_mainPanel, "StimEditorMaxFireCountValue");
184
185 // Chance variable
186 _propertyWidgets.chanceToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorChance");
187 wxPanel* chancePanel = findNamedObject<wxPanel>(_mainPanel, "StimEditorChanceValuePanel");
188
189 _propertyWidgets.chanceEntry = new wxSpinCtrlDouble(chancePanel, wxID_ANY);
190 _propertyWidgets.chanceEntry->SetRange(0.0, 1.0);
191 _propertyWidgets.chanceEntry->SetIncrement(0.01);
192 _propertyWidgets.chanceEntry->SetValue(0);
193
194 chancePanel->GetSizer()->Add(_propertyWidgets.chanceEntry, 1);
195
196 // Velocity variable
197 _propertyWidgets.velocityToggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorVelocity");
198 _propertyWidgets.velocityEntry = findNamedObject<wxTextCtrl>(_mainPanel, "StimEditorVelocityValue");
199
200 // Bounds mins and maxs
201 _propertyWidgets.bounds.toggle = findNamedObject<wxCheckBox>(_mainPanel, "StimEditorBounds");
202 _propertyWidgets.bounds.panel = findNamedObject<wxPanel>(_mainPanel, "StimEditorBoundsPanel");
203 _propertyWidgets.bounds.minEntry = findNamedObject<wxTextCtrl>(_mainPanel, "StimEditorBoundsMinValue");
204 _propertyWidgets.bounds.maxEntry = findNamedObject<wxTextCtrl>(_mainPanel, "StimEditorBoundsMaxValue");
205 _propertyWidgets.bounds.minEntry->SetMinClientSize(wxSize(100, -1));
206 _propertyWidgets.bounds.maxEntry->SetMinClientSize(wxSize(100, -1));
207
208 // Associae the entry fields to stim property keys
209 connectSpinButton(_propertyWidgets.radiusEntry, "radius");
210 connectSpinButton(_propertyWidgets.finalRadiusEntry, "radius_final");
211 connectSpinButton(_propertyWidgets.timeIntEntry, "time_interval");
212 connectSpinButton(_propertyWidgets.magnEntry, "magnitude");
213 connectSpinButton(_propertyWidgets.falloffEntry, "falloffexponent");
214 connectSpinButton(_propertyWidgets.chanceEntry, "chance");
215 connectSpinButton(_propertyWidgets.maxFireCountEntry, "max_fire_count");
216 connectSpinButton(_propertyWidgets.durationEntry, "duration");
217 connectSpinButton(_propertyWidgets.timer.reloadEntry, "timer_reload");
218
219 // These four don't have a direct entity key associated
220 connectSpinButton(_propertyWidgets.timer.hour, "");
221 connectSpinButton(_propertyWidgets.timer.minute, "");
222 connectSpinButton(_propertyWidgets.timer.second, "");
223 connectSpinButton(_propertyWidgets.timer.millisecond, "");
224
225 // Connect text entries
226 connectEntry(_propertyWidgets.velocityEntry, "velocity");
227 connectEntry(_propertyWidgets.bounds.minEntry, "bounds_mins");
228 connectEntry(_propertyWidgets.bounds.maxEntry, "bounds_maxs");
229
230 // Connect the checkboxes
231 connectCheckButton(_propertyWidgets.active);
232 connectCheckButton(_propertyWidgets.useBounds);
233 connectCheckButton(_propertyWidgets.radiusToggle);
234 connectCheckButton(_propertyWidgets.finalRadiusToggle);
235 connectCheckButton(_propertyWidgets.timeIntToggle);
236 connectCheckButton(_propertyWidgets.magnToggle);
237 connectCheckButton(_propertyWidgets.falloffToggle);
238 connectCheckButton(_propertyWidgets.timer.typeToggle);
239 connectCheckButton(_propertyWidgets.chanceToggle);
240 connectCheckButton(_propertyWidgets.maxFireCountToggle);
241 connectCheckButton(_propertyWidgets.durationToggle);
242 connectCheckButton(_propertyWidgets.timer.toggle);
243 connectCheckButton(_propertyWidgets.timer.reloadToggle);
244 connectCheckButton(_propertyWidgets.timer.waitToggle);
245 connectCheckButton(_propertyWidgets.velocityToggle);
246 connectCheckButton(_propertyWidgets.bounds.toggle);
247 }
248
249 std::string StimEditor::getTimerString()
250 {
251 std::string hour = string::to_string(_propertyWidgets.timer.hour->GetValue());
252 std::string minute = string::to_string(_propertyWidgets.timer.minute->GetValue());
253 std::string second = string::to_string(_propertyWidgets.timer.second->GetValue());
254 std::string ms = string::to_string(_propertyWidgets.timer.millisecond->GetValue());
255
256 return hour + ":" + minute + ":" + second + ":" + ms;
257 }
258
259 void StimEditor::spinButtonChanged(wxSpinCtrl* ctrl)
260 {
261 // Pass the call to the base class
262 ClassEditor::spinButtonChanged(ctrl);
263
264 // These four time entries are not in the SpinButtonMap, treat them separately
265 if (ctrl == _propertyWidgets.timer.hour ||
266 ctrl == _propertyWidgets.timer.minute ||
267 ctrl == _propertyWidgets.timer.second ||
268 ctrl == _propertyWidgets.timer.millisecond)
269 {
270 setProperty("timer_time", getTimerString());
271 }
272 }
273
274 void StimEditor::checkBoxToggled(wxCheckBox* toggleButton)
275 {
276 bool active = toggleButton->GetValue();
277
278 if (toggleButton == _propertyWidgets.active)
279 {
280 setProperty("state", active ? "1" : "0");
281 }
282 else if (toggleButton == _propertyWidgets.useBounds)
283 {
284 setProperty("use_bounds", active ? "1" : "");
285 }
286 else if (toggleButton == _propertyWidgets.timer.typeToggle)
287 {
288 setProperty("timer_type", active ? "RELOAD" : "");
289 }
290 else if (toggleButton == _propertyWidgets.radiusToggle)
291 {
292 setProperty("radius", active ? "10" : "");
293
294 // Clear final radius if disabled
295 if (!active)
296 {
297 setProperty("radius_final", "");
298 }
299 }
300 else if (toggleButton == _propertyWidgets.finalRadiusToggle)
301 {
302 setProperty("radius_final", active ? "10" : "");
303 }
304 else if (toggleButton == _propertyWidgets.magnToggle)
305 {
306 setProperty("magnitude", active ? "10" : "");
307 }
308 else if (toggleButton == _propertyWidgets.maxFireCountToggle)
309 {
310 setProperty("max_fire_count", active ? "10" : "");
311 }
312 else if (toggleButton == _propertyWidgets.falloffToggle)
313 {
314 setProperty("falloffexponent", active ? "1" : "");
315 }
316 else if (toggleButton == _propertyWidgets.timeIntToggle)
317 {
318 setProperty("time_interval", active ? "1000" : "");
319 }
320 else if (toggleButton == _propertyWidgets.chanceToggle)
321 {
322 std::string entryText = string::to_string(_propertyWidgets.chanceEntry->GetValue());
323
324 setProperty("chance", active ? entryText : "");
325 }
326 else if (toggleButton == _propertyWidgets.velocityToggle)
327 {
328 std::string entryText = _propertyWidgets.velocityEntry->GetValue().ToStdString();
329
330 // Enter a default value for the entry text, if it's empty up till now.
331 if (active)
332 {
333 entryText += (entryText.empty()) ? "0 0 100" : "";
334 }
335 else
336 {
337 entryText = "";
338 }
339
340 setProperty("velocity", entryText);
341 }
342 else if (toggleButton == _propertyWidgets.bounds.toggle)
343 {
344 std::string entryText = _propertyWidgets.bounds.minEntry->GetValue().ToStdString();
345
346 // Enter a default value for the entry text, if it's empty up till now.
347 if (active)
348 {
349 entryText += (entryText.empty()) ? "-10 -10 -10" : "";
350 }
351 else
352 {
353 entryText = "";
354 }
355
356 setProperty("bounds_mins", entryText);
357
358 entryText = _propertyWidgets.bounds.maxEntry->GetValue().ToStdString();
359
360 // Enter a default value for the entry text, if it's empty up till now.
361 if (active)
362 {
363 entryText += (entryText.empty()) ? "10 10 10" : "";
364 }
365 else
366 {
367 entryText = "";
368 }
369
370 setProperty("bounds_maxs", entryText);
371 }
372 else if (toggleButton == _propertyWidgets.durationToggle)
373 {
374 setProperty("duration", active ? "1000" : "");
375
376 // Clear final radius if disabled
377 if (!active)
378 {
379 setProperty("radius_final", "");
380 }
381 }
382 else if (toggleButton == _propertyWidgets.timer.toggle)
383 {
384 std::string timerStr = getTimerString();
385 setProperty("timer_time", active ? timerStr : "");
386 }
387 else if (toggleButton == _propertyWidgets.timer.reloadToggle)
388 {
389 setProperty("timer_reload", active ? "1" : "");
390 }
391 else if (toggleButton == _propertyWidgets.timer.waitToggle)
392 {
393 setProperty("timer_waitforstart", active ? "1" : "");
394 }
395 }
396
397 void StimEditor::openSRListContextMenu()
398 {
399 _list->PopupMenu(_contextMenu.menu.get());
400 }
401
402 void StimEditor::addSR()
403 {
404 if (!_entity) return;
405
406 // Create a new StimResponse object
407 int index = _entity->add();
408
409 // Get a reference to the newly allocated object
410 StimResponse& sr = _entity->get(index);
411 sr.set("class", "S");
412
413 // Get the selected stim type name from the combo box
414 std::string name = getStimTypeIdFromSelector(_addType);
415 sr.set("type", (!name.empty()) ? name : _stimTypes.getFirstName());
416
417 sr.set("state", "1");
418
419 // Update the list stores AFTER the type has been set
420 _entity->updateListStores();
421
422 // Select the newly created stim
423 selectIndex(index);
424 }
425
426 // Create the context menus
427 void StimEditor::createContextMenu()
428 {
429 // Menu widgets (is not packed, hence create a shared_ptr)
430 _contextMenu.menu.reset(new wxMenu);
431
432 _contextMenu.enable =
433 _contextMenu.menu->Append(new wxutil::IconTextMenuItem(_("Activate"), "sr_stim.png"));
434 _contextMenu.disable =
435 _contextMenu.menu->Append(new wxutil::IconTextMenuItem(_("Deactivate"), "sr_stim_inactive.png"));
436 _contextMenu.duplicate =
437 _contextMenu.menu->Append(new wxutil::StockIconTextMenuItem(_("Duplicate"), wxART_COPY));
438 _contextMenu.remove =
439 _contextMenu.menu->Append(new wxutil::StockIconTextMenuItem(_("Delete"), wxART_DELETE));
440
441 // Connect up the signals
442 _contextMenu.menu->Connect(_contextMenu.remove->GetId(), wxEVT_MENU,
443 wxCommandEventHandler(StimEditor::onContextMenuDelete), nullptr, this);
444 _contextMenu.menu->Connect(_contextMenu.enable->GetId(), wxEVT_MENU,
445 wxCommandEventHandler(StimEditor::onContextMenuEnable), nullptr, this);
446 _contextMenu.menu->Connect(_contextMenu.disable->GetId(), wxEVT_MENU,
447 wxCommandEventHandler(StimEditor::onContextMenuDisable), nullptr, this);
448 _contextMenu.menu->Connect(_contextMenu.duplicate->GetId(), wxEVT_MENU,
449 wxCommandEventHandler(StimEditor::onContextMenuDuplicate), nullptr, this);
450 }
451
452 void StimEditor::update()
453 {
454 _updatesDisabled = true; // avoid unwanted callbacks
455
456 wxPanel* mainPanel = findNamedObject<wxPanel>(_mainPanel, "SREditorStimPanel");
457 auto removeButton = findNamedObject<wxButton>(_mainPanel, "RemoveStimButton");
458
459 int index = getIndexFromSelection();
460
461 if (index > 0)
462 {
463 // Update all the widgets
464 mainPanel->Enable(true);
465
466 StimResponse& sr = _entity->get(index);
467
468 std::string typeToFind = sr.get("type");
469
470 // Get the iter into the liststore pointing at the correct STIM_YYYY type
471 wxutil::ChoiceHelper::SelectComboItemByStoredString(_type, typeToFind);
472
473 // Active
474 _propertyWidgets.active->SetValue(sr.get("state") == "1");
475
476 // Use Radius
477 bool useRadius = (sr.get("radius") != "");
478 _propertyWidgets.radiusToggle->SetValue(useRadius);
479 _propertyWidgets.radiusEntry->SetValue(string::convert<int>(sr.get("radius")));
480 _propertyWidgets.radiusEntry->Enable(useRadius);
481
482 // Use Bounds
483 _propertyWidgets.useBounds->SetValue(sr.get("use_bounds") == "1" && useRadius);
484 _propertyWidgets.useBounds->Enable(useRadius);
485
486 // Use Duration
487 bool useDuration = (sr.get("duration") != "");
488 _propertyWidgets.durationToggle->SetValue(useDuration);
489 _propertyWidgets.durationEntry->SetValue(string::convert<int>(sr.get("duration")));
490 _propertyWidgets.durationEntry->Enable(useDuration);
491 _propertyWidgets.durationUnitLabel->Enable(useDuration);
492
493 // Use Time interval
494 bool useTimeInterval = (sr.get("time_interval") != "");
495 _propertyWidgets.timeIntToggle->SetValue(useTimeInterval);
496 _propertyWidgets.timeIntEntry->SetValue(string::convert<int>(sr.get("time_interval")));
497 _propertyWidgets.timeIntEntry->Enable(useTimeInterval);
498 _propertyWidgets.timeUnitLabel->Enable(useTimeInterval);
499
500 // Use Final radius (duration must be enabled for this to work)
501 bool useFinalRadius = (sr.get("radius_final") != "");
502 _propertyWidgets.finalRadiusToggle->SetValue(useFinalRadius && useDuration);
503 _propertyWidgets.finalRadiusEntry->SetValue(string::convert<int>(sr.get("radius_final")));
504 _propertyWidgets.finalRadiusToggle->Enable(useRadius && useDuration);
505 _propertyWidgets.finalRadiusEntry->Enable(useFinalRadius && useDuration && useRadius);
506
507 // Timer time
508 bool useTimerTime = !sr.get("timer_time").empty();
509 _propertyWidgets.timer.toggle->SetValue(useTimerTime);
510 _propertyWidgets.timer.toggle->Enable(true);
511 _propertyWidgets.timer.entryHBox->Enable(useTimerTime);
512
513 // Split the property string and distribute the parts into the entry fields
514 std::vector<std::string> parts;
515 std::string timerTime = sr.get("timer_time");
516 string::split(parts, timerTime, ":");
517
518 std::string hour = (parts.size() > 0) ? parts[0] : "";
519 std::string minute = (parts.size() > 1) ? parts[1] : "";
520 std::string second = (parts.size() > 2) ? parts[2] : "";
521 std::string ms = (parts.size() > 3) ? parts[3] : "";
522
523 _propertyWidgets.timer.hour->SetValue(string::convert<int>(hour));
524 _propertyWidgets.timer.minute->SetValue(string::convert<int>(minute));
525 _propertyWidgets.timer.second->SetValue(string::convert<int>(second));
526 _propertyWidgets.timer.millisecond->SetValue(string::convert<int>(ms));
527
528 _propertyWidgets.timer.waitToggle->SetValue(
529 useTimerTime && sr.get("timer_waitforstart") == "1"
530 );
531 _propertyWidgets.timer.waitToggle->Enable(useTimerTime);
532
533 // Timer Type
534 bool useTimerType = sr.get("timer_type") == "RELOAD" && useTimerTime;
535 _propertyWidgets.timer.typeToggle->SetValue(useTimerType);
536 _propertyWidgets.timer.typeToggle->Enable(useTimerTime);
537
538 bool userTimerReload = useTimerType && !sr.get("timer_reload").empty();
539 _propertyWidgets.timer.reloadToggle->SetValue(userTimerReload);
540 _propertyWidgets.timer.reloadToggle->Enable(useTimerType);
541 _propertyWidgets.timer.reloadEntry->SetValue(string::convert<int>(sr.get("timer_reload")));
542 _propertyWidgets.timer.reloadHBox->Enable(userTimerReload);
543
544 // Use Magnitude
545 bool useMagnitude = (sr.get("magnitude") != "");
546 _propertyWidgets.magnToggle->SetValue(useMagnitude);
547 _propertyWidgets.magnEntry->SetValue(string::convert<int>(sr.get("magnitude")));
548 _propertyWidgets.magnEntry->Enable(useMagnitude);
549
550 // Use falloff exponent widgets
551 bool useFalloff = (sr.get("falloffexponent") != "");
552
553 _propertyWidgets.falloffToggle->SetValue(useFalloff);
554 _propertyWidgets.falloffEntry->SetValue(string::convert<double>(sr.get("falloffexponent")));
555 _propertyWidgets.falloffToggle->Enable(useMagnitude);
556 _propertyWidgets.falloffEntry->Enable(useMagnitude && useFalloff);
557
558 // Use Chance
559 bool useChance = (sr.get("chance") != "");
560 _propertyWidgets.chanceToggle->SetValue(useChance);
561 _propertyWidgets.chanceEntry->SetValue(string::convert<double>(sr.get("chance")));
562 _propertyWidgets.chanceEntry->Enable(useChance);
563
564 // Use Max Fire Count
565 bool useMaxFireCount = (sr.get("max_fire_count") != "");
566 _propertyWidgets.maxFireCountToggle->SetValue(useMaxFireCount);
567 _propertyWidgets.maxFireCountEntry->SetValue(string::convert<int>(sr.get("max_fire_count")));
568 _propertyWidgets.maxFireCountEntry->Enable(useMaxFireCount);
569
570 // Use Velocity
571 bool useVelocity = (sr.get("velocity") != "");
572 _propertyWidgets.velocityToggle->SetValue(useVelocity);
573 _propertyWidgets.velocityEntry->SetValue(sr.get("velocity"));
574 _propertyWidgets.velocityEntry->Enable(useVelocity);
575
576 // Use Bounds mins/max
577 bool useBoundsMinMax = (sr.get("bounds_mins") != "");
578 _propertyWidgets.bounds.toggle->SetValue(useBoundsMinMax);
579 _propertyWidgets.bounds.minEntry->SetValue(sr.get("bounds_mins"));
580 _propertyWidgets.bounds.maxEntry->SetValue(sr.get("bounds_maxs"));
581 _propertyWidgets.bounds.panel->Enable(useBoundsMinMax);
582
583 // Disable the editing of inherited properties completely
584 if (sr.inherited())
585 {
586 mainPanel->Enable(false);
587 }
588
589 // If there is anything selected, the duplicate item is always active
590 _contextMenu.menu->Enable(_contextMenu.duplicate->GetId(), true);
591
592 // Update the delete context menu item
593 _contextMenu.menu->Enable(_contextMenu.remove->GetId(), !sr.inherited());
594 removeButton->Enable(!sr.inherited());
595
596 // Update the "enable/disable" menu items
597 bool state = sr.get("state") == "1";
598 _contextMenu.menu->Enable(_contextMenu.enable->GetId(), !state);
599 _contextMenu.menu->Enable(_contextMenu.disable->GetId(), state);
600 }
601 else
602 {
603 mainPanel->Enable(false);
604
605 // Disable the "non-Add" context menu items
606 _contextMenu.menu->Enable(_contextMenu.remove->GetId(), false);
607 _contextMenu.menu->Enable(_contextMenu.enable->GetId(), false);
608 _contextMenu.menu->Enable(_contextMenu.disable->GetId(), false);
609 _contextMenu.menu->Enable(_contextMenu.duplicate->GetId(), false);
610
611 removeButton->Enable(false);
612 }
613
614 _updatesDisabled = false;
615 }
616
617 void StimEditor::selectionChanged()
618 {
619 update();
620 }
621
622 // Delete context menu items activated
623 void StimEditor::onContextMenuDelete(wxCommandEvent& ev)
624 {
625 // Delete the selected stim from the list
626 removeSR();
627 }
628
629 // Delete context menu items activated
630 void StimEditor::onContextMenuAdd(wxCommandEvent& ev)
631 {
632 addSR();
633 }
634
635 } // namespace ui