Skip to content

Commit c072a71

Browse files
kipod8ThisAMJ
authored andcommitted
feat: sar_velocitygraph_show_line (#276)
Added "sar_velocitygraph_show_line" which when set to 0 (1 by default), keeps only the speedometer from the velocity graph giving us a speedometer like in Half-Life 1. This displays our velocity separate from the HUD in the bottom middle of our screen nicely, so we can more easily see it whilst bunnyhopping.
1 parent 78e5e34 commit c072a71

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

docs/cvars.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@
638638
|sar_velocitygraph|0|Shows velocity graph.|
639639
|sar_velocitygraph_background|0|Background of velocity graph.|
640640
|sar_velocitygraph_font_index|21|Font index of velocity graph.|
641+
|sar_velocitygraph_show_line|1|Shows line for velocity graph.|
641642
|sar_velocitygraph_rainbow|0|Rainbow mode of velocity graph text.|
642643
|sar_velocitygraph_show_speed_on_graph|1|Show speed between jumps.|
643644
|sar_velocitygraph_x|-250|Velocity graph x axis offset.|

src/Features/Hud/VelocityGraph.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
Variable sar_velocitygraph("sar_velocitygraph", "0", "Shows velocity graph.\n");
1616
Variable sar_velocitygraph_font_index("sar_velocitygraph_font_index", "21", 0, "Font index of velocity graph.\n"); // 21 looks pretty good
17+
Variable sar_velocitygraph_show_line("sar_velocitygraph_show_line", "1", "Shows line for velocity graph.\n");
1718
Variable sar_velocitygraph_x("sar_velocitygraph_x", "-250", "Velocity graph x axis offset.\n");
1819
Variable sar_velocitygraph_y("sar_velocitygraph_y", "-175", "Velocity graph y axis offset.\n");
1920
Variable sar_velocitygraph_background("sar_velocitygraph_background", "0", "Background of velocity graph.\n"); // imo this should be off by default
@@ -81,8 +82,23 @@ void VelocityGraph::Paint(int slot) {
8182
const Vector2<int> graphPos = Vector2<int>(x / 2, y) +
8283
Vector2<int>(sar_velocitygraph_x.GetInt(), sar_velocitygraph_y.GetInt());
8384

84-
if (sar_velocitygraph_background.GetBool())
85-
surface->DrawRect({0, 0, 0, 192}, graphPos - Vector2<int>(5, 150 + 5), graphPos + Vector2<int>(5 + 500, 5));
85+
bool should_draw_takeoff = !last_on_ground[slot] || take_off_display_timeout[slot] > engine->GetClientTime();
86+
int recentSpeed = velocityStamps[slot][velocityStamps[slot].size - 10].speed;
87+
Color c = Color(30, 255, 109);
88+
if (sar_velocitygraph_rainbow.GetBool()) {
89+
c = Utils::HSVToRGB(speed, 100, 100);
90+
} else if (std::abs(speed - recentSpeed) < 5) {
91+
c = Color(255, 199, 89);
92+
} else if (speed < recentSpeed + 5) {
93+
c = Color(255, 119, 119);
94+
}
95+
96+
auto font = scheme->GetFontByID(sar_velocitygraph_font_index.GetInt());
97+
auto length = surface->GetFontLength(font, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);
98+
99+
surface->DrawTxt(font, graphPos.x + 250 - length / 2, graphPos.y + 25, c, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);
100+
101+
if (!sar_velocitygraph_show_line.GetBool()) return;
86102

87103
for (int i = 1; i < velocityStamps[slot].size - 1; i++) {
88104
const auto current = velocityStamps[slot][i];
@@ -102,28 +118,14 @@ void VelocityGraph::Paint(int slot) {
102118
Color(255, 255, 255), std::to_string(next.speed).c_str());
103119
}
104120
}
105-
106121
surface->DrawColoredLine(
107122
graphPos + Vector2<int>(i - 1, -current_speed),
108123
graphPos + Vector2<int>(i, -next_speed),
109124
Color(255, 255, 255));
110125
}
111126

112-
bool should_draw_takeoff = !last_on_ground[slot] || take_off_display_timeout[slot] > engine->GetClientTime();
113-
int recentSpeed = velocityStamps[slot][velocityStamps[slot].size - 10].speed;
114-
Color c = Color(30, 255, 109);
115-
if (sar_velocitygraph_rainbow.GetBool()) {
116-
c = Utils::HSVToRGB(speed, 100, 100);
117-
} else if (std::abs(speed - recentSpeed) < 5) {
118-
c = Color(255, 199, 89);
119-
} else if (speed < recentSpeed + 5) {
120-
c = Color(255, 119, 119);
121-
}
122-
123-
auto font = scheme->GetFontByID(sar_velocitygraph_font_index.GetInt());
124-
auto length = surface->GetFontLength(font, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);
125-
126-
surface->DrawTxt(font, graphPos.x + 250 - length / 2, graphPos.y + 25, c, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);
127+
if (sar_velocitygraph_background.GetBool())
128+
surface->DrawRect({0, 0, 0, 192}, graphPos - Vector2<int>(5, 150 + 5), graphPos + Vector2<int>(5 + 500, 5));
127129
}
128130
bool VelocityGraph::GetCurrentSize(int &xSize, int &ySize) {
129131
return false;

src/Features/Hud/VelocityGraph.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern VelocityGraph *velocityGraph;
1616

1717
extern Variable sar_velocitygraph;
1818
extern Variable sar_velocitygraph_font_index;
19+
extern Variable sar_velocitygraph_show_line;
1920
extern Variable sar_velocitygraph_x;
2021
extern Variable sar_velocitygraph_y;
2122
extern Variable sar_velocitygraph_background;

0 commit comments

Comments
 (0)