Skip to content

Commit

Permalink
#5127: Add context menu option to apply the sound shader to selected …
Browse files Browse the repository at this point in the history
…entities (WIP)
  • Loading branch information
codereader committed Jan 24, 2021
1 parent f19486d commit 790c29d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
42 changes: 38 additions & 4 deletions radiant/ui/favourites/FavouritesBrowser.cpp
Expand Up @@ -30,6 +30,9 @@ namespace
const char* const APPLY_TEXTURE_TEXT = N_("Apply to selection");
const char* const APPLY_TEXTURE_ICON = "textureApplyToSelection16.png";

const char* const APPLY_SOUNDSHADER_TEXT = N_("Apply to selection");
const char* const APPLY_SOUNDSHADER_ICON = "icon_sound.png";

const char* const ADD_ENTITY_TEXT = N_("Create entity");
const char* const ADD_ENTITY_ICON = "cmenu_add_entity.png";

Expand Down Expand Up @@ -92,7 +95,7 @@ void FavouritesBrowser::constructPopupMenu()

_popupMenu->addItem(
new wxutil::IconTextMenuItem(_(APPLY_TEXTURE_TEXT), APPLY_TEXTURE_ICON),
std::bind(&FavouritesBrowser::onApplyToSelection, this),
std::bind(&FavouritesBrowser::onApplyTextureToSelection, this),
std::bind(&FavouritesBrowser::testSingleTextureSelected, this)
);

Expand All @@ -108,6 +111,12 @@ void FavouritesBrowser::constructPopupMenu()
std::bind(&FavouritesBrowser::testCreateSpeaker, this)
);

_popupMenu->addItem(
new wxutil::IconTextMenuItem(_(APPLY_SOUNDSHADER_TEXT), APPLY_SOUNDSHADER_ICON),
std::bind(&FavouritesBrowser::onApplySoundToSelection, this),
std::bind(&FavouritesBrowser::testApplySoundToSelection, this)
);

_popupMenu->addItem(
new wxutil::StockIconTextMenuItem(_(REMOVE_FROM_FAVOURITES), wxART_DEL_BOOKMARK),
std::bind(&FavouritesBrowser::onRemoveFromFavourite, this),
Expand Down Expand Up @@ -332,13 +341,20 @@ void FavouritesBrowser::onItemActivated(wxListEvent& ev)
switch (data->type)
{
case decl::Type::Material:
onApplyToSelection();
onApplyTextureToSelection();
break;
case decl::Type::EntityDef:
onCreateEntity();
break;
case decl::Type::SoundShader:
onCreateSpeaker();
if (testCreateSpeaker())
{
onCreateSpeaker();
}
else if (testApplySoundToSelection())
{
onApplyTextureToSelection();
}
break;
}
}
Expand Down Expand Up @@ -382,7 +398,7 @@ void FavouritesBrowser::onRemoveFromFavourite()
// A repopulation has already been rescheduled
}

void FavouritesBrowser::onApplyToSelection()
void FavouritesBrowser::onApplyTextureToSelection()
{
auto selection = getSelectedItems();

Expand All @@ -398,6 +414,24 @@ bool FavouritesBrowser::testSingleTextureSelected()
return getSelectedDeclType() == decl::Type::Material;
}

void FavouritesBrowser::onApplySoundToSelection()
{
auto selection = getSelectedItems();

if (selection.size() != 1) return;

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

// TODO: Apply sound shader to entities
}

bool FavouritesBrowser::testApplySoundToSelection()
{
const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();

return info.entityCount > 0 && getSelectedDeclType() == decl::Type::SoundShader;
}

void FavouritesBrowser::onCreateEntity()
{
if (!testCreateEntity()) return;
Expand Down
4 changes: 3 additions & 1 deletion radiant/ui/favourites/FavouritesBrowser.h
Expand Up @@ -82,8 +82,10 @@ class FavouritesBrowser :
std::vector<long> getSelectedItems();
decl::Type getSelectedDeclType();

void onApplyToSelection();
void onApplyTextureToSelection();
bool testSingleTextureSelected();
void onApplySoundToSelection();
bool testApplySoundToSelection();
void onCreateEntity();
bool testCreateEntity();
void onCreateSpeaker();
Expand Down

0 comments on commit 790c29d

Please sign in to comment.