Skip to content

Commit

Permalink
Fixed some issues with inspectors in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
fLindahl committed Feb 28, 2024
1 parent 5921460 commit 7e9fcb2
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
56 changes: 56 additions & 0 deletions code/application/game/componentinspection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,60 @@ ComponentDrawFuncT<Math::mat4>(ComponentId component, void* data, bool* commit)
*commit = true;
}

//------------------------------------------------------------------------------
/**
*/
template<>
void
ComponentDrawFuncT<Math::vec3>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::Text(desc->name.Value());
if (ImGui::InputFloat3("##vec", (float*)data))
*commit = true;
}

//------------------------------------------------------------------------------
/**
*/
template<>
void
ComponentDrawFuncT<Game::Position>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::SameLine();
if (ImGui::InputFloat3("##pos", (float*)data))
*commit = true;
}

//------------------------------------------------------------------------------
/**
*/
template<>
void
ComponentDrawFuncT<Game::Orientation>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::SameLine();
if (ImGui::InputFloat4("##orient", (float*)data))
*commit = true;
}

//------------------------------------------------------------------------------
/**
*/
template<>
void
ComponentDrawFuncT<Game::Scale>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::SameLine();
if (ImGui::InputFloat3("##scl", (float*)data))
*commit = true;
}

} // namespace Game
15 changes: 15 additions & 0 deletions code/application/game/componentinspection.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "util/stringatom.h"
#include "game/entity.h"
#include "game/componentid.h"
#include "basegamefeature/components/position.h"
#include "basegamefeature/components/orientation.h"
#include "basegamefeature/components/scale.h"
#include "imgui.h"

namespace Game
{
Expand Down Expand Up @@ -47,6 +51,13 @@ template<typename TYPE>
void
ComponentDrawFuncT(ComponentId, void*, bool*)
{
if constexpr (TYPE::Traits::num_fields > 0)
{
for (size_t i = 0; i < TYPE::Traits::num_fields; i++)
{
ImGui::Text(TYPE::Traits::field_names[i]);
}
}
return;
}

Expand All @@ -56,5 +67,9 @@ template<> void ComponentDrawFuncT<uint>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<float>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Util::StringAtom>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Math::mat4>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Math::vec3>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Game::Position>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Game::Orientation>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Game::Scale>(ComponentId, void*, bool*);

} // namespace Game
2 changes: 1 addition & 1 deletion fips-files/generators/IDLC/idlcomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def WriteComponentHeaderDeclarations(f, document):
if (len(c.variables) > 0):
f.WriteLine('static constexpr const char* field_names[num_fields] = {')
for v in c.variables:
f.WriteLine(' "{}"'.format(v.name))
f.WriteLine(' "{}",'.format(v.name))
f.WriteLine('};')
f.DecreaseIndent()
f.WriteLine("};")
Expand Down
2 changes: 1 addition & 1 deletion fips-files/generators/NIDL.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version = 131
Version = 133

import sys
if __name__ == '__main__':
Expand Down
16 changes: 10 additions & 6 deletions toolkit/editor/editor/ui/windows/inspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,28 @@ Inspector::Run()
(entityMapping.table != lastEntityMapping.table || entityMapping.instance != lastEntityMapping.instance);
lastEntityMapping = Editor::state.editorWorld->GetEntityMapping(entity);

Util::StringAtom const ownerAtom = "Owner"_atm;
for (int i = 0; i < components.Size(); i++)
{
auto component = components[i];

if (MemDb::AttributeRegistry::GetAttribute(component)->name == ownerAtom)
if (component == Game::GetComponentId<Game::Entity>())
{
continue;
}
ImGui::PushID(0xA3FC + (int)component.id); // offset the ids with some magic number
ImGui::Text(MemDb::AttributeRegistry::GetAttribute(component)->name.Value());
ImGui::SameLine();

if (ImGui::Button("Remove"))
if (component != Game::GetComponentId<Game::Position>() &&
component != Game::GetComponentId<Game::Orientation>() &&
component != Game::GetComponentId<Game::Scale>())
{
Edit::RemoveComponent(entity, component);
ImGui::PopID();
return; // return, otherwise we're reading stale data.
if (ImGui::Button("Remove"))
{
Edit::RemoveComponent(entity, component);
ImGui::PopID();
return; // return, otherwise we're reading stale data.
}
}

auto& tempComponent = this->tempComponents[i];
Expand Down

0 comments on commit 7e9fcb2

Please sign in to comment.