124 lines
3.4 KiB
C++
124 lines
3.4 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "SMixerEffectList.h"
|
|
|
|
#include "DesktopPlatformModule.h"
|
|
#include "SButton.h"
|
|
#include "SlateOptMacros.h"
|
|
#include "SMixerEffectItem.h"
|
|
#include "SScrollBox.h"
|
|
#include "Singleton/MixerList.h"
|
|
#include "Mixer/MixerTrack.h"
|
|
#include "Singleton/PluginHostList.h"
|
|
|
|
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
|
|
|
SMixerEffectList::~SMixerEffectList()
|
|
{
|
|
FMixerList::Get().OnMixerTrackEffectAdded.RemoveAll(this);
|
|
// FMixerList::Get().OnMixerTrackEffectRemoved.RemoveAll(this);
|
|
FMixerList::Get().OnMixerTrackRemoved.RemoveAll(this);
|
|
}
|
|
|
|
void SMixerEffectList::Construct(const FArguments& InArgs)
|
|
{
|
|
FMixerList::Get().OnMixerTrackRemoved.AddRaw(this, &SMixerEffectList::OnMixerTrackRemoved);
|
|
FMixerList::Get().OnMixerTrackEffectAdded.AddRaw(this, &SMixerEffectList::OnMixerTrackEffectAdded);
|
|
// FMixerList::Get().OnMixerTrackEffectRemoved.AddRaw(this, &SMixerEffectList::OnMixerTrackEffectRemoved);
|
|
FPluginHostList::Get().OnPluginHostRemoved.AddRaw(this, &SMixerEffectList::OnMixerTrackEffectRemoved);
|
|
|
|
ChildSlot
|
|
[
|
|
SAssignNew(ScrollBox, SScrollBox)
|
|
.Orientation(Orient_Vertical)
|
|
.AnimateWheelScrolling(true)
|
|
.Visibility(EVisibility::SelfHitTestInvisible)
|
|
+SScrollBox::Slot()
|
|
[
|
|
SAssignNew(VerticalBox, SVerticalBox)
|
|
]
|
|
+SScrollBox::Slot()
|
|
[
|
|
SAssignNew(AddEffectButton, SButton)
|
|
.Text(FText::FromString("Add Effect"))
|
|
.OnClicked(this, &SMixerEffectList::AddNewEffect)
|
|
.IsEnabled(false)
|
|
]
|
|
];
|
|
}
|
|
|
|
void SMixerEffectList::SetMixerTrack(FMixerTrack* InMixerTrack)
|
|
{
|
|
if (MixerTrack == InMixerTrack)
|
|
return;
|
|
VerticalBox->ClearChildren();
|
|
MixerTrack = InMixerTrack;
|
|
if (!MixerTrack)
|
|
{
|
|
AddEffectButton->SetEnabled(false);
|
|
return;
|
|
}
|
|
|
|
AddEffectButton->SetEnabled(true);
|
|
for (FPluginHost* Effect : MixerTrack->Effects)
|
|
{
|
|
AddEffectItemWidget(Effect);
|
|
}
|
|
}
|
|
|
|
void SMixerEffectList::OnMixerTrackEffectAdded(FMixerTrack* InMixerTrack, FPluginHost* InPluginHost)
|
|
{
|
|
if (MixerTrack != InMixerTrack)
|
|
return;
|
|
AddEffectItemWidget(InPluginHost);
|
|
}
|
|
|
|
void SMixerEffectList::OnMixerTrackEffectRemoved(FPluginHost* InPluginHost)
|
|
{
|
|
const int32 NumSlots = VerticalBox->NumSlots();
|
|
for (int i = 0; i < NumSlots; ++i)
|
|
{
|
|
SVerticalBox::FSlot& Slot = VerticalBox->GetSlot(i);
|
|
const TSharedRef<SWidget>& Widget = Slot.GetWidget();
|
|
TSharedRef<SMixerEffectItem> EffectItem = StaticCastSharedRef<SMixerEffectItem>(Widget);
|
|
if (EffectItem->PluginHost == InPluginHost)
|
|
{
|
|
VerticalBox->RemoveSlot(EffectItem);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SMixerEffectList::OnMixerTrackRemoved(FMixerTrack* InMixerTrack)
|
|
{
|
|
if (MixerTrack != InMixerTrack)
|
|
return;
|
|
VerticalBox->ClearChildren();
|
|
}
|
|
|
|
void SMixerEffectList::AddEffectItemWidget(FPluginHost* InPluginHost)
|
|
{
|
|
VerticalBox->AddSlot()
|
|
[
|
|
SNew(SMixerEffectItem, InPluginHost)
|
|
];
|
|
}
|
|
|
|
FReply SMixerEffectList::AddNewEffect()
|
|
{
|
|
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
|
|
FString FileTypes = TEXT("Dynamic Link Library (*.dll)|*.dll");
|
|
TArray<FString> OutFiles;
|
|
DesktopPlatform->OpenFileDialog(nullptr, TEXT("Choose a DLL"), TEXT(""), TEXT(""), FileTypes, EFileDialogFlags::None, OutFiles);
|
|
if (OutFiles.Num() == 0)
|
|
return FReply::Handled();
|
|
FPluginHost* EffectPlugin = FPluginHostList::Get().TryLoadPlugin(OutFiles[0]);
|
|
if (!EffectPlugin)
|
|
return FReply::Handled();
|
|
MixerTrack->AddEffect(EffectPlugin);
|
|
return FReply::Handled();
|
|
}
|
|
|
|
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
|