Skip to content

Commit

Permalink
#5127: Implement the "Apply Sound to Selection" algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 24, 2021
1 parent 790c29d commit 6b7edd3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
17 changes: 17 additions & 0 deletions libs/entitylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ientity.h"
#include "ieclass.h"
#include "irender.h"
#include "iselection.h"
#include "igl.h"
#include "iselectiontest.h"

Expand Down Expand Up @@ -476,3 +477,19 @@ class WorldspawnArgFinder :
return _value;
}
};

namespace scene
{

inline void foreachSelectedEntity(const std::function<void(Entity&)>& functor)
{
GlobalSelectionSystem().foreachSelected([&](const INodePtr& node)
{
if (Node_isEntity(node))
{
functor(*Node_getEntity(node));
}
});
}

}
24 changes: 13 additions & 11 deletions radiant/ui/favourites/FavouritesBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "wxutil/dialog/MessageBox.h"
#include "iorthoview.h"
#include "selectionlib.h"
#include "entitylib.h"

namespace ui
{
Expand Down Expand Up @@ -210,18 +211,14 @@ void FavouritesBrowser::reloadFavourites()

for (const auto& fav : favourites)
{
auto displayName = fav;

if (!_showFullPath->IsChecked())
{
auto slashPos = displayName.rfind('/');
displayName = displayName.substr(slashPos == std::string::npos ? 0 : slashPos + 1);
}
auto slashPos = fav.rfind('/');
auto leafName = fav.substr(slashPos == std::string::npos ? 0 : slashPos + 1);;
auto displayName = !_showFullPath->IsChecked() ? leafName : fav;

auto index = _listView->InsertItem(_listView->GetItemCount(), displayName, category.iconIndex);

// Keep the item info locally, store a pointer to it in the list item user data
_listItems.emplace_back(FavouriteItem{ category.type, fav });
_listItems.emplace_back(FavouriteItem{ category.type, fav, leafName });
_listView->SetItemPtrData(index, reinterpret_cast<wxUIntPtr>(&(_listItems.back())));
}
}
Expand Down Expand Up @@ -353,7 +350,7 @@ void FavouritesBrowser::onItemActivated(wxListEvent& ev)
}
else if (testApplySoundToSelection())
{
onApplyTextureToSelection();
onApplySoundToSelection();
}
break;
}
Expand Down Expand Up @@ -422,7 +419,12 @@ void FavouritesBrowser::onApplySoundToSelection()

auto* data = reinterpret_cast<FavouriteItem*>(_listView->GetItemData(selection.front()));

// TODO: Apply sound shader to entities
UndoableCommand cmd("ApplySoundShaderToSelection");

scene::foreachSelectedEntity([&](Entity& entity)
{
entity.setKeyValue("s_shader", data->leafName);
});
}

bool FavouritesBrowser::testApplySoundToSelection()
Expand Down Expand Up @@ -489,7 +491,7 @@ void FavouritesBrowser::onCreateSpeaker()
auto* data = reinterpret_cast<FavouriteItem*>(_listView->GetItemData(selection.front()));

GlobalCommandSystem().executeCommand("CreateSpeaker", {
cmd::Argument(data->fullPath), cmd::Argument(GlobalXYWndManager().getActiveViewOrigin())
cmd::Argument(data->leafName), cmd::Argument(GlobalXYWndManager().getActiveViewOrigin())
});
}

Expand Down
1 change: 1 addition & 0 deletions radiant/ui/favourites/FavouritesBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FavouritesBrowser :
{
decl::Type type;
std::string fullPath;
std::string leafName;
};

wxFrame* _tempParent;
Expand Down

0 comments on commit 6b7edd3

Please sign in to comment.