2024-12-25 23:35:38 +00:00
|
|
|
#include "InspectorWindow.h"
|
2024-12-26 00:53:17 +00:00
|
|
|
#include <cstdio> // for debugging or printing if needed
|
|
|
|
#include <cstring> // for strcpy, if needed
|
|
|
|
|
|
|
|
#include <glm/gtc/type_ptr.hpp> // Required for glm::value_ptr
|
|
|
|
|
|
|
|
#include <vector>
|
2024-12-26 00:29:24 +00:00
|
|
|
|
2024-12-26 03:06:17 +00:00
|
|
|
extern std::vector<GameObject> g_GameObjects;
|
|
|
|
extern GameObject* g_SelectedObject; // Pointer to the currently selected object
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-26 00:53:17 +00:00
|
|
|
|
|
|
|
void InspectorWindow::Show()
|
2024-12-25 23:35:38 +00:00
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
// Increase window/item spacing for a cleaner look
|
2024-12-25 23:35:38 +00:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(12, 12));
|
2024-12-26 00:53:17 +00:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6, 4));
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10, 10));
|
2024-12-25 23:35:38 +00:00
|
|
|
|
|
|
|
if (ImGui::Begin("Inspector"))
|
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
// Title label (white text)
|
|
|
|
ImGui::TextUnformatted("Selected Object Inspector");
|
2024-12-25 23:35:38 +00:00
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
// ===========================
|
|
|
|
// 1) TRANSFORM
|
|
|
|
// ===========================
|
|
|
|
// Color the Transform header
|
2024-12-26 00:53:17 +00:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 0.4f, 1.0f));
|
2024-12-25 23:42:58 +00:00
|
|
|
bool transformOpen = ImGui::CollapsingHeader("Transform##Main", ImGuiTreeNodeFlags_DefaultOpen);
|
|
|
|
ImGui::PopStyleColor();
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-26 03:06:17 +00:00
|
|
|
if (transformOpen && g_SelectedObject) //! Funny: I did not put a null check here and it broke everything.
|
2024-12-25 23:42:58 +00:00
|
|
|
{
|
2024-12-26 00:53:17 +00:00
|
|
|
|
2024-12-26 03:06:17 +00:00
|
|
|
Transform* transform = &g_SelectedObject->transform;
|
2024-12-25 23:42:58 +00:00
|
|
|
if (ImGui::IsItemHovered())
|
2024-12-25 23:35:38 +00:00
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::BeginTooltip();
|
|
|
|
ImGui::TextUnformatted("Controls the object's Position, Rotation, and Scale.");
|
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Position
|
|
|
|
// -----------------------------------
|
|
|
|
ImGui::TextUnformatted("Position");
|
|
|
|
ImGui::Spacing();
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
{
|
|
|
|
// We'll assign colors for X, Y, Z buttons
|
|
|
|
// (normal, hovered, active)
|
2024-12-26 00:53:17 +00:00
|
|
|
static const ImVec4 colX = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
static const ImVec4 colXHover = ImVec4(1.0f, 0.6f, 0.6f, 1.0f);
|
2024-12-26 00:53:17 +00:00
|
|
|
static const ImVec4 colXActive = ImVec4(1.0f, 0.2f, 0.2f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
|
2024-12-26 00:53:17 +00:00
|
|
|
static const ImVec4 colY = ImVec4(0.4f, 1.0f, 0.4f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
static const ImVec4 colYHover = ImVec4(0.6f, 1.0f, 0.6f, 1.0f);
|
2024-12-26 00:53:17 +00:00
|
|
|
static const ImVec4 colYActive = ImVec4(0.2f, 1.0f, 0.2f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
|
2024-12-26 00:53:17 +00:00
|
|
|
static const ImVec4 colZ = ImVec4(0.4f, 0.4f, 1.0f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
static const ImVec4 colZHover = ImVec4(0.6f, 0.6f, 1.0f, 1.0f);
|
2024-12-26 00:53:17 +00:00
|
|
|
static const ImVec4 colZActive = ImVec4(0.2f, 0.2f, 1.0f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
|
2024-12-26 00:53:17 +00:00
|
|
|
const char *axisNames[3] = {"X", "Y", "Z"};
|
2024-12-25 23:42:58 +00:00
|
|
|
// We'll reference transform.position here
|
2024-12-26 00:53:17 +00:00
|
|
|
float *pos = glm::value_ptr(transform->position);
|
2024-12-25 23:42:58 +00:00
|
|
|
|
|
|
|
ImGui::PushID("PositionRow");
|
|
|
|
for (int i = 0; i < 3; i++)
|
2024-12-25 23:35:38 +00:00
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
// Determine color set
|
|
|
|
ImVec4 col, colH, colA;
|
2024-12-26 00:53:17 +00:00
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
col = colX;
|
|
|
|
colH = colXHover;
|
|
|
|
colA = colXActive;
|
|
|
|
}
|
|
|
|
else if (i == 1)
|
|
|
|
{
|
|
|
|
col = colY;
|
|
|
|
colH = colYHover;
|
|
|
|
colA = colYActive;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
col = colZ;
|
|
|
|
colH = colZHover;
|
|
|
|
colA = colZActive;
|
|
|
|
}
|
2024-12-25 23:42:58 +00:00
|
|
|
|
|
|
|
// Push color style for button
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, col);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colH);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, colA);
|
|
|
|
|
|
|
|
// Small button with the axis name
|
|
|
|
if (ImGui::Button(axisNames[i], ImVec2(20, 0)))
|
2024-12-25 23:35:38 +00:00
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
// No action on click, but we have a box with color
|
2024-12-25 23:35:38 +00:00
|
|
|
}
|
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::PopStyleColor(3);
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetNextItemWidth(60.0f);
|
|
|
|
ImGui::DragFloat((std::string("##Pos") + axisNames[i]).c_str(), &pos[i], 0.1f);
|
|
|
|
|
2024-12-26 00:53:17 +00:00
|
|
|
if (i < 2)
|
|
|
|
ImGui::SameLine(0, 15);
|
2024-12-25 23:35:38 +00:00
|
|
|
}
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::PopID();
|
|
|
|
}
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::Separator();
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
// -----------------------------------
|
|
|
|
// Rotation
|
|
|
|
// -----------------------------------
|
|
|
|
ImGui::TextUnformatted("Rotation");
|
|
|
|
ImGui::Spacing();
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
{
|
|
|
|
// Same approach, but referencing transform.rotation
|
2024-12-26 00:53:17 +00:00
|
|
|
const char *axisNames[3] = {"X", "Y", "Z"};
|
|
|
|
float *rot = glm::value_ptr(transform->rotation);
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
// We can reuse the same color sets
|
|
|
|
ImGui::PushID("RotationRow");
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
// Decide color sets for X, Y, Z
|
|
|
|
ImVec4 col, colH, colA;
|
2024-12-26 00:53:17 +00:00
|
|
|
if (i == 0)
|
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
col = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
|
2024-12-26 00:53:17 +00:00
|
|
|
colH = ImVec4(1.0f, 0.6f, 0.6f, 1.0f);
|
|
|
|
colA = ImVec4(1.0f, 0.2f, 0.2f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
}
|
2024-12-26 00:53:17 +00:00
|
|
|
else if (i == 1)
|
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
col = ImVec4(0.4f, 1.0f, 0.4f, 1.0f);
|
2024-12-26 00:53:17 +00:00
|
|
|
colH = ImVec4(0.6f, 1.0f, 0.6f, 1.0f);
|
|
|
|
colA = ImVec4(0.2f, 1.0f, 0.2f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
}
|
2024-12-26 00:53:17 +00:00
|
|
|
else
|
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
col = ImVec4(0.4f, 0.4f, 1.0f, 1.0f);
|
2024-12-26 00:53:17 +00:00
|
|
|
colH = ImVec4(0.6f, 0.6f, 1.0f, 1.0f);
|
|
|
|
colA = ImVec4(0.2f, 0.2f, 1.0f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, col);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colH);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, colA);
|
|
|
|
|
|
|
|
if (ImGui::Button(axisNames[i], ImVec2(20, 0)))
|
2024-12-25 23:35:38 +00:00
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
// No action
|
2024-12-25 23:35:38 +00:00
|
|
|
}
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::PopStyleColor(3);
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetNextItemWidth(60.0f);
|
|
|
|
ImGui::DragFloat((std::string("##Rot") + axisNames[i]).c_str(), &rot[i], 0.1f);
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-26 00:53:17 +00:00
|
|
|
if (i < 2)
|
|
|
|
ImGui::SameLine(0, 15);
|
2024-12-25 23:35:38 +00:00
|
|
|
}
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::PopID();
|
|
|
|
}
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Scale
|
|
|
|
// -----------------------------------
|
|
|
|
ImGui::TextUnformatted("Scale");
|
|
|
|
ImGui::Spacing();
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
{
|
2024-12-26 00:53:17 +00:00
|
|
|
const char *axisNames[3] = {"X", "Y", "Z"};
|
|
|
|
float *scl = glm::value_ptr(transform->scale);
|
2024-12-25 23:42:58 +00:00
|
|
|
|
|
|
|
ImGui::PushID("ScaleRow");
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
// same color approach
|
|
|
|
ImVec4 col, colH, colA;
|
2024-12-26 00:53:17 +00:00
|
|
|
if (i == 0)
|
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
col = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
|
2024-12-26 00:53:17 +00:00
|
|
|
colH = ImVec4(1.0f, 0.6f, 0.6f, 1.0f);
|
|
|
|
colA = ImVec4(1.0f, 0.2f, 0.2f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
}
|
2024-12-26 00:53:17 +00:00
|
|
|
else if (i == 1)
|
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
col = ImVec4(0.4f, 1.0f, 0.4f, 1.0f);
|
2024-12-26 00:53:17 +00:00
|
|
|
colH = ImVec4(0.6f, 1.0f, 0.6f, 1.0f);
|
|
|
|
colA = ImVec4(0.2f, 1.0f, 0.2f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
}
|
2024-12-26 00:53:17 +00:00
|
|
|
else
|
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
col = ImVec4(0.4f, 0.4f, 1.0f, 1.0f);
|
2024-12-26 00:53:17 +00:00
|
|
|
colH = ImVec4(0.6f, 0.6f, 1.0f, 1.0f);
|
|
|
|
colA = ImVec4(0.2f, 0.2f, 1.0f, 1.0f);
|
2024-12-25 23:42:58 +00:00
|
|
|
}
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, col);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colH);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, colA);
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
if (ImGui::Button(axisNames[i], ImVec2(20, 0)))
|
2024-12-25 23:35:38 +00:00
|
|
|
{
|
2024-12-25 23:42:58 +00:00
|
|
|
// No action
|
2024-12-25 23:35:38 +00:00
|
|
|
}
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::PopStyleColor(3);
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetNextItemWidth(60.0f);
|
|
|
|
ImGui::DragFloat((std::string("##Scl") + axisNames[i]).c_str(), &scl[i], 0.1f);
|
2024-12-25 23:35:38 +00:00
|
|
|
|
2024-12-26 00:53:17 +00:00
|
|
|
if (i < 2)
|
|
|
|
ImGui::SameLine(0, 15);
|
2024-12-25 23:42:58 +00:00
|
|
|
}
|
|
|
|
ImGui::PopID();
|
2024-12-25 23:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::Separator();
|
2024-12-25 23:35:38 +00:00
|
|
|
}
|
|
|
|
|
2024-12-25 23:42:58 +00:00
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
// ===========================
|
|
|
|
// 2) SCRIPT
|
|
|
|
// ===========================
|
|
|
|
// We keep script text in white
|
2024-12-26 00:53:17 +00:00
|
|
|
// if (ImGui::CollapsingHeader("Script##Main", ImGuiTreeNodeFlags_DefaultOpen))
|
|
|
|
//{
|
|
|
|
// if (ImGui::IsItemHovered())
|
|
|
|
// {
|
|
|
|
// ImGui::BeginTooltip();
|
|
|
|
// ImGui::TextUnformatted("Attach a script or logic component here.");
|
|
|
|
// ImGui::EndTooltip();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// ImGui::TextUnformatted("Script Name:");
|
|
|
|
// ImGui::SameLine();
|
|
|
|
|
|
|
|
// {
|
|
|
|
// char buffer[128];
|
|
|
|
// std::snprintf(buffer, sizeof(buffer), "%s", script.scriptName.c_str());
|
|
|
|
// ImGui::SetNextItemWidth(-1);
|
|
|
|
// if (ImGui::InputText("##ScriptName", buffer, sizeof(buffer)))
|
|
|
|
// {
|
|
|
|
// script.scriptName = buffer;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// ImGui::Spacing();
|
|
|
|
|
|
|
|
// ImGui::TextUnformatted("Script Enabled:");
|
|
|
|
// ImGui::SameLine();
|
|
|
|
// ImGui::Checkbox("##ScriptEnabled", &script.enabled);
|
|
|
|
|
|
|
|
// ImGui::Spacing();
|
|
|
|
// ImGui::Separator();
|
|
|
|
//}
|
2024-12-25 23:35:38 +00:00
|
|
|
ImGui::End();
|
2024-12-26 00:53:17 +00:00
|
|
|
|
|
|
|
} //
|
2024-12-25 23:35:38 +00:00
|
|
|
|
|
|
|
// Restore style
|
|
|
|
ImGui::PopStyleVar(3);
|
|
|
|
}
|