Debian Codegraph @

plugins/dm.objectives/ce/KillComponentEditor.cpp

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