Skip to content

Commit

Permalink
Small/Big Bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Fotonnn committed Oct 10, 2023
1 parent e702650 commit 4b19454
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
66 changes: 41 additions & 25 deletions controller/src/enhancements/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,44 +350,60 @@ impl Enhancement for PlayerESP {
.build();

if settings.esp_health_bar {
let bar_height = vmax.y - vmin.y; // height = box height
let bar_height = vmax.y - vmin.y; // Altura da caixa

let player_health = entry.player_health as f32;
let clamped_player_health = player_health.clamp(0.0, HEALTH_BAR_MAX_HEALTH);
let health_percentage = clamped_player_health / HEALTH_BAR_MAX_HEALTH;
let filled_height = bar_height * health_percentage;
let clamped_player_health =
player_health.clamp(0.0, HEALTH_BAR_MAX_HEALTH);
let health_percentage =
clamped_player_health / HEALTH_BAR_MAX_HEALTH;
let filled_height = bar_height * health_percentage;

let border_color = [0.0, 0.0, 0.0, esp_color[3]];

//+ and - -> align the bar and border perfectly.

// Determine a largura com base em settings.esp_health_bar_width
let bar_width = if settings.esp_health_bar_size {
6.0 // Largura da barra grande
} else {
1.0 // Largura da barra pequena
};

// Ajuste a posição X com base em settings.esp_health_bar_width
let bar_x = if settings.esp_health_bar_size {
vmin.x - bar_width + 1.0 // Barra grande
} else {
vmin.x + 1.0 // Barra pequena
};
// Adicione a borda
draw.add_rect(
[vmin.x - 6.0, vmax.y - 1.0], // upper-left
[vmin.x + 1.0, vmin.y + 1.0], //lower-right
[vmin.x - bar_width, vmax.y - 1.0], // Canto superior esquerdo
[vmin.x + 1.0, vmin.y + 1.0], // Canto inferior direito
border_color,
)
.build();

if settings.rainbow_health_bar {
let rainbow_color =
view.calculate_rainbow_color(player_health as f32, *esp_color);
draw.add_rect(
[vmin.x - 5.0, vmax.y - 1.0], // upper-left
[vmin.x, (vmax.y + 1.0) - filled_height], // lower-right
rainbow_color,
)
.filled(true)
.build();
let rainbow_color = view
.calculate_rainbow_color(player_health as f32, *esp_color);
// Adicione a barra de saúde
draw.add_rect(
[bar_x, vmax.y - 1.0], // Canto superior esquerdo
[vmin.x, (vmax.y + 1.0) - filled_height], // Canto inferior direito
rainbow_color,
)
.filled(true)
.build();
} else {
let health_color =
view.calculate_health_color(health_percentage, *esp_color);
draw.add_rect(
[vmin.x - 5.0, vmax.y - 1.0], // upper-left
[vmin.x, (vmax.y + 1.0) - filled_height], // lower-right
health_color,
)
.filled(true)
.build();
}
draw.add_rect(
[bar_x, vmax.y - 1.0], // Canto superior esquerdo
[vmin.x, (vmax.y + 1.0) - filled_height], // Canto inferior direito
health_color,
)
.filled(true)
.build();
}
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions controller/src/settings/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ fn default_esp_skeleton_thickness() -> f32 {
fn default_esp_boxes_thickness() -> f32 {
3.0
}
fn default_esp_health_bar_width() -> f32 {
3.5
}
fn default_u32<const V: u32>() -> u32 {
V
}
Expand Down Expand Up @@ -95,8 +92,8 @@ pub struct AppSettings {
#[serde(default = "bool_false")]
pub esp_health_bar: bool,

#[serde(default = "default_esp_health_bar_width")]
pub esp_health_bar_width: f32,
#[serde(default = "bool_false")]
pub esp_health_bar_size: bool,

#[serde(default = "bool_false")]
pub rainbow_health_bar: bool,
Expand Down
3 changes: 1 addition & 2 deletions controller/src/settings/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ impl SettingsUI {
ui.checkbox(obfstr!("2DBOX: Show Health Bar"), &mut settings.esp_health_bar);
if settings.esp_health_bar {
ui.same_line();
ui.slider_config(obfstr!("Width"), 1.0, 10.0)
.build(&mut settings.esp_health_bar_width);
ui.checkbox(obfstr!("Big bar"), &mut settings.esp_health_bar_size);
ui.checkbox(obfstr!("Rainbow Health Bar (Random colors!)"), &mut settings.rainbow_health_bar);
}
}
Expand Down

0 comments on commit 4b19454

Please sign in to comment.