added active inventory slots

This commit is contained in:
Pfauenauge90
2019-06-29 02:11:53 +02:00
parent d9ab3ef76c
commit 12e7d749ec
2 changed files with 22 additions and 10 deletions

View File

@ -15,12 +15,13 @@ widget_ids! {
inv_scrollbar, inv_scrollbar,
inv_slot_0, inv_slot_0,
map_title, map_title,
inv_slot[],
} }
} }
#[derive(WidgetCommon)] #[derive(WidgetCommon)]
pub struct Bag<'a> { pub struct Bag<'a> {
inventory_space: u32, inventory_space: usize,
imgs: &'a Imgs, imgs: &'a Imgs,
_fonts: &'a Fonts, _fonts: &'a Fonts,
@ -29,7 +30,7 @@ pub struct Bag<'a> {
} }
impl<'a> Bag<'a> { impl<'a> Bag<'a> {
pub fn new(inventory_space: u32, imgs: &'a Imgs, _fonts: &'a Fonts) -> Self { pub fn new(inventory_space: usize, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
Self { Self {
inventory_space, inventory_space,
imgs, imgs,
@ -91,14 +92,25 @@ impl<'a> Widget for Bag<'a> {
.rgba(0.33, 0.33, 0.33, 1.0) .rgba(0.33, 0.33, 0.33, 1.0)
.set(state.ids.inv_scrollbar, ui); .set(state.ids.inv_scrollbar, ui);
if self.inventory_space > 0 { // Create available inventory slot widgets
// First Slot
dbg!(self.inventory_space);
if state.ids.inv_slot.len() < self.inventory_space {
state.update(|s| { s.ids.inv_slot.resize(self.inventory_space, &mut ui.widget_id_generator());});}
for i in 0..self.inventory_space {
let x = i % 5;
let y = i / 5;
Button::image(self.imgs.inv_slot) Button::image(self.imgs.inv_slot)
.top_left_with_margins_on(state.ids.inv_grid_1, 4.0, 4.0) .top_left_with_margins_on(state.ids.inv_alignment, 4.0 + y as f64 * (40.0 + 4.0), 4.0 + x as f64 * (40.0 + 4.0))
.w_h(10.0 * 4.0, 10.0 * 4.0) .w_h(40.0, 40.0)
.set(state.ids.inv_slot_0, ui); .set(state.ids.inv_slot[i], ui);
} }
// X-button // X-button
if Button::image(self.imgs.close_button) if Button::image(self.imgs.close_button)
.w_h(28.0, 28.0) .w_h(28.0, 28.0)

View File

@ -256,7 +256,7 @@ pub struct Hud {
imgs: Imgs, imgs: Imgs,
fonts: Fonts, fonts: Fonts,
new_messages: VecDeque<String>, new_messages: VecDeque<String>,
inventory_space: u32, inventory_space: usize,
show: Show, show: Show,
to_focus: Option<Option<widget::Id>>, to_focus: Option<Option<widget::Id>>,
force_ungrab: bool, force_ungrab: bool,
@ -486,7 +486,7 @@ impl Hud {
.set(self.ids.bag_space_add, ui_widgets) .set(self.ids.bag_space_add, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.inventory_space += 1; if self.inventory_space < 91 {self.inventory_space += 10;} else {}
}; };
} }