mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Use new slot widget for armor slots
This commit is contained in:
parent
968c064874
commit
0b932ae99a
@ -387,6 +387,8 @@ impl Client {
|
|||||||
|
|
||||||
pub fn inventories(&self) -> ReadStorage<comp::Inventory> { self.state.read_storage() }
|
pub fn inventories(&self) -> ReadStorage<comp::Inventory> { self.state.read_storage() }
|
||||||
|
|
||||||
|
pub fn loadouts(&self) -> ReadStorage<comp::Loadout> { self.state.read_storage() }
|
||||||
|
|
||||||
/// Send a chat message to the server.
|
/// Send a chat message to the server.
|
||||||
pub fn send_chat(&mut self, message: String) {
|
pub fn send_chat(&mut self, message: String) {
|
||||||
match validate_chat_msg(&message) {
|
match validate_chat_msg(&message) {
|
||||||
|
@ -7,6 +7,15 @@ use vek::*;
|
|||||||
/// Default duration before an input is considered 'held'.
|
/// Default duration before an input is considered 'held'.
|
||||||
pub const DEFAULT_HOLD_DURATION: Duration = Duration::from_millis(200);
|
pub const DEFAULT_HOLD_DURATION: Duration = Duration::from_millis(200);
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub enum InventoryManip {
|
||||||
|
Pickup(Uid),
|
||||||
|
Collect(Vec3<i32>),
|
||||||
|
Use(usize),
|
||||||
|
Swap(usize, usize),
|
||||||
|
Drop(usize),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum ControlEvent {
|
pub enum ControlEvent {
|
||||||
Mount(Uid),
|
Mount(Uid),
|
||||||
@ -230,12 +239,3 @@ pub struct Mounting(pub Uid);
|
|||||||
impl Component for Mounting {
|
impl Component for Mounting {
|
||||||
type Storage = FlaggedStorage<Self, IDVStorage<Self>>;
|
type Storage = FlaggedStorage<Self, IDVStorage<Self>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
||||||
pub enum InventoryManip {
|
|
||||||
Pickup(Uid),
|
|
||||||
Collect(Vec3<i32>),
|
|
||||||
Use(usize),
|
|
||||||
Swap(usize, usize),
|
|
||||||
Drop(usize),
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::{
|
use super::{
|
||||||
img_ids::{Imgs, ImgsRot},
|
img_ids::{Imgs, ImgsRot},
|
||||||
item_imgs::ItemImgs,
|
item_imgs::ItemImgs,
|
||||||
slot_kinds::{HudSlotManager, InventorySlot},
|
slot_kinds::{ArmorSlot, HudSlotManager, InventorySlot},
|
||||||
Event as HudEvent, Show, CRITICAL_HP_COLOR, LOW_HP_COLOR, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
|
Event as HudEvent, Show, CRITICAL_HP_COLOR, LOW_HP_COLOR, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
|
||||||
XP_COLOR,
|
XP_COLOR,
|
||||||
};
|
};
|
||||||
@ -47,7 +47,7 @@ widget_ids! {
|
|||||||
tab_2,
|
tab_2,
|
||||||
tab_3,
|
tab_3,
|
||||||
tab_4,
|
tab_4,
|
||||||
//Stats
|
// Stats
|
||||||
stats_alignment,
|
stats_alignment,
|
||||||
level,
|
level,
|
||||||
exp_rectangle,
|
exp_rectangle,
|
||||||
@ -57,36 +57,23 @@ widget_ids! {
|
|||||||
divider,
|
divider,
|
||||||
statnames,
|
statnames,
|
||||||
stats,
|
stats,
|
||||||
//Armor Slots
|
// Armor Slots
|
||||||
slots_bg,
|
slots_bg,
|
||||||
head_bg,
|
head_slot,
|
||||||
neck_bg,
|
neck_slot,
|
||||||
chest_bg,
|
chest_slot,
|
||||||
shoulder_bg,
|
shoulders_slot,
|
||||||
hands_bg,
|
hands_slot,
|
||||||
legs_bg,
|
legs_slot,
|
||||||
belt_bg,
|
belt_slot,
|
||||||
ring_r_bg,
|
ring_r_slot,
|
||||||
ring_l_bg,
|
ring_l_slot,
|
||||||
foot_bg,
|
feet_slot,
|
||||||
back_bg,
|
back_slot,
|
||||||
tabard_bg,
|
tabard_slot,
|
||||||
mainhand_bg,
|
mainhand_slot,
|
||||||
offhand_bg,
|
offhand_slot,
|
||||||
head_ico,
|
// ???
|
||||||
neck_ico,
|
|
||||||
chest_ico,
|
|
||||||
shoulder_ico,
|
|
||||||
hands_ico,
|
|
||||||
legs_ico,
|
|
||||||
belt_ico,
|
|
||||||
ring_r_ico,
|
|
||||||
ring_l_ico,
|
|
||||||
foot_ico,
|
|
||||||
back_ico,
|
|
||||||
tabard_ico,
|
|
||||||
mainhand_ico,
|
|
||||||
offhand_ico,
|
|
||||||
end_ico,
|
end_ico,
|
||||||
fit_ico,
|
fit_ico,
|
||||||
wp_ico,
|
wp_ico,
|
||||||
@ -143,7 +130,6 @@ impl<'a> Bag<'a> {
|
|||||||
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
ids: Ids,
|
ids: Ids,
|
||||||
selected_slot: Option<usize>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
@ -160,7 +146,6 @@ impl<'a> Widget for Bag<'a> {
|
|||||||
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||||
State {
|
State {
|
||||||
ids: Ids::new(id_gen),
|
ids: Ids::new(id_gen),
|
||||||
selected_slot: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,9 +158,15 @@ impl<'a> Widget for Bag<'a> {
|
|||||||
|
|
||||||
let invs = self.client.inventories();
|
let invs = self.client.inventories();
|
||||||
let inventory = match invs.get(self.client.entity()) {
|
let inventory = match invs.get(self.client.entity()) {
|
||||||
Some(inv) => inv,
|
Some(i) => i,
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
|
let loadouts = self.client.loadouts();
|
||||||
|
let loadout = match loadouts.get(self.client.entity()) {
|
||||||
|
Some(l) => l,
|
||||||
|
None => return None,
|
||||||
|
};
|
||||||
|
|
||||||
let exp_percentage = (self.stats.exp.current() as f64) / (self.stats.exp.maximum() as f64);
|
let exp_percentage = (self.stats.exp.current() as f64) / (self.stats.exp.maximum() as f64);
|
||||||
let exp_treshold = format!(
|
let exp_treshold = format!(
|
||||||
"{}/{} {}",
|
"{}/{} {}",
|
||||||
@ -322,174 +313,173 @@ impl<'a> Widget for Bag<'a> {
|
|||||||
.color(Some(UI_HIGHLIGHT_0))
|
.color(Some(UI_HIGHLIGHT_0))
|
||||||
.set(state.ids.slots_bg, ui);*/
|
.set(state.ids.slots_bg, ui);*/
|
||||||
// Armor Slots
|
// Armor Slots
|
||||||
//Head
|
let mut slot_maker = SlotMaker {
|
||||||
Image::new(self.imgs.armor_slot)
|
background: self.imgs.armor_slot,
|
||||||
|
selected_background: self.imgs.armor_slot,
|
||||||
|
background_color: Some(UI_HIGHLIGHT_0),
|
||||||
|
content_size: Vec2::broadcast(30.0),
|
||||||
|
selected_content_size: Vec2::broadcast(32.0),
|
||||||
|
amount_font: self.fonts.cyri.conrod_id,
|
||||||
|
amount_margins: Vec2::new(-4.0, 0.0),
|
||||||
|
amount_font_size: self.fonts.cyri.scale(12),
|
||||||
|
amount_text_color: TEXT_COLOR,
|
||||||
|
content_source: loadout,
|
||||||
|
image_source: self.item_imgs,
|
||||||
|
slot_manager: Some(self.slot_manager),
|
||||||
|
};
|
||||||
|
// Head
|
||||||
|
let (title, desc) = ("Helmet", "");
|
||||||
|
slot_maker
|
||||||
|
.fabricate(ArmorSlot::Head)
|
||||||
.w_h(45.0, 45.0)
|
.w_h(45.0, 45.0)
|
||||||
.mid_top_with_margin_on(state.ids.bg_frame, 60.0)
|
.mid_top_with_margin_on(state.ids.bg_frame, 60.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.head_bg, Vec2::new(32.0, 40.0), Some(UI_MAIN))
|
||||||
.set(state.ids.head_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.head_bg)
|
.set(state.ids.head_slot, ui);
|
||||||
.w_h(32.0, 40.0)
|
// Necklace
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = ("Neck", "");
|
||||||
.middle_of(state.ids.head_bg)
|
slot_maker
|
||||||
.with_tooltip(self.tooltip_manager, "Helmet", "", &item_tooltip)
|
.fabricate(ArmorSlot::Neck)
|
||||||
.set(state.ids.head_ico, ui);
|
|
||||||
//Necklace
|
|
||||||
Image::new(self.imgs.armor_slot)
|
|
||||||
.w_h(45.0, 45.0)
|
.w_h(45.0, 45.0)
|
||||||
.mid_bottom_with_margin_on(state.ids.head_bg, -55.0)
|
.mid_bottom_with_margin_on(state.ids.head_slot, -55.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.necklace_bg, Vec2::new(40.0, 31.0), Some(UI_MAIN))
|
||||||
.set(state.ids.neck_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.necklace_bg)
|
.set(state.ids.neck_slot, ui);
|
||||||
.w_h(40.0, 31.0)
|
// Chest
|
||||||
.image_color(UI_MAIN)
|
//Image::new(self.imgs.armor_slot) // different graphics for empty/non empty
|
||||||
.middle_of(state.ids.neck_bg)
|
let (title, desc) = loadout
|
||||||
.with_tooltip(self.tooltip_manager, "Neck", "", &item_tooltip)
|
.chest
|
||||||
.set(state.ids.neck_ico, ui);
|
.as_ref()
|
||||||
//Chest
|
.map_or(("Chest", ""), |item| (item.name(), item.description()));
|
||||||
Image::new(self.imgs.armor_slot) // different graphics for empty/non empty
|
slot_maker
|
||||||
|
.fabricate(ArmorSlot::Chest)
|
||||||
.w_h(85.0, 85.0)
|
.w_h(85.0, 85.0)
|
||||||
.mid_bottom_with_margin_on(state.ids.neck_bg, -95.0)
|
.mid_bottom_with_margin_on(state.ids.neck_slot, -95.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.chest_bg, Vec2::new(64.0, 42.0), Some(UI_MAIN))
|
||||||
.set(state.ids.chest_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.chest_bg)
|
.set(state.ids.chest_slot, ui);
|
||||||
.w_h(64.0, 42.0)
|
// Shoulders
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = loadout
|
||||||
.middle_of(state.ids.chest_bg)
|
.shoulder
|
||||||
.with_tooltip(self.tooltip_manager, "Chest", "", &item_tooltip)
|
.as_ref()
|
||||||
.set(state.ids.chest_ico, ui);
|
.map_or(("Shoulders", ""), |item| (item.name(), item.description()));
|
||||||
//Shoulder
|
slot_maker
|
||||||
Image::new(self.imgs.armor_slot)
|
.fabricate(ArmorSlot::Shoulders)
|
||||||
.w_h(70.0, 70.0)
|
.w_h(70.0, 70.0)
|
||||||
.bottom_left_with_margins_on(state.ids.chest_bg, 0.0, -80.0)
|
.bottom_left_with_margins_on(state.ids.chest_slot, 0.0, -80.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.shoulders_bg, Vec2::new(60.0, 36.0), Some(UI_MAIN))
|
||||||
.set(state.ids.shoulder_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.shoulders_bg)
|
.set(state.ids.shoulders_slot, ui);
|
||||||
.w_h(60.0, 36.0)
|
// Hands
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = loadout
|
||||||
.middle_of(state.ids.shoulder_bg)
|
.hand
|
||||||
.with_tooltip(self.tooltip_manager, "Shoulders", "", &item_tooltip)
|
.as_ref()
|
||||||
.set(state.ids.shoulder_ico, ui);
|
.map_or(("Hands", ""), |item| (item.name(), item.description()));
|
||||||
//Hands
|
slot_maker
|
||||||
Image::new(self.imgs.armor_slot)
|
.fabricate(ArmorSlot::Hands)
|
||||||
.w_h(70.0, 70.0)
|
.w_h(70.0, 70.0)
|
||||||
.bottom_right_with_margins_on(state.ids.chest_bg, 0.0, -80.0)
|
.bottom_right_with_margins_on(state.ids.chest_slot, 0.0, -80.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.hands_bg, Vec2::new(55.0, 60.0), Some(UI_MAIN))
|
||||||
.set(state.ids.hands_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.hands_bg)
|
.set(state.ids.hands_slot, ui);
|
||||||
.w_h(55.0, 60.0)
|
// Belt
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = loadout
|
||||||
.middle_of(state.ids.hands_bg)
|
.belt
|
||||||
.with_tooltip(self.tooltip_manager, "Hands", "", &item_tooltip)
|
.as_ref()
|
||||||
.set(state.ids.hands_ico, ui);
|
.map_or(("Belt", ""), |item| (item.name(), item.description()));
|
||||||
//Belt
|
slot_maker
|
||||||
Image::new(self.imgs.armor_slot)
|
.fabricate(ArmorSlot::Belt)
|
||||||
.w_h(45.0, 45.0)
|
.w_h(45.0, 45.0)
|
||||||
.mid_bottom_with_margin_on(state.ids.chest_bg, -55.0)
|
.mid_bottom_with_margin_on(state.ids.chest_slot, -55.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.belt_bg, Vec2::new(40.0, 23.0), Some(UI_MAIN))
|
||||||
.set(state.ids.belt_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.belt_bg)
|
.set(state.ids.belt_slot, ui);
|
||||||
.w_h(40.0, 23.0)
|
// Legs
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = loadout
|
||||||
.middle_of(state.ids.belt_bg)
|
.belt
|
||||||
.with_tooltip(self.tooltip_manager, "Belt", "", &item_tooltip)
|
.as_ref()
|
||||||
.set(state.ids.belt_ico, ui);
|
.map_or(("Legs", ""), |item| (item.name(), item.description()));
|
||||||
//Legs
|
slot_maker
|
||||||
Image::new(self.imgs.armor_slot)
|
.fabricate(ArmorSlot::Legs)
|
||||||
.w_h(85.0, 85.0)
|
.w_h(85.0, 85.0)
|
||||||
.mid_bottom_with_margin_on(state.ids.belt_bg, -95.0)
|
.mid_bottom_with_margin_on(state.ids.belt_slot, -95.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.legs_bg, Vec2::new(48.0, 70.0), Some(UI_MAIN))
|
||||||
.set(state.ids.legs_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.legs_bg)
|
.set(state.ids.legs_slot, ui);
|
||||||
.w_h(48.0, 70.0)
|
// Ring-L
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = ("Left Ring", "");
|
||||||
.middle_of(state.ids.legs_bg)
|
slot_maker
|
||||||
.with_tooltip(self.tooltip_manager, "Legs", "", &item_tooltip)
|
.fabricate(ArmorSlot::LeftRing)
|
||||||
.set(state.ids.legs_ico, ui);
|
|
||||||
//Ring-L
|
|
||||||
Image::new(self.imgs.armor_slot)
|
|
||||||
.w_h(45.0, 45.0)
|
.w_h(45.0, 45.0)
|
||||||
.bottom_right_with_margins_on(state.ids.shoulder_bg, -55.0, 0.0)
|
.bottom_right_with_margins_on(state.ids.shoulders_slot, -55.0, 0.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.ring_l_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN))
|
||||||
.set(state.ids.ring_l_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.ring_l_bg)
|
.set(state.ids.ring_l_slot, ui);
|
||||||
.w_h(36.0, 40.0)
|
// Ring-R
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = ("Right Ring", "");
|
||||||
.middle_of(state.ids.ring_l_bg)
|
slot_maker
|
||||||
.with_tooltip(self.tooltip_manager, "Left Ring", "", &item_tooltip)
|
.fabricate(ArmorSlot::RightRing)
|
||||||
.set(state.ids.ring_l_ico, ui);
|
|
||||||
//Ring-R
|
|
||||||
Image::new(self.imgs.armor_slot)
|
|
||||||
.w_h(45.0, 45.0)
|
.w_h(45.0, 45.0)
|
||||||
.bottom_left_with_margins_on(state.ids.hands_bg, -55.0, 0.0)
|
.bottom_left_with_margins_on(state.ids.hands_slot, -55.0, 0.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.ring_r_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN))
|
||||||
.set(state.ids.ring_r_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.ring_r_bg)
|
.set(state.ids.ring_r_slot, ui);
|
||||||
.w_h(36.0, 40.0)
|
// Back
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = ("Back", "");
|
||||||
.middle_of(state.ids.ring_r_bg)
|
slot_maker
|
||||||
.with_tooltip(self.tooltip_manager, "Right Ring", "", &item_tooltip)
|
.fabricate(ArmorSlot::Back)
|
||||||
.set(state.ids.ring_r_ico, ui);
|
|
||||||
//Back
|
|
||||||
Image::new(self.imgs.armor_slot)
|
|
||||||
.w_h(45.0, 45.0)
|
.w_h(45.0, 45.0)
|
||||||
.down_from(state.ids.ring_l_bg, 10.0)
|
.down_from(state.ids.ring_l_slot, 10.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.back_bg, Vec2::new(33.0, 40.0), Some(UI_MAIN))
|
||||||
.set(state.ids.back_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.back_bg)
|
.set(state.ids.back_slot, ui);
|
||||||
.w_h(33.0, 40.0)
|
// Foot
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = loadout
|
||||||
.middle_of(state.ids.back_bg)
|
.foot
|
||||||
.with_tooltip(self.tooltip_manager, "Back", "", &item_tooltip)
|
.as_ref()
|
||||||
.set(state.ids.back_ico, ui);
|
.map_or(("Feet", ""), |item| (item.name(), item.description()));
|
||||||
//Foot
|
slot_maker
|
||||||
Image::new(self.imgs.armor_slot)
|
.fabricate(ArmorSlot::Feet)
|
||||||
.w_h(45.0, 45.0)
|
.w_h(45.0, 45.0)
|
||||||
.down_from(state.ids.ring_r_bg, 10.0)
|
.down_from(state.ids.ring_r_slot, 10.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.feet_bg, Vec2::new(32.0, 40.0), Some(UI_MAIN))
|
||||||
.set(state.ids.foot_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.feet_bg)
|
.set(state.ids.feet_slot, ui);
|
||||||
.w_h(32.0, 40.0)
|
// Tabard
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = ("Tabard", "");
|
||||||
.middle_of(state.ids.foot_bg)
|
slot_maker
|
||||||
.with_tooltip(self.tooltip_manager, "Feet", "", &item_tooltip)
|
.fabricate(ArmorSlot::Tabard)
|
||||||
.set(state.ids.foot_ico, ui);
|
|
||||||
//Tabard
|
|
||||||
Image::new(self.imgs.armor_slot)
|
|
||||||
.w_h(70.0, 70.0)
|
.w_h(70.0, 70.0)
|
||||||
.top_right_with_margins_on(state.ids.bg_frame, 80.5, 53.0)
|
.top_right_with_margins_on(state.ids.bg_frame, 80.5, 53.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.tabard_bg, Vec2::new(60.0, 60.0), Some(UI_MAIN))
|
||||||
.set(state.ids.tabard_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.tabard_bg)
|
.set(state.ids.tabard_slot, ui);
|
||||||
.w_h(60.0, 60.0)
|
// Mainhand/Left-Slot
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = loadout
|
||||||
.middle_of(state.ids.tabard_bg)
|
.active_item
|
||||||
.with_tooltip(self.tooltip_manager, "Tabard", "", &item_tooltip)
|
.as_ref()
|
||||||
.set(state.ids.tabard_ico, ui);
|
.map(|i| &i.item)
|
||||||
//Mainhand/Left-Slot
|
.map_or(("Mainhand", ""), |item| (item.name(), item.description()));
|
||||||
Image::new(self.imgs.armor_slot)
|
slot_maker
|
||||||
|
.fabricate(ArmorSlot::Mainhand)
|
||||||
.w_h(85.0, 85.0)
|
.w_h(85.0, 85.0)
|
||||||
.bottom_right_with_margins_on(state.ids.back_bg, -95.0, 0.0)
|
.bottom_right_with_margins_on(state.ids.back_slot, -95.0, 0.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.mainhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN))
|
||||||
.set(state.ids.mainhand_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.mainhand_bg)
|
.set(state.ids.mainhand_slot, ui);
|
||||||
.w_h(75.0, 75.0)
|
// Offhand/Right-Slot
|
||||||
.image_color(UI_MAIN)
|
let (title, desc) = loadout
|
||||||
.middle_of(state.ids.mainhand_bg)
|
.second_item
|
||||||
.with_tooltip(self.tooltip_manager, "Mainhand", "", &item_tooltip)
|
.as_ref()
|
||||||
.set(state.ids.mainhand_ico, ui);
|
.map(|i| &i.item)
|
||||||
//Offhand/Right-Slot
|
.map_or(("Offhand", ""), |item| (item.name(), item.description()));
|
||||||
Image::new(self.imgs.armor_slot)
|
slot_maker
|
||||||
|
.fabricate(ArmorSlot::Offhand)
|
||||||
.w_h(85.0, 85.0)
|
.w_h(85.0, 85.0)
|
||||||
.bottom_left_with_margins_on(state.ids.foot_bg, -95.0, 0.0)
|
.bottom_left_with_margins_on(state.ids.feet_slot, -95.0, 0.0)
|
||||||
.color(Some(UI_HIGHLIGHT_0))
|
.with_icon(self.imgs.offhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN))
|
||||||
.set(state.ids.offhand_bg, ui);
|
.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip)
|
||||||
Button::image(self.imgs.offhand_bg)
|
.set(state.ids.offhand_slot, ui);
|
||||||
.w_h(75.0, 75.0)
|
|
||||||
.image_color(UI_MAIN)
|
|
||||||
.middle_of(state.ids.offhand_bg)
|
|
||||||
.with_tooltip(self.tooltip_manager, "Offhand", "", &item_tooltip)
|
|
||||||
.set(state.ids.offhand_ico, ui);
|
|
||||||
} else {
|
} else {
|
||||||
// Stats
|
// Stats
|
||||||
// Title
|
// Title
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use super::item_imgs::{ItemImgs, ItemKey};
|
use super::item_imgs::{ItemImgs, ItemKey};
|
||||||
use crate::ui::slot::{ContentKey, SlotKinds, SlotManager};
|
use crate::ui::slot::{ContentKey, SlotKinds, SlotManager};
|
||||||
use common::comp::{item::ItemKind, Inventory};
|
use common::comp::{item::ItemKind, Inventory, Loadout};
|
||||||
use conrod_core::image;
|
use conrod_core::image;
|
||||||
use vek::*;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
pub enum HudSlotKinds {
|
pub enum HudSlotKinds {
|
||||||
@ -18,7 +17,7 @@ pub struct InventorySlot(pub usize);
|
|||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
pub enum ArmorSlot {
|
pub enum ArmorSlot {
|
||||||
Helmet,
|
Head,
|
||||||
Neck,
|
Neck,
|
||||||
Shoulders,
|
Shoulders,
|
||||||
Chest,
|
Chest,
|
||||||
@ -72,8 +71,32 @@ impl ContentKey for InventorySlot {
|
|||||||
fn image_id(key: &Self::ImageKey, source: &Self::ImageSource) -> image::Id {
|
fn image_id(key: &Self::ImageKey, source: &Self::ImageSource) -> image::Id {
|
||||||
source.img_id_or_not_found_img(key.clone())
|
source.img_id_or_not_found_img(key.clone())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn back_icon(&self, _: &Self::ImageSource) -> Option<(image::Id, Vec2<f32>)> { None }
|
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(),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<InventorySlot> for HudSlotKinds {
|
impl From<InventorySlot> for HudSlotKinds {
|
||||||
|
@ -18,8 +18,6 @@ pub trait ContentKey: Copy {
|
|||||||
// TODO: is this the right integer type?
|
// TODO: is this the right integer type?
|
||||||
fn amount(&self, source: &Self::ContentSource) -> Option<u32>;
|
fn amount(&self, source: &Self::ContentSource) -> Option<u32>;
|
||||||
fn image_id(key: &Self::ImageKey, source: &Self::ImageSource) -> image::Id;
|
fn image_id(key: &Self::ImageKey, source: &Self::ImageSource) -> image::Id;
|
||||||
/// Returns slot icon and icon size as fraction of slot size
|
|
||||||
fn back_icon(&self, source: &Self::ImageSource) -> Option<(image::Id, Vec2<f32>)>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SlotKinds: Sized + PartialEq + Copy {}
|
pub trait SlotKinds: Sized + PartialEq + Copy {}
|
||||||
@ -223,6 +221,8 @@ pub struct Slot<'a, C: ContentKey + Into<K>, K: SlotKinds> {
|
|||||||
// TODO: maybe use constant scale factor or move this setting to the slot manager?
|
// TODO: maybe use constant scale factor or move this setting to the slot manager?
|
||||||
selected_content_size: Vec2<f32>,
|
selected_content_size: Vec2<f32>,
|
||||||
|
|
||||||
|
icon: Option<(image::Id, Vec2<f32>, Option<Color>)>,
|
||||||
|
|
||||||
// Amount styling
|
// Amount styling
|
||||||
amount_font: font::Id,
|
amount_font: font::Id,
|
||||||
amount_font_size: u32,
|
amount_font_size: u32,
|
||||||
@ -265,6 +265,11 @@ where
|
|||||||
pub with_background_color { background_color = Some(Color) }
|
pub with_background_color { background_color = Some(Color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_icon(mut self, img: image::Id, size: Vec2<f32>, color: Option<Color>) -> Self {
|
||||||
|
self.icon = Some((img, size, color));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
fn new(
|
fn new(
|
||||||
content: C,
|
content: C,
|
||||||
background: image::Id,
|
background: image::Id,
|
||||||
@ -285,6 +290,7 @@ where
|
|||||||
background_color: None,
|
background_color: None,
|
||||||
content_size,
|
content_size,
|
||||||
selected_content_size,
|
selected_content_size,
|
||||||
|
icon: None,
|
||||||
amount_font,
|
amount_font,
|
||||||
amount_font_size,
|
amount_font_size,
|
||||||
amount_margins,
|
amount_margins,
|
||||||
@ -331,6 +337,7 @@ where
|
|||||||
background_color,
|
background_color,
|
||||||
content_size,
|
content_size,
|
||||||
selected_content_size,
|
selected_content_size,
|
||||||
|
icon,
|
||||||
amount_font,
|
amount_font,
|
||||||
amount_font_size,
|
amount_font_size,
|
||||||
amount_margins,
|
amount_margins,
|
||||||
@ -362,7 +369,6 @@ where
|
|||||||
} else {
|
} else {
|
||||||
background
|
background
|
||||||
};
|
};
|
||||||
let icon = content.back_icon(image_source);
|
|
||||||
let content_image = state.cached_image.as_ref().map(|c| c.1);
|
let content_image = state.cached_image.as_ref().map(|c| c.1);
|
||||||
|
|
||||||
// Get amount (None => no amount text)
|
// Get amount (None => no amount text)
|
||||||
@ -381,13 +387,14 @@ where
|
|||||||
.set(state.ids.background, ui);
|
.set(state.ids.background, ui);
|
||||||
|
|
||||||
// Draw icon
|
// Draw icon
|
||||||
if let Some((icon_image, size_frac)) = icon {
|
if let Some((icon_image, size, color)) = icon {
|
||||||
let wh = (size_frac.map(|e| e as f64) * Vec2::new(w, h)).into_array();
|
let wh = size.map(|e| e as f64).into_array();
|
||||||
Image::new(icon_image)
|
Image::new(icon_image)
|
||||||
.x_y(x, y)
|
.x_y(x, y)
|
||||||
.wh(wh)
|
.wh(wh)
|
||||||
.parent(id)
|
.parent(id)
|
||||||
.graphics_for(id)
|
.graphics_for(id)
|
||||||
|
.color(color)
|
||||||
.set(state.ids.icon, ui);
|
.set(state.ids.icon, ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user