From 1bc3eb7ddb6ed9272611c904bcba78609d874467 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Fri, 22 Sep 2023 20:32:05 -0400 Subject: [PATCH] Added audio emitter editor panel --- .../src/ComponentsPanel/AudioEmitterPanel.h | 91 +++++++++++++++++++ Editor/src/Windows/EditorSelectionPanel.cpp | 1 + Editor/src/Windows/EditorSelectionPanel.h | 2 + .../Scene/Components/AudioEmitterComponent.h | 2 + 4 files changed, 96 insertions(+) create mode 100644 Editor/src/ComponentsPanel/AudioEmitterPanel.h diff --git a/Editor/src/ComponentsPanel/AudioEmitterPanel.h b/Editor/src/ComponentsPanel/AudioEmitterPanel.h new file mode 100644 index 00000000..912107b8 --- /dev/null +++ b/Editor/src/ComponentsPanel/AudioEmitterPanel.h @@ -0,0 +1,91 @@ +#pragma once +#include "ComponentPanel.h" + +#include +#include +#include +#include + + +class AudioEmitterPanel : ComponentPanel +{ +public: + AudioEmitterPanel() = default; + ~AudioEmitterPanel() = default; + + void Draw(Nuake::Entity entity) override + { + using namespace Nuake; + + if (!entity.HasComponent()) + return; + + auto& component = entity.GetComponent(); + 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(); + } +}; \ No newline at end of file diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index f7c5c74d..8d14d45c 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -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) diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index 1e608200..b380444a 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -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 currentFile; Ref selectedResource; diff --git a/Nuake/src/Scene/Components/AudioEmitterComponent.h b/Nuake/src/Scene/Components/AudioEmitterComponent.h index 1687f9de..c4d04a82 100644 --- a/Nuake/src/Scene/Components/AudioEmitterComponent.h +++ b/Nuake/src/Scene/Components/AudioEmitterComponent.h @@ -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);