VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
PropertiesMenu.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <imgui.h>
10#include <imgui_internal.h>
11#include <ImReflect.hpp>
12#include <glm/glm.hpp>
14
15#include <string>
16#include <algorithm>
17#include <cctype>
18
21
28inline void DrawPropertiesOfAnObject(vex::GameObject* object, bool temporary){
29 if(!object) return;
30
31 if(temporary){
32 ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(120, 13, 13, 255));
33 ImGui::Text("[WARNING]");
34 ImGui::TextWrapped("This object was created at runtime. Anything you edit here will be not be saved. To edit this object you need to find where in code it was created.");
35 ImGui::PopStyleColor();
36 }
37
38 char buffer[256] = "";
39 if (object->HasComponent<vex::NameComponent>()) {
40 strncpy(buffer, object->GetComponent<vex::NameComponent>().name.c_str(), sizeof(buffer));
41 if (ImGui::InputText("Name", buffer, sizeof(buffer))) {
42 object->GetComponent<vex::NameComponent>().name = std::string(buffer);
43 }
44 } else {
45 ImGui::TextDisabled("No NameComponent");
46 }
47
48 ImGui::Separator();
49 vex::ComponentRegistry::getInstance().drawInspectorForObject(*object);
50
51 ImGui::Spacing();
52 ImGui::Separator();
53 ImGui::Spacing();
54
55 float width = ImGui::GetContentRegionAvail().x;
56 ImGui::SetCursorPosX((width - 150) * 0.5f);
57
58 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.00f, 0.23f, 0.01f, 1.0f));
59 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.47f, 0.05f, 0.05f, 1.0f));
60 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.30f, 0.03f, 0.03f, 1.0f));
61 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.94f, 0.85f, 0.85f, 1.0f));
62
63 if (ImGui::Button("Add Component", ImVec2(150, 0))) {
64 ImGui::OpenPopup("AddComponentPopup");
65 }
66
67 ImGui::PopStyleColor(4);
68
69 if (ImGui::BeginPopup("AddComponentPopup")) {
70 auto availableComponents = vex::ComponentRegistry::getInstance().getMissingComponents(*object);
71
72 if (availableComponents.empty()) {
73 ImGui::TextDisabled("No more components available");
74 } else {
75 static char searchBuffer[256] = "";
76 ImGui::InputTextWithHint("##SearchComponent", "Search...", searchBuffer, sizeof(searchBuffer));
77 ImGui::Separator();
78
79 ImGui::TextDisabled("Available Components");
80 ImGui::Separator();
81
82 for (const auto& compName : availableComponents) {
83 if (searchBuffer[0] != '\0') {
84 std::string lowerName = compName;
85 std::string lowerSearch = searchBuffer;
86 std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), [](unsigned char c){ return std::tolower(c); });
87 std::transform(lowerSearch.begin(), lowerSearch.end(), lowerSearch.begin(), [](unsigned char c){ return std::tolower(c); });
88 if (lowerName.find(lowerSearch) == std::string::npos) {
89 continue;
90 }
91 }
92
93 if (ImGui::Selectable(compName.c_str())) {
94 vex::ComponentRegistry::getInstance().createComponent(*object, compName);
95 ImGui::CloseCurrentPopup();
96 searchBuffer[0] = '\0';
97 }
98 }
99 }
100 ImGui::EndPopup();
101 }
102
103}
Contains ComponentRegistry class used to have register of posible to create components....
Main header for the Entity Component System (ECS) framework.
This file defines the GameObject class.
void DrawPropertiesOfAnObject(vex::GameObject *object, bool temporary)
Draws the properties panel for a given GameObject, including its name and all components.
Its base class for all game objects, eg. Player, Enemy, Weapon. Your Class needs to inherit from it.
bool HasComponent() const
Function that checks if the GameObject has a component.
T & GetComponent()
Function that returns reference to a requested component.
Struct that simply contains name of the entity. It is used to identify entity and needs to be unique.