Files
o3de/Code/Framework/AzToolsFramework/AzToolsFramework/Commands/ComponentModeCommand.cpp
T
Steve Pham 38261d0800 Shorten copyright headers by splitting into 2 lines (#2213)
* Updated all copyright headers to split the longer original copyright line into 2 shorter lines

Signed-off-by: Steve Pham <spham@amazon.com>
2021-07-16 15:25:48 -07:00

72 lines
2.6 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "ComponentModeCommand.h"
namespace AzToolsFramework
{
namespace ComponentModeFramework
{
static void HandleTransitionToFromComponentMode(
const AZStd::vector<EntityAndComponentModeBuilders>& componentModeBuilders,
ComponentModeCommand::Transition transition)
{
switch (transition)
{
case ComponentModeCommand::Transition::Enter:
ComponentModeSystemRequestBus::Broadcast(
&ComponentModeSystemRequests::BeginComponentMode,
componentModeBuilders);
break;
case ComponentModeCommand::Transition::Leave:
ComponentModeSystemRequestBus::Broadcast(
&ComponentModeSystemRequests::EndComponentMode);
break;
default:
break;
}
}
// mirror/swap the incoming transition
// enter -> leave, leave -> enter
static ComponentModeCommand::Transition Mirror(
const ComponentModeCommand::Transition transition)
{
switch (transition)
{
case ComponentModeCommand::Transition::Enter:
return ComponentModeCommand::Transition::Leave;
case ComponentModeCommand::Transition::Leave:
return ComponentModeCommand::Transition::Enter;
default:
AZ_Error("ComponentMode", false, "Invalid ComponentMode transition passed");
return ComponentModeCommand::Transition::Enter;
}
}
ComponentModeCommand::ComponentModeCommand(
const Transition transition, const AZStd::string& friendlyName,
const AZStd::vector<EntityAndComponentModeBuilders>& componentModeBuilders)
: URSequencePoint(friendlyName)
, m_componentModeBuilders(componentModeBuilders)
, m_transition(transition) {}
void ComponentModeCommand::Undo()
{
HandleTransitionToFromComponentMode(
m_componentModeBuilders, Mirror(m_transition));
}
void ComponentModeCommand::Redo()
{
HandleTransitionToFromComponentMode(
m_componentModeBuilders, m_transition);
}
} // namespace ComponentModeFramework
} // namespace AzToolsFramework