Skip to content

Commit

Permalink
custom component editor gui
Browse files Browse the repository at this point in the history
  • Loading branch information
goopey7 committed Jan 4, 2024
1 parent 9a56301 commit d722c8a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ file(GLOB STB_IMAGE_HEADER "libs/stb/stb_image.h")
add_executable(${PROJECT_NAME} ${ENGINE_SRC_FILES} ${STB_VORBIS_SOURCE})

# define app type
#target_compile_definitions(${PROJECT_NAME} PRIVATE GOOP_APPTYPE_EDITOR)
target_compile_definitions(${PROJECT_NAME} PRIVATE GOOP_APPTYPE_EDITOR)

# define systems
target_compile_definitions(${PROJECT_NAME} PRIVATE GOOP_RENDERER_VULKAN)
Expand Down
4 changes: 3 additions & 1 deletion components/CustomComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <goop/Scene.h>
#include <map>
#include <variant>
#include <imgui.h>

using CustomComponentVariant = std::variant<
Shoutout
Expand Down Expand Up @@ -57,12 +58,13 @@ inline void guiCustomComponents(goop::Scene* s)
for (auto& [name, factory] : customComponentFactoryMap)
{
auto variant = factory(entt::null, s);
std::visit([s](auto& arg)
std::visit([s, &name](auto& arg)
{
using T = std::decay_t<decltype(arg)>;
auto view = s->view<T>();
for (auto e : view)
{
ImGui::Text("%s", name.c_str());
goop::Entity(e, s).getComponent<T>().gui();
}
}, variant);
Expand Down
3 changes: 2 additions & 1 deletion components/Shoutout.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Shoutout.h"
#include <imgui.h>
#include <iostream>

// Gets called when the game starts
Expand All @@ -19,5 +20,5 @@ void Shoutout::update(float dt)
// Editor GUI - Shown in inspector view
void Shoutout::gui()
{
//...
ImGui::Text("Shoutout to my mom");
}
1 change: 1 addition & 0 deletions components/createComponent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ echo "Creating C++ class: ${CLASS_NAME}..."
cat <<EOF >"${HEADER_FILE}"
#pragma once
#include <goop/Components.h>
#include <imgui.h>
class ${CLASS_NAME} : public goop::CustomComponent
{
Expand Down
4 changes: 3 additions & 1 deletion components/updateComponents.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ done
echo "#include <goop/Scene.h>" >>CustomComponents.h
echo "#include <map>" >>CustomComponents.h
echo "#include <variant>" >>CustomComponents.h
echo "#include <imgui.h>" >> CustomComponents.h
echo >>CustomComponents.h
echo "using CustomComponentVariant = std::variant<" >>CustomComponents.h

Expand Down Expand Up @@ -116,12 +117,13 @@ echo "{" >> CustomComponents.h
echo " for (auto& [name, factory] : customComponentFactoryMap)" >> CustomComponents.h
echo " {" >> CustomComponents.h
echo " auto variant = factory(entt::null, s);" >> CustomComponents.h
echo " std::visit([s](auto& arg)" >> CustomComponents.h
echo " std::visit([s, &name](auto& arg)" >> CustomComponents.h
echo " {" >> CustomComponents.h
echo " using T = std::decay_t<decltype(arg)>;" >> CustomComponents.h
echo " auto view = s->view<T>();" >> CustomComponents.h
echo " for (auto e : view)" >> CustomComponents.h
echo " {" >> CustomComponents.h
echo " ImGui::Text(\"%s\", name.c_str());" >> CustomComponents.h
echo " goop::Entity(e, s).getComponent<T>().gui();" >> CustomComponents.h
echo " }" >> CustomComponents.h
echo " }, variant);" >> CustomComponents.h
Expand Down

0 comments on commit d722c8a

Please sign in to comment.