showinventory runstate (draw nyi)

This commit is contained in:
Llywelwyn 2023-09-30 08:13:20 +01:00
parent 56f6cb6ae8
commit b524cc3b08
6 changed files with 191 additions and 175 deletions

View file

@ -273,7 +273,52 @@ impl State {
}
}
}
// RunState::ShowInventory
RunState::ShowInventory => {
let result = gui::show_inventory(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 is_ranged = self.ecs.read_storage::<Ranged>();
let ranged_item = is_ranged.get(item_entity);
if let Some(ranged_item) = ranged_item {
let is_aoe = self.ecs.read_storage::<AOE>();
let aoe_item = is_aoe.get(item_entity);
let bounds = camera::get_screen_bounds(&self.ecs, false);
let ppos = self.ecs.fetch::<Point>();
if let Some(aoe_item) = aoe_item {
new_runstate = RunState::ShowTargeting {
x: ppos.x + bounds.x_offset - bounds.min_x,
y: ppos.y + bounds.y_offset - bounds.min_y,
range: ranged_item.range,
item: item_entity,
aoe: aoe_item.radius,
};
} else {
new_runstate = RunState::ShowTargeting {
x: ppos.x + bounds.x_offset - bounds.min_x,
y: ppos.y + bounds.y_offset - bounds.min_y,
range: ranged_item.range,
item: item_entity,
aoe: 0,
};
}
} else {
let mut intent = self.ecs.write_storage::<WantsToUseItem>();
intent
.insert(*self.ecs.fetch::<Entity>(), WantsToUseItem {
item: item_entity,
target: None,
})
.expect("Unable to insert intent.");
new_runstate = RunState::Ticking;
}
}
}
}
// RunState::ShowDropItem
// RunState::ShowRemoveItem
// RunState::ShowTargeting
@ -562,49 +607,12 @@ impl State {
}
}
RunState::ShowInventory => {
let result = gui::show_inventory(self, ctx);
match result.0 {
let result = gui::ItemMenuResult::Cancel; //gui::show_inventory(self, ctx);
match result {
gui::ItemMenuResult::Cancel => {
new_runstate = RunState::AwaitingInput;
}
gui::ItemMenuResult::NoResponse => {}
gui::ItemMenuResult::Selected => {
let item_entity = result.1.unwrap();
let is_ranged = self.ecs.read_storage::<Ranged>();
let ranged_item = is_ranged.get(item_entity);
if let Some(ranged_item) = ranged_item {
let is_aoe = self.ecs.read_storage::<AOE>();
let aoe_item = is_aoe.get(item_entity);
let bounds = camera::get_screen_bounds(&self.ecs, false);
let ppos = self.ecs.fetch::<Point>();
if let Some(aoe_item) = aoe_item {
new_runstate = RunState::ShowTargeting {
x: ppos.x + bounds.x_offset - bounds.min_x,
y: ppos.y + bounds.y_offset - bounds.min_y,
range: ranged_item.range,
item: item_entity,
aoe: aoe_item.radius,
};
} else {
new_runstate = RunState::ShowTargeting {
x: ppos.x + bounds.x_offset - bounds.min_x,
y: ppos.y + bounds.y_offset - bounds.min_y,
range: ranged_item.range,
item: item_entity,
aoe: 0,
};
}
} else {
let mut intent = self.ecs.write_storage::<WantsToUseItem>();
intent
.insert(*self.ecs.fetch::<Entity>(), WantsToUseItem {
item: item_entity,
target: None,
})
.expect("Unable to insert intent.");
new_runstate = RunState::Ticking;
}
}
_ => {}
}
}
RunState::ShowDropItem => {