From 880df6c8896807942498f888176f966f89b206da Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 29 May 2021 17:42:29 +0200 Subject: [PATCH] #5623: Use excluded flag to not interfere with the user hiding/unhiding nodes during merge --- libs/scene/Node.h | 4 +- radiantcore/map/MergeActionNode.h | 83 +++++++++++++++++++------------ 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/libs/scene/Node.h b/libs/scene/Node.h index e9e74fc51f..b832e6d65d 100644 --- a/libs/scene/Node.h +++ b/libs/scene/Node.h @@ -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: diff --git a/radiantcore/map/MergeActionNode.h b/radiantcore/map/MergeActionNode.h index 38f1515ece..2004b6b10a 100644 --- a/radiantcore/map/MergeActionNode.h +++ b/radiantcore/map/MergeActionNode.h @@ -25,23 +25,6 @@ class MergeActionNode final : _action(action) { _affectedNode = _action->getAffectedNode(); - - auto addNodeAction = std::dynamic_pointer_cast(_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 @@ -49,25 +32,15 @@ class MergeActionNode final : SelectableNode::onInsertIntoScene(rootNode); _action->activate(); + + addPreviewNodeForAddAction(); + hideAffectedNodes(); } void onRemoveFromScene(scene::IMapRootNode& rootNode) override { - auto addNodeAction = std::dynamic_pointer_cast(_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(); @@ -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(_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(_action); + + if (addNodeAction) + { + scene::removeNodeFromParent(_affectedNode); + } + } }; }