Skip to content
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

feat: Add sar_velocitygraph_show_line #276

Merged
merged 8 commits into from
Sep 2, 2024
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
1 change: 1 addition & 0 deletions docs/cvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@
|sar_velocitygraph|0|Shows velocity graph.|
|sar_velocitygraph_background|0|Background of velocity graph.|
|sar_velocitygraph_font_index|21|Font index of velocity graph.|
|sar_velocitygraph_show_line|1|Shows line for velocity graph.|
|sar_velocitygraph_rainbow|0|Rainbow mode of velocity graph text.|
|sar_velocitygraph_show_speed_on_graph|1|Show speed between jumps.|
|sar_velocitygraph_x|-250|Velocity graph x axis offset.|
Expand Down
38 changes: 20 additions & 18 deletions src/Features/Hud/VelocityGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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

if (sar_velocitygraph_background.GetBool())
surface->DrawRect({0, 0, 0, 192}, graphPos - Vector2<int>(5, 150 + 5), graphPos + Vector2<int>(5 + 500, 5));
bool should_draw_takeoff = !last_on_ground[slot] || take_off_display_timeout[slot] > engine->GetClientTime();
int recentSpeed = velocityStamps[slot][velocityStamps[slot].size - 10].speed;
Color c = Color(30, 255, 109);
if (sar_velocitygraph_rainbow.GetBool()) {
c = Utils::HSVToRGB(speed, 100, 100);
} else if (std::abs(speed - recentSpeed) < 5) {
c = Color(255, 199, 89);
} else if (speed < recentSpeed + 5) {
c = Color(255, 119, 119);
}

auto font = scheme->GetFontByID(sar_velocitygraph_font_index.GetInt());
auto length = surface->GetFontLength(font, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);

surface->DrawTxt(font, graphPos.x + 250 - length / 2, graphPos.y + 25, c, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);

if (!sar_velocitygraph_show_line.GetBool()) return;

for (int i = 1; i < velocityStamps[slot].size - 1; i++) {
const auto current = velocityStamps[slot][i];
Expand All @@ -102,28 +118,14 @@ void VelocityGraph::Paint(int slot) {
Color(255, 255, 255), std::to_string(next.speed).c_str());
}
}

surface->DrawColoredLine(
graphPos + Vector2<int>(i - 1, -current_speed),
graphPos + Vector2<int>(i, -next_speed),
Color(255, 255, 255));
}

bool should_draw_takeoff = !last_on_ground[slot] || take_off_display_timeout[slot] > engine->GetClientTime();
int recentSpeed = velocityStamps[slot][velocityStamps[slot].size - 10].speed;
Color c = Color(30, 255, 109);
if (sar_velocitygraph_rainbow.GetBool()) {
c = Utils::HSVToRGB(speed, 100, 100);
} else if (std::abs(speed - recentSpeed) < 5) {
c = Color(255, 199, 89);
} else if (speed < recentSpeed + 5) {
c = Color(255, 119, 119);
}

auto font = scheme->GetFontByID(sar_velocitygraph_font_index.GetInt());
auto length = surface->GetFontLength(font, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);

surface->DrawTxt(font, graphPos.x + 250 - length / 2, graphPos.y + 25, c, should_draw_takeoff ? "%i (%i)\n" : "%i", speed, take_off[slot]);
if (sar_velocitygraph_background.GetBool())
surface->DrawRect({0, 0, 0, 192}, graphPos - Vector2<int>(5, 150 + 5), graphPos + Vector2<int>(5 + 500, 5));
}
bool VelocityGraph::GetCurrentSize(int &xSize, int &ySize) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/Features/Hud/VelocityGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern VelocityGraph *velocityGraph;

extern Variable sar_velocitygraph;
extern Variable sar_velocitygraph_font_index;
extern Variable sar_velocitygraph_show_line;
extern Variable sar_velocitygraph_x;
extern Variable sar_velocitygraph_y;
extern Variable sar_velocitygraph_background;
Expand Down