diff --git a/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp index 0dc44bc4..fffc5005 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp @@ -25,6 +25,7 @@ of DigiPen Institute of Technology is prohibited. #include "Editor/EditorWindow/SHEditorWindowManager.h" #include "Editor/SHEditorUI.h" #include "Assets/SHAssetManager.h" +#include "Editor/SHEditorWidgets.hpp" namespace SHADE { @@ -133,7 +134,7 @@ namespace SHADE drawMenuBar(); // Button to add a new clip - if (ImGui::Button(std::format("{} Add", ICON_MD_ADD).data())) + if (ImGui::Button(std::format("{} Create Animation Clip", ICON_MD_ADD).data())) { auto prompt = SHEditorWindowManager::GetPopupWindow(); prompt->Init(currRawAnim, [this](AssetID createdAssetId) @@ -146,39 +147,56 @@ namespace SHADE prompt->isOpen = true; } - // Render all clips - for (auto animClip : childAnimClips) + // Render all animation clips + if (SHEditorUI::CollapsingHeader("Existing Animation Clips")) { - bool changed = false; - std::optional animClipName = SHResourceManager::GetAssetName(animClip); - - int firstIndex = animClip->GetStartFrameIndex(); - int endIndex = animClip->GetEndFrameIndex(); - - ImGui::Text(animClipName.has_value() ? animClipName.value().c_str() : ""); - ImGui::SameLine(); - SHEditorUI::PushID(0); - changed |= SHEditorUI::InputInt("", firstIndex); - SHEditorUI::PopID(); - ImGui::SameLine(); - ImGui::Text(" - "); - ImGui::SameLine(); - SHEditorUI::PushID(1); - changed |= SHEditorUI::InputInt("", endIndex); - SHEditorUI::PopID(); - - // If there's a change we need to commit changes - if (changed) + ImGui::Indent(); + for (auto animClip : childAnimClips) { - auto assetId = SHResourceManager::GetAssetID(animClip); - if (assetId.has_value()) + bool changed = false; + std::optional animClipName = SHResourceManager::GetAssetName(animClip); + + int firstIndex = animClip->GetStartFrameIndex(); + int endIndex = animClip->GetEndFrameIndex(); + + ImGui::Separator(); + ImGui::Text(animClipName.has_value() ? animClipName.value().c_str() : ""); + changed |= SHEditorWidgets::SliderInt + ( + "Start", 0, currRawAnim->GetTotalFrames(), + [&]() { return firstIndex; }, + [&](int i) { firstIndex = i; } + ); + changed |= SHEditorWidgets::SliderInt + ( + "End", 0, currRawAnim->GetTotalFrames(), + [&]() { return endIndex; }, + [&](int i) { endIndex = i; } + ); + + // If there's a change we need to commit changes + if (changed && firstIndex < endIndex) { - auto animAsset = SHAssetManager::GetData(assetId.value()); - animAsset->firstIndex = firstIndex; - animAsset->lastIndex = endIndex; - SHAssetManager::SaveAsset(assetId.value()); + // Update runtime asset + *animClip = SHAnimationClip(currRawAnim, firstIndex, endIndex); + + // Update serialized asset + auto assetId = SHResourceManager::GetAssetID(animClip); + if (assetId.has_value()) + { + auto animAsset = SHAssetManager::GetData(assetId.value()); + animAsset->firstIndex = firstIndex; + animAsset->lastIndex = endIndex; + SHAssetManager::SaveAsset(assetId.value()); + } } } + + // Extra separator if there is more than one + if (!childAnimClips.empty()) + ImGui::Separator(); + + ImGui::Unindent(); } } ImGui::End(); @@ -202,6 +220,10 @@ namespace SHADE { childAnimClips = getChildAnimClips(assetId); } + else + { + childAnimClips.clear(); + } } /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Resource/SHResourceManager.hpp b/SHADE_Engine/src/Resource/SHResourceManager.hpp index f2469833..cdda1ad7 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.hpp +++ b/SHADE_Engine/src/Resource/SHResourceManager.hpp @@ -361,6 +361,8 @@ namespace SHADE else if constexpr (std::is_same_v) { loadedAssetData.emplace_back(assetId); + if (assetData.anims.empty()) + return {}; return resourceHub.Create(*assetData.anims[0]); } else if constexpr (std::is_same_v)