Skip to content

Commit

Permalink
#5623: Use excluded flag to not interfere with the user hiding/unhidi…
Browse files Browse the repository at this point in the history
…ng nodes during merge
  • Loading branch information
codereader committed May 29, 2021
1 parent ffb6f87 commit 880df6c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 34 deletions.
4 changes: 2 additions & 2 deletions libs/scene/Node.h
Expand Up @@ -25,8 +25,8 @@ class Node :
eVisible = 0,
eHidden = 1 << 0, // manually hidden by the user
eFiltered = 1 << 1, // excluded due to filter settings
eExcluded = 1 << 2, // excluded due to regioning
eLayered = 1 << 3 // invisible at the current layer settings
eExcluded = 1 << 2, // excluded due to regioning or merging
eLayered = 1 << 3, // invisible at the current layer settings
};

private:
Expand Down
83 changes: 51 additions & 32 deletions radiantcore/map/MergeActionNode.h
Expand Up @@ -25,49 +25,22 @@ class MergeActionNode final :
_action(action)
{
_affectedNode = _action->getAffectedNode();

auto addNodeAction = std::dynamic_pointer_cast<scene::merge::AddCloneToParentAction>(_action);

if (addNodeAction)
{
// Get the clone and add it to the target scene, it needs to be renderable here
scene::addNodeToContainer(_affectedNode, addNodeAction->getParent());
}

// Hide the affected node itself, we're doing the rendering ourselves, recursively
_affectedNode->enable(Node::eHidden);

_affectedNode->foreachNode([&](const scene::INodePtr& child)
{
child->enable(Node::eHidden);
return true;
});
}

void onInsertIntoScene(scene::IMapRootNode& rootNode) override
{
SelectableNode::onInsertIntoScene(rootNode);

_action->activate();

addPreviewNodeForAddAction();
hideAffectedNodes();
}

void onRemoveFromScene(scene::IMapRootNode& rootNode) override
{
auto addNodeAction = std::dynamic_pointer_cast<scene::merge::AddCloneToParentAction>(_action);

if (addNodeAction)
{
scene::removeNodeFromParent(_affectedNode);
}

// Release the hidden state of the contained nodes
_affectedNode->disable(Node::eHidden);

_affectedNode->foreachNode([&](const scene::INodePtr& child)
{
child->disable(Node::eHidden);
return true;
});
unhideAffectedNodes();
removePreviewNodeForAddAction();

_action->deactivate();

Expand Down Expand Up @@ -144,6 +117,52 @@ class MergeActionNode final :

selector.popSelectable();
}

void hideAffectedNodes()
{
// Hide the affected node itself, we're doing the rendering ourselves, recursively
_affectedNode->enable(Node::eExcluded);

_affectedNode->foreachNode([&](const scene::INodePtr& child)
{
child->enable(Node::eExcluded);
return true;
});
}

void unhideAffectedNodes()
{
// Release the excluded state of the contained nodes
_affectedNode->disable(Node::eExcluded);

_affectedNode->foreachNode([&](const scene::INodePtr& child)
{
child->disable(Node::eExcluded);
return true;
});
}

void addPreviewNodeForAddAction()
{
// We add the node to the target scene, for preview purposes
auto addNodeAction = std::dynamic_pointer_cast<scene::merge::AddCloneToParentAction>(_action);

if (addNodeAction)
{
// Get the clone and add it to the target scene, it needs to be renderable here
scene::addNodeToContainer(_affectedNode, addNodeAction->getParent());
}
}

void removePreviewNodeForAddAction()
{
auto addNodeAction = std::dynamic_pointer_cast<scene::merge::AddCloneToParentAction>(_action);

if (addNodeAction)
{
scene::removeNodeFromParent(_affectedNode);
}
}
};

}

0 comments on commit 880df6c

Please sign in to comment.