/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "LmbrCentral_precompiled.h" #include "QuadShapeComponent.h" #include #include "EditorQuadShapeComponent.h" #include "EditorShapeComponentConverters.h" #include "ShapeDisplay.h" namespace LmbrCentral { void EditorQuadShapeComponent::Reflect(AZ::ReflectContext* context) { if (auto serializeContext = azrtti_cast(context)) { serializeContext->Class() ->Version(1) ->Field("QuadShape", &EditorQuadShapeComponent::m_quadShape) ; if (AZ::EditContext* editContext = serializeContext->GetEditContext()) { editContext->Class( "Quad Shape", "The Quad Shape component creates a quad around the associated entity") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::Category, "Shape") ->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/Quad_Shape.svg") ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/Viewport/Quad_Shape.png") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c)) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://docs.aws.amazon.com/lumberyard/latest/userguide/component-shapes.html") ->DataElement(AZ::Edit::UIHandlers::Default, &EditorQuadShapeComponent::m_quadShape, "Quad Shape", "Quad Shape Configuration") ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorQuadShapeComponent::ConfigurationChanged) ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ; } } } void EditorQuadShapeComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { EditorBaseShapeComponent::GetProvidedServices(provided); provided.push_back(AZ_CRC("QuadShapeService", 0xe449b0fc)); provided.push_back(AZ_CRC("AreaLightShapeService", 0x68ea78dc)); } void EditorQuadShapeComponent::Init() { EditorBaseShapeComponent::Init(); SetShapeComponentConfig(&m_quadShape.ModifyShapeComponent()); } void EditorQuadShapeComponent::Activate() { EditorBaseShapeComponent::Activate(); m_quadShape.Activate(GetEntityId()); AzFramework::EntityDebugDisplayEventBus::Handler::BusConnect(GetEntityId()); } void EditorQuadShapeComponent::Deactivate() { AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect(); m_quadShape.Deactivate(); EditorBaseShapeComponent::Deactivate(); } void EditorQuadShapeComponent::DisplayEntityViewport( const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) { DisplayShape( debugDisplay, [this]() { return CanDraw(); }, [this](AzFramework::DebugDisplayRequests& debugDisplay) { DrawQuadShape( { m_shapeColor, m_shapeWireColor, m_displayFilled }, m_quadShape.GetQuadConfiguration(), debugDisplay); }, m_quadShape.GetCurrentTransform()); } void EditorQuadShapeComponent::ConfigurationChanged() { m_quadShape.InvalidateCache(InvalidateShapeCacheReason::ShapeChange); ShapeComponentNotificationsBus::Event( GetEntityId(), &ShapeComponentNotificationsBus::Events::OnShapeChanged, ShapeComponentNotifications::ShapeChangeReasons::ShapeChanged); } void EditorQuadShapeComponent::BuildGameEntity(AZ::Entity* gameEntity) { if (auto component = gameEntity->CreateComponent()) { component->SetConfiguration(m_quadShape.GetQuadConfiguration()); } if (m_visibleInGameView) { if (auto component = gameEntity->CreateComponent()) { component->SetConfiguration(m_quadShape.GetQuadConfiguration()); } } } } // namespace LmbrCentral