Added audio emitter editor panel

This commit is contained in:
Antoine Pilote
2023-09-22 20:32:05 -04:00
parent 7971757868
commit 1bc3eb7ddb
4 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
#pragma once
#include "ComponentPanel.h"
#include <src/Core/FileSystem.h>
#include <src/Core/Maths.h>
#include <src/Scene/Components/AudioEmitterComponent.h>
#include <src/Scene/Entities/ImGuiHelper.h>
class AudioEmitterPanel : ComponentPanel
{
public:
AudioEmitterPanel() = default;
~AudioEmitterPanel() = default;
void Draw(Nuake::Entity entity) override
{
using namespace Nuake;
if (!entity.HasComponent<AudioEmitterComponent>())
return;
auto& component = entity.GetComponent<AudioEmitterComponent>();
BeginComponentTable(AUDIO EMITTER, AudioEmitterComponent);
{
{
ImGui::Text("Audio File");
ImGui::TableNextColumn();
std::string path = component.FilePath;
ImGui::Button(component.FilePath.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0));
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_AudioFile"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
path = Nuake::FileSystem::AbsoluteToRelative(fullPath);
component.FilePath = path;
}
ImGui::EndDragDropTarget();
}
ImGui::TableNextColumn();
ComponentTableReset(component.FilePath, "");
}
ImGui::TableNextColumn();
{
ImGui::Text("Playing");
ImGui::TableNextColumn();
ImGui::Checkbox("##Playing", &component.IsPlaying);
ImGui::TableNextColumn();
ComponentTableReset(component.IsPlaying, false);
}
ImGui::TableNextColumn();
{
ImGui::Text("Volume");
ImGui::TableNextColumn();
ImGui::DragFloat("##Volume", &component.Volume, 0.00f, 1.0f);
ImGui::TableNextColumn();
ComponentTableReset(component.Volume, 1.0f);
}
ImGui::TableNextColumn();
{
ImGui::Text("Playback Speed");
ImGui::TableNextColumn();
ImGui::DragFloat("##PlaybackSpeed", &component.PlaybackSpeed, 0.01f, 0.0001f);
ImGui::TableNextColumn();
ComponentTableReset(component.PlaybackSpeed, 1.0f);
}
ImGui::TableNextColumn();
{
ImGui::Text("Pan");
ImGui::TableNextColumn();
ImGui::DragFloat("##Pan", &component.Pan, 0.01f, -1.0f, 1.0f);
ImGui::TableNextColumn();
ComponentTableReset(component.Pan, 0.0f);
}
}
EndComponentTable();
}
};

View File

@@ -111,6 +111,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
mCylinderColliderPanel.Draw(entity);
mMeshColliderPanel.Draw(entity);
mCharacterControllerPanel.Draw(entity);
mAudioEmitterPanel.Draw(entity);
}
void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity)

View File

@@ -22,6 +22,7 @@
#include "../ComponentsPanel/ParticleEmitterPanel.h"
#include "../ComponentsPanel/SkinnedModelPanel.h"
#include "../ComponentsPanel/BonePanel.h"
#include "../ComponentsPanel/AudioEmitterPanel.h"
class EditorSelectionPanel
{
@@ -43,6 +44,7 @@ private:
CharacterControllerPanel mCharacterControllerPanel;
ParticleEmitterPanel mParticleEmitterPanel;
BonePanel mBonePanel;
AudioEmitterPanel mAudioEmitterPanel;
Ref<Nuake::File> currentFile;
Ref<Nuake::Resource> selectedResource;

View File

@@ -10,6 +10,8 @@ namespace Nuake {
float Volume = 1.0f;
float Pan = 0.0f;
float PlaybackSpeed = 1.0f;
bool IsPlaying = false;
std::string FilePath;
json Serialize();
bool Deserialize(const json& j);