mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
added item tooltips
This commit is contained in:
parent
bdf74cf151
commit
931e53ebbe
@ -1,11 +1,17 @@
|
||||
use super::{img_ids::Imgs, Event as HudEvent, Fonts, TEXT_COLOR};
|
||||
use super::{img_ids::{Imgs, ImgsRot}, Event as HudEvent, Fonts, TEXT_COLOR, TEXT_COLOR_2};
|
||||
use client::Client;
|
||||
use conrod_core::{
|
||||
color,
|
||||
position::Relative,
|
||||
widget::{self, Button, Image, Rectangle /*, Scrollbar*/},
|
||||
widget_ids, /*Color, Colorable,*/ Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
widget_ids, Color, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
use crate::{
|
||||
ui::{
|
||||
ImageFrame, Tooltip, Tooltipable, TooltipManager
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
widget_ids! {
|
||||
struct Ids {
|
||||
@ -31,15 +37,19 @@ pub struct Bag<'a> {
|
||||
fonts: &'a Fonts,
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
rot_imgs: &'a ImgsRot,
|
||||
tooltip_manager: &'a TooltipManager,
|
||||
}
|
||||
|
||||
impl<'a> Bag<'a> {
|
||||
pub fn new(client: &'a Client, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
||||
pub fn new(client: &'a Client, imgs: &'a Imgs, fonts: &'a Fonts, tooltip_manager: &'a TooltipManager, rot_imgs: &'a ImgsRot,) -> Self {
|
||||
Self {
|
||||
client,
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
rot_imgs,
|
||||
tooltip_manager,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,13 +85,30 @@ impl<'a> Widget for Bag<'a> {
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs { state, ui, .. } = args;
|
||||
|
||||
let mut event = None;
|
||||
let mut event = None;
|
||||
|
||||
let invs = self.client.inventories();
|
||||
let inventory = match invs.get(self.client.entity()) {
|
||||
Some(inv) => inv,
|
||||
None => return None,
|
||||
};
|
||||
// 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(15)
|
||||
.desc_font_size(10)
|
||||
.title_text_color(TEXT_COLOR)
|
||||
.desc_text_color(TEXT_COLOR_2);
|
||||
|
||||
// Bag parts
|
||||
Image::new(self.imgs.bag_bot)
|
||||
@ -178,6 +205,7 @@ impl<'a> Widget for Bag<'a> {
|
||||
.label_color(TEXT_COLOR)
|
||||
.parent(state.ids.inv_slots[i])
|
||||
.graphics_for(state.ids.inv_slots[i])
|
||||
.with_tooltip(&mut self.tooltip_manager, "Test", "", &item_tooltip)
|
||||
.set(state.ids.items[i], ui);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,13 @@
|
||||
use crate::ui::img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic, VoxelMs9Graphic};
|
||||
rotation_image_ids! {
|
||||
pub struct ImgsRot {
|
||||
<VoxelGraphic>
|
||||
|
||||
// Tooltip Test
|
||||
tt_side: "voxygen/element/frames/tt_test_edge",
|
||||
tt_corner: "voxygen/element/frames/tt_test_corner_tr",
|
||||
}
|
||||
}
|
||||
|
||||
image_ids! {
|
||||
pub struct Imgs {
|
||||
|
@ -12,6 +12,7 @@ mod skillbar;
|
||||
mod social;
|
||||
mod spell;
|
||||
|
||||
use crate::hud::img_ids::ImgsRot;
|
||||
pub use settings_window::ScaleChange;
|
||||
|
||||
use bag::Bag;
|
||||
@ -34,7 +35,7 @@ use crate::{
|
||||
render::{Consts, Globals, Renderer},
|
||||
scene::camera::Camera,
|
||||
settings::ControlSettings,
|
||||
ui::{Ingameable, ScaleMode, Ui},
|
||||
ui::{Ingameable, ScaleMode, Ui, TooltipManager},
|
||||
window::{Event as WinEvent, GameInput},
|
||||
GlobalState,
|
||||
};
|
||||
@ -360,11 +361,13 @@ impl Show {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Hud {
|
||||
pub struct Hud<'a> {
|
||||
ui: Ui,
|
||||
ids: Ids,
|
||||
imgs: Imgs,
|
||||
fonts: Fonts,
|
||||
rot_imgs: ImgsRot,
|
||||
tooltip_manager: &'a mut TooltipManager,
|
||||
new_messages: VecDeque<ClientEvent>,
|
||||
inventory_space: usize,
|
||||
show: Show,
|
||||
@ -374,7 +377,7 @@ pub struct Hud {
|
||||
force_chat_cursor: Option<Index>,
|
||||
}
|
||||
|
||||
impl Hud {
|
||||
impl Hud<'_> {
|
||||
pub fn new(global_state: &mut GlobalState) -> Self {
|
||||
let window = &mut global_state.window;
|
||||
let settings = &global_state.settings;
|
||||
@ -391,10 +394,12 @@ impl Hud {
|
||||
Self {
|
||||
ui,
|
||||
imgs,
|
||||
rot_imgs,
|
||||
fonts,
|
||||
ids,
|
||||
new_messages: VecDeque::new(),
|
||||
inventory_space: 8,
|
||||
tooltip_manager,
|
||||
show: Show {
|
||||
help: false,
|
||||
debug: true,
|
||||
@ -428,7 +433,7 @@ impl Hud {
|
||||
debug_info: DebugInfo,
|
||||
) -> Vec<Event> {
|
||||
let mut events = Vec::new();
|
||||
let ref mut ui_widgets = self.ui.set_widgets().0;
|
||||
let (ref mut ui_widgets, ref mut tooltip_manager) = self.ui.set_widgets();
|
||||
|
||||
let version = format!("{}-{}", env!("CARGO_PKG_VERSION"), common::util::GIT_HASH);
|
||||
|
||||
@ -723,7 +728,7 @@ impl Hud {
|
||||
|
||||
// Bag contents
|
||||
if self.show.bag {
|
||||
match Bag::new(client, &self.imgs, &self.fonts).set(self.ids.bag, ui_widgets) {
|
||||
match Bag::new(client, &self.imgs, &self.rot_imgs, &self.fonts, &self.tooltip_manager).set(self.ids.bag, ui_widgets) {
|
||||
Some(bag::Event::HudEvent(event)) => events.push(event),
|
||||
Some(bag::Event::Close) => {
|
||||
self.show.bag(false);
|
||||
|
@ -16,7 +16,7 @@ pub use widgets::{
|
||||
image_slider::ImageSlider,
|
||||
ingame::{Ingame, IngameAnchor, Ingameable},
|
||||
toggle_button::ToggleButton,
|
||||
tooltip::{Tooltip, Tooltipable},
|
||||
tooltip::{Tooltip, Tooltipable, TooltipManager},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -49,7 +49,6 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
use vek::*;
|
||||
use widgets::tooltip::TooltipManager;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UiError {
|
||||
|
Loading…
Reference in New Issue
Block a user