Basic inspector reflection working for 2 components
This commit is contained in:
@@ -124,6 +124,8 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
|
||||
|
||||
DrawAddComponentMenu(entity);
|
||||
|
||||
mTransformPanel.Draw(entity);
|
||||
|
||||
entt::registry& registry = entity.GetScene()->m_Registry;
|
||||
for (auto&& [componentTypeId, storage] : registry.storage())
|
||||
{
|
||||
@@ -148,27 +150,26 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
|
||||
|
||||
|
||||
// Draw each component properties panels.
|
||||
mTransformPanel.Draw(entity);
|
||||
mLightPanel.Draw(entity);
|
||||
mScriptPanel.Draw(entity);
|
||||
mNetScriptPanel.Draw(entity);
|
||||
mAudioEmitterPanel.Draw(entity);
|
||||
mParticleEmitterPanel.Draw(entity);
|
||||
mSpritePanel.Draw(entity);
|
||||
mMeshPanel.Draw(entity);
|
||||
mSkinnedModelPanel.Draw(entity);
|
||||
mBonePanel.Draw(entity);
|
||||
mQuakeMapPanel.Draw(entity);
|
||||
mCameraPanel.Draw(entity);
|
||||
mRigidbodyPanel.Draw(entity);
|
||||
mBoxColliderPanel.Draw(entity);
|
||||
mSphereColliderPanel.Draw(entity);
|
||||
mCapsuleColliderPanel.Draw(entity);
|
||||
mCylinderColliderPanel.Draw(entity);
|
||||
mMeshColliderPanel.Draw(entity);
|
||||
mCharacterControllerPanel.Draw(entity);
|
||||
mNavMeshVolumePanel.Draw(entity);
|
||||
mUiPanel.Draw(entity);
|
||||
// mLightPanel.Draw(entity);
|
||||
// mScriptPanel.Draw(entity);
|
||||
// mNetScriptPanel.Draw(entity);
|
||||
// mAudioEmitterPanel.Draw(entity);
|
||||
// mParticleEmitterPanel.Draw(entity);
|
||||
// mSpritePanel.Draw(entity);
|
||||
// mMeshPanel.Draw(entity);
|
||||
// mSkinnedModelPanel.Draw(entity);
|
||||
// mBonePanel.Draw(entity);
|
||||
// mQuakeMapPanel.Draw(entity);
|
||||
// mCameraPanel.Draw(entity);
|
||||
// mRigidbodyPanel.Draw(entity);
|
||||
// mBoxColliderPanel.Draw(entity);
|
||||
// mSphereColliderPanel.Draw(entity);
|
||||
// mCapsuleColliderPanel.Draw(entity);
|
||||
// mCylinderColliderPanel.Draw(entity);
|
||||
// mMeshColliderPanel.Draw(entity);
|
||||
// mCharacterControllerPanel.Draw(entity);
|
||||
// mNavMeshVolumePanel.Draw(entity);
|
||||
// mUiPanel.Draw(entity);
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -607,7 +608,43 @@ void EditorSelectionPanel::DrawComponentContent(entt::meta_any& component)
|
||||
|
||||
void EditorSelectionPanel::DrawFieldTypeFloat(entt::meta_data& field, entt::meta_any& component)
|
||||
{
|
||||
ImGui::Text("Hello World!!!");
|
||||
float stepSize = 1.f;
|
||||
if (auto prop = field.prop(HashedFieldPropName::FloatStep))
|
||||
stepSize = *prop.value().try_cast<float>();
|
||||
|
||||
float min = 0.f;
|
||||
if (auto prop = field.prop(HashedFieldPropName::FloatMin))
|
||||
min = *prop.value().try_cast<float>();
|
||||
|
||||
float max = 0.f;
|
||||
if (auto prop = field.prop(HashedFieldPropName::FloatMax))
|
||||
max = *prop.value().try_cast<float>();
|
||||
|
||||
auto propDisplayName = field.prop(HashedName::DisplayName);
|
||||
const char* displayName = *propDisplayName.value().try_cast<const char*>();
|
||||
if (displayName != nullptr)
|
||||
{
|
||||
ImGui::Text(displayName);
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
auto fieldVal = field.get(component);
|
||||
float* floatPtr = fieldVal.try_cast<float>();
|
||||
if (floatPtr != nullptr)
|
||||
{
|
||||
float floatProxy = *floatPtr;
|
||||
const std::string controlId = std::string("##") + displayName;
|
||||
if (ImGui::DragFloat(controlId.c_str(), &floatProxy, stepSize, min, max))
|
||||
{
|
||||
field.set(component, floatProxy);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::Text("ERR");
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::TableNextRow();
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::DrawFieldTypeBool(entt::meta_data& field, entt::meta_any& component)
|
||||
@@ -626,7 +663,8 @@ void EditorSelectionPanel::DrawFieldTypeBool(entt::meta_data& field, entt::meta_
|
||||
if (boolPtr != nullptr)
|
||||
{
|
||||
bool boolProxy = *boolPtr;
|
||||
if (ImGui::Checkbox("##isTrigger", &boolProxy))
|
||||
std::string controlId = std::string("##") + displayName;
|
||||
if (ImGui::Checkbox(controlId.c_str(), &boolProxy))
|
||||
{
|
||||
field.set(component, boolProxy);
|
||||
}
|
||||
@@ -635,9 +673,9 @@ void EditorSelectionPanel::DrawFieldTypeBool(entt::meta_data& field, entt::meta_
|
||||
{
|
||||
ImGui::Text("ERR");
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
ImGui::TableNextRow();
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::DrawFieldTypeVector3(entt::meta_data& field, entt::meta_any& component)
|
||||
@@ -653,12 +691,17 @@ void EditorSelectionPanel::DrawFieldTypeVector3(entt::meta_data& field, entt::me
|
||||
|
||||
auto fieldVal = field.get(component);
|
||||
Vector3* vec3Ptr = fieldVal.try_cast<Vector3>();
|
||||
std::string controlId = std::string("##") + displayName;
|
||||
ImGui::PushID(controlId.c_str());
|
||||
|
||||
if (ImGuiHelper::DrawVec3("BoxSize", vec3Ptr, 0.5f, 100.0, 0.01f))
|
||||
{
|
||||
field.set(component, *vec3Ptr);
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
ImGui::TableNextRow();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,13 @@ namespace Nuake
|
||||
NK_HASHED_STATIC_STR(AddToEntity)
|
||||
};
|
||||
|
||||
struct HashedFieldPropName
|
||||
{
|
||||
NK_HASHED_STATIC_STR(FloatStep)
|
||||
NK_HASHED_STATIC_STR(FloatMin)
|
||||
NK_HASHED_STATIC_STR(FloatMax)
|
||||
};
|
||||
|
||||
struct HashedName
|
||||
{
|
||||
NK_HASHED_STATIC_STR(DisplayName)
|
||||
@@ -86,9 +93,29 @@ public:
|
||||
} \
|
||||
\
|
||||
initialized = true; \
|
||||
}
|
||||
|
||||
#define BINDCOMPONENTFIELD(field, displayName) \
|
||||
ComponentFactory \
|
||||
.data<&field>(entt::hashed_string(#field)) \
|
||||
.prop(HashedName::DisplayName, displayName)
|
||||
\
|
||||
}\
|
||||
\
|
||||
template<auto Data> \
|
||||
static auto BindComponentField(const char* varName, const char* displayName) \
|
||||
{ \
|
||||
return ComponentFactory \
|
||||
.data<Data>(entt::hashed_string(varName)) \
|
||||
.prop(HashedName::DisplayName, displayName); \
|
||||
} \
|
||||
\
|
||||
template<auto Getter, auto Setter> \
|
||||
static auto BindComponentProperty(const char* varName, const char* displayName) \
|
||||
{ \
|
||||
return ComponentFactory \
|
||||
.data<Getter, Setter>(entt::hashed_string(varName)) \
|
||||
.prop(HashedName::DisplayName, displayName); \
|
||||
} \
|
||||
\
|
||||
static auto FloatFieldLimits(float stepSize, float min, float max) \
|
||||
{ \
|
||||
return ComponentFactory \
|
||||
.prop(HashedFieldPropName::FloatStep, stepSize) \
|
||||
.prop(HashedFieldPropName::FloatMin, min) \
|
||||
.prop(HashedFieldPropName::FloatMax, max); \
|
||||
}
|
||||
@@ -11,6 +11,28 @@ namespace Nuake {
|
||||
{
|
||||
NUAKECOMPONENT(AudioEmitterComponent, "Audio Emitter")
|
||||
|
||||
static void InitializeComponentClass()
|
||||
{
|
||||
BindComponentField<&AudioEmitterComponent::IsPlaying>("IsPlaying", "Is Playing");
|
||||
BindComponentField<&AudioEmitterComponent::Loop>("Loop", "Loop");
|
||||
|
||||
BindComponentField<&AudioEmitterComponent::Volume>("Volume", "Volume");
|
||||
FloatFieldLimits(0.001f, 0.0f, 2.0f);
|
||||
BindComponentField<&AudioEmitterComponent::Pan>("Pan", "Pan");
|
||||
FloatFieldLimits(0.01f, -1.0f, 1.0f);
|
||||
BindComponentField<&AudioEmitterComponent::PlaybackSpeed>("PlaybackSpeed", "Playback Speed");
|
||||
FloatFieldLimits(0.01f, 0.0001f, 0.f);
|
||||
|
||||
BindComponentField<&AudioEmitterComponent::Spatialized>("Spatialized", "Spatialized");
|
||||
|
||||
BindComponentField<&AudioEmitterComponent::MinDistance>("MinDistance", "Min Distance");
|
||||
FloatFieldLimits(0.001f, 0.f, 0.f);
|
||||
BindComponentField<&AudioEmitterComponent::MaxDistance>("MaxDistance", "Max Distance");
|
||||
FloatFieldLimits(0.001f, 0.f, 0.f);
|
||||
BindComponentField<&AudioEmitterComponent::AttenuationFactor>("AttenuationFactor", "Attenuation Factor");
|
||||
FloatFieldLimits(0.001f, 0.f, 0.f);
|
||||
}
|
||||
|
||||
public:
|
||||
std::string FilePath;
|
||||
|
||||
|
||||
@@ -13,11 +13,8 @@ namespace Nuake
|
||||
|
||||
static void InitializeComponentClass()
|
||||
{
|
||||
BINDCOMPONENTFIELD(BoxColliderComponent::IsTrigger, "Is Trigger");
|
||||
|
||||
ComponentFactory
|
||||
.data<&BoxColliderComponent::SetSize, &BoxColliderComponent::GetSize>(entt::hashed_string("size"))
|
||||
.prop(HashedName::DisplayName, "Size");
|
||||
BindComponentField<&BoxColliderComponent::IsTrigger>("IsTrigger", "Is Trigger");
|
||||
BindComponentProperty<&BoxColliderComponent::SetSize, &BoxColliderComponent::GetSize>("Size", "Size");
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user