/
AIHeadPropertyEditor.cpp
106 lines (81 loc) · 2.45 KB
/
AIHeadPropertyEditor.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
#include "AIHeadPropertyEditor.h"
#include "i18n.h"
#include "ieclass.h"
#include "iuimanager.h"
#include "ientity.h"
#include <wx/panel.h>
#include <wx/button.h>
#include <wx/artprov.h>
#include <wx/sizer.h>
#include "AIHeadChooserDialog.h"
namespace ui
{
AIHeadPropertyEditor::AIHeadPropertyEditor() :
_widget(nullptr),
_entity(nullptr)
{}
AIHeadPropertyEditor::AIHeadPropertyEditor(wxWindow* parent, Entity* entity, const std::string& key, const std::string& options) :
_entity(entity)
{
// Construct the main widget (will be managed by the base class)
_widget = new wxPanel(parent, wxID_ANY);
_widget->SetSizer(new wxBoxSizer(wxHORIZONTAL));
// Create the browse button
wxButton* browseButton = new wxButton(_widget, wxID_ANY, _("Choose AI head..."));
browseButton->SetBitmap(wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "icon_model.png"));
browseButton->Bind(wxEVT_BUTTON, &AIHeadPropertyEditor::onChooseButton, this);
_widget->GetSizer()->Add(browseButton, 0, wxALIGN_CENTER_VERTICAL);
}
AIHeadPropertyEditor::~AIHeadPropertyEditor()
{
if (_widget != nullptr)
{
_widget->Destroy();
}
}
wxPanel* AIHeadPropertyEditor::getWidget()
{
return _widget;
}
void AIHeadPropertyEditor::updateFromEntity()
{
// nothing to do
}
void AIHeadPropertyEditor::setEntity(Entity* entity)
{
if (entity == nullptr) throw std::logic_error("No nullptrs allowed as entity argument");
_entity = entity;
}
IPropertyEditorPtr AIHeadPropertyEditor::createNew(wxWindow* parent, Entity* entity,
const std::string& key, const std::string& options)
{
return IPropertyEditorPtr(new AIHeadPropertyEditor(parent, entity, key, options));
}
void AIHeadPropertyEditor::onChooseButton(wxCommandEvent& ev)
{
// Construct a new head chooser dialog
AIHeadChooserDialog* dialog = new AIHeadChooserDialog;
dialog->setSelectedHead(_entity->getKeyValue(DEF_HEAD_KEY));
// Show and block
if (dialog->ShowModal() == wxID_OK)
{
_entity->setKeyValue(DEF_HEAD_KEY, dialog->getSelectedHead());
}
dialog->Destroy();
}
std::string AIHeadPropertyEditor::runDialog(Entity* entity, const std::string& key)
{
// Construct a new head chooser dialog
AIHeadChooserDialog* dialog = new AIHeadChooserDialog;
std::string prevHead = entity->getKeyValue(key);
dialog->setSelectedHead(prevHead);
// Show and block
std::string selected = prevHead;
if (dialog->ShowModal() == wxID_OK)
{
selected = dialog->getSelectedHead();
}
dialog->Destroy();
return selected;
}
} // namespace ui