2020-04-04 05:40:00 +00:00
|
|
|
use super::item_imgs::{ItemImgs, ItemKey};
|
|
|
|
use crate::ui::slot::{ContentKey, SlotKinds, SlotManager};
|
2020-04-04 17:51:41 +00:00
|
|
|
use common::comp::{item::ItemKind, Inventory, Loadout};
|
2020-04-04 05:40:00 +00:00
|
|
|
use conrod_core::image;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, PartialEq)]
|
|
|
|
pub enum HudSlotKinds {
|
|
|
|
Inventory(InventorySlot),
|
|
|
|
Armor(ArmorSlot),
|
|
|
|
Hotbar(HotbarSlot),
|
2020-04-06 21:16:24 +00:00
|
|
|
//Spellbook(SpellbookSlot), TODO
|
2020-04-04 05:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub type HudSlotManager = SlotManager<HudSlotKinds>;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, PartialEq)]
|
|
|
|
pub struct InventorySlot(pub usize);
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, PartialEq)]
|
|
|
|
pub enum ArmorSlot {
|
2020-04-04 17:51:41 +00:00
|
|
|
Head,
|
2020-04-04 05:40:00 +00:00
|
|
|
Neck,
|
|
|
|
Shoulders,
|
|
|
|
Chest,
|
|
|
|
Hands,
|
2020-04-06 21:16:24 +00:00
|
|
|
Ring,
|
|
|
|
Lantern,
|
2020-04-04 05:40:00 +00:00
|
|
|
Back,
|
|
|
|
Belt,
|
|
|
|
Legs,
|
|
|
|
Feet,
|
|
|
|
Mainhand,
|
|
|
|
Offhand,
|
|
|
|
Tabard,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, PartialEq)]
|
|
|
|
pub enum HotbarSlot {
|
|
|
|
One,
|
|
|
|
Two,
|
|
|
|
Three,
|
|
|
|
Four,
|
|
|
|
Five,
|
|
|
|
Six,
|
|
|
|
Seven,
|
|
|
|
Eight,
|
|
|
|
Nine,
|
|
|
|
Ten,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ContentKey for InventorySlot {
|
|
|
|
type ContentSource = Inventory;
|
|
|
|
type ImageKey = ItemKey;
|
|
|
|
type ImageSource = ItemImgs;
|
|
|
|
|
|
|
|
fn image_key(&self, source: &Self::ContentSource) -> Option<Self::ImageKey> {
|
|
|
|
source.get(self.0).map(Into::into)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn amount(&self, source: &Self::ContentSource) -> Option<u32> {
|
|
|
|
source
|
|
|
|
.get(self.0)
|
|
|
|
.and_then(|item| match item.kind {
|
|
|
|
ItemKind::Tool { .. } | ItemKind::Armor { .. } => None,
|
|
|
|
ItemKind::Utility { amount, .. }
|
|
|
|
| ItemKind::Consumable { amount, .. }
|
|
|
|
| ItemKind::Ingredient { amount, .. } => Some(amount),
|
|
|
|
})
|
|
|
|
.filter(|amount| *amount > 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn image_id(key: &Self::ImageKey, source: &Self::ImageSource) -> image::Id {
|
|
|
|
source.img_id_or_not_found_img(key.clone())
|
|
|
|
}
|
2020-04-04 17:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ContentKey for ArmorSlot {
|
|
|
|
type ContentSource = Loadout;
|
|
|
|
type ImageKey = ItemKey;
|
|
|
|
type ImageSource = ItemImgs;
|
|
|
|
|
|
|
|
fn image_key(&self, source: &Self::ContentSource) -> Option<Self::ImageKey> {
|
|
|
|
let item = match self {
|
|
|
|
ArmorSlot::Shoulders => source.shoulder.as_ref(),
|
|
|
|
ArmorSlot::Chest => source.chest.as_ref(),
|
|
|
|
ArmorSlot::Belt => source.belt.as_ref(),
|
|
|
|
ArmorSlot::Hands => source.hand.as_ref(),
|
|
|
|
ArmorSlot::Legs => source.pants.as_ref(),
|
|
|
|
ArmorSlot::Feet => source.foot.as_ref(),
|
2020-04-06 21:16:24 +00:00
|
|
|
ArmorSlot::Back => source.back.as_ref(),
|
|
|
|
ArmorSlot::Ring => source.ring.as_ref(),
|
|
|
|
ArmorSlot::Neck => source.neck.as_ref(),
|
|
|
|
ArmorSlot::Head => source.head.as_ref(),
|
|
|
|
ArmorSlot::Lantern => source.lantern.as_ref(),
|
|
|
|
ArmorSlot::Tabard => source.tabard.as_ref(),
|
2020-04-06 00:03:59 +00:00
|
|
|
ArmorSlot::Mainhand => source.active_item.as_ref().map(|i| &i.item),
|
|
|
|
ArmorSlot::Offhand => source.second_item.as_ref().map(|i| &i.item),
|
2020-04-04 17:51:41 +00:00
|
|
|
_ => None,
|
|
|
|
};
|
2020-04-04 05:40:00 +00:00
|
|
|
|
2020-04-04 17:51:41 +00:00
|
|
|
item.map(Into::into)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn amount(&self, _: &Self::ContentSource) -> Option<u32> { None }
|
|
|
|
|
|
|
|
fn image_id(key: &Self::ImageKey, source: &Self::ImageSource) -> image::Id {
|
|
|
|
source.img_id_or_not_found_img(key.clone())
|
|
|
|
}
|
2020-04-04 05:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<InventorySlot> for HudSlotKinds {
|
|
|
|
fn from(inventory: InventorySlot) -> Self { Self::Inventory(inventory) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ArmorSlot> for HudSlotKinds {
|
|
|
|
fn from(armor: ArmorSlot) -> Self { Self::Armor(armor) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<HotbarSlot> for HudSlotKinds {
|
|
|
|
fn from(hotbar: HotbarSlot) -> Self { Self::Hotbar(hotbar) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SlotKinds for HudSlotKinds {}
|