Debian Codegraph @

plugins/dm.objectives/ce/ItemComponentEditor.cpp

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