From 0ddc6c8cd217dfff09b483e572b756c83595dad8 Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Tue, 5 Dec 2023 18:49:03 +0000 Subject: [PATCH] refactor: UI improvements Former-commit-id: 18ca9fe51ec1419b8e210894f2b299c43905f3a6 --- src/main.rs | 4 ++-- src/player.rs | 6 ++---- src/ui.rs | 31 ++++++++++++++++++++++--------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5571d77..90c78e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,9 +82,9 @@ fn setup(mut commands: Commands, asset_server: Res) { movement_speed: 512., rotation_speed: f32::to_radians(360.), - health: 0.4, + health: 10., health_max: 10., - stamina: 0.1, + stamina: 10., stamina_max: 10., defence: 40., diff --git a/src/player.rs b/src/player.rs index 15daa81..2616f0e 100644 --- a/src/player.rs +++ b/src/player.rs @@ -74,10 +74,8 @@ pub fn movement( movement_distance = blink_factor * player.movement_speed * 0.01; } - // Create the translation using the movement direction and distance - let translation_delta = movement_direction * movement_distance; - // Update the player translation with the created translation - transform.translation += translation_delta; + // Update the player translation with the translation + transform.translation += movement_direction * movement_distance; // Define the bounds of play (the window size) let window = windows.single_mut(); diff --git a/src/ui.rs b/src/ui.rs index 24fd957..80ce4c2 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -50,6 +50,12 @@ pub fn render_ui( let ctx = contexts.ctx_mut(); + let purple = HYPERNOVA.get("PURPLE").unwrap(); + let purple = egui::Color32::from_rgb(purple.0, purple.1, purple.2); + + let black = HYPERNOVA.get("BLACK").unwrap(); + let black = egui::Color32::from_rgb(black.0, black.1, black.2); + egui::Window::new("Login") .anchor(egui::Align2::CENTER_CENTER, egui::Vec2::new(0., 0.)) .resizable(false) @@ -60,12 +66,6 @@ pub fn render_ui( ui.set_height(window_height / 3.); ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| { - let purple = HYPERNOVA.get("PURPLE").unwrap(); - let purple = egui::Color32::from_rgb(purple.0, purple.1, purple.2); - - let black = HYPERNOVA.get("BLACK").unwrap(); - let black = egui::Color32::from_rgb(black.0, black.1, black.2); - // Define spacing between items (widgets) and add manually add some space // between the window border and the heading ui.spacing_mut().item_spacing = egui::vec2(0., 10.); @@ -108,11 +108,24 @@ pub fn render_ui( ..default() }) .show(ctx, |ui| { + ui.visuals_mut().menu_rounding = egui::Rounding::ZERO; + ui.visuals_mut().selection.bg_fill = purple; + let health = egui::widgets::ProgressBar::new(player.health) .desired_width(window_width / 10.); - let defence = egui::widgets::ProgressBar::new(player.defence) + let stamina = egui::widgets::ProgressBar::new(player.stamina) .desired_width(window_width / 10.); - ui.add(health); - ui.add(defence); + + egui::Grid::new("Stats") + .spacing(egui::Vec2::new(20., 10.)) + .show(ui, |ui| { + ui.label(egui::RichText::new("Health").color(purple)); + ui.add(health); + ui.end_row(); + + ui.label(egui::RichText::new("Stamina").color(purple)); + ui.add(stamina); + ui.end_row(); + }); }); }