Implemented Animation Clip asset and animation controller #410

Merged
XiaoQiDigipen merged 66 commits from SP3-22-AnimationController into main 2023-03-09 16:19:40 +08:00
3 changed files with 37 additions and 9 deletions
Showing only changes of commit e816df28a8 - Show all commits

View File

@ -25,11 +25,14 @@ of DigiPen Institute of Technology is prohibited.
#include "Editor/SHEditorWidgets.hpp"
#include "Editor/Command/SHCommand.hpp"
#include "Input/SHInputManager.h"
#include "Resource/SHResourceManager.h"
#include "Editor/EditorWindow/SHEditorWindowManager.h"
#include "Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Cosntructors/Destructors */
/* Constructors/Destructors */
/*-----------------------------------------------------------------------------------*/
SHAnimationControllerEditor::SHAnimationControllerEditor()
: SHEditorWindow("Animation Controller Editor", ImGuiWindowFlags_MenuBar)
@ -318,6 +321,7 @@ namespace SHADE
void SHAnimationControllerEditor::drawNodeEditor()
{
static constexpr float NODE_WIDTH = 80.0f;
static constexpr float TEXT_FIELD_PADDING = 15.0f;
ImNodes::BeginNodeEditor();
{
@ -346,8 +350,8 @@ namespace SHADE
node.EditingName = false;
}
ImGui::SameLine();
static constexpr float TEXT_FIELD_PADDING = 15.0f;
ImGui::SetNextItemWidth(std::max(ImGui::CalcTextSize(node.Name.c_str()).x + TEXT_FIELD_PADDING, NODE_WIDTH));
SHEditorUI::InputTextField("", node.Name);
}
else
@ -363,11 +367,32 @@ namespace SHADE
ImNodes::EndNodeTitleBar();
// Body
ImGui::Text("Clip");
ImGui::SameLine();
std::array<char, 255> buffer = { '\0' };
ImGui::SetNextItemWidth(std::max(NODE_WIDTH, ImGui::CalcTextSize(buffer.data()).x));
ImGui::InputText("", buffer.data(), buffer.size());
const auto CLIP_NAME = SHResourceManager::GetAssetName<SHAnimationClip>(node.Clip).value_or("");
ImGui::SetNextItemWidth(NODE_WIDTH);
SHEditorWidgets::DragDropReadOnlyField<AssetID>
(
"Clip", CLIP_NAME,
[&]()
{
return SHResourceManager::GetAssetID<SHAnimationClip>(node.Clip).value_or(0);
},
[&](AssetID id)
{
if (SHAssetManager::GetType(id) != AssetType::ANIM_CLIP)
return;
node.Clip = SHResourceManager::LoadOrGet<SHAnimationClip>(id);
SHResourceManager::FinaliseChanges();
},
SHDragDrop::DRAG_RESOURCE, {}, NODE_WIDTH
);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if (node.Clip)
{
AssetID assetID = SHResourceManager::GetAssetID<SHAnimationClip>(node.Clip).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->SetScrollTo(assetID);
}
}
// Input Nodes
for (auto inputAttrib : node.InputAttribs)

View File

@ -5,7 +5,6 @@
\date Mar 1, 2023
\brief Contains the definition of SHRawAnimInspector's functions.
Copyright (C) 2023 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.

View File

@ -418,12 +418,16 @@ namespace SHADE
}
template<typename T>
static bool DragDropReadOnlyField(std::string const& label, std::string_view const& fieldVTextValue, std::function<T (void)> const& get, std::function<void(T const&)> const& set, SHDragDrop::DragDropTag const& dragDropTag, std::string_view const& tooltip = {})
static bool DragDropReadOnlyField(std::string const& label, std::string_view const& fieldVTextValue, std::function<T (void)> const& get, std::function<void(T const&)> const& set, SHDragDrop::DragDropTag const& dragDropTag, std::string_view const& tooltip = {}, float customWidth = -1.0f)
{
std::string text = fieldVTextValue.data();
ImGui::BeginGroup();
ImGui::PushID(label.data());
TextLabel(label);
if (customWidth > 0.0f)
{
ImGui::SetNextItemWidth(customWidth);
}
bool changed = ImGui::InputText("##inputText", &text, ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AutoSelectAll, nullptr, nullptr);
if(SHDragDrop::BeginTarget())
{