Debian Codegraph @

plugins/dm.objectives/ce/AlertComponentEditor.cpp

raw
1 #include "AlertComponentEditor.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
18 AlertComponentEditor::RegHelper AlertComponentEditor::regHelper;
19
20 // Constructor
21 AlertComponentEditor::AlertComponentEditor(wxWindow* parent, Component& component) :
22 ComponentEditorBase(parent),
23 _component(&component),
24 _targetCombo(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 _amount->Bind(wxEVT_SPINCTRL, [&] (wxSpinEvent& ev) { writeToComponent(); });
30
31 _alertLevel = new wxSpinCtrl(_panel, wxID_ANY);
32 _alertLevel->SetValue(1);
33 _alertLevel->SetRange(1, 5);
34 _alertLevel->Bind(wxEVT_SPINCTRL, [&] (wxSpinEvent& ev) { writeToComponent(); });
35
36 // Main vbox
37 wxStaticText* label = new wxStaticText(_panel, wxID_ANY, _("AI:"));
38 label->SetFont(label->GetFont().Bold());
39
40 _panel->GetSizer()->Add(label, 0, wxBOTTOM, 6);
41 _panel->GetSizer()->Add(_targetCombo, 0, wxBOTTOM | wxEXPAND, 6);
42
43 _panel->GetSizer()->Add(new wxStaticText(_panel, wxID_ANY, _("Amount:")), 0, wxBOTTOM, 6);
44 _panel->GetSizer()->Add(_amount, 0, wxBOTTOM, 6);
45
46 _panel->GetSizer()->Add(new wxStaticText(_panel, wxID_ANY, _("Minimum Alert Level:")), 0, wxBOTTOM, 6);
47 _panel->GetSizer()->Add(_alertLevel, 0, wxBOTTOM, 6);
48
49 // Populate the SpecifierEditCombo with the first specifier
50 _targetCombo->setSpecifier(
51 component.getSpecifier(Specifier::FIRST_SPECIFIER)
52 );
53
54 // Initialise the spin buttons with the values from the component arguments
55 _amount->SetValue(string::convert<int>(component.getArgument(0)));
56 _alertLevel->SetValue(string::convert<int>(component.getArgument(1)));
57 }
58
59 // Write to component
60 void AlertComponentEditor::writeToComponent() const
61 {
62 if (!_active) return; // still under construction
63
64 assert(_component);
65 _component->setSpecifier(
66 Specifier::FIRST_SPECIFIER, _targetCombo->getSpecifier()
67 );
68
69 _component->clearArguments();
70 _component->setArgument(0, string::to_string(_amount->GetValue()));
71 _component->setArgument(1, string::to_string(_alertLevel->GetValue()));
72 }
73
74 } // namespace ce
75
76 } // namespace objectives