mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
integrate blank graphic, remove Graphic from impls
Former-commit-id: 190e03fe98591e8ab29d1202cf462cf6b51ede4d
This commit is contained in:
parent
2f9358f167
commit
775b5e731e
@ -1,6 +1,8 @@
|
||||
use crate::ui::{ImageGraphic, VoxelGraphic, BlankGraphic};
|
||||
|
||||
image_ids! {
|
||||
pub struct Imgs {
|
||||
<dot_vox::DotVoxData>
|
||||
<VoxelGraphic>
|
||||
// Bag
|
||||
bag_contents: "/voxygen/element/frames/bag.vox",
|
||||
inv_grid: "/voxygen/element/frames/inv_grid.vox",
|
||||
@ -45,7 +47,7 @@ image_ids! {
|
||||
map_frame_l: "/voxygen/element/frames/map_l.vox",
|
||||
map_frame_r: "/voxygen/element/frames/map_r.vox",
|
||||
|
||||
<image::DynamicImage>
|
||||
<ImageGraphic>
|
||||
// Bag
|
||||
bag: "/voxygen/element/buttons/bag/closed.png",
|
||||
bag_hover: "/voxygen/element/buttons/bag/closed_hover.png",
|
||||
@ -127,5 +129,8 @@ image_ids! {
|
||||
chat_arrow: "/voxygen/element/buttons/arrow/chat_arrow.png",
|
||||
chat_arrow_mo: "/voxygen/element/buttons/arrow/chat_arrow_mo.png",
|
||||
chat_arrow_press: "/voxygen/element/buttons/arrow/chat_arrow_press.png",
|
||||
|
||||
<BlankGraphic>
|
||||
blank: (),
|
||||
}
|
||||
}
|
||||
|
@ -225,7 +225,6 @@ pub struct Hud {
|
||||
ui: Ui,
|
||||
ids: Ids,
|
||||
imgs: Imgs,
|
||||
blank_img: conrod_core::image::Id,
|
||||
chat: chat::Chat,
|
||||
font_metamorph: FontId,
|
||||
font_opensans: FontId,
|
||||
@ -255,8 +254,6 @@ impl Hud {
|
||||
let ids = Ids::new(ui.id_generator());
|
||||
// Load images
|
||||
let imgs = Imgs::load(&mut ui).unwrap();
|
||||
// Blank graphic
|
||||
let blank_img = ui.new_graphic(Graphic::Blank);
|
||||
// Load fonts
|
||||
let load_font = |filename, ui: &mut Ui| {
|
||||
let fullpath: String = ["/voxygen/font", filename].concat();
|
||||
@ -276,7 +273,6 @@ impl Hud {
|
||||
Self {
|
||||
ui,
|
||||
imgs,
|
||||
blank_img,
|
||||
ids,
|
||||
chat,
|
||||
settings_tab: SettingsTab::Interface,
|
||||
@ -830,7 +826,7 @@ impl Hud {
|
||||
if Button::image(if let SettingsTab::Interface = self.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
self.imgs.settings_button
|
||||
self.imgs.blank
|
||||
})
|
||||
.w_h(31.0 * 4.0, 12.0 * 4.0)
|
||||
.hover_image(if let SettingsTab::Interface = self.settings_tab {
|
||||
@ -907,27 +903,20 @@ impl Hud {
|
||||
|
||||
// 2 Gameplay////////////////
|
||||
if Button::image(if let SettingsTab::Gameplay = self.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
self.imgs.settings_button
|
||||
})
|
||||
.w_h(31.0 * 4.0, 12.0 * 4.0)
|
||||
.hover_image(if let SettingsTab::Gameplay = self.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
self.imgs.settings_button_hover
|
||||
})
|
||||
.press_image(if let SettingsTab::Gameplay = self.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
self.imgs.settings_button_press
|
||||
})
|
||||
.right_from(self.ids.interface, 0.0)
|
||||
.label("Gameplay")
|
||||
.label_font_size(14)
|
||||
.label_color(TEXT_COLOR)
|
||||
.set(self.ids.gameplay, ui_widgets)
|
||||
.was_clicked()
|
||||
self.imgs.button_blue_mo
|
||||
} else {
|
||||
self.imgs.blank
|
||||
}
|
||||
)
|
||||
.w_h(304.0 / 2.5, 80.0 / 2.5)
|
||||
.hover_image(self.imgs.button_blue_mo)
|
||||
.press_image(self.imgs.button_blue_press)
|
||||
.down_from(self.ids.interface, 1.0)
|
||||
.label("Gameplay")
|
||||
.label_font_size(14)
|
||||
.label_color(TEXT_COLOR)
|
||||
.set(self.ids.gameplay, ui_widgets)
|
||||
.was_clicked()
|
||||
{
|
||||
self.settings_tab = SettingsTab::Gameplay;
|
||||
}
|
||||
@ -936,7 +925,7 @@ impl Hud {
|
||||
if Button::image(if let SettingsTab::Controls = self.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
self.imgs.settings_button
|
||||
self.imgs.blank
|
||||
})
|
||||
.w_h(31.0 * 4.0, 12.0 * 4.0)
|
||||
.hover_image(if let SettingsTab::Controls = self.settings_tab {
|
||||
@ -1095,7 +1084,7 @@ impl Hud {
|
||||
if Button::image(if let SettingsTab::Video = self.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
self.imgs.settings_button
|
||||
self.imgs.blank
|
||||
})
|
||||
.w_h(31.0 * 4.0, 12.0 * 4.0)
|
||||
.hover_image(if let SettingsTab::Video = self.settings_tab {
|
||||
@ -1123,7 +1112,7 @@ impl Hud {
|
||||
if Button::image(if let SettingsTab::Sound = self.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
self.imgs.settings_button
|
||||
self.imgs.blank
|
||||
})
|
||||
.w_h(31.0 * 4.0, 12.0 * 4.0)
|
||||
.hover_image(if let SettingsTab::Sound = self.settings_tab {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
render::Renderer,
|
||||
ui::{self, ScaleMode, Ui},
|
||||
window::Window,
|
||||
ui::{self, Graphic, ScaleMode, Ui},
|
||||
window::Window,
|
||||
};
|
||||
use common::{
|
||||
assets,
|
||||
@ -246,13 +246,13 @@ impl Imgs {
|
||||
let fullpath: String = ["/voxygen/", filename].concat();
|
||||
let image = assets::load::<image::DynamicImage>(fullpath.as_str())
|
||||
.unwrap();
|
||||
ui.new_graphic(image.into())
|
||||
ui.add_graphic(Graphic::Image(image))
|
||||
};
|
||||
let load_vox = |filename, ui: &mut Ui| {
|
||||
let fullpath: String = ["/voxygen/", filename].concat();
|
||||
let dot_vox = assets::load::<dot_vox::DotVoxData>(fullpath.as_str())
|
||||
.unwrap();
|
||||
ui.new_graphic(dot_vox.into())
|
||||
ui.add_graphic(Graphic::Voxel(dot_vox))
|
||||
};
|
||||
Imgs {
|
||||
v_logo: load_vox("element/v_logo.vox", ui),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
render::Renderer,
|
||||
ui::{self, ScaleMode, Ui},
|
||||
ui::{self, Graphic, ScaleMode, Ui},
|
||||
GlobalState, DEFAULT_PUBLIC_SERVER,
|
||||
};
|
||||
use common::{
|
||||
@ -69,13 +69,13 @@ impl Imgs {
|
||||
let fullpath: String = ["/voxygen/", filename].concat();
|
||||
let image = assets::load::<image::DynamicImage>(fullpath.as_str())
|
||||
.unwrap();
|
||||
ui.new_graphic(image.into())
|
||||
ui.add_graphic(Graphic::Image(image))
|
||||
};
|
||||
let load_vox = |filename, ui: &mut Ui| {
|
||||
let fullpath: String = ["/voxygen/", filename].concat();
|
||||
let dot_vox = assets::load::<dot_vox::DotVoxData>(fullpath.as_str())
|
||||
.unwrap();
|
||||
ui.new_graphic(dot_vox.into())
|
||||
ui.add_graphic(Graphic::Voxel(dot_vox))
|
||||
};
|
||||
Imgs {
|
||||
bg: load_img("background/bg_main.png", ui),
|
||||
|
@ -11,17 +11,6 @@ pub enum Graphic {
|
||||
Blank,
|
||||
}
|
||||
|
||||
impl From<Arc<DynamicImage>> for Graphic {
|
||||
fn from(image: Arc<DynamicImage>) -> Self {
|
||||
Graphic::Image(image)
|
||||
}
|
||||
}
|
||||
impl From<Arc<DotVoxData>> for Graphic {
|
||||
fn from(vox: Arc<DotVoxData>) -> Self {
|
||||
Graphic::Voxel(vox)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Copy, Clone)]
|
||||
pub struct Id(u32);
|
||||
|
||||
@ -42,7 +31,7 @@ impl GraphicCache {
|
||||
next_id: 0,
|
||||
}
|
||||
}
|
||||
pub fn new_graphic(&mut self, graphic: Graphic) -> Id {
|
||||
pub fn add_graphic(&mut self, graphic: Graphic) -> Id {
|
||||
let id = self.next_id;
|
||||
self.next_id = id.wrapping_add(1);
|
||||
|
||||
|
@ -1,3 +1,35 @@
|
||||
use super::Graphic;
|
||||
use dot_vox::DotVoxData;
|
||||
use image::DynamicImage;
|
||||
use common::assets::{Error, load};
|
||||
|
||||
pub struct BlankGraphic;
|
||||
pub struct ImageGraphic;
|
||||
pub struct VoxelGraphic;
|
||||
|
||||
pub trait GraphicCreator<'a> {
|
||||
type Specifier;
|
||||
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error>;
|
||||
}
|
||||
impl<'a> GraphicCreator<'a> for BlankGraphic {
|
||||
type Specifier = ();
|
||||
fn new_graphic(_: ()) -> Result<Graphic, Error> {
|
||||
Ok(Graphic::Blank)
|
||||
}
|
||||
}
|
||||
impl<'a> GraphicCreator<'a> for ImageGraphic {
|
||||
type Specifier = &'a str;
|
||||
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
||||
Ok(Graphic::Image(load::<DynamicImage>(specifier)?))
|
||||
}
|
||||
}
|
||||
impl<'a> GraphicCreator<'a> for VoxelGraphic {
|
||||
type Specifier = &'a str;
|
||||
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
||||
Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?))
|
||||
}
|
||||
}
|
||||
|
||||
/// This macro will automatically load all specified assets, get the corresponding ImgIds and
|
||||
/// create a struct with all of them
|
||||
///
|
||||
@ -5,12 +37,15 @@
|
||||
/// ```
|
||||
/// image_ids! {
|
||||
/// pub struct Imgs {
|
||||
/// <DotVoxData>
|
||||
/// <VoxelGraphic>
|
||||
/// button1: "filename1.vox",
|
||||
/// button2: "filename2.vox",
|
||||
///
|
||||
/// <DynamicImage>
|
||||
/// <ImageGraphic>
|
||||
/// background: "background.png",
|
||||
///
|
||||
/// <BlankGraphic>
|
||||
/// blank: (),
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
@ -25,8 +60,9 @@ macro_rules! image_ids {
|
||||
|
||||
impl $Ids {
|
||||
pub fn load(ui: &mut crate::ui::Ui) -> Result<Self, common::assets::Error> {
|
||||
use crate::ui::GraphicCreator;
|
||||
Ok(Self {
|
||||
$($( $name: ui.new_graphic(common::assets::load::<$T>($specifier)?.into()), )*)*
|
||||
$($( $name: ui.add_graphic(<$T>::new_graphic($specifier)?), )*)*
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,9 @@ mod widgets;
|
||||
mod img_ids;
|
||||
|
||||
pub use graphic::Graphic;
|
||||
pub(self) use util::{linear_to_srgb, srgb_to_linear};
|
||||
pub use widgets::toggle_button::ToggleButton;
|
||||
pub use img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic, GraphicCreator};
|
||||
pub(self) use util::{srgb_to_linear, linear_to_srgb};
|
||||
|
||||
use crate::{
|
||||
render::{
|
||||
@ -115,7 +116,7 @@ impl Cache {
|
||||
pub fn graphic_cache_mut_and_tex(&mut self) -> (&mut GraphicCache, &Texture<UiPipeline>) {
|
||||
(&mut self.graphic_cache, &self.graphic_cache_tex)
|
||||
}
|
||||
pub fn new_graphic(&mut self, graphic: Graphic) -> GraphicId {
|
||||
pub fn add_graphic(&mut self, graphic: Graphic) -> GraphicId {
|
||||
self.graphic_cache.new_graphic(graphic)
|
||||
}
|
||||
pub fn clear_graphic_cache(&mut self, renderer: &mut Renderer, new_size: Vec2<u16>) {
|
||||
@ -249,8 +250,8 @@ impl Ui {
|
||||
self.ui.handle_event(Input::Resize(w, h));
|
||||
}
|
||||
|
||||
pub fn new_graphic(&mut self, graphic: Graphic) -> ImgId {
|
||||
self.image_map.insert(self.cache.new_graphic(graphic))
|
||||
pub fn add_graphic(&mut self, graphic: Graphic) -> ImgId {
|
||||
self.image_map.insert(self.cache.add_graphic(graphic))
|
||||
}
|
||||
|
||||
pub fn new_font(&mut self, font: Font) -> FontId {
|
||||
|
Loading…
Reference in New Issue
Block a user