Fix rot_imgs and tooltip manager

This commit is contained in:
timokoesters 2019-09-25 22:18:40 +02:00 committed by Pfauenauge90
parent 931e53ebbe
commit 1fc7c9b67b
3 changed files with 31 additions and 17 deletions

View File

@ -1,4 +1,8 @@
use super::{img_ids::{Imgs, ImgsRot}, Event as HudEvent, Fonts, TEXT_COLOR, TEXT_COLOR_2};
use super::{
img_ids::{Imgs, ImgsRot},
Event as HudEvent, Fonts, TEXT_COLOR, TEXT_COLOR_2,
};
use crate::ui::{ImageFrame, Tooltip, TooltipManager, Tooltipable};
use client::Client;
use conrod_core::{
color,
@ -6,12 +10,6 @@ use conrod_core::{
widget::{self, Button, Image, Rectangle /*, Scrollbar*/},
widget_ids, Color, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
};
use crate::{
ui::{
ImageFrame, Tooltip, Tooltipable, TooltipManager
}
};
widget_ids! {
struct Ids {
@ -38,11 +36,17 @@ pub struct Bag<'a> {
#[conrod(common_builder)]
common: widget::CommonBuilder,
rot_imgs: &'a ImgsRot,
tooltip_manager: &'a TooltipManager,
tooltip_manager: &'a mut TooltipManager,
}
impl<'a> Bag<'a> {
pub fn new(client: &'a Client, imgs: &'a Imgs, fonts: &'a Fonts, tooltip_manager: &'a TooltipManager, rot_imgs: &'a ImgsRot,) -> Self {
pub fn new(
client: &'a Client,
imgs: &'a Imgs,
fonts: &'a Fonts,
rot_imgs: &'a ImgsRot,
tooltip_manager: &'a mut TooltipManager,
) -> Self {
Self {
client,
imgs,
@ -85,7 +89,7 @@ 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()) {
@ -205,7 +209,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)
.with_tooltip(self.tooltip_manager, "Test", "", &item_tooltip)
.set(state.ids.items[i], ui);
}
}

View File

@ -1,4 +1,6 @@
use crate::ui::img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic, VoxelMs9Graphic};
// TODO: Combine with image_ids, see macro definition
rotation_image_ids! {
pub struct ImgsRot {
<VoxelGraphic>

View File

@ -35,7 +35,7 @@ use crate::{
render::{Consts, Globals, Renderer},
scene::camera::Camera,
settings::ControlSettings,
ui::{Ingameable, ScaleMode, Ui, TooltipManager},
ui::{Ingameable, ScaleMode, TooltipManager, Ui},
window::{Event as WinEvent, GameInput},
GlobalState,
};
@ -361,13 +361,12 @@ impl Show {
}
}
pub struct Hud<'a> {
pub struct Hud {
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,
@ -377,7 +376,7 @@ pub struct Hud<'a> {
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;
@ -388,6 +387,8 @@ impl Hud<'_> {
let ids = Ids::new(ui.id_generator());
// Load images.
let imgs = Imgs::load(&mut ui).expect("Failed to load images!");
// Load rotation images.
let rot_imgs = ImgsRot::load(&mut ui).expect("Failed to load rot images!");
// Load fonts.
let fonts = Fonts::load(&mut ui).expect("Failed to load fonts!");
@ -399,7 +400,6 @@ impl Hud<'_> {
ids,
new_messages: VecDeque::new(),
inventory_space: 8,
tooltip_manager,
show: Show {
help: false,
debug: true,
@ -728,7 +728,15 @@ impl Hud<'_> {
// Bag contents
if self.show.bag {
match Bag::new(client, &self.imgs, &self.rot_imgs, &self.fonts, &self.tooltip_manager).set(self.ids.bag, ui_widgets) {
match Bag::new(
client,
&self.imgs,
&self.fonts,
&self.rot_imgs,
tooltip_manager,
)
.set(self.ids.bag, ui_widgets)
{
Some(bag::Event::HudEvent(event)) => events.push(event),
Some(bag::Event::Close) => {
self.show.bag(false);