Correctly handle link modifications, run OnLoadFinished when creating new nodes
This commit is contained in:
parent
c4e05610f3
commit
2bcf29dd7f
|
@ -22,7 +22,7 @@ void CAddLinkCommand::undo()
|
||||||
pReceiver->RemoveLink(eIncoming, pLink);
|
pReceiver->RemoveLink(eIncoming, pLink);
|
||||||
delete pLink;
|
delete pLink;
|
||||||
|
|
||||||
mpEditor->InstanceLinksModified(mAffectedInstances.DereferenceList());
|
mpEditor->OnLinksModified(mAffectedInstances.DereferenceList());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAddLinkCommand::redo()
|
void CAddLinkCommand::redo()
|
||||||
|
@ -31,5 +31,5 @@ void CAddLinkCommand::redo()
|
||||||
pLink->Sender()->AddLink(eOutgoing, pLink, -1);
|
pLink->Sender()->AddLink(eOutgoing, pLink, -1);
|
||||||
pLink->Receiver()->AddLink(eIncoming, pLink, -1);
|
pLink->Receiver()->AddLink(eIncoming, pLink, -1);
|
||||||
|
|
||||||
mpEditor->InstanceLinksModified(mAffectedInstances.DereferenceList());
|
mpEditor->OnLinksModified(mAffectedInstances.DereferenceList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ void CCreateInstanceCommand::redo()
|
||||||
CScriptObject *pNewInst = mpArea->SpawnInstance(mpTemplate, pLayer, mSpawnPosition);
|
CScriptObject *pNewInst = mpArea->SpawnInstance(mpTemplate, pLayer, mSpawnPosition);
|
||||||
CScriptNode *pNewNode = mpScene->CreateScriptNode(pNewInst);
|
CScriptNode *pNewNode = mpScene->CreateScriptNode(pNewInst);
|
||||||
pNewNode->SetPosition(mSpawnPosition);
|
pNewNode->SetPosition(mSpawnPosition);
|
||||||
|
pNewNode->OnLoadFinished();
|
||||||
|
|
||||||
mpEditor->NotifyNodeSpawned(pNewNode);
|
mpEditor->NotifyNodeSpawned(pNewNode);
|
||||||
mpEditor->Selection()->ClearAndSelectNode(pNewNode);
|
mpEditor->Selection()->ClearAndSelectNode(pNewNode);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ CDeleteSelectionCommand::CDeleteSelectionCommand(CWorldEditor *pEditor)
|
||||||
, mpEditor(pEditor)
|
, mpEditor(pEditor)
|
||||||
{
|
{
|
||||||
QSet<CLink*> Links;
|
QSet<CLink*> Links;
|
||||||
|
QList<CScriptObject*> LinkedInstances;
|
||||||
|
|
||||||
for (CSelectionIterator It(pEditor->Selection()); It; ++It)
|
for (CSelectionIterator It(pEditor->Selection()); It; ++It)
|
||||||
{
|
{
|
||||||
|
@ -53,6 +54,11 @@ CDeleteSelectionCommand::CDeleteSelectionCommand(CWorldEditor *pEditor)
|
||||||
Link.pReceiver = pLink->Receiver();
|
Link.pReceiver = pLink->Receiver();
|
||||||
mDeletedLinks << Link;
|
mDeletedLinks << Link;
|
||||||
Links << pLink;
|
Links << pLink;
|
||||||
|
|
||||||
|
if (!LinkedInstances.contains(pLink->Sender()))
|
||||||
|
LinkedInstances << pLink->Sender();
|
||||||
|
if (!LinkedInstances.contains(pLink->Receiver()))
|
||||||
|
LinkedInstances << pLink->Receiver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,13 +71,19 @@ CDeleteSelectionCommand::CDeleteSelectionCommand(CWorldEditor *pEditor)
|
||||||
mNewSelection << *It;
|
mNewSelection << *It;
|
||||||
}
|
}
|
||||||
|
|
||||||
qSort(mDeletedNodes.begin(), mDeletedNodes.end(), [](SDeletedNode& rLeft, SDeletedNode& rRight) -> bool {
|
// Remove selected objects from the linked instances list.
|
||||||
return (rLeft.NodeID < rRight.NodeID);
|
foreach (CScriptObject *pInst, LinkedInstances)
|
||||||
});
|
{
|
||||||
|
if (mpEditor->Scene()->NodeForObject(pInst)->IsSelected())
|
||||||
|
LinkedInstances.removeOne(pInst);
|
||||||
|
}
|
||||||
|
|
||||||
|
mLinkedInstances = LinkedInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDeleteSelectionCommand::undo()
|
void CDeleteSelectionCommand::undo()
|
||||||
{
|
{
|
||||||
|
QList<CSceneNode*> NewNodes;
|
||||||
QList<u32> NewInstanceIDs;
|
QList<u32> NewInstanceIDs;
|
||||||
|
|
||||||
// Spawn nodes
|
// Spawn nodes
|
||||||
|
@ -90,6 +102,7 @@ void CDeleteSelectionCommand::undo()
|
||||||
if (!pInstance->RotationProperty()) pNode->SetRotation(rNode.Rotation);
|
if (!pInstance->RotationProperty()) pNode->SetRotation(rNode.Rotation);
|
||||||
if (!pInstance->ScaleProperty()) pNode->SetScale(rNode.Scale);
|
if (!pInstance->ScaleProperty()) pNode->SetScale(rNode.Scale);
|
||||||
|
|
||||||
|
NewNodes << pNode;
|
||||||
NewInstanceIDs << pInstance->InstanceID();
|
NewInstanceIDs << pInstance->InstanceID();
|
||||||
mpEditor->NotifyNodeSpawned(*rNode.NodePtr);
|
mpEditor->NotifyNodeSpawned(*rNode.NodePtr);
|
||||||
}
|
}
|
||||||
|
@ -123,8 +136,13 @@ void CDeleteSelectionCommand::undo()
|
||||||
rLink.pReceiver->AddLink(eIncoming, pLink, rLink.ReceiverIndex);
|
rLink.pReceiver->AddLink(eIncoming, pLink, rLink.ReceiverIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run OnLoadFinished
|
||||||
|
foreach (CSceneNode *pNode, NewNodes)
|
||||||
|
pNode->OnLoadFinished();
|
||||||
|
|
||||||
// Add selection and done
|
// Add selection and done
|
||||||
mpEditor->Selection()->SetSelectedNodes(mOldSelection.DereferenceList());
|
mpEditor->Selection()->SetSelectedNodes(mOldSelection.DereferenceList());
|
||||||
|
mpEditor->OnLinksModified(mLinkedInstances.DereferenceList());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDeleteSelectionCommand::redo()
|
void CDeleteSelectionCommand::redo()
|
||||||
|
@ -142,4 +160,6 @@ void CDeleteSelectionCommand::redo()
|
||||||
mpEditor->ActiveArea()->DeleteInstance(pInst);
|
mpEditor->ActiveArea()->DeleteInstance(pInst);
|
||||||
mpEditor->NotifyNodeDeleted();
|
mpEditor->NotifyNodeDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mpEditor->OnLinksModified(mLinkedInstances.DereferenceList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ class CDeleteSelectionCommand : public IUndoCommand
|
||||||
CWorldEditor *mpEditor;
|
CWorldEditor *mpEditor;
|
||||||
CNodePtrList mOldSelection;
|
CNodePtrList mOldSelection;
|
||||||
CNodePtrList mNewSelection;
|
CNodePtrList mNewSelection;
|
||||||
|
CInstancePtrList mLinkedInstances;
|
||||||
|
|
||||||
struct SDeletedNode
|
struct SDeletedNode
|
||||||
{
|
{
|
||||||
|
|
|
@ -280,7 +280,8 @@ void CWorldEditor::OnLinksModified(const QList<CScriptObject*>& rkInstances)
|
||||||
pNode->LinksModified();
|
pNode->LinksModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
emit InstanceLinksModified(rkInstances);
|
if (!rkInstances.isEmpty())
|
||||||
|
emit InstanceLinksModified(rkInstances);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWorldEditor::OnPropertyModified(IProperty *pProp)
|
void CWorldEditor::OnPropertyModified(IProperty *pProp)
|
||||||
|
|
Loading…
Reference in New Issue