Debian Codegraph @

plugins/dm.objectives/ce/AIFindBodyComponentEditor.cpp

raw
1 #include "AIFindBodyComponentEditor.h"
2 #include "../SpecifierType.h"
3 #include "../Component.h"
4
5 #include "string/convert.h"
6
7 #include "i18n.h"
8 #include <wx/spinctrl.h>
9 #include <wx/stattext.h>
10
11 namespace objectives
12 {
13
14 namespace ce
15 {
16
17 // Registration helper, will register this editor in the factory
18 AIFindBodyComponentEditor::RegHelper AIFindBodyComponentEditor::regHelper;
19
20 // Constructor
21 AIFindBodyComponentEditor::AIFindBodyComponentEditor(wxWindow* parent, Component& component) :
22 ComponentEditorBase(parent),
23 _component(&component),
24 _bodyCombo(new SpecifierEditCombo(_panel, getChangeCallback(), SpecifierType::SET_STANDARD_AI()))
25 {
26 _amount = new wxSpinCtrl(_panel, wxID_ANY);
27 _amount->SetValue(1);
28 _amount->SetRange(0, 65535);
29
30 // Main vbox
31 wxStaticText* label = new wxStaticText(_panel, wxID_ANY, _("Body:"));
32 label->SetFont(label->GetFont().Bold());
33
34 _panel->GetSizer()->Add(label, 0, wxBOTTOM, 6);
35 _panel->GetSizer()->Add(_bodyCombo, 0, wxBOTTOM | wxEXPAND, 6);
36 _panel->GetSizer()->Add(new wxStaticText(_panel, wxID_ANY, _("Amount:")), 0, wxBOTTOM, 6);
37 _panel->GetSizer()->Add(_amount, 0, wxBOTTOM, 6);
38
39 // Populate the SpecifierEditCombo with the first specifier
40 _bodyCombo->setSpecifier(
41 component.getSpecifier(Specifier::FIRST_SPECIFIER)
42 );
43
44 // Initialise the spin button with the value from the first component argument
45 _amount->SetValue(string::convert<int>(component.getArgument(0), 1));
46
47 _amount->Bind(wxEVT_SPINCTRL, [&] (wxSpinEvent& ev) { writeToComponent(); });
48 }
49
50 // Write to component
51 void AIFindBodyComponentEditor::writeToComponent() const
52 {
53 if (!_active) return; // still under construction
54
55 assert(_component);
56 _component->setSpecifier(
57 Specifier::FIRST_SPECIFIER, _bodyCombo->getSpecifier()
58 );
59
60 _component->clearArguments();
61 _component->setArgument(0, string::to_string(_amount->GetValue()));
62 }
63
64 } // namespace ce
65
66 } // namespace objectives