#pragma once #include "IComponentEditor.h" #include "UI/UI.h" #include namespace XCEngine { namespace Editor { class LightComponentEditor : public IComponentEditor { public: const char* GetDisplayName() const override { return "Light"; } bool CanEdit(::XCEngine::Components::Component* component) const override { return dynamic_cast<::XCEngine::Components::LightComponent*>(component) != nullptr; } bool Render(::XCEngine::Components::Component* component) override { auto* light = dynamic_cast<::XCEngine::Components::LightComponent*>(component); if (!light) { return false; } int lightType = static_cast(light->GetLightType()); const char* lightTypeLabels[] = { "Directional", "Point", "Spot" }; bool changed = false; if (ImGui::Combo("Type", &lightType, lightTypeLabels, 3)) { light->SetLightType(static_cast<::XCEngine::Components::LightType>(lightType)); changed = true; } float color[4] = { light->GetColor().r, light->GetColor().g, light->GetColor().b, light->GetColor().a }; if (UI::DrawColor4("Color", color)) { light->SetColor(::XCEngine::Math::Color(color[0], color[1], color[2], color[3])); changed = true; } float intensity = light->GetIntensity(); if (UI::DrawFloat("Intensity", intensity, 100.0f, 0.1f, 0.0f)) { light->SetIntensity(intensity); changed = true; } if (light->GetLightType() != ::XCEngine::Components::LightType::Directional) { float range = light->GetRange(); if (UI::DrawFloat("Range", range, 100.0f, 0.1f, 0.001f)) { light->SetRange(range); changed = true; } } if (light->GetLightType() == ::XCEngine::Components::LightType::Spot) { float spotAngle = light->GetSpotAngle(); if (UI::DrawSliderFloat("Spot Angle", spotAngle, 1.0f, 179.0f, 100.0f, "%.1f")) { light->SetSpotAngle(spotAngle); changed = true; } } bool castsShadows = light->GetCastsShadows(); if (UI::DrawBool("Cast Shadows", castsShadows)) { light->SetCastsShadows(castsShadows); changed = true; } return changed; } bool CanAddTo(::XCEngine::Components::GameObject* gameObject) const override { return gameObject && !gameObject->GetComponent<::XCEngine::Components::LightComponent>(); } const char* GetAddDisabledReason(::XCEngine::Components::GameObject* gameObject) const override { if (!gameObject) { return "Invalid"; } return gameObject->GetComponent<::XCEngine::Components::LightComponent>() ? "Already Added" : nullptr; } ::XCEngine::Components::Component* AddTo(::XCEngine::Components::GameObject* gameObject) const override { return gameObject ? gameObject->AddComponent<::XCEngine::Components::LightComponent>() : nullptr; } bool CanRemove(::XCEngine::Components::Component* component) const override { return CanEdit(component); } }; } // namespace Editor } // namespace XCEngine