/
EffectArgumentItem.cpp
150 lines (120 loc) · 3.23 KB
/
EffectArgumentItem.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
#include "EffectArgumentItem.h"
#include "string/convert.h"
#include <wx/textctrl.h>
#include <wx/stattext.h>
#include <wx/choice.h>
#include <wx/combobox.h>
#include <wx/checkbox.h>
#include <wx/bmpcbox.h>
#include "wxutil/ChoiceHelper.h"
#include "StimTypes.h"
EffectArgumentItem::EffectArgumentItem(wxWindow* parent,
ResponseEffect::Argument& arg) :
_arg(arg)
{
// Create the label
_label = new wxStaticText(parent, wxID_ANY, _arg.title + ":");
_label->SetToolTip(arg.desc);
// Create the description widget
_descBox = new wxStaticText(parent, wxID_ANY, "?");
_descBox->SetFont(_descBox->GetFont().Bold());
_descBox->SetToolTip(arg.desc);
}
// Retrieve the label widget
wxWindow* EffectArgumentItem::getLabelWidget()
{
return _label;
}
wxWindow* EffectArgumentItem::getHelpWidget()
{
return _descBox;
}
void EffectArgumentItem::save()
{
// Save the value to the effect
_arg.value = getValue();
}
// StringArgument
StringArgument::StringArgument(wxWindow* parent, ResponseEffect::Argument& arg) :
EffectArgumentItem(parent, arg)
{
_entry = new wxTextCtrl(parent, wxID_ANY);
_entry->SetValue(arg.value);
}
wxWindow* StringArgument::getEditWidget()
{
return _entry;
}
std::string StringArgument::getValue()
{
return _entry->GetValue().ToStdString();
}
// Boolean argument
BooleanArgument::BooleanArgument(wxWindow* parent, ResponseEffect::Argument& arg) :
EffectArgumentItem(parent, arg)
{
_checkButton = new wxCheckBox(parent, wxID_ANY, arg.title);
_checkButton->SetValue(!arg.value.empty());
}
wxWindow* BooleanArgument::getEditWidget()
{
return _checkButton;
}
std::string BooleanArgument::getValue()
{
return _checkButton->GetValue() ? "1" : "";
}
// Entity Argument
EntityArgument::EntityArgument(
wxWindow* parent,
ResponseEffect::Argument& arg,
const wxArrayString& entityChoices) :
EffectArgumentItem(parent, arg)
{
// Create a combo box entry with the given entity list
_comboBox = new wxComboBox(parent, wxID_ANY);
_comboBox->Append(entityChoices);
_comboBox->SetValue(arg.value);
}
std::string EntityArgument::getValue()
{
return _comboBox->GetValue().ToStdString();
}
wxWindow* EntityArgument::getEditWidget()
{
return _comboBox;
}
// StimType Argument
StimTypeArgument::StimTypeArgument(wxWindow* parent,
ResponseEffect::Argument& arg,
const StimTypes& stimTypes) :
EffectArgumentItem(parent, arg),
_stimTypes(stimTypes)
{
#ifdef USE_BMP_COMBO_BOX
_comboBox = new wxBitmapComboBox(parent, wxID_ANY);
#else
_comboBox = new wxComboBox(parent, wxID_ANY);
#endif
_stimTypes.populateComboBox(_comboBox);
StimType stimType = _stimTypes.get(string::convert<int>(arg.value));
wxutil::ChoiceHelper::SelectComboItemByStoredString(_comboBox, stimType.name);
}
std::string StimTypeArgument::getValue()
{
// The effect argument stores the stim type ID as value
if (_comboBox->GetSelection() != wxNOT_FOUND)
{
wxClientData* data = _comboBox->GetClientObject(_comboBox->GetSelection());
if (data == NULL) return "";
wxStringClientData* nameStr = dynamic_cast<wxStringClientData*>(data);
int id = _stimTypes.getIdForName(nameStr->GetData().ToStdString());
if (id == -1) return "";
return string::to_string(id);
}
return "";
}
wxWindow* StimTypeArgument::getEditWidget()
{
return _comboBox;
}