From d989e429bb95042262ac5c17da744f15f7613a1b Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 28 Mar 2021 07:18:18 +0200 Subject: [PATCH] #5565: WIP commit, working on "New Material" functionality --- install/ui/materialeditor.fbp | 8 +-- install/ui/materialeditor.xrc | 4 ++ radiant/ui/materials/MaterialPopulator.cpp | 10 +++- .../ui/materials/editor/MaterialEditor.cpp | 55 +++++++++++++++---- radiant/ui/materials/editor/MaterialEditor.h | 2 + 5 files changed, 63 insertions(+), 16 deletions(-) diff --git a/install/ui/materialeditor.fbp b/install/ui/materialeditor.fbp index 37eb6bec36..51af8d8df8 100644 --- a/install/ui/materialeditor.fbp +++ b/install/ui/materialeditor.fbp @@ -925,7 +925,7 @@ Resizable 1 - + wxTE_PROCESS_ENTER ; ; forward_declare 0 @@ -1184,7 +1184,7 @@ Resizable 1 - + wxTE_PROCESS_ENTER ; ; forward_declare 0 @@ -2169,7 +2169,7 @@ Resizable 1 - + wxTE_PROCESS_ENTER ; ; forward_declare 0 @@ -10405,7 +10405,7 @@ Resizable 1 - + wxTE_PROCESS_ENTER 0 diff --git a/install/ui/materialeditor.xrc b/install/ui/materialeditor.xrc index f0d232a454..2eae9ac9da 100644 --- a/install/ui/materialeditor.xrc +++ b/install/ui/materialeditor.xrc @@ -157,6 +157,7 @@ wxEXPAND 0 + @@ -198,6 +199,7 @@ wxEXPAND|wxLEFT 6 + @@ -381,6 +383,7 @@ wxALIGN_CENTER_VERTICAL 6 + @@ -1767,6 +1770,7 @@ 0 + diff --git a/radiant/ui/materials/MaterialPopulator.cpp b/radiant/ui/materials/MaterialPopulator.cpp index ea3d798e74..dab7cc200f 100644 --- a/radiant/ui/materials/MaterialPopulator.cpp +++ b/radiant/ui/materials/MaterialPopulator.cpp @@ -183,13 +183,19 @@ void MaterialPopulator::AddSingleMaterial(const wxutil::TreeModel::Ptr& model, c parentPath += !parentPath.empty() ? "/" : ""; parentPath += parts[i]; - parentItem = model->FindString(parentPath, _columns.fullName, parentItem); + auto existingItem = model->FindString(parentPath, _columns.fullName, parentItem); - if (!parentItem.IsOk()) + if (!existingItem.IsOk()) { // Insert this folder auto row = functor.insertFolder(parentPath, parts[i], parentItem, i == 0 && parts[i] == otherMaterialsFolder); row.SendItemAdded(); + + parentItem = row.getItem(); + } + else + { + parentItem = existingItem; } } diff --git a/radiant/ui/materials/editor/MaterialEditor.cpp b/radiant/ui/materials/editor/MaterialEditor.cpp index ceb13c3c13..6181ab89c0 100644 --- a/radiant/ui/materials/editor/MaterialEditor.cpp +++ b/radiant/ui/materials/editor/MaterialEditor.cpp @@ -275,6 +275,17 @@ void MaterialEditor::setupMaterialProperties() convertTextCtrlToMapExpressionEntry("MaterialLightFalloffMap"); convertTextCtrlToMapExpressionEntry("MaterialEditorImage"); + auto nameEntry = getControl("MaterialName"); + nameEntry->Bind(wxEVT_TEXT, [nameEntry, this](wxCommandEvent& ev) + { + if (_materialUpdateInProgress || !_material) return; + + GlobalMaterialManager().renameMaterial(_material->getName(), nameEntry->GetValue().ToStdString()); + auto item = _treeView->GetTreeModel()->FindString(_material->getName(), _treeView->Columns().fullName); + _treeView->EnsureVisible(item); + onMaterialChanged(); + }); + auto editorImage = getControl("MaterialEditorImage"); _materialBindings.emplace(std::make_shared>(editorImage->GetTextCtrl(), [](const MaterialPtr& material) @@ -1109,16 +1120,8 @@ bool MaterialEditor::isAllowedToChangeMaterial() return true; } -void MaterialEditor::_onMaterialSelectionChanged(wxDataViewEvent& ev) +void MaterialEditor::handleMaterialSelectionChange() { - // Check if the material has been modified and ask for save - if (!isAllowedToChangeMaterial()) - { - // Revert the selection and cancel the operation - _treeView->Select(_selectedMaterialItem); - return; - } - _selectedMaterialItem = _treeView->GetSelection(); _materialChanged.disconnect(); @@ -1141,6 +1144,19 @@ void MaterialEditor::_onMaterialSelectionChanged(wxDataViewEvent& ev) updateControlsFromMaterial(); } +void MaterialEditor::_onMaterialSelectionChanged(wxDataViewEvent& ev) +{ + // Check if the material has been modified and ask for save + if (!isAllowedToChangeMaterial()) + { + // Revert the selection and cancel the operation + _treeView->Select(_selectedMaterialItem); + return; + } + + handleMaterialSelectionChange(); +} + void MaterialEditor::_onSaveMaterial(wxCommandEvent& ev) { if (!_material) return; @@ -1159,7 +1175,9 @@ void MaterialEditor::_onNewMaterial(wxCommandEvent& ev) if (newItem.IsOk()) { _treeView->Select(newItem); + _treeView->EnsureVisible(newItem); updateMaterialTreeItem(); + handleMaterialSelectionChange(); } } @@ -1269,7 +1287,7 @@ void MaterialEditor::_onStageListItemActivated(wxDataViewEvent& ev) void MaterialEditor::updateMaterialControlSensitivity() { - getControl("MaterialEditorNewDefButton")->Enable(!_material || !_material->isModified()); + getControl("MaterialEditorNewDefButton")->Enable(true); getControl("MaterialEditorSaveDefButton")->Enable(_material && _material->isModified() && GlobalMaterialManager().materialCanBeModified(_material->getName())); @@ -1419,6 +1437,7 @@ void MaterialEditor::updateMaterialPropertiesFromMaterial() auto nameEntry = getControl("MaterialName"); nameEntry->Enable(_material != nullptr); nameEntry->SetValue(_material ? _material->getName() : ""); + updateMaterialNameControl(); getControl("MaterialEditorStageSettingsPanel")->Enable(_material != nullptr); @@ -2127,6 +2146,21 @@ void MaterialEditor::_onSortRequestChanged(wxCommandEvent& ev) onMaterialChanged(); } +void MaterialEditor::updateMaterialNameControl() +{ + if (!_material) return; + + auto nameControl = getControl("MaterialName"); + if (nameControl->GetValue() != _material->getName()) + { + nameControl->SetForegroundColour(wxColor(220, 0, 0)); + } + else + { + nameControl->SetForegroundColour(wxNullColour); + } +} + void MaterialEditor::updateMaterialTreeItem() { if (!_material) return; @@ -2161,6 +2195,7 @@ void MaterialEditor::updateMaterialTreeItem() void MaterialEditor::onMaterialChanged() { + updateMaterialNameControl(); updateMaterialTreeItem(); updateMaterialControlSensitivity(); updateSourceView(); diff --git a/radiant/ui/materials/editor/MaterialEditor.h b/radiant/ui/materials/editor/MaterialEditor.h index 5ce9d8173c..954fcfc5ab 100644 --- a/radiant/ui/materials/editor/MaterialEditor.h +++ b/radiant/ui/materials/editor/MaterialEditor.h @@ -145,6 +145,8 @@ class MaterialEditor : void updateMaterialControlSensitivity(); void updateSourceView(); void updateMaterialTreeItem(); + void updateMaterialNameControl(); + void handleMaterialSelectionChange(); bool isAllowedToChangeMaterial(); bool askUserAboutModifiedMaterial();