summaryrefslogtreecommitdiff
path: root/graphics/src/render.rs
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/src/render.rs')
-rw-r--r--graphics/src/render.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index 613763c..762827c 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -7,8 +7,9 @@ use std::{
use dungeon::{
Dungeon,
- entity::{Entity, EntityKind, Item, PLAYER_INVENTORY_SIZE, Player},
+ entity::{Entity, EntityKind, Item},
map::{Floor, MAP_SIZE, Tile},
+ player::{PLAYER_INVENTORY_SIZE, Player},
pos::{Direction, Pos},
};
use raylib::{
@@ -635,21 +636,11 @@ impl Renderer {
self.draw_text_vertical(r, b"INV", TEXT_X, UI_PADDING);
// Draw slots
- for idx in 0..PLAYER_INVENTORY_SIZE {
- if idx >= PLAYER_INVENTORY_SIZE {
- // This should never happen!
- // Maybe use a different type??
- break;
- }
-
- let slot_x = SLOTS_X + SLOT_LEN * idx;
+ for (idx, (opt_item, active)) in player.inventory.iter().enumerate() {
+ let slot_x = SLOTS_X + SLOT_LEN * downcast!(idx, u16);
// Draw slot container
- let tint = if (idx as usize) == player.active_inv_slot {
- Color::YELLOW
- } else {
- Color::WHITE
- };
+ let tint = if active { Color::YELLOW } else { Color::WHITE };
r.draw_atlas(
&self.textures.atlas,
ATLAS_INV_CONTAINER,
@@ -660,8 +651,8 @@ impl Renderer {
tint,
);
- if let Some(item) = player.inventory.get(idx as usize) {
- let tex = self.textures.item_texture(*item);
+ if let Some(item) = opt_item {
+ let tex = self.textures.item_texture(item);
const ITEM_PADDDING: u16 = UI_PADDING * 3;
let dest_rec = rect! {
slot_x + ITEM_PADDDING/2,