2020-01-03 03:51:07 +00:00
|
|
|
use super::{Graphic, SampleStrat, Transform};
|
2020-04-06 02:50:27 +00:00
|
|
|
use common::{
|
2020-08-28 01:02:17 +00:00
|
|
|
assets::{Asset, Error},
|
2020-04-06 02:50:27 +00:00
|
|
|
figure::Segment,
|
|
|
|
};
|
2019-04-28 18:18:08 +00:00
|
|
|
use dot_vox::DotVoxData;
|
|
|
|
use image::DynamicImage;
|
2020-04-06 02:50:27 +00:00
|
|
|
use std::sync::Arc;
|
2019-10-09 19:28:05 +00:00
|
|
|
use vek::*;
|
2019-04-28 18:18:08 +00:00
|
|
|
|
2019-05-09 01:38:34 +00:00
|
|
|
pub enum BlankGraphic {}
|
|
|
|
pub enum ImageGraphic {}
|
2019-04-28 18:18:08 +00:00
|
|
|
|
|
|
|
pub trait GraphicCreator<'a> {
|
|
|
|
type Specifier;
|
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error>;
|
|
|
|
}
|
|
|
|
impl<'a> GraphicCreator<'a> for BlankGraphic {
|
|
|
|
type Specifier = ();
|
2020-02-01 20:39:39 +00:00
|
|
|
|
|
|
|
fn new_graphic(_: ()) -> Result<Graphic, Error> { Ok(Graphic::Blank) }
|
2019-04-28 18:18:08 +00:00
|
|
|
}
|
|
|
|
impl<'a> GraphicCreator<'a> for ImageGraphic {
|
|
|
|
type Specifier = &'a str;
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-04-28 18:18:08 +00:00
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
2020-08-28 01:02:17 +00:00
|
|
|
Ok(Graphic::Image(DynamicImage::load(specifier)?, None))
|
2019-04-28 18:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-09 01:38:34 +00:00
|
|
|
|
|
|
|
pub enum VoxelGraphic {}
|
2020-08-25 12:21:25 +00:00
|
|
|
// TODO: Are these unneeded now that we have PixArtGraphic?
|
2020-01-03 03:51:07 +00:00
|
|
|
pub enum VoxelSsGraphic {}
|
|
|
|
pub enum VoxelSs4Graphic {}
|
|
|
|
pub enum VoxelSs9Graphic {}
|
2020-04-06 02:50:27 +00:00
|
|
|
|
2020-01-03 03:51:07 +00:00
|
|
|
pub enum VoxelPixArtGraphic {}
|
2019-05-09 01:38:34 +00:00
|
|
|
|
2020-04-06 02:50:27 +00:00
|
|
|
fn load_segment(specifier: &str) -> Result<Arc<Segment>, Error> {
|
2020-08-28 01:02:17 +00:00
|
|
|
let dot_vox = DotVoxData::load(specifier)?;
|
2020-04-06 02:50:27 +00:00
|
|
|
let seg = dot_vox.as_ref().into();
|
|
|
|
Ok(Arc::new(seg))
|
|
|
|
}
|
|
|
|
|
2019-04-28 18:18:08 +00:00
|
|
|
impl<'a> GraphicCreator<'a> for VoxelGraphic {
|
|
|
|
type Specifier = &'a str;
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-04-28 18:18:08 +00:00
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
2019-10-09 19:28:05 +00:00
|
|
|
Ok(Graphic::Voxel(
|
2020-04-06 02:50:27 +00:00
|
|
|
load_segment(specifier)?,
|
2019-10-09 19:28:05 +00:00
|
|
|
Transform {
|
|
|
|
ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2020-01-03 03:51:07 +00:00
|
|
|
SampleStrat::None,
|
2019-10-09 19:28:05 +00:00
|
|
|
))
|
2019-05-09 01:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-03 03:51:07 +00:00
|
|
|
impl<'a> GraphicCreator<'a> for VoxelSsGraphic {
|
2019-05-09 01:38:34 +00:00
|
|
|
type Specifier = (&'a str, u8);
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-05-09 01:38:34 +00:00
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
|
|
|
Ok(Graphic::Voxel(
|
2020-04-06 02:50:27 +00:00
|
|
|
load_segment(specifier.0)?,
|
2019-10-09 19:28:05 +00:00
|
|
|
Transform {
|
|
|
|
ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2020-01-03 03:51:07 +00:00
|
|
|
SampleStrat::SuperSampling(specifier.1),
|
2019-05-09 01:38:34 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
2020-01-03 03:51:07 +00:00
|
|
|
impl<'a> GraphicCreator<'a> for VoxelSs4Graphic {
|
2019-05-09 01:38:34 +00:00
|
|
|
type Specifier = &'a str;
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-05-09 01:38:34 +00:00
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
2019-08-01 02:51:40 +00:00
|
|
|
Ok(Graphic::Voxel(
|
2020-04-06 02:50:27 +00:00
|
|
|
load_segment(specifier)?,
|
2019-10-09 19:28:05 +00:00
|
|
|
Transform {
|
|
|
|
ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2020-01-03 03:51:07 +00:00
|
|
|
SampleStrat::SuperSampling(4),
|
2019-08-01 02:51:40 +00:00
|
|
|
))
|
2019-05-09 01:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-03 03:51:07 +00:00
|
|
|
impl<'a> GraphicCreator<'a> for VoxelSs9Graphic {
|
2019-05-09 01:38:34 +00:00
|
|
|
type Specifier = &'a str;
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-05-09 01:38:34 +00:00
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
2019-08-01 02:51:40 +00:00
|
|
|
Ok(Graphic::Voxel(
|
2020-04-06 02:50:27 +00:00
|
|
|
load_segment(specifier)?,
|
2019-10-09 19:28:05 +00:00
|
|
|
Transform {
|
|
|
|
ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2020-01-03 03:51:07 +00:00
|
|
|
SampleStrat::SuperSampling(9),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<'a> GraphicCreator<'a> for VoxelPixArtGraphic {
|
|
|
|
type Specifier = &'a str;
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2020-01-03 03:51:07 +00:00
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
|
|
|
Ok(Graphic::Voxel(
|
2020-04-06 02:50:27 +00:00
|
|
|
load_segment(specifier)?,
|
2020-01-03 03:51:07 +00:00
|
|
|
Transform {
|
|
|
|
ori: Quaternion::rotation_x(-std::f32::consts::PI / 2.0),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
SampleStrat::PixelCoverage,
|
2019-08-01 02:51:40 +00:00
|
|
|
))
|
2019-04-28 18:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 02:51:40 +00:00
|
|
|
pub struct Rotations {
|
|
|
|
pub none: conrod_core::image::Id,
|
|
|
|
pub cw90: conrod_core::image::Id,
|
|
|
|
pub cw180: conrod_core::image::Id,
|
|
|
|
pub cw270: conrod_core::image::Id,
|
2020-02-06 17:34:32 +00:00
|
|
|
pub source_north: conrod_core::image::Id,
|
|
|
|
pub target_north: conrod_core::image::Id,
|
2019-08-01 02:51:40 +00:00
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
/// This macro will automatically load all specified assets, get the
|
|
|
|
/// corresponding ImgIds and create a struct with all of them.
|
2019-04-26 03:30:46 +00:00
|
|
|
///
|
|
|
|
/// Example usage:
|
2020-03-06 00:07:48 +00:00
|
|
|
/// ```ignore
|
|
|
|
/// use veloren_voxygen::{
|
|
|
|
/// image_ids,
|
|
|
|
/// ui::img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic},
|
|
|
|
/// };
|
|
|
|
///
|
2019-04-26 03:30:46 +00:00
|
|
|
/// image_ids! {
|
2019-04-28 16:44:44 +00:00
|
|
|
/// pub struct Imgs {
|
2019-04-28 18:18:08 +00:00
|
|
|
/// <VoxelGraphic>
|
2019-08-06 06:31:48 +00:00
|
|
|
/// button1: "specifier1",
|
|
|
|
/// button2: "specifier2",
|
2019-04-28 16:44:44 +00:00
|
|
|
///
|
2019-04-28 18:18:08 +00:00
|
|
|
/// <ImageGraphic>
|
2019-08-06 06:31:48 +00:00
|
|
|
/// background: "background",
|
2019-05-07 05:40:03 +00:00
|
|
|
///
|
2019-04-28 18:18:08 +00:00
|
|
|
/// <BlankGraphic>
|
|
|
|
/// blank: (),
|
2019-04-26 03:30:46 +00:00
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! image_ids {
|
2019-04-28 16:44:44 +00:00
|
|
|
($($v:vis struct $Ids:ident { $( <$T:ty> $( $name:ident: $specifier:expr ),* $(,)? )* })*) => {
|
2019-04-26 03:30:46 +00:00
|
|
|
$(
|
|
|
|
$v struct $Ids {
|
2019-08-01 02:51:40 +00:00
|
|
|
$($( $v $name: conrod_core::image::Id, )*)*
|
2019-04-26 03:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl $Ids {
|
2019-04-28 04:44:13 +00:00
|
|
|
pub fn load(ui: &mut crate::ui::Ui) -> Result<Self, common::assets::Error> {
|
2019-05-09 01:38:34 +00:00
|
|
|
use crate::ui::img_ids::GraphicCreator;
|
2019-04-26 03:30:46 +00:00
|
|
|
Ok(Self {
|
2019-12-15 17:13:52 +00:00
|
|
|
$($( $name: ui.add_graphic(<$T as GraphicCreator>::new_graphic($specifier)?), )*)*
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! image_ids_ice {
|
|
|
|
($($v:vis struct $Ids:ident { $( <$T:ty> $( $name:ident: $specifier:expr ),* $(,)? )* })*) => {
|
|
|
|
$(
|
|
|
|
$v struct $Ids {
|
|
|
|
$($( $v $name: crate::ui::GraphicId, )*)*
|
|
|
|
}
|
|
|
|
|
|
|
|
impl $Ids {
|
|
|
|
pub fn load(ui: &mut crate::ui::ice::IcedUi) -> Result<Self, common::assets::Error> {
|
|
|
|
use crate::ui::img_ids::GraphicCreator;
|
|
|
|
Ok(Self {
|
2019-05-11 14:59:48 +00:00
|
|
|
$($( $name: ui.add_graphic(<$T as GraphicCreator>::new_graphic($specifier)?), )*)*
|
2019-04-26 03:30:46 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
};
|
2019-04-30 20:43:55 +00:00
|
|
|
}
|
2019-08-01 02:51:40 +00:00
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
// TODO: combine with the img_ids macro above using a marker for specific fields
|
|
|
|
// that should be `Rotations` instead of `widget::Id`
|
2019-08-01 02:51:40 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! rotation_image_ids {
|
|
|
|
($($v:vis struct $Ids:ident { $( <$T:ty> $( $name:ident: $specifier:expr ),* $(,)? )* })*) => {
|
|
|
|
$(
|
|
|
|
$v struct $Ids {
|
|
|
|
$($( $v $name: crate::ui::img_ids::Rotations, )*)*
|
|
|
|
}
|
|
|
|
|
|
|
|
impl $Ids {
|
|
|
|
pub fn load(ui: &mut crate::ui::Ui) -> Result<Self, common::assets::Error> {
|
|
|
|
use crate::ui::img_ids::GraphicCreator;
|
|
|
|
Ok(Self {
|
|
|
|
$($( $name: ui.add_graphic_with_rotations(<$T as GraphicCreator>::new_graphic($specifier)?), )*)*
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
};
|
|
|
|
}
|