Skip to content

Commit

Permalink
#5532: Display the map expression used in a stage
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Feb 23, 2021
1 parent 7e45278 commit 137dc91
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
4 changes: 4 additions & 0 deletions include/ShaderLayer.h
@@ -1,6 +1,7 @@
#pragma once

#include "Texture.h"
#include "ishaderexpression.h"

#include <memory>
#include <vector>
Expand Down Expand Up @@ -270,6 +271,9 @@ class ShaderLayer
// the VFS path to it with the file extension removed.
// If this layer doesn't refer to a single image file, an empty string is returned
virtual std::string getMapImageFilename() = 0;

// The map expression used to generate/define the texture of this stage
virtual shaders::IMapExpression::Ptr getMapExpression() = 0;
};

/**
Expand Down
39 changes: 25 additions & 14 deletions radiant/ui/materials/MaterialEditor.cpp
Expand Up @@ -665,9 +665,13 @@ void MaterialEditor::updateStageBlendControls()
{
auto selectedStage = getSelectedStage();

auto blendType = getControl<wxChoice>("MaterialStageBlendType");
auto blendTypeSrc = getControl<wxChoice>("MaterialStageBlendTypeSrc");
auto blendTypeDest = getControl<wxChoice>("MaterialStageBlendTypeDest");

if (selectedStage)
{
getControl<wxChoice>("MaterialStageBlendType")->Enable();
blendType->Enable();
auto blendTypeStrings = selectedStage->getBlendFuncStrings();

switch (selectedStage->getType())
Expand All @@ -686,39 +690,39 @@ void MaterialEditor::updateStageBlendControls()
break;
};

getControl<wxChoice>("MaterialStageBlendTypeSrc")->Enable(!blendTypeStrings.second.empty());
getControl<wxChoice>("MaterialStageBlendTypeDest")->Enable(!blendTypeStrings.second.empty());
blendTypeSrc->Enable(!blendTypeStrings.second.empty());
blendTypeDest->Enable(!blendTypeStrings.second.empty());

if (blendTypeStrings.second.empty())
{
getControl<wxChoice>("MaterialStageBlendType")->SetStringSelection(blendTypeStrings.first);
blendType->SetStringSelection(blendTypeStrings.first);

getControl<wxChoice>("MaterialStageBlendTypeSrc")->SetStringSelection("");
getControl<wxChoice>("MaterialStageBlendTypeDest")->SetStringSelection("");
blendTypeSrc->SetStringSelection("");
blendTypeDest->SetStringSelection("");

// Get the actual src and dest blend types this shortcut is working with
for (const auto& pair : shaders::BlendTypeShortcuts)
{
if (blendTypeStrings.first == pair.first)
{
getControl<wxChoice>("MaterialStageBlendTypeSrc")->SetStringSelection(pair.second.first);
getControl<wxChoice>("MaterialStageBlendTypeDest")->SetStringSelection(pair.second.second);
blendTypeSrc->SetStringSelection(pair.second.first);
blendTypeDest->SetStringSelection(pair.second.second);
break;
}
}
}
else
{
getControl<wxChoice>("MaterialStageBlendType")->SetStringSelection("Custom");
getControl<wxChoice>("MaterialStageBlendTypeSrc")->SetStringSelection(blendTypeStrings.first);
getControl<wxChoice>("MaterialStageBlendTypeDest")->SetStringSelection(blendTypeStrings.second);
blendType->SetStringSelection("Custom");
blendTypeSrc->SetStringSelection(blendTypeStrings.first);
blendTypeDest->SetStringSelection(blendTypeStrings.second);
}
}
else
{
getControl<wxChoice>("MaterialStageBlendType")->Disable();
getControl<wxChoice>("MaterialStageBlendTypeSrc")->Disable();
getControl<wxChoice>("MaterialStageBlendTypeDest")->Disable();
blendType->Disable();
blendTypeSrc->Disable();
blendTypeDest->Disable();
}
}

Expand All @@ -742,6 +746,13 @@ void MaterialEditor::updateStageControls()

getControl<wxSpinCtrlDouble>("MaterialStageAlphaTestValue")->SetValue(selectedStage->getAlphaTest());
getControl<wxSpinCtrlDouble>("MaterialStagePrivatePolygonOffset")->SetValue(selectedStage->getPrivatePolygonOffset());

auto mapExpr = selectedStage->getMapExpression();
getControl<wxTextCtrl>("MaterialEditorStageMap")->SetValue(mapExpr ? mapExpr->getExpressionString() : "");
}
else
{
getControl<wxTextCtrl>("MaterialEditorStageMap")->SetValue("");
}
}

Expand Down
5 changes: 5 additions & 0 deletions radiantcore/shaders/Doom3ShaderLayer.cpp
Expand Up @@ -247,5 +247,10 @@ std::string Doom3ShaderLayer::getMapImageFilename()
return std::string();
}

IMapExpression::Ptr Doom3ShaderLayer::getMapExpression()
{
return std::dynamic_pointer_cast<IMapExpression>(_bindableTex);
}

}

2 changes: 2 additions & 0 deletions radiantcore/shaders/Doom3ShaderLayer.h
Expand Up @@ -514,6 +514,8 @@ class Doom3ShaderLayer
}

std::string getMapImageFilename() override;

shaders::IMapExpression::Ptr getMapExpression() override;
};

/**
Expand Down

0 comments on commit 137dc91

Please sign in to comment.