| 1 |
#include "AIVocalSetChooserDialog.h" |
| 2 |
|
| 3 |
#include "i18n.h" |
| 4 |
#include "ieclass.h" |
| 5 |
#include "isound.h" |
| 6 |
|
| 7 |
#include "eclass.h" |
| 8 |
|
| 9 |
#include <wx/stattext.h> |
| 10 |
#include <wx/sizer.h> |
| 11 |
|
| 12 |
#include "ifavourites.h" |
| 13 |
#include "wxutil/Bitmap.h" |
| 14 |
#include "wxutil/dataview/ResourceTreeViewToolbar.h" |
| 15 |
#include "wxutil/dataview/TreeViewItemStyle.h" |
| 16 |
#include "ThreadedEntityDefPopulator.h" |
| 17 |
|
| 18 |
namespace ui |
| 19 |
{ |
| 20 |
|
| 21 |
namespace |
| 22 |
{ |
| 23 |
const char* const WINDOW_TITLE = N_("Choose AI Vocal Set"); |
| 24 |
} |
| 25 |
|
| 26 |
class ThreadedVocalSetLoader : |
| 27 |
public ThreadedEntityDefPopulator |
| 28 |
{ |
| 29 |
public: |
| 30 |
ThreadedVocalSetLoader(const wxutil::DeclarationTreeView::Columns& columns) : |
| 31 |
ThreadedEntityDefPopulator(columns, "icon_sound.png") |
| 32 |
{} |
| 33 |
|
| 34 |
protected: |
| 35 |
bool ClassShouldBeListed(const IEntityClassPtr& eclass) override |
| 36 |
{ |
| 37 |
return eclass->getAttributeValue("editor_vocal_set") == "1"; |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
AIVocalSetChooserDialog::AIVocalSetChooserDialog() : |
| 42 |
DialogBase(_(WINDOW_TITLE)), |
| 43 |
_preview(nullptr) |
| 44 |
{ |
| 45 |
SetSizer(new wxBoxSizer(wxVERTICAL)); |
| 46 |
|
| 47 |
if (module::GlobalModuleRegistry().moduleExists(MODULE_SOUNDMANAGER)) |
| 48 |
{ |
| 49 |
_preview = new AIVocalSetPreview(this); |
| 50 |
} |
| 51 |
|
| 52 |
_setView = new wxutil::DeclarationTreeView(this, decl::Type::EntityDef, _columns, wxDV_NO_HEADER); |
| 53 |
_setView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &AIVocalSetChooserDialog::onSetSelectionChanged, this); |
| 54 |
|
| 55 |
// Head Name column |
| 56 |
_setView->AppendIconTextColumn("", _columns.iconAndName.getColumnIndex(), |
| 57 |
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 58 |
|
| 59 |
// Allow searching for the name |
| 60 |
_setView->AddSearchColumn(_columns.leafName); |
| 61 |
|
| 62 |
auto vbox1 = new wxBoxSizer(wxVERTICAL); |
| 63 |
|
| 64 |
auto label1 = new wxStaticText(this, wxID_ANY, _("Available Sets")); |
| 65 |
label1->SetFont(label1->GetFont().Bold()); |
| 66 |
|
| 67 |
auto treeViewToolbar = new wxutil::ResourceTreeViewToolbar(this, _setView); |
| 68 |
|
| 69 |
vbox1->Add(label1, 0, wxBOTTOM, 6); |
| 70 |
vbox1->Add(treeViewToolbar, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 6); |
| 71 |
vbox1->Add(_setView, 1, wxEXPAND); |
| 72 |
|
| 73 |
// Right: the description |
| 74 |
auto vbox2 = new wxBoxSizer(wxVERTICAL); |
| 75 |
|
| 76 |
auto label2 = new wxStaticText(this, wxID_ANY, _("Description")); |
| 77 |
label2->SetFont(label2->GetFont().Bold()); |
| 78 |
|
| 79 |
_description = new wxTextCtrl(this, wxID_ANY, "", |
| 80 |
wxDefaultPosition, wxDefaultSize, wxTE_LEFT | wxTE_MULTILINE | wxTE_READONLY | wxTE_WORDWRAP); |
| 81 |
_description->SetMinClientSize(wxSize(-1, 60)); |
| 82 |
|
| 83 |
vbox2->Add(label2, 0, wxBOTTOM, 6); |
| 84 |
vbox2->Add(_description, 1, wxEXPAND | wxBOTTOM, 6); |
| 85 |
|
| 86 |
// Right: the preview control panel |
| 87 |
if (_preview) |
| 88 |
{ |
| 89 |
vbox2->Add(_preview, 0, wxEXPAND); |
| 90 |
} |
| 91 |
|
| 92 |
// dialog hbox, left is the treeview, right is the preview panel |
| 93 |
auto hbox = new wxBoxSizer(wxHORIZONTAL); |
| 94 |
|
| 95 |
hbox->Add(vbox1, 1, wxEXPAND | wxRIGHT, 6); |
| 96 |
hbox->Add(vbox2, 1, wxEXPAND | wxRIGHT, 6); |
| 97 |
|
| 98 |
GetSizer()->Add(hbox, 1, wxEXPAND | wxALL, 12); |
| 99 |
GetSizer()->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_RIGHT | wxBOTTOM | wxRIGHT, 12); |
| 100 |
|
| 101 |
FitToScreen(0.7f, 0.6f); |
| 102 |
|
| 103 |
// Load the found sets into the GtkListStore |
| 104 |
populateSetStore(); |
| 105 |
|
| 106 |
Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &AIVocalSetChooserDialog::_onItemActivated, this); |
| 107 |
} |
| 108 |
|
| 109 |
void AIVocalSetChooserDialog::_onItemActivated(wxDataViewEvent& ev) |
| 110 |
{ |
| 111 |
EndModal(wxID_OK); |
| 112 |
} |
| 113 |
|
| 114 |
void AIVocalSetChooserDialog::setSelectedVocalSet(const std::string& setName) |
| 115 |
{ |
| 116 |
_setView->SetSelectedDeclName(setName); |
| 117 |
} |
| 118 |
|
| 119 |
std::string AIVocalSetChooserDialog::getSelectedVocalSet() |
| 120 |
{ |
| 121 |
return _setView->GetSelectedDeclName(); |
| 122 |
} |
| 123 |
|
| 124 |
void AIVocalSetChooserDialog::handleSetSelectionChanged() |
| 125 |
{ |
| 126 |
_selectedSet = _setView->GetSelectedDeclName(); |
| 127 |
|
| 128 |
// Update sensitivity |
| 129 |
FindWindowById(wxID_OK, this)->Enable(!_selectedSet.empty()); |
| 130 |
_description->Enable(!_selectedSet.empty()); |
| 131 |
|
| 132 |
if (!_selectedSet.empty()) |
| 133 |
{ |
| 134 |
// Lookup the IEntityClass instance |
| 135 |
if (auto ecls = GlobalEntityClassManager().findClass(_selectedSet); ecls) |
| 136 |
{ |
| 137 |
// Update the preview pane |
| 138 |
if (_preview) |
| 139 |
{ |
| 140 |
_preview->setVocalSetEclass(ecls); |
| 141 |
} |
| 142 |
|
| 143 |
// Update the usage panel |
| 144 |
_description->SetValue(eclass::getUsage(ecls)); |
| 145 |
} |
| 146 |
} |
| 147 |
else |
| 148 |
{ |
| 149 |
if (_preview) |
| 150 |
{ |
| 151 |
_preview->setVocalSetEclass(IEntityClassPtr()); |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
void AIVocalSetChooserDialog::onSetSelectionChanged(wxDataViewEvent& ev) |
| 157 |
{ |
| 158 |
handleSetSelectionChanged(); |
| 159 |
} |
| 160 |
|
| 161 |
void AIVocalSetChooserDialog::populateSetStore() |
| 162 |
{ |
| 163 |
_setView->Populate(std::make_shared<ThreadedVocalSetLoader>(_columns)); |
| 164 |
} |
| 165 |
|
| 166 |
} // namespace |