refactor: UI improvements

Former-commit-id: 18ca9fe51ec1419b8e210894f2b299c43905f3a6
This commit is contained in:
Muhammad Nauman Raza 2023-12-05 18:49:03 +00:00
parent 76e3a0cc5d
commit 0ddc6c8cd2
Signed by: devraza
GPG key ID: 91EAD6081011574B
3 changed files with 26 additions and 15 deletions

View file

@ -82,9 +82,9 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
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.,

View file

@ -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();

View file

@ -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();
});
});
}