Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baa2120
commit 7fc8b5c
Showing
7 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "FxChooser.h" | ||
|
||
#include "debugging/ScopedDebugTimer.h" | ||
#include "os/path.h" | ||
#include "wxutil/dataview/ThreadedDeclarationTreePopulator.h" | ||
#include "wxutil/dataview/VFSTreePopulator.h" | ||
#include "wxutil/decl/DeclarationSelector.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
// Local class for loading FX declarations in a separate thread | ||
class ThreadedFxLoader : | ||
public wxutil::ThreadedDeclarationTreePopulator | ||
{ | ||
private: | ||
constexpr static const char* const FX_ICON = "icon_fx.png"; | ||
|
||
public: | ||
ThreadedFxLoader(const wxutil::DeclarationTreeView::Columns& columns) : | ||
ThreadedDeclarationTreePopulator(decl::Type::Fx, columns, FX_ICON) | ||
{} | ||
|
||
~ThreadedFxLoader() | ||
{ | ||
EnsureStopped(); | ||
} | ||
|
||
void PopulateModel(const wxutil::TreeModel::Ptr& model) override | ||
{ | ||
ScopedDebugTimer timer("ThreadedFxLoader::run()"); | ||
|
||
wxutil::VFSTreePopulator populator(model); | ||
|
||
// Visit all sound shaders and collect them for later insertion | ||
GlobalDeclarationManager().foreachDeclaration(decl::Type::Fx, [&](const decl::IDeclaration::Ptr& decl) | ||
{ | ||
ThrowIfCancellationRequested(); | ||
|
||
// Some shaders contain backslashes, sort them in the tree by replacing the backslashes | ||
auto shaderNameForwardSlashes = os::standardPath(decl->getDeclName()); | ||
|
||
auto fullPath = decl->getModName() + "/" + shaderNameForwardSlashes; | ||
|
||
// Sort the shader into the tree and set the values | ||
populator.addPath(fullPath, [&](wxutil::TreeModel::Row& row, | ||
const std::string& path, const std::string& leafName, bool isFolder) | ||
{ | ||
AssignValuesToRow(row, path, isFolder ? path : decl->getDeclName(), leafName, isFolder); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
class FxSelector : | ||
public wxutil::DeclarationSelector | ||
{ | ||
public: | ||
FxSelector(wxWindow* parent) : | ||
DeclarationSelector(parent, decl::Type::Fx) | ||
{ | ||
Populate(); | ||
} | ||
|
||
void Populate() override | ||
{ | ||
PopulateTreeView(std::make_shared<ThreadedFxLoader>(GetColumns())); | ||
} | ||
}; | ||
|
||
FxChooser::FxChooser(wxWindow* parent) : | ||
DeclarationSelectorDialog(decl::Type::SoundShader, _("Choose FX Declaration"), "FxChooser", parent) | ||
{ | ||
SetSelector(new FxSelector(this)); | ||
AddItemToBottomRow(new wxStaticText(this, wxID_ANY, _("Ctrl + Double Click on treeview items for quick play"))); | ||
} | ||
|
||
std::string FxChooser::ChooseDeclaration(const std::string& preselected) | ||
{ | ||
if (!preselected.empty()) | ||
{ | ||
SetSelectedDeclName(preselected); | ||
} | ||
|
||
if (ShowModal() == wxID_OK) | ||
{ | ||
return GetSelectedDeclName(); | ||
} | ||
|
||
return ""; // Empty selection on cancel | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "wxutil/decl/DeclarationSelectorDialog.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
/** | ||
* Dialog for listing and selection of FX declarations. | ||
*/ | ||
class FxChooser : | ||
public wxutil::DeclarationSelectorDialog | ||
{ | ||
private: | ||
FxChooser(wxWindow* parent = nullptr); | ||
|
||
public: | ||
// Run the dialog and return the selected decl - this will be empty if the user clicks cancel | ||
std::string ChooseDeclaration(const std::string& preselected = std::string()); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters