Skip to content

Commit

Permalink
#5565: More robust renaming algorithm in ShaderLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 28, 2021
1 parent 0e8ea39 commit a127ea4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
18 changes: 10 additions & 8 deletions radiant/ui/materials/editor/MaterialEditor.cpp
Expand Up @@ -1292,7 +1292,8 @@ void MaterialEditor::updateMaterialControlSensitivity()
getControl<wxButton>("MaterialEditorSaveDefButton")->Enable(_material && _material->isModified() &&
GlobalMaterialManager().materialCanBeModified(_material->getName()));

getControl<wxButton>("MaterialEditorCopyDefButton")->Enable(_material != nullptr);
// TODO: Copy not implemented yet
getControl<wxButton>("MaterialEditorCopyDefButton")->Enable(false/*_material != nullptr*/);
getControl<wxButton>("MaterialEditorRevertButton")->Enable(_material && _material->isModified());
}

Expand Down Expand Up @@ -2165,7 +2166,8 @@ void MaterialEditor::updateMaterialTreeItem()
{
if (!_material) return;

auto item = _treeView->GetTreeModel()->FindString(_material->getName(), _treeView->Columns().fullName);
const auto& columns = _treeView->Columns();
auto item = _treeView->GetTreeModel()->FindString(_material->getName(), columns.fullName);

if (!item.IsOk())
{
Expand All @@ -2176,26 +2178,26 @@ void MaterialEditor::updateMaterialTreeItem()

wxutil::TreeModel::Row row(item, *_treeView->GetModel());

if (!row[_treeView->Columns().isFolder].getBool())
if (!row[columns.isFolder].getBool())
{
row[_treeView->Columns().iconAndName] = wxutil::TreeViewItemStyle::Modified(isModified);
row[columns.iconAndName] = wxutil::TreeViewItemStyle::Modified(isModified);
}
else
{
row[_treeView->Columns().iconAndName] = wxDataViewItemAttr();
row[columns.iconAndName] = wxDataViewItemAttr();
}

wxDataViewIconText value = row[_treeView->Columns().iconAndName];
wxDataViewIconText value = row[columns.iconAndName];

if (!isModified && value.GetText().EndsWith("*"))
{
value.SetText(value.GetText().RemoveLast(1));
row[_treeView->Columns().iconAndName] = wxVariant(value);
row[columns.iconAndName] = wxVariant(value);
}
else if (isModified && !value.GetText().EndsWith("*"))
{
value.SetText(value.GetText() + "*");
row[_treeView->Columns().iconAndName] = wxVariant(value);
row[columns.iconAndName] = wxVariant(value);
}

row.SendItemChanged();
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/rendersystem/backend/OpenGLShader.cpp
Expand Up @@ -929,6 +929,12 @@ void OpenGLShader::construct()

void OpenGLShader::onMaterialChanged()
{
// It's possible that the name of the material got changed, update it
if (_material && _material->getName() != _name)
{
_name = _material->getName();
}

unrealise();
realise();
}
Expand Down
9 changes: 6 additions & 3 deletions radiantcore/shaders/ShaderLibrary.cpp
Expand Up @@ -96,10 +96,13 @@ void ShaderLibrary::renameDefinition(const std::string& oldName, const std::stri
auto extractedShader = _shaders.extract(oldName);
extractedShader.key() = newName;

// Rename the CShader instance
extractedShader.mapped()->setName(newName);
// Insert it under the new name before setting the CShader instance's name
// the observing OpenGLShader instance will request the material to reconstruct itself
// If the new name is not present at that point, the library will create a default material.
auto result = _shaders.insert(std::move(extractedShader));

_shaders.insert(std::move(extractedShader));
// Rename the CShader instance
result.position->second->setName(newName);
}
}

Expand Down

0 comments on commit a127ea4

Please sign in to comment.