Clips can now be dragged and dropped into the animation controller editor

This commit is contained in:
Kah Wei 2023-03-09 12:07:07 +08:00
parent 2c8eca4125
commit e816df28a8
3 changed files with 37 additions and 9 deletions

View File

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

View File

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

View File

@ -418,12 +418,16 @@ namespace SHADE
} }
template<typename T> 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(); std::string text = fieldVTextValue.data();
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.data()); ImGui::PushID(label.data());
TextLabel(label); TextLabel(label);
if (customWidth > 0.0f)
{
ImGui::SetNextItemWidth(customWidth);
}
bool changed = ImGui::InputText("##inputText", &text, ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AutoSelectAll, nullptr, nullptr); bool changed = ImGui::InputText("##inputText", &text, ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AutoSelectAll, nullptr, nullptr);
if(SHDragDrop::BeginTarget()) if(SHDragDrop::BeginTarget())
{ {