diff --git a/Editor/src/ComponentsPanel/UIPanel.h b/Editor/src/ComponentsPanel/UIPanel.h index 70251dac..0f4b48fc 100644 --- a/Editor/src/ComponentsPanel/UIPanel.h +++ b/Editor/src/ComponentsPanel/UIPanel.h @@ -15,47 +15,47 @@ public: void Draw(Nuake::Entity entity) override { - using namespace Nuake; - - if (!entity.HasComponent()) - return; - - auto& component = entity.GetComponent(); - BeginComponentTable(UI EMITTER, UIComponent); - { - { - ImGui::Text("HTML File"); - ImGui::TableNextColumn(); - - std::string path = component.UIFilePath; - ImGui::Button(component.UIFilePath.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_UIFile")) - { - char* file = (char*)payload->Data; - std::string fullPath = std::string(file, 256); - path = Nuake::FileSystem::AbsoluteToRelative(fullPath); - component.UIFilePath = path; - } - ImGui::EndDragDropTarget(); - } - - ImGui::TableNextColumn(); - - ComponentTableReset(component.UIFilePath, ""); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Worldspace"); - ImGui::TableNextColumn(); - - ImGui::Checkbox("##WorldSpace", &component.IsWorldSpace); - ImGui::TableNextColumn(); - - ComponentTableReset(component.IsWorldSpace, false); - } - } - EndComponentTable(); + // using namespace Nuake; + // + // if (!entity.HasComponent()) + // return; + // + // auto& component = entity.GetComponent(); + // BeginComponentTable(UI EMITTER, UIComponent); + // { + // { + // ImGui::Text("HTML File"); + // ImGui::TableNextColumn(); + // + // std::string path = component.UIFilePath; + // ImGui::Button(component.UIFilePath.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); + // if (ImGui::BeginDragDropTarget()) + // { + // if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_UIFile")) + // { + // char* file = (char*)payload->Data; + // std::string fullPath = std::string(file, 256); + // path = Nuake::FileSystem::AbsoluteToRelative(fullPath); + // component.UIFilePath = path; + // } + // ImGui::EndDragDropTarget(); + // } + // + // ImGui::TableNextColumn(); + // + // ComponentTableReset(component.UIFilePath, ""); + // } + // ImGui::TableNextColumn(); + // { + // ImGui::Text("Worldspace"); + // ImGui::TableNextColumn(); + // + // ImGui::Checkbox("##WorldSpace", &component.IsWorldSpace); + // ImGui::TableNextColumn(); + // + // ComponentTableReset(component.IsWorldSpace, false); + // } + // } + // EndComponentTable(); } }; \ No newline at end of file diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index db2431d5..a741ba1a 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -598,8 +598,15 @@ void EditorSelectionPanel::DrawComponentContent(entt::meta_any& component) entt::meta_type componentMeta = component.type(); for (auto [fst, dataType] : componentMeta.data()) { + const ComponentFieldTrait fieldTraits = dataType.traits(); + // Field marked as internal and thus not exposed to the inspector + if ((fieldTraits & ComponentFieldTrait::Internal) == ComponentFieldTrait::Internal) + { + continue; + } + ImGui::TableNextColumn(); - + // Search for the appropriate drawer for the type entt::id_type dataId = dataType.type().id(); if (FieldTypeDrawers.contains(dataId)) @@ -607,6 +614,12 @@ void EditorSelectionPanel::DrawComponentContent(entt::meta_any& component) auto drawerFn = FieldTypeDrawers[dataId]; drawerFn(dataType, component); } + else + { + ImGui::Text("ERR"); + } + + ImGui::TableNextRow(); } } @@ -647,8 +660,6 @@ void EditorSelectionPanel::DrawFieldTypeFloat(entt::meta_data& field, entt::meta ImGui::Text("ERR"); } } - - ImGui::TableNextRow(); } void EditorSelectionPanel::DrawFieldTypeBool(entt::meta_data& field, entt::meta_any& component) @@ -678,8 +689,6 @@ void EditorSelectionPanel::DrawFieldTypeBool(entt::meta_data& field, entt::meta_ ImGui::Text("ERR"); } } - - ImGui::TableNextRow(); } void EditorSelectionPanel::DrawFieldTypeVector3(entt::meta_data& field, entt::meta_any& component) @@ -705,8 +714,6 @@ void EditorSelectionPanel::DrawFieldTypeVector3(entt::meta_data& field, entt::me ImGui::PopID(); } - - ImGui::TableNextRow(); } void EditorSelectionPanel::DrawFieldTypeString(entt::meta_data& field, entt::meta_any& component) @@ -733,8 +740,6 @@ void EditorSelectionPanel::DrawFieldTypeString(entt::meta_data& field, entt::met ImGui::Text("ERR"); } } - - ImGui::TableNextRow(); } void EditorSelectionPanel::DrawFieldTypeResourceFile(entt::meta_data& field, entt::meta_any& component) @@ -776,7 +781,5 @@ void EditorSelectionPanel::DrawFieldTypeResourceFile(entt::meta_data& field, ent ImGui::Text("ERR"); } } - - ImGui::TableNextRow(); } diff --git a/Nuake/src/Core/Object/Object.h b/Nuake/src/Core/Object/Object.h index 4b23c8c2..72f9d793 100644 --- a/Nuake/src/Core/Object/Object.h +++ b/Nuake/src/Core/Object/Object.h @@ -5,6 +5,17 @@ #define NK_HASHED_STATIC_STR(name) inline static constexpr entt::hashed_string name = entt::hashed_string(#name); +#define NK_ENUM_BITWISE_IMPL(enumClassName) \ + inline enumClassName operator|(enumClassName lhs, enumClassName rhs) \ + { \ + return static_cast(ToUnderlying(lhs) | ToUnderlying(rhs)); \ + } \ + \ + inline enumClassName operator&(enumClassName lhs, enumClassName rhs) \ + { \ + return static_cast(ToUnderlying(lhs) & ToUnderlying(rhs)); \ + } + namespace Nuake { struct HashedFnName @@ -18,7 +29,7 @@ namespace Nuake NK_HASHED_STATIC_STR(FloatStep) NK_HASHED_STATIC_STR(FloatMin) NK_HASHED_STATIC_STR(FloatMax) - + NK_HASHED_STATIC_STR(ResourceFileType) }; @@ -58,6 +69,16 @@ namespace Nuake { return static_cast(ToUnderlying(lhs) & ToUnderlying(rhs)); } + + inline ComponentFieldTrait operator|(ComponentFieldTrait lhs, ComponentFieldTrait rhs) + { + return static_cast(ToUnderlying(lhs) | ToUnderlying(rhs)); + } + + inline ComponentFieldTrait operator&(ComponentFieldTrait lhs, ComponentFieldTrait rhs) + { + return static_cast(ToUnderlying(lhs) & ToUnderlying(rhs)); + } } #define NUAKECOMPONENT(klass, componentName) \ @@ -140,7 +161,5 @@ public: static auto SetFlags(Enums... enums) \ { \ static_assert((std::is_enum_v && ...), "All arguments must be of enum class type"); \ - return ComponentFactory.traits((static_cast(enums) | ...)); \ + return ComponentFactory.traits((enums | ...)); \ } - - diff --git a/Nuake/src/Resource/ResourceLoader.cpp b/Nuake/src/Resource/ResourceLoader.cpp index fbb25949..22f062d7 100644 --- a/Nuake/src/Resource/ResourceLoader.cpp +++ b/Nuake/src/Resource/ResourceLoader.cpp @@ -1,6 +1,7 @@ #include "ResourceLoader.h" #include "src/Core/Logger.h" #include "src/Core/String.h" +#include "src/FileSystem/File.h" #include "src/Resource/Resource.h" #include "src/Resource/ResourceManager.h" #include "src/Rendering/Textures/Material.h" @@ -101,6 +102,16 @@ Ref ResourceLoader::LoadUI(const std::string& path) return uiResource; } +Ref ResourceLoader::LoadUI(const Ref& file) +{ + if (file == nullptr || !file->Exist()) + { + return nullptr; + } + + return LoadUI(file->GetRelativePath()); +} + UUID ResourceLoader::ReadUUID(json j) { if (j.contains("UUID")) diff --git a/Nuake/src/Resource/ResourceLoader.h b/Nuake/src/Resource/ResourceLoader.h index 4e916a7b..378cd6de 100644 --- a/Nuake/src/Resource/ResourceLoader.h +++ b/Nuake/src/Resource/ResourceLoader.h @@ -8,6 +8,7 @@ namespace Nuake class Material; class Model; class UIResource; + class File; class ResourceLoader { @@ -23,6 +24,7 @@ namespace Nuake static Ref LoadMaterial(const std::string& path); static Ref LoadModel(const std::string& path); static Ref LoadUI(const std::string& path); + static Ref LoadUI(const Ref& file); private: static UUID ReadUUID(json j); diff --git a/Nuake/src/Scene/Components/UIComponent.h b/Nuake/src/Scene/Components/UIComponent.h index 13955b58..55188105 100644 --- a/Nuake/src/Scene/Components/UIComponent.h +++ b/Nuake/src/Scene/Components/UIComponent.h @@ -19,7 +19,7 @@ namespace Nuake { BindComponentField<&UIComponent::UIResource>("UIResource", "UIResource"); SetFlags(ComponentFieldTrait::Internal, ComponentFieldTrait::Transient); - + BindComponentField<&UIComponent::UIFilePath>("UIFilePath", "File Path"); BindComponentField<&UIComponent::IsWorldSpace>("IsWorldspace", "Is Worldspace"); } @@ -34,12 +34,14 @@ namespace Nuake { BEGIN_SERIALIZE(); SERIALIZE_RES_FILE(UIFilePath); + SERIALIZE_VAL(IsWorldSpace); END_SERIALIZE(); } bool Deserialize(const json& j) { DESERIALIZE_RES_FILE(UIFilePath); + DESERIALIZE_VAL(IsWorldSpace); return true; } }; diff --git a/Nuake/src/Scene/Systems/AudioSystem.cpp b/Nuake/src/Scene/Systems/AudioSystem.cpp index 9b715eef..96bfb8dd 100644 --- a/Nuake/src/Scene/Systems/AudioSystem.cpp +++ b/Nuake/src/Scene/Systems/AudioSystem.cpp @@ -4,12 +4,11 @@ #include "src/Scene/Scene.h" #include "src/Scene/Entities/Entity.h" #include "src/Scene/Components/AudioEmitterComponent.h" - +#include "src/FileSystem/File.h" #include "src/Audio/AudioManager.h" #include - namespace Nuake { AudioSystem::AudioSystem(Scene* scene) diff --git a/Nuake/src/Scene/Systems/UISystem.cpp b/Nuake/src/Scene/Systems/UISystem.cpp index 537f2505..99dd7fbb 100644 --- a/Nuake/src/Scene/Systems/UISystem.cpp +++ b/Nuake/src/Scene/Systems/UISystem.cpp @@ -28,15 +28,15 @@ namespace Nuake for (auto e : uiView) { auto& uiViewComponent = uiView.get(e); - const std::string& filePath = uiViewComponent.UIFilePath; + Ref file = uiViewComponent.UIFilePath.file; if (uiViewComponent.UIResource == 0) { - if (filePath.empty() || !FileSystem::FileExists(filePath)) + if (file == nullptr || !file->Exist()) { continue; } - Ref uiResource = ResourceLoader::LoadUI(filePath); + Ref uiResource = ResourceLoader::LoadUI(file); uiViewComponent.UIResource = uiResource->ID; uis[uiViewComponent.UIResource] = uiResource; @@ -44,7 +44,7 @@ namespace Nuake } else { - if (FileSystem::FileExists(filePath)) + if (file != nullptr && file->Exist()) { auto ui = ResourceManager::GetResource(uiViewComponent.UIResource); bool sourceHasChanged = false;