File: AIVocalSetPropertyEditor.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (106 lines) | stat: -rw-r--r-- 2,709 bytes parent folder | download | duplicates (3)
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 "AIVocalSetPropertyEditor.h"

#include "i18n.h"
#include "ieclass.h"
#include "ientity.h"

#include <wx/panel.h>
#include <wx/button.h>
#include "wxutil/Bitmap.h"
#include <wx/sizer.h>

#include "AIVocalSetChooserDialog.h"

namespace ui
{

AIVocalSetPropertyEditor::AIVocalSetPropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key) :
	_entities(entities),
    _key(key)
{
	// 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, _("Select Vocal Set..."));
	browseButton->SetBitmap(wxutil::GetLocalBitmap("icon_sound.png"));
	browseButton->Bind(wxEVT_BUTTON, &AIVocalSetPropertyEditor::onChooseButton, this);

	_widget->GetSizer()->Add(browseButton, 0, wxALIGN_CENTER_VERTICAL);
}

AIVocalSetPropertyEditor::~AIVocalSetPropertyEditor()
{
	if (_widget != nullptr)
	{
		_widget->Destroy();
	}
}

wxPanel* AIVocalSetPropertyEditor::getWidget()
{
	return _widget;
}

void AIVocalSetPropertyEditor::updateFromEntities()
{
	// Nothing to do
}

sigc::signal<void(const std::string&, const std::string&)>& AIVocalSetPropertyEditor::signal_keyValueApplied()
{
    return _sigKeyValueApplied;
}

IPropertyEditor::Ptr AIVocalSetPropertyEditor::CreateNew(wxWindow* parent, IEntitySelection& entities,
    const ITargetKey::Ptr& key)
{
	return std::make_shared<AIVocalSetPropertyEditor>(parent, entities, key);
}

void AIVocalSetPropertyEditor::onChooseButton(wxCommandEvent& ev)
{
	// Construct a new vocal set chooser dialog
	AIVocalSetChooserDialog* dialog = new AIVocalSetChooserDialog;

	dialog->setSelectedVocalSet(_entities.getSharedKeyValue(DEF_VOCAL_SET_KEY, true));

	// Show and block
	if (dialog->ShowModal() == wxID_OK)
	{
        auto selectedSet = dialog->getSelectedVocalSet();

        _entities.foreachEntity([&](const IEntityNodePtr& entity)
        {
            entity->getEntity().setKeyValue(DEF_VOCAL_SET_KEY, selectedSet);
        });

        signal_keyValueApplied().emit(DEF_VOCAL_SET_KEY, selectedSet);
	}

	dialog->Destroy();
}

std::string AIVocalSetEditorDialogWrapper::runDialog(Entity* entity, const std::string& key)
{
    // Construct a new vocal set chooser dialog
    AIVocalSetChooserDialog* dialog = new AIVocalSetChooserDialog;

    std::string oldValue = entity->getKeyValue(DEF_VOCAL_SET_KEY);
    dialog->setSelectedVocalSet(oldValue);

    // Show and block
    std::string rv = oldValue;

    if (dialog->ShowModal() == wxID_OK)
    {
        rv = dialog->getSelectedVocalSet();
    }

    dialog->Destroy();

    return rv;
}

} // namespace ui