Repository navigation
Walking Indicator #1831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Walking Indicator #1831
Changes from all commits
8abe065
6b30193
b89129a
f91c132
d095f96
82139b4
9129b87
708e7b7
3b983fd
63bf813
ab53c4a
2e9e5f1
a16a5c0
109df8f
3140c25
315ffb1
829910f
58adde2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| #include "neo_hud_walking_indicator.h" | ||
|
|
||
| #include "iclientmode.h" | ||
| #include <vgui/ISurface.h> | ||
|
|
||
| #include "c_neo_player.h" | ||
| #include "view.h" | ||
|
|
||
| // memdbgon must be the last include file in a .cpp file!!! | ||
| #include "tier0/memdbgon.h" | ||
|
|
||
| DECLARE_NAMED_HUDELEMENT(CNEOHud_WalkingIndicator, neo_walking_indicator); | ||
|
|
||
| NEO_HUD_ELEMENT_DECLARE_FREQ_CVAR(WalkingIndicator, 0.1) | ||
|
|
||
| CNEOHud_WalkingIndicator::CNEOHud_WalkingIndicator(const char *pElementName, vgui::Panel *parent) | ||
| : CHudElement(pElementName), Panel(parent, pElementName) | ||
| { | ||
| SetAutoDelete(true); | ||
| m_iHideHudElementNumber = NEO_HUD_ELEMENT_WALKING_INDICATOR; | ||
|
|
||
| if (parent) | ||
| { | ||
| SetParent(parent); | ||
| } | ||
| else | ||
| { | ||
| SetParent(g_pClientMode->GetViewport()); | ||
| } | ||
|
|
||
| SetVisible(true); | ||
| } | ||
|
|
||
| const wchar_t notWalkingText[] = L"NOT "; | ||
| const wchar_t walkingText[] = L"WALKING"; | ||
| int notWalkingTextWidth = 0; | ||
| int textHeight = 0; | ||
|
Comment on lines
+36
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
| void CNEOHud_WalkingIndicator::ApplySchemeSettings(vgui::IScheme* pScheme) | ||
| { | ||
| BaseClass::ApplySchemeSettings(pScheme); | ||
|
|
||
| int w,h; | ||
| vgui::surface()->GetTextSize(m_hFont, notWalkingText, notWalkingTextWidth, h); | ||
| int walkingTextWidth; | ||
| vgui::surface()->GetTextSize(m_hFont, walkingText, walkingTextWidth, h); | ||
| textHeight = vgui::surface()->GetFontTall(m_hFont); | ||
|
|
||
| vgui::ipanel()->GetSize( GetVParent(), w, h ); | ||
|
|
||
| SetBounds(m_iXpos, m_iYpos, w - m_iXpos, textHeight * 2); | ||
| SetFgColor(COLOR_TRANSPARENT); | ||
| SetBgColor(COLOR_TRANSPARENT); | ||
| } | ||
|
|
||
| ConVar cl_neo_hud_rangefinder_enabled("cl_neo_hud_rangefinder_enabled", "1", FCVAR_ARCHIVE, | ||
| "Show the rangefinder", true, 0.0f, true, 1.0f); | ||
| wchar_t m_wszRangeFinder[11]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: not technically a member (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: The old |
||
| void CNEOHud_WalkingIndicator::UpdateStateForNeoHudElementDraw() | ||
| { | ||
| C_NEO_Player* pLocalPlayer = C_NEO_Player::GetLocalNEOPlayer(); | ||
| if (!pLocalPlayer) | ||
| return; | ||
|
|
||
| C_NEO_Player* pTargetPlayer = pLocalPlayer->IsObserver() && (pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE || pLocalPlayer->GetObserverMode() == OBS_MODE_CHASE) | ||
| ? static_cast<C_NEO_Player *>(pLocalPlayer->GetObserverTarget()) | ||
|
Comment on lines
+64
to
+65
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: If we ever add observer targets that are non-players (for example observing some kind of objective for a custom game mode like Jeff/Payload/etc, the Perhaps grab a But I'm ok with merging this and fixing in the future if it breaks. |
||
| : pLocalPlayer; | ||
| if (!pTargetPlayer || !pTargetPlayer->IsAlive()) | ||
| return; | ||
|
|
||
| if (cl_neo_hud_rangefinder_enabled.GetBool()) | ||
| { | ||
| if (pTargetPlayer->IsInAim()) | ||
| { | ||
| // Update Rangefinder | ||
| trace_t tr; | ||
| Vector vecForward; | ||
| AngleVectors(MainViewAngles(), &vecForward); | ||
| UTIL_TraceLine(MainViewOrigin(), MainViewOrigin() + (vecForward * MAX_TRACE_LENGTH), | ||
| MASK_SHOT, pTargetPlayer, 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_WalkingIndicator::DrawRangeFinder(C_NEO_Player * pPlayer, int &offset) | ||
| { | ||
| if (!cl_neo_hud_rangefinder_enabled.GetBool()) | ||
| return; | ||
|
|
||
| if (pPlayer->IsInAim()) | ||
| { | ||
| vgui::surface()->DrawSetTextColor(m_color); | ||
| vgui::surface()->DrawSetTextFont(m_hFont); | ||
| vgui::surface()->DrawSetTextPos(notWalkingTextWidth, offset); | ||
| vgui::surface()->DrawPrintText(m_wszRangeFinder, ARRAYSIZE(m_wszRangeFinder) - 1); | ||
| } | ||
| offset += textHeight; | ||
| } | ||
|
|
||
| ConVar cl_neo_hud_walkindicator_enabled("cl_neo_hud_walkindicator_enabled", "1", FCVAR_ARCHIVE, | ||
| "Show the walking indicator", true, 0.0f, true, 1.0f); | ||
| void CNEOHud_WalkingIndicator::DrawWalkingIndicator(C_NEO_Player * pPlayer, int &offset) | ||
| { | ||
| if (!cl_neo_hud_walkindicator_enabled.GetBool()) | ||
| return; | ||
|
|
||
| static float animWalkKeyPressed = 0.f; | ||
| const bool isWalking = pPlayer->IsWalking(); | ||
| static float animIsMakingFootsteps = 0.f; | ||
| const bool isMakingFootsteps = pPlayer->IsMakingFootstepSounds() || !(pPlayer->GetFlags() & FL_ONGROUND); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: for |
||
| if (isWalking) | ||
| { | ||
| if (animWalkKeyPressed == 0.f) | ||
| { | ||
| if (isMakingFootsteps) | ||
| { | ||
| animIsMakingFootsteps = 1.f; | ||
| } | ||
| else | ||
| { | ||
| animIsMakingFootsteps = 0.f; | ||
| } | ||
| } | ||
| animWalkKeyPressed += gpGlobals->frametime * m_flAnimationSpeed; | ||
| } | ||
| else | ||
| { | ||
| animWalkKeyPressed -= gpGlobals->frametime * m_flAnimationSpeed; | ||
| } | ||
| animWalkKeyPressed = Clamp(animWalkKeyPressed, 0.f, 1.f); | ||
|
|
||
| if (animWalkKeyPressed == 0.f) | ||
| { | ||
| offset += textHeight; | ||
| return; | ||
| } | ||
|
|
||
| if (isMakingFootsteps) | ||
| { | ||
| animIsMakingFootsteps += gpGlobals->frametime * m_flAnimationSpeed; | ||
| } | ||
| else | ||
| { | ||
| animIsMakingFootsteps -= gpGlobals->frametime * m_flAnimationSpeed; | ||
| } | ||
| animIsMakingFootsteps = Clamp(animIsMakingFootsteps, 0.f, 1.f); | ||
|
|
||
| const float animWalkKeyPressedSmooth = animWalkKeyPressed * animWalkKeyPressed * (3.0f - 2.0f * animWalkKeyPressed); | ||
| const float animIsMakingFootstepsSmoothStep = animIsMakingFootsteps * animIsMakingFootsteps * (3.0f - 2.0f * animIsMakingFootsteps); | ||
| const float inverseAnimIsMakingFootstepsSmooth = 1.f - animIsMakingFootstepsSmoothStep; | ||
|
|
||
| const Color finalColor = Color((m_color2.r() * animIsMakingFootstepsSmoothStep) + (m_color.r() * inverseAnimIsMakingFootstepsSmooth), | ||
| (m_color2.g() * animIsMakingFootstepsSmoothStep) + (m_color.g() * inverseAnimIsMakingFootstepsSmooth), | ||
| (m_color2.b() * animIsMakingFootstepsSmoothStep) + (m_color.b() * inverseAnimIsMakingFootstepsSmooth), | ||
| ((m_color2.a() * animIsMakingFootstepsSmoothStep) + (m_color.a() * inverseAnimIsMakingFootstepsSmooth)) * animWalkKeyPressedSmooth); | ||
| vgui::surface()->DrawSetTextFont(m_hFont); | ||
| if (animIsMakingFootsteps > 0.f) | ||
| { | ||
| vgui::surface()->DrawSetTextColor(finalColor.r(), finalColor.g(), finalColor.b(), finalColor.a() * animIsMakingFootstepsSmoothStep); | ||
| vgui::surface()->DrawSetTextPos(0, offset); | ||
| vgui::surface()->DrawPrintText(notWalkingText, ARRAYSIZE(notWalkingText) - 1); | ||
| } | ||
| vgui::surface()->DrawSetTextColor(finalColor); | ||
| vgui::surface()->DrawSetTextPos(notWalkingTextWidth, offset); | ||
| vgui::surface()->DrawPrintText(walkingText, ARRAYSIZE(walkingText) - 1); | ||
|
|
||
| offset += textHeight; | ||
| } | ||
|
|
||
| void CNEOHud_WalkingIndicator::DrawNeoHudElement() | ||
| { | ||
| if (!m_bVisible || !ShouldDraw()) | ||
| return; | ||
|
|
||
| C_NEO_Player* pLocalPlayer = C_NEO_Player::GetLocalNEOPlayer(); | ||
| if (!pLocalPlayer) | ||
| return; | ||
|
|
||
| C_NEO_Player* pTargetPlayer = pLocalPlayer->IsObserver() && (pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE || pLocalPlayer->GetObserverMode() == OBS_MODE_CHASE) | ||
| ? assert_cast<C_NEO_Player *>(pLocalPlayer->GetObserverTarget()) | ||
| : pLocalPlayer; | ||
| if (!pTargetPlayer || !pTargetPlayer->IsAlive()) | ||
| return; | ||
|
|
||
| int offset = 0; | ||
| DrawRangeFinder(pTargetPlayer, offset); | ||
| DrawWalkingIndicator(pTargetPlayer, offset); | ||
| } | ||
|
|
||
| void CNEOHud_WalkingIndicator::Paint() | ||
| { | ||
| BaseClass::Paint(); | ||
| PaintNeoElement(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #pragma once | ||
|
|
||
| #include "neo_hud_childelement.h" | ||
| #include "hudelement.h" | ||
| #include <vgui_controls/Panel.h> | ||
|
|
||
| class CNEOHud_WalkingIndicator : public CNEOHud_ChildElement, public CHudElement, public vgui::Panel | ||
| { | ||
| DECLARE_CLASS_SIMPLE(CNEOHud_WalkingIndicator, Panel); | ||
|
|
||
| public: | ||
| CNEOHud_WalkingIndicator(const char *pElementName, vgui::Panel *parent = NULL); | ||
| void ApplySchemeSettings(vgui::IScheme* pScheme) override; | ||
|
|
||
| virtual void Paint() override; | ||
|
|
||
| protected: | ||
| virtual void UpdateStateForNeoHudElementDraw() override; | ||
| virtual void DrawNeoHudElement() override; | ||
| virtual ConVar* GetUpdateFrequencyConVar() const override; | ||
|
|
||
| private: | ||
| void DrawRangeFinder(C_NEO_Player* pPlayer, int &offset); | ||
| void DrawWalkingIndicator(C_NEO_Player* pPlayer, int &offset); | ||
|
|
||
| CPanelAnimationVarAliasType(bool, m_bVisible, "visible", "1", "bool"); | ||
|
|
||
| CPanelAnimationVarAliasType(int, m_iXpos, "xpos", "r203", "proportional_xpos"); | ||
|
Comment on lines
+27
to
+28
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the value supposed to be "203" instead of "r203" here, or is that a typo? Grepping around we also do it at https://github.com/NeotokyoRebuild/neo/blame/5cb282a7a0ea123a2b571c01c22e6f953aa69eb0/src/game/client/neo/ui/neo_hud_ammo.h#L40 but I was too lazy to expand the macros and figure out where this is parsed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. specifying proportional_xpos uses CProportionalIntWithScreenspacePropertyX, and in ExtractValue ComputePos checks whether the first character is an alignment character. The default value here should follow the default value in HudLayout.res where I actually use c30 and c40, meaning 30 pixels to the right and 40 pixels down from the center of the screen on 640x480, but actually once I remove the entry the text is nowhere near the center, so there must be some difference in how the value in hudlayout.res is handled compared to the default in this constructor 🤔 |
||
| CPanelAnimationVarAliasType(int, m_iYpos, "ypos", "446", "proportional_ypos"); | ||
|
|
||
| CPanelAnimationVar(float, m_flAnimationSpeed, "animationSpeed", "2"); | ||
|
|
||
| CPanelAnimationVarAliasType(Color, m_color, "color", COLOR_NEO_WHITE_STR, "Color"); | ||
| CPanelAnimationVarAliasType(Color, m_color2, "color2", "255 150 150 255", "Color"); | ||
| CPanelAnimationVar(vgui::HFont, m_hFont, "font", "NHudPanelText"); | ||
|
|
||
| private: | ||
| CNEOHud_WalkingIndicator(const CNEOHud_WalkingIndicator&other); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Seems like this couples the position of the range finder with the walking indicator, and also resets customized positions of the range finder with the disappearance of these convars. I suppose I'm fine with it because one can disable the walking indicator as a new feature that previously didn't exist and just weak the new hud config, but maybe a future refinement is to allow a player to customize these two elements differently. (on the other hand I see how text alignment can be hard and this could be a pain to align separately)