Draw config options manually instead of looping through them.

This commit is contained in:
Skyth 2024-11-15 19:14:23 +03:00
parent 639206f5de
commit 8a11917ce5

View file

@ -292,7 +292,8 @@ static void DrawCategories()
drawList->PushClipRect({ clipRectMin.x, clipRectMin.y + gridSize * 6.0f }, clipRectMax); drawList->PushClipRect({ clipRectMin.x, clipRectMin.y + gridSize * 6.0f }, clipRectMax);
} }
static void DrawConfigOptions() template<typename T, bool isMenuOption = true>
static void DrawConfigOption(int32_t rowIndex, const ConfigDef<T, isMenuOption>& config)
{ {
auto drawList = ImGui::GetForegroundDrawList(); auto drawList = ImGui::GetForegroundDrawList();
auto clipRectMin = drawList->GetClipRectMin(); auto clipRectMin = drawList->GetClipRectMin();
@ -307,24 +308,18 @@ static void DrawConfigOptions()
float optionPadding = gridSize * 0.5f; float optionPadding = gridSize * 0.5f;
float valueWidth = gridSize * 24.0f; float valueWidth = gridSize * 24.0f;
float valueHeight = gridSize * 3.0f; float valueHeight = gridSize * 3.0f;
int32_t currentRow = 0;
for (auto& config : Config::Definitions)
{
if (_stricmp(config->GetSection().data(), CATEGORIES[g_categoryIndex]) != 0)
continue;
// Left side // Left side
ImVec2 min = { clipRectMin.x, clipRectMin.y + (optionHeight + optionPadding) * currentRow }; ImVec2 min = { clipRectMin.x, clipRectMin.y + (optionHeight + optionPadding) * rowIndex };
ImVec2 max = { min.x + optionWidth, min.y + optionHeight }; ImVec2 max = { min.x + optionWidth, min.y + optionHeight };
if (ImGui::IsMouseHoveringRect(min, max, false)) if (ImGui::IsMouseHoveringRect(min, max, false))
drawList->AddRectFilledMultiColor(min, max, COLOR0, COLOR0, COLOR1, COLOR1); drawList->AddRectFilledMultiColor(min, max, COLOR0, COLOR0, COLOR1, COLOR1);
float size = Scale(26.0f); float size = Scale(26.0f);
auto textSize = g_seuratFont->CalcTextSizeA(size, FLT_MAX, 0.0f, config->GetName().data()); auto textSize = g_seuratFont->CalcTextSizeA(size, FLT_MAX, 0.0f, config.Name.c_str());
drawList->AddText(g_seuratFont, size, { min.x + gridSize, min.y + (optionHeight - textSize.y) / 2.0f }, IM_COL32_WHITE, config->GetName().data()); drawList->AddText(g_seuratFont, size, { min.x + gridSize, min.y + (optionHeight - textSize.y) / 2.0f }, IM_COL32_WHITE, config.GetName().data());
// Right side // Right side
min = { max.x + (clipRectMax.x - max.x - valueWidth) / 2.0f, min.y + (optionHeight - valueHeight) / 2.0f }; min = { max.x + (clipRectMax.x - max.x - valueWidth) / 2.0f, min.y + (optionHeight - valueHeight) / 2.0f };
@ -338,7 +333,7 @@ static void DrawConfigOptions()
SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE); SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE);
auto valueText = config->ToString(); auto valueText = config.ToString();
std::transform(valueText.begin(), valueText.end(), valueText.begin(), toupper); std::transform(valueText.begin(), valueText.end(), valueText.begin(), toupper);
size = Scale(20.0f); size = Scale(20.0f);
@ -349,7 +344,7 @@ static void DrawConfigOptions()
SetGradient( SetGradient(
min, min,
{min.x + textSize.x, min.y + textSize.y}, { min.x + textSize.x, min.y + textSize.y },
IM_COL32(192, 255, 0, 255), IM_COL32(192, 255, 0, 255),
IM_COL32(128, 170, 0, 255) IM_COL32(128, 170, 0, 255)
); );
@ -364,8 +359,55 @@ static void DrawConfigOptions()
IM_COL32_BLACK); IM_COL32_BLACK);
ResetGradient(); ResetGradient();
}
++currentRow; static void DrawConfigOptions()
{
int32_t rowIndex = 0;
// TODO: Don't use raw numbers here!
switch (g_categoryIndex)
{
case 0: // SYSTEM
DrawConfigOption(rowIndex++, Config::Language);
DrawConfigOption(rowIndex++, Config::Hints);
DrawConfigOption(rowIndex++, Config::ControlTutorial);
DrawConfigOption(rowIndex++, Config::ScoreBehaviour);
DrawConfigOption(rowIndex++, Config::UnleashOutOfControlDrain);
DrawConfigOption(rowIndex++, Config::WerehogHubTransformVideo);
DrawConfigOption(rowIndex++, Config::LogoSkip);
break;
case 1: // CONTROLS
DrawConfigOption(rowIndex++, Config::CameraXInvert);
DrawConfigOption(rowIndex++, Config::CameraYInvert);
DrawConfigOption(rowIndex++, Config::XButtonHoming);
DrawConfigOption(rowIndex++, Config::UnleashCancel);
break;
case 2: // AUDIO
DrawConfigOption(rowIndex++, Config::MusicVolume);
DrawConfigOption(rowIndex++, Config::SEVolume);
DrawConfigOption(rowIndex++, Config::VoiceLanguage);
DrawConfigOption(rowIndex++, Config::Subtitles);
DrawConfigOption(rowIndex++, Config::WerehogBattleMusic);
break;
case 3: // VIDEO
DrawConfigOption(rowIndex++, Config::WindowWidth);
DrawConfigOption(rowIndex++, Config::WindowHeight);
DrawConfigOption(rowIndex++, Config::ResolutionScale);
DrawConfigOption(rowIndex++, Config::Fullscreen);
DrawConfigOption(rowIndex++, Config::VSync);
DrawConfigOption(rowIndex++, Config::TripleBuffering);
DrawConfigOption(rowIndex++, Config::FPS);
DrawConfigOption(rowIndex++, Config::Brightness);
DrawConfigOption(rowIndex++, Config::MSAA);
DrawConfigOption(rowIndex++, Config::ShadowResolution);
DrawConfigOption(rowIndex++, Config::GITextureFiltering);
DrawConfigOption(rowIndex++, Config::AlphaToCoverage);
DrawConfigOption(rowIndex++, Config::MotionBlur);
DrawConfigOption(rowIndex++, Config::Xbox360ColourCorrection);
DrawConfigOption(rowIndex++, Config::MovieScaleMode);
DrawConfigOption(rowIndex++, Config::UIScaleMode);
break;
} }
} }