integrate timo's macro change

Former-commit-id: a7657636efe4ce1db8c1714077262585e662c982
This commit is contained in:
Imbris 2019-04-28 12:44:44 -04:00
parent 33fbcd1e93
commit 2f9358f167
4 changed files with 36 additions and 41 deletions

View File

@ -6,7 +6,7 @@ use conrod_core::{
};
use super::{
imgs::{Imgs, Voxs},
imgs::Imgs,
WindowStyle, XP_COLOR,
};
@ -35,7 +35,6 @@ widget_ids! {
pub struct CharacterWindow<'a> {
xp_percentage: f64,
imgs: &'a Imgs,
voxs: &'a Voxs,
#[conrod(common_builder)]
common: widget::CommonBuilder,
@ -43,11 +42,10 @@ pub struct CharacterWindow<'a> {
}
impl<'a> CharacterWindow<'a> {
pub fn new(imgs: &'a Imgs, voxs: &'a Voxs) -> Self {
pub fn new(imgs: &'a Imgs) -> Self {
Self {
xp_percentage: 0.4,
imgs,
voxs,
common: widget::CommonBuilder::default(),
style: WindowStyle::default(),
}
@ -97,7 +95,7 @@ impl<'a> Widget for CharacterWindow<'a> {
let text_color = style.text_color(&ui.theme);
// Frame
Image::new(self.voxs.window_frame)
Image::new(self.imgs.window_frame)
.middle_of(id)
.set(state.ids.charwindow_frame, ui);
@ -119,10 +117,10 @@ impl<'a> Widget for CharacterWindow<'a> {
//.set(state.ids.charwindow_icon, ui);
// X-Button
let closed = Button::image(self.voxs.close_button)
let closed = Button::image(self.imgs.close_button)
.w_h(244.0 * 0.22 / 4.0, 244.0 * 0.22 / 4.0)
.hover_image(self.voxs.close_button_hover)
.press_image(self.voxs.close_button_press)
.hover_image(self.imgs.close_button_hover)
.press_image(self.imgs.close_button_press)
.top_right_with_margins_on(state.ids.charwindow_frame, 4.0, 4.0)
.set(state.ids.charwindow_close, ui)
.was_clicked();

View File

@ -1,5 +1,6 @@
image_ids! {
pub struct<dot_vox::DotVoxData> Voxs {
pub struct Imgs {
<dot_vox::DotVoxData>
// Bag
bag_contents: "/voxygen/element/frames/bag.vox",
inv_grid: "/voxygen/element/frames/inv_grid.vox",
@ -43,9 +44,8 @@ image_ids! {
window_frame: "/voxygen/element/frames/window2.vox",
map_frame_l: "/voxygen/element/frames/map_l.vox",
map_frame_r: "/voxygen/element/frames/map_r.vox",
}
pub struct<image::DynamicImage> Imgs {
<image::DynamicImage>
// Bag
bag: "/voxygen/element/buttons/bag/closed.png",
bag_hover: "/voxygen/element/buttons/bag/closed_hover.png",

View File

@ -3,7 +3,7 @@ mod character_window;
mod imgs;
use character_window::CharacterWindow;
use imgs::{Imgs, Voxs};
use imgs::Imgs;
use crate::{
render::Renderer,
@ -225,7 +225,6 @@ pub struct Hud {
ui: Ui,
ids: Ids,
imgs: Imgs,
voxs: Voxs,
blank_img: conrod_core::image::Id,
chat: chat::Chat,
font_metamorph: FontId,
@ -256,8 +255,6 @@ impl Hud {
let ids = Ids::new(ui.id_generator());
// Load images
let imgs = Imgs::load(&mut ui).unwrap();
// Load vox files
let voxs = Voxs::load(&mut ui).unwrap();
// Blank graphic
let blank_img = ui.new_graphic(Graphic::Blank);
// Load fonts
@ -279,7 +276,6 @@ impl Hud {
Self {
ui,
imgs,
voxs,
blank_img,
ids,
chat,
@ -367,10 +363,10 @@ impl Hud {
.font_size(18)
.set(self.ids.help, ui_widgets);
// X-button
if Button::image(self.voxs.close_button)
if Button::image(self.imgs.close_button)
.w_h(100.0 * 0.2, 100.0 * 0.2)
.hover_image(self.voxs.close_button_hover)
.press_image(self.voxs.close_button_press)
.hover_image(self.imgs.close_button_hover)
.press_image(self.imgs.close_button_press)
.top_right_with_margins_on(self.ids.help_bg, 8.0, 3.0)
.set(self.ids.button_help2, ui_widgets)
.was_clicked()
@ -431,7 +427,7 @@ impl Hud {
// Buttons at Bag
// 0 Settings
if Button::image(self.voxs.settings)
if Button::image(self.imgs.settings)
.w_h(29.0, 25.0)
.bottom_right_with_margins_on(ui_widgets.window, 5.0, 57.0)
.hover_image(self.imgs.settings_hover)
@ -454,7 +450,7 @@ impl Hud {
};
// 2 Map
if Button::image(self.voxs.map_button)
if Button::image(self.imgs.map_button)
.w_h(22.0, 25.0)
.left_from(self.ids.social_button, 10.0)
.hover_image(self.imgs.map_hover)
@ -475,19 +471,19 @@ impl Hud {
// Other Windows can only be accessed, when Settings are closed.
// Opening Settings will close all other Windows including the Bag.
// Opening the Map won't close the windows displayed before.
Image::new(self.voxs.social_button)
Image::new(self.imgs.social_button)
.w_h(25.0, 25.0)
.left_from(self.ids.settings_button, 10.0)
.set(self.ids.social_button_bg, ui_widgets);
Image::new(self.voxs.spellbook_button)
Image::new(self.imgs.spellbook_button)
.w_h(28.0, 25.0)
.left_from(self.ids.map_button, 10.0)
.set(self.ids.spellbook_button_bg, ui_widgets);
Image::new(self.voxs.character_button)
Image::new(self.imgs.character_button)
.w_h(27.0, 25.0)
.left_from(self.ids.spellbook_button, 10.0)
.set(self.ids.character_button_bg, ui_widgets);
Image::new(self.voxs.qlog_button)
Image::new(self.imgs.qlog_button)
.w_h(23.0, 25.0)
.left_from(self.ids.character_button, 10.0)
.set(self.ids.qlog_button_bg, ui_widgets);
@ -498,7 +494,7 @@ impl Hud {
} && self.map_open == false
{
// 1 Social
if Button::image(self.voxs.social_button)
if Button::image(self.imgs.social_button)
.w_h(25.0, 25.0)
.left_from(self.ids.settings_button, 10.0)
.hover_image(self.imgs.social_hover)
@ -524,7 +520,7 @@ impl Hud {
}
// 3 Spellbook
if Button::image(self.voxs.spellbook_button)
if Button::image(self.imgs.spellbook_button)
.w_h(28.0, 25.0)
.left_from(self.ids.map_button, 10.0)
.hover_image(self.imgs.spellbook_hover)
@ -550,7 +546,7 @@ impl Hud {
}
// 4 Char-Window
if Button::image(self.voxs.character_button)
if Button::image(self.imgs.character_button)
.w_h(27.0, 25.0)
.left_from(self.ids.spellbook_button, 10.0)
.hover_image(self.imgs.character_hover)
@ -1162,12 +1158,12 @@ impl Hud {
Small::Social => {
//Frame
if char_window_open {
Image::new(self.voxs.window_frame)
Image::new(self.imgs.window_frame)
.right_from(self.ids.charwindow_frame, 20.0)
.w_h(107.0 * 4.0, 125.0 * 4.0)
.set(self.ids.social_frame, ui_widgets);
} else {
Image::new(self.voxs.window_frame)
Image::new(self.imgs.window_frame)
.top_left_with_margins_on(ui_widgets.window, 200.0, 10.0)
.w_h(107.0 * 4.0, 125.0 * 4.0)
.set(self.ids.social_frame, ui_widgets);
@ -1212,7 +1208,7 @@ impl Hud {
Small::Spellbook => {
// Frame
if char_window_open {
Image::new(self.voxs.window_frame)
Image::new(self.imgs.window_frame)
.right_from(self.ids.charwindow_frame, 20.0)
.w_h(107.0 * 4.0, 125.0 * 4.0)
.set(self.ids.spellbook_frame, ui_widgets);
@ -1261,7 +1257,7 @@ impl Hud {
Small::Questlog => {
// Frame
if char_window_open {
Image::new(self.voxs.window_frame)
Image::new(self.imgs.window_frame)
.right_from(self.ids.charwindow_frame, 20.0)
.w_h(107.0 * 4.0, 125.0 * 4.0)
.set(self.ids.questlog_frame, ui_widgets);
@ -1310,7 +1306,7 @@ impl Hud {
}
if let Windows::CharacterAnd(small) = self.open_windows {
match CharacterWindow::new(&self.imgs, &self.voxs)
match CharacterWindow::new(&self.imgs)
.font_id(self.font_opensans)
.text_color(TEXT_COLOR)
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
@ -1334,7 +1330,7 @@ impl Hud {
.scroll_kids_vertically()
.set(self.ids.map_bg, ui_widgets);
// Frame
Image::new(self.voxs.map_frame_l)
Image::new(self.imgs.map_frame_l)
.top_left_with_margins_on(self.ids.map_bg, 0.0, 0.0)
.w_h(412.0, 488.0)
.set(self.ids.map_frame_l, ui_widgets);
@ -1384,7 +1380,7 @@ impl Hud {
.middle_of(ui_widgets.window)
.set(self.ids.esc_bg, ui_widgets);
Image::new(self.voxs.fireplace)
Image::new(self.imgs.fireplace)
.w_h(180.0, 60.0)
.mid_top_with_margin_on(self.ids.esc_bg, 50.0)
.set(self.ids.fireplace, ui_widgets);

View File

@ -4,11 +4,12 @@
/// Example usage:
/// ```
/// image_ids! {
/// struct<DotVoxData> Voxs {
/// pub struct Imgs {
/// <DotVoxData>
/// button1: "filename1.vox",
/// button2: "filename2.vox",
/// }
/// struct<DynamicImage> Imgs {
///
/// <DynamicImage>
/// background: "background.png",
/// }
/// }
@ -16,16 +17,16 @@
// TODO: will this work with shorter name paths? eg not rate::ui::Graphic::
#[macro_export]
macro_rules! image_ids {
($($v:vis struct<$T:ty> $Ids:ident { $( $name:ident: $specifier:expr ), *$(,)? } )*) => {
($($v:vis struct $Ids:ident { $( <$T:ty> $( $name:ident: $specifier:expr ),* $(,)? )* })*) => {
$(
$v struct $Ids {
$( $v $name: conrod_core::image::Id, )*
$($( $v $name: conrod_core::image::Id, )*)*
}
impl $Ids {
pub fn load(ui: &mut crate::ui::Ui) -> Result<Self, common::assets::Error> {
Ok(Self {
$( $name: ui.new_graphic(common::assets::load::<$T>($specifier)?.into()), )*
$($( $name: ui.new_graphic(common::assets::load::<$T>($specifier)?.into()), )*)*
})
}
}