Skip to content

Commit

Permalink
#5532: Set material type on choice
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 12, 2021
1 parent 975ec22 commit 8521dbe
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/ishaders.h
Expand Up @@ -236,6 +236,9 @@ class Material
/// Surface Type (wood, stone, surfType15, ...)
virtual SurfaceType getSurfaceType() const = 0;

// Set the surface type of this material
virtual void setSurfaceType(SurfaceType type) = 0;

/// Get the deform type of this material
virtual DeformType getDeformType() const = 0;

Expand Down
13 changes: 13 additions & 0 deletions libs/materials/ParseLib.h
Expand Up @@ -39,6 +39,19 @@ inline std::string getStringForSurfaceType(Material::SurfaceType type)
return std::string();
}

inline Material::SurfaceType getSurfaceTypeForString(const std::string& surfaceTypeString)
{
for (const auto& pair : SurfaceTypeMapping)
{
if (surfaceTypeString == pair.first)
{
return pair.second;
}
}

return Material::SURFTYPE_DEFAULT;
}

constexpr std::pair<const char*, Material::SortRequest> PredefinedSortValues[]
{
{ "subview", Material::SORT_SUBVIEW },
Expand Down
10 changes: 10 additions & 0 deletions radiant/ui/materials/MaterialEditor.cpp
Expand Up @@ -155,6 +155,8 @@ void MaterialEditor::setupMaterialProperties()
typeDropdown->AppendString(pair.first);
}

typeDropdown->Bind(wxEVT_CHOICE, &MaterialEditor::_onMaterialTypeChoice, this);

auto* sortDropdown = getControl<wxComboBox>("MaterialSortValue");

sortDropdown->AppendString(""); // empty string for undefined
Expand Down Expand Up @@ -1084,4 +1086,12 @@ void MaterialEditor::updateStageControls()
}
}

void MaterialEditor::_onMaterialTypeChoice(wxCommandEvent& ev)
{
if (!_material) return;

auto selectedString = getControl<wxChoice>("MaterialType")->GetStringSelection();
_material->setSurfaceType(shaders::getSurfaceTypeForString(selectedString.ToStdString()));
}

}
1 change: 1 addition & 0 deletions radiant/ui/materials/MaterialEditor.h
Expand Up @@ -92,6 +92,7 @@ class MaterialEditor :

void _onTreeViewSelectionChanged(wxDataViewEvent& ev);
void _onStageListSelectionChanged(wxDataViewEvent& ev);
void _onMaterialTypeChoice(wxCommandEvent& ev);

// Shortcut
template<typename ObjectClass>
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/shaders/CShader.cpp
Expand Up @@ -185,6 +185,12 @@ Material::SurfaceType CShader::getSurfaceType() const
return _template->getSurfaceType();
}

void CShader::setSurfaceType(SurfaceType type)
{
ensureTemplateCopy();
_template->setSurfaceType(type);
}

Material::DeformType CShader::getDeformType() const
{
return _template->getDeformType();
Expand Down
1 change: 1 addition & 0 deletions radiantcore/shaders/CShader.h
Expand Up @@ -72,6 +72,7 @@ class CShader final :
ClampType getClampType() const override;
int getSurfaceFlags() const override;
SurfaceType getSurfaceType() const override;
void setSurfaceType(SurfaceType type) override;
DeformType getDeformType() const override;
IShaderExpressionPtr getDeformExpression(std::size_t index) override;
std::string getDeformDeclName() override;
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/shaders/ShaderTemplate.h
Expand Up @@ -207,6 +207,12 @@ class ShaderTemplate final
return _surfaceType;
}

void setSurfaceType(Material::SurfaceType type)
{
if (!_parsed) parseDefinition();
_surfaceType = type;
}

Material::DeformType getDeformType()
{
if (!_parsed) parseDefinition();
Expand Down

0 comments on commit 8521dbe

Please sign in to comment.