diff --git a/Editor/src/ComponentsPanel/SpritePanel.h b/Editor/src/ComponentsPanel/SpritePanel.h index b21c58e0..bc03e632 100644 --- a/Editor/src/ComponentsPanel/SpritePanel.h +++ b/Editor/src/ComponentsPanel/SpritePanel.h @@ -15,75 +15,6 @@ public: void Draw(Nuake::Entity entity) override { - if (!entity.HasComponent()) - { - return; - } - - auto& component = entity.GetComponent(); - BeginComponentTable(SPRITE, Nuake::SpriteComponent); - { - { - ImGui::Text("Sprite"); - ImGui::TableNextColumn(); - - std::string path = component.SpritePath; - ImGui::Button(path.empty() ? "Drag image" : component.SpritePath.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Image")) - { - char* file = (char*)payload->Data; - - std::string fullPath = std::string(file, 512); - path = Nuake::FileSystem::AbsoluteToRelative(std::move(fullPath)); - component.SpritePath = path; - - component.LoadSprite(); - } - ImGui::EndDragDropTarget(); - } - - ImGui::TableNextColumn(); - ComponentTableReset(component.LockYRotation, false); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Billboard"); - ImGui::TableNextColumn(); - - ImGui::Checkbox("##billboard", &component.Billboard); - ImGui::TableNextColumn(); - - ComponentTableReset(component.Billboard, false); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Lock Y rotation"); - ImGui::TableNextColumn(); - - ImGui::Checkbox("##lockYRotation", &component.LockYRotation); - ImGui::TableNextColumn(); - - ComponentTableReset(component.LockYRotation, false); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Position Based"); - if (ImGui::BeginItemTooltip()) - { - ImGui::Text("Orientation is based on the position of the camera or the orientation of the camera."); - ImGui::EndTooltip(); - } - - ImGui::TableNextColumn(); - - ImGui::Checkbox("##positionbased", &component.PositionFacing); - ImGui::TableNextColumn(); - - ComponentTableReset(component.LockYRotation, false); - } - } - EndComponentTable(); + } }; \ No newline at end of file diff --git a/Nuake/src/Scene/Components/SpriteComponent.cpp b/Nuake/src/Scene/Components/SpriteComponent.cpp index c2892e6c..369e0a92 100644 --- a/Nuake/src/Scene/Components/SpriteComponent.cpp +++ b/Nuake/src/Scene/Components/SpriteComponent.cpp @@ -1,5 +1,6 @@ #include "SpriteComponent.h" +#include "src/FileSystem/File.h" #include "src/FileSystem/FileSystem.h" #include "src/Rendering/Textures/TextureManager.h" #include "src/Rendering/Textures/MaterialManager.h" @@ -10,8 +11,7 @@ namespace Nuake { SpriteComponent::SpriteComponent() : Billboard(false), - LockYRotation(false), - SpritePath("") + LockYRotation(false) { } @@ -32,7 +32,13 @@ namespace Nuake SpriteMesh = CreateRef(); SpriteMesh->AddSurface(quadVertices, { 0, 1, 2, 3, 4, 5 }); - Ref material = MaterialManager::Get()->GetMaterial(FileSystem::Root + SpritePath); + std::string absPath = ""; + if (SpritePath.file != nullptr && SpritePath.file->Exist()) + { + absPath = SpritePath.file->GetAbsolutePath(); + } + + Ref material = MaterialManager::Get()->GetMaterial(absPath); bool hasNormal = material->HasNormal(); SpriteMesh->SetMaterial(material); @@ -44,7 +50,7 @@ namespace Nuake BEGIN_SERIALIZE(); SERIALIZE_VAL(Billboard); SERIALIZE_VAL(LockYRotation); - SERIALIZE_VAL(SpritePath); + SERIALIZE_RES_FILE(SpritePath); SERIALIZE_VAL(PositionFacing); END_SERIALIZE(); } @@ -61,17 +67,13 @@ namespace Nuake LockYRotation = j["LockYRotation"]; } + DESERIALIZE_RES_FILE(SpritePath); + if (j.contains("PositionFacing")) { PositionFacing = j["PositionFacing"]; } - if (j.contains("SpritePath")) - { - SpritePath = j["SpritePath"]; - LoadSprite(); - } - return true; } } \ No newline at end of file diff --git a/Nuake/src/Scene/Components/SpriteComponent.h b/Nuake/src/Scene/Components/SpriteComponent.h index f2e3f1fe..ab2bacf2 100644 --- a/Nuake/src/Scene/Components/SpriteComponent.h +++ b/Nuake/src/Scene/Components/SpriteComponent.h @@ -1,6 +1,7 @@ #pragma once #include "Component.h" +#include "FieldTypes.h" #include "src/Core/Core.h" #include "src/Resource/Serializable.h" @@ -13,12 +14,20 @@ namespace Nuake { NUAKECOMPONENT(SpriteComponent, "Sprite") + static void InitializeComponentClass() + { + BindComponentField<&SpriteComponent::Billboard>("Billboard", "Billboard"); + BindComponentField<&SpriteComponent::LockYRotation>("LockYRotation", "Lock Y Rotation"); + BindComponentField<&SpriteComponent::PositionFacing>("PositionFacing", "Position Facing"); + BindComponentField<&SpriteComponent::SpritePath>("SpritePath", "Sprite Path"); + } + public: bool Billboard; bool LockYRotation; bool PositionFacing; - std::string SpritePath; + ResourceFile SpritePath; Ref SpriteMesh; SpriteComponent();