refactor: UI improvements
Former-commit-id: 18ca9fe51ec1419b8e210894f2b299c43905f3a6
This commit is contained in:
parent
76e3a0cc5d
commit
0ddc6c8cd2
3 changed files with 26 additions and 15 deletions
|
@ -82,9 +82,9 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
movement_speed: 512.,
|
movement_speed: 512.,
|
||||||
rotation_speed: f32::to_radians(360.),
|
rotation_speed: f32::to_radians(360.),
|
||||||
|
|
||||||
health: 0.4,
|
health: 10.,
|
||||||
health_max: 10.,
|
health_max: 10.,
|
||||||
stamina: 0.1,
|
stamina: 10.,
|
||||||
stamina_max: 10.,
|
stamina_max: 10.,
|
||||||
|
|
||||||
defence: 40.,
|
defence: 40.,
|
||||||
|
|
|
@ -74,10 +74,8 @@ pub fn movement(
|
||||||
movement_distance = blink_factor * player.movement_speed * 0.01;
|
movement_distance = blink_factor * player.movement_speed * 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the translation using the movement direction and distance
|
// Update the player translation with the translation
|
||||||
let translation_delta = movement_direction * movement_distance;
|
transform.translation += movement_direction * movement_distance;
|
||||||
// Update the player translation with the created translation
|
|
||||||
transform.translation += translation_delta;
|
|
||||||
|
|
||||||
// Define the bounds of play (the window size)
|
// Define the bounds of play (the window size)
|
||||||
let window = windows.single_mut();
|
let window = windows.single_mut();
|
||||||
|
|
31
src/ui.rs
31
src/ui.rs
|
@ -50,6 +50,12 @@ pub fn render_ui(
|
||||||
|
|
||||||
let ctx = contexts.ctx_mut();
|
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")
|
egui::Window::new("Login")
|
||||||
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::new(0., 0.))
|
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::new(0., 0.))
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
|
@ -60,12 +66,6 @@ pub fn render_ui(
|
||||||
ui.set_height(window_height / 3.);
|
ui.set_height(window_height / 3.);
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| {
|
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
|
// Define spacing between items (widgets) and add manually add some space
|
||||||
// between the window border and the heading
|
// between the window border and the heading
|
||||||
ui.spacing_mut().item_spacing = egui::vec2(0., 10.);
|
ui.spacing_mut().item_spacing = egui::vec2(0., 10.);
|
||||||
|
@ -108,11 +108,24 @@ pub fn render_ui(
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.show(ctx, |ui| {
|
.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)
|
let health = egui::widgets::ProgressBar::new(player.health)
|
||||||
.desired_width(window_width / 10.);
|
.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.);
|
.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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue