Allow users to rename AnimGraph and Actor node groups to contain any string #2309
Allow users to rename AnimGraph and Actor node groups to contain any string
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "CommandManager.h"
|
||||
|
||||
#include <EMotionFX/CommandSystem/Source/AnimGraphTriggerActionCommands.h>
|
||||
#include <EMotionFX/CommandSystem/Source/AnimGraphNodeGroupCommands.h>
|
||||
#include <EMotionFX/Source/ActorInstance.h>
|
||||
#include <EMotionFX/Source/ActorManager.h>
|
||||
#include <EMotionFX/Source/AnimGraph.h>
|
||||
@@ -858,8 +859,16 @@ namespace CommandSystem
|
||||
// add it to the old node group if it was assigned to one before
|
||||
if (!mNodeGroupName.empty())
|
||||
{
|
||||
commandString = AZStd::string::format("AnimGraphAdjustNodeGroup -animGraphID %i -name \"%s\" -nodeNames \"%s\" -nodeAction \"add\"", animGraph->GetID(), mNodeGroupName.c_str(), mName.c_str());
|
||||
if (GetCommandManager()->ExecuteCommandInsideCommand(commandString.c_str(), outResult) == false)
|
||||
auto* command = aznew CommandSystem::CommandAnimGraphAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAnimGraphAdjustNodeGroup::s_commandName),
|
||||
/*animGraphId = */ animGraph->GetID(),
|
||||
/*name = */ mNodeGroupName,
|
||||
/*visible = */ AZStd::nullopt,
|
||||
/*newName = */ AZStd::nullopt,
|
||||
/*nodeNames = */ {{mName}},
|
||||
/*nodeAction = */ CommandSystem::CommandAnimGraphAdjustNodeGroup::NodeAction::Add
|
||||
);
|
||||
if (GetCommandManager()->ExecuteCommandInsideCommand(command, outResult) == false)
|
||||
{
|
||||
if (outResult.size() > 0)
|
||||
{
|
||||
@@ -1363,11 +1372,16 @@ namespace CommandSystem
|
||||
EMotionFX::AnimGraphNodeGroup* nodeGroup = node->GetAnimGraph()->FindNodeGroupForNode(node);
|
||||
if (nodeGroup && !cutMode)
|
||||
{
|
||||
commandString = AZStd::string::format("AnimGraphAdjustNodeGroup -animGraphID %d -name \"%s\" -nodeNames \"%s\" -nodeAction \"add\"",
|
||||
targetAnimGraph->GetID(),
|
||||
nodeGroup->GetName(),
|
||||
nodeName.c_str());
|
||||
commandGroup->AddCommandString(commandString);
|
||||
auto* command = aznew CommandSystem::CommandAnimGraphAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAnimGraphAdjustNodeGroup::s_commandName),
|
||||
/*animGraphId = */ targetAnimGraph->GetID(),
|
||||
/*name = */ nodeGroup->GetNameString(),
|
||||
/*visible = */ AZStd::nullopt,
|
||||
/*newName = */ AZStd::nullopt,
|
||||
/*nodeNames = */ {{nodeName}},
|
||||
/*nodeAction = */ CommandSystem::CommandAnimGraphAdjustNodeGroup::NodeAction::Add
|
||||
);
|
||||
commandGroup->AddCommand(command);
|
||||
}
|
||||
|
||||
// Recurse through the child nodes.
|
||||
|
||||
+121
-130
@@ -6,6 +6,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/std/optional.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
#include "AnimGraphNodeGroupCommands.h"
|
||||
#include "AnimGraphConnectionCommands.h"
|
||||
@@ -22,45 +23,46 @@
|
||||
|
||||
namespace CommandSystem
|
||||
{
|
||||
AZ_CLASS_ALLOCATOR_IMPL(CommandAnimGraphAdjustNodeGroup, EMotionFX::CommandAllocator, 0)
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// CommandAnimGraphAdjustNodeGroup
|
||||
//--------------------------------------------------------------------------------
|
||||
CommandAnimGraphAdjustNodeGroup::CommandAnimGraphAdjustNodeGroup(MCore::Command* orgCommand)
|
||||
: MCore::Command("AnimGraphAdjustNodeGroup", orgCommand)
|
||||
CommandAnimGraphAdjustNodeGroup::CommandAnimGraphAdjustNodeGroup(
|
||||
MCore::Command* orgCommand,
|
||||
AZ::u32 animGraphId,
|
||||
AZStd::string name,
|
||||
AZStd::optional<bool> visible,
|
||||
AZStd::optional<AZStd::string> newName,
|
||||
AZStd::optional<AZStd::vector<AZStd::string>> nodeNames,
|
||||
AZStd::optional<NodeAction> nodeAction,
|
||||
AZStd::optional<AZ::u32> color,
|
||||
AZStd::optional<bool> updateUI
|
||||
)
|
||||
: MCore::Command(s_commandName, orgCommand)
|
||||
, ParameterMixinAnimGraphId(animGraphId)
|
||||
, m_name(AZStd::move(name))
|
||||
, m_isVisible(visible)
|
||||
, m_newName(AZStd::move(newName))
|
||||
, m_nodeNames(AZStd::move(nodeNames))
|
||||
, m_nodeAction(nodeAction)
|
||||
, m_color(color)
|
||||
, m_updateUI(updateUI)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CommandAnimGraphAdjustNodeGroup::~CommandAnimGraphAdjustNodeGroup()
|
||||
AZStd::vector<AZStd::string> CommandAnimGraphAdjustNodeGroup::GenerateNodeNameVector(EMotionFX::AnimGraph* animGraph, const AZStd::vector<EMotionFX::AnimGraphNodeId>& nodeIDs)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AZStd::string CommandAnimGraphAdjustNodeGroup::GenerateNodeNameString(EMotionFX::AnimGraph* animGraph, const AZStd::vector<EMotionFX::AnimGraphNodeId>& nodeIDs)
|
||||
{
|
||||
if (nodeIDs.empty())
|
||||
AZStd::vector<AZStd::string> result;
|
||||
for (const auto& nodeID : nodeIDs)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
AZStd::string result;
|
||||
|
||||
const size_t numNodes = nodeIDs.size();
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
EMotionFX::AnimGraphNode* animGraphNode = animGraph->RecursiveFindNodeById(nodeIDs[i]);
|
||||
const EMotionFX::AnimGraphNode* animGraphNode = animGraph->RecursiveFindNodeById(nodeID);
|
||||
if (!animGraphNode)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result += animGraphNode->GetName();
|
||||
if (i < numNodes - 1)
|
||||
{
|
||||
result += ';';
|
||||
}
|
||||
result.emplace_back(animGraphNode->GetName());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -80,78 +82,51 @@ namespace CommandSystem
|
||||
}
|
||||
|
||||
|
||||
bool CommandAnimGraphAdjustNodeGroup::Execute(const MCore::CommandLine& parameters, AZStd::string& outResult)
|
||||
bool CommandAnimGraphAdjustNodeGroup::Execute(const MCore::CommandLine&, AZStd::string& outResult)
|
||||
{
|
||||
EMotionFX::AnimGraph* animGraph = CommandsGetAnimGraph(parameters, this, outResult);
|
||||
EMotionFX::AnimGraph* animGraph = EMotionFX::GetAnimGraphManager().FindAnimGraphByID(m_animGraphId);
|
||||
if (!animGraph)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the node group name
|
||||
AZStd::string groupName;
|
||||
parameters.GetValue("name", this, groupName);
|
||||
|
||||
// find the node group index
|
||||
const uint32 groupIndex = animGraph->FindNodeGroupIndexByName(groupName.c_str());
|
||||
const uint32 groupIndex = animGraph->FindNodeGroupIndexByName(m_name.c_str());
|
||||
if (groupIndex == MCORE_INVALIDINDEX32)
|
||||
{
|
||||
outResult = AZStd::string::format("Node group \"%s\" can not be found.", groupName.c_str());
|
||||
outResult = AZStd::string::format("Node group \"%s\" can not be found.", m_name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// get a pointer to the node group and keep the old name
|
||||
EMotionFX::AnimGraphNodeGroup* nodeGroup = animGraph->GetNodeGroup(groupIndex);
|
||||
mOldName = nodeGroup->GetName();
|
||||
|
||||
// is visible?
|
||||
if (parameters.CheckIfHasParameter("isVisible"))
|
||||
if (m_isVisible.has_value())
|
||||
{
|
||||
const bool isVisible = parameters.GetValueAsBool("isVisible", this);
|
||||
mOldIsVisible = nodeGroup->GetIsVisible();
|
||||
nodeGroup->SetIsVisible(isVisible);
|
||||
m_oldIsVisible = nodeGroup->GetIsVisible();
|
||||
nodeGroup->SetIsVisible(*m_isVisible);
|
||||
}
|
||||
|
||||
// background color
|
||||
if (parameters.CheckIfHasParameter("color"))
|
||||
if (m_color.has_value())
|
||||
{
|
||||
const AZ::Vector4 colorVector4 = parameters.GetValueAsVector4("color", this);
|
||||
const AZ::u32 color = AZ::Color(static_cast<float>(colorVector4.GetX()), static_cast<float>(colorVector4.GetY()), static_cast<float>(colorVector4.GetZ()), static_cast<float>(colorVector4.GetW())).ToU32();
|
||||
mOldColor = nodeGroup->GetColor();
|
||||
nodeGroup->SetColor(color);
|
||||
m_oldColor = nodeGroup->GetColor();
|
||||
nodeGroup->SetColor(*m_color);
|
||||
}
|
||||
|
||||
// set the new name
|
||||
// if the new name is empty, the name is not changed
|
||||
AZStd::string newGroupName;
|
||||
parameters.GetValue("newName", this, newGroupName);
|
||||
if (!newGroupName.empty())
|
||||
if (m_newName.has_value())
|
||||
{
|
||||
nodeGroup->SetName(newGroupName.c_str());
|
||||
nodeGroup->SetName(m_newName->c_str());
|
||||
}
|
||||
|
||||
// check if parametes nodeNames is set
|
||||
if (parameters.CheckIfHasParameter("nodeNames"))
|
||||
if (m_nodeNames.has_value())
|
||||
{
|
||||
// keep the old nodes IDs
|
||||
mOldNodeIds = CollectNodeIdsFromGroup(nodeGroup);
|
||||
|
||||
// get the node action
|
||||
AZStd::string nodeAction;
|
||||
parameters.GetValue("nodeAction", this, nodeAction);
|
||||
|
||||
// get the node names and split the string
|
||||
AZStd::string nodeNamesString;
|
||||
parameters.GetValue("nodeNames", this, nodeNamesString);
|
||||
|
||||
|
||||
AZStd::vector<AZStd::string> nodeNames;
|
||||
AzFramework::StringFunc::Tokenize(nodeNamesString.c_str(), nodeNames, ";", false, true);
|
||||
m_oldNodeIds = CollectNodeIdsFromGroup(nodeGroup);
|
||||
|
||||
// remove the selected nodes from the given node group
|
||||
if (AzFramework::StringFunc::Equal(nodeAction.c_str(), "remove"))
|
||||
if (*m_nodeAction == NodeAction::Remove)
|
||||
{
|
||||
for (const AZStd::string& nodeName : nodeNames)
|
||||
for (const AZStd::string& nodeName : *m_nodeNames)
|
||||
{
|
||||
EMotionFX::AnimGraphNode* animGraphNode = animGraph->RecursiveFindNodeByName(nodeName.c_str());
|
||||
if (!animGraphNode)
|
||||
@@ -163,9 +138,9 @@ namespace CommandSystem
|
||||
nodeGroup->RemoveNodeById(animGraphNode->GetId());
|
||||
}
|
||||
}
|
||||
else if (AzFramework::StringFunc::Equal(nodeAction.c_str(), "add")) // add the selected nodes to the given node group
|
||||
else if (*m_nodeAction == NodeAction::Add)
|
||||
{
|
||||
for (const AZStd::string& nodeName : nodeNames)
|
||||
for (const AZStd::string& nodeName : *m_nodeNames)
|
||||
{
|
||||
EMotionFX::AnimGraphNode* animGraphNode = animGraph->RecursiveFindNodeByName(nodeName.c_str());
|
||||
if (!animGraphNode)
|
||||
@@ -184,12 +159,12 @@ namespace CommandSystem
|
||||
nodeGroup->AddNode(animGraphNode->GetId());
|
||||
}
|
||||
}
|
||||
else if (AzFramework::StringFunc::Equal(nodeAction.c_str(), "replace")) // clear the node group and then add the selected nodes to the given node group
|
||||
else if (*m_nodeAction == NodeAction::Replace)
|
||||
{
|
||||
// clear the node group upfront
|
||||
nodeGroup->RemoveAllNodes();
|
||||
|
||||
for (const AZStd::string& nodeName : nodeNames)
|
||||
for (const AZStd::string& nodeName : *m_nodeNames)
|
||||
{
|
||||
EMotionFX::AnimGraphNode* animGraphNode = animGraph->RecursiveFindNodeByName(nodeName.c_str());
|
||||
if (!animGraphNode)
|
||||
@@ -211,68 +186,40 @@ namespace CommandSystem
|
||||
}
|
||||
|
||||
// save the current dirty flag and tell the anim graph that something got changed
|
||||
mOldDirtyFlag = animGraph->GetDirtyFlag();
|
||||
m_oldDirtyFlag = animGraph->GetDirtyFlag();
|
||||
animGraph->SetDirtyFlag(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// undo the command
|
||||
bool CommandAnimGraphAdjustNodeGroup::Undo(const MCore::CommandLine& parameters, AZStd::string& outResult)
|
||||
bool CommandAnimGraphAdjustNodeGroup::Undo(const MCore::CommandLine&, AZStd::string& outResult)
|
||||
{
|
||||
EMotionFX::AnimGraph* animGraph = CommandsGetAnimGraph(parameters, this, outResult);
|
||||
EMotionFX::AnimGraph* animGraph = EMotionFX::GetAnimGraphManager().FindAnimGraphByID(m_animGraphId);
|
||||
if (!animGraph)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AZStd::string commandString = AZStd::string::format("AnimGraphAdjustNodeGroup -animGraphID %i", animGraph->GetID());
|
||||
|
||||
// set the old name or simply set the name if the name is not changed
|
||||
if (parameters.CheckIfHasParameter("newName"))
|
||||
{
|
||||
AZStd::string newName;
|
||||
parameters.GetValue("newName", this, newName);
|
||||
|
||||
commandString += AZStd::string::format(" -name \"%s\"", newName.c_str());
|
||||
commandString += AZStd::string::format(" -newName \"%s\"", mOldName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
commandString += AZStd::string::format(" -name \"%s\"", mOldName.c_str());
|
||||
}
|
||||
|
||||
// set the old visible flag
|
||||
if (parameters.CheckIfHasParameter("isVisible"))
|
||||
{
|
||||
commandString += AZStd::string::format(" -isVisible %i", mOldIsVisible);
|
||||
}
|
||||
|
||||
// set the old color
|
||||
if (parameters.CheckIfHasParameter("color"))
|
||||
{
|
||||
AZ::Color oldColor;
|
||||
oldColor.FromU32(mOldColor);
|
||||
const AZStd::string oldColorString = AZStd::string::format("%.8f,%.8f,%.8f,%.8f", static_cast<float>(oldColor.GetR()), static_cast<float>(oldColor.GetG()), static_cast<float>(oldColor.GetB()), static_cast<float>(oldColor.GetA()));
|
||||
|
||||
commandString += AZStd::string::format(" -color \"%s\"", oldColorString.c_str());
|
||||
}
|
||||
|
||||
// set the old nodes
|
||||
if (parameters.CheckIfHasParameter("nodeNames"))
|
||||
{
|
||||
const AZStd::string nodeNamesString = CommandAnimGraphAdjustNodeGroup::GenerateNodeNameString(animGraph, mOldNodeIds);
|
||||
commandString += AZStd::string::format(" -nodeNames \"%s\" -nodeAction \"replace\"", nodeNamesString.c_str());
|
||||
}
|
||||
CommandAnimGraphAdjustNodeGroup* command = aznew CommandAnimGraphAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandAnimGraphAdjustNodeGroup::s_commandName),
|
||||
/*animGraphId = */ m_animGraphId,
|
||||
/*name = */ m_newName.has_value() ? *m_newName : m_name,
|
||||
/*visible = */ m_isVisible.has_value() ? AZStd::optional<bool>(m_oldIsVisible) : AZStd::nullopt,
|
||||
/*newName = */ m_newName.has_value() ? AZStd::optional<AZStd::string>(m_name) : AZStd::nullopt,
|
||||
/*nodeNames = */ m_nodeNames.has_value() ? AZStd::optional<AZStd::vector<AZStd::string>>(GenerateNodeNameVector(animGraph, m_oldNodeIds)) : AZStd::nullopt,
|
||||
/*nodeAction = */ m_nodeNames.has_value() ? AZStd::optional<NodeAction>(NodeAction::Replace) : AZStd::nullopt,
|
||||
/*color = */ m_color.has_value() ? AZStd::optional<AZ::u32>(m_oldColor) : AZStd::nullopt
|
||||
);
|
||||
|
||||
// execute the command
|
||||
if (!GetCommandManager()->ExecuteCommandInsideCommand(commandString, outResult))
|
||||
if (!GetCommandManager()->ExecuteCommandInsideCommand(command, outResult))
|
||||
{
|
||||
AZ_Error("EMotionFX", false, outResult.c_str());
|
||||
}
|
||||
|
||||
// set the dirty flag back to the old value
|
||||
animGraph->SetDirtyFlag(mOldDirtyFlag);
|
||||
animGraph->SetDirtyFlag(m_oldDirtyFlag);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -282,7 +229,7 @@ namespace CommandSystem
|
||||
{
|
||||
GetSyntax().ReserveParameters(8);
|
||||
GetSyntax().AddRequiredParameter("name", "The name of the node group to adjust.", MCore::CommandSyntax::PARAMTYPE_STRING);
|
||||
GetSyntax().AddParameter("animGraphID", "The id of the blend set the node group belongs to.", MCore::CommandSyntax::PARAMTYPE_INT, "-1");
|
||||
EMotionFX::ParameterMixinAnimGraphId::InitSyntax(GetSyntax(), /*isParameterRequired=*/ false);
|
||||
GetSyntax().AddParameter("isVisible", "The visibility flag of the node group.", MCore::CommandSyntax::PARAMTYPE_BOOLEAN, "true");
|
||||
GetSyntax().AddParameter("newName", "The new name of the node group.", MCore::CommandSyntax::PARAMTYPE_STRING, "");
|
||||
GetSyntax().AddParameter("nodeNames", "A list of node names that should be added/removed to/from the node group.", MCore::CommandSyntax::PARAMTYPE_STRING, "");
|
||||
@@ -291,6 +238,51 @@ namespace CommandSystem
|
||||
GetSyntax().AddParameter("updateUI", "Setting this to true will trigger a refresh of the node groups UI.", MCore::CommandSyntax::PARAMTYPE_BOOLEAN, "true");
|
||||
}
|
||||
|
||||
bool CommandAnimGraphAdjustNodeGroup::SetCommandParameters(const MCore::CommandLine& parameters)
|
||||
{
|
||||
EMotionFX::ParameterMixinAnimGraphId::SetCommandParameters(parameters);
|
||||
m_name = parameters.GetValue("name", this);
|
||||
|
||||
if (parameters.CheckIfHasParameter("isVisible"))
|
||||
{
|
||||
m_isVisible = parameters.GetValueAsBool("isVisible", this);
|
||||
}
|
||||
if (parameters.CheckIfHasParameter("newName"))
|
||||
{
|
||||
m_newName = parameters.GetValue("newName", this);
|
||||
}
|
||||
if (parameters.CheckIfHasParameter("nodeNames"))
|
||||
{
|
||||
m_nodeNames.emplace();
|
||||
AzFramework::StringFunc::Tokenize(parameters.GetValue("nodeNames", this), m_nodeNames.value(), ";", false, true);
|
||||
}
|
||||
if (parameters.CheckIfHasValue("nodeAction"))
|
||||
{
|
||||
const AZStd::string& nodeActionStr = parameters.GetValue("nodeAction", this);
|
||||
if (nodeActionStr == "add")
|
||||
{
|
||||
m_nodeAction = NodeAction::Add;
|
||||
}
|
||||
else if (nodeActionStr == "remove")
|
||||
{
|
||||
m_nodeAction = NodeAction::Remove;
|
||||
}
|
||||
else if (nodeActionStr == "replace")
|
||||
{
|
||||
m_nodeAction = NodeAction::Replace;
|
||||
}
|
||||
}
|
||||
if (parameters.CheckIfHasParameter("color"))
|
||||
{
|
||||
m_color = AZ::Color(parameters.GetValueAsVector4("color", this)).ToU32();
|
||||
}
|
||||
if (parameters.CheckIfHasParameter("updateUI"))
|
||||
{
|
||||
m_updateUI = parameters.GetValueAsBool("updateUI", this);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* CommandAnimGraphAdjustNodeGroup::GetDescription() const
|
||||
{
|
||||
@@ -447,21 +439,20 @@ namespace CommandSystem
|
||||
|
||||
MCore::CommandGroup commandGroup;
|
||||
|
||||
AZStd::string commandString = AZStd::string::format("AnimGraphAddNodeGroup -animGraphID %i -name \"%s\" -updateUI %s",animGraph->GetID(), mOldName.c_str(), updateWindow.c_str());
|
||||
commandGroup.AddCommandString(commandString);
|
||||
commandGroup.AddCommandString(AZStd::string::format("AnimGraphAddNodeGroup -animGraphID %i -name \"%s\" -updateUI %s",animGraph->GetID(), mOldName.c_str(), updateWindow.c_str()));
|
||||
|
||||
const AZStd::string nodeNamesString = CommandAnimGraphAdjustNodeGroup::GenerateNodeNameString(animGraph, mOldNodeIds);
|
||||
auto* command = aznew CommandAnimGraphAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandAnimGraphAdjustNodeGroup::s_commandName),
|
||||
/*animGraphId = */ animGraph->GetID(),
|
||||
/*name = */ mOldName,
|
||||
/*visible = */ mOldIsVisible,
|
||||
/*newName = */ AZStd::nullopt,
|
||||
/*nodeNames = */ CommandAnimGraphAdjustNodeGroup::GenerateNodeNameVector(animGraph, mOldNodeIds),
|
||||
/*nodeAction = */ CommandAnimGraphAdjustNodeGroup::NodeAction::Add,
|
||||
/*color = */ mOldColor
|
||||
);
|
||||
|
||||
AZ::Color oldColor;
|
||||
oldColor.FromU32(mOldColor);
|
||||
const AZStd::string oldColorString = AZStd::string::format("%.8f,%.8f,%.8f,%.8f",
|
||||
static_cast<float>(oldColor.GetR()), static_cast<float>(oldColor.GetG()), static_cast<float>(oldColor.GetB()), static_cast<float>(oldColor.GetA()));
|
||||
|
||||
commandString = AZStd::string::format(
|
||||
"AnimGraphAdjustNodeGroup -animGraphID %i -name \"%s\" -isVisible %s -color \"%s\" -nodeNames \"%s\" -nodeAction \"add\" -updateUI %s",
|
||||
animGraph->GetID(), mOldName.c_str(), AZStd::to_string(mOldIsVisible).c_str(), oldColorString.c_str(), nodeNamesString.c_str(), updateWindow.c_str());
|
||||
|
||||
commandGroup.AddCommandString(commandString);
|
||||
commandGroup.AddCommand(command);
|
||||
|
||||
AZStd::string result;
|
||||
if (!GetCommandManager()->ExecuteCommandGroupInsideCommand(commandGroup, result))
|
||||
|
||||
@@ -13,22 +13,73 @@
|
||||
#include <MCore/Source/CommandGroup.h>
|
||||
#include <EMotionFX/Source/AnimGraphNodeGroup.h>
|
||||
#include <EMotionFX/Source/AnimGraph.h>
|
||||
#include <EMotionFX/CommandSystem/Source/ParameterMixins.h>
|
||||
|
||||
namespace CommandSystem
|
||||
{
|
||||
// adjust a node group
|
||||
MCORE_DEFINECOMMAND_START(CommandAnimGraphAdjustNodeGroup, "Adjust anim graph node group", true)
|
||||
public:
|
||||
static AZStd::string GenerateNodeNameString(EMotionFX::AnimGraph* animGraph, const AZStd::vector<EMotionFX::AnimGraphNodeId>& nodeIDs);
|
||||
static AZStd::vector<EMotionFX::AnimGraphNodeId> CollectNodeIdsFromGroup(EMotionFX::AnimGraphNodeGroup* nodeGroup);
|
||||
class CommandAnimGraphAdjustNodeGroup
|
||||
: public MCore::Command
|
||||
, public EMotionFX::ParameterMixinAnimGraphId
|
||||
{
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR_DECL
|
||||
|
||||
AZStd::string mOldName;
|
||||
bool mOldIsVisible;
|
||||
AZ::u32 mOldColor;
|
||||
AZStd::vector<EMotionFX::AnimGraphNodeId> mOldNodeIds;
|
||||
bool mOldDirtyFlag;
|
||||
MCORE_DEFINECOMMAND_END
|
||||
static constexpr inline AZStd::string_view s_commandName = "AnimGraphAdjustNodeGroup";
|
||||
|
||||
enum class NodeAction
|
||||
{
|
||||
Add,
|
||||
Remove,
|
||||
Replace
|
||||
};
|
||||
|
||||
explicit CommandAnimGraphAdjustNodeGroup(
|
||||
MCore::Command* orgCommand = nullptr,
|
||||
AZ::u32 animGraphId = MCORE_INVALIDINDEX32,
|
||||
AZStd::string name = AZStd::string{},
|
||||
AZStd::optional<bool> visible = AZStd::nullopt,
|
||||
AZStd::optional<AZStd::string> newName = AZStd::nullopt,
|
||||
AZStd::optional<AZStd::vector<AZStd::string>> nodeNames = AZStd::nullopt,
|
||||
AZStd::optional<NodeAction> nodeAction = AZStd::nullopt,
|
||||
AZStd::optional<AZ::u32> color = AZStd::nullopt,
|
||||
AZStd::optional<bool> updateUI = AZStd::nullopt
|
||||
);
|
||||
bool Execute(const MCore::CommandLine& parameters, AZStd::string& outResult) override;
|
||||
bool Undo(const MCore::CommandLine& parameters, AZStd::string& outResult) override;
|
||||
void InitSyntax() override;
|
||||
bool SetCommandParameters(const MCore::CommandLine& parameters) override;
|
||||
bool GetIsUndoable() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
const char* GetHistoryName() const override
|
||||
{
|
||||
return "Adjust anim graph node group";
|
||||
}
|
||||
const char* GetDescription() const override;
|
||||
MCore::Command* Create() override
|
||||
{
|
||||
return new CommandAnimGraphAdjustNodeGroup(this);
|
||||
}
|
||||
|
||||
static AZStd::vector<AZStd::string> GenerateNodeNameVector(EMotionFX::AnimGraph* animGraph, const AZStd::vector<EMotionFX::AnimGraphNodeId>& nodeIDs);
|
||||
static AZStd::vector<EMotionFX::AnimGraphNodeId> CollectNodeIdsFromGroup(EMotionFX::AnimGraphNodeGroup* nodeGroup);
|
||||
|
||||
private:
|
||||
AZStd::string m_name;
|
||||
AZStd::optional<bool> m_isVisible;
|
||||
AZStd::optional<AZStd::string> m_newName;
|
||||
AZStd::optional<AZStd::vector<AZStd::string>> m_nodeNames;
|
||||
AZStd::optional<NodeAction> m_nodeAction;
|
||||
AZStd::optional<AZ::u32> m_color;
|
||||
AZStd::optional<bool> m_updateUI;
|
||||
|
||||
bool m_oldIsVisible;
|
||||
AZ::u32 m_oldColor;
|
||||
AZStd::vector<EMotionFX::AnimGraphNodeId> m_oldNodeIds;
|
||||
bool m_oldDirtyFlag;
|
||||
};
|
||||
|
||||
// add node group
|
||||
MCORE_DEFINECOMMAND_START(CommandAnimGraphAddNodeGroup, "Add anim graph node group", true)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// include the required headers
|
||||
#include "NodeGroupCommands.h"
|
||||
#include "CommandManager.h"
|
||||
#include <EMotionFX/Source/NodeGroup.h>
|
||||
#include <EMotionFX/Source/Allocators.h>
|
||||
#include <EMotionFX/Source/ActorManager.h>
|
||||
#include <MCore/Source/LogManager.h>
|
||||
#include <MCore/Source/StringConversions.h>
|
||||
@@ -20,230 +20,147 @@ namespace CommandSystem
|
||||
//--------------------------------------------------------------------------------
|
||||
// CommandAdjustNodeGroup
|
||||
//--------------------------------------------------------------------------------
|
||||
AZ_CLASS_ALLOCATOR_IMPL(CommandAdjustNodeGroup, EMotionFX::CommandAllocator, 0)
|
||||
|
||||
// constructor
|
||||
CommandAdjustNodeGroup::CommandAdjustNodeGroup(MCore::Command* orgCommand)
|
||||
: MCore::Command("AdjustNodeGroup", orgCommand)
|
||||
, mOldNodeGroup(nullptr)
|
||||
CommandAdjustNodeGroup::CommandAdjustNodeGroup(
|
||||
MCore::Command* orgCommand,
|
||||
uint32 actorId,
|
||||
const AZStd::string& name,
|
||||
AZStd::optional<AZStd::string> newName,
|
||||
AZStd::optional<bool> enabledOnDefault,
|
||||
AZStd::optional<AZStd::vector<AZStd::string>> nodeNames,
|
||||
AZStd::optional<NodeAction> nodeAction
|
||||
)
|
||||
: MCore::Command(s_commandName.data(), orgCommand)
|
||||
, EMotionFX::ParameterMixinActorId(actorId)
|
||||
, m_name(name)
|
||||
, m_newName(AZStd::move(newName))
|
||||
, m_enabledOnDefault(enabledOnDefault)
|
||||
, m_nodeNames(AZStd::move(nodeNames))
|
||||
, m_nodeAction(nodeAction)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// destructor
|
||||
CommandAdjustNodeGroup::~CommandAdjustNodeGroup()
|
||||
{
|
||||
if (mOldNodeGroup)
|
||||
{
|
||||
mOldNodeGroup->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// execute
|
||||
bool CommandAdjustNodeGroup::Execute(const MCore::CommandLine& parameters, AZStd::string& outResult)
|
||||
bool CommandAdjustNodeGroup::Execute(const MCore::CommandLine&, AZStd::string& outResult)
|
||||
{
|
||||
AZStd::string valueString;
|
||||
|
||||
// get the motion id and the corresponding motion pointer
|
||||
const int32 actorID = parameters.GetValueAsInt("actorID", this);
|
||||
parameters.GetValue("name", this, &valueString);
|
||||
|
||||
// get the actor
|
||||
EMotionFX::Actor* actor = EMotionFX::GetActorManager().FindActorByID(actorID);
|
||||
EMotionFX::Actor* actor = EMotionFX::GetActorManager().FindActorByID(m_actorId);
|
||||
if (actor == nullptr)
|
||||
{
|
||||
outResult = AZStd::string::format("Cannot adjust node group. Actor with id='%i' does not exist.", actorID);
|
||||
outResult = AZStd::string::format("Cannot adjust node group. Actor with id='%i' does not exist.", m_actorId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the node group
|
||||
EMotionFX::NodeGroup* nodeGroup = actor->FindNodeGroupByNameNoCase(valueString.c_str());
|
||||
EMotionFX::NodeGroup* nodeGroup = actor->FindNodeGroupByNameNoCase(m_name.c_str());
|
||||
if (nodeGroup == nullptr)
|
||||
{
|
||||
outResult = AZStd::string::format("Cannot adjust node group. Node group with name='%s' does not exist.", valueString.c_str());
|
||||
outResult = AZStd::string::format("Cannot adjust node group. Node group with name='%s' does not exist.", m_name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// copy the old node group for undo
|
||||
if (mOldNodeGroup)
|
||||
{
|
||||
mOldNodeGroup->Destroy();
|
||||
}
|
||||
|
||||
mOldNodeGroup = aznew EMotionFX::NodeGroup(*nodeGroup);
|
||||
m_oldNodeGroup = AZStd::make_unique<EMotionFX::NodeGroup>(*nodeGroup);
|
||||
|
||||
// check if newName is set and apply new name
|
||||
if (parameters.CheckIfHasParameter("newName"))
|
||||
if (m_newName.has_value())
|
||||
{
|
||||
parameters.GetValue("newName", this, &valueString);
|
||||
nodeGroup->SetName(valueString.c_str());
|
||||
nodeGroup->SetName(*m_newName);
|
||||
}
|
||||
|
||||
// check if parameter disabledOnDefault is set and adjust it
|
||||
if (parameters.CheckIfHasParameter("enabledOnDefault"))
|
||||
if (m_enabledOnDefault.has_value())
|
||||
{
|
||||
const bool enabledOnDefault = parameters.GetValueAsBool("enabledOnDefault", this);
|
||||
nodeGroup->SetIsEnabledOnDefault(enabledOnDefault);
|
||||
nodeGroup->SetIsEnabledOnDefault(*m_enabledOnDefault);
|
||||
}
|
||||
|
||||
// check if parametes nodeNames is set
|
||||
if (parameters.CheckIfHasParameter("nodeNames"))
|
||||
if (m_nodeNames.has_value())
|
||||
{
|
||||
// get the node action
|
||||
AZStd::string nodeAction;
|
||||
parameters.GetValue("nodeAction", this, &valueString);
|
||||
|
||||
// get the node names and split the string
|
||||
AZStd::string nodeNameString;
|
||||
parameters.GetValue("nodeNames", this, &nodeNameString);
|
||||
|
||||
// get the individual node names
|
||||
AZStd::vector<AZStd::string> nodeNames;
|
||||
AzFramework::StringFunc::Tokenize(nodeNameString.c_str(), nodeNames, MCore::CharacterConstants::semiColon, true /* keep empty strings */, true /* keep space strings */);
|
||||
|
||||
// get the number of nodes
|
||||
const size_t numNodes = nodeNames.size();
|
||||
|
||||
// remove the selected nodes from the node group
|
||||
if (AzFramework::StringFunc::Equal(valueString.c_str(), "remove", false /* no case */))
|
||||
if (*m_nodeAction == NodeAction::Replace)
|
||||
{
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
// get the node
|
||||
EMotionFX::Node* node = actor->GetSkeleton()->FindNodeByName(nodeNames[i].c_str());
|
||||
if (node == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// remove the node
|
||||
nodeGroup->RemoveNodeByNodeIndex((uint16)node->GetNodeIndex());
|
||||
}
|
||||
}
|
||||
else if (AzFramework::StringFunc::Equal(valueString.c_str(), "add", false /* no case */)) // add the selected nodes to the node group
|
||||
{
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
{
|
||||
// get the node
|
||||
EMotionFX::Node* node = actor->GetSkeleton()->FindNodeByName(nodeNames[i].c_str());
|
||||
if (node == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// add the node
|
||||
uint16 nodeIndex = (uint16)node->GetNodeIndex();
|
||||
nodeGroup->RemoveNodeByNodeIndex(nodeIndex);
|
||||
nodeGroup->AddNode(nodeIndex);
|
||||
}
|
||||
}
|
||||
else // selected nodes form the new node group
|
||||
{
|
||||
// clear previous nodes
|
||||
nodeGroup->GetNodeArray().Clear();
|
||||
|
||||
// add all nodes to the group
|
||||
for (size_t i = 0; i < numNodes; ++i)
|
||||
}
|
||||
for (const AZStd::string& nodeName : *m_nodeNames)
|
||||
{
|
||||
EMotionFX::Node* node = actor->GetSkeleton()->FindNodeByName(nodeName);
|
||||
if (!node)
|
||||
{
|
||||
// get the node
|
||||
EMotionFX::Node* node = actor->GetSkeleton()->FindNodeByName(nodeNames[i].c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if node exists
|
||||
if (node == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// add the node
|
||||
nodeGroup->AddNode((uint16)node->GetNodeIndex());
|
||||
uint16 nodeIndex = (uint16)node->GetNodeIndex();
|
||||
nodeGroup->RemoveNodeByNodeIndex(nodeIndex);
|
||||
if (*m_nodeAction == NodeAction::Add || *m_nodeAction == NodeAction::Replace)
|
||||
{
|
||||
nodeGroup->AddNode(nodeIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// save the current dirty flag and tell the actor that something got changed
|
||||
mOldDirtyFlag = actor->GetDirtyFlag();
|
||||
m_oldDirtyFlag = actor->GetDirtyFlag();
|
||||
actor->SetDirtyFlag(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// undo the command
|
||||
bool CommandAdjustNodeGroup::Undo(const MCore::CommandLine& parameters, AZStd::string& outResult)
|
||||
bool CommandAdjustNodeGroup::Undo(const MCore::CommandLine&, AZStd::string& outResult)
|
||||
{
|
||||
// return if no information about the previous node group was stored
|
||||
if (!mOldNodeGroup)
|
||||
if (!m_oldNodeGroup)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the motion id and the corresponding motion pointer
|
||||
int32 actorID = parameters.GetValueAsInt("actorID", this);
|
||||
|
||||
// get the name
|
||||
AZStd::string name;
|
||||
if (parameters.CheckIfHasParameter("newName"))
|
||||
{
|
||||
parameters.GetValue("newName", this, &name);
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters.GetValue("name", this, &name);
|
||||
}
|
||||
|
||||
// get the actor
|
||||
EMotionFX::Actor* actor = EMotionFX::GetActorManager().FindActorByID(actorID);
|
||||
EMotionFX::Actor* actor = EMotionFX::GetActorManager().FindActorByID(m_actorId);
|
||||
|
||||
// return error if actor was not found
|
||||
if (actor == nullptr)
|
||||
{
|
||||
outResult = AZStd::string::format("Cannot adjust node group. Actor with id='%i' does not exist.", actorID);
|
||||
outResult = AZStd::string::format("Cannot adjust node group. Actor with id='%i' does not exist.", m_actorId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the node group
|
||||
EMotionFX::NodeGroup* nodeGroup = actor->FindNodeGroupByNameNoCase(name.c_str());
|
||||
EMotionFX::NodeGroup* nodeGroup = actor->FindNodeGroupByNameNoCase(m_newName.has_value() ? m_newName->c_str() : m_name.c_str());
|
||||
|
||||
// return error if node group name is not set
|
||||
if (nodeGroup == nullptr)
|
||||
if (!nodeGroup)
|
||||
{
|
||||
outResult = AZStd::string::format("Cannot adjust node group. Node group with name='%s' does not exist.", name.c_str());
|
||||
outResult = AZStd::string::format("Cannot adjust node group. Node group with name='%s' does not exist.", m_newName.has_value() ? m_newName->c_str() : m_name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// reset the old values
|
||||
if (parameters.CheckIfHasParameter("enabledOnDefault"))
|
||||
if (m_enabledOnDefault.has_value())
|
||||
{
|
||||
nodeGroup->SetIsEnabledOnDefault(mOldNodeGroup->GetIsEnabledOnDefault());
|
||||
nodeGroup->SetIsEnabledOnDefault(m_oldNodeGroup->GetIsEnabledOnDefault());
|
||||
}
|
||||
|
||||
if (parameters.CheckIfHasParameter("newName"))
|
||||
if (m_newName.has_value())
|
||||
{
|
||||
nodeGroup->SetName(mOldNodeGroup->GetName());
|
||||
nodeGroup->SetName(m_oldNodeGroup->GetName());
|
||||
}
|
||||
|
||||
if (parameters.CheckIfHasParameter("nodeNames"))
|
||||
if (m_nodeNames.has_value())
|
||||
{
|
||||
// clear previous nodes
|
||||
nodeGroup->GetNodeArray().Clear();
|
||||
const uint32 numNodes = mOldNodeGroup->GetNumNodes();
|
||||
nodeGroup->SetNumNodes(static_cast<uint16>(numNodes));
|
||||
const uint16 numNodes = m_oldNodeGroup->GetNumNodes();
|
||||
nodeGroup->SetNumNodes(numNodes);
|
||||
|
||||
// add all nodes to the group
|
||||
for (uint32 i = 0; i < numNodes; ++i)
|
||||
for (uint16 i = 0; i < numNodes; ++i)
|
||||
{
|
||||
nodeGroup->SetNode(static_cast<uint16>(i), mOldNodeGroup->GetNode(static_cast<uint16>(i)));
|
||||
nodeGroup->SetNode(i, m_oldNodeGroup->GetNode(i));
|
||||
}
|
||||
}
|
||||
|
||||
// delete the old node group
|
||||
if (mOldNodeGroup)
|
||||
{
|
||||
mOldNodeGroup->Destroy();
|
||||
}
|
||||
mOldNodeGroup = nullptr;
|
||||
m_oldNodeGroup = nullptr;
|
||||
|
||||
// set the dirty flag back to the old value
|
||||
actor->SetDirtyFlag(mOldDirtyFlag);
|
||||
actor->SetDirtyFlag(m_oldDirtyFlag);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -252,7 +169,7 @@ namespace CommandSystem
|
||||
void CommandAdjustNodeGroup::InitSyntax()
|
||||
{
|
||||
GetSyntax().ReserveParameters(6);
|
||||
GetSyntax().AddRequiredParameter("actorID", "The id of the actor the node group belongs to.", MCore::CommandSyntax::PARAMTYPE_INT);
|
||||
EMotionFX::ParameterMixinActorId::InitSyntax(GetSyntax(), /*isParameterRequired=*/ true);
|
||||
GetSyntax().AddRequiredParameter("name", "The name of the node group to adjust.", MCore::CommandSyntax::PARAMTYPE_STRING);
|
||||
GetSyntax().AddParameter("newName", "The new name of the node group.", MCore::CommandSyntax::PARAMTYPE_STRING, "");
|
||||
GetSyntax().AddParameter("enabledOnDefault", "The enabled on default flag.", MCore::CommandSyntax::PARAMTYPE_BOOLEAN, "false");
|
||||
@@ -261,6 +178,45 @@ namespace CommandSystem
|
||||
}
|
||||
|
||||
|
||||
bool CommandAdjustNodeGroup::SetCommandParameters(const MCore::CommandLine& parameters)
|
||||
{
|
||||
EMotionFX::ParameterMixinActorId::SetCommandParameters(parameters);
|
||||
|
||||
m_name = parameters.GetValue("name", this);
|
||||
if (parameters.CheckIfHasParameter("newName"))
|
||||
{
|
||||
m_newName = parameters.GetValue("newName", this);
|
||||
}
|
||||
if (parameters.CheckIfHasParameter("enabledOnDefault"))
|
||||
{
|
||||
m_enabledOnDefault = parameters.GetValueAsBool("enabledOnDefault", this);
|
||||
}
|
||||
if (parameters.CheckIfHasParameter("nodeNames"))
|
||||
{
|
||||
m_nodeNames.emplace();
|
||||
AzFramework::StringFunc::Tokenize(parameters.GetValue("nodeNames", this), m_nodeNames.value(), ";", false, true);
|
||||
}
|
||||
if (parameters.CheckIfHasParameter("nodeAction"))
|
||||
{
|
||||
const AZStd::string& nodeActionStr = parameters.GetValue("nodeAction", this);
|
||||
if (nodeActionStr == "add")
|
||||
{
|
||||
m_nodeAction = NodeAction::Add;
|
||||
}
|
||||
else if (nodeActionStr == "remove")
|
||||
{
|
||||
m_nodeAction = NodeAction::Remove;
|
||||
}
|
||||
else if (nodeActionStr == "replace")
|
||||
{
|
||||
m_nodeAction = NodeAction::Replace;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// get the description
|
||||
const char* CommandAdjustNodeGroup::GetDescription() const
|
||||
{
|
||||
@@ -304,7 +260,7 @@ namespace CommandSystem
|
||||
}
|
||||
|
||||
// add new node group to the actor
|
||||
EMotionFX::NodeGroup* nodeGroup = EMotionFX::NodeGroup::Create(name.c_str());
|
||||
EMotionFX::NodeGroup* nodeGroup = aznew EMotionFX::NodeGroup(name);
|
||||
actor->AddNodeGroup(nodeGroup);
|
||||
|
||||
// save the current dirty flag and tell the actor that something got changed
|
||||
@@ -374,10 +330,7 @@ namespace CommandSystem
|
||||
// destructor
|
||||
CommandRemoveNodeGroup::~CommandRemoveNodeGroup()
|
||||
{
|
||||
if (mOldNodeGroup)
|
||||
{
|
||||
mOldNodeGroup->Destroy();
|
||||
}
|
||||
delete mOldNodeGroup;
|
||||
}
|
||||
|
||||
|
||||
@@ -407,11 +360,7 @@ namespace CommandSystem
|
||||
}
|
||||
|
||||
// copy the old node group for undo
|
||||
if (mOldNodeGroup)
|
||||
{
|
||||
mOldNodeGroup->Destroy();
|
||||
}
|
||||
|
||||
delete mOldNodeGroup;
|
||||
mOldNodeGroup = aznew EMotionFX::NodeGroup(*nodeGroup);
|
||||
|
||||
// remove the node group
|
||||
|
||||
@@ -9,10 +9,13 @@
|
||||
#pragma once
|
||||
|
||||
// include the required headers
|
||||
#include <AzCore/std/smart_ptr/unique_ptr.h>
|
||||
#include "CommandSystemConfig.h"
|
||||
#include <MCore/Source/Command.h>
|
||||
#include <MCore/Source/CommandGroup.h>
|
||||
#include <EMotionFX/Source/EMotionFXConfig.h>
|
||||
#include <EMotionFX/Source/NodeGroup.h>
|
||||
#include <EMotionFX/CommandSystem/Source/ParameterMixins.h>
|
||||
|
||||
EMFX_FORWARD_DECLARE(Actor);
|
||||
EMFX_FORWARD_DECLARE(NodeGroup);
|
||||
@@ -20,20 +23,68 @@ EMFX_FORWARD_DECLARE(NodeGroup);
|
||||
namespace CommandSystem
|
||||
{
|
||||
// adjust a node group
|
||||
MCORE_DEFINECOMMAND_START(CommandAdjustNodeGroup, "Adjust node group", true)
|
||||
bool mOldDirtyFlag;
|
||||
EMotionFX::NodeGroup* mOldNodeGroup;
|
||||
MCORE_DEFINECOMMAND_END
|
||||
class CommandAdjustNodeGroup
|
||||
: public MCore::Command
|
||||
, public EMotionFX::ParameterMixinActorId
|
||||
{
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR_DECL
|
||||
|
||||
enum class NodeAction
|
||||
{
|
||||
Add,
|
||||
Remove,
|
||||
Replace
|
||||
};
|
||||
|
||||
static constexpr inline AZStd::string_view s_commandName = "AdjustNodeGroup";
|
||||
|
||||
CommandAdjustNodeGroup(
|
||||
MCore::Command* orgCommand = nullptr,
|
||||
uint32 actorId = MCORE_INVALIDINDEX32,
|
||||
const AZStd::string& name = {},
|
||||
AZStd::optional<AZStd::string> newName = AZStd::nullopt,
|
||||
AZStd::optional<bool> enabledOnDefault = AZStd::nullopt,
|
||||
AZStd::optional<AZStd::vector<AZStd::string>> nodeNames = AZStd::nullopt,
|
||||
AZStd::optional<NodeAction> nodeAction = AZStd::nullopt
|
||||
);
|
||||
bool Execute(const MCore::CommandLine& parameters, AZStd::string& outResult) override;
|
||||
bool Undo(const MCore::CommandLine& parameters, AZStd::string& outResult) override;
|
||||
void InitSyntax() override;
|
||||
bool SetCommandParameters(const MCore::CommandLine& parameters) override;
|
||||
bool GetIsUndoable() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
const char* GetHistoryName() const override
|
||||
{
|
||||
return "Adjust node group";
|
||||
}
|
||||
const char* GetDescription() const override;
|
||||
MCore::Command* Create() override
|
||||
{
|
||||
return new CommandAdjustNodeGroup(this);
|
||||
}
|
||||
|
||||
private:
|
||||
AZStd::string m_name;
|
||||
AZStd::optional<AZStd::string> m_newName;
|
||||
AZStd::optional<bool> m_enabledOnDefault;
|
||||
AZStd::optional<AZStd::vector<AZStd::string>> m_nodeNames;
|
||||
AZStd::optional<NodeAction> m_nodeAction;
|
||||
|
||||
bool m_oldDirtyFlag = false;
|
||||
AZStd::unique_ptr<EMotionFX::NodeGroup> m_oldNodeGroup = nullptr;
|
||||
};
|
||||
|
||||
// add node group
|
||||
MCORE_DEFINECOMMAND_START(CommandAddNodeGroup, "Add node group", true)
|
||||
MCORE_DEFINECOMMAND_START(CommandAddNodeGroup, "Add node group", true)
|
||||
bool mOldDirtyFlag;
|
||||
MCORE_DEFINECOMMAND_END
|
||||
|
||||
|
||||
// remove a node group
|
||||
MCORE_DEFINECOMMAND_START(CommandRemoveNodeGroup, "Remove node group", true)
|
||||
MCORE_DEFINECOMMAND_START(CommandRemoveNodeGroup, "Remove node group", true)
|
||||
EMotionFX::NodeGroup * mOldNodeGroup;
|
||||
bool mOldDirtyFlag;
|
||||
MCORE_DEFINECOMMAND_END
|
||||
|
||||
@@ -80,6 +80,8 @@ namespace EMotionFX
|
||||
AZ_RTTI(ParameterMixinAnimGraphId, "{3F48199E-6566-471F-A7EA-ADF67CAC4DCD}")
|
||||
AZ_CLASS_ALLOCATOR_DECL
|
||||
|
||||
ParameterMixinAnimGraphId() = default;
|
||||
ParameterMixinAnimGraphId(AZ::u32 id) : m_animGraphId(id) {}
|
||||
virtual ~ParameterMixinAnimGraphId() = default;
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
@@ -1015,7 +1015,7 @@ namespace EMotionFX
|
||||
const uint32 numGroups = mNodeGroups.GetLength();
|
||||
for (uint32 i = 0; i < numGroups; ++i)
|
||||
{
|
||||
mNodeGroups[i]->Destroy();
|
||||
delete mNodeGroups[i];
|
||||
}
|
||||
mNodeGroups.Clear();
|
||||
}
|
||||
@@ -2085,7 +2085,7 @@ namespace EMotionFX
|
||||
{
|
||||
if (delFromMem)
|
||||
{
|
||||
mNodeGroups[index]->Destroy();
|
||||
delete mNodeGroups[index];
|
||||
}
|
||||
|
||||
mNodeGroups.Remove(index);
|
||||
@@ -2097,7 +2097,7 @@ namespace EMotionFX
|
||||
mNodeGroups.RemoveByValue(group);
|
||||
if (delFromMem)
|
||||
{
|
||||
group->Destroy();
|
||||
delete group;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1469,7 +1469,7 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// create the new group inside the actor
|
||||
NodeGroup* newGroup = NodeGroup::Create(groupName, fileGroup.mNumNodes, fileGroup.mDisabledOnDefault ? false : true);
|
||||
NodeGroup* newGroup = aznew NodeGroup(groupName, fileGroup.mNumNodes, fileGroup.mDisabledOnDefault ? false : true);
|
||||
|
||||
// read the node numbers
|
||||
uint16 nodeIndex;
|
||||
|
||||
@@ -17,63 +17,16 @@ namespace EMotionFX
|
||||
AZ_CLASS_ALLOCATOR_IMPL(NodeGroup, NodeAllocator, 0)
|
||||
|
||||
|
||||
// default constructor
|
||||
NodeGroup::NodeGroup()
|
||||
: BaseObject()
|
||||
NodeGroup::NodeGroup(const AZStd::string& groupName, uint16 numNodes, bool enabledOnDefault)
|
||||
: mName(groupName)
|
||||
, mNodes(numNodes)
|
||||
, mEnabledOnDefault(enabledOnDefault)
|
||||
{
|
||||
SetIsEnabledOnDefault(true);
|
||||
}
|
||||
|
||||
|
||||
// extended constructor
|
||||
NodeGroup::NodeGroup(const char* groupName, bool enabledOnDefault)
|
||||
: BaseObject()
|
||||
{
|
||||
SetName(groupName);
|
||||
SetIsEnabledOnDefault(enabledOnDefault);
|
||||
}
|
||||
|
||||
|
||||
// another extended constructor
|
||||
NodeGroup::NodeGroup(const char* groupName, uint16 numNodes, bool enabledOnDefault)
|
||||
: BaseObject()
|
||||
{
|
||||
SetName(groupName);
|
||||
SetNumNodes(numNodes);
|
||||
SetIsEnabledOnDefault(enabledOnDefault);
|
||||
}
|
||||
|
||||
|
||||
// destructor
|
||||
NodeGroup::~NodeGroup()
|
||||
{
|
||||
mNodes.Clear();
|
||||
}
|
||||
|
||||
|
||||
// create
|
||||
NodeGroup* NodeGroup::Create()
|
||||
{
|
||||
return aznew NodeGroup();
|
||||
}
|
||||
|
||||
|
||||
// create
|
||||
NodeGroup* NodeGroup::Create(const char* groupName, bool enabledOnDefault)
|
||||
{
|
||||
return aznew NodeGroup(groupName, enabledOnDefault);
|
||||
}
|
||||
|
||||
|
||||
// create
|
||||
NodeGroup* NodeGroup::Create(const char* groupName, uint16 numNodes, bool enabledOnDefault)
|
||||
{
|
||||
return aznew NodeGroup(groupName, numNodes, enabledOnDefault);
|
||||
}
|
||||
|
||||
|
||||
// set the name of the group
|
||||
void NodeGroup::SetName(const char* groupName)
|
||||
void NodeGroup::SetName(const AZStd::string& groupName)
|
||||
{
|
||||
mName = groupName;
|
||||
}
|
||||
|
||||
@@ -30,38 +30,19 @@ namespace EMotionFX
|
||||
* might contain incorrect or even uninitialized data.
|
||||
*/
|
||||
class EMFX_API NodeGroup
|
||||
: public BaseObject
|
||||
{
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR_DECL
|
||||
/**
|
||||
* The default creation method.
|
||||
* This does not assign a name and there will be nodes inside this group on default.
|
||||
* Also the default enabled state is set to true.
|
||||
*/
|
||||
static NodeGroup* Create();
|
||||
|
||||
/**
|
||||
* Extended creation.
|
||||
* @param groupName The name of the group. Please keep in mind that it is not allowed to have two groups with the same name inside an Actor.
|
||||
* @param enabledOnDefault Set to true (default) when the nodes inside this group should be enabled on default.
|
||||
*/
|
||||
static NodeGroup* Create(const char* groupName, bool enabledOnDefault = true);
|
||||
|
||||
/**
|
||||
* Another extended constructor.
|
||||
* @param groupName The name of the group. Please keep in mind that it is not allowed to have two groups with the same name inside an Actor.
|
||||
* @param numNodes The number of nodes to create inside the group. This will have all uninitialized values for the node indices in the group, so be sure that you
|
||||
* set them all to some valid node index using the NodeGroup::SetNode(...) method. This method automatically calls the SetNumNodes(...) method.
|
||||
* @param enabledOnDefault Set to true (default) when the nodes inside this group should be enabled on default.
|
||||
*/
|
||||
static NodeGroup* Create(const char* groupName, uint16 numNodes, bool enabledOnDefault = true);
|
||||
NodeGroup(const AZStd::string& groupName = {}, uint16 numNodes = 0, bool enabledOnDefault = true);
|
||||
NodeGroup(const NodeGroup& aOther);
|
||||
NodeGroup& operator=(const NodeGroup& aOther);
|
||||
|
||||
/**
|
||||
* Set the name of the group. Please keep in mind that group names must be unique inside the Actor objects. So you should not have two or more groups with the same name.
|
||||
* @param groupName The name of the group.
|
||||
*/
|
||||
void SetName(const char* groupName);
|
||||
void SetName(const AZStd::string& groupName);
|
||||
|
||||
/**
|
||||
* Get the name of the group as null terminated character buffer.
|
||||
@@ -172,37 +153,6 @@ namespace EMotionFX
|
||||
*/
|
||||
void SetIsEnabledOnDefault(bool enabledOnDefault);
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
* This does not assign a name and there will be nodes inside this group on default.
|
||||
* Also the default enabled state is set to true.
|
||||
*/
|
||||
NodeGroup();
|
||||
|
||||
/**
|
||||
* Extended constructor.
|
||||
* @param groupName The name of the group. Please keep in mind that it is not allowed to have two groups with the same name inside an Actor.
|
||||
* @param enabledOnDefault Set to true (default) when the nodes inside this group should be enabled on default.
|
||||
*/
|
||||
NodeGroup(const char* groupName, bool enabledOnDefault = true);
|
||||
|
||||
/**
|
||||
* Another extended constructor.
|
||||
* @param groupName The name of the group. Please keep in mind that it is not allowed to have two groups with the same name inside an Actor.
|
||||
* @param numNodes The number of nodes to create inside the group. This will have all uninitialized values for the node indices in the group, so be sure that you
|
||||
* set them all to some valid node index using the NodeGroup::SetNode(...) method. This method automatically calls the SetNumNodes(...) method.
|
||||
* @param enabledOnDefault Set to true (default) when the nodes inside this group should be enabled on default.
|
||||
*/
|
||||
NodeGroup(const char* groupName, uint16 numNodes, bool enabledOnDefault = true);
|
||||
|
||||
/**
|
||||
* The destructor.
|
||||
*/
|
||||
~NodeGroup();
|
||||
|
||||
NodeGroup(const NodeGroup& aOther);
|
||||
NodeGroup& operator=(const NodeGroup& aOther);
|
||||
|
||||
private:
|
||||
AZStd::string mName; /**< The name of the group. */
|
||||
MCore::SmallArray<uint16> mNodes; /**< The node index numbers that are inside this group. */
|
||||
|
||||
+23
-7
@@ -9,6 +9,7 @@
|
||||
#include <AzQtComponents/Utilities/Conversions.h>
|
||||
#include <EMotionFX/CommandSystem/Source/AnimGraphConnectionCommands.h>
|
||||
#include <EMotionFX/CommandSystem/Source/AnimGraphNodeCommands.h>
|
||||
#include <EMotionFX/CommandSystem/Source/AnimGraphNodeGroupCommands.h>
|
||||
#include <EMotionFX/CommandSystem/Source/MotionSetCommands.h>
|
||||
#include <EMotionFX/Source/AnimGraphExitNode.h>
|
||||
#include <EMotionFX/Source/AnimGraphMotionNode.h>
|
||||
@@ -1208,7 +1209,7 @@ namespace EMStudio
|
||||
|
||||
MCore::CommandGroup commandGroup("Adjust anim graph node group");
|
||||
|
||||
AZStd::string nodeNames;
|
||||
AZStd::vector<AZStd::string> nodeNames;
|
||||
for (const QModelIndex& selectedIndex : selectionList)
|
||||
{
|
||||
// Skip transitions and blend tree connections.
|
||||
@@ -1221,12 +1222,19 @@ namespace EMStudio
|
||||
EMotionFX::AnimGraphNodeGroup* nodeGroup = animGraph->FindNodeGroupForNode(selectedNode);
|
||||
if (nodeGroup)
|
||||
{
|
||||
const AZStd::string command = AZStd::string::format("AnimGraphAdjustNodeGroup -animGraphID %i -name \"%s\" -nodeNames \"%s\" -nodeAction \"remove\"", animGraph->GetID(), nodeGroup->GetName(), selectedNode->GetName());
|
||||
commandGroup.AddCommandString(command);
|
||||
auto* command = aznew CommandSystem::CommandAnimGraphAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAnimGraphAdjustNodeGroup::s_commandName),
|
||||
/*animGraphId = */ animGraph->GetID(),
|
||||
/*name = */ nodeGroup->GetNameString(),
|
||||
/*visible = */ AZStd::nullopt,
|
||||
/*newName = */ AZStd::nullopt,
|
||||
/*nodeNames = */ {{selectedNode->GetNameString()}},
|
||||
/*nodeAction = */ CommandSystem::CommandAnimGraphAdjustNodeGroup::NodeAction::Remove
|
||||
);
|
||||
commandGroup.AddCommand(command);
|
||||
}
|
||||
|
||||
nodeNames += selectedNode->GetName();
|
||||
nodeNames += ";";
|
||||
nodeNames.emplace_back(selectedNode->GetName());
|
||||
}
|
||||
if (!nodeNames.empty())
|
||||
{
|
||||
@@ -1235,8 +1243,16 @@ namespace EMStudio
|
||||
|
||||
if (newNodeGroup)
|
||||
{
|
||||
const AZStd::string command = AZStd::string::format("AnimGraphAdjustNodeGroup -animGraphID %i -name \"%s\" -nodeNames \"%s\" -nodeAction \"add\"", animGraph->GetID(), newNodeGroup->GetName(), nodeNames.c_str());
|
||||
commandGroup.AddCommandString(command);
|
||||
auto* command = aznew CommandSystem::CommandAnimGraphAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAnimGraphAdjustNodeGroup::s_commandName),
|
||||
/*animGraphId = */ animGraph->GetID(),
|
||||
/*name = */ newNodeGroup->GetNameString(),
|
||||
/*visible = */ AZStd::nullopt,
|
||||
/*newName = */ AZStd::nullopt,
|
||||
/*nodeNames = */ nodeNames,
|
||||
/*nodeAction = */ CommandSystem::CommandAnimGraphAdjustNodeGroup::NodeAction::Add
|
||||
);
|
||||
commandGroup.AddCommand(command);
|
||||
}
|
||||
|
||||
AZStd::string outResult;
|
||||
|
||||
+28
-19
@@ -74,11 +74,6 @@ namespace EMStudio
|
||||
mLineEdit->setText(nodeGroup.c_str());
|
||||
mLineEdit->selectAll();
|
||||
|
||||
// create add the error message
|
||||
/*mErrorMsg = new QLabel("<font color='red'>Error: Duplicate name found</font>");
|
||||
mErrorMsg->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
||||
mErrorMsg->setVisible(false);*/
|
||||
|
||||
// create the button layout
|
||||
QHBoxLayout* buttonLayout = new QHBoxLayout();
|
||||
mOKButton = new QPushButton("OK");
|
||||
@@ -139,10 +134,16 @@ namespace EMStudio
|
||||
void NodeGroupRenameWindow::Accepted()
|
||||
{
|
||||
// Execute the command
|
||||
AZStd::string commandString, outResult;
|
||||
AZStd::string outResult;
|
||||
const AZStd::string convertedNewName = FromQtString(mLineEdit->text());
|
||||
commandString = AZStd::string::format("AnimGraphAdjustNodeGroup -animGraphID %i -name \"%s\" -newName \"%s\"", mAnimGraph->GetID(), mNodeGroup.c_str(), convertedNewName.c_str());
|
||||
if (GetCommandManager()->ExecuteCommand(commandString.c_str(), outResult) == false)
|
||||
auto* command = aznew CommandSystem::CommandAnimGraphAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAnimGraphAdjustNodeGroup::s_commandName),
|
||||
mAnimGraph->GetID(),
|
||||
/*name = */ mNodeGroup,
|
||||
/*visible = */ AZStd::nullopt,
|
||||
/*newName = */ convertedNewName
|
||||
);
|
||||
if (!GetCommandManager()->ExecuteCommand(command, outResult))
|
||||
{
|
||||
MCore::LogError(outResult.c_str());
|
||||
}
|
||||
@@ -167,7 +168,7 @@ namespace EMStudio
|
||||
mAdjustCallback = new CommandAnimGraphAdjustNodeGroupCallback(false);
|
||||
GetCommandManager()->RegisterCommandCallback("AnimGraphAddNodeGroup", mCreateCallback);
|
||||
GetCommandManager()->RegisterCommandCallback("AnimGraphRemoveNodeGroup", mRemoveCallback);
|
||||
GetCommandManager()->RegisterCommandCallback("AnimGraphAdjustNodeGroup", mAdjustCallback);
|
||||
GetCommandManager()->RegisterCommandCallback(CommandSystem::CommandAnimGraphAdjustNodeGroup::s_commandName.data(), mAdjustCallback);
|
||||
|
||||
// add the add button
|
||||
mAddAction = new QAction(MysticQt::GetMysticQt()->FindIcon("Images/Icons/Plus.svg"), tr("Add new node group"), this);
|
||||
@@ -486,13 +487,16 @@ namespace EMStudio
|
||||
|
||||
bool isVisible = state == Qt::Checked;
|
||||
|
||||
// construct the command
|
||||
AZStd::string commandString;
|
||||
commandString = AZStd::string::format("AnimGraphAdjustNodeGroup -animGraphID %i -name \"%s\" -isVisible %s", animGraph->GetID(), nodeGroup->GetName(), AZStd::to_string(isVisible).c_str());
|
||||
auto* command = aznew CommandSystem::CommandAnimGraphAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAnimGraphAdjustNodeGroup::s_commandName),
|
||||
/*animGraphId = */ animGraph->GetID(),
|
||||
/*name = */ nodeGroup->GetNameString(),
|
||||
/*visible = */ isVisible
|
||||
);
|
||||
|
||||
// execute the command
|
||||
AZStd::string resultString;
|
||||
if (GetCommandManager()->ExecuteCommand(commandString.c_str(), resultString) == false)
|
||||
if (GetCommandManager()->ExecuteCommand(command, resultString) == false)
|
||||
{
|
||||
if (resultString.size() > 0)
|
||||
{
|
||||
@@ -519,16 +523,21 @@ namespace EMStudio
|
||||
// get a pointer to the node group
|
||||
EMotionFX::AnimGraphNodeGroup* nodeGroup = animGraph->GetNodeGroup(groupIndex);
|
||||
|
||||
// get the color
|
||||
AZ::Vector4 finalColor = color.GetAsVector4();
|
||||
|
||||
// construct the command
|
||||
AZStd::string commandString;
|
||||
commandString = AZStd::string::format("AnimGraphAdjustNodeGroup -animGraphID %i -name \"%s\" -color \"%s\"", animGraph->GetID(), nodeGroup->GetName(), AZStd::to_string(finalColor).c_str());
|
||||
auto* command = aznew CommandSystem::CommandAnimGraphAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAnimGraphAdjustNodeGroup::s_commandName),
|
||||
/*animGraphId = */ animGraph->GetID(),
|
||||
/*name = */ nodeGroup->GetName(),
|
||||
/*visible = */ AZStd::nullopt,
|
||||
/*newName = */ AZStd::nullopt,
|
||||
/*nodeNames = */ AZStd::nullopt,
|
||||
/*nodeAction = */ AZStd::nullopt,
|
||||
/*color = */ color.ToU32()
|
||||
);
|
||||
|
||||
// execute the command
|
||||
AZStd::string resultString;
|
||||
if (GetCommandManager()->ExecuteCommand(commandString.c_str(), resultString) == false)
|
||||
if (GetCommandManager()->ExecuteCommand(command, resultString) == false)
|
||||
{
|
||||
if (resultString.size() > 0)
|
||||
{
|
||||
|
||||
+16
-99
@@ -112,8 +112,13 @@ namespace EMStudio
|
||||
|
||||
// execute the command
|
||||
AZStd::string outResult;
|
||||
AZStd::string command = AZStd::string::format("AdjustNodeGroup -actorID %i -name \"%s\" -newName \"%s\"", mActor->GetID(), mNodeGroupName.c_str(), convertedNewName.c_str());
|
||||
if (GetCommandManager()->ExecuteCommand(command.c_str(), outResult) == false)
|
||||
auto* command = aznew CommandSystem::CommandAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAdjustNodeGroup::s_commandName),
|
||||
/*actorId=*/ mActor->GetID(),
|
||||
/*name=*/ mNodeGroupName,
|
||||
/*newName=*/ convertedNewName
|
||||
);
|
||||
if (GetCommandManager()->ExecuteCommand(command, outResult) == false)
|
||||
{
|
||||
AZ_Error("EMotionFX", false, outResult.c_str());
|
||||
}
|
||||
@@ -362,98 +367,6 @@ namespace EMStudio
|
||||
mSelectedRow = MCORE_INVALIDINDEX32;
|
||||
}
|
||||
}
|
||||
/*void NodeGroupManagementWidget::UpdateNodeGroupWidget(QTableWidgetItem* current, QTableWidgetItem* previous)
|
||||
{
|
||||
MCORE_UNUSED(previous);
|
||||
|
||||
// return if no node group widget is set
|
||||
if (mNodeGroupWidget == nullptr)
|
||||
return;
|
||||
|
||||
// set the node group widget to the actual selection
|
||||
mNodeGroupWidget->SetActor( mActor );
|
||||
|
||||
if (current)
|
||||
{
|
||||
// set the current row
|
||||
mSelectedRow = current->row();
|
||||
|
||||
// set the node group
|
||||
NodeGroup* nodeGroup = mActor->FindNodeGroupByName( FromQtString(mNodeGroupsTable->item(current->row(), 1)->text()).c_str() );
|
||||
mNodeGroupWidget->SetNodeGroup( nodeGroup );
|
||||
}
|
||||
else
|
||||
{
|
||||
mNodeGroupWidget->SetNodeGroup( nullptr );
|
||||
mSelectedRow = MCORE_INVALIDINDEX32;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
// called whenever a cell is changed
|
||||
/*void NodeGroupManagementWidget::NodeGroupNamesChanged(const QString& text)
|
||||
{
|
||||
// get the sender widget
|
||||
QWidget* senderWidget = (QWidget*)sender();
|
||||
|
||||
// check for duplicates
|
||||
const int duplicateFound = SearchTableForString( mNodeGroupsTable, text );
|
||||
|
||||
// mark edit field in red, if entry already exists
|
||||
if (duplicateFound >= 0)
|
||||
GetManager()->SetWidgetAsInvalidInput( senderWidget );
|
||||
else
|
||||
senderWidget->setStyleSheet("");
|
||||
}*/
|
||||
|
||||
|
||||
// starts editing
|
||||
/*void NodeGroupManagementWidget::NodeGroupeNameDoubleClicked(QTableWidgetItem* item)
|
||||
{
|
||||
// add new line edit for the selected widget
|
||||
QLineEdit* lineEdit = new QLineEdit( mNodeGroupsTable->item(item->row(), 0)->text() );
|
||||
mNodeGroupsTable->setCellWidget( item->row(), 0, lineEdit );
|
||||
|
||||
// jump into the edit field
|
||||
lineEdit->selectAll();
|
||||
lineEdit->setFocus();
|
||||
mNodeGroupsTable->setCurrentCell( item->row(), 0 );
|
||||
|
||||
// connect slots for edit finishing and text change
|
||||
connect( lineEdit, SIGNAL(editingFinished()), this, SLOT(NodeGroupNameEditingFinished()) );
|
||||
connect( lineEdit, SIGNAL(textChanged(QString)), this, SLOT(NodeGroupNamesChanged(QString)) );
|
||||
}*/
|
||||
|
||||
|
||||
// called when editing is finished
|
||||
/*void NodeGroupManagementWidget::NodeGroupNameEditingFinished()
|
||||
{
|
||||
// get the current item
|
||||
QTableWidgetItem* item = mNodeGroupsTable->currentItem();
|
||||
|
||||
// get the sender widget
|
||||
QLineEdit* senderWidget = (QLineEdit*)sender();
|
||||
|
||||
// return if one of the widgets does not exist
|
||||
if (item == nullptr || senderWidget == nullptr)
|
||||
return;
|
||||
|
||||
// call commands for name change if name does not exist yet
|
||||
if (senderWidget->styleSheet() == "")
|
||||
{
|
||||
// call command for adding a new node group
|
||||
String outResult;
|
||||
String command;
|
||||
command.Format( "AdjustNodeGroup -actorID %i -name \"%s\" -newName \"%s\"", mActor->GetID(), FromQtString(item->text()).c_str(), FromQtString(senderWidget->text()).c_str() );
|
||||
if (EMStudio::GetCommandManager()->ExecuteCommand( command.c_str(), outResult ) == false)
|
||||
LogError( outResult.c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// delete the line edit
|
||||
mNodeGroupsTable->setCellWidget(item->row(), item->column(), nullptr);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
// function to add a new node group with the specified name
|
||||
@@ -562,16 +475,20 @@ namespace EMStudio
|
||||
if (rowChechbox == senderCheckbox)
|
||||
{
|
||||
nodeGroupName = mNodeGroupsTable->item(i, 1)->text().toUtf8().data();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// execute the command
|
||||
AZStd::string outResult;
|
||||
const AZStd::string command = AZStd::string::format("AdjustNodeGroup -actorID %i -name \"%s\" -enabledOnDefault \"%s\"",
|
||||
mActor->GetID(),
|
||||
nodeGroupName.c_str(),
|
||||
AZStd::to_string(checked).c_str());
|
||||
if (EMStudio::GetCommandManager()->ExecuteCommand(command.c_str(), outResult) == false)
|
||||
auto* command = aznew CommandSystem::CommandAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAdjustNodeGroup::s_commandName),
|
||||
/*actorId=*/ mActor->GetID(),
|
||||
/*name=*/ nodeGroupName,
|
||||
/*newName=*/ AZStd::nullopt,
|
||||
/*enabledOnDefault=*/ checked
|
||||
);
|
||||
if (EMStudio::GetCommandManager()->ExecuteCommand(command, outResult) == false)
|
||||
{
|
||||
AZ_Error("EMotionFX", false, outResult.c_str());
|
||||
}
|
||||
|
||||
+35
-41
@@ -35,7 +35,6 @@ namespace EMStudio
|
||||
mNodeTable = nullptr;
|
||||
mSelectNodesButton = nullptr;
|
||||
mNodeGroup = nullptr;
|
||||
mNodeAction = "";
|
||||
|
||||
// init the widget
|
||||
Init();
|
||||
@@ -254,11 +253,11 @@ namespace EMStudio
|
||||
QWidget* senderWidget = (QWidget*)sender();
|
||||
if (senderWidget == mAddNodesButton)
|
||||
{
|
||||
mNodeAction = "add";
|
||||
mNodeAction = CommandSystem::CommandAdjustNodeGroup::NodeAction::Add;
|
||||
}
|
||||
else
|
||||
{
|
||||
mNodeAction = "select";
|
||||
mNodeAction = CommandSystem::CommandAdjustNodeGroup::NodeAction::Replace;
|
||||
}
|
||||
|
||||
// get the selected actorinstance
|
||||
@@ -293,46 +292,37 @@ namespace EMStudio
|
||||
// remove nodes
|
||||
void NodeGroupWidget::RemoveNodesButtonPressed()
|
||||
{
|
||||
// generate node list string
|
||||
AZStd::string nodeList;
|
||||
uint32 lowestSelectedRow = MCORE_INVALIDINDEX32;
|
||||
const uint32 numTableRows = mNodeTable->rowCount();
|
||||
for (uint32 i = 0; i < numTableRows; ++i)
|
||||
{
|
||||
// get the current table item
|
||||
QTableWidgetItem* item = mNodeTable->item(i, 0);
|
||||
if (item == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// add the item to remove list, if it's selected
|
||||
if (item->isSelected())
|
||||
{
|
||||
nodeList += AZStd::string::format("%s;", item->text().toUtf8().data());
|
||||
if ((uint32)item->row() < lowestSelectedRow)
|
||||
{
|
||||
lowestSelectedRow = (uint32)item->row();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// stop here if nothing selected
|
||||
if (nodeList.empty())
|
||||
if (mNodeTable->selectedItems().empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// call command for adjusting disable on default flag
|
||||
// generate node list string
|
||||
AZStd::vector<AZStd::string> nodeList;
|
||||
int lowestSelectedRow = AZStd::numeric_limits<int>::max();
|
||||
for (const QTableWidgetItem* item : mNodeTable->selectedItems())
|
||||
{
|
||||
nodeList.emplace_back(FromQtString(item->text()));
|
||||
lowestSelectedRow = AZStd::min(lowestSelectedRow, item->row());
|
||||
}
|
||||
|
||||
AZStd::string outResult;
|
||||
AZStd::string command = AZStd::string::format("AdjustNodeGroup -actorID %i -name \"%s\" -nodeAction \"remove\" -nodeNames \"%s\"", mActor->GetID(), mNodeGroup->GetName(), nodeList.c_str());
|
||||
auto* command = aznew CommandSystem::CommandAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAdjustNodeGroup::s_commandName),
|
||||
/*actorId=*/ mActor->GetID(),
|
||||
/*name=*/ mNodeGroup->GetName(),
|
||||
/*newName=*/ AZStd::nullopt,
|
||||
/*enabledOnDefault=*/ AZStd::nullopt,
|
||||
/*nodeNames=*/ AZStd::move(nodeList),
|
||||
/*nodeAction=*/ CommandSystem::CommandAdjustNodeGroup::NodeAction::Remove
|
||||
);
|
||||
if (EMStudio::GetCommandManager()->ExecuteCommand(command, outResult) == false)
|
||||
{
|
||||
AZ_Error("EMotionFX", false, outResult.c_str());
|
||||
}
|
||||
|
||||
// selected the next row
|
||||
if (lowestSelectedRow > ((uint32)mNodeTable->rowCount() - 1))
|
||||
if (lowestSelectedRow > (mNodeTable->rowCount() - 1))
|
||||
{
|
||||
mNodeTable->selectRow(lowestSelectedRow - 1);
|
||||
}
|
||||
@@ -353,19 +343,23 @@ namespace EMStudio
|
||||
}
|
||||
|
||||
// generate node list string
|
||||
AZStd::string nodeList;
|
||||
nodeList.reserve(16448);
|
||||
const uint32 numSelectedNodes = selectionList.GetLength();
|
||||
for (uint32 i = 0; i < numSelectedNodes; ++i)
|
||||
AZStd::vector<AZStd::string> nodeList;
|
||||
const uint32 selectionListSize = selectionList.GetLength();
|
||||
for (uint32 i = 0; i < selectionListSize; ++i)
|
||||
{
|
||||
nodeList += selectionList[i].GetNodeName();
|
||||
nodeList += ";";
|
||||
nodeList.emplace_back(selectionList[i].GetNodeName());
|
||||
}
|
||||
AzFramework::StringFunc::Strip(nodeList, MCore::CharacterConstants::semiColon, true /* case sensitive */, false /* beginning */, true /* ending */);
|
||||
|
||||
// call command for adjusting disable on default flag
|
||||
AZStd::string outResult;
|
||||
AZStd::string command = AZStd::string::format("AdjustNodeGroup -actorID %i -name \"%s\" -nodeAction \"%s\" -nodeNames \"%s\"", mActor->GetID(), mNodeGroup->GetName(), mNodeAction.c_str(), nodeList.c_str());
|
||||
auto* command = aznew CommandSystem::CommandAdjustNodeGroup(
|
||||
GetCommandManager()->FindCommand(CommandSystem::CommandAdjustNodeGroup::s_commandName),
|
||||
/*actorId=*/ mActor->GetID(),
|
||||
/*name=*/ mNodeGroup->GetName(),
|
||||
/*newName=*/ AZStd::nullopt,
|
||||
/*enabledOnDefault=*/ AZStd::nullopt,
|
||||
/*nodeNames=*/ AZStd::move(nodeList),
|
||||
/*nodeAction=*/ mNodeAction
|
||||
);
|
||||
if (EMStudio::GetCommandManager()->ExecuteCommand(command, outResult) == false)
|
||||
{
|
||||
AZ_Error("EMotionFX", false, outResult.c_str());
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@
|
||||
#include <MysticQt/Source/DialogStack.h>
|
||||
#include "../../../../EMStudioSDK/Source/DockWidgetPlugin.h"
|
||||
#include "../../../../EMStudioSDK/Source/NodeSelectionWindow.h"
|
||||
#include <EMotionFX/CommandSystem/Source/NodeGroupCommands.h>
|
||||
#endif
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QLineEdit)
|
||||
@@ -58,7 +59,7 @@ namespace EMStudio
|
||||
CommandSystem::SelectionList mNodeSelectionList;
|
||||
EMotionFX::NodeGroup* mNodeGroup;
|
||||
uint16 mNodeGroupIndex;
|
||||
AZStd::string mNodeAction;
|
||||
CommandSystem::CommandAdjustNodeGroup::NodeAction mNodeAction;
|
||||
|
||||
// widgets
|
||||
QTableWidget* mNodeTable;
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@
|
||||
#include "../../../../EMStudioSDK/Source/EMStudioCore.h"
|
||||
#include <MCore/Source/LogManager.h>
|
||||
#include <EMotionFX/CommandSystem/Source/CommandManager.h>
|
||||
#include <EMotionFX/CommandSystem/Source/NodeGroupCommands.h>
|
||||
#include "../../../../EMStudioSDK/Source/EMStudioManager.h"
|
||||
|
||||
// include qt headers
|
||||
@@ -99,7 +100,7 @@ namespace EMStudio
|
||||
GetCommandManager()->RegisterCommandCallback("Select", mSelectCallback);
|
||||
GetCommandManager()->RegisterCommandCallback("Unselect", mUnselectCallback);
|
||||
GetCommandManager()->RegisterCommandCallback("ClearSelection", mClearSelectionCallback);
|
||||
GetCommandManager()->RegisterCommandCallback("AdjustNodeGroup", mAdjustNodeGroupCallback);
|
||||
GetCommandManager()->RegisterCommandCallback(CommandSystem::CommandAdjustNodeGroup::s_commandName.data(), mAdjustNodeGroupCallback);
|
||||
GetCommandManager()->RegisterCommandCallback("AddNodeGroup", mAddNodeGroupCallback);
|
||||
GetCommandManager()->RegisterCommandCallback("RemoveNodeGroup", mRemoveNodeGroupCallback);
|
||||
|
||||
|
||||
@@ -28,10 +28,10 @@ namespace MCore
|
||||
|
||||
|
||||
// constructor
|
||||
Command::Command(const char* commandName, Command* originalCommand)
|
||||
Command::Command(AZStd::string commandName, Command* originalCommand)
|
||||
: mOrgCommand(originalCommand)
|
||||
, mCommandName(AZStd::move(commandName))
|
||||
{
|
||||
mCommandName = commandName;
|
||||
mOrgCommand = originalCommand;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace MCore
|
||||
* @param commandName The unique identifier for the command.
|
||||
* @param originalCommand The original command, or nullptr when this is the original command.
|
||||
*/
|
||||
Command(const char* commandName, Command* originalCommand);
|
||||
Command(AZStd::string commandName, Command* originalCommand);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
|
||||
Reference in New Issue
Block a user