UI system now working well with the new component changes, fixed trait compile issues, fixed inspector rendering issues
This commit is contained in:
@@ -15,47 +15,47 @@ public:
|
||||
|
||||
void Draw(Nuake::Entity entity) override
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
if (!entity.HasComponent<UIComponent>())
|
||||
return;
|
||||
|
||||
auto& component = entity.GetComponent<UIComponent>();
|
||||
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<UIComponent>())
|
||||
// return;
|
||||
//
|
||||
// auto& component = entity.GetComponent<UIComponent>();
|
||||
// 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();
|
||||
}
|
||||
};
|
||||
@@ -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<ComponentFieldTrait>();
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<enumClassName>(ToUnderlying(lhs) | ToUnderlying(rhs)); \
|
||||
} \
|
||||
\
|
||||
inline enumClassName operator&(enumClassName lhs, enumClassName rhs) \
|
||||
{ \
|
||||
return static_cast<enumClassName>(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<ComponentTypeTrait>(ToUnderlying(lhs) & ToUnderlying(rhs));
|
||||
}
|
||||
|
||||
inline ComponentFieldTrait operator|(ComponentFieldTrait lhs, ComponentFieldTrait rhs)
|
||||
{
|
||||
return static_cast<ComponentFieldTrait>(ToUnderlying(lhs) | ToUnderlying(rhs));
|
||||
}
|
||||
|
||||
inline ComponentFieldTrait operator&(ComponentFieldTrait lhs, ComponentFieldTrait rhs)
|
||||
{
|
||||
return static_cast<ComponentFieldTrait>(ToUnderlying(lhs) & ToUnderlying(rhs));
|
||||
}
|
||||
}
|
||||
|
||||
#define NUAKECOMPONENT(klass, componentName) \
|
||||
@@ -140,7 +161,5 @@ public:
|
||||
static auto SetFlags(Enums... enums) \
|
||||
{ \
|
||||
static_assert((std::is_enum_v<Enums> && ...), "All arguments must be of enum class type"); \
|
||||
return ComponentFactory.traits((static_cast<uint16_t>(enums) | ...)); \
|
||||
return ComponentFactory.traits((enums | ...)); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<UIResource> ResourceLoader::LoadUI(const std::string& path)
|
||||
return uiResource;
|
||||
}
|
||||
|
||||
Ref<UIResource> ResourceLoader::LoadUI(const Ref<File>& file)
|
||||
{
|
||||
if (file == nullptr || !file->Exist())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return LoadUI(file->GetRelativePath());
|
||||
}
|
||||
|
||||
UUID ResourceLoader::ReadUUID(json j)
|
||||
{
|
||||
if (j.contains("UUID"))
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Nuake
|
||||
class Material;
|
||||
class Model;
|
||||
class UIResource;
|
||||
class File;
|
||||
|
||||
class ResourceLoader
|
||||
{
|
||||
@@ -23,6 +24,7 @@ namespace Nuake
|
||||
static Ref<Material> LoadMaterial(const std::string& path);
|
||||
static Ref<Model> LoadModel(const std::string& path);
|
||||
static Ref<UIResource> LoadUI(const std::string& path);
|
||||
static Ref<UIResource> LoadUI(const Ref<File>& file);
|
||||
|
||||
private:
|
||||
static UUID ReadUUID(json j);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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 <future>
|
||||
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
AudioSystem::AudioSystem(Scene* scene)
|
||||
|
||||
@@ -28,15 +28,15 @@ namespace Nuake
|
||||
for (auto e : uiView)
|
||||
{
|
||||
auto& uiViewComponent = uiView.get<UIComponent>(e);
|
||||
const std::string& filePath = uiViewComponent.UIFilePath;
|
||||
Ref<File> file = uiViewComponent.UIFilePath.file;
|
||||
if (uiViewComponent.UIResource == 0)
|
||||
{
|
||||
if (filePath.empty() || !FileSystem::FileExists(filePath))
|
||||
if (file == nullptr || !file->Exist())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Ref<UIResource> uiResource = ResourceLoader::LoadUI(filePath);
|
||||
Ref<UIResource> 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<UIResource>(uiViewComponent.UIResource);
|
||||
bool sourceHasChanged = false;
|
||||
|
||||
Reference in New Issue
Block a user