diff --git a/include/ishaders.h b/include/ishaders.h index c6bd3b833d..ebb351714c 100644 --- a/include/ishaders.h +++ b/include/ishaders.h @@ -595,6 +595,10 @@ class MaterialManager virtual void removeMaterial(const std::string& name) = 0; + // Saves the named material to the file location as specified in its shaderfile info. + // If the path is not writable or the material is not suitable for saving, this will throw an exception + virtual void saveMaterial(const std::string& name) = 0; + // Creates a named, internal material for debug/testing etc. // Used by shaders without corresponding material declaration, like entity wireframe shaders virtual MaterialPtr createDefaultMaterial(const std::string& name) = 0; diff --git a/radiant/ui/materials/editor/MaterialEditor.cpp b/radiant/ui/materials/editor/MaterialEditor.cpp index a0614d1494..a035f58446 100644 --- a/radiant/ui/materials/editor/MaterialEditor.cpp +++ b/radiant/ui/materials/editor/MaterialEditor.cpp @@ -1121,7 +1121,20 @@ bool MaterialEditor::saveCurrentMaterial() _material->setShaderFileName(os::standardPath(result)); } - // TODO: Let the shader module write the material file + try + { + // Write to the specified .mtr file + GlobalMaterialManager().saveMaterial(_material->getName()); + } + catch (const std::runtime_error& ex) + { + rError() << "Could not save file: " << ex.what() << std::endl; + wxutil::Messagebox::ShowError(ex.what(), this); + + return false; // failure means to abort the process + } + + updateMaterialTreeItem(); return true; } diff --git a/radiantcore/shaders/Doom3ShaderSystem.cpp b/radiantcore/shaders/Doom3ShaderSystem.cpp index e015cce375..a906886287 100644 --- a/radiantcore/shaders/Doom3ShaderSystem.cpp +++ b/radiantcore/shaders/Doom3ShaderSystem.cpp @@ -434,6 +434,13 @@ MaterialPtr Doom3ShaderSystem::copyMaterial(const std::string& nameOfOriginal, c return material; } +void Doom3ShaderSystem::saveMaterial(const std::string& name) +{ + ensureDefsLoaded(); + + +} + ITableDefinition::Ptr Doom3ShaderSystem::getTable(const std::string& name) { ensureDefsLoaded(); diff --git a/radiantcore/shaders/Doom3ShaderSystem.h b/radiantcore/shaders/Doom3ShaderSystem.h index b5071b071a..6de726af41 100644 --- a/radiantcore/shaders/Doom3ShaderSystem.h +++ b/radiantcore/shaders/Doom3ShaderSystem.h @@ -123,6 +123,7 @@ class Doom3ShaderSystem : MaterialPtr copyMaterial(const std::string& nameOfOriginal, const std::string& nameOfCopy) override; bool renameMaterial(const std::string& oldName, const std::string& newName) override; void removeMaterial(const std::string& name) override; + void saveMaterial(const std::string& name) override; // Look up a table def, return NULL if not found ITableDefinition::Ptr getTable(const std::string& name);