Skip to content

Commit

Permalink
wzscriptdebug: Add Shadow Cascades option
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 31, 2023
1 parent baec7f9 commit efca68c
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion src/wzscriptdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,9 @@ class WzGraphicsPanel : public W_FORM
auto shadowFilterDropdownWidget = panel->makeShadowFilterSizeDropdown(4, shadowsLabel);
panel->makeShadowMapResolutionDropdown(4, shadowFilterDropdownWidget);

auto shadowModeDropdownWidget = panel->makeShadowModeDropdown(5);
panel->makeShadowCascadesDropdown(5, shadowsLabel);

auto shadowModeDropdownWidget = panel->makeShadowModeDropdown(6);

return panel;
}
Expand Down Expand Up @@ -1241,6 +1243,79 @@ class WzGraphicsPanel : public W_FORM
return dropdown;
}

std::shared_ptr<DropdownWidget> makeShadowCascadesDropdown(int row, const std::shared_ptr<WIDGET>& previousButton = nullptr)
{
int previousButtonRight = (previousButton) ? previousButton->x() + previousButton->width() : 0;

std::vector<std::tuple<WzString, uint32_t>> dropDownChoices = {
{WzString::fromUtf8("Medium (2)"), 2},
{WzString::fromUtf8("Highest (3)"), 3}
};

// If current value is not one of the presets in dropDownChoices, add a "Custom" entry
size_t currentSettingIdx = 0;
uint32_t currValue = pie_getShadowCascades();
auto it = std::find_if(dropDownChoices.begin(), dropDownChoices.end(), [currValue](const std::tuple<WzString, uint32_t>& item) -> bool {
return std::get<1>(item) == currValue;
});
if (it != dropDownChoices.end())
{
currentSettingIdx = it - dropDownChoices.begin();
}
else
{
dropDownChoices.push_back({WzString::fromUtf8(astringf("(Custom: %u)", currValue)), currValue});
currentSettingIdx = dropDownChoices.size() - 1;
}

int yPos = (row * (TAB_BUTTONS_HEIGHT + ACTION_BUTTON_ROW_SPACING));

auto contextLabel = std::make_shared<W_LABEL>();
contextLabel->setFont(font_regular, WZCOL_FORM_TEXT);
contextLabel->setString("Cascades:");
contextLabel->setGeometry((previousButtonRight > 0) ? previousButtonRight + ACTION_BUTTON_SPACING : 0, yPos, contextLabel->getMaxLineWidth() + 10, TAB_BUTTONS_HEIGHT);
contextLabel->setCacheNeverExpires(true);
attach(contextLabel);

auto dropdown = std::make_shared<DropdownWidget>();
dropdown->setListHeight(TAB_BUTTONS_HEIGHT * std::min<uint32_t>(5, dropDownChoices.size()));
attach(dropdown);
for (const auto& option : dropDownChoices)
{
WzString buttonLabel = std::get<0>(option);
auto button = makeDebugButton(buttonLabel.toUtf8().c_str());
bool supportedCascadeValue = pie_supportsShadowMapping().value_or(false);
if (!supportedCascadeValue)
{
button->setState(WBUT_DISABLE);
}
dropdown->addItem(button);
}

dropdown->setSelectedIndex(currentSettingIdx);

dropdown->setCanChange([dropDownChoices](DropdownWidget &widget, size_t newIndex, std::shared_ptr<WIDGET> newSelectedWidget) -> bool {
ASSERT_OR_RETURN(false, newIndex < dropDownChoices.size(), "Invalid index");
auto newCascadesCount = std::get<1>(dropDownChoices.at(newIndex));
if (!pie_supportsShadowMapping().value_or(false))
{
return false;
}
if (!pie_setShadowCascades(newCascadesCount))
{
debug(LOG_ERROR, "Failed to set shadow cascades: %" PRIu32, newCascadesCount);
return false;
}
// Possible Future TODO: could persist to config (if this proves useful beyond debugging and testing)
return true;
});

int contextDropdownX0 = contextLabel->x() + contextLabel->width();
dropdown->setGeometry(contextDropdownX0, yPos, dropdown->idealWidth() + ACTION_BUTTON_SPACING, TAB_BUTTONS_HEIGHT);

return dropdown;
}

std::shared_ptr<DropdownWidget> makeShadowMapResolutionDropdown(int row, const std::shared_ptr<WIDGET>& previousButton = nullptr)
{
int previousButtonRight = (previousButton) ? previousButton->x() + previousButton->width() : 0;
Expand Down

0 comments on commit efca68c

Please sign in to comment.