Skip to content

Commit

Permalink
#5537: Add FxChooser dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 23, 2022
1 parent baa2120 commit 7fc8b5c
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
Binary file added install/bitmaps/icon_fx.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions install/user.xml
Expand Up @@ -344,6 +344,7 @@
<ParticleChooser defaultWidthFraction="0.7" defaultHeightFraction="0.8" />
<SoundChooser defaultWidthFraction="0.5" defaultHeightFraction="0.7" />
<MaterialChooser defaultWidthFraction="0.4" defaultHeightFraction="0.8" />
<FxChooser defaultWidthFraction="0.4" defaultHeightFraction="0.8" />
</windowStates>
</ui>
</user>
1 change: 1 addition & 0 deletions radiant/CMakeLists.txt
Expand Up @@ -72,6 +72,7 @@ add_executable(darkradiant
ui/filters/FiltersMainMenu.cpp
ui/filters/FilterUserInterface.cpp
ui/findshader/FindShader.cpp
ui/fx/FxChooser.cpp
ui/gl/WxGLWidgetManager.cpp
ui/grid/GridUserInterface.cpp
ui/layers/CreateLayerDialog.cpp
Expand Down
93 changes: 93 additions & 0 deletions radiant/ui/fx/FxChooser.cpp
@@ -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
}

}
22 changes: 22 additions & 0 deletions radiant/ui/fx/FxChooser.h
@@ -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());
};

}
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -251,6 +251,7 @@
<ClCompile Include="..\..\radiant\ui\filters\FilterOrthoContextMenuItem.cpp" />
<ClCompile Include="..\..\radiant\ui\filters\FiltersMainMenu.cpp" />
<ClCompile Include="..\..\radiant\ui\filters\FilterUserInterface.cpp" />
<ClCompile Include="..\..\radiant\ui\fx\FxChooser.cpp" />
<ClCompile Include="..\..\radiant\ui\gl\WxGLWidgetManager.cpp" />
<ClCompile Include="..\..\radiant\ui\grid\GridUserInterface.cpp" />
<ClCompile Include="..\..\radiant\ui\groupdialog\GroupDialog.cpp" />
Expand Down Expand Up @@ -449,6 +450,7 @@
<ClInclude Include="..\..\radiant\ui\filters\FilterOrthoContextMenuItem.h" />
<ClInclude Include="..\..\radiant\ui\filters\FiltersMainMenu.h" />
<ClInclude Include="..\..\radiant\ui\filters\FilterUserInterface.h" />
<ClInclude Include="..\..\radiant\ui\fx\FxChooser.h" />
<ClInclude Include="..\..\radiant\ui\gl\WxGLWidgetManager.h" />
<ClInclude Include="..\..\radiant\ui\grid\GridUserInterface.h" />
<ClInclude Include="..\..\radiant\ui\groupdialog\GroupDialog.h" />
Expand Down
9 changes: 9 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -191,6 +191,9 @@
<Filter Include="src\ui\console">
<UniqueIdentifier>{66e30145-e977-405c-9507-fc783318215a}</UniqueIdentifier>
</Filter>
<Filter Include="src\ui\fx">
<UniqueIdentifier>{7d1fd900-f463-401a-bceb-d04af2bd05f3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\radiant\main.cpp">
Expand Down Expand Up @@ -706,6 +709,9 @@
<ClCompile Include="..\..\radiant\ui\materials\MaterialChooser.cpp">
<Filter>src\ui\materials</Filter>
</ClCompile>
<ClCompile Include="..\..\radiant\ui\fx\FxChooser.cpp">
<Filter>src\ui\fx</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\camera\CameraSettings.h">
Expand Down Expand Up @@ -1377,6 +1383,9 @@
<ClInclude Include="..\..\radiant\ui\common\SoundShaderSelector.h">
<Filter>src\ui\common</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\fx\FxChooser.h">
<Filter>src\ui\fx</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit 7fc8b5c

Please sign in to comment.