#pragma once #include "IComponentEditor.h" #include "Core/IUndoManager.h" #include "UI/UI.h" #include namespace XCEngine { namespace Editor { class LightComponentEditor : public IComponentEditor { public: const char* GetComponentTypeName() const override { return "Light"; } const char* GetDisplayName() const override { return "Light"; } bool Render(::XCEngine::Components::Component* component, IUndoManager* undoManager) override { auto* light = dynamic_cast<::XCEngine::Components::LightComponent*>(component); if (!light) { return false; } constexpr const char* kUndoLabel = "Modify Light"; int lightType = static_cast(light->GetLightType()); const char* lightTypeLabels[] = { "Directional", "Point", "Spot" }; bool changed = false; const int newLightType = UI::DrawPropertyCombo("Type", lightType, lightTypeLabels, 3); changed |= UI::ApplyPropertyChange( newLightType != lightType, undoManager, kUndoLabel, [&]() { light->SetLightType(static_cast<::XCEngine::Components::LightType>(newLightType)); }); float color[4] = { light->GetColor().r, light->GetColor().g, light->GetColor().b, light->GetColor().a }; changed |= UI::ApplyPropertyChange( UI::DrawPropertyColor4("Color", color), undoManager, kUndoLabel, [&]() { light->SetColor(::XCEngine::Math::Color(color[0], color[1], color[2], color[3])); }); float intensity = light->GetIntensity(); changed |= UI::ApplyPropertyChange( UI::DrawPropertyFloat("Intensity", intensity, 0.1f, 0.0f), undoManager, kUndoLabel, [&]() { light->SetIntensity(intensity); }); if (light->GetLightType() != ::XCEngine::Components::LightType::Directional) { float range = light->GetRange(); changed |= UI::ApplyPropertyChange( UI::DrawPropertyFloat("Range", range, 0.1f, 0.001f), undoManager, kUndoLabel, [&]() { light->SetRange(range); }); } if (light->GetLightType() == ::XCEngine::Components::LightType::Spot) { float spotAngle = light->GetSpotAngle(); changed |= UI::ApplyPropertyChange( UI::DrawPropertySliderFloat("Spot Angle", spotAngle, 1.0f, 179.0f, "%.1f"), undoManager, kUndoLabel, [&]() { light->SetSpotAngle(spotAngle); }); } bool castsShadows = light->GetCastsShadows(); changed |= UI::ApplyPropertyChange( UI::DrawPropertyBool("Cast Shadows", castsShadows), undoManager, kUndoLabel, [&]() { light->SetCastsShadows(castsShadows); }); 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; } bool CanRemove(::XCEngine::Components::Component* component) const override { return CanEdit(component); } }; } // namespace Editor } // namespace XCEngine