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:
@ -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 client::Client;
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
color,
|
color,
|
||||||
position::Relative,
|
position::Relative,
|
||||||
widget::{self, Button, Image, Rectangle /*, Scrollbar*/},
|
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! {
|
widget_ids! {
|
||||||
struct Ids {
|
struct Ids {
|
||||||
@ -31,15 +37,19 @@ pub struct Bag<'a> {
|
|||||||
fonts: &'a Fonts,
|
fonts: &'a Fonts,
|
||||||
#[conrod(common_builder)]
|
#[conrod(common_builder)]
|
||||||
common: widget::CommonBuilder,
|
common: widget::CommonBuilder,
|
||||||
|
rot_imgs: &'a ImgsRot,
|
||||||
|
tooltip_manager: &'a TooltipManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Bag<'a> {
|
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 {
|
Self {
|
||||||
client,
|
client,
|
||||||
imgs,
|
imgs,
|
||||||
fonts,
|
fonts,
|
||||||
common: widget::CommonBuilder::default(),
|
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 {
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||||
let widget::UpdateArgs { state, ui, .. } = args;
|
let widget::UpdateArgs { state, ui, .. } = args;
|
||||||
|
|
||||||
let mut event = None;
|
let mut event = None;
|
||||||
|
|
||||||
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(inv) => inv,
|
||||||
None => return None,
|
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
|
// Bag parts
|
||||||
Image::new(self.imgs.bag_bot)
|
Image::new(self.imgs.bag_bot)
|
||||||
@ -178,6 +205,7 @@ impl<'a> Widget for Bag<'a> {
|
|||||||
.label_color(TEXT_COLOR)
|
.label_color(TEXT_COLOR)
|
||||||
.parent(state.ids.inv_slots[i])
|
.parent(state.ids.inv_slots[i])
|
||||||
.graphics_for(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);
|
.set(state.ids.items[i], ui);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
use crate::ui::img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic, VoxelMs9Graphic};
|
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! {
|
image_ids! {
|
||||||
pub struct Imgs {
|
pub struct Imgs {
|
||||||
|
@ -12,6 +12,7 @@ mod skillbar;
|
|||||||
mod social;
|
mod social;
|
||||||
mod spell;
|
mod spell;
|
||||||
|
|
||||||
|
use crate::hud::img_ids::ImgsRot;
|
||||||
pub use settings_window::ScaleChange;
|
pub use settings_window::ScaleChange;
|
||||||
|
|
||||||
use bag::Bag;
|
use bag::Bag;
|
||||||
@ -34,7 +35,7 @@ use crate::{
|
|||||||
render::{Consts, Globals, Renderer},
|
render::{Consts, Globals, Renderer},
|
||||||
scene::camera::Camera,
|
scene::camera::Camera,
|
||||||
settings::ControlSettings,
|
settings::ControlSettings,
|
||||||
ui::{Ingameable, ScaleMode, Ui},
|
ui::{Ingameable, ScaleMode, Ui, TooltipManager},
|
||||||
window::{Event as WinEvent, GameInput},
|
window::{Event as WinEvent, GameInput},
|
||||||
GlobalState,
|
GlobalState,
|
||||||
};
|
};
|
||||||
@ -360,11 +361,13 @@ impl Show {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Hud {
|
pub struct Hud<'a> {
|
||||||
ui: Ui,
|
ui: Ui,
|
||||||
ids: Ids,
|
ids: Ids,
|
||||||
imgs: Imgs,
|
imgs: Imgs,
|
||||||
fonts: Fonts,
|
fonts: Fonts,
|
||||||
|
rot_imgs: ImgsRot,
|
||||||
|
tooltip_manager: &'a mut TooltipManager,
|
||||||
new_messages: VecDeque<ClientEvent>,
|
new_messages: VecDeque<ClientEvent>,
|
||||||
inventory_space: usize,
|
inventory_space: usize,
|
||||||
show: Show,
|
show: Show,
|
||||||
@ -374,7 +377,7 @@ pub struct Hud {
|
|||||||
force_chat_cursor: Option<Index>,
|
force_chat_cursor: Option<Index>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hud {
|
impl Hud<'_> {
|
||||||
pub fn new(global_state: &mut GlobalState) -> Self {
|
pub fn new(global_state: &mut GlobalState) -> Self {
|
||||||
let window = &mut global_state.window;
|
let window = &mut global_state.window;
|
||||||
let settings = &global_state.settings;
|
let settings = &global_state.settings;
|
||||||
@ -391,10 +394,12 @@ impl Hud {
|
|||||||
Self {
|
Self {
|
||||||
ui,
|
ui,
|
||||||
imgs,
|
imgs,
|
||||||
|
rot_imgs,
|
||||||
fonts,
|
fonts,
|
||||||
ids,
|
ids,
|
||||||
new_messages: VecDeque::new(),
|
new_messages: VecDeque::new(),
|
||||||
inventory_space: 8,
|
inventory_space: 8,
|
||||||
|
tooltip_manager,
|
||||||
show: Show {
|
show: Show {
|
||||||
help: false,
|
help: false,
|
||||||
debug: true,
|
debug: true,
|
||||||
@ -428,7 +433,7 @@ impl Hud {
|
|||||||
debug_info: DebugInfo,
|
debug_info: DebugInfo,
|
||||||
) -> Vec<Event> {
|
) -> Vec<Event> {
|
||||||
let mut events = Vec::new();
|
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);
|
let version = format!("{}-{}", env!("CARGO_PKG_VERSION"), common::util::GIT_HASH);
|
||||||
|
|
||||||
@ -723,7 +728,7 @@ impl Hud {
|
|||||||
|
|
||||||
// Bag contents
|
// Bag contents
|
||||||
if self.show.bag {
|
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::HudEvent(event)) => events.push(event),
|
||||||
Some(bag::Event::Close) => {
|
Some(bag::Event::Close) => {
|
||||||
self.show.bag(false);
|
self.show.bag(false);
|
||||||
|
@ -16,7 +16,7 @@ pub use widgets::{
|
|||||||
image_slider::ImageSlider,
|
image_slider::ImageSlider,
|
||||||
ingame::{Ingame, IngameAnchor, Ingameable},
|
ingame::{Ingame, IngameAnchor, Ingameable},
|
||||||
toggle_button::ToggleButton,
|
toggle_button::ToggleButton,
|
||||||
tooltip::{Tooltip, Tooltipable},
|
tooltip::{Tooltip, Tooltipable, TooltipManager},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -49,7 +49,6 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use widgets::tooltip::TooltipManager;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum UiError {
|
pub enum UiError {
|
||||||
|
Reference in New Issue
Block a user