Draw low quality text for custom UI that is directly part of the game. (#434)

This commit is contained in:
Skyth (Asilkan)
2025-02-20 17:18:27 +03:00
committed by GitHub
parent 0afd01ff7e
commit ba522c0e42
11 changed files with 144 additions and 64 deletions
+1 -1
View File
@@ -763,7 +763,7 @@ void AchievementMenu::Open()
return std::get<1>(a) > std::get<1>(b);
});
ButtonGuide::Open(Button("Common_Back", FLT_MAX, EButtonIcon::B));
ButtonGuide::Open(Button("Common_Back", FLT_MAX, EButtonIcon::B, EFontQuality::Low));
ResetSelection();
Game_PlaySound("sys_actstg_pausewinopen");
@@ -183,6 +183,9 @@ void AchievementOverlay::Draw()
IM_COL32(255, 255, 255, 255) // col
);
// Use low quality text.
SetShaderModifier(IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT);
// Draw header text.
DrawTextWithShadow
(
@@ -208,6 +211,9 @@ void AchievementOverlay::Draw()
1.0f, // radius
IM_COL32(0, 0, 0, 255) // shadowColour
);
// Reset low quality text shader modifier.
SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE);
}
else
{
+11 -16
View File
@@ -14,7 +14,6 @@
constexpr float DEFAULT_SIDE_MARGINS = 379;
ImFont* g_fntNewRodin;
ImFont* g_fntNewRodinLQ;
std::unique_ptr<GuestTexture> g_upControllerIcons;
std::unique_ptr<GuestTexture> g_upKBMIcons;
@@ -144,21 +143,13 @@ std::tuple<std::tuple<ImVec2, ImVec2>, GuestTexture*> GetButtonIcon(EButtonIcon
return std::make_tuple(btn, texture);
}
ImFont* GetFont(EFontQuality fontQuality)
{
return fontQuality == EFontQuality::Low
? g_fntNewRodinLQ
: g_fntNewRodin;
}
static void DrawGuide(float* offset, ImVec2 regionMin, ImVec2 regionMax, EButtonIcon icon,
EButtonAlignment alignment, ImVec2 iconMin, ImVec2 iconMax, EFontQuality fontQuality,
float textWidth, float maxTextWidth, float textScale, float fontSize, const char* text)
{
auto drawList = ImGui::GetBackgroundDrawList();
auto iconWidth = Scale(g_iconWidths[icon]);
auto font = GetFont(fontQuality);
auto textMarginY = regionMin.y + Scale(8.89f);
auto textMarginY = regionMin.y + Scale(9.0f);
ImVec2 textPos;
@@ -206,11 +197,17 @@ static void DrawGuide(float* offset, ImVec2 regionMin, ImVec2 regionMax, EButton
SetScale({ textScale, 1.0f });
SetOrigin(textPos);
DrawTextWithOutline(font, fontSize, textPos, IM_COL32_WHITE, text, 4, IM_COL32_BLACK);
// Add extra luminance to low quality text.
if (fontQuality == EFontQuality::Low)
drawList->AddText(font, fontSize, textPos, IM_COL32(255, 255, 255, 127), text);
SetShaderModifier(IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT);
DrawTextWithOutline(g_fntNewRodin, fontSize, textPos, IM_COL32_WHITE, text, 4, IM_COL32_BLACK);
if (fontQuality == EFontQuality::Low)
{
// Add extra luminance to low quality text.
drawList->AddText(g_fntNewRodin, fontSize, textPos, IM_COL32(255, 255, 255, 127), text);
SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE);
}
SetScale({ 1.0f, 1.0f });
SetOrigin({ 0.0f, 0.0f });
@@ -221,8 +218,6 @@ void ButtonGuide::Init()
auto& io = ImGui::GetIO();
g_fntNewRodin = ImFontAtlasSnapshot::GetFont("FOT-NewRodinPro-M.otf");
g_fntNewRodinLQ = ImFontAtlasSnapshot::GetFont("FOT-NewRodinPro-M.otf");
g_upControllerIcons = LOAD_ZSTD_TEXTURE(g_controller);
g_upKBMIcons = LOAD_ZSTD_TEXTURE(g_kbm);
}
+2 -2
View File
@@ -55,8 +55,8 @@ public:
Button(std::string name, float maxWidth, EButtonIcon icon, bool* visibility)
: Name(name), MaxWidth(maxWidth), Icon(icon), Visibility(visibility) {}
Button(std::string name, float maxWidth, EButtonIcon icon)
: Name(name), MaxWidth(maxWidth), Icon(icon) {}
Button(std::string name, float maxWidth, EButtonIcon icon, EFontQuality fontQuality = EFontQuality::High)
: Name(name), MaxWidth(maxWidth), Icon(icon), FontQuality(fontQuality) {}
};
class ButtonGuide
+3
View File
@@ -45,6 +45,9 @@ void ResetGradient()
void SetShaderModifier(uint32_t shaderModifier)
{
if (shaderModifier == IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT && Config::DisableLowResolutionFontOnCustomUI)
shaderModifier = IMGUI_SHADER_MODIFIER_NONE;
auto callbackData = AddImGuiCallback(ImGuiCallback::SetShaderModifier);
callbackData->setShaderModifier.shaderModifier = shaderModifier;
}
+34 -6
View File
@@ -223,6 +223,10 @@ void DrawButton(int rowIndex, float yOffset, float width, float height, std::str
auto fontSize = Scale(28);
auto textSize = g_fntSeurat->CalcTextSizeA(fontSize, FLT_MAX, 0, text.c_str());
// Show low quality text in-game.
if (App::s_isInit)
SetShaderModifier(IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT);
DrawTextWithShadow
(
g_fntSeurat,
@@ -231,6 +235,10 @@ void DrawButton(int rowIndex, float yOffset, float width, float height, std::str
isSelected ? IM_COL32(255, 128, 0, 255) : IM_COL32(255, 255, 255, 255),
text.c_str()
);
// Reset the shader modifier.
if (App::s_isInit)
SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE);
}
void DrawNextButtonGuide(bool isController, bool isKeyboard)
@@ -241,11 +249,16 @@ void DrawNextButtonGuide(bool isController, bool isKeyboard)
? EButtonIcon::Enter
: EButtonIcon::LMB;
// Always show controller prompt in-game.
if (App::s_isInit)
icon = EButtonIcon::A;
auto fontQuality = EFontQuality::High;
ButtonGuide::Open(Button("Common_Next", FLT_MAX, icon));
// Always show controller prompt and low quality text in-game.
if (App::s_isInit)
{
icon = EButtonIcon::A;
fontQuality = EFontQuality::Low;
}
ButtonGuide::Open(Button("Common_Next", FLT_MAX, icon, fontQuality));
}
static void ResetSelection()
@@ -338,6 +351,10 @@ void MessageWindow::Draw()
if (DrawContainer(g_appearTime, centre, { textSize.x / 2 + textMarginX, textSize.y / 2 + textMarginY }, !g_isControlsVisible))
{
// Use low quality text when the game is booted to not clash with existing UI.
if (App::s_isInit)
SetShaderModifier(IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT);
DrawRubyAnnotatedText
(
g_fntSeurat,
@@ -359,6 +376,10 @@ void MessageWindow::Draw()
true
);
// Reset the shader modifier.
if (App::s_isInit)
SetShaderModifier(IMGUI_SHADER_MODIFIER_LOW_QUALITY_TEXT);
drawList->PopClipRect();
if (g_buttons.size())
@@ -423,10 +444,17 @@ void MessageWindow::Draw()
backIcon = EButtonIcon::Escape;
}
auto fontQuality = EFontQuality::High;
if (App::s_isInit)
{
// Show low quality text in-game.
fontQuality = EFontQuality::Low;
}
std::array<Button, 2> buttons =
{
Button("Common_Select", 115.0f, selectIcon),
Button("Common_Back", FLT_MAX, backIcon),
Button("Common_Select", 115.0f, selectIcon, fontQuality),
Button("Common_Back", FLT_MAX, backIcon, fontQuality),
};
ButtonGuide::Open(buttons);