From d789b0f62db7701bf873c67713d9b8b135dfaf57 Mon Sep 17 00:00:00 2001 From: futile Date: Sun, 20 Apr 2025 07:33:34 +0100 Subject: [PATCH] rework networking indicator dot --- src/features/game_networking.rs | 15 +-------------- src/gui/app.rs | 22 +++++++++++++--------- src/gui/colours.rs | 16 ++++++++++++++++ src/gui/mod.rs | 1 + src/util/consts.rs | 7 ------- 5 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 src/gui/colours.rs diff --git a/src/features/game_networking.rs b/src/features/game_networking.rs index 94f5a84..f22e8ab 100644 --- a/src/features/game_networking.rs +++ b/src/features/game_networking.rs @@ -1,7 +1,4 @@ -use crate::util::consts::{ - colours, - game::{EXE_ENHANCED, EXE_LEGACY}, -}; +use crate::util::consts::game::{EXE_ENHANCED, EXE_LEGACY}; use std::{ path::Path, time::{Duration, Instant}, @@ -44,16 +41,6 @@ impl From for BlockedStatus { } } -impl From for eframe::egui::Color32 { - fn from(value: BlockedStatus) -> Self { - match value { - BlockedStatus::Blocked => colours::RED, - BlockedStatus::Failed => colours::YELLOW, - BlockedStatus::Unblocked => colours::GREEN, - } - } -} - impl BlockedStatus { pub fn to_color32(self) -> eframe::egui::Color32 { self.into() diff --git a/src/gui/app.rs b/src/gui/app.rs index 05f975f..b780f96 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -139,9 +139,20 @@ impl App { .outer_margin(egui::vec2(0.0, -2.0)) .show(ui, |ui| { let response = ui.add_enabled_ui(self.flags.elevated, |ui| { - let label = ui.label("Game's network access"); + let label = ui.horizontal(|ui| { + let label = ui.label("Game's network access"); + ui.add_space(1.0); + ui.add( + egui::Image::new(egui::include_image!("../../assets/circle.svg")) + .max_size([4.0, 4.0].into()) + .tint(self.game_networking.blocked_status.to_color32()), + ) + .on_hover_text("This turns yellow if GTA Tools\ncannot find your game."); + self.game_networking.if_failed_return_to_unblocked(); + label + }); ui.horizontal(|ui| { - let available_width = label.rect.width(); + let available_width = label.inner.rect.width(); let spacing = ui.spacing().item_spacing.x; let button_width = (available_width - spacing) / 2.0; if ui @@ -156,13 +167,6 @@ impl App { { self.game_networking.unblock_all(); } - ui.add( - egui::Image::new(egui::include_image!("../../assets/circle.svg")) - .max_size([4.0, 4.0].into()) - .tint(self.game_networking.blocked_status.to_color32()), - ) - .on_hover_text("This turns yellow if GTA Tools\ncannot find your game."); - self.game_networking.if_failed_return_to_unblocked(); }); }); response.response.on_disabled_hover_text( diff --git a/src/gui/colours.rs b/src/gui/colours.rs new file mode 100644 index 0000000..8b04629 --- /dev/null +++ b/src/gui/colours.rs @@ -0,0 +1,16 @@ +use crate::features::game_networking::BlockedStatus; +use eframe::egui; + +pub const RED: egui::Color32 = egui::Color32::from_rgb(255, 128, 128); +pub const YELLOW: egui::Color32 = egui::Color32::from_rgb(255, 255, 128); +pub const GREEN: egui::Color32 = egui::Color32::from_rgb(128, 255, 128); + +impl From for egui::Color32 { + fn from(value: BlockedStatus) -> Self { + match value { + BlockedStatus::Blocked => RED, + BlockedStatus::Failed => YELLOW, + BlockedStatus::Unblocked => GREEN, + } + } +} diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 680f462..f281df6 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -1,4 +1,5 @@ mod app; +mod colours; mod debug; pub mod run; pub mod settings; diff --git a/src/util/consts.rs b/src/util/consts.rs index 83cd953..d50ef32 100644 --- a/src/util/consts.rs +++ b/src/util/consts.rs @@ -8,10 +8,3 @@ pub mod game { pub const EXE_LEGACY: &str = "GTA5.exe"; pub const WINDOW_TITLE: &str = "Grand Theft Auto V"; } - -pub mod colours { - use eframe::egui::Color32; - pub const RED: Color32 = Color32::from_rgb(249, 101, 84); - pub const YELLOW: Color32 = Color32::from_rgb(249, 236, 84); - pub const GREEN: Color32 = Color32::from_rgb(104, 249, 84); -}