mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Don't show icon when slot is filled and have a separate image for filled
slot backgrounds
This commit is contained in:
parent
cac2321464
commit
4c5f668203
@ -314,8 +314,9 @@ impl<'a> Widget for Bag<'a> {
|
|||||||
.set(state.ids.slots_bg, ui);*/
|
.set(state.ids.slots_bg, ui);*/
|
||||||
// Armor Slots
|
// Armor Slots
|
||||||
let mut slot_maker = SlotMaker {
|
let mut slot_maker = SlotMaker {
|
||||||
background: self.imgs.armor_slot,
|
empty_slot: self.imgs.armor_slot_empty,
|
||||||
selected_background: self.imgs.armor_slot,
|
filled_slot: self.imgs.armor_slot,
|
||||||
|
selected_slot: self.imgs.armor_slot_sel,
|
||||||
background_color: Some(UI_HIGHLIGHT_0),
|
background_color: Some(UI_HIGHLIGHT_0),
|
||||||
content_size: Vec2::broadcast(30.0),
|
content_size: Vec2::broadcast(30.0),
|
||||||
selected_content_size: Vec2::broadcast(32.0),
|
selected_content_size: Vec2::broadcast(32.0),
|
||||||
@ -596,8 +597,9 @@ impl<'a> Widget for Bag<'a> {
|
|||||||
}
|
}
|
||||||
// Display inventory contents
|
// Display inventory contents
|
||||||
let mut slot_maker = SlotMaker {
|
let mut slot_maker = SlotMaker {
|
||||||
background: self.imgs.inv_slot,
|
empty_slot: self.imgs.inv_slot,
|
||||||
selected_background: self.imgs.inv_slot_sel,
|
filled_slot: self.imgs.inv_slot,
|
||||||
|
selected_slot: self.imgs.inv_slot_sel,
|
||||||
background_color: Some(UI_MAIN),
|
background_color: Some(UI_MAIN),
|
||||||
content_size: Vec2::broadcast(30.0),
|
content_size: Vec2::broadcast(30.0),
|
||||||
selected_content_size: Vec2::broadcast(32.0),
|
selected_content_size: Vec2::broadcast(32.0),
|
||||||
|
@ -230,7 +230,7 @@ image_ids! {
|
|||||||
inv_slots: "voxygen.element.misc_bg.inv_slots",
|
inv_slots: "voxygen.element.misc_bg.inv_slots",
|
||||||
inv_runes: "voxygen.element.misc_bg.inv_runes",
|
inv_runes: "voxygen.element.misc_bg.inv_runes",
|
||||||
armor_slot: "voxygen.element.buttons.armor_slot",
|
armor_slot: "voxygen.element.buttons.armor_slot",
|
||||||
armor_slot_sel: "voxygen.element.buttons.armor_slot_sel",
|
armor_slot_sel: "voxygen.element.buttons.armor_slot_selected",
|
||||||
armor_slot_empty: "voxygen.element.buttons.armor_slot_empty",
|
armor_slot_empty: "voxygen.element.buttons.armor_slot_empty",
|
||||||
head_bg: "voxygen.element.icons.head",
|
head_bg: "voxygen.element.icons.head",
|
||||||
shoulders_bg: "voxygen.element.icons.shoulders",
|
shoulders_bg: "voxygen.element.icons.shoulders",
|
||||||
|
@ -23,8 +23,10 @@ pub trait ContentKey: Copy {
|
|||||||
pub trait SlotKinds: Sized + PartialEq + Copy {}
|
pub trait SlotKinds: Sized + PartialEq + Copy {}
|
||||||
|
|
||||||
pub struct SlotMaker<'a, C: ContentKey + Into<K>, K: SlotKinds> {
|
pub struct SlotMaker<'a, C: ContentKey + Into<K>, K: SlotKinds> {
|
||||||
pub background: image::Id,
|
pub empty_slot: image::Id,
|
||||||
pub selected_background: image::Id,
|
pub filled_slot: image::Id,
|
||||||
|
pub selected_slot: image::Id,
|
||||||
|
// Is this useful?
|
||||||
pub background_color: Option<Color>,
|
pub background_color: Option<Color>,
|
||||||
pub content_size: Vec2<f32>,
|
pub content_size: Vec2<f32>,
|
||||||
pub selected_content_size: Vec2<f32>,
|
pub selected_content_size: Vec2<f32>,
|
||||||
@ -45,8 +47,9 @@ where
|
|||||||
pub fn fabricate(&mut self, contents: C) -> Slot<C, K> {
|
pub fn fabricate(&mut self, contents: C) -> Slot<C, K> {
|
||||||
Slot::new(
|
Slot::new(
|
||||||
contents,
|
contents,
|
||||||
self.background,
|
self.empty_slot,
|
||||||
self.selected_background,
|
self.filled_slot,
|
||||||
|
self.selected_slot,
|
||||||
self.content_size,
|
self.content_size,
|
||||||
self.selected_content_size,
|
self.selected_content_size,
|
||||||
self.amount_font,
|
self.amount_font,
|
||||||
@ -211,9 +214,10 @@ where
|
|||||||
pub struct Slot<'a, C: ContentKey + Into<K>, K: SlotKinds> {
|
pub struct Slot<'a, C: ContentKey + Into<K>, K: SlotKinds> {
|
||||||
content: C,
|
content: C,
|
||||||
|
|
||||||
// Background is also the frame
|
// Images for slot background and frame
|
||||||
background: image::Id,
|
empty_slot: image::Id,
|
||||||
selected_background: image::Id,
|
filled_slot: image::Id,
|
||||||
|
selected_slot: image::Id,
|
||||||
background_color: Option<Color>,
|
background_color: Option<Color>,
|
||||||
|
|
||||||
// Size of content image
|
// Size of content image
|
||||||
@ -272,8 +276,9 @@ where
|
|||||||
|
|
||||||
fn new(
|
fn new(
|
||||||
content: C,
|
content: C,
|
||||||
background: image::Id,
|
empty_slot: image::Id,
|
||||||
selected_background: image::Id,
|
filled_slot: image::Id,
|
||||||
|
selected_slot: image::Id,
|
||||||
content_size: Vec2<f32>,
|
content_size: Vec2<f32>,
|
||||||
selected_content_size: Vec2<f32>,
|
selected_content_size: Vec2<f32>,
|
||||||
amount_font: font::Id,
|
amount_font: font::Id,
|
||||||
@ -285,8 +290,9 @@ where
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
content,
|
content,
|
||||||
background,
|
empty_slot,
|
||||||
selected_background,
|
filled_slot,
|
||||||
|
selected_slot,
|
||||||
background_color: None,
|
background_color: None,
|
||||||
content_size,
|
content_size,
|
||||||
selected_content_size,
|
selected_content_size,
|
||||||
@ -332,8 +338,9 @@ where
|
|||||||
} = args;
|
} = args;
|
||||||
let Slot {
|
let Slot {
|
||||||
content,
|
content,
|
||||||
background,
|
empty_slot,
|
||||||
selected_background,
|
filled_slot,
|
||||||
|
selected_slot,
|
||||||
background_color,
|
background_color,
|
||||||
content_size,
|
content_size,
|
||||||
selected_content_size,
|
selected_content_size,
|
||||||
@ -364,12 +371,14 @@ where
|
|||||||
.map_or(Interaction::None, |m| m.update(id, content.into(), ui));
|
.map_or(Interaction::None, |m| m.update(id, content.into(), ui));
|
||||||
|
|
||||||
// Get image ids
|
// Get image ids
|
||||||
let background_image = if let Interaction::Selected = interaction {
|
|
||||||
selected_background
|
|
||||||
} else {
|
|
||||||
background
|
|
||||||
};
|
|
||||||
let content_image = state.cached_image.as_ref().map(|c| c.1);
|
let content_image = state.cached_image.as_ref().map(|c| c.1);
|
||||||
|
let slot_image = if let Interaction::Selected = interaction {
|
||||||
|
selected_slot
|
||||||
|
} else if content_image.is_some() {
|
||||||
|
filled_slot
|
||||||
|
} else {
|
||||||
|
empty_slot
|
||||||
|
};
|
||||||
|
|
||||||
// Get amount (None => no amount text)
|
// Get amount (None => no amount text)
|
||||||
let amount = content.amount(content_source);
|
let amount = content.amount(content_source);
|
||||||
@ -377,8 +386,8 @@ where
|
|||||||
// Get slot widget dimensions and position
|
// Get slot widget dimensions and position
|
||||||
let (x, y, w, h) = rect.x_y_w_h();
|
let (x, y, w, h) = rect.x_y_w_h();
|
||||||
|
|
||||||
// Draw background
|
// Draw slot frame/background
|
||||||
Image::new(background_image)
|
Image::new(slot_image)
|
||||||
.x_y(x, y)
|
.x_y(x, y)
|
||||||
.w_h(w, h)
|
.w_h(w, h)
|
||||||
.parent(id)
|
.parent(id)
|
||||||
@ -386,8 +395,9 @@ where
|
|||||||
.color(background_color)
|
.color(background_color)
|
||||||
.set(state.ids.background, ui);
|
.set(state.ids.background, ui);
|
||||||
|
|
||||||
// Draw icon
|
// Draw icon (only when there is not content)
|
||||||
if let Some((icon_image, size, color)) = icon {
|
// Note: this could potentially be done by the user instead
|
||||||
|
if let (Some((icon_image, size, color)), true) = (icon, content_image.is_none()) {
|
||||||
let wh = size.map(|e| e as f64).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)
|
||||||
|
Loading…
Reference in New Issue
Block a user