veloren/voxygen/src/hud/bag.rs

814 lines
30 KiB
Rust
Raw Normal View History

2019-09-25 20:18:40 +00:00
use super::{
img_ids::{Imgs, ImgsRot},
item_imgs::{ItemImgs, ItemKey},
2020-03-24 00:31:14 +00:00
Event as HudEvent, Show, CRITICAL_HP_COLOR, LOW_HP_COLOR, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
XP_COLOR,
2019-09-25 20:18:40 +00:00
};
2020-03-15 16:27:56 +00:00
use crate::{
i18n::VoxygenLocalization,
ui::{fonts::ConrodVoxygenFonts, ImageFrame, Tooltip, TooltipManager, Tooltipable},
};
use client::Client;
2020-03-20 14:45:36 +00:00
use common::comp::{ItemKind, Stats};
use conrod_core::{
2019-10-09 19:28:05 +00:00
color, image,
2020-03-15 16:27:56 +00:00
widget::{self, Button, Image, Rectangle, Text},
2020-03-15 20:33:51 +00:00
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
};
2020-03-20 19:52:32 +00:00
//use const_tweaker::tweak;
widget_ids! {
2020-03-17 18:04:06 +00:00
pub struct Ids {
2020-03-17 16:02:50 +00:00
test,
bag_close,
inv_alignment,
inv_grid_1,
inv_grid_2,
inv_scrollbar,
2019-07-25 22:52:28 +00:00
inv_slots_0,
map_title,
2019-07-25 22:52:28 +00:00
inv_slots[],
items[],
2020-03-19 15:43:11 +00:00
amounts[],
amounts_bg[],
2019-09-25 22:16:23 +00:00
tooltip[],
2020-03-09 21:54:36 +00:00
bg,
bg_frame,
2020-03-18 11:05:36 +00:00
char_ico,
coin_ico,
2020-03-18 18:51:48 +00:00
space_txt,
2020-03-18 11:05:36 +00:00
currency_txt,
2020-03-15 16:27:56 +00:00
inventory_title,
2020-03-15 20:33:51 +00:00
inventory_title_bg,
scrollbar_bg,
stats_button,
tab_1,
tab_2,
tab_3,
tab_4,
//Stats
stats_alignment,
level,
exp_rectangle,
exp_progress_rectangle,
expbar,
exp,
divider,
statnames,
stats,
2020-03-17 16:02:50 +00:00
//Armor Slots
slots_bg,
head_bg,
neck_bg,
chest_bg,
shoulder_bg,
hands_bg,
2020-03-18 00:43:55 +00:00
legs_bg,
2020-03-17 16:02:50 +00:00
belt_bg,
2020-03-17 18:04:06 +00:00
ring_r_bg,
ring_l_bg,
2020-03-17 16:02:50 +00:00
foot_bg,
back_bg,
tabard_bg,
mainhand_bg,
offhand_bg,
2020-03-18 00:43:55 +00:00
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,
2020-03-20 19:52:32 +00:00
end_ico,
fit_ico,
wp_ico,
}
}
#[derive(WidgetCommon)]
2019-10-09 22:42:39 +00:00
#[allow(dead_code)]
pub struct Bag<'a> {
client: &'a Client,
imgs: &'a Imgs,
2019-10-09 19:28:05 +00:00
item_imgs: &'a ItemImgs,
fonts: &'a ConrodVoxygenFonts,
#[conrod(common_builder)]
common: widget::CommonBuilder,
2019-09-25 16:51:47 +00:00
rot_imgs: &'a ImgsRot,
2019-09-25 20:18:40 +00:00
tooltip_manager: &'a mut TooltipManager,
pulse: f32,
2020-03-15 16:27:56 +00:00
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
stats: &'a Stats,
show: &'a Show,
}
impl<'a> Bag<'a> {
2019-09-25 20:18:40 +00:00
pub fn new(
client: &'a Client,
imgs: &'a Imgs,
2019-10-09 19:28:05 +00:00
item_imgs: &'a ItemImgs,
fonts: &'a ConrodVoxygenFonts,
2019-09-25 20:18:40 +00:00
rot_imgs: &'a ImgsRot,
tooltip_manager: &'a mut TooltipManager,
pulse: f32,
2020-03-15 16:27:56 +00:00
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
stats: &'a Stats,
show: &'a Show,
2019-09-25 20:18:40 +00:00
) -> Self {
Self {
client,
imgs,
2019-10-09 19:28:05 +00:00
item_imgs,
2019-07-04 20:55:23 +00:00
fonts,
common: widget::CommonBuilder::default(),
2019-09-25 16:51:47 +00:00
rot_imgs,
tooltip_manager,
pulse,
2020-03-15 16:27:56 +00:00
localized_strings,
stats,
show,
}
}
}
pub struct State {
ids: Ids,
img_id_cache: Vec<Option<(ItemKey, image::Id)>>,
2019-07-26 17:08:40 +00:00
selected_slot: Option<usize>,
}
pub enum Event {
2019-07-25 22:52:28 +00:00
HudEvent(HudEvent),
Stats,
Close,
}
2020-03-20 19:52:32 +00:00
/*
#[tweak(min = -100.0, max = 20.0, step = 1.0)]
const END_X: f64 = 10.0;
*/
impl<'a> Widget for Bag<'a> {
type Event = Option<Event>;
type State = State;
type Style = ();
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
State {
ids: Ids::new(id_gen),
2019-10-09 19:28:05 +00:00
img_id_cache: Vec::new(),
2019-07-26 17:08:40 +00:00
selected_slot: None,
}
}
fn style(&self) -> Self::Style { () }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { state, ui, .. } = args;
2019-09-25 20:18:40 +00:00
let mut event = None;
2019-07-25 22:52:28 +00:00
let invs = self.client.inventories();
let inventory = match invs.get(self.client.entity()) {
Some(inv) => inv,
None => return None,
};
2020-03-15 16:27:56 +00:00
let exp_percentage = (self.stats.exp.current() as f64) / (self.stats.exp.maximum() as f64);
2020-03-16 21:58:19 +00:00
let exp_treshold = format!(
"{}/{} {}",
self.stats.exp.current(),
self.stats.exp.maximum(),
&self.localized_strings.get("hud.bag.exp")
);
2020-03-23 23:23:21 +00:00
let space_used = inventory.amount;
2020-03-23 23:38:00 +00:00
let space_max = inventory.slots.len();
2020-03-18 18:51:48 +00:00
let bag_space = format!("{}/{}", space_used, space_max);
2020-03-24 00:31:14 +00:00
let bag_space_percentage = space_used as f32 / space_max as f32;
2020-03-15 16:27:56 +00:00
let level = (self.stats.level.level()).to_string();
2020-03-20 00:11:02 +00:00
let currency = 0; // TODO: Add as a Stat maybe?
2020-03-15 20:33:51 +00:00
2019-09-25 16:51:47 +00:00
// Tooltips
let item_tooltip = Tooltip::new({
// Edge images [t, b, r, l]
// Corner images [tr, tl, br, bl]
let edge = &self.rot_imgs.tt_side;
let corner = &self.rot_imgs.tt_corner;
ImageFrame::new(
[edge.cw180, edge.none, edge.cw270, edge.cw90],
[corner.none, corner.cw270, corner.cw90, corner.cw180],
Color::Rgba(0.08, 0.07, 0.04, 1.0),
5.0,
)
})
.title_font_size(self.fonts.cyri.scale(15))
2019-10-09 19:28:05 +00:00
.parent(ui.window)
.desc_font_size(self.fonts.cyri.scale(12))
2019-09-25 16:51:47 +00:00
.title_text_color(TEXT_COLOR)
.font_id(self.fonts.cyri.conrod_id)
.desc_text_color(TEXT_COLOR);
2020-03-09 21:54:36 +00:00
// BG
2020-03-16 21:58:19 +00:00
Image::new(if self.show.stats {
self.imgs.inv_bg_stats
} else {
self.imgs.inv_bg_armor
})
.w_h(424.0, 708.0)
.bottom_right_with_margins_on(ui.window, 60.0, 5.0)
.color(Some(UI_MAIN))
.set(state.ids.bg, ui);
2020-03-09 21:54:36 +00:00
Image::new(self.imgs.inv_frame)
.w_h(424.0, 708.0)
.middle_of(state.ids.bg)
.color(Some(UI_HIGHLIGHT_0))
2020-03-09 21:54:36 +00:00
.set(state.ids.bg_frame, ui);
2020-03-15 16:27:56 +00:00
// Title
Text::new(&format!(
"{}{}",
&self.stats.name,
&self.localized_strings.get("hud.bag.inventory")
))
.mid_top_with_margin_on(state.ids.bg_frame, 9.0)
.font_id(self.fonts.cyri.conrod_id)
2020-03-15 20:33:51 +00:00
.font_size(self.fonts.cyri.scale(22))
.color(Color::Rgba(0.0, 0.0, 0.0, 1.0))
.set(state.ids.inventory_title_bg, ui);
Text::new(&format!(
"{}{}",
&self.stats.name,
&self.localized_strings.get("hud.bag.inventory")
))
.top_left_with_margins_on(state.ids.inventory_title_bg, 2.0, 2.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(22))
2020-03-15 16:27:56 +00:00
.color(TEXT_COLOR)
.set(state.ids.inventory_title, ui);
2020-03-15 20:33:51 +00:00
// Scrollbar-BG
Image::new(self.imgs.scrollbar_bg)
.w_h(9.0, 173.0)
.bottom_right_with_margins_on(state.ids.bg_frame, 42.0, 3.0)
.color(Some(UI_HIGHLIGHT_0))
2020-03-15 20:33:51 +00:00
.set(state.ids.scrollbar_bg, ui);
// Char Pixel-Art
2020-03-15 16:27:56 +00:00
Image::new(self.imgs.char_art)
.w_h(40.0, 37.0)
.top_left_with_margins_on(state.ids.bg, 4.0, 2.0)
2020-03-18 11:05:36 +00:00
.set(state.ids.char_ico, ui);
// Coin Icon and Currency Text
Image::new(self.imgs.coin_ico)
2020-03-18 18:51:48 +00:00
.w_h(16.0, 17.0)
2020-03-18 11:05:36 +00:00
.bottom_left_with_margins_on(state.ids.bg_frame, 2.0, 43.0)
.set(state.ids.coin_ico, ui);
Text::new(&format!("{}", currency))
2020-03-18 18:51:48 +00:00
.bottom_left_with_margins_on(state.ids.bg_frame, 6.0, 64.0)
2020-03-18 11:05:36 +00:00
.font_id(self.fonts.cyri.conrod_id)
2020-03-18 18:51:48 +00:00
.font_size(self.fonts.cyri.scale(14))
.color(Color::Rgba(0.871, 0.863, 0.05, 1.0))
2020-03-18 11:05:36 +00:00
.set(state.ids.currency_txt, ui);
2020-03-18 18:51:48 +00:00
//Free Bag-Space
Text::new(&bag_space)
.bottom_right_with_margins_on(state.ids.bg_frame, 6.0, 43.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(14))
2020-03-24 00:31:14 +00:00
.color(if bag_space_percentage < 0.8 {
TEXT_COLOR
} else if bag_space_percentage < 1.0 {
LOW_HP_COLOR
} else {
CRITICAL_HP_COLOR
})
2020-03-18 18:51:48 +00:00
.set(state.ids.space_txt, ui);
2020-03-15 16:27:56 +00:00
// Alignment for Grid
2020-03-15 20:33:51 +00:00
Rectangle::fill_with([362.0, 200.0], color::TRANSPARENT)
2020-03-15 16:27:56 +00:00
.bottom_left_with_margins_on(state.ids.bg_frame, 29.0, 44.0)
.scroll_kids_vertically()
.set(state.ids.inv_alignment, ui);
2020-03-15 20:33:51 +00:00
if !self.show.stats {
2020-03-16 21:58:19 +00:00
// Title
Text::new(&format!(
"{}{}",
&self.stats.name,
&self.localized_strings.get("hud.bag.inventory")
))
.mid_top_with_margin_on(state.ids.bg_frame, 9.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(22))
.color(Color::Rgba(0.0, 0.0, 0.0, 1.0))
.set(state.ids.inventory_title_bg, ui);
Text::new(&format!(
"{}{}",
&self.stats.name,
&self.localized_strings.get("hud.bag.inventory")
))
.top_left_with_margins_on(state.ids.inventory_title_bg, 2.0, 2.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(22))
.color(TEXT_COLOR)
.set(state.ids.inventory_title, ui);
//Armor Slots
//Slots BG
2020-03-17 18:04:06 +00:00
/*Image::new(self.imgs.inv_runes)
2020-03-16 18:56:15 +00:00
.w_h(424.0, 454.0)
.mid_top_with_margin_on(state.ids.bg, 0.0)
.color(Some(UI_HIGHLIGHT_0))
2020-03-16 21:58:19 +00:00
.floating(true)
.set(state.ids.slots_bg, ui);
Image::new(self.imgs.inv_slots)
2020-03-17 18:04:06 +00:00
.w_h(424.0, 401.0)
.mid_top_with_margin_on(state.ids.bg, 57.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.slots_bg, ui);*/
2020-03-17 16:02:50 +00:00
// Armor Slots
//Head
2020-03-17 18:04:06 +00:00
Image::new(self.imgs.armor_slot)
.w_h(45.0, 45.0)
.mid_top_with_margin_on(state.ids.bg_frame, 60.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.head_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.head_bg)
.w_h(32.0, 40.0)
.image_color(UI_MAIN)
.middle_of(state.ids.head_bg)
.with_tooltip(self.tooltip_manager, "Helmet", "", &item_tooltip)
.set(state.ids.head_ico, ui);
2020-03-17 16:02:50 +00:00
//Necklace
2020-03-17 18:04:06 +00:00
Image::new(self.imgs.armor_slot)
.w_h(45.0, 45.0)
.mid_bottom_with_margin_on(state.ids.head_bg, -55.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.neck_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.necklace_bg)
.w_h(40.0, 31.0)
.image_color(UI_MAIN)
.middle_of(state.ids.neck_bg)
.with_tooltip(self.tooltip_manager, "Neck", "", &item_tooltip)
.set(state.ids.neck_ico, ui);
2020-03-17 16:02:50 +00:00
//Chest
Image::new(self.imgs.armor_slot) // different graphics for empty/non empty
2020-03-17 18:04:06 +00:00
.w_h(85.0, 85.0)
.mid_bottom_with_margin_on(state.ids.neck_bg, -95.0)
2020-03-17 16:02:50 +00:00
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.chest_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.chest_bg)
.w_h(64.0, 42.0)
.image_color(UI_MAIN)
2020-03-17 16:02:50 +00:00
.middle_of(state.ids.chest_bg)
2020-03-18 00:43:55 +00:00
.with_tooltip(self.tooltip_manager, "Chest", "", &item_tooltip)
.set(state.ids.chest_ico, ui);
2020-03-17 16:02:50 +00:00
//Shoulder
2020-03-17 18:04:06 +00:00
Image::new(self.imgs.armor_slot)
.w_h(70.0, 70.0)
.bottom_left_with_margins_on(state.ids.chest_bg, 0.0, -80.0)
.color(Some(UI_HIGHLIGHT_0))
2020-03-17 18:48:15 +00:00
.set(state.ids.shoulder_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.shoulders_bg)
.w_h(60.0, 36.0)
.image_color(UI_MAIN)
.middle_of(state.ids.shoulder_bg)
.with_tooltip(self.tooltip_manager, "Shoulders", "", &item_tooltip)
.set(state.ids.shoulder_ico, ui);
2020-03-17 16:02:50 +00:00
//Hands
2020-03-17 18:04:06 +00:00
Image::new(self.imgs.armor_slot)
.w_h(70.0, 70.0)
.bottom_right_with_margins_on(state.ids.chest_bg, 0.0, -80.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.hands_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.hands_bg)
.w_h(55.0, 60.0)
.image_color(UI_MAIN)
.middle_of(state.ids.hands_bg)
.with_tooltip(self.tooltip_manager, "Hands", "", &item_tooltip)
.set(state.ids.hands_ico, ui);
2020-03-17 16:02:50 +00:00
//Belt
Image::new(self.imgs.armor_slot)
2020-03-17 18:04:06 +00:00
.w_h(45.0, 45.0)
.mid_bottom_with_margin_on(state.ids.chest_bg, -55.0)
2020-03-17 16:02:50 +00:00
.color(Some(UI_HIGHLIGHT_0))
2020-03-17 18:04:06 +00:00
.set(state.ids.belt_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.belt_bg)
.w_h(40.0, 23.0)
.image_color(UI_MAIN)
.middle_of(state.ids.belt_bg)
.with_tooltip(self.tooltip_manager, "Belt", "", &item_tooltip)
.set(state.ids.belt_ico, ui);
//Legs
2020-03-17 16:02:50 +00:00
Image::new(self.imgs.armor_slot)
2020-03-17 18:04:06 +00:00
.w_h(85.0, 85.0)
.mid_bottom_with_margin_on(state.ids.belt_bg, -95.0)
2020-03-17 16:02:50 +00:00
.color(Some(UI_HIGHLIGHT_0))
2020-03-18 00:43:55 +00:00
.set(state.ids.legs_bg, ui);
Button::image(self.imgs.legs_bg)
.w_h(48.0, 70.0)
.image_color(UI_MAIN)
.middle_of(state.ids.legs_bg)
.with_tooltip(self.tooltip_manager, "Legs", "", &item_tooltip)
.set(state.ids.legs_ico, ui);
2020-03-17 18:48:15 +00:00
//Ring-L
Image::new(self.imgs.armor_slot)
.w_h(45.0, 45.0)
.bottom_right_with_margins_on(state.ids.shoulder_bg, -55.0, 0.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.ring_l_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.ring_l_bg)
.w_h(36.0, 40.0)
.image_color(UI_MAIN)
.middle_of(state.ids.ring_l_bg)
.with_tooltip(self.tooltip_manager, "Left Ring", "", &item_tooltip)
.set(state.ids.ring_l_ico, ui);
2020-03-17 18:48:15 +00:00
//Ring-R
Image::new(self.imgs.armor_slot)
.w_h(45.0, 45.0)
.bottom_left_with_margins_on(state.ids.hands_bg, -55.0, 0.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.ring_r_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.ring_r_bg)
.w_h(36.0, 40.0)
.image_color(UI_MAIN)
.middle_of(state.ids.ring_r_bg)
.with_tooltip(self.tooltip_manager, "Right Ring", "", &item_tooltip)
.set(state.ids.ring_r_ico, ui);
2020-03-17 18:48:15 +00:00
//Back
Image::new(self.imgs.armor_slot)
.w_h(45.0, 45.0)
.down_from(state.ids.ring_l_bg, 10.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.back_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.back_bg)
.w_h(33.0, 40.0)
.image_color(UI_MAIN)
.middle_of(state.ids.back_bg)
.with_tooltip(self.tooltip_manager, "Back", "", &item_tooltip)
.set(state.ids.back_ico, ui);
2020-03-17 18:48:15 +00:00
//Foot
Image::new(self.imgs.armor_slot)
.w_h(45.0, 45.0)
.down_from(state.ids.ring_r_bg, 10.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.foot_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.feet_bg)
.w_h(32.0, 40.0)
.image_color(UI_MAIN)
.middle_of(state.ids.foot_bg)
.with_tooltip(self.tooltip_manager, "Feet", "", &item_tooltip)
.set(state.ids.foot_ico, ui);
2020-03-17 18:48:15 +00:00
//Tabard
Image::new(self.imgs.armor_slot)
.w_h(70.0, 70.0)
.top_right_with_margins_on(state.ids.bg_frame, 80.5, 53.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.tabard_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.tabard_bg)
.w_h(60.0, 60.0)
.image_color(UI_MAIN)
.middle_of(state.ids.tabard_bg)
.with_tooltip(self.tooltip_manager, "Tabard", "", &item_tooltip)
.set(state.ids.tabard_ico, ui);
2020-03-17 18:48:15 +00:00
//Mainhand/Left-Slot
Image::new(self.imgs.armor_slot)
.w_h(85.0, 85.0)
.bottom_right_with_margins_on(state.ids.back_bg, -95.0, 0.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.mainhand_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.mainhand_bg)
.w_h(75.0, 75.0)
.image_color(UI_MAIN)
.middle_of(state.ids.mainhand_bg)
.with_tooltip(self.tooltip_manager, "Mainhand", "", &item_tooltip)
.set(state.ids.mainhand_ico, ui);
2020-03-17 18:48:15 +00:00
//Offhand/Right-Slot
Image::new(self.imgs.armor_slot)
.w_h(85.0, 85.0)
.bottom_left_with_margins_on(state.ids.foot_bg, -95.0, 0.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.offhand_bg, ui);
2020-03-18 00:43:55 +00:00
Button::image(self.imgs.offhand_bg)
.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 {
// Stats
2020-03-16 21:58:19 +00:00
// Title
Text::new(&format!(
"{}{}",
&self.stats.name,
&self.localized_strings.get("hud.bag.stats")
))
.mid_top_with_margin_on(state.ids.bg_frame, 9.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(22))
.color(Color::Rgba(0.0, 0.0, 0.0, 1.0))
.set(state.ids.inventory_title_bg, ui);
Text::new(&format!(
"{}{}",
&self.stats.name,
&self.localized_strings.get("hud.bag.stats")
))
.top_left_with_margins_on(state.ids.inventory_title_bg, 2.0, 2.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(22))
.color(TEXT_COLOR)
.set(state.ids.inventory_title, ui);
// Alignment for Stats
Rectangle::fill_with([418.0, 384.0], color::TRANSPARENT)
.mid_top_with_margin_on(state.ids.bg_frame, 48.0)
.scroll_kids_vertically()
.set(state.ids.stats_alignment, ui);
// Level
Text::new(&level)
.mid_top_with_margin_on(state.ids.stats_alignment, 10.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(30))
.color(TEXT_COLOR)
.set(state.ids.level, ui);
// Exp-Bar Background
Rectangle::fill_with([170.0, 10.0], color::BLACK)
.mid_top_with_margin_on(state.ids.stats_alignment, 50.0)
.set(state.ids.exp_rectangle, ui);
// Exp-Bar Progress
Rectangle::fill_with([170.0 * (exp_percentage), 6.0], XP_COLOR) // 0.8 = Experience percentage
.mid_left_with_margin_on(state.ids.expbar, 1.0)
.set(state.ids.exp_progress_rectangle, ui);
// Exp-Bar Foreground Frame
Image::new(self.imgs.progress_frame)
.w_h(170.0, 10.0)
.middle_of(state.ids.exp_rectangle)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.expbar, ui);
// Exp-Text
Text::new(&exp_treshold)
.mid_top_with_margin_on(state.ids.expbar, 10.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(15))
.color(TEXT_COLOR)
.set(state.ids.exp, ui);
// Divider
/*Image::new(self.imgs.divider)
.w_h(50.0, 5.0)
.mid_top_with_margin_on(state.ids.exp, 30.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.divider, ui);*/
2019-07-25 22:52:28 +00:00
// Stats
Text::new(
&self
.localized_strings
.get("character_window.character_stats"),
)
.top_left_with_margins_on(state.ids.stats_alignment, 120.0, 150.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(16))
.color(TEXT_COLOR)
.set(state.ids.statnames, ui);
2020-03-20 19:52:32 +00:00
Image::new(self.imgs.endurance_ico)
.w_h(30.0, 30.0)
.top_left_with_margins_on(state.ids.statnames, -10.0, -40.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.end_ico, ui);
Image::new(self.imgs.fitness_ico)
.w_h(30.0, 30.0)
.down_from(state.ids.end_ico, 10.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.fit_ico, ui);
Image::new(self.imgs.willpower_ico)
.w_h(30.0, 30.0)
.down_from(state.ids.fit_ico, 10.0)
.color(Some(UI_HIGHLIGHT_0))
.set(state.ids.wp_ico, ui);
Text::new(&format!(
"{}\n\n{}\n\n{}",
self.stats.endurance, self.stats.fitness, self.stats.willpower
))
.top_right_with_margins_on(state.ids.stats_alignment, 120.0, 150.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(16))
.color(TEXT_COLOR)
.set(state.ids.stats, ui);
}
// Bag Slots
2019-09-27 04:23:42 +00:00
// Create available inventory slot widgets
2019-07-25 22:52:28 +00:00
if state.ids.inv_slots.len() < inventory.len() {
state.update(|s| {
s.ids
.inv_slots
.resize(inventory.len(), &mut ui.widget_id_generator());
});
}
if state.ids.items.len() < inventory.len() {
2019-06-29 13:03:48 +00:00
state.update(|s| {
s.ids
2019-07-25 22:52:28 +00:00
.items
.resize(inventory.len(), &mut ui.widget_id_generator());
2019-06-29 13:03:48 +00:00
});
}
2020-03-19 15:51:50 +00:00
if state.ids.amounts.len() < inventory.len() {
state.update(|s| {
s.ids
.amounts
.resize(inventory.len(), &mut ui.widget_id_generator());
});
}
if state.ids.amounts_bg.len() < inventory.len() {
state.update(|s| {
s.ids
.amounts_bg
.resize(inventory.len(), &mut ui.widget_id_generator());
});
}
2019-10-09 19:28:05 +00:00
// Expand img id cache to the number of slots
if state.img_id_cache.len() < inventory.len() {
state.update(|s| {
s.img_id_cache.resize(inventory.len(), None);
});
}
2019-07-25 22:52:28 +00:00
// Display inventory contents
for (i, item) in inventory.slots().iter().enumerate() {
2020-03-15 16:27:56 +00:00
let x = i % 9;
let y = i / 9;
2019-07-25 22:52:28 +00:00
2019-07-26 17:08:40 +00:00
let is_selected = Some(i) == state.selected_slot;
2019-07-25 22:52:28 +00:00
// Slot
2019-10-09 19:28:05 +00:00
let slot_widget = Button::image(if !is_selected {
self.imgs.inv_slot
} else {
self.imgs.inv_slot_sel
})
.top_left_with_margins_on(
state.ids.inv_alignment,
2020-03-15 16:27:56 +00:00
0.0 + y as f64 * (40.0),
0.0 + x as f64 * (40.0),
)
2020-03-15 20:33:51 +00:00
.wh([40.0; 2])
.image_color(UI_MAIN);
2019-09-26 13:41:04 +00:00
2019-09-27 04:23:42 +00:00
let slot_widget_clicked = if let Some(item) = item {
2019-09-26 13:41:04 +00:00
slot_widget
.with_tooltip(
self.tooltip_manager,
&item.name(),
&format!(
"{}",
/* item.kind, item.effect(), */ item.description()
),
2019-09-26 13:41:04 +00:00
&item_tooltip,
2019-09-26 15:07:09 +00:00
)
2019-09-26 13:41:04 +00:00
.set(state.ids.inv_slots[i], ui)
} else {
slot_widget.set(state.ids.inv_slots[i], ui)
2019-09-27 04:23:42 +00:00
}
.was_clicked();
2019-09-26 00:25:14 +00:00
// Item
2019-09-27 04:23:42 +00:00
if slot_widget_clicked {
2019-07-26 17:08:40 +00:00
let selected_slot = match state.selected_slot {
Some(a) => {
if a == i {
event = Some(Event::HudEvent(HudEvent::UseInventorySlot(i)));
2019-07-26 17:08:40 +00:00
} else {
event = Some(Event::HudEvent(HudEvent::SwapInventorySlots(a, i)));
}
None
},
2019-07-26 17:08:40 +00:00
None if item.is_some() => Some(i),
None => None,
};
state.update(|s| s.selected_slot = selected_slot);
2019-07-25 22:52:28 +00:00
}
2019-09-26 13:41:04 +00:00
// Item
if let Some(kind) = item.as_ref().map(|i| ItemKey::from(i)) {
2020-03-19 14:49:32 +00:00
//Stack Size
2019-10-09 19:28:05 +00:00
Button::image(match &state.img_id_cache[i] {
Some((cached_kind, id)) if cached_kind == &kind => *id,
_ => {
let id = self
.item_imgs
.img_id(kind.clone())
.unwrap_or(self.imgs.not_found);
state.update(|s| s.img_id_cache[i] = Some((kind, id)));
id
},
2019-10-09 19:28:05 +00:00
})
2020-01-24 15:10:38 +00:00
.wh(if is_selected { [32.0; 2] } else { [30.0; 2] })
.middle_of(state.ids.inv_slots[i])
2019-10-09 19:28:05 +00:00
.graphics_for(state.ids.inv_slots[i])
.set(state.ids.items[i], ui);
2019-07-25 22:52:28 +00:00
}
2020-03-19 15:43:11 +00:00
if let Some(item) = item {
if let Some(amount) = match item.kind {
ItemKind::Tool { .. } | ItemKind::Armor { .. } => None,
ItemKind::Utility { amount, .. }
| ItemKind::Consumable { amount, .. }
| ItemKind::Ingredient { amount, .. } => Some(amount),
} {
2020-03-19 18:33:59 +00:00
if amount > 1 {
2020-03-19 15:43:11 +00:00
Text::new(&format!("{}", &amount))
2020-03-19 18:33:59 +00:00
.top_right_with_margins_on(state.ids.items[i], -4.0, 0.0)
2020-03-19 15:43:11 +00:00
.font_id(self.fonts.cyri.conrod_id)
2020-03-19 18:33:59 +00:00
.floating(true)
.font_size(self.fonts.cyri.scale(12))
2020-03-19 15:43:11 +00:00
.color(Color::Rgba(0.0, 0.0, 0.0, 1.0))
.floating(true)
.set(state.ids.amounts_bg[i], ui);
Text::new(&format!("{}", &amount))
2020-03-19 19:01:31 +00:00
.bottom_left_with_margins_on(state.ids.amounts_bg[i], 1.0, 1.0)
2020-03-19 15:43:11 +00:00
.font_id(self.fonts.cyri.conrod_id)
2020-03-19 18:33:59 +00:00
.font_size(self.fonts.cyri.scale(12))
2020-03-19 15:43:11 +00:00
.color(TEXT_COLOR)
.floating(true)
.set(state.ids.amounts[i], ui);
}
}
}
2019-06-29 01:47:38 +00:00
}
2019-07-25 22:52:28 +00:00
// Drop selected item
if let Some(to_drop) = state.selected_slot {
if ui.widget_input(ui.window).clicks().left().next().is_some() {
event = Some(Event::HudEvent(HudEvent::DropInventorySlot(to_drop)));
state.update(|s| s.selected_slot = None);
}
}
// Stats Button
if Button::image(self.imgs.button)
.w_h(92.0, 22.0)
.mid_top_with_margin_on(state.ids.bg, 435.0)
.hover_image(self.imgs.button_hover)
.press_image(self.imgs.button_press)
.label(if self.show.stats { "Armor" } else { "Stats" })
.label_y(conrod_core::position::Relative::Scalar(1.0))
.label_color(TEXT_COLOR)
.label_font_size(self.fonts.cyri.scale(12))
.label_font_id(self.fonts.cyri.conrod_id)
.set(state.ids.stats_button, ui)
.was_clicked()
{
return Some(Event::Stats);
};
// Tabs
if Button::image(self.imgs.inv_tab_active)
.w_h(28.0, 44.0)
.bottom_left_with_margins_on(state.ids.bg, 172.0, 13.0)
2020-03-18 18:51:48 +00:00
.image_color(UI_MAIN)
.set(state.ids.tab_1, ui)
.was_clicked()
{}
if Button::image(self.imgs.inv_tab_inactive)
.w_h(28.0, 44.0)
.hover_image(self.imgs.inv_tab_inactive_hover)
.press_image(self.imgs.inv_tab_inactive_press)
.image_color(UI_HIGHLIGHT_0)
.down_from(state.ids.tab_1, 0.0)
.with_tooltip(self.tooltip_manager, "Not yet Available", "", &item_tooltip)
.set(state.ids.tab_2, ui)
.was_clicked()
{}
if Button::image(self.imgs.inv_tab_inactive)
.w_h(28.0, 44.0)
.hover_image(self.imgs.inv_tab_inactive_hover)
.press_image(self.imgs.inv_tab_inactive_press)
.down_from(state.ids.tab_2, 0.0)
.image_color(UI_HIGHLIGHT_0)
.with_tooltip(self.tooltip_manager, "Not yet Available", "", &item_tooltip)
.set(state.ids.tab_3, ui)
.was_clicked()
{}
if Button::image(self.imgs.inv_tab_inactive)
.w_h(28.0, 44.0)
.hover_image(self.imgs.inv_tab_inactive_hover)
.press_image(self.imgs.inv_tab_inactive_press)
.down_from(state.ids.tab_3, 0.0)
.image_color(UI_HIGHLIGHT_0)
.with_tooltip(self.tooltip_manager, "Not yet Available", "", &item_tooltip)
.set(state.ids.tab_4, ui)
.was_clicked()
{}
2020-03-16 18:56:15 +00:00
// Close button
if Button::image(self.imgs.close_btn)
.w_h(24.0, 25.0)
.hover_image(self.imgs.close_btn_hover)
.press_image(self.imgs.close_btn_press)
.top_right_with_margins_on(state.ids.bg, 0.0, 0.0)
.set(state.ids.bag_close, ui)
.was_clicked()
{
event = Some(Event::Close);
}
2019-07-25 22:52:28 +00:00
event
}
}