inventory finishes

This commit is contained in:
Llywelwyn 2023-07-07 08:37:29 +01:00
parent aadb966fa4
commit f26adf352e
6 changed files with 126 additions and 5 deletions

View file

@ -37,6 +37,7 @@ pub enum RunState {
PlayerTurn,
MonsterTurn,
ShowInventory,
ShowDropItem,
}
pub struct State {
@ -59,6 +60,8 @@ impl State {
inventory_system.run_now(&self.ecs);
let mut potion_system = PotionUseSystem {};
potion_system.run_now(&self.ecs);
let mut drop_system = ItemDropSystem {};
drop_system.run_now(&self.ecs);
self.ecs.maintain();
}
}
@ -75,7 +78,9 @@ impl GameState for State {
let renderables = self.ecs.read_storage::<Renderable>();
let map = self.ecs.fetch::<Map>();
for (pos, render) in (&positions, &renderables).join() {
let mut data = (&positions, &renderables).join().collect::<Vec<_>>();
data.sort_by(|&a, &b| b.1.render_order.cmp(&a.1.render_order));
for (pos, render) in data.iter() {
let idx = map.xy_idx(pos.x, pos.y);
if map.visible_tiles[idx] {
ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph);
@ -124,6 +129,21 @@ impl GameState for State {
}
}
}
RunState::ShowDropItem => {
let result = gui::drop_item_menu(self, ctx);
match result.0 {
gui::ItemMenuResult::Cancel => new_runstate = RunState::AwaitingInput,
gui::ItemMenuResult::NoResponse => {}
gui::ItemMenuResult::Selected => {
let item_entity = result.1.unwrap();
let mut intent = self.ecs.write_storage::<WantsToDropItem>();
intent
.insert(*self.ecs.fetch::<Entity>(), WantsToDropItem { item: item_entity })
.expect("Unable to insert intent");
new_runstate = RunState::PlayerTurn;
}
}
}
}
{
@ -159,6 +179,7 @@ fn main() -> rltk::BError {
gs.ecs.register::<Potion>();
gs.ecs.register::<InBackpack>();
gs.ecs.register::<WantsToPickupItem>();
gs.ecs.register::<WantsToDropItem>();
gs.ecs.register::<WantsToDrinkPotion>();
let map = Map::new_map_rooms_and_corridors();