Skip to content

Commit

Permalink
feat(hud): a min alpha setting to go with the max alpha
Browse files Browse the repository at this point in the history
You can now pin the HUD alpha levels between above 0 and below 1
if you like an always-faintly-visible fainter HUD.

This in theory fixes #113, which asks for a min alpha setting.
  • Loading branch information
ceejbot committed Jan 18, 2024
1 parent c9c4ef5 commit b4fd72a
Show file tree
Hide file tree
Showing 16 changed files with 682 additions and 648 deletions.
Binary file modified installer/core/Interface/Translations/SoulsyHUD_czech.txt
Binary file not shown.
Binary file modified installer/core/Interface/Translations/SoulsyHUD_english.txt
Binary file not shown.
Binary file modified installer/core/Interface/Translations/SoulsyHUD_french.txt
Binary file not shown.
Binary file modified installer/core/Interface/Translations/SoulsyHUD_german.txt
Binary file not shown.
Binary file modified installer/core/Interface/Translations/SoulsyHUD_italian.txt
Binary file not shown.
Binary file modified installer/core/Interface/Translations/SoulsyHUD_japanese.txt
Binary file not shown.
Binary file modified installer/core/Interface/Translations/SoulsyHUD_polish.txt
Binary file not shown.
Binary file modified installer/core/Interface/Translations/SoulsyHUD_russian.txt
Binary file not shown.
Binary file modified installer/core/Interface/Translations/SoulsyHUD_spanish.txt
Binary file not shown.
1,291 changes: 652 additions & 639 deletions installer/core/mcm/config/SoulsyHUD/config.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions installer/core/mcm/config/SoulsyHUD/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ uLongPressMillis = 1250
bAutoFade = 1
uFadeTime = 2000
fMaxAlpha = 1.0
fMinAlpha = 0.0
uLongPressTime = 1000
uControllerKind = 0
bCyclingSlowsTime = 0
Expand Down
1 change: 1 addition & 0 deletions src/controller/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl Controller {
}

setMaxAlpha(settings.max_alpha());
setMinAlpha(settings.min_alpha());

if !settings.autofade() {
if self.cycles.hud_visible() {
Expand Down
11 changes: 11 additions & 0 deletions src/controller/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ pub struct UserSettings {
fade_time: u32,
/// Max alpha: the most transparent the HUD goes.
max_alpha: f32,
/// Min alpha: the least transparent the HUD gets.
min_alpha: f32,

/// Whether to slow down time when cycling
cycling_slows_time: bool,
Expand Down Expand Up @@ -161,6 +163,7 @@ impl Default for UserSettings {
long_press_ms: 1250, // in milliseconds
autofade: true,
max_alpha: 1.0,
min_alpha: 0.0,
fade_time: 2000, // in milliseconds
controller_kind: 0, // PS5
cycling_slows_time: false,
Expand Down Expand Up @@ -261,6 +264,7 @@ impl UserSettings {
self.autofade = read_from_ini(self.autofade, "bAutoFade", options);
self.fade_time = u32::clamp(read_from_ini(self.fade_time, "uFadeTime", options), 0, 2500);
self.max_alpha = read_from_ini(self.max_alpha, "fMaxAlpha", options);
self.min_alpha = read_from_ini(self.min_alpha, "fMinAlpha", options);

self.controller_kind = u32::clamp(
read_from_ini(self.controller_kind, "uControllerKind", options),
Expand Down Expand Up @@ -436,6 +440,9 @@ impl UserSettings {
pub fn max_alpha(&self) -> f32 {
self.max_alpha
}
pub fn min_alpha(&self) -> f32 {
self.min_alpha
}
pub fn controller_kind(&self) -> u32 {
u32::clamp(self.controller_kind, 0, 2)
}
Expand Down Expand Up @@ -663,6 +670,8 @@ impl std::fmt::Display for UserSettings {
long_press_ms: {} ms
autofade: {}
fade_time: {} ms
max alpha: {}
min alpha: {}
controller_kind: {}
cycling_slows_time: {}
slow_time_factor: {} %
Expand Down Expand Up @@ -696,6 +705,8 @@ impl std::fmt::Display for UserSettings {
self.long_press_ms,
self.autofade,
self.fade_time,
self.max_alpha,
self.min_alpha,
self.controller_kind,
self.cycling_slows_time,
self.slow_time_factor,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ pub mod plugin {
fn startAlphaTransition(fade_in: bool, alpha: f32);
/// Set the max alpha value the HUD is allowed to reach. From user settings.
fn setMaxAlpha(max: f32);
/// Set the min alpha value the HUD is allowed to reach. From user settings.
fn setMinAlpha(max: f32);
}

// A verbose shim between Rust and the PlayerCharacter type.
Expand Down
23 changes: 14 additions & 9 deletions src/renderer/ui_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace ui
auto gHudAlpha = 0.0f; // this is the current alpha
auto gGoalAlpha = 1.0f; // our goal if we're fading
auto gMaxAlpha = 1.0f; // the least transparent we allow ourselves to be (user setting)
auto gMinAlpha = 0.0f; // the most transparent
auto doFadeIn = true;
auto gFullFadeDuration = 3.0f; // seconds
auto gFadeDurRemaining = 2.0f; // seconds
Expand Down Expand Up @@ -834,23 +835,29 @@ namespace ui

void showBriefly()
{
if (gDoingBriefPeek || gHudAlpha >= gMaxAlpha || (doFadeIn == true && gHudAlpha > 0.0f)) { return; }
if (gDoingBriefPeek || gHudAlpha >= gMaxAlpha || (doFadeIn == true && gHudAlpha > gMinAlpha)) { return; }

gDoingBriefPeek = true;
startAlphaTransition(true, gMaxAlpha);
}

void setMaxAlpha(float max)
{
gMaxAlpha = std::clamp(std::abs(max), 0.2f, 1.0f);
gMaxAlpha = std::clamp(std::abs(max), gMinAlpha, 1.0f);
if (gHudAlpha > gMaxAlpha) { gHudAlpha = gMaxAlpha; }
}

void setMinAlpha(float min)
{
gMinAlpha = std::clamp(std::abs(min), 0.0f, gMaxAlpha);
if (gHudAlpha < gMinAlpha) { gHudAlpha = gMinAlpha; }
}

void startAlphaTransition(const bool becomeVisible, const float goal)
{
gGoalAlpha = std::clamp(goal, 0.0f, gMaxAlpha);
gGoalAlpha = std::clamp(goal, gMinAlpha, gMaxAlpha);
if (becomeVisible && gHudAlpha >= gMaxAlpha) { return; }
if (!becomeVisible && gHudAlpha == 0.0f) { return; }
if (!becomeVisible && gHudAlpha <= gMinAlpha) { return; }
rlog::trace("startAlphaTransition() called with in={} and goal={}; gHudAlpha={};"sv,
becomeVisible,
gGoalAlpha,
Expand Down Expand Up @@ -912,7 +919,7 @@ namespace ui
gDoingBriefPeek = false;
}
// The auto-fade case here.
if ((gHudAlpha > 0.0f && !gIsFading) || (gIsFading && doFadeIn)) { startAlphaTransition(false, 0.0f); }
if ((gHudAlpha > gMinAlpha && !gIsFading) || (gIsFading && doFadeIn)) { startAlphaTransition(false, 0.0f); }
}
else if (helpers::hudShouldAutoFadeIn())
{
Expand All @@ -939,8 +946,6 @@ namespace ui

void advanceTransition(float timeDelta)
{
// This fading code is triggered by the toggle hud shortcut even if autofade
// is off. This is maybe the only place where bug #44 might be caused.
if (doFadeIn && gIsFading)
{
if (gHudAlpha >= gMaxAlpha)
Expand All @@ -958,9 +963,9 @@ namespace ui
if (delayBeforeFadeout > 0.0f) { delayBeforeFadeout -= timeDelta; }
else
{
if (gHudAlpha <= 0.0f)
if (gHudAlpha <= gMinAlpha)
{
gHudAlpha = 0.0f;
gHudAlpha = gMinAlpha;
gFadeDurRemaining = 0.0f;
gIsFading = false;
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/ui_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace ui
void makeFadeDecision();
void showBriefly();
void setMaxAlpha(float max);
void setMinAlpha(float min);

void startTimer(Action which, uint32_t duration);
void stopTimer(Action which);
Expand Down

0 comments on commit b4fd72a

Please sign in to comment.