Skip to content

Commit

Permalink
feat: add core feature support (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlayaN authored Oct 21, 2024
1 parent facfb2a commit 0215f5a
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 43 deletions.
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ if(AUTO_PLUGIN_DEPLOYMENT OR AIO_ZIP_TO_DIST)
COMMAND ${CMAKE_COMMAND} -E copy_directory ${FEATURE_PATHS} "${AIO_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> "${AIO_DIR}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> "${AIO_DIR}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E remove "${AIO_DIR}/CORE"
)

add_custom_command(
Expand Down Expand Up @@ -209,17 +210,24 @@ endif()
# Zip base CommunityShaders and all addons as their own 7z in dist folder
if(ZIP_TO_DIST)
set(ZIP_DIR "${CMAKE_CURRENT_BINARY_DIR}/zip")
message("Copying base CommunityShader into ${ZIP_DIR}.")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory "${ZIP_DIR}" ${CMAKE_SOURCE_DIR}/dist
COMMAND ${CMAKE_COMMAND} -E make_directory "${ZIP_DIR}/SKSE/Plugins" ${CMAKE_SOURCE_DIR}/dist
)

message("Copying base CommunityShader into ${ZIP_DIR}.")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/package "${ZIP_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> "${ZIP_DIR}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> "${ZIP_DIR}/SKSE/Plugins/"
)
foreach(FEATURE_PATH ${FEATURE_PATHS})
if (EXISTS "${FEATURE_PATH}/CORE")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${FEATURE_PATH} "${ZIP_DIR}"
)
endif()
endforeach()
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove "${ZIP_DIR}/CORE"
)

set(TARGET_ZIP "${PROJECT_NAME}-${UTC_NOW}.7z")
message("Zipping ${ZIP_DIR} to ${CMAKE_SOURCE_DIR}/dist/${TARGET_ZIP}")
Expand All @@ -229,6 +237,9 @@ if(ZIP_TO_DIST)
)

foreach(FEATURE_PATH ${FEATURE_PATHS})
if (EXISTS "${FEATURE_PATH}/CORE")
continue()
endif()
get_filename_component(FEATURE ${FEATURE_PATH} NAME)
message("Zipping ${FEATURE_PATH} to ${CMAKE_SOURCE_DIR}/dist/${FEATURE}-${UTC_NOW}.7z")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ If you want an example CMakeUserPreset to start off with you can copy the `CMake
#### ZIP_TO_DIST
* This option is default `"ON"`
* Make sure `"ZIP_TO_DIST"` is set to `"ON"` in `CMakeUserPresets.json`
* This will create a zip for each feature and one for the base Community shaders in /dist containing
* This will create a zip for each feature and one for the base Community shaders in /dist
* If having a file with name `CORE` in the root of the features folder it will instead be merged into the core zip
#### TRACY_SUPPORT
* This option is default `"OFF"`
* This will enable tracy support, might need to delete build folder when this option is changed
Expand Down
Empty file added features/Dynamic Cubemaps/CORE
Empty file.
Empty file.
Empty file added features/Frame Generation/CORE
Empty file.
8 changes: 8 additions & 0 deletions src/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ struct Feature
*/
virtual bool SupportsVR() { return false; }

/**
* Whether the feature is a CORE feature
* This will place it under "Core Features" in UI
* Also need to create a file named "CORE" in the root of the feature folder
* if it should be merged into main cs zip file
*/
virtual bool IsCore() const { return false; }

virtual void SetupResources() {}
virtual void Reset() {}

Expand Down
1 change: 1 addition & 0 deletions src/Features/DynamicCubemaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@ struct DynamicCubemaps : Feature
void Irradiance(bool a_reflections);

virtual bool SupportsVR() override { return true; };
virtual bool IsCore() const override { return true; };
};
1 change: 1 addition & 0 deletions src/Features/ExtendedMaterials.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ struct ExtendedMaterials : Feature
virtual void RestoreDefaultSettings() override;

virtual bool SupportsVR() override { return true; };
virtual bool IsCore() const override { return true; };
};
99 changes: 61 additions & 38 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void Menu::SetupImGuiStyle() const
colors[ImGuiCol_TextDisabled] = textDisabled;

colors[ImGuiCol_FrameBg] = themeSettings.Palette.Background;
colors[ImGuiCol_FrameBgHovered] = colors[ImGuiCol_FrameBg];
colors[ImGuiCol_FrameBgHovered] = headerHovered;
colors[ImGuiCol_FrameBgActive] = colors[ImGuiCol_FrameBg];

colors[ImGuiCol_DockingEmptyBg] = themeSettings.Palette.Border;
Expand Down Expand Up @@ -424,49 +424,60 @@ void Menu::DrawSettings()
bool hasFailedMessage = !feat->failedLoadedMessage.empty();
auto& themeSettings = Menu::GetSingleton()->settings.Theme;

ImVec4 textColor;
if (ImGui::BeginTable("##FeatureButtons", 2, ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableNextColumn();

// Determine the text color based on the state
if (isDisabled) {
textColor = themeSettings.StatusPalette.Disable;
} else if (hasFailedMessage) {
textColor = themeSettings.StatusPalette.Error;
} else {
textColor = ImGui::GetStyleColorVec4(ImGuiCol_Text);
}
ImGui::PushStyleColor(ImGuiCol_Text, textColor);
ImVec4 textColor;

if (ImGui::Button(isDisabled ? "Enable at Boot" : "Disable at Boot", { -1, 0 })) {
bool newState = feat->ToggleAtBootSetting();
logger::info("{}: {} at boot.", featureName, newState ? "Enabled" : "Disabled");
}
// Determine the text color based on the state
if (isDisabled) {
textColor = themeSettings.StatusPalette.Disable;
} else if (hasFailedMessage) {
textColor = themeSettings.StatusPalette.Error;
} else {
textColor = ImGui::GetStyleColorVec4(ImGuiCol_Text);
}
ImGui::PushStyleColor(ImGuiCol_Text, textColor);

if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Current State: %s\n"
"%s the feature settings at boot. "
"Restart will be required to reenable. "
"This is the same as deleting the ini file. "
"This should remove any performance impact for the feature.",
isDisabled ? "Disabled" : "Enabled",
isDisabled ? "Enable" : "Disable");
}
if (ImGui::Button(isDisabled ? "Enable at Boot" : "Disable at Boot", { -1, 0 })) {
bool newState = feat->ToggleAtBootSetting();
logger::info("{}: {} at boot.", featureName, newState ? "Enabled" : "Disabled");
}

ImGui::PopStyleColor();
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Current State: %s\n"
"%s the feature settings at boot. "
"Restart will be required to reenable. "
"This is the same as deleting the ini file. "
"This should remove any performance impact for the feature.",
isDisabled ? "Disabled" : "Enabled",
isDisabled ? "Enable" : "Disable");
}

ImGui::PopStyleColor();

ImGui::TableNextColumn();

if (!isDisabled && isLoaded) {
if (ImGui::Button("Restore Defaults", { -1, 0 })) {
feat->RestoreDefaultSettings();
}
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Restores the feature's settings back to their default values. "
"You will still need to Save Settings to make these changes permanent.");
}
}

ImGui::EndTable();
}

if (hasFailedMessage) {
ImGui::TextColored(themeSettings.StatusPalette.Error, feat->failedLoadedMessage.c_str());
}

if (!isDisabled && isLoaded) {
if (ImGui::Button("Restore Defaults", { -1, 0 })) {
feat->RestoreDefaultSettings();
}
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Restores the feature's settings back to their default values. "
"You will still need to Save Settings to make these changes permanent.");
}
if (ImGui::BeginChild("##FeatureConfigFrame", { 0, 0 }, true)) {
feat->DrawSettings();
}
Expand All @@ -477,17 +488,29 @@ void Menu::DrawSettings()

auto& featureList = Feature::GetFeatureList();
auto sortedFeatureList{ featureList }; // need a copy so the load order is not lost
std::sort(sortedFeatureList.begin(), sortedFeatureList.end(), [](Feature* a, Feature* b) {
std::ranges::sort(sortedFeatureList, [](Feature* a, Feature* b) {
return a->GetName() < b->GetName();
});

auto menuList = std::vector<MenuFuncInfo>{
BuiltInMenu{ "General", [&]() { DrawGeneralSettings(); } },
BuiltInMenu{ "Advanced", [&]() { DrawAdvancedSettings(); } },
BuiltInMenu{ "Display", [&]() { DrawDisplaySettings(); } },
"Features"s
BuiltInMenu{ "Display", [&]() { DrawDisplaySettings(); } }
};
std::ranges::copy(sortedFeatureList, std::back_inserter(menuList));

menuList.push_back("Core Features"s);
std::ranges::copy(
sortedFeatureList | std::ranges::views::filter([](Feature* feat) {
return feat->IsCore();
}),
std::back_inserter(menuList));

menuList.push_back("Features"s);
std::ranges::copy(
sortedFeatureList | std::ranges::views::filter([](Feature* feat) {
return !feat->IsCore();
}),
std::back_inserter(menuList));

ImGui::TableNextColumn();
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
Expand Down

0 comments on commit 0215f5a

Please sign in to comment.