From 9a8114f5dd404042310273b68e5e7b4fd0844eff Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 6 Mar 2023 16:43:15 +0800 Subject: [PATCH] Added work in progress animation parameter panel --- .../Animation/SHAnimationControllerEditor.cpp | 83 ++++++++++++++++++- .../Animation/SHAnimationControllerEditor.h | 2 + 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/Animation/SHAnimationControllerEditor.cpp b/SHADE_Engine/src/Editor/EditorWindow/Animation/SHAnimationControllerEditor.cpp index b062e591..8dd98057 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Animation/SHAnimationControllerEditor.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Animation/SHAnimationControllerEditor.cpp @@ -52,6 +52,13 @@ namespace SHADE ">", ">=" }; + typesList = + { + "Boolean", + "Trigger", + "Float", + "Integer" + }; // Set up sample animation controller for testing SHAnimationController controller; @@ -101,7 +108,7 @@ namespace SHADE ImGui::TableNextRow(); { ImGui::TableSetColumnIndex(0); - ImGui::Text("Parameters"); + drawParamsPanel(); ImGui::TableSetColumnIndex(1); drawNodeEditor(); ImGui::TableSetColumnIndex(2); @@ -147,6 +154,79 @@ namespace SHADE } } + void SHAnimationControllerEditor::drawParamsPanel() + { + // Add Parameter Button + if (ImGui::BeginCombo("##Type", "Add Parameter", ImGuiComboFlags_None)) + { + // All other options + for (int i = 0; i < static_cast(typesList.size()); ++i) + { + if (ImGui::Selectable(typesList[i].c_str())) + { + controllerData->Params.emplace("New", static_cast(i)); + } + } + ImGui::EndCombo(); + } + + int paramId = 0; + for (auto param : controllerData->Params) + { + ImGui::PushID(paramId++); + if (SHEditorWidgets::InputText + ( + "", + [&]() { return param.first; }, + [&](const std::string& val) + { + // Remove from previous + const SHAnimationController::AnimParam::Type TYPE = param.second; + controllerData->Params.erase(param.first); + // Put into the new + controllerData->Params[val] = TYPE; + } + )) + { + ImGui::PopID(); + break; // Map was modified + } + ImGui::SameLine(); + if (ImGui::BeginCombo("##Type", typesList[static_cast(param.second)].c_str(), ImGuiComboFlags_None)) + { + // All other options + for (int i = 0; i < static_cast(typesList.size()); ++i) + { + const bool IS_SELECTED = static_cast(param.second) == i; + + if (ImGui::Selectable(typesList[i].c_str(), IS_SELECTED)) + { + SHCommandManager::PerformCommand + ( + std::reinterpret_pointer_cast + ( + std::make_shared> + ( + param.second, + static_cast(i), + [&](SHAnimationController::AnimParam::Type val) { controllerData->Params[param.first] = val; } + ) + ), + false + ); + } + + if (IS_SELECTED) + { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + ImGui::PopID(); + } + } + void SHAnimationControllerEditor::drawNodeEditor() { static constexpr float NODE_WIDTH = 80.0f; @@ -324,7 +404,6 @@ namespace SHADE const bool IS_SELECTED = param.first == linkData.ParamName; if (ImGui::Selectable(param.first.c_str(), IS_SELECTED)) { - linkData.ParamName = param.first; SHCommandManager::PerformCommand ( std::reinterpret_pointer_cast diff --git a/SHADE_Engine/src/Editor/EditorWindow/Animation/SHAnimationControllerEditor.h b/SHADE_Engine/src/Editor/EditorWindow/Animation/SHAnimationControllerEditor.h index 0b566270..adc0887d 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Animation/SHAnimationControllerEditor.h +++ b/SHADE_Engine/src/Editor/EditorWindow/Animation/SHAnimationControllerEditor.h @@ -114,11 +114,13 @@ namespace SHADE std::optional controllerData; // Persistent Cached Data std::vector conditionsList; + std::vector typesList; /*---------------------------------------------------------------------------------*/ /* Helper Functions */ /*---------------------------------------------------------------------------------*/ void drawActiveMenuBar(); + void drawParamsPanel(); void drawNodeEditor(); void drawPropertiesPanel(); NodeAttributeIndex getExtraInputAttrib(uint32_t nodeIndex);