From b2abd5304973f0dee977a3a43ca5aa772163c301 Mon Sep 17 00:00:00 2001 From: codereader Date: Mon, 20 Apr 2020 13:03:03 +0200 Subject: [PATCH] #5176: Let DR remember the shader in ShaderClipboard after closing, it's saved in each map's root node properties --- .../shaderclipboard/ShaderClipboard.cpp | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/radiant/selection/shaderclipboard/ShaderClipboard.cpp b/radiant/selection/shaderclipboard/ShaderClipboard.cpp index e07ff91651..be43d2e192 100644 --- a/radiant/selection/shaderclipboard/ShaderClipboard.cpp +++ b/radiant/selection/shaderclipboard/ShaderClipboard.cpp @@ -1,6 +1,7 @@ #include "ShaderClipboard.h" #include "i18n.h" +#include "imap.h" #include "iselectiontest.h" #include "iscenegraph.h" #include "iuimanager.h" @@ -15,6 +16,11 @@ namespace selection { +namespace +{ + const char* const LAST_USED_MATERIAL_KEY = "LastShaderClipboardMaterial"; +} + ShaderClipboard::ShaderClipboard() : _updatesDisabled(false) { @@ -165,11 +171,36 @@ sigc::signal ShaderClipboard::signal_sourceChanged() const void ShaderClipboard::onMapEvent(IMap::MapEvent ev) { - if (ev == IMap::MapUnloading || ev == IMap::MapLoaded) + switch (ev) { + case IMap::MapUnloading: // Clear the shaderclipboard, the references are most probably invalid now clear(); - } + break; + + case IMap::MapSaving: + // Write the current value to the map properties on save + if (!_source.empty() && GlobalMapModule().getRoot()) + { + GlobalMapModule().getRoot()->setProperty(LAST_USED_MATERIAL_KEY, _source.getShader()); + } + break; + + case IMap::MapLoaded: + // Try to load the last used material name from the properties + if (GlobalMapModule().getRoot()) + { + auto shader = GlobalMapModule().getRoot()->getProperty(LAST_USED_MATERIAL_KEY); + + if (!shader.empty()) + { + setSource(shader); + break; + } + } + clear(); + break; + }; } } // namespace selection