2022-02-02 11:52:19 -05:00
|
|
|
use ::rltk::prelude::*;
|
|
|
|
use ::rltk::Rltk;
|
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 drop_item_menu(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()
|
2022-02-02 11:52:19 -05:00
|
|
|
.filter(|item| item.1.owner == *player_entity)
|
|
|
|
.for_each(|item| items.push((item.0, get_item_display_name(&gs.ecs, item.0))));
|
2022-02-02 09:45:19 -05:00
|
|
|
|
2022-02-02 11:52:19 -05:00
|
|
|
let result = item_result_menu(
|
|
|
|
&mut draw_batch,
|
|
|
|
"Drop which item?",
|
|
|
|
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 Drop Item 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
|
|
|
}
|