diff --git a/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestComponents.h b/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestComponents.h index e2e53d6b..b95a0233 100644 --- a/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestComponents.h +++ b/SHADE_Engine/src/ECS_Base/UnitTesting/SHTestComponents.h @@ -1,6 +1,7 @@ #pragma once #include "../Components/SHComponent.h" +#include namespace SHADE { @@ -27,4 +28,50 @@ namespace SHADE std::string value{}; }; + class SHComponent_ENUM : public SHComponent + { + public: + enum class Option + { + OPT_A, + OPT_B, + OPT_C + }; + + bool boolTest{}; + int intTest{}; + float floatTest{}; + double doubleTest{}; + long longTest{}; + uint8_t uint8Test{}; + uint16_t uint16Test{}; + uint32_t uint32Test{}; + uint64_t uint64Test{}; + + + Option option; + RTTR_ENABLE() + }; + + RTTR_REGISTRATION + { + using namespace rttr; + registration::enumeration("Option") + ( + value("Option A", SHComponent_ENUM::Option::OPT_A), + value("Option B", SHComponent_ENUM::Option::OPT_B), + value("Option C", SHComponent_ENUM::Option::OPT_C) + ); + rttr::registration::class_("Enum Component") + .property("Option", &SHComponent_ENUM::option) + .property("boolTest", &SHComponent_ENUM::boolTest) + .property("intTest", &SHComponent_ENUM::intTest)( metadata("MIN", 0.0f), metadata("MAX", 1.f)) + .property("floatTest", &SHComponent_ENUM::floatTest)(metadata("MIN", 0.0f), metadata("MAX", 1.f)) + .property("doubleTest", &SHComponent_ENUM::doubleTest)(metadata("MIN", 0.0f), metadata("MAX", 1.f)) + .property("uint8Test", &SHComponent_ENUM::uint8Test)(metadata("MIN", 0.0f), metadata("MAX", 1.f)) + .property("uint16Test", &SHComponent_ENUM::uint16Test)(metadata("MIN", 0.0f), metadata("MAX", 1.f)) + .property("uint32Test", &SHComponent_ENUM::uint32Test)(metadata("MIN", 0.0f), metadata("MAX", 1.f)) + .property("uint64Test", &SHComponent_ENUM::uint64Test)(metadata("MIN", 0.0f), metadata("MAX", 1.f)); + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index c0db5622..2d326d09 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -12,6 +12,7 @@ #include "Editor/IconsMaterialDesign.h" #include "ECS_Base/Components/SHComponent.h" #include "Editor/SHEditorWidgets.hpp" +#include "Reflection/SHReflectionMetadata.h" namespace SHADE { template::value, bool> = true> @@ -65,14 +66,112 @@ namespace SHADE ComboBox(property.get_name().data(), list, [component, property]{return property.get_value(component).to_int();}, [component, property](int const& idx) { auto enumAlign = property.get_enumeration(); - auto names = enumAlign.get_names(); - - property.set_value(component, *(enumAlign.get_values().begin().operator++(idx))); + auto values = enumAlign.get_values(); + auto it = std::next(values.begin(), idx); + property.set_value(component, *it); }); } else if(type.is_arithmetic()) { - + if (type == rttr::type::get()) + { + CheckBox(property.get_name().data(), [component, property]{return property.get_value(component).to_bool();}, [component, property](bool const& result){property.set_value(component, result);}); + } + //else if (type == rttr::type::get()) + //{ + // + //} + else if (type == rttr::type::get() || type == rttr::type::get() || type == rttr::type::get() || type == rttr::type::get()) + { + auto metaMin = property.get_metadata(META::min); + auto metaMax = property.get_metadata(META::max); + if(metaMin && metaMax) + { + SliderInt(property.get_name().data(), metaMin.template get_value(), metaMin.template get_value(), [component, property]{return property.get_value(component).to_int();}, [component, property](int const& result){property.set_value(component, result);}); + } + else + { + DragInt(property.get_name().data(), [component, property]{return property.get_value(component).to_int();}, [component, property](int const& result){property.set_value(component, result);}); + } + } + else if (type == rttr::type::get()) + { + auto metaMin = property.get_metadata(META::min); + auto metaMax = property.get_metadata(META::max); + if(metaMin.is_valid() && metaMax.is_valid()) + { + SliderScalar(property.get_name().data(), ImGuiDataType_U8, metaMin.template get_value(), metaMax.template get_value(), [component, property]{return property.get_value(component).to_uint8();}, [component, property](uint8_t const& result){property.set_value(component, result);},"%zu"); + } + else + { + DragScalar(property.get_name().data(), ImGuiDataType_U8, [component, property]{return property.get_value(component).to_uint8();}, [component, property](uint8_t const& result){property.set_value(component, result);},0.1f,0,0,"%zu"); + } + } + else if (type == rttr::type::get()) + { + auto metaMin = property.get_metadata(META::min); + auto metaMax = property.get_metadata(META::max); + if(metaMin.is_valid() && metaMax.is_valid()) + { + SliderScalar(property.get_name().data(), ImGuiDataType_U16, metaMin.template get_value(), metaMin.template get_value(), [component, property]{return property.get_value(component).to_uint16();}, [component, property](uint16_t const& result){property.set_value(component, result);},"%zu"); + } + else + { + DragScalar(property.get_name().data(), ImGuiDataType_U16, [component, property]{return property.get_value(component).to_uint16();}, [component, property](uint16_t const& result){property.set_value(component, result);},0.1f,0,0,"%zu"); + } + } + else if (type == rttr::type::get()) + { + auto metaMin = property.get_metadata(META::min); + auto metaMax = property.get_metadata(META::max); + if (metaMin.is_valid() && metaMax.is_valid()) + { + SliderScalar(property.get_name().data(), ImGuiDataType_U32, metaMin.template get_value(), metaMin.template get_value(), [component, property]{ return property.get_value(component).to_uint32(); }, [component, property](uint32_t const& result){property.set_value(component, result); },"%zu"); + } + else + { + DragScalar(property.get_name().data(), ImGuiDataType_U32, [component, property]{ return property.get_value(component).to_uint32(); }, [component, property](uint32_t const& result){property.set_value(component, result); },0.1f,0,0,"%zu"); + } + } + else if (type == rttr::type::get()) + { + auto metaMin = property.get_metadata(META::min); + auto metaMax = property.get_metadata(META::max); + if(metaMin.is_valid() && metaMax.is_valid()) + { + SliderScalar(property.get_name().data(), ImGuiDataType_U64, metaMin.template get_value(), metaMin.template get_value(), [component, property]{return property.get_value(component).to_uint64();}, [component, property](uint64_t const& result){property.set_value(component, result);},"%zu"); + } + else + { + DragScalar(property.get_name().data(), ImGuiDataType_U64, [component, property]{return property.get_value(component).to_uint64();}, [component, property](uint64_t const& result){property.set_value(component, result);},0.1f,0,0,"%zu"); + } + } + else if (type == rttr::type::get()) + { + auto metaMin = property.get_metadata(META::min); + auto metaMax = property.get_metadata(META::max); + if(metaMin.is_valid() && metaMax.is_valid()) + { + SliderFloat(property.get_name().data(), metaMin.template get_value(), metaMin.template get_value(), [component, property]{return property.get_value(component).to_float();}, [component, property](float const& result){property.set_value(component, result);}); + } + else + { + DragFloat(property.get_name().data(), [component, property]{return property.get_value(component).to_float();}, [component, property](float const& result){property.set_value(component, result);}); + } + } + else if (type == rttr::type::get()) + { + auto metaMin = property.get_metadata(META::min); + auto metaMax = property.get_metadata(META::max); + if(metaMin.is_valid() && metaMax.is_valid()) + { + SliderScalar(property.get_name().data(), ImGuiDataType_Double, metaMin.template get_value(), metaMin.template get_value(), [component, property]{return property.get_value(component).to_double();}, [component, property](double const& result){property.set_value(component, result);}); + } + else + { + DragScalar(property.get_name().data(), ImGuiDataType_Double, [component, property]{return property.get_value(component).to_double();}, [component, property](double const& result){property.set_value(component, result);}, 0.1f); + } + } } else if (type == rttr::type::get()) { diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index fba9512e..0fb5b926 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -11,6 +11,7 @@ #include "Editor/SHImGuiHelpers.hpp" #include "Editor/SHEditorWidgets.hpp" #include "SHEditorComponentView.hpp" +#include "ECS_Base/UnitTesting/SHTestComponents.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" namespace SHADE @@ -54,11 +55,20 @@ namespace SHADE { DrawComponent(transformComponent); } + if(auto renderableComponent = SHComponentManager::GetComponent_s(eid)) + { + DrawComponent(renderableComponent); + } + if(auto testComponent = SHComponentManager::GetComponent_s(eid)) + { + DrawComponent(testComponent); + } ImGui::Separator(); if(ImGui::BeginMenu(std::format("{} Add Component", ICON_MD_LIBRARY_ADD).data())) { DrawAddComponentButton(eid); DrawAddComponentButton(eid); + DrawAddComponentButton(eid); ImGui::EndMenu(); } } diff --git a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp index 0c869c98..6dcf5dfd 100644 --- a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp +++ b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp @@ -202,6 +202,7 @@ namespace SHADE float speed = 1.0f, T p_min = T(), T p_max = T(), const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0) { T value = get(); + std::cout << value <<" \n"; //bool hasChange = ImGui::DragScalar(fieldLabel.c_str(), data_type, &value, speed, &p_min, &p_max, displayFormat, flags); if (ImGui::DragScalar(fieldLabel.c_str(), data_type, &value, speed, &p_min, &p_max, displayFormat, flags)) @@ -257,6 +258,23 @@ namespace SHADE return false; } + template + static bool SliderScalar(const std::string& fieldLabel, ImGuiDataType data_type, T min, T max, std::function get, std::function set, + const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0) + { + T value = get(); + if (ImGui::SliderScalar(fieldLabel.c_str(), data_type, &value, &min, &max, displayFormat, flags)) + { + if (ImGui::IsMouseClicked(ImGuiMouseButton_Left, false) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left, -0.2f)) + SHCommandManager::PerformCommand(std::reinterpret_pointer_cast(std::make_shared>(get(), value, set)), false); + else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) + SHCommandManager::PerformCommand(std::reinterpret_pointer_cast(std::make_shared>(get(), value, set)), true); + + return true; + } + + return false; + } static bool SliderFloat(const std::string& fieldLabel, float min, float max, std::function get, std::function set, const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0) @@ -295,14 +313,17 @@ namespace SHADE static bool ComboBox(const std::string& fieldLabel, std::vector list, std::function get, std::function set) { + bool edited = false; int selected = get(); - if (ImGui::Combo(fieldLabel.c_str(), &selected, list.data(), list.size())) + ImGui::PushID(fieldLabel.c_str()); + ImGui::Text(fieldLabel.c_str()); ImGui::SameLine(); + + if (edited = ImGui::Combo("##Combo", &selected, list.data(), list.size())) { SHCommandManager::PerformCommand(std::reinterpret_pointer_cast(std::make_shared>(get(), selected, set)), false); - return true; } - - return false; + ImGui::PopID(); + return edited; } diff --git a/SHADE_Engine/src/Reflection/SHReflectionMetadata.h b/SHADE_Engine/src/Reflection/SHReflectionMetadata.h new file mode 100644 index 00000000..0cc6d8a5 --- /dev/null +++ b/SHADE_Engine/src/Reflection/SHReflectionMetadata.h @@ -0,0 +1,11 @@ +#pragma once +#include "string_view" +namespace SHADE +{ + namespace META + { + constexpr const char* min = "MIN"; + constexpr const char* max = "MAX"; + constexpr const char* tooltip = "tooltip"; + } +}