2022-02-02 11:52:19 -05:00
|
|
|
use ::rltk::prelude::*;
|
2022-02-02 09:45:19 -05:00
|
|
|
use ::specs::prelude::*;
|
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
use super::{get_item_display_name, item_result_menu, ItemMenuResult};
|
|
|
|
use crate::components::InBackpack;
|
|
|
|
use crate::State;
|
2022-02-02 09:45:19 -05:00
|
|
|
|
|
|
|
pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
2022-02-02 11:52:19 -05:00
|
|
|
let mut draw_batch = DrawBatch::new();
|
|
|
|
|
2022-02-02 09:45:19 -05:00
|
|
|
let player_entity = gs.ecs.fetch::<Entity>();
|
|
|
|
let backpack = gs.ecs.read_storage::<InBackpack>();
|
|
|
|
let entities = gs.ecs.entities();
|
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
let mut items: Vec<(Entity, String)> = Vec::new();
|
|
|
|
(&entities, &backpack)
|
2022-02-02 09:45:19 -05:00
|
|
|
.join()
|
|
|
|
.filter(|item| item.1.owner == *player_entity)
|
2022-02-02 11:52:19 -05:00
|
|
|
.for_each(|item| items.push((item.0, get_item_display_name(&gs.ecs, item.0))));
|
|
|
|
|
|
|
|
let result = item_result_menu(&mut draw_batch, "Inventory", items.len(), &items, ctx.key);
|
2022-02-02 09:45:19 -05:00
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
draw_batch
|
|
|
|
.submit(6000)
|
|
|
|
.expect("Failed to batch render Inventory Menu");
|
2022-02-02 09:45:19 -05:00
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
result
|
2022-02-02 09:45:19 -05:00
|
|
|
}
|