Skip to content

Commit 6563c59

Browse files
authored
Changing cl_neo_squad_hud_avatar_size updates star texture sizes immediately, also cl_neo_hud_centre convars (#1829)
* init * also solve the woldpos marker centre sizes not updating automatically * le epic linux fail * maybe inline breaking it * center -> centre, GetFloat, f
1 parent 4196f93 commit 6563c59

9 files changed

Lines changed: 84 additions & 44 deletions

src/game/client/neo/ui/neo_hud_ghost_cap_point.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@
1010

1111
ConVar neo_ghost_cap_point_hud_scale_factor("neo_ghost_cap_point_hud_scale_factor", "1", FCVAR_ARCHIVE,
1212
"Ghost cap HUD element scaling factor", true, 0.01, false, 0);
13-
ConVar cl_neo_hud_center_ghost_cap_size("cl_neo_hud_center_ghost_cap_size", "12.5", FCVAR_ARCHIVE,
14-
"HUD center size in percentage to fade ghost cap point.", true, 1, false, 0);
13+
14+
static float ghostCapViewCentreSize = 0;
15+
extern ConVar cl_neo_hud_centre_ghost_cap_size;
16+
void ghostCapViewCentreSizeChangeCallBack(IConVar* pConVar [[maybe_unused]] = nullptr, char const* pOldString [[maybe_unused]] = nullptr, float flOldValue [[maybe_unused]] = 0.f) {
17+
int w, h;
18+
vgui::surface()->GetScreenSize(w, h);
19+
20+
const auto widerAxis = Max(w, h);
21+
ghostCapViewCentreSize = widerAxis * (cl_neo_hud_centre_ghost_cap_size.GetFloat() / 100);
22+
}
23+
ConVar cl_neo_hud_centre_ghost_cap_size("cl_neo_hud_centre_ghost_cap_size", "12.5", FCVAR_ARCHIVE,
24+
"HUD center size in percentage to fade ghost cap point.", true, 1, false, 0, ghostCapViewCentreSizeChangeCallBack);
1525

1626
NEO_HUD_ELEMENT_DECLARE_FREQ_CVAR(GhostCapPoint, 0.01)
1727

@@ -48,10 +58,13 @@ void CNEOHud_GhostCapPoint::ApplySchemeSettings(vgui::IScheme *pScheme)
4858

4959
vgui::surface()->GetScreenSize(m_iPosX, m_iPosY);
5060
SetBounds(0, 0, m_iPosX, m_iPosY);
61+
62+
ghostCapViewCentreSizeChangeCallBack();
63+
}
5164

52-
// Override CNEOHud_WorldPosMarker's sizing with our own
53-
const int widerAxis = Max(m_viewWidth, m_viewHeight);
54-
m_viewCentreSize = widerAxis * (cl_neo_hud_center_ghost_cap_size.GetFloat() / 100.0f);
65+
float CNEOHud_GhostCapPoint::GetHudCentreSize() const
66+
{
67+
return ghostCapViewCentreSize;
5568
}
5669

5770
extern ConVar cl_neo_hud_worldpos_verbose;

src/game/client/neo/ui/neo_hud_ghost_cap_point.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class CNEOHud_GhostCapPoint : public CNEOHud_WorldPosMarker
1919
virtual void UpdateStateForNeoHudElementDraw() override;
2020
virtual void DrawNeoHudElement() override;
2121
virtual ConVar *GetUpdateFrequencyConVar() const override;
22+
23+
float GetHudCentreSize() const override;
2224

2325
void SetTeam(const int team) { m_iCapTeam = team; }
2426
void SetRadius(const float radius) { m_flMyRadius = radius; }

src/game/client/neo/ui/neo_hud_ghost_marker.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ using vgui::surface;
2525

2626
ConVar neo_ghost_marker_hud_scale_factor("neo_ghost_marker_hud_scale_factor", "1", FCVAR_ARCHIVE,
2727
"Ghost marker HUD element scaling factor", true, 0.01, false, 0);
28-
ConVar cl_neo_hud_center_ghost_marker_size("cl_neo_hud_center_ghost_marker_size", "12.5", FCVAR_ARCHIVE,
29-
"HUD center size in percentage to fade ghost marker.", true, 1, false, 0);
3028

29+
static float ghostViewCentreSize = 0;
30+
extern ConVar cl_neo_hud_centre_ghost_marker_size;
31+
void ghostViewCentreSizeChangeCallBack(IConVar* pConVar [[maybe_unused]] = nullptr, char const* pOldString [[maybe_unused]] = nullptr, float flOldValue [[maybe_unused]] = 0.f) {
32+
int w, h;
33+
vgui::surface()->GetScreenSize(w, h);
34+
35+
const auto widerAxis = Max(w, h);
36+
ghostViewCentreSize = widerAxis * (cl_neo_hud_centre_ghost_marker_size.GetFloat() / 100);
37+
}
38+
ConVar cl_neo_hud_centre_ghost_marker_size("cl_neo_hud_centre_ghost_marker_size", "12.5", FCVAR_ARCHIVE,
39+
"HUD center size in percentage to fade ghost marker.", true, 1, false, 0, ghostViewCentreSizeChangeCallBack);
3140

3241
DECLARE_NAMED_HUDELEMENT(CNEOHud_GhostMarker, neo_ghost_marker);
3342

@@ -71,13 +80,16 @@ void CNEOHud_GhostMarker::ApplySchemeSettings(vgui::IScheme *pScheme)
7180
int wide, tall;
7281
surface()->GetScreenSize(wide, tall);
7382
SetBounds(0, 0, wide, tall);
83+
84+
ghostViewCentreSizeChangeCallBack();
7485

7586
SetFgColor(COLOR_TRANSPARENT);
7687
SetBgColor(COLOR_TRANSPARENT);
88+
}
7789

78-
// Override CNEOHud_WorldPosMarker's sizing with our own
79-
const int widerAxis = Max(m_viewWidth, m_viewHeight);
80-
m_viewCentreSize = widerAxis * (cl_neo_hud_center_ghost_marker_size.GetFloat() / 100.0f);
90+
float CNEOHud_GhostMarker::GetHudCentreSize() const
91+
{
92+
return ghostViewCentreSize;
8193
}
8294

8395
extern ConVar cl_neo_hud_worldpos_verbose;

src/game/client/neo/ui/neo_hud_ghost_marker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class CNEOHud_GhostMarker : public CNEOHud_WorldPosMarker
1919

2020
virtual void ApplySchemeSettings(vgui::IScheme *pScheme) override;
2121
virtual void Paint() override;
22+
23+
float GetHudCentreSize() const override;
2224

2325
protected:
2426
virtual void UpdateStateForNeoHudElementDraw() override;

src/game/client/neo/ui/neo_hud_round_state.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ ConVar cl_neo_hud_team_swap_sides("cl_neo_hud_team_swap_sides", "1", FCVAR_ARCHI
3535
g_pNeoScoreBoard->UpdateTeamColumnsPosition(GetLocalPlayerTeam());
3636
});
3737
ConVar cl_neo_squad_hud_original("cl_neo_squad_hud_original", "1", FCVAR_ARCHIVE, "Use the old squad HUD", true, 0.0, true, 1.0);
38-
ConVar cl_neo_squad_hud_star_scale("cl_neo_squad_hud_star_scale", "0", FCVAR_ARCHIVE, "Scaling to apply from 1080p, 0 disables scaling");
38+
ConVar cl_neo_squad_hud_star_scale("cl_neo_squad_hud_star_scale", "0", FCVAR_ARCHIVE, "Scaling to apply from 1080p, 0 disables scaling",
39+
[](IConVar* pConVar, char const* pOldString, float flOldValue) -> void {
40+
if (g_pNeoHudRoundState)
41+
g_pNeoHudRoundState->UpdateStarSize();
42+
});
3943
extern ConVar sv_neo_dm_win_xp;
4044
extern ConVar cl_neo_streamermode;
4145
extern ConVar sv_neo_readyup_countdown;
@@ -160,6 +164,20 @@ void CNEOHud_RoundState::UpdateAvatarSize()
160164
}
161165
}
162166

167+
void CNEOHud_RoundState::UpdateStarSize()
168+
{
169+
IntDim res = {};
170+
surface()->GetScreenSize(res.w, res.h);
171+
const float scale = cl_neo_squad_hud_star_scale.GetFloat() != 0 ? cl_neo_squad_hud_star_scale.GetFloat() * (res.h / 1080.0f)
172+
: 1.f;
173+
174+
for (auto* star : m_ipStars)
175+
{
176+
star->SetWide(192 * scale);
177+
star->SetTall(48 * scale);
178+
}
179+
}
180+
163181
void CNEOHud_RoundState::ApplySchemeSettings(vgui::IScheme* pScheme)
164182
{
165183
BaseClass::ApplySchemeSettings(pScheme);
@@ -179,23 +197,6 @@ void CNEOHud_RoundState::ApplySchemeSettings(vgui::IScheme* pScheme)
179197
surface()->GetScreenSize(res.w, res.h);
180198
m_iXpos = (res.w / 2);
181199

182-
if (cl_neo_squad_hud_star_scale.GetFloat())
183-
{
184-
const float scale = cl_neo_squad_hud_star_scale.GetFloat() * (res.h / 1080.0);
185-
for (auto* star : m_ipStars)
186-
{
187-
star->SetWide(192 * scale);
188-
star->SetTall(48 * scale);
189-
}
190-
}
191-
else {
192-
for (auto* star : m_ipStars)
193-
{
194-
star->SetWide(192);
195-
star->SetTall(48);
196-
}
197-
}
198-
199200
// Box dimensions
200201
[[maybe_unused]] int iSmallFontWidth = 0;
201202
int iFontHeight = 0;
@@ -214,6 +215,7 @@ void CNEOHud_RoundState::ApplySchemeSettings(vgui::IScheme* pScheme)
214215
m_iBoxYEnd = Y_POS + iBoxHeight;
215216

216217
UpdateAvatarSize();
218+
UpdateStarSize();
217219

218220
m_rectLeftTeamTotalLogo = vgui::IntRect{
219221
.x0 = m_iLeftOffset,

src/game/client/neo/ui/neo_hud_round_state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CNEOHud_RoundState : public CNEOHud_ChildElement, public CHudElement, publ
3030
virtual void Paint();
3131

3232
void UpdateAvatarSize();
33+
void UpdateStarSize();
3334
// sunk cost fallacy and all that, in hindsight I should have made all of this only work with two teams and split players into separate resizeable cutlvectors by team instead of doing this minus index stuff.
3435
// basically any minusindexed n index works such that negative values give the -nth player in the player list, and any positive values give the (n - leftTeamTotal)th player in the list
3536
int GetEntityIndexAtPositionInHud(int position, bool positionIsZeroIndexed = false);

src/game/client/neo/ui/neo_hud_worldpos_marker.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@
66

77
using vgui::surface;
88

9-
ConVar cl_neo_hud_centre_size("cl_neo_hud_centre_size", "25", FCVAR_ARCHIVE,
10-
"HUD centre size in percentage to fade markers.", true, 1, false, 0);
9+
static float viewCentreSize = 0;
10+
extern ConVar cl_neo_hud_centre_size;
11+
void viewCentreSizeChangeCallBack(IConVar* pConVar [[maybe_unused]] = nullptr, char const* pOldString [[maybe_unused]] = nullptr, float flOldValue [[maybe_unused]] = 0.f) {
12+
int w, h;
13+
vgui::surface()->GetScreenSize(w, h);
14+
15+
const auto widerAxis = Max(w, h);
16+
viewCentreSize = widerAxis * (cl_neo_hud_centre_size.GetFloat() / 100);
17+
}
18+
ConVar cl_neo_hud_centre_size("cl_neo_hud_centre_size", "25", FCVAR_ARCHIVE, "HUD centre size in percentage to fade markers.", true, 1, false, 0, viewCentreSizeChangeCallBack);
1119
ConVar cl_neo_hud_worldpos_verbose("cl_neo_hud_worldpos_verbose", "1", FCVAR_ARCHIVE, "Display full world pos marker string", true, 0, true, 1);
1220

1321
CNEOHud_WorldPosMarker::CNEOHud_WorldPosMarker(const char* pElementName, Panel* parent)
1422
: CHudElement(pElementName),
1523
Panel(parent, pElementName),
1624
m_viewWidth(0),
1725
m_viewHeight(0),
18-
m_viewCentreSize(0),
1926
m_viewCentreX(0),
2027
m_viewCentreY(0)
2128
{
@@ -30,12 +37,16 @@ void CNEOHud_WorldPosMarker::ApplySchemeSettings(vgui::IScheme* pScheme)
3037
m_viewCentreX = m_viewWidth / 2;
3138
m_viewCentreY = m_viewHeight / 2;
3239

33-
auto widerAxis = Max(m_viewWidth, m_viewHeight);
34-
m_viewCentreSize = widerAxis * (static_cast<float>(cl_neo_hud_centre_size.GetInt()) / 100);
40+
viewCentreSizeChangeCallBack(); // value of viewCentreSize depends on screen size, so update during applySchemeSettings
3541

3642
BaseClass::ApplySchemeSettings(pScheme);
3743
}
3844

45+
float CNEOHud_WorldPosMarker::GetHudCentreSize() const
46+
{
47+
return viewCentreSize;
48+
}
49+
3950
void CNEOHud_WorldPosMarker::RectToPoint(int x0, int x1, int y0, int y1, int& x, int& y)
4051
{
4152
x = (x0 - x1) / 2;
@@ -50,14 +61,14 @@ float CNEOHud_WorldPosMarker::DistanceToCentre(int x, int y) const
5061

5162
float CNEOHud_WorldPosMarker::GetFadeValueTowardsScreenCentre(int x, int y) const
5263
{
53-
float innerArea = m_viewCentreSize / 2.f;
64+
float innerArea = GetHudCentreSize() / 2.f;
5465
auto dist = DistanceToCentre(x, y);
5566
if(dist <= innerArea)
5667
{
5768
return 1;
5869
}
5970

60-
if(dist <= m_viewCentreSize)
71+
if(dist <= GetHudCentreSize())
6172
{
6273
return (innerArea - (dist - innerArea)) / innerArea;
6374
}
@@ -67,14 +78,14 @@ float CNEOHud_WorldPosMarker::GetFadeValueTowardsScreenCentre(int x, int y) cons
6778

6879
float CNEOHud_WorldPosMarker::GetFadeValueTowardsScreenCentreInverted(int x, int y, float min) const
6980
{
70-
float innerArea = m_viewCentreSize / 2.f;
81+
float innerArea = GetHudCentreSize() / 2.f;
7182
auto dist = DistanceToCentre(x, y);
7283
if(dist <= innerArea)
7384
{
7485
return min;
7586
}
7687

77-
if(dist <= m_viewCentreSize)
88+
if(dist <= GetHudCentreSize())
7889
{
7990
return Max(min, (dist - innerArea) / innerArea);
8091
}
@@ -84,14 +95,14 @@ float CNEOHud_WorldPosMarker::GetFadeValueTowardsScreenCentreInverted(int x, int
8495

8596
float CNEOHud_WorldPosMarker::GetFadeValueTowardsScreenCentreInAndOut(int x, int y, float min) const
8697
{
87-
float innerArea = m_viewCentreSize / 2.f;
98+
float innerArea = GetHudCentreSize() / 2.f;
8899
auto dist = DistanceToCentre(x, y);
89100
if(dist <= innerArea)
90101
{
91102
return Max(min, dist / innerArea);
92103
}
93104

94-
if(dist <= m_viewCentreSize)
105+
if(dist <= GetHudCentreSize())
95106
{
96107
return (innerArea - (dist - innerArea)) / innerArea;
97108
}

src/game/client/neo/ui/neo_hud_worldpos_marker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ abstract_class CNEOHud_WorldPosMarker : public CNEOHud_ChildElement, public CHud
2121

2222
protected:
2323
int m_viewWidth, m_viewHeight;
24-
float m_viewCentreSize;
24+
25+
virtual float GetHudCentreSize() const;
2526

2627
static Color FadeColour(const Color& originalColour, float alphaMultiplier);
2728

src/game/client/neo/ui/neo_hud_worldpos_marker_generic.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "neo_gamerules.h"
88

99
extern ConVar neo_ghost_cap_point_hud_scale_factor;
10-
extern ConVar cl_neo_hud_center_ghost_cap_size;
1110

1211
NEO_HUD_ELEMENT_DECLARE_FREQ_CVAR( WorldPosMarker_Generic, 0 )
1312

@@ -52,9 +51,6 @@ void CNEOHud_WorldPosMarker_Generic::ApplySchemeSettings( vgui::IScheme *pScheme
5251

5352
vgui::surface()->GetScreenSize(m_iPosX, m_iPosY);
5453
SetBounds(0, 0, m_iPosX, m_iPosY);
55-
56-
const int widerAxis = max(m_viewWidth, m_viewHeight);
57-
m_viewCentreSize = widerAxis * (cl_neo_hud_center_ghost_cap_size.GetFloat() / 100.0f);
5854
}
5955

6056
void CNEOHud_WorldPosMarker_Generic::UpdateStateForNeoHudElementDraw()

0 commit comments

Comments
 (0)