Skip to content

Commit

Permalink
Dry-coded a max alpha setting for the entire HUD.
Browse files Browse the repository at this point in the history
I think I got all the spots in the renderer where we decide
if we're done fading in or not. This was only partially
generalized before this commit.
  • Loading branch information
ceejbot committed Dec 10, 2023
1 parent e2ad82d commit 91a08bb
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 14 deletions.
Binary file modified data/Interface/Translations/SoulsyHUD_czech.txt
Binary file not shown.
Binary file modified data/Interface/Translations/SoulsyHUD_english.txt
Binary file not shown.
Binary file modified data/Interface/Translations/SoulsyHUD_french.txt
Binary file not shown.
Binary file modified data/Interface/Translations/SoulsyHUD_german.txt
Binary file not shown.
Binary file modified data/Interface/Translations/SoulsyHUD_italian.txt
Binary file not shown.
Binary file modified data/Interface/Translations/SoulsyHUD_japanese.txt
Binary file not shown.
Binary file modified data/Interface/Translations/SoulsyHUD_polish.txt
Binary file not shown.
Binary file modified data/Interface/Translations/SoulsyHUD_russian.txt
Binary file not shown.
Binary file modified data/Interface/Translations/SoulsyHUD_spanish.txt
Binary file not shown.
11 changes: 11 additions & 0 deletions data/mcm/config/SoulsyHUD/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,17 @@
"sourceType": "ModSettingInt"
}
},
{
"id": "fMaxAlpha:Options",
"text": "$SoulsyHUD_Options_MaxAlpha_Text",
"help": "$SoulsyHUD_Options_MaxAlpha_Help",
"type": "slider",
"valueOptions": {
"min": 0.125,
"max": 1.0,
"sourceType": "ModSettingFloat"
}
},
{
"id": "uShowHideKey:Controls",
"text": "$SoulsyHUD_Controls_ShowHideKey_Text",
Expand Down
1 change: 1 addition & 0 deletions data/mcm/config/SoulsyHUD/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ uEquipDelay = 750
uLongPressMillis = 1250
bAutoFade = 1
uFadeTime = 2000
uMaxAlpha = 255
uLongPressTime = 1000
uControllerKind = 0
bCyclingSlowsTime = 0
Expand Down
21 changes: 21 additions & 0 deletions src/controller/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub struct UserSettings {
autofade: bool,
/// The time in milliseconds it takes to fade out.
fade_time: u32,
/// Max alpha: the most transparent the HUD goes.
max_alpha: f32,
/// The controller kind to show in the UX. Matches the controller_set enum in key_path.h
controller_kind: u32, // 0 = pc, 1 = ps, 2 = xbox
/// Whether to slow down time when cycling
Expand Down Expand Up @@ -149,6 +151,7 @@ impl Default for UserSettings {
equip_delay_ms: 750, // in milliseconds
long_press_ms: 1250, // in milliseconds
autofade: true,
max_alpha: 1.0,
fade_time: 2000, // in milliseconds
controller_kind: 0, // PS5
cycling_slows_time: false,
Expand Down Expand Up @@ -239,6 +242,8 @@ 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.controller_kind = u32::clamp(
read_from_ini(self.controller_kind, "uControllerKind", options),
0,
Expand Down Expand Up @@ -403,6 +408,9 @@ impl UserSettings {
pub fn fade_time(&self) -> u32 {
self.fade_time
}
pub fn max_alpha(&self) -> f32 {
self.max_alpha
}
pub fn controller_kind(&self) -> u32 {
u32::clamp(self.controller_kind, 0, 2)
}
Expand Down Expand Up @@ -521,6 +529,19 @@ impl FromIniStr for bool {
}
}

impl FromIniStr for u8 {
fn from_ini(v: &str) -> Option<Self>
where
Self: Sized,
{
if let Ok(v) = v.parse::<u8>() {
Some(v)
} else {
None
}
}
}

impl FromIniStr for u32 {
fn from_ini(value: &str) -> Option<Self> {
if let Ok(v) = value.parse::<u32>() {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ pub mod plugin {
fn slow_time_factor(self: &UserSettings) -> f32;
/// How long to spend fading in or out.
fn fade_time(self: &UserSettings) -> u32;
/// The max hud alpha to allow.
fn max_alpha(self: &UserSettings) -> f32;
/// If we care about favorites.
fn link_to_favorites(self: &UserSettings) -> bool;
/// If icons should be colorful.
Expand Down
33 changes: 19 additions & 14 deletions src/renderer/ui_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "constant.h"
#include "gear.h"
#include "helpers.h"
#include "image_path.h"
#include "key_path.h"
#include "keycodes.h"

Expand All @@ -26,8 +25,9 @@ namespace ui
static const float FADEOUT_HYSTERESIS = 0.5f; // seconds
static const uint32_t MAX_ICON_DIM = 300; // rasterized at 96 dpi

auto gHudAlpha = 0.0f;
auto gGoalAlpha = 1.0f;
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 doFadeIn = true;
auto gFullFadeDuration = 3.0f; // seconds
auto gFadeDurRemaining = 2.0f; // seconds
Expand Down Expand Up @@ -685,20 +685,22 @@ namespace ui

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

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

void setMaxAlpha(float maxgoal) { gMaxAlpha = std::clamp(maxgoal, 0.125f, 1.0f); }

void startAlphaTransition(const bool becomeVisible, const float goal)
{
if (becomeVisible && gHudAlpha == 1.0f) { return; }
if (becomeVisible && gHudAlpha == gMaxAlpha) { return; }
if (!becomeVisible && gHudAlpha == 0.0f) { return; }
logger::debug(
"startAlphaTransition() called with in={} and goal={}; gHudAlpha={};"sv, becomeVisible, goal, gHudAlpha);

gGoalAlpha = std::clamp(goal, 0.0f, 1.0f);
gGoalAlpha = std::clamp(goal, 0.0f, gMaxAlpha);
doFadeIn = becomeVisible;

// The game will report that the player has sheathed weapons when
Expand Down Expand Up @@ -738,7 +740,7 @@ namespace ui
// We do the peek even when autofade is false, so we need to fade out automatically in that one case.
if (!autofade)
{
if (gDoingBriefPeek && gHudAlpha >= 1.0f)
if (gDoingBriefPeek && gHudAlpha >= gMaxAlpha)
{
gDoingBriefPeek = false;
startAlphaTransition(false, 0.0f);
Expand All @@ -751,15 +753,18 @@ namespace ui
{
if (gDoingBriefPeek)
{
if (gHudAlpha < 1.0f) { return; }
if (gHudAlpha < gMaxAlpha) { return; }
gDoingBriefPeek = false;
}
// The auto-fade case here.
if ((gHudAlpha > 0.0f && !gIsFading) || (gIsFading && doFadeIn)) { startAlphaTransition(false, 0.0f); }
}
else if (helpers::hudShouldAutoFadeIn())
{
if ((gHudAlpha < 1.0f && !gIsFading) || (gIsFading && !doFadeIn)) { startAlphaTransition(true, 1.0f); }
if ((gHudAlpha < gMaxAlpha && !gIsFading) || (gIsFading && !doFadeIn))
{
startAlphaTransition(true, gMaxAlpha);
}
}
}

Expand All @@ -783,15 +788,15 @@ namespace ui
// is off. This is maybe the only place where bug #44 might be caused.
if (doFadeIn && gIsFading)
{
if (gHudAlpha >= 1.0f)
if (gHudAlpha >= gMaxAlpha)
{
gHudAlpha = 1.0f;
gHudAlpha = gMaxAlpha;
gFadeDurRemaining = 0.0f;
gIsFading = false;
return;
}
if (gFadeDurRemaining > 0.0f) { gFadeDurRemaining -= timeDelta; }
gHudAlpha = easeInCubic(1.0f - (gFadeDurRemaining / gFullFadeDuration));
gHudAlpha = easeInCubic(gMaxAlpha - (gFadeDurRemaining / gFullFadeDuration));
}
else if (!doFadeIn && gIsFading)
{
Expand All @@ -806,7 +811,7 @@ namespace ui
}
delayBeforeFadeout = 0.0f;
if (gFadeDurRemaining > 0.0f) { gFadeDurRemaining -= timeDelta; }
gHudAlpha = 1.0f - easeInCubic(1.0f - (gFadeDurRemaining / gFullFadeDuration));
gHudAlpha = gMaxAlpha - easeInCubic(gMaxAlpha - (gFadeDurRemaining / gFullFadeDuration));
}
}
}
Expand Down

0 comments on commit 91a08bb

Please sign in to comment.