Skip to content

Commit

Permalink
Added a bullets fired hud element
Browse files Browse the repository at this point in the history
  • Loading branch information
druerridge committed Feb 26, 2019
1 parent b61bdb8 commit 55cd6a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/ui_widget_ids.rs
Expand Up @@ -11,6 +11,7 @@ widget_ids! {
rust_logo,
guns_hud[],
shots_taken_hud[],
bullets_remaining_hud[],

// Main Menu World List
world_list[],
Expand Down
24 changes: 21 additions & 3 deletions src/world.rs
Expand Up @@ -204,9 +204,11 @@ impl World {

// todo: gif of ctrl+f of shots_taken in our codebase
fn update_ui(&self, ui_bundle: &mut UiBundle) {
// TODO: Please help.
let gun_templates = &self.player.borrow().gun_templates;
ui_bundle.ids.guns_hud.resize(gun_templates.len(), &mut ui_bundle.conrod_ui.widget_id_generator());
ui_bundle.ids.shots_taken_hud.resize(gun_templates.len(), &mut ui_bundle.conrod_ui.widget_id_generator());
ui_bundle.ids.bullets_remaining_hud.resize(gun_templates.len(), &mut ui_bundle.conrod_ui.widget_id_generator());

let mut ui_cell = ui_bundle.conrod_ui.set_widgets();
conrod_core::widget::Canvas::new()
Expand All @@ -227,8 +229,8 @@ impl World {
let mut id_gun_right = ui_bundle.ids.canvas;
let mut width_gun_right = 0.0;
for i in 0..gun_templates.len() {
// Draw gun texture & highlight selected
let is_selected_gun = i == self.player.borrow().current_gun_template_index;

let gun_image_id = if is_selected_gun {
self.player.borrow().gun_templates[i].borrow().selected_gun_image_id
} else {
Expand All @@ -252,20 +254,36 @@ impl World {
}
image.set(ui_bundle.ids.guns_hud[i], &mut ui_cell);

let shots_taken_count = if self.player.borrow().gun_templates[i].borrow().has_gun_depth() {
// draw guns depth remaining
let gun_depth_remaining_text = if self.player.borrow().gun_templates[i].borrow().has_gun_depth() {
let shots_taken = self.player.borrow().gun_templates[i].borrow().shots_taken;
let gun_depth = self.player.borrow().gun_templates[i].borrow().get_gun_depth();
format!("{}/{}", gun_depth - shots_taken, gun_depth)
} else {
"∞".to_string()
};

conrod_core::widget::Text::new(shots_taken_count.as_str())
conrod_core::widget::Text::new(gun_depth_remaining_text.as_str())
.font_size(18)
.color(conrod_core::color::WHITE)
.mid_bottom_of(ui_bundle.ids.guns_hud[i])
.set(ui_bundle.ids.shots_taken_hud[i], &mut ui_cell);

// draw bullets remaining
let bullets_remaining = if self.player.borrow().gun_templates[i].borrow().has_shot_bullet {
0
} else {
1
};

let bullets_remaining_text = format!("{}/{}", bullets_remaining, 1);

conrod_core::widget::Text::new(bullets_remaining_text.as_str())
.font_size(18)
.color(conrod_core::color::WHITE)
.down_from(ui_bundle.ids.shots_taken_hud[i], 18.0)
.set(ui_bundle.ids.bullets_remaining_hud[i], &mut ui_cell);

id_gun_right = ui_bundle.ids.guns_hud[i];
width_gun_right = gun_texture.get_width() as f64;
}
Expand Down

0 comments on commit 55cd6a5

Please sign in to comment.