Skip to content

Commit

Permalink
refactor: extract common UI codes, including restore default button, …
Browse files Browse the repository at this point in the history
…and hovered tooltip formatting (doodlum#170)

* refactor: extract "reset default" UI button code

* refactor: extract hovered tooltip code into HoverTooltipWrapper

* refactor: safer HoverTooltipWrapper

* style: 🎨 apply clang-format changes

---------

Co-authored-by: Pentalimbed <[email protected]>
  • Loading branch information
Pentalimbed and Pentalimbed authored Feb 1, 2024
1 parent 9dcb5a1 commit eca469a
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 470 deletions.
34 changes: 3 additions & 31 deletions src/Features/DistantTreeLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ void DistantTreeLighting::DrawSettings()
{
if (ImGui::TreeNodeEx("Complex Tree LOD", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Checkbox("Enable Complex Tree LOD", (bool*)&settings.EnableComplexTreeLOD);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Enables advanced lighting simulation on tree LOD. "
"Requires DynDOLOD. "
"See https://dyndolod.info/ for more information. ");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::Spacing();
Expand All @@ -31,12 +27,8 @@ void DistantTreeLighting::DrawSettings()

if (ImGui::TreeNodeEx("Lights", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Checkbox("Enable Directional Light Fix", (bool*)&settings.EnableDirLightFix);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Fix for trees not being affected by sunlight scale.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::Spacing();
Expand All @@ -46,38 +38,18 @@ void DistantTreeLighting::DrawSettings()

if (ImGui::TreeNodeEx("Effects", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::SliderFloat("SSS Amount", &settings.SubsurfaceScatteringAmount, 0.0f, 1.0f);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Subsurface Scattering (SSS) amount. "
"Soft lighting controls how evenly lit an object is. "
"Back lighting illuminates the back face of an object. "
"Combined to model the transport of light through the surface. ");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::Spacing();
ImGui::Spacing();
ImGui::TreePop();
}

ImGui::Spacing();
ImGui::Spacing();

if (ImGui::Button("Restore Defaults", { -1, 0 })) {
DistantTreeLighting::GetSingleton()->RestoreDefaultSettings();
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
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::PopTextWrapPos();
ImGui::EndTooltip();
}
}

enum class DistantTreeShaderTechniques
Expand Down
12 changes: 2 additions & 10 deletions src/Features/DynamicCubemaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ void DynamicCubemaps::DrawSettings()
if (auto setting = RE::INISettingCollection::GetSingleton()->GetSetting(settingName); setting) {
ImGui::TableNextColumn();
ImGui::Checkbox(settingName.c_str(), &setting->data.b);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
//ImGui::Text(fmt::format(fmt::runtime("{} {0:x}"), settingName, &setting->data.b).c_str());
ImGui::Text(settingName.c_str());
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
}
}
Expand All @@ -28,13 +24,9 @@ void DynamicCubemaps::DrawSettings()
bool* setting = reinterpret_cast<bool*>(address);
ImGui::TableNextColumn();
ImGui::Checkbox(settingName.c_str(), setting);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(settingName.c_str());
//ImGui::Text(fmt::format(fmt::runtime("{} {0:x}"), settingName, address).c_str());
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
}
ImGui::EndTable();
Expand Down
84 changes: 13 additions & 71 deletions src/Features/ExtendedMaterials.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ExtendedMaterials.h"

#include "Util.h"

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
ExtendedMaterials::Settings,
EnableParallax,
Expand Down Expand Up @@ -30,15 +32,11 @@ void ExtendedMaterials::DrawSettings()
{
if (ImGui::TreeNodeEx("Complex Material", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Checkbox("Enable Complex Material", (bool*)&settings.EnableComplexMaterial);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Enables support for the Complex Material specification which makes use of the environment mask. "
"This includes parallax, as well as more realistic metals and specular reflections. "
"May lead to some warped textures on modded content which have an invalid alpha channel in their environment mask. ");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::Spacing();
Expand All @@ -48,79 +46,51 @@ void ExtendedMaterials::DrawSettings()

if (ImGui::TreeNodeEx("Contact Refinement Parallax Mapping", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Checkbox("Enable Parallax", (bool*)&settings.EnableParallax);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Enables parallax on standard meshes made for parallax.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

if (ImGui::Checkbox("Enable Terrain", (bool*)&settings.EnableTerrain)) {
if (settings.EnableTerrain) {
DataLoaded();
}
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Enables terrain parallax using the alpha channel of each landscape texture. "
"Therefore, all landscape textures must support parallax for this effect to work properly. ");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::Checkbox("Enable High Quality", (bool*)&settings.EnableHighQuality);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Doubles the sample count and approximates the intersection point using Parallax Occlusion Mapping. "
"Significantly improves the quality and removes aliasing. "
"TAA or the Skyrim Upscaler is recommended when using this option due to CRPM artifacts. ");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::Spacing();
ImGui::Spacing();
ImGui::SliderInt("Max Distance", (int*)&settings.MaxDistance, 0, 4096);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("The furthest distance from the camera which uses parallax.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::SliderFloat("CRPM Range", &settings.CRPMRange, 0.0f, 1.0f);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("The percentage of the max distance which uses Contact Refinement Parallax Mapping (CRPM).");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::SliderFloat("Blend Range", &settings.BlendRange, 0.0f, settings.CRPMRange);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"The range that parallax blends from Parallax Occlusion Mapping (POM) to bump mapping, and bump mapping to nothing. "
"This value should be set as low as possible due to the performance impact of blending POM and relief mapping. ");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::SliderFloat("Height", &settings.Height, 0, 0.2f);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("The range between the highest and lowest point a surface can be offset by.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::Spacing();
Expand All @@ -130,55 +100,27 @@ void ExtendedMaterials::DrawSettings()

if (ImGui::TreeNodeEx("Approximate Soft Shadows", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Checkbox("Enable Shadows", (bool*)&settings.EnableShadows);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Enables cheap soft shadows when using parallax. "
"This applies to all directional and point lights. ");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::Spacing();
ImGui::Spacing();
ImGui::TextWrapped("Modifying the shadow start and end fade can improve performance and hide obvious texture tiling.");
ImGui::SliderInt("Start Fade", (int*)&settings.ShadowsStartFade, 0, settings.ShadowsEndFade);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Distance shadows start to fade.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::SliderInt("End Fade", (int*)&settings.ShadowsEndFade, settings.ShadowsStartFade, 4096);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Distance shadows finish fading.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::TreePop();
}

ImGui::Spacing();
ImGui::Spacing();

if (ImGui::Button("Restore Defaults", { -1, 0 })) {
ExtendedMaterials::GetSingleton()->RestoreDefaultSettings();
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
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::PopTextWrapPos();
ImGui::EndTooltip();
}
}

void ExtendedMaterials::ModifyLighting(const RE::BSShader*, const uint32_t)
Expand Down
46 changes: 5 additions & 41 deletions src/Features/GrassCollision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,32 @@ void GrassCollision::DrawSettings()
{
if (ImGui::TreeNodeEx("Grass Collision", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Checkbox("Enable Grass Collision", (bool*)&settings.EnableGrassCollision);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Allows player collision to modify grass position.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::Spacing();
ImGui::SliderFloat("Radius Multiplier", &settings.RadiusMultiplier, 0.0f, 8.0f);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Distance from collision centres to apply collision.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::SliderFloat("Max Distance from Player", &settings.maxDistance, 0.0f, 1500.0f);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Distance from player to apply collision (NPCs). 0 to disable NPC collisions.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::SliderFloat("Displacement Multiplier", &settings.DisplacementMultiplier, 0.0f, 32.0f);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Strength of each collision on grass position.");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

if (ImGui::SliderInt("Calculation Frame Interval", (int*)&settings.frameInterval, 0, 30)) {
if (settings.frameInterval) // increment so mod math works (e.g., skip 1 frame means frame % 2).
settings.frameInterval++;
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("How many frames to skip before calculating positions again. 0 means calculate every frame (most smooth/costly).");
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}

ImGui::TreePop();
Expand All @@ -73,22 +53,6 @@ void GrassCollision::DrawSettings()
ImGui::Text(std::format("Total Collisions : {}", currentCollisionCount).c_str());
ImGui::TreePop();
}

ImGui::Spacing();
ImGui::Spacing();

if (ImGui::Button("Restore Defaults", { -1, 0 })) {
GrassCollision::GetSingleton()->RestoreDefaultSettings();
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
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::PopTextWrapPos();
ImGui::EndTooltip();
}
}

static bool GetShapeBound(RE::NiAVObject* a_node, RE::NiPoint3& centerPos, float& radius)
Expand Down
Loading

0 comments on commit eca469a

Please sign in to comment.