added audio stuff

This commit is contained in:
2026-01-18 19:42:25 +01:00
parent 5fdcb6989f
commit f9185e7b26
13 changed files with 471 additions and 1 deletions

View File

@@ -191,6 +191,10 @@ namespace TSE::EDITOR
{
Draw((RectBase*)element, debug);
}
else if (name == "Audio Source")
{
Draw((AudioSource*)element, debug);
}
else if (name == "Camera")
{
Draw((Camera*)element, debug);
@@ -478,6 +482,78 @@ namespace TSE::EDITOR
if(small) DrawImageAnimationSetCompact(element, debug, label);
else DrawImageAnimationSetNormal(element, debug, label);
}
void ElementDrawer::Draw(AudioSource *element, const bool &debug)
{
float availWidth = ImGui::GetContentRegionAvail().x;
int buttonCount = 3;
float spacing = ImGui::GetStyle().ItemSpacing.x;
float buttonWidth = (availWidth - (buttonCount - 1) * spacing) / buttonCount;
float buttonHeight = 0.0f; // 0.0 = default height
if (ImGui::Button("Play", ImVec2(buttonWidth, buttonHeight)))
{
element->StartClip(element->currentlyPlaying, false);
}
ImGui::SameLine();
if (ImGui::Button("Pause", ImVec2(buttonWidth, buttonHeight)))
{
element->PausePlaying();
}
ImGui::SameLine();
if (ImGui::Button("Stop", ImVec2(buttonWidth, buttonHeight)))
{
element->StopPlaying();
}
ImGui::Separator();
bool global = element->GetGlobal();
if(ImGui::Checkbox("Global", &global))
{
element->SetGlobal(global);
}
float minDistance = element->GetMinDistance();
if(ImGui::DragFloat("Cutoff Distance", &minDistance))
{
element->SetMinDistance(minDistance);
}
float maxDistance = element->GetMaxDistance();
if(ImGui::DragFloat("Falloff Distance", &maxDistance))
{
element->SetMaxDistance(maxDistance);
}
BeginList("Audio Clips");
//if(ListAddBtn()) { } // --> no add function for now maybe when asset manager is done
for(int i = 0; i < element->clips.size(); i++)
{
BeginListItem("subcomponent##" + std::to_string(i));
Draw(element->GetClipAt(i), debug, "", true);
if (ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows))
{
// Check auf Doppelclick mit linker Maustaste
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
element->StopPlaying();
element->currentlyPlaying = element->GetClipAt(i)->name;
}
}
EndListItem();
if(ListItemXBotton("x##" + std::to_string(i)))
{
element->RemoveClip(element->GetClipAt(i)->name);
}
}
EndList();
}
void ElementDrawer::Draw(AudioClip *element, const bool &debug, const std::string &label, const bool small)
{
if(element == nullptr)
{
ImGui::Text("No Audio Clip Asigned");
return;
}
if(small) DrawAudioClipCompact(element, debug, label);
else DrawAudioClipNormal(element, debug, label);
}
void ElementDrawer::Draw(Camera *element, const bool &debug)
{
const bool isMain = (Camera::mainCamera == element);
@@ -737,6 +813,39 @@ namespace TSE::EDITOR
ImGui::Unindent(20.0f);
}
}
void ElementDrawer::DrawAudioClipCompact(AudioClip *element, const bool &debug, const std::string &label)
{
float item_spacing = ImGui::GetStyle().ItemSpacing.x;
ImVec2 label_size = ImGui::CalcTextSize(label.c_str());
float available_width = ImGui::GetContentRegionAvail().x;
float field_width = available_width - label_size.x - item_spacing;
ImVec2 field_size = ImVec2(field_width, label_size.y + 4);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetColorU32(ImGuiCol_FrameBg)); // gleiche Farbe wie InputText
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, ImGui::GetStyle().FrameRounding);
ImGui::BeginChild("##FakeInput", field_size, true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ImGui::SetCursorPos(ImVec2(2, 2));
ImGui::TextUnformatted(element->name.c_str());
ImGui::EndChild();
ImGui::PopStyleVar();
ImGui::PopStyleColor();
ImGui::SameLine();
ImVec2 cursorCurrent = ImGui::GetCursorPos();
cursorCurrent.y += 2;
ImGui::SetCursorPos(cursorCurrent);
ImGui::TextUnformatted(label.c_str());
}
void ElementDrawer::DrawAudioClipNormal(AudioClip *element, const bool &debug, const std::string &label)
{
//TODO implement
}
void ElementDrawer::DrawImageAnimationSetCompact(ImageAnimationSet *element, const bool &debug, const std::string &label)
{
float item_spacing = ImGui::GetStyle().ItemSpacing.x;

View File

@@ -11,6 +11,8 @@
#include "BehaviourScripts/ImageAnimation.hpp"
#include "BehaviourScripts/RectBase.hpp"
#include "BehaviourScripts/ParticleSystem.hpp"
#include "BehaviourScripts/AudioListener.hpp"
#include "BehaviourScripts/AudioSource.hpp"
namespace TSE::EDITOR
{
@@ -73,10 +75,13 @@ namespace TSE::EDITOR
static void Draw(Sprite* element, const bool& debug, const std::string& label = "", const bool small = false);
static void Draw(Mesh* element, const bool& debug, const std::string& label = "", const bool small = false);
static void Draw(ImageAnimationSet* element, const bool& debug, const std::string& label = "", const bool small = false);
static void Draw(AudioSource* element, const bool& debug);
static void Draw(AudioClip* element, const bool& debug, const std::string& label = "", const bool small = false);
static void Draw(Camera* element, const bool& debug);
static void Draw(ParticleSystem* element, const bool& debug);
static void DrawAudioClipCompact(AudioClip* element, const bool& debug, const std::string& label);
static void DrawAudioClipNormal(AudioClip* element, const bool& debug, const std::string& label);
static void DrawImageAnimationSetCompact(ImageAnimationSet* element, const bool& debug, const std::string& label);
static void DrawImageAnimationSetNormal(ImageAnimationSet* element, const bool& debug, const std::string& label);
static void DrawMeshCompact(Mesh* element, const bool& debug, const std::string& label);