Skip to content

Commit

Permalink
Improve mic testing bar, brought back more readable bar delays
Browse files Browse the repository at this point in the history
  • Loading branch information
nullsystem committed Sep 12, 2024
1 parent 597c447 commit 99be616
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
31 changes: 24 additions & 7 deletions mp/src/game/client/neo/ui/neo_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,7 @@ void NeoSettings_General(NeoSettings *ns)
(bShowSteamNick) ? (void)g_pVGuiLocalize->ConvertANSIToUnicode(steamapicontext->SteamFriends()->GetPersonaName(), wszDisplayName, sizeof(wszDisplayName))
: (void)V_wcscpy_safe(wszDisplayName, pGeneral->wszNeoName);

wchar_t wszDisplayNameLabelText[128];
V_swprintf_safe(wszDisplayNameLabelText, L"Display name: %ls", wszDisplayName);
NeoUI::Label(wszDisplayNameLabelText);
NeoUI::Label(L"Display name", wszDisplayName);
NeoUI::SliderInt(L"FOV", &pGeneral->iFov, 75, 110);
NeoUI::SliderInt(L"Viewmodel FOV Offset", &pGeneral->iViewmodelFov, -20, 40);
NeoUI::RingBoxBool(L"Aim hold", &pGeneral->bAimHold);
Expand Down Expand Up @@ -772,18 +770,37 @@ void NeoSettings_Audio(NeoSettings *ns)
NeoUI::RingBoxBool(L"Microphone Boost", &pAudio->bMicBoost);
IVoiceTweak_s *pVoiceTweak = engine->GetVoiceTweakAPI();
const bool bTweaking = pVoiceTweak->IsStillTweaking();
if (bTweaking && g_uiCtx.eMode == NeoUI::MODE_PAINT)
{
// Only fetch the value at interval as immediate is too quick/flickers, and give a longer delay when
// it goes from sound to no sound.
static constexpr float FL_FETCH_INTERVAL = 0.1f;
static constexpr float FL_SILENCE_INTERVAL = 0.4f;
const float flNowSpeakingVol = pVoiceTweak->GetControlFloat(SpeakingVolume);
if ((flNowSpeakingVol > 0.0f && pAudio->flLastFetchInterval + FL_FETCH_INTERVAL < gpGlobals->curtime) ||
(flNowSpeakingVol == 0.0f && pAudio->flSpeakingVol > 0.0f &&
pAudio->flLastFetchInterval + FL_SILENCE_INTERVAL < gpGlobals->curtime))
{
pAudio->flSpeakingVol = flNowSpeakingVol;
pAudio->flLastFetchInterval = gpGlobals->curtime;
}
surface()->DrawSetColor(COLOR_NEOPANELMICTEST);
NeoUI::GCtxDrawFilledRectXtoX(g_uiCtx.iWgXPos, 0,
g_uiCtx.iWgXPos + (pAudio->flSpeakingVol * (g_uiCtx.dPanel.wide - g_uiCtx.iWgXPos)), g_uiCtx.iRowTall);
surface()->DrawSetColor(COLOR_TRANSPARENT);
g_uiCtx.selectBgColor = COLOR_TRANSPARENT;
}
if (NeoUI::Button(L"Microphone Tester",
bTweaking ? L"Stop testing" : L"Start testing").bPressed)
{
bTweaking ? pVoiceTweak->EndVoiceTweakMode() : (void)pVoiceTweak->StartVoiceTweakMode();
pAudio->flSpeakingVol = 0.0f;
pAudio->flLastFetchInterval = 0.0f;
}
if (bTweaking && g_uiCtx.eMode == NeoUI::MODE_PAINT)
{
const float flSpeakingVol = pVoiceTweak->GetControlFloat(SpeakingVolume);
surface()->DrawSetColor(COLOR_NEOPANELMICTEST);
NeoUI::GCtxDrawFilledRectXtoX(0, flSpeakingVol * g_uiCtx.dPanel.wide);
g_uiCtx.iLayoutY += g_uiCtx.iRowTall;
surface()->DrawSetColor(COLOR_NEOPANELACCENTBG);
g_uiCtx.selectBgColor = COLOR_NEOPANELSELECTBG;
}
}

Expand Down
4 changes: 4 additions & 0 deletions mp/src/game/client/neo/ui/neo_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ struct NeoSettings
bool bVoiceEnabled;
float flVolVoiceRecv;
bool bMicBoost;

// Microphone tweaking
float flSpeakingVol;
float flLastFetchInterval;
};

struct Video
Expand Down
3 changes: 2 additions & 1 deletion mp/src/game/client/neo/ui/neo_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void BeginContext(NeoUI::Context *ctx, const NeoUI::Mode eMode, const wchar_t *w
g_pCtx->eButtonTextStyle = TEXTSTYLE_CENTER;
g_pCtx->eLabelTextStyle = TEXTSTYLE_LEFT;
g_pCtx->bTextEditIsPassword = false;
g_pCtx->selectBgColor = COLOR_NEOPANELSELECTBG;
// Different pointer, change context
if (g_pCtx->pSzCurCtxName != pSzCtxName)
{
Expand Down Expand Up @@ -354,7 +355,7 @@ static GetMouseinFocusedRet InternalGetMouseinFocused()
const bool bActive = g_pCtx->iWidget == g_pCtx->iActive && g_pCtx->iSection == g_pCtx->iActiveSection;
if (bActive || bHot)
{
surface()->DrawSetColor(COLOR_NEOPANELSELECTBG);
surface()->DrawSetColor(g_pCtx->selectBgColor);
if (bActive) surface()->DrawSetTextColor(COLOR_NEOPANELTEXTBRIGHT);
}
return GetMouseinFocusedRet{
Expand Down
1 change: 1 addition & 0 deletions mp/src/game/client/neo/ui/neo_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ struct Context
ButtonCode_t eCode;
wchar_t unichar;
Color bgColor;
Color selectBgColor;

// Mouse handling
int iMouseAbsX;
Expand Down

0 comments on commit 99be616

Please sign in to comment.