Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions game/neo/scripts/HudLayout.res
Original file line number Diff line number Diff line change
Expand Up @@ -1007,4 +1007,15 @@
"tall" "480"
"box_color" "200 200 200 40"
}

neo_context_hint
{
"fieldName" "neo_context_hint"
"font" "NeoUINormal"
"padding_x" "4"
"padding_y" "6"
"box_y_factor" "0.75"
"box_color" "20 20 20 0"
"text_color" "255 255 255 255"
}
}
2 changes: 2 additions & 0 deletions src/game/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,8 @@ target_sources_grouped(
neo/ui/neo_hud_worldpos_marker.h
neo/ui/neo_scoreboard.cpp
neo/ui/neo_scoreboard.h
neo/ui/neo_hud_context_hint.cpp
neo/ui/neo_hud_context_hint.h
)

target_sources_grouped(
Expand Down
184 changes: 184 additions & 0 deletions src/game/client/neo/ui/neo_hud_context_hint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#include "cbase.h"
#include "neo_hud_context_hint.h"

#include "iclientmode.h"
#include "c_neo_player.h"
#include "vgui/ISurface.h"
#include "igameresources.h"
#include "ienginevgui.h"
#include "vgui/IInput.h"
#include "vgui/IPanel.h"
#include "vgui_controls/AnimationController.h"
#include "neo_root_settings.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

ConVar cl_neo_hud_context_hint_enabled("cl_neo_hud_context_hint_enabled", "1",
FCVAR_ARCHIVE, "Whether to show contextual hud hints. 0: Disabled, 1: Enabled.", false, 0, true, 1);

ConVar cl_neo_spec_takeover_player_hint_time_sec("cl_neo_spec_takeover_player_hint_time_sec", "3.0",
FCVAR_ARCHIVE, "Duration in seconds to display the spectator bot takeover hint.", true, 0, true, 9999);

DECLARE_HUDELEMENT(CNEOHud_ContextHint);

NEO_HUD_ELEMENT_DECLARE_FREQ_CVAR(ContextHint, 0.00695);

CNEOHud_ContextHint::CNEOHud_ContextHint(const char* pElementName)
: CNEOHud_ChildElement(), CHudElement(pElementName), vgui::EditablePanel(NULL, "neo_context_hint")
{
SetParent(g_pClientMode->GetViewport());
SetVisible(false);

m_flDisplayTime = 0.0f;
m_bHintShownForCurrentSpecTarget = false;
m_hLastSpecTarget = nullptr;
}

CNEOHud_ContextHint::~CNEOHud_ContextHint()
{
}

void CNEOHud_ContextHint::Init()
{
}

void CNEOHud_ContextHint::VidInit()
{
}

void CNEOHud_ContextHint::Reset()
{
m_flDisplayTime = 0.0f;
m_bHintShownForCurrentSpecTarget = false;
m_hLastSpecTarget = nullptr;
SetVisible(false);
}

void CNEOHud_ContextHint::ApplySchemeSettings(vgui::IScheme* pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);

int iScrWide, iScrTall;
vgui::surface()->GetScreenSize(iScrWide, iScrTall);
SetBounds(0, 0, iScrWide, iScrTall);

LoadControlSettings("scripts/HudLayout.res");
}

bool CNEOHud_ContextHint::ShouldDraw()
{
if (!cl_neo_hud_context_hint_enabled.GetBool())
{
return false;
}

C_BasePlayer* pLocalPlayer = C_BasePlayer::GetLocalPlayer();
if (!pLocalPlayer)
{
return false;
}

C_BaseEntity* pObserverTargetEntity = pLocalPlayer->GetObserverTarget();
C_BasePlayer* pObserverTargetPlayer = (pObserverTargetEntity && pObserverTargetEntity->IsPlayer()) ? ToBasePlayer(pObserverTargetEntity) : nullptr;

auto eObserverMode = pLocalPlayer->GetObserverMode();
bool bIsSpectating = (eObserverMode == OBS_MODE_CHASE || eObserverMode == OBS_MODE_IN_EYE);

if (pObserverTargetPlayer != m_hLastSpecTarget.Get())
{
m_bHintShownForCurrentSpecTarget = false;
m_hLastSpecTarget = pObserverTargetPlayer;
}

bool bShouldDisplayBotTakeoverHint = false;
if (bIsSpectating && pObserverTargetPlayer)
{
if (GameResources()->IsFakePlayer(pObserverTargetPlayer->entindex()))
{
if (pLocalPlayer->InSameTeam(pObserverTargetPlayer))
{
ConVar* pBotEnableCvar = g_pCVar->FindVar("sv_neo_spec_replace_player_bot_enable");
bool bBotEnable = pBotEnableCvar ? pBotEnableCvar->GetBool() : false;

if (bBotEnable)
{
// Check that spectator's XP is not at concerning griefing levels
int localPlayerXP = GameResources()->GetXP(pLocalPlayer->entindex());
ConVar* pMinExpCvar = g_pCVar->FindVar("sv_neo_spec_replace_player_min_exp");
int minExp = pMinExpCvar ? pMinExpCvar->GetInt() : 0;

bShouldDisplayBotTakeoverHint = (localPlayerXP >= minExp);
}
}
}
}

if (bShouldDisplayBotTakeoverHint)
{
// If the hint has not been shown for the current target yet, start the timer.
if (!m_bHintShownForCurrentSpecTarget)
{
m_flDisplayTime = gpGlobals->curtime + cl_neo_spec_takeover_player_hint_time_sec.GetFloat();
m_bHintShownForCurrentSpecTarget = true;
}

// If the hint is displaying and the timer hasn't expired, keep displaying it.
if (gpGlobals->curtime < m_flDisplayTime)
{
return true;
}
}

// If conditions are not met, or timer has expired, hide the hint.
return false;
}

void CNEOHud_ContextHint::UpdateStateForNeoHudElementDraw()
{
const char* useKeyBinding = engine->Key_LookupBinding("+use");
if (useKeyBinding && useKeyBinding[0] != '\0')
{
char szUppercaseKeyBinding[16]; // Assuming keybinds won't exceed 15 characters + null terminator
V_strncpy(szUppercaseKeyBinding, useKeyBinding, sizeof(szUppercaseKeyBinding));
V_strupr(szUppercaseKeyBinding);
V_snwprintf(m_wszHintText, ARRAYSIZE(m_wszHintText), L"[%hs] Control Bot", szUppercaseKeyBinding);
}
else
{
V_wcsncpy(m_wszHintText, L"Press Use To Control Bot", sizeof(m_wszHintText));
}
}

void CNEOHud_ContextHint::DrawNeoHudElement()
{
int iScrWide, iScrTall;
vgui::surface()->GetScreenSize(iScrWide, iScrTall);

int iTextWide, iTextTall;
vgui::surface()->GetTextSize(m_hHintFont, m_wszHintText, iTextWide, iTextTall);

int iBoxWide = iTextWide + m_iPaddingX * 2;
int iBoxTall = iTextTall + m_iPaddingY * 2;

int iBoxX = (iScrWide - iBoxWide) / 2;
int iBoxY = iScrTall * m_flBoxYFactor - iBoxTall / 2;

vgui::surface()->DrawSetColor(m_BoxColor);
vgui::surface()->DrawFilledRect(iBoxX, iBoxY, iBoxX + iBoxWide, iBoxY + iBoxTall);

vgui::surface()->DrawSetTextFont(m_hHintFont);
vgui::surface()->DrawSetTextColor(m_TextColor);
vgui::surface()->DrawSetTextPos(iBoxX + m_iPaddingX, iBoxY + m_iPaddingY);
vgui::surface()->DrawPrintText(m_wszHintText, static_cast<int>(wcslen(m_wszHintText)));
}

void CNEOHud_ContextHint::Paint()
{
PaintNeoElement();
BaseClass::Paint();
}

void CNEOHud_ContextHint::FireGameEvent(IGameEvent* event)
{
}
51 changes: 51 additions & 0 deletions src/game/client/neo/ui/neo_hud_context_hint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef NEO_HUD_CONTEXT_HINT_H
#define NEO_HUD_CONTEXT_HINT_H
#ifdef _WIN32
#pragma once
#endif

#include "hudelement.h"
#include "vgui_controls/EditablePanel.h"
#include "neo_hud_childelement.h"

//-----------------------------------------------------------------------------
// Purpose: Displays a contextual hint based on what the player is focused on
//-----------------------------------------------------------------------------
class CNEOHud_ContextHint : public CNEOHud_ChildElement, public CHudElement, public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE(CNEOHud_ContextHint, vgui::EditablePanel);

public:
CNEOHud_ContextHint(const char *pElementName);
~CNEOHud_ContextHint();

void Init();
void VidInit();
void Reset();
bool ShouldDraw();

virtual void FireGameEvent( IGameEvent * event );

protected:
void ApplySchemeSettings(vgui::IScheme *pScheme) override;
virtual void UpdateStateForNeoHudElementDraw() override;
virtual void DrawNeoHudElement() override;
virtual ConVar* GetUpdateFrequencyConVar() const override;
virtual void Paint() override;

private:
wchar_t m_wszHintText[32];

float m_flDisplayTime;
bool m_bHintShownForCurrentSpecTarget;
CHandle<C_BasePlayer> m_hLastSpecTarget;

CPanelAnimationVar(vgui::HFont, m_hHintFont, "font", "NeoUINormal");
CPanelAnimationVarAliasType(int, m_iPaddingX, "padding_x", "4", "proportional_xpos");
CPanelAnimationVarAliasType(int, m_iPaddingY, "padding_y", "6", "proportional_ypos");
CPanelAnimationVar(float, m_flBoxYFactor, "box_y_factor", "0.75");
CPanelAnimationVar(Color, m_BoxColor, "box_color", "20 20 20 220");
CPanelAnimationVar(Color, m_TextColor, "text_color", "255 255 255 255");
};

#endif // NEO_HUD_CONTEXT_HINT_H
3 changes: 3 additions & 0 deletions src/game/client/neo/ui/neo_root_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ void NeoSettingsRestore(NeoSettings *ns, const NeoSettings::Keys::Flags flagsKey
pGeneral->bExtendedKillfeed = cvr->cl_neo_hud_extended_killfeed.GetBool();
pGeneral->iBackground = clamp(cvr->sv_unlockedchapters.GetInt(), 0, ns->iCBListSize - 1);
pGeneral->iKdinfoToggletype = cvr->cl_neo_kdinfo_toggletype.GetInt();
pGeneral->bShowHudContextHints = cvr->cl_neo_hud_context_hint_enabled.GetBool();
NeoSettingsBackgroundWrite(ns);
NeoUI::ResetTextures();
}
Expand Down Expand Up @@ -699,6 +700,7 @@ void NeoSettingsSave(const NeoSettings *ns)
cvr->cl_neo_hud_extended_killfeed.SetValue(pGeneral->bExtendedKillfeed);
cvr->sv_unlockedchapters.SetValue(pGeneral->iBackground);
cvr->cl_neo_kdinfo_toggletype.SetValue(pGeneral->iKdinfoToggletype);
cvr->cl_neo_hud_context_hint_enabled.SetValue(pGeneral->bShowHudContextHints);
NeoSettingsBackgroundWrite(ns);
}
{
Expand Down Expand Up @@ -932,6 +934,7 @@ void NeoSettings_General(NeoSettings *ns)
NeoUI::RingBox(L"Automatic leaning", AUTOMATIC_LEAN_LABELS, ARRAYSIZE(AUTOMATIC_LEAN_LABELS), &pGeneral->iLeanAutomatic);
NeoUI::RingBoxBool(L"Classic squad list", &pGeneral->bShowSquadList);
NeoUI::RingBoxBool(L"Show hints", &pGeneral->bShowHints);
NeoUI::RingBoxBool(L"Show HUD contextual hints", &pGeneral->bShowHudContextHints);
NeoUI::RingBoxBool(L"Show position", &pGeneral->bShowPos);
NeoUI::RingBox(L"Show FPS", SHOWFPS_LABELS, ARRAYSIZE(SHOWFPS_LABELS), &pGeneral->iShowFps);
NeoUI::RingBoxBool(L"Show rangefinder", &pGeneral->bEnableRangeFinder);
Expand Down
2 changes: 2 additions & 0 deletions src/game/client/neo/ui/neo_root_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct NeoSettings
bool bExtendedKillfeed;
int iBackground;
int iKdinfoToggletype;
bool bShowHudContextHints;
};

struct Keys
Expand Down Expand Up @@ -220,6 +221,7 @@ struct NeoSettings
CONVARREF_DEF(cl_neo_hud_rangefinder_enabled);
CONVARREF_DEF(sv_unlockedchapters);
CONVARREF_DEF(cl_neo_kdinfo_toggletype);
CONVARREF_DEF(cl_neo_hud_context_hint_enabled);

// Multiplayer
CONVARREF_DEF(cl_spraydisable);
Expand Down