Skip to content

Commit

Permalink
Rangefinder HUD
Browse files Browse the repository at this point in the history
* In meters, the distance between the player and solid wall
* Skybox and >= 999m will return "---m" to show infinity value
* Only shown in ADS, also shown on spectating ADS
* ConVars:
    * neo_cl_hud_rangefinder_enabled - 1 as default, Toggle enable/disable
    * neo_cl_hud_rangefinder_pos_frac_[x/y] - 0.55 as default, position in
      fraction in screen width/height
* Added to settings > General to toggle rangefinder

* fixes #761
  • Loading branch information
nullsystem committed Oct 24, 2024
1 parent 762398a commit dee42e2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
61 changes: 59 additions & 2 deletions mp/src/game/client/neo/ui/neo_hud_compass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ ConVar neo_cl_hud_debug_compass_color_b("neo_cl_hud_debug_compass_color_b", "205
ConVar neo_cl_hud_debug_compass_color_a("neo_cl_hud_debug_compass_color_a", "255", FCVAR_USERINFO | FCVAR_CHEAT,
"Alpha color value of the Debug compass, in range 0 - 255.", true, 0.0f, true, 255.0f);

ConVar neo_cl_hud_rangefinder_enabled("neo_cl_hud_rangefinder_enabled", "1", FCVAR_ARCHIVE,
"Whether the rangefinder HUD is enabled or not.", true, 0.0f, true, 1.0f);
ConVar neo_cl_hud_rangefinder_pos_frac_x("neo_cl_hud_rangefinder_pos_frac_x", "0.55", FCVAR_ARCHIVE,
"In fractional to the total screen width, the x-axis position of the rangefinder.",
true, 0.0f, true, 1.0f);
ConVar neo_cl_hud_rangefinder_pos_frac_y("neo_cl_hud_rangefinder_pos_frac_y", "0.55", FCVAR_ARCHIVE,
"In fractional to the total screen height, the y-axis position of the rangefinder.",
true, 0.0f, true, 1.0f);

DECLARE_NAMED_HUDELEMENT(CNEOHud_Compass, NHudCompass);

NEO_HUD_ELEMENT_DECLARE_FREQ_CVAR(Compass, 0.00695)
Expand Down Expand Up @@ -116,9 +125,25 @@ void CNEOHud_Compass::GetCompassUnicodeString(const float angle, wchar_t* outUni
g_pVGuiLocalize->ConvertANSIToUnicode(compass, outUnicodeStr, UNICODE_NEO_COMPASS_SIZE_BYTES);
}

static C_NEO_Player *GetFirstPersonPlayer()
{
auto pLocalPlayer = C_NEO_Player::GetLocalNEOPlayer();
C_NEO_Player *pFPPlayer = pLocalPlayer;
if (pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE)
{
auto *pTargetPlayer = dynamic_cast<C_NEO_Player *>(pLocalPlayer->GetObserverTarget());
if (pTargetPlayer && !pTargetPlayer->IsObserver())
{
pFPPlayer = pTargetPlayer;
}
}
return pFPPlayer;
}

void CNEOHud_Compass::UpdateStateForNeoHudElementDraw()
{
Assert(C_NEO_Player::GetLocalNEOPlayer());
auto pLocalPlayer = C_NEO_Player::GetLocalNEOPlayer();
Assert(pLocalPlayer);

static auto safeAngle = [](const float angle) -> float {
if (angle > 180.0f)
Expand All @@ -133,11 +158,34 @@ void CNEOHud_Compass::UpdateStateForNeoHudElementDraw()
};

// Direction in -180 to 180
float angle = C_NEO_Player::GetLocalNEOPlayer()->EyeAngles()[YAW] * -1;
float angle = pLocalPlayer->EyeAngles()[YAW] * -1;
angle = safeAngle(angle);
angle += 180.0f; // NEO NOTE (nullsystem): Adjust it again to match OG:NT's compass angle
angle = safeAngle(angle);
GetCompassUnicodeString(angle, m_wszCompassUnicode);

if (neo_cl_hud_rangefinder_enabled.GetBool())
{
C_NEO_Player *pFPPlayer = GetFirstPersonPlayer();
if (pFPPlayer->IsInAim())
{
// Update Rangefinder
trace_t tr;
Vector vecForward;
AngleVectors(pFPPlayer->EyeAngles(), &vecForward);
UTIL_TraceLine(pFPPlayer->EyePosition(), pFPPlayer->EyePosition() + (vecForward * MAX_TRACE_LENGTH),
MASK_SHOT, pFPPlayer, COLLISION_GROUP_NONE, &tr);
const float flDist = METERS_PER_INCH * tr.startpos.DistTo(tr.endpos);
if (flDist >= 999.0f || tr.surface.flags & (SURF_SKY | SURF_SKY2D))
{
V_swprintf_safe(m_wszRangeFinder, L"RANGE ---m");
}
else
{
V_swprintf_safe(m_wszRangeFinder, L"RANGE %3.0fm", flDist);
}
}
}
}

void CNEOHud_Compass::DrawNeoHudElement(void)
Expand All @@ -156,6 +204,15 @@ void CNEOHud_Compass::DrawNeoHudElement(void)
{
DrawDebugCompass();
}

if (neo_cl_hud_rangefinder_enabled.GetBool() && GetFirstPersonPlayer()->IsInAim())
{
surface()->DrawSetTextColor(COLOR_NEO_WHITE);
surface()->DrawSetTextFont(m_hFont);
surface()->DrawSetTextPos((m_resX * neo_cl_hud_rangefinder_pos_frac_x.GetFloat()),
(m_resY * neo_cl_hud_rangefinder_pos_frac_y.GetFloat()));
surface()->DrawPrintText(m_wszRangeFinder, ARRAYSIZE(m_wszRangeFinder) - 1);
}
}

void CNEOHud_Compass::ApplySchemeSettings(vgui::IScheme *pScheme)
Expand Down
1 change: 1 addition & 0 deletions mp/src/game/client/neo/ui/neo_hud_compass.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CNEOHud_Compass : public CNEOHud_ChildElement, public CHudElement, public
mutable int m_savedXBoxWidth = 0;

wchar_t m_wszCompassUnicode[UNICODE_NEO_COMPASS_STR_LENGTH];
wchar_t m_wszRangeFinder[11];

CPanelAnimationVarAliasType(bool, m_showCompass, "visible", "1", "bool");
CPanelAnimationVarAliasType(int, m_yFromBottomPos, "y_bottom_pos", "3", "proportional_ypos");
Expand Down
3 changes: 3 additions & 0 deletions mp/src/game/client/neo/ui/neo_root_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ void NeoSettingsRestore(NeoSettings *ns, const NeoSettings::Keys::Flags flagsKey
}
pGeneral->bStreamerMode = cvr->neo_cl_streamermode.GetBool();
pGeneral->bAutoDetectOBS = cvr->neo_cl_streamermode_autodetect_obs.GetBool();
pGeneral->bEnableRangeFinder = cvr->neo_cl_hud_rangefinder_enabled.GetBool();
}
{
NeoSettings::Keys *pKeys = &ns->keys;
Expand Down Expand Up @@ -444,6 +445,7 @@ void NeoSettingsSave(const NeoSettings *ns)
cvr->cl_downloadfilter.SetValue(DLFILTER_STRMAP[pGeneral->iDlFilter]);
cvr->neo_cl_streamermode.SetValue(pGeneral->bStreamerMode);
cvr->neo_cl_streamermode_autodetect_obs.SetValue(pGeneral->bAutoDetectOBS);
cvr->neo_cl_hud_rangefinder_enabled.SetValue(pGeneral->bEnableRangeFinder);
}
{
const NeoSettings::Keys *pKeys = &ns->keys;
Expand Down Expand Up @@ -644,6 +646,7 @@ void NeoSettings_General(NeoSettings *ns)
NeoUI::RingBoxBool(L"Streamer mode", &pGeneral->bStreamerMode);
NeoUI::RingBoxBool(L"Auto streamer mode (requires restart)", &pGeneral->bAutoDetectOBS);
NeoUI::Label(L"OBS detection", g_bOBSDetected ? L"OBS detected on startup" : L"Not detected on startup");
NeoUI::RingBoxBool(L"Show rangefinder", &pGeneral->bEnableRangeFinder);
}

void NeoSettings_Keys(NeoSettings *ns)
Expand Down
2 changes: 2 additions & 0 deletions mp/src/game/client/neo/ui/neo_root_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct NeoSettings
int iDlFilter;
bool bStreamerMode;
bool bAutoDetectOBS;
bool bEnableRangeFinder;
};

struct Keys
Expand Down Expand Up @@ -164,6 +165,7 @@ struct NeoSettings
CONVARREF_DEF(neo_cl_toggleconsole);
CONVARREF_DEF(neo_cl_streamermode);
CONVARREF_DEF(neo_cl_streamermode_autodetect_obs);
CONVARREF_DEF(neo_cl_hud_rangefinder_enabled);

// Multiplayer
CONVARREF_DEF(cl_playerspraydisable);
Expand Down

0 comments on commit dee42e2

Please sign in to comment.