Skip to content

Commit

Permalink
#5565: WIP commit, working on "New Material" functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 28, 2021
1 parent e30d587 commit d989e42
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
8 changes: 4 additions & 4 deletions install/ui/materialeditor.fbp
Expand Up @@ -925,7 +925,7 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="style">wxTE_PROCESS_ENTER</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
Expand Down Expand Up @@ -1184,7 +1184,7 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="style">wxTE_PROCESS_ENTER</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
Expand Down Expand Up @@ -2169,7 +2169,7 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="style">wxTE_PROCESS_ENTER</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
Expand Down Expand Up @@ -10405,7 +10405,7 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="style">wxTE_PROCESS_ENTER</property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
Expand Down
4 changes: 4 additions & 0 deletions install/ui/materialeditor.xrc
Expand Up @@ -157,6 +157,7 @@
<flag>wxEXPAND</flag>
<border>0</border>
<object class="wxTextCtrl" name="MaterialName">
<style>wxTE_PROCESS_ENTER</style>
<value></value>
</object>
</object>
Expand Down Expand Up @@ -198,6 +199,7 @@
<flag>wxEXPAND|wxLEFT</flag>
<border>6</border>
<object class="wxTextCtrl" name="MaterialDescription">
<style>wxTE_PROCESS_ENTER</style>
<value></value>
</object>
</object>
Expand Down Expand Up @@ -381,6 +383,7 @@
<flag>wxALIGN_CENTER_VERTICAL</flag>
<border>6</border>
<object class="wxTextCtrl" name="MaterialEditorImage">
<style>wxTE_PROCESS_ENTER</style>
<value></value>
</object>
</object>
Expand Down Expand Up @@ -1767,6 +1770,7 @@
<flag></flag>
<border>0</border>
<object class="wxTextCtrl" name="MaterialStageImageMap">
<style>wxTE_PROCESS_ENTER</style>
<value></value>
</object>
</object>
Expand Down
10 changes: 8 additions & 2 deletions radiant/ui/materials/MaterialPopulator.cpp
Expand Up @@ -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;
}
}

Expand Down
55 changes: 45 additions & 10 deletions radiant/ui/materials/editor/MaterialEditor.cpp
Expand Up @@ -275,6 +275,17 @@ void MaterialEditor::setupMaterialProperties()
convertTextCtrlToMapExpressionEntry("MaterialLightFalloffMap");
convertTextCtrlToMapExpressionEntry("MaterialEditorImage");

auto nameEntry = getControl<wxTextCtrl>("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<MapExpressionEntry>("MaterialEditorImage");
_materialBindings.emplace(std::make_shared<ExpressionBinding<MaterialPtr>>(editorImage->GetTextCtrl(),
[](const MaterialPtr& material)
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -1159,7 +1175,9 @@ void MaterialEditor::_onNewMaterial(wxCommandEvent& ev)
if (newItem.IsOk())
{
_treeView->Select(newItem);
_treeView->EnsureVisible(newItem);
updateMaterialTreeItem();
handleMaterialSelectionChange();
}
}

Expand Down Expand Up @@ -1269,7 +1287,7 @@ void MaterialEditor::_onStageListItemActivated(wxDataViewEvent& ev)

void MaterialEditor::updateMaterialControlSensitivity()
{
getControl<wxButton>("MaterialEditorNewDefButton")->Enable(!_material || !_material->isModified());
getControl<wxButton>("MaterialEditorNewDefButton")->Enable(true);

getControl<wxButton>("MaterialEditorSaveDefButton")->Enable(_material && _material->isModified() &&
GlobalMaterialManager().materialCanBeModified(_material->getName()));
Expand Down Expand Up @@ -1419,6 +1437,7 @@ void MaterialEditor::updateMaterialPropertiesFromMaterial()
auto nameEntry = getControl<wxTextCtrl>("MaterialName");
nameEntry->Enable(_material != nullptr);
nameEntry->SetValue(_material ? _material->getName() : "");
updateMaterialNameControl();

getControl<wxPanel>("MaterialEditorStageSettingsPanel")->Enable(_material != nullptr);

Expand Down Expand Up @@ -2127,6 +2146,21 @@ void MaterialEditor::_onSortRequestChanged(wxCommandEvent& ev)
onMaterialChanged();
}

void MaterialEditor::updateMaterialNameControl()
{
if (!_material) return;

auto nameControl = getControl<wxTextCtrl>("MaterialName");
if (nameControl->GetValue() != _material->getName())
{
nameControl->SetForegroundColour(wxColor(220, 0, 0));
}
else
{
nameControl->SetForegroundColour(wxNullColour);
}
}

void MaterialEditor::updateMaterialTreeItem()
{
if (!_material) return;
Expand Down Expand Up @@ -2161,6 +2195,7 @@ void MaterialEditor::updateMaterialTreeItem()

void MaterialEditor::onMaterialChanged()
{
updateMaterialNameControl();
updateMaterialTreeItem();
updateMaterialControlSensitivity();
updateSourceView();
Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/materials/editor/MaterialEditor.h
Expand Up @@ -145,6 +145,8 @@ class MaterialEditor :
void updateMaterialControlSensitivity();
void updateSourceView();
void updateMaterialTreeItem();
void updateMaterialNameControl();
void handleMaterialSelectionChange();

bool isAllowedToChangeMaterial();
bool askUserAboutModifiedMaterial();
Expand Down

0 comments on commit d989e42

Please sign in to comment.