diff --git a/radiantcore/layers/LayerInfoFileModule.cpp b/radiantcore/layers/LayerInfoFileModule.cpp index f5739b012a..23c9e98376 100644 --- a/radiantcore/layers/LayerInfoFileModule.cpp +++ b/radiantcore/layers/LayerInfoFileModule.cpp @@ -17,7 +17,10 @@ namespace constexpr const char* const NODE_TO_LAYER_MAPPING = "NodeToLayerMapping"; constexpr const char* const LAYER_HIERARCHY = "LayerHierarchy"; constexpr const char* const LAYER = "Layer"; + constexpr const char* const ACTIVE_LAYER = "ActiveLayer"; + constexpr const char* const HIDDEN_LAYERS = "HiddenLayers"; constexpr const char* const LAYERS = "Layers"; + constexpr const char* const LAYER_PROPERTIES = "LayerProperties"; constexpr const char* const NODE = "Node"; constexpr const char* const PARENT = "Parent"; } @@ -46,6 +49,8 @@ void LayerInfoFileModule::clear() _layerNames.clear(); _layerMappings.clear(); _layerParentIds.clear(); + _activeLayerId = 0; + _hiddenLayerIds.clear(); } void LayerInfoFileModule::onInfoFileSaveStart() @@ -154,7 +159,8 @@ void LayerInfoFileModule::onInfoFileLoadStart() bool LayerInfoFileModule::canParseBlock(const std::string& blockName) { - return blockName == LAYERS || blockName == NODE_TO_LAYER_MAPPING || blockName == LAYER_HIERARCHY; + return blockName == LAYERS || blockName == NODE_TO_LAYER_MAPPING || + blockName == LAYER_HIERARCHY || blockName == LAYER_PROPERTIES; } void LayerInfoFileModule::parseBlock(const std::string& blockName, parser::DefTokeniser& tok) @@ -170,9 +176,13 @@ void LayerInfoFileModule::parseBlock(const std::string& blockName, parser::DefTo parseNodeToLayerMapping(tok); } else if (blockName == LAYER_HIERARCHY) - { - parseLayerHierarchy(tok); - } + { + parseLayerHierarchy(tok); + } + else if (blockName == LAYER_PROPERTIES) + { + parseLayerProperties(tok); + } } void LayerInfoFileModule::parseLayerNames(parser::DefTokeniser& tok) @@ -290,6 +300,60 @@ void LayerInfoFileModule::parseLayerHierarchy(parser::DefTokeniser& tok) } } +void LayerInfoFileModule::parseLayerProperties(parser::DefTokeniser& tok) +{ + /* + LayerProperties + { + ActiveLayer { 9 } + HiddenLayers { 2 1 6 7 } + } + */ + + // The opening brace + tok.assertNextToken("{"); + + while (tok.hasMoreTokens()) + { + auto token = tok.nextToken(); + + if (token == ACTIVE_LAYER) + { + // The block just contains the active layer ID, only a single one is supported + tok.assertNextToken("{"); + _activeLayerId = string::convert(tok.nextToken(), -1); + tok.assertNextToken("}"); + + if (_activeLayerId != -1) + { + rDebug() << "[InfoFile]: ActiveLayer ID could not be parsed: " << _activeLayerId << std::endl; + } + + continue; + } + + if (token == HIDDEN_LAYERS) + { + // The block just contains a list of delimited layer IDs (or nothing) + tok.assertNextToken("{"); + + while (tok.hasMoreTokens()) + { + auto nodeToken = tok.nextToken(); + + if (nodeToken == "}") break; + + // Add the ID to the list + _hiddenLayerIds.push_back(string::convert(nodeToken)); + } + + continue; + } + + if (token == "}") break; + } +} + void LayerInfoFileModule::applyInfoToScene(const IMapRootNodePtr& root, const map::NodeIndexMap& nodeMap) { auto& layerManager = root->getLayerManager(); @@ -301,6 +365,19 @@ void LayerInfoFileModule::applyInfoToScene(const IMapRootNodePtr& root, const ma layerManager.createLayer(name, id); } + // Set the active layer before setting visibility + if (_activeLayerId != 0) + { + layerManager.setActiveLayer(_activeLayerId); + } + + // Assign layer visibility status before the hierarchy is restored + // this way we don't implicitly set the child layer visibility + for (auto hiddenLayerId : _hiddenLayerIds) + { + layerManager.setLayerVisibility(hiddenLayerId, false); + } + // Assigning child and parent layers needs to happen after all layers have been created for (const auto& [childLayerId, parentLayerId] : _layerParentIds) { diff --git a/radiantcore/layers/LayerInfoFileModule.h b/radiantcore/layers/LayerInfoFileModule.h index 02ed0c6741..b9c516e3ed 100644 --- a/radiantcore/layers/LayerInfoFileModule.h +++ b/radiantcore/layers/LayerInfoFileModule.h @@ -22,6 +22,8 @@ class LayerInfoFileModule : std::map _layerNames; std::map _layerParentIds; + int _activeLayerId; + std::vector _hiddenLayerIds; typedef std::vector LayerLists; LayerLists _layerMappings; @@ -55,6 +57,7 @@ class LayerInfoFileModule : void parseLayerNames(parser::DefTokeniser& tok); void parseNodeToLayerMapping(parser::DefTokeniser& tok); void parseLayerHierarchy(parser::DefTokeniser& tok); + void parseLayerProperties(parser::DefTokeniser& tok); }; }