Former-commit-id: 7e2cdb284c670b5991c69b6aab042194c806171f
This commit is contained in:
Imbris
2019-05-07 01:40:03 -04:00
parent 99d6c92c8d
commit eb3d8310f8
18 changed files with 432 additions and 528 deletions

View File

@ -1,6 +1,6 @@
use conrod_core::text::Font;
use dot_vox::DotVoxData; use dot_vox::DotVoxData;
use image::DynamicImage; use image::DynamicImage;
use conrod_core::text::Font;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::{ use std::{
any::Any, any::Any,
@ -41,12 +41,13 @@ lazy_static! {
/// ``` /// ```
/// use image::DynamicImage; /// use image::DynamicImage;
/// use common::assets; /// use common::assets;
/// ///
/// let my_image = Assets::load::<DynamicImage>("core.ui.backgrounds.city").unwrap(); /// let my_image = Assets::load::<DynamicImage>("core.ui.backgrounds.city").unwrap();
/// ``` /// ```
pub fn load<A: Asset + 'static>(specifier: &str) -> Result<Arc<A>, Error> { pub fn load<A: Asset + 'static>(specifier: &str) -> Result<Arc<A>, Error> {
Ok(ASSETS Ok(ASSETS
.write().unwrap() .write()
.unwrap()
.entry(specifier.to_string()) .entry(specifier.to_string())
.or_insert(Arc::new(A::load(specifier)?)) .or_insert(Arc::new(A::load(specifier)?))
.clone() .clone()
@ -60,12 +61,11 @@ pub fn load<A: Asset + 'static>(specifier: &str) -> Result<Arc<A>, Error> {
/// ``` /// ```
/// use image::DynamicImage; /// use image::DynamicImage;
/// use common::assets; /// use common::assets;
/// ///
/// let my_image = Assets::load_expect::<DynamicImage>("core.ui.backgrounds.city"); /// let my_image = Assets::load_expect::<DynamicImage>("core.ui.backgrounds.city");
/// ``` /// ```
pub fn load_expect<A: Asset + 'static>(specifier: &str) -> Arc<A> { pub fn load_expect<A: Asset + 'static>(specifier: &str) -> Arc<A> {
load(specifier) load(specifier).expect(&format!("Failed loading essential asset: {}", specifier))
.expect(&format!("Failed loading essential asset: {}", specifier))
} }
/// Asset Trait /// Asset Trait
@ -75,29 +75,19 @@ pub trait Asset: Send + Sync + Sized {
impl Asset for DynamicImage { impl Asset for DynamicImage {
fn load(specifier: &str) -> Result<Self, Error> { fn load(specifier: &str) -> Result<Self, Error> {
Ok(image::load_from_memory( Ok(image::load_from_memory(load_from_path(specifier)?.as_slice()).unwrap())
load_from_path(specifier)?.as_slice()
)
.unwrap()
)
} }
} }
impl Asset for DotVoxData { impl Asset for DotVoxData {
fn load(specifier: &str) -> Result<Self, Error> { fn load(specifier: &str) -> Result<Self, Error> {
Ok(dot_vox::load_bytes( Ok(dot_vox::load_bytes(load_from_path(specifier)?.as_slice()).unwrap())
load_from_path(specifier)?.as_slice()
)
.unwrap()
)
} }
} }
impl Asset for Font { impl Asset for Font {
fn load(specifier: &str) -> Result<Self, Error> { fn load(specifier: &str) -> Result<Self, Error> {
Ok(Font::from_bytes( Ok(Font::from_bytes(load_from_path(specifier)?).unwrap())
load_from_path(specifier)?).unwrap()
)
} }
} }
@ -127,10 +117,8 @@ pub fn load_from_path(name: &str) -> Result<Vec<u8>, Error> {
let mut content = Vec::<u8>::new(); let mut content = Vec::<u8>::new();
f.read_to_end(&mut content)?; f.read_to_end(&mut content)?;
Ok(content) Ok(content)
},
None => {
Err(Error::NotFound(name.to_owned()))
} }
None => Err(Error::NotFound(name.to_owned())),
} }
} }

View File

@ -1,11 +1,8 @@
use super::{font_ids::Fonts, img_ids::Imgs};
use conrod_core::{ use conrod_core::{
color, color,
widget::{self, Button, Image, Rectangle, Scrollbar}, widget::{self, Button, Image, Rectangle, Scrollbar},
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon, widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
};
use super::{
img_ids::Imgs,
font_ids::Fonts,
}; };
widget_ids! { widget_ids! {
@ -67,11 +64,7 @@ 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 { let widget::UpdateArgs { state, ui, .. } = args;
state,
ui,
..
} = args;
// Contents // Contents
Image::new(self.imgs.bag_contents) Image::new(self.imgs.bag_contents)
@ -81,24 +74,23 @@ impl<'a> Widget for Bag<'a> {
// Alignment for Grid // Alignment for Grid
Rectangle::fill_with([58.0 * 4.0 - 5.0, 100.0 * 4.0], color::TRANSPARENT) Rectangle::fill_with([58.0 * 4.0 - 5.0, 100.0 * 4.0], color::TRANSPARENT)
.top_left_with_margins_on(state.ids.bag_contents, 11.0 * 4.0, 5.0 * 4.0) .top_left_with_margins_on(state.ids.bag_contents, 11.0 * 4.0, 5.0 * 4.0)
.scroll_kids() .scroll_kids()
.scroll_kids_vertically() .scroll_kids_vertically()
.set(state.ids.inv_alignment, ui); .set(state.ids.inv_alignment, ui);
// Grid // Grid
Image::new(self.imgs.inv_grid) Image::new(self.imgs.inv_grid)
.w_h(58.0 * 4.0, 111.0 * 4.0) .w_h(58.0 * 4.0, 111.0 * 4.0)
.mid_top_with_margin_on(state.ids.inv_alignment, 0.0) .mid_top_with_margin_on(state.ids.inv_alignment, 0.0)
.set(state.ids.inv_grid_1, ui); .set(state.ids.inv_grid_1, ui);
Image::new(self.imgs.inv_grid) Image::new(self.imgs.inv_grid)
.w_h(58.0 * 4.0, 111.0 * 4.0) .w_h(58.0 * 4.0, 111.0 * 4.0)
.mid_top_with_margin_on(state.ids.inv_alignment, 110.0 * 4.0) .mid_top_with_margin_on(state.ids.inv_alignment, 110.0 * 4.0)
.set(state.ids.inv_grid_2, ui); .set(state.ids.inv_grid_2, ui);
Scrollbar::y_axis(state.ids.inv_alignment) Scrollbar::y_axis(state.ids.inv_alignment)
.thickness(5.0) .thickness(5.0)
.rgba(0.33, 0.33, 0.33, 1.0) .rgba(0.33, 0.33, 0.33, 1.0)
.set(state.ids.inv_scrollbar, ui); .set(state.ids.inv_scrollbar, ui);
if self.inventory_space > 0 { if self.inventory_space > 0 {
// First Slot // First Slot

View File

@ -3,13 +3,7 @@ use conrod_core::{
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
}; };
use super::{ use super::{font_ids::Fonts, img_ids::Imgs, small_window::SmallWindowType, Windows, TEXT_COLOR};
img_ids::Imgs,
font_ids::Fonts,
small_window::SmallWindowType,
Windows,
TEXT_COLOR,
};
use crate::ui::ToggleButton; use crate::ui::ToggleButton;
widget_ids! { widget_ids! {
@ -44,7 +38,13 @@ pub struct Buttons<'a> {
} }
impl<'a> Buttons<'a> { impl<'a> Buttons<'a> {
pub fn new(open_windows: &'a Windows, show_map: bool, show_bag: bool, imgs: &'a Imgs, fonts: &'a Fonts) -> Self { pub fn new(
open_windows: &'a Windows,
show_map: bool,
show_bag: bool,
imgs: &'a Imgs,
fonts: &'a Fonts,
) -> Self {
Self { Self {
open_windows, open_windows,
show_map, show_map,
@ -84,21 +84,19 @@ impl<'a> Widget for Buttons<'a> {
} }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { let widget::UpdateArgs { state, ui, .. } = args;
state,
ui,
..
} = args;
// Bag // Bag
if !self.show_map { if !self.show_map {
if self.show_bag != ToggleButton::new(self.show_bag, self.imgs.bag, self.imgs.bag_open) if self.show_bag
.bottom_right_with_margins_on(ui.window, 5.0, 5.0) != ToggleButton::new(self.show_bag, self.imgs.bag, self.imgs.bag_open)
.hover_images(self.imgs.bag_hover, self.imgs.bag_open_hover) .bottom_right_with_margins_on(ui.window, 5.0, 5.0)
.press_images(self.imgs.bag_press, self.imgs.bag_open_press) .hover_images(self.imgs.bag_hover, self.imgs.bag_open_hover)
.w_h(420.0 / 10.0, 480.0 / 10.0) .press_images(self.imgs.bag_press, self.imgs.bag_open_press)
.set(state.ids.bag, ui) { .w_h(420.0 / 10.0, 480.0 / 10.0)
return Some(Event::ToggleBag); .set(state.ids.bag, ui)
{
return Some(Event::ToggleBag);
} }
Text::new("B") Text::new("B")

View File

@ -1,14 +1,9 @@
use super::{font_ids::Fonts, img_ids::Imgs, TEXT_COLOR, XP_COLOR};
use conrod_core::{ use conrod_core::{
color, color,
widget::{self, Button, Image, Rectangle, Text}, widget::{self, Button, Image, Rectangle, Text},
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
}; };
use super::{
img_ids::Imgs,
font_ids::Fonts,
TEXT_COLOR,
XP_COLOR,
};
widget_ids! { widget_ids! {
pub struct Ids { pub struct Ids {
@ -68,12 +63,7 @@ impl<'a> Widget for CharacterWindow<'a> {
} }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { let widget::UpdateArgs { id, state, ui, .. } = args;
id,
state,
ui,
..
} = args;
// TODO: Read from parameter / character struct // TODO: Read from parameter / character struct
let xp_percentage = 0.4; let xp_percentage = 0.4;
@ -82,8 +72,8 @@ impl<'a> Widget for CharacterWindow<'a> {
Image::new(self.imgs.window_frame) Image::new(self.imgs.window_frame)
.middle_of(id) .middle_of(id)
.top_left_with_margins_on(ui.window, 200.0, 215.0) .top_left_with_margins_on(ui.window, 200.0, 215.0)
.w_h(107.0*4.0, 125.0*4.0) .w_h(107.0 * 4.0, 125.0 * 4.0)
.set(state.charwindow_frame, ui); .set(state.charwindow_frame, ui);
// Icon // Icon
//Image::new(self.imgs.charwindow_icon) //Image::new(self.imgs.charwindow_icon)
@ -98,8 +88,9 @@ impl<'a> Widget for CharacterWindow<'a> {
.press_image(self.imgs.close_button_press) .press_image(self.imgs.close_button_press)
.top_right_with_margins_on(state.charwindow_frame, 12.0, 0.0) .top_right_with_margins_on(state.charwindow_frame, 12.0, 0.0)
.set(state.charwindow_close, ui) .set(state.charwindow_close, ui)
.was_clicked() { .was_clicked()
return Some(Event::Close); {
return Some(Event::Close);
} }
// Title // Title
@ -171,11 +162,11 @@ impl<'a> Widget for CharacterWindow<'a> {
\n\ \n\
Intelligence", Intelligence",
) )
.top_left_with_margins_on(state.charwindow_rectangle, 100.0, 20.0) .top_left_with_margins_on(state.charwindow_rectangle, 100.0, 20.0)
.font_id(self.fonts.opensans) .font_id(self.fonts.opensans)
.font_size(16) .font_size(16)
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(state.charwindow_tab1_statnames, ui); .set(state.charwindow_tab1_statnames, ui);
Text::new( Text::new(
"1234\n\ "1234\n\
@ -186,11 +177,11 @@ impl<'a> Widget for CharacterWindow<'a> {
\n\ \n\
124124", 124124",
) )
.right_from(state.charwindow_tab1_statnames, 10.0) .right_from(state.charwindow_tab1_statnames, 10.0)
.font_id(self.fonts.opensans) .font_id(self.fonts.opensans)
.font_size(16) .font_size(16)
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(state.charwindow_tab1_stats, ui); .set(state.charwindow_tab1_stats, ui);
None None
} }

View File

@ -1,13 +1,9 @@
use super::{font_ids::Fonts, img_ids::Imgs, TEXT_COLOR};
use conrod_core::{ use conrod_core::{
input::Key, input::Key,
widget::{self, Button, Id, List, Rectangle, Text, TextEdit},
position::Dimension, position::Dimension,
UiCell, widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon, widget::{self, Button, Id, List, Rectangle, Text, TextEdit},
}; widget_ids, Colorable, Positionable, Sizeable, UiCell, Widget, WidgetCommon,
use super::{
img_ids::Imgs,
font_ids::Fonts,
TEXT_COLOR,
}; };
use std::collections::VecDeque; use std::collections::VecDeque;
@ -86,12 +82,7 @@ impl<'a> Widget for Chat<'a> {
} }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { let widget::UpdateArgs { id, state, ui, .. } = args;
id,
state,
ui,
..
} = args;
// Maintain scrolling // Maintain scrolling
if !self.new_messages.is_empty() { if !self.new_messages.is_empty() {
@ -134,10 +125,12 @@ impl<'a> Widget for Chat<'a> {
// Message box // Message box
Rectangle::fill([470.0, 174.0]) Rectangle::fill([470.0, 174.0])
.rgba(0.0, 0.0, 0.0, 0.4) .rgba(0.0, 0.0, 0.0, 0.4)
.and(|r| if input_focused { .and(|r| {
r.up_from(state.ids.input_bg, 0.0) if input_focused {
} else { r.up_from(state.ids.input_bg, 0.0)
r.bottom_left_with_margins_on(ui.window, 10.0, 10.0) } else {
r.bottom_left_with_margins_on(ui.window, 10.0, 10.0)
}
}) })
.set(state.ids.message_box_bg, ui); .set(state.ids.message_box_bg, ui);
let (mut items, _) = List::flow_down(state.messages.len() + 1) let (mut items, _) = List::flow_down(state.messages.len() + 1)
@ -165,7 +158,10 @@ impl<'a> Widget for Chat<'a> {
} else { } else {
// Spacer at bottom of the last message so that it is not cut off // Spacer at bottom of the last message so that it is not cut off
// Needs to be larger than the space above // Needs to be larger than the space above
Text::new("").font_size(6).font_id(self.fonts.opensans).w(470.0) Text::new("")
.font_size(6)
.font_id(self.fonts.opensans)
.w(470.0)
}; };
item.set(widget, ui); item.set(widget, ui);
} }
@ -190,7 +186,7 @@ impl<'a> Widget for Chat<'a> {
Some(Event::Focus(state.ids.input)) Some(Event::Focus(state.ids.input))
} }
// If enter is pressed and the input box is not empty send the current message // If enter is pressed and the input box is not empty send the current message
else if ui else if ui
.widget_input(state.ids.input) .widget_input(state.ids.input)
.presses() .presses()
.key() .key()

View File

@ -3,11 +3,7 @@ use conrod_core::{
widget_ids, Labelable, Positionable, Sizeable, Widget, WidgetCommon, widget_ids, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
}; };
use super::{ use super::{font_ids::Fonts, img_ids::Imgs, TEXT_COLOR};
img_ids::Imgs,
font_ids::Fonts,
TEXT_COLOR,
};
widget_ids! { widget_ids! {
struct Ids { struct Ids {
@ -23,7 +19,6 @@ widget_ids! {
#[derive(WidgetCommon)] #[derive(WidgetCommon)]
pub struct EscMenu<'a> { pub struct EscMenu<'a> {
imgs: &'a Imgs, imgs: &'a Imgs,
fonts: &'a Fonts, fonts: &'a Fonts,
@ -68,11 +63,7 @@ impl<'a> Widget for EscMenu<'a> {
} }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { let widget::UpdateArgs { state, ui, .. } = args;
state,
ui,
..
} = args;
Image::new(self.imgs.esc_bg) Image::new(self.imgs.esc_bg)
.w_h(228.0, 450.0) .w_h(228.0, 450.0)

View File

@ -1,4 +1,4 @@
use crate::ui::{ImageGraphic, VoxelGraphic, BlankGraphic}; use crate::ui::{BlankGraphic, ImageGraphic, VoxelGraphic};
image_ids! { image_ids! {
pub struct Imgs { pub struct Imgs {
@ -39,14 +39,14 @@ image_ids! {
qlog_button: "/voxygen/element/buttons/qlog.vox", qlog_button: "/voxygen/element/buttons/qlog.vox",
qlog_hover: "/voxygen/element/buttons/qlog_hover.vox", qlog_hover: "/voxygen/element/buttons/qlog_hover.vox",
qlog_press: "/voxygen/element/buttons/qlog_press.vox", qlog_press: "/voxygen/element/buttons/qlog_press.vox",
// Close button // Close button
close_button: "/voxygen/element/buttons/x.vox", close_button: "/voxygen/element/buttons/x.vox",
close_button_hover: "/voxygen/element/buttons/x_hover.vox", close_button_hover: "/voxygen/element/buttons/x_hover.vox",
close_button_press: "/voxygen/element/buttons/x_press.vox", close_button_press: "/voxygen/element/buttons/x_press.vox",
// Esc-Menu // Esc-Menu
fireplace: "/voxygen/element/misc_bg/fireplace.vox", fireplace: "/voxygen/element/misc_bg/fireplace.vox",
button: "/voxygen/element/buttons/button.vox", button: "/voxygen/element/buttons/button.vox",
button_hover: "/voxygen/element/buttons/button_hover.vox", button_hover: "/voxygen/element/buttons/button_hover.vox",
@ -55,10 +55,10 @@ image_ids! {
// MiniMap // MiniMap
mmap_frame: "/voxygen/element/frames/mmap.vox", mmap_frame: "/voxygen/element/frames/mmap.vox",
mmap_frame_closed: "/voxygen/element/frames/mmap_closed.vox", mmap_frame_closed: "/voxygen/element/frames/mmap_closed.vox",
// Missing: Buff Frame Animation .gif ?! we could do animation in ui.maintain, or in shader? // Missing: Buff Frame Animation .gif ?! we could do animation in ui.maintain, or in shader?
window_frame: "/voxygen/element/frames/window2.vox", window_frame: "/voxygen/element/frames/window2.vox",
// Settings Window // Settings Window
settings_frame_r: "/voxygen/element/frames/settings_r.vox", settings_frame_r: "/voxygen/element/frames/settings_r.vox",
@ -66,23 +66,23 @@ image_ids! {
settings_button: "/voxygen/element/buttons/settings_button.vox", settings_button: "/voxygen/element/buttons/settings_button.vox",
settings_button_pressed: "/voxygen/element/buttons/settings_button_pressed.vox", settings_button_pressed: "/voxygen/element/buttons/settings_button_pressed.vox",
settings_button_hover: "/voxygen/element/buttons/settings_button_hover.vox", settings_button_hover: "/voxygen/element/buttons/settings_button_hover.vox",
settings_button_press: "/voxygen/element/buttons/settings_button_press.vox", settings_button_press: "/voxygen/element/buttons/settings_button_press.vox",
check: "/voxygen/element/buttons/check/no.vox", check: "/voxygen/element/buttons/check/no.vox",
check_mo: "/voxygen/element/buttons/check/no_mo.vox", check_mo: "/voxygen/element/buttons/check/no_mo.vox",
check_press: "/voxygen/element/buttons/check/press.vox", check_press: "/voxygen/element/buttons/check/press.vox",
check_checked: "/voxygen/element/buttons/check/yes.vox", check_checked: "/voxygen/element/buttons/check/yes.vox",
check_checked_mo: "/voxygen/element/buttons/check/yes_mo.vox", check_checked_mo: "/voxygen/element/buttons/check/yes_mo.vox",
slider: "/voxygen/element/slider/track.vox", slider: "/voxygen/element/slider/track.vox",
slider_indicator: "/voxygen/element/slider/indicator.vox", slider_indicator: "/voxygen/element/slider/indicator.vox",
// Map Window
// Map Window
map_frame_l: "/voxygen/element/frames/map_l.vox", map_frame_l: "/voxygen/element/frames/map_l.vox",
map_frame_r: "/voxygen/element/frames/map_r.vox", map_frame_r: "/voxygen/element/frames/map_r.vox",
map_frame_bl: "/voxygen/element/frames/map_bl.vox", map_frame_bl: "/voxygen/element/frames/map_bl.vox",
map_frame_br: "/voxygen/element/frames/map_br.vox", map_frame_br: "/voxygen/element/frames/map_br.vox",
// Chat-Arrows // Chat-Arrows
chat_arrow: "/voxygen/element/buttons/arrow_down.vox", chat_arrow: "/voxygen/element/buttons/arrow_down.vox",
chat_arrow_mo: "/voxygen/element/buttons/arrow_down_hover.vox", chat_arrow_mo: "/voxygen/element/buttons/arrow_down_hover.vox",

View File

@ -4,10 +4,7 @@ use conrod_core::{
widget_ids, Positionable, Sizeable, Widget, WidgetCommon, widget_ids, Positionable, Sizeable, Widget, WidgetCommon,
}; };
use super::{ use super::{font_ids::Fonts, img_ids::Imgs};
img_ids::Imgs,
font_ids::Fonts,
};
widget_ids! { widget_ids! {
struct Ids { struct Ids {
@ -66,42 +63,37 @@ impl<'a> Widget for Map<'a> {
} }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { let widget::UpdateArgs { state, ui, .. } = args;
state,
ui,
..
} = args;
// BG // BG
Rectangle::fill_with([824.0, 976.0], color::TRANSPARENT) Rectangle::fill_with([824.0, 976.0], color::TRANSPARENT)
.mid_top_with_margin_on(ui.window, 15.0) .mid_top_with_margin_on(ui.window, 15.0)
.scroll_kids() .scroll_kids()
.scroll_kids_vertically() .scroll_kids_vertically()
.set(state.ids.map_bg, ui); .set(state.ids.map_bg, ui);
// Frame // Frame
Image::new(self.imgs.map_frame_l) Image::new(self.imgs.map_frame_l)
.top_left_with_margins_on(state.ids.map_bg, 0.0, 0.0) .top_left_with_margins_on(state.ids.map_bg, 0.0, 0.0)
.w_h(412.0, 488.0) .w_h(412.0, 488.0)
.set(state.ids.map_frame_l, ui); .set(state.ids.map_frame_l, ui);
Image::new(self.imgs.map_frame_r) Image::new(self.imgs.map_frame_r)
.right_from(state.ids.map_frame_l, 0.0) .right_from(state.ids.map_frame_l, 0.0)
.w_h(412.0, 488.0) .w_h(412.0, 488.0)
.set(state.ids.map_frame_r, ui); .set(state.ids.map_frame_r, ui);
Image::new(self.imgs.map_frame_br) Image::new(self.imgs.map_frame_br)
.down_from(state.ids.map_frame_r, 0.0) .down_from(state.ids.map_frame_r, 0.0)
.w_h(412.0, 488.0) .w_h(412.0, 488.0)
.set(state.ids.map_frame_br, ui); .set(state.ids.map_frame_br, ui);
Image::new(self.imgs.map_frame_bl) Image::new(self.imgs.map_frame_bl)
.down_from(state.ids.map_frame_l, 0.0) .down_from(state.ids.map_frame_l, 0.0)
.w_h(412.0, 488.0) .w_h(412.0, 488.0)
.set(state.ids.map_frame_bl, ui); .set(state.ids.map_frame_bl, ui);
// Icon
Image::new(self.imgs.map_icon)
.w_h(224.0 / 3.0, 224.0 / 3.0)
.top_left_with_margins_on(state.ids.map_frame, -10.0, -10.0)
.set(state.ids.map_icon, ui);
// Icon
Image::new(self.imgs.map_icon)
.w_h(224.0 / 3.0, 224.0 / 3.0)
.top_left_with_margins_on(state.ids.map_frame, -10.0, -10.0)
.set(state.ids.map_icon, ui);
// Icon // Icon
Image::new(self.imgs.map_icon) Image::new(self.imgs.map_icon)
@ -110,16 +102,16 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.map_icon, ui); .set(state.ids.map_icon, ui);
// X-Button // X-Button
if Button::image(self.imgs.close_button) if Button::image(self.imgs.close_button)
.w_h(28.0, 28.0) .w_h(28.0, 28.0)
.hover_image(self.imgs.close_button_hover) .hover_image(self.imgs.close_button_hover)
.press_image(self.imgs.close_button_press) .press_image(self.imgs.close_button_press)
.top_right_with_margins_on(state.ids.map_frame_r, 0.0, 0.0) .top_right_with_margins_on(state.ids.map_frame_r, 0.0, 0.0)
.set(state.ids.map_close, ui) .set(state.ids.map_close, ui)
.was_clicked() .was_clicked()
{ {
return Some(Event::Close); return Some(Event::Close);
} }
None None
} }

View File

@ -1,26 +1,26 @@
mod chat;
mod character_window;
mod skillbar;
mod buttons;
mod map;
mod bag; mod bag;
mod buttons;
mod character_window;
mod chat;
mod esc_menu; mod esc_menu;
mod small_window;
mod settings_window;
mod img_ids;
mod font_ids; mod font_ids;
mod img_ids;
mod map;
mod settings_window;
mod skillbar;
mod small_window;
use chat::Chat;
use character_window::CharacterWindow;
use map::Map;
use bag::Bag; use bag::Bag;
use skillbar::Skillbar;
use buttons::Buttons; use buttons::Buttons;
use character_window::CharacterWindow;
use chat::Chat;
use esc_menu::EscMenu; use esc_menu::EscMenu;
use small_window::{SmallWindow, SmallWindowType};
use settings_window::SettingsWindow;
use img_ids::Imgs;
use font_ids::Fonts; use font_ids::Fonts;
use img_ids::Imgs;
use map::Map;
use settings_window::SettingsWindow;
use skillbar::Skillbar;
use small_window::{SmallWindow, SmallWindowType};
use crate::{ use crate::{
render::Renderer, render::Renderer,
@ -30,7 +30,9 @@ use crate::{
GlobalState, GlobalState,
}; };
use conrod_core::{ use conrod_core::{
widget::{self, Button, Image, Text, Rectangle}, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, color, graph color, graph,
widget::{self, Button, Image, Rectangle, Text},
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
}; };
use std::collections::VecDeque; use std::collections::VecDeque;
@ -46,7 +48,7 @@ widget_ids! {
// Debug // Debug
debug_bg, debug_bg,
fps_counter, fps_counter,
// Game Version // Game Version
version, version,
@ -95,7 +97,7 @@ pub enum Event {
// map not here because it currently is displayed over the top of other open windows // map not here because it currently is displayed over the top of other open windows
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum Windows { pub enum Windows {
Settings, // display settings window Settings, // display settings window
CharacterAnd(Option<SmallWindowType>), // show character window + optionally another CharacterAnd(Option<SmallWindowType>), // show character window + optionally another
Small(SmallWindowType), Small(SmallWindowType),
None, None,
@ -110,7 +112,7 @@ pub struct Show {
open_windows: Windows, open_windows: Windows,
map: bool, map: bool,
inventory_test_button: bool, inventory_test_button: bool,
mini_map: bool, mini_map: bool,
} }
impl Show { impl Show {
fn toggle_bag(&mut self) { fn toggle_bag(&mut self) {
@ -267,7 +269,7 @@ impl Hud {
{ {
self.inventory_space += 1; self.inventory_space += 1;
}; };
} }
// Help Text // Help Text
if self.show.help { if self.show.help {
Image::new(self.imgs.window_frame_2) Image::new(self.imgs.window_frame_2)
@ -293,8 +295,14 @@ impl Hud {
}; };
} }
match Buttons::new(&self.show.open_windows, self.show.map, self.show.bag, &self.imgs, &self.fonts) match Buttons::new(
.set(self.ids.buttons, ui_widgets) &self.show.open_windows,
self.show.map,
self.show.bag,
&self.imgs,
&self.fonts,
)
.set(self.ids.buttons, ui_widgets)
{ {
Some(buttons::Event::ToggleBag) => self.show.toggle_bag(), Some(buttons::Event::ToggleBag) => self.show.toggle_bag(),
Some(buttons::Event::ToggleSettings) => self.show.toggle_settings(), Some(buttons::Event::ToggleSettings) => self.show.toggle_settings(),
@ -356,15 +364,14 @@ impl Hud {
// Bag contents // Bag contents
if self.show.bag { if self.show.bag {
match Bag::new(self.inventory_space, &self.imgs, &self.fonts) match Bag::new(self.inventory_space, &self.imgs, &self.fonts)
.set(self.ids.bag, ui_widgets) .set(self.ids.bag, ui_widgets)
{ {
Some(bag::Event::Close) => self.show.bag = false, Some(bag::Event::Close) => self.show.bag = false,
None => {} None => {}
} }
} }
Skillbar::new(&self.imgs, &self.fonts) Skillbar::new(&self.imgs, &self.fonts).set(self.ids.skillbar, ui_widgets);
.set(self.ids.skillbar, ui_widgets);
// Chat box // Chat box
match Chat::new(&mut self.new_messages, &self.imgs, &self.fonts) match Chat::new(&mut self.new_messages, &self.imgs, &self.fonts)
@ -389,7 +396,7 @@ impl Hud {
if let Windows::Settings = self.show.open_windows { if let Windows::Settings = self.show.open_windows {
match SettingsWindow::new(&mut self.show, &self.imgs, &self.fonts) match SettingsWindow::new(&mut self.show, &self.imgs, &self.fonts)
.set(self.ids.settings_window, ui_widgets) .set(self.ids.settings_window, ui_widgets)
{ {
Some(settings_window::Event::Close) => { Some(settings_window::Event::Close) => {
self.show.open_windows = Windows::None; self.show.open_windows = Windows::None;
@ -401,13 +408,15 @@ impl Hud {
// Small Window // Small Window
if let Windows::Small(small) | Windows::CharacterAnd(Some(small)) = self.show.open_windows { if let Windows::Small(small) | Windows::CharacterAnd(Some(small)) = self.show.open_windows {
match SmallWindow::new(small, &self.show, &self.imgs, &self.fonts) match SmallWindow::new(small, &self.show, &self.imgs, &self.fonts)
.set(self.ids.small_window, ui_widgets) .set(self.ids.small_window, ui_widgets)
{ {
Some(small_window::Event::Close) => self.show.open_windows = match self.show.open_windows { Some(small_window::Event::Close) => {
Windows::Small(_) => Windows::None, self.show.open_windows = match self.show.open_windows {
Windows::CharacterAnd(_) => Windows::CharacterAnd(None), Windows::Small(_) => Windows::None,
_ => Windows::Settings, Windows::CharacterAnd(_) => Windows::CharacterAnd(None),
}, _ => Windows::Settings,
}
}
None => {} None => {}
} }
} }
@ -415,21 +424,21 @@ impl Hud {
// Character Window // Character Window
if let Windows::CharacterAnd(small) = self.show.open_windows { if let Windows::CharacterAnd(small) = self.show.open_windows {
match CharacterWindow::new(&self.imgs, &self.fonts) match CharacterWindow::new(&self.imgs, &self.fonts)
.set(self.ids.character_window, ui_widgets) .set(self.ids.character_window, ui_widgets)
{ {
Some(character_window::Event::Close) => self.show.open_windows = match small { Some(character_window::Event::Close) => {
Some(small) => Windows::Small(small), self.show.open_windows = match small {
None => Windows::None, Some(small) => Windows::Small(small),
}, None => Windows::None,
}
}
None => {} None => {}
} }
} }
// Map // Map
if self.show.map { if self.show.map {
match Map::new(&self.imgs, &self.fonts) match Map::new(&self.imgs, &self.fonts).set(self.ids.map, ui_widgets) {
.set(self.ids.map, ui_widgets)
{
Some(map::Event::Close) => self.show.map = false, Some(map::Event::Close) => self.show.map = false,
None => {} None => {}
} }
@ -437,9 +446,7 @@ impl Hud {
// Esc-menu // Esc-menu
if self.show.esc_menu { if self.show.esc_menu {
match EscMenu::new(&self.imgs, &self.fonts) match EscMenu::new(&self.imgs, &self.fonts).set(self.ids.esc_menu, ui_widgets) {
.set(self.ids.esc_menu, ui_widgets)
{
Some(esc_menu::Event::OpenSettings) => { Some(esc_menu::Event::OpenSettings) => {
self.show.esc_menu = false; self.show.esc_menu = false;
self.show.open_windows = Windows::Settings; self.show.open_windows = Windows::Settings;
@ -447,10 +454,10 @@ impl Hud {
Some(esc_menu::Event::Close) => self.show.esc_menu = false, Some(esc_menu::Event::Close) => self.show.esc_menu = false,
Some(esc_menu::Event::Logout) => events.push(Event::Logout), Some(esc_menu::Event::Logout) => events.push(Event::Logout),
Some(esc_menu::Event::Quit) => events.push(Event::Quit), Some(esc_menu::Event::Quit) => events.push(Event::Quit),
None => {}, None => {}
} }
} }
events events
} }
@ -466,7 +473,6 @@ impl Hud {
.widget(id) .widget(id)
.and_then(graph::Container::unique_widget_state::<widget::TextEdit>) .and_then(graph::Container::unique_widget_state::<widget::TextEdit>)
.is_some() .is_some()
} else { } else {
false false
} }

View File

@ -1,21 +1,14 @@
use super::{font_ids::Fonts, img_ids::Imgs, TEXT_COLOR};
use crate::{hud::Show, ui::ToggleButton};
use conrod_core::{ use conrod_core::{
color, color,
widget::{self, Button, Image, Rectangle, Scrollbar, Text}, widget::{self, Button, Image, Rectangle, Scrollbar, Text},
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
}; };
use super::{
img_ids::Imgs,
font_ids::Fonts,
TEXT_COLOR,
};
use crate::{
ui::ToggleButton,
hud::Show,
};
widget_ids! { widget_ids! {
struct Ids { struct Ids {
settings_content, settings_content,
settings_icon, settings_icon,
settings_button_mo, settings_button_mo,
@ -25,19 +18,19 @@ widget_ids! {
settings_l, settings_l,
settings_scrollbar, settings_scrollbar,
controls_text, controls_text,
controls_controls, controls_controls,
button_help, button_help,
button_help2, button_help2,
show_help_label, show_help_label,
gameplay, gameplay,
controls, controls,
rectangle, rectangle,
debug_button, debug_button,
debug_button_label, debug_button_label,
interface, interface,
inventory_test_button, inventory_test_button,
inventory_test_button_label, inventory_test_button_label,
settings_bg, settings_bg,
sound, sound,
test, test,
video, video,
@ -101,11 +94,7 @@ impl<'a> Widget for SettingsWindow<'a> {
} }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { let widget::UpdateArgs { state, ui, .. } = args;
state,
ui,
..
} = args;
// Frame Alignment // Frame Alignment
Rectangle::fill_with([824.0, 488.0], color::TRANSPARENT) Rectangle::fill_with([824.0, 488.0], color::TRANSPARENT)
@ -148,33 +137,31 @@ impl<'a> Widget for SettingsWindow<'a> {
.mid_top_with_margin_on(state.ids.settings_bg, 5.0) .mid_top_with_margin_on(state.ids.settings_bg, 5.0)
.font_size(14) .font_size(14)
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(state.ids.settings_title, ui); .set(state.ids.settings_title, ui);
// Interface // Interface
if Button::image(if let SettingsTab::Interface = state.settings_tab { if Button::image(if let SettingsTab::Interface = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button self.imgs.settings_button
}) })
.w_h(31.0 * 4.0, 12.0 * 4.0) .w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Interface = state.settings_tab { .hover_image(if let SettingsTab::Interface = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_hover self.imgs.settings_button_hover
}) })
.press_image(if let SettingsTab::Interface = state.settings_tab { .press_image(if let SettingsTab::Interface = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_press self.imgs.settings_button_press
}) })
.top_left_with_margins_on(state.ids.settings_l, 8.0 * 4.0, 2.0 * 4.0) .top_left_with_margins_on(state.ids.settings_l, 8.0 * 4.0, 2.0 * 4.0)
.label("Interface") .label("Interface")
.label_font_size(14) .label_font_size(14)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
.set(state.ids.interface, ui) .set(state.ids.interface, ui)
.was_clicked() .was_clicked()
{ {
state.update(|s| s.settings_tab = SettingsTab::Interface); state.update(|s| s.settings_tab = SettingsTab::Interface);
} }
@ -188,7 +175,7 @@ impl<'a> Widget for SettingsWindow<'a> {
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo) .hover_images(self.imgs.check_checked_mo, self.imgs.check_mo)
.press_images(self.imgs.check_press, self.imgs.check_press) .press_images(self.imgs.check_press, self.imgs.check_press)
.set(state.ids.button_help, ui); .set(state.ids.button_help, ui);
if self.show.help != show_help { if self.show.help != show_help {
self.show.toggle_help(); self.show.toggle_help();
} }
@ -207,11 +194,11 @@ impl<'a> Widget for SettingsWindow<'a> {
self.imgs.check, self.imgs.check,
self.imgs.check_checked, self.imgs.check_checked,
) )
.w_h(288.0 / 24.0, 288.0 / 24.0) .w_h(288.0 / 24.0, 288.0 / 24.0)
.down_from(state.ids.button_help, 7.0) .down_from(state.ids.button_help, 7.0)
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo) .hover_images(self.imgs.check_checked_mo, self.imgs.check_mo)
.press_images(self.imgs.check_press, self.imgs.check_press) .press_images(self.imgs.check_press, self.imgs.check_press)
.set(state.ids.inventory_test_button, ui); .set(state.ids.inventory_test_button, ui);
if self.show.inventory_test_button != inventory_test_button { if self.show.inventory_test_button != inventory_test_button {
self.show.inventory_test_button = inventory_test_button; self.show.inventory_test_button = inventory_test_button;
@ -226,16 +213,13 @@ impl<'a> Widget for SettingsWindow<'a> {
.set(state.ids.inventory_test_button_label, ui); .set(state.ids.inventory_test_button_label, ui);
// Debug // Debug
let show_debug = ToggleButton::new( let show_debug =
self.show.debug, ToggleButton::new(self.show.debug, self.imgs.check, self.imgs.check_checked)
self.imgs.check, .w_h(288.0 / 24.0, 288.0 / 24.0)
self.imgs.check_checked .down_from(state.ids.inventory_test_button, 7.0)
) .hover_images(self.imgs.check_checked_mo, self.imgs.check_mo)
.w_h(288.0 / 24.0, 288.0 / 24.0) .press_images(self.imgs.check_press, self.imgs.check_press)
.down_from(state.ids.inventory_test_button, 7.0) .set(state.ids.debug_button, ui);
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo)
.press_images(self.imgs.check_press, self.imgs.check_press)
.set(state.ids.debug_button, ui);
if self.show.debug != show_debug { if self.show.debug != show_debug {
self.show.debug = show_debug; self.show.debug = show_debug;
@ -248,65 +232,64 @@ impl<'a> Widget for SettingsWindow<'a> {
.graphics_for(state.ids.debug_button) .graphics_for(state.ids.debug_button)
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(state.ids.debug_button_label, ui); .set(state.ids.debug_button_label, ui);
} }
// 2 Gameplay//////////////// // 2 Gameplay////////////////
if Button::image(if let SettingsTab::Gameplay = state.settings_tab { if Button::image(if let SettingsTab::Gameplay = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button self.imgs.settings_button
}) })
.w_h(31.0 * 4.0, 12.0 * 4.0) .w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Gameplay = state.settings_tab { .hover_image(if let SettingsTab::Gameplay = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_hover self.imgs.settings_button_hover
}) })
.press_image(if let SettingsTab::Gameplay = state.settings_tab { .press_image(if let SettingsTab::Gameplay = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_press self.imgs.settings_button_press
}) })
.right_from(state.ids.interface, 0.0) .right_from(state.ids.interface, 0.0)
.label("Gameplay") .label("Gameplay")
.label_font_size(14) .label_font_size(14)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
.set(state.ids.gameplay, ui) .set(state.ids.gameplay, ui)
.was_clicked() .was_clicked()
{ {
state.update(|s| s.settings_tab = SettingsTab::Gameplay); state.update(|s| s.settings_tab = SettingsTab::Gameplay);
} }
// 3 Controls///////////////////// // 3 Controls/////////////////////
if Button::image(if let SettingsTab::Controls = state.settings_tab { if Button::image(if let SettingsTab::Controls = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button self.imgs.settings_button
}) })
.w_h(31.0 * 4.0, 12.0 * 4.0) .w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Controls = state.settings_tab { .hover_image(if let SettingsTab::Controls = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_hover self.imgs.settings_button_hover
}) })
.press_image(if let SettingsTab::Controls = state.settings_tab { .press_image(if let SettingsTab::Controls = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_press self.imgs.settings_button_press
}) })
.right_from(state.ids.gameplay, 0.0) .right_from(state.ids.gameplay, 0.0)
.label("Controls") .label("Controls")
.label_font_size(14) .label_font_size(14)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
.set(state.ids.controls, ui) .set(state.ids.controls, ui)
.was_clicked() .was_clicked()
{ {
state.update(|s| s.settings_tab = SettingsTab::Controls); state.update(|s| s.settings_tab = SettingsTab::Controls);
} }
if let SettingsTab::Controls = state.settings_tab { if let SettingsTab::Controls = state.settings_tab {
Text::new( Text::new(
"Free Cursor\n\ "Free Cursor\n\
Toggle Help Window\n\ Toggle Help Window\n\
Toggle Interface\n\ Toggle Interface\n\
Toggle FPS and Debug Info\n\ Toggle FPS and Debug Info\n\
@ -364,131 +347,131 @@ impl<'a> Widget for SettingsWindow<'a> {
/alias [Name] - Change your Chat Name \n\ /alias [Name] - Change your Chat Name \n\
/tp [Name] - Teleports you to another player /tp [Name] - Teleports you to another player
", ",
) )
.color(TEXT_COLOR) .color(TEXT_COLOR)
.top_left_with_margins_on(state.ids.settings_content, 5.0, 5.0) .top_left_with_margins_on(state.ids.settings_content, 5.0, 5.0)
.font_id(self.fonts.opensans) .font_id(self.fonts.opensans)
.font_size(18) .font_size(18)
.set(state.ids.controls_text, ui); .set(state.ids.controls_text, ui);
// TODO: Replace with buttons that show the actual keybind and allow the user to change it. // TODO: Replace with buttons that show the actual keybind and allow the user to change it.
Text::new( Text::new(
"TAB\n\ "TAB\n\
F1\n\ F1\n\
F2\n\ F2\n\
F3\n\ F3\n\
\n\ \n\
\n\ \n\
W\n\ W\n\
A\n\ A\n\
S\n\ S\n\
D\n\ D\n\
\n\ \n\
SPACE\n\ SPACE\n\
\n\ \n\
??\n\ ??\n\
\n\ \n\
??\n\ ??\n\
\n\ \n\
??\n\ ??\n\
\n\ \n\
??\n\ ??\n\
\n\ \n\
\n\ \n\
L-Click\n\ L-Click\n\
R-Click\n\ R-Click\n\
\n\ \n\
\n\ \n\
1\n\ 1\n\
2\n\ 2\n\
3\n\ 3\n\
4\n\ 4\n\
5\n\ 5\n\
6\n\ 6\n\
7\n\ 7\n\
8\n\ 8\n\
9\n\ 9\n\
0\n\ 0\n\
\n\ \n\
\n\ \n\
ESC\n\ ESC\n\
N\n\ N\n\
O\n\ O\n\
M\n\ M\n\
P\n\ P\n\
C\n\ C\n\
L\n\ L\n\
B\n\ B\n\
\n\ \n\
\n\ \n\
\n\ \n\
ENTER\n\ ENTER\n\
Mousewheel\n\ Mousewheel\n\
\n\ \n\
\n\ \n\
\n\ \n\
\n\ \n\
\n\ \n\
\n\ \n\
", ",
) )
.color(TEXT_COLOR) .color(TEXT_COLOR)
.right_from(state.ids.controls_text, 0.0) .right_from(state.ids.controls_text, 0.0)
.font_id(self.fonts.opensans) .font_id(self.fonts.opensans)
.font_size(18) .font_size(18)
.set(state.ids.controls_controls, ui); .set(state.ids.controls_controls, ui);
} }
// 4 Video//////////////////////////////// // 4 Video////////////////////////////////
if Button::image(if let SettingsTab::Video = state.settings_tab { if Button::image(if let SettingsTab::Video = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button self.imgs.settings_button
}) })
.w_h(31.0 * 4.0, 12.0 * 4.0) .w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Video = state.settings_tab { .hover_image(if let SettingsTab::Video = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_hover self.imgs.settings_button_hover
}) })
.press_image(if let SettingsTab::Video = state.settings_tab { .press_image(if let SettingsTab::Video = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_press self.imgs.settings_button_press
}) })
.right_from(state.ids.controls, 0.0) .right_from(state.ids.controls, 0.0)
.label("Video") .label("Video")
.parent(state.ids.settings_r) .parent(state.ids.settings_r)
.label_font_size(14) .label_font_size(14)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
.set(state.ids.video, ui) .set(state.ids.video, ui)
.was_clicked() .was_clicked()
{ {
state.update(|s| s.settings_tab = SettingsTab::Video); state.update(|s| s.settings_tab = SettingsTab::Video);
} }
// 5 Sound/////////////////////////////// // 5 Sound///////////////////////////////
if Button::image(if let SettingsTab::Sound = state.settings_tab { if Button::image(if let SettingsTab::Sound = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button self.imgs.settings_button
}) })
.w_h(31.0 * 4.0, 12.0 * 4.0) .w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Sound = state.settings_tab { .hover_image(if let SettingsTab::Sound = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_hover self.imgs.settings_button_hover
}) })
.press_image(if let SettingsTab::Sound = state.settings_tab { .press_image(if let SettingsTab::Sound = state.settings_tab {
self.imgs.settings_button_pressed self.imgs.settings_button_pressed
} else { } else {
self.imgs.settings_button_press self.imgs.settings_button_press
}) })
.right_from(state.ids.video, 0.0) .right_from(state.ids.video, 0.0)
.parent(state.ids.settings_r) .parent(state.ids.settings_r)
.label("Sound") .label("Sound")
.label_font_size(14) .label_font_size(14)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
.set(state.ids.sound, ui) .set(state.ids.sound, ui)
.was_clicked() .was_clicked()
{ {
state.update(|s| s.settings_tab = SettingsTab::Sound); state.update(|s| s.settings_tab = SettingsTab::Sound);
} }

View File

@ -1,12 +1,8 @@
use super::{font_ids::Fonts, img_ids::Imgs, HP_COLOR, MANA_COLOR, TEXT_COLOR, XP_COLOR};
use conrod_core::{ use conrod_core::{
widget::{self, Image, Rectangle, Text}, widget::{self, Image, Rectangle, Text},
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon, widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
}; };
use super::{
img_ids::Imgs,
font_ids::Fonts,
TEXT_COLOR, XP_COLOR, HP_COLOR, MANA_COLOR,
};
widget_ids! { widget_ids! {
struct Ids { struct Ids {
@ -69,11 +65,7 @@ impl<'a> Widget for Skillbar<'a> {
} }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { let widget::UpdateArgs { state, ui, .. } = args;
state,
ui,
..
} = args;
// TODO: Read from parameter / character struct // TODO: Read from parameter / character struct
let xp_percentage = 0.4; let xp_percentage = 0.4;

View File

@ -1,15 +1,10 @@
use super::{font_ids::Fonts, img_ids::Imgs, Windows, TEXT_COLOR};
use crate::hud::Show;
use conrod_core::{ use conrod_core::{
color, color,
widget::{self, Button, Image, Rectangle, Text}, widget::{self, Button, Image, Rectangle, Text},
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon, widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
}; };
use crate::hud::Show;
use super::{
img_ids::Imgs,
font_ids::Fonts,
Windows,
TEXT_COLOR,
};
widget_ids! { widget_ids! {
struct Ids { struct Ids {
@ -76,11 +71,7 @@ impl<'a> Widget for SmallWindow<'a> {
} }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event { fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { let widget::UpdateArgs { state, ui, .. } = args;
state,
ui,
..
} = args;
let (title, icon) = match self.content { let (title, icon) = match self.content {
SmallWindowType::Social => ("Social", self.imgs.social_icon), SmallWindowType::Social => ("Social", self.imgs.social_icon),
@ -91,14 +82,14 @@ impl<'a> Widget for SmallWindow<'a> {
// Frame // Frame
// TODO: Relative to Char Window? // TODO: Relative to Char Window?
if let Windows::CharacterAnd(_) = self.show.open_windows { if let Windows::CharacterAnd(_) = self.show.open_windows {
Image::new(self.imgs.window_frame) Image::new(self.imgs.window_frame)
.top_left_with_margins_on(ui.window, 200.0, 658.0) .top_left_with_margins_on(ui.window, 200.0, 658.0)
.w_h(107.0*4.0, 125.0*4.0) .w_h(107.0 * 4.0, 125.0 * 4.0)
.set(state.ids.frame, ui); .set(state.ids.frame, ui);
} else { } else {
Image::new(self.imgs.window_frame) Image::new(self.imgs.window_frame)
.top_left_with_margins_on(ui.window, 200.0, 10.0) .top_left_with_margins_on(ui.window, 200.0, 10.0)
.w_h(107.0*4.0, 125.0*4.0) .w_h(107.0 * 4.0, 125.0 * 4.0)
.set(state.ids.frame, ui); .set(state.ids.frame, ui);
} }
@ -143,4 +134,3 @@ impl<'a> Widget for SmallWindow<'a> {
None None
} }
} }

View File

@ -1,23 +1,11 @@
use std::sync::Arc;
use crate::{ use crate::{
render::Renderer, render::Renderer,
ui::{self, Graphic, ScaleMode, Ui}, ui::{self, Graphic, ScaleMode, Ui},
window::Window, window::Window,
}; };
use common::{ use common::{
assets, assets,
comp::character::{ comp::character::{Belt, Character, Chest, Foot, Gender, Hand, Head, Pants, Race, Weapon},
Character,
Race,
Gender,
Head,
Chest,
Belt,
Pants,
Hand,
Foot,
Weapon,
}
}; };
use conrod_core::{ use conrod_core::{
color, color,
@ -27,6 +15,7 @@ use conrod_core::{
widget::{text_box::Event as TextBoxEvent, Button, Image, Rectangle, Text, TextBox}, widget::{text_box::Event as TextBoxEvent, Button, Image, Rectangle, Text, TextBox},
widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, Widget, widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
}; };
use std::sync::Arc;
widget_ids! { widget_ids! {
struct Ids { struct Ids {
@ -245,14 +234,12 @@ impl Imgs {
fn new(ui: &mut Ui) -> Imgs { fn new(ui: &mut Ui) -> Imgs {
let load_img = |filename, ui: &mut Ui| { let load_img = |filename, ui: &mut Ui| {
let fullpath: String = ["/voxygen/", filename].concat(); let fullpath: String = ["/voxygen/", filename].concat();
let image = assets::load::<image::DynamicImage>(fullpath.as_str()) let image = assets::load::<image::DynamicImage>(fullpath.as_str()).unwrap();
.unwrap();
ui.add_graphic(Graphic::Image(image)) ui.add_graphic(Graphic::Image(image))
}; };
let load_vox = |filename, ui: &mut Ui| { let load_vox = |filename, ui: &mut Ui| {
let fullpath: String = ["/voxygen/", filename].concat(); let fullpath: String = ["/voxygen/", filename].concat();
let dot_vox = assets::load::<dot_vox::DotVoxData>(fullpath.as_str()) let dot_vox = assets::load::<dot_vox::DotVoxData>(fullpath.as_str()).unwrap();
.unwrap();
ui.add_graphic(Graphic::Voxel(dot_vox)) ui.add_graphic(Graphic::Voxel(dot_vox))
}; };
Imgs { Imgs {
@ -374,10 +361,12 @@ impl CharSelectionUi {
// Load fonts // Load fonts
let load_font = |filename, ui: &mut Ui| { let load_font = |filename, ui: &mut Ui| {
let fullpath: String = ["/voxygen/font", filename].concat(); let fullpath: String = ["/voxygen/font", filename].concat();
ui.new_font(Arc::new(conrod_core::text::Font::from_bytes( ui.new_font(Arc::new(
assets::load_from_path(fullpath.as_str()) conrod_core::text::Font::from_bytes(
.expect("Error loading file") assets::load_from_path(fullpath.as_str()).expect("Error loading file"),
).unwrap())) )
.unwrap(),
))
}; };
let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui); let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui);
let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui); let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui);

View File

@ -1,12 +1,9 @@
use std::sync::Arc;
use crate::{ use crate::{
render::Renderer, render::Renderer,
ui::{self, Graphic, ScaleMode, Ui}, ui::{self, Graphic, ScaleMode, Ui},
GlobalState, DEFAULT_PUBLIC_SERVER, GlobalState, DEFAULT_PUBLIC_SERVER,
}; };
use common::{ use common::assets;
assets,
};
use conrod_core::{ use conrod_core::{
color, color,
color::TRANSPARENT, color::TRANSPARENT,
@ -16,6 +13,7 @@ use conrod_core::{
widget::{text_box::Event as TextBoxEvent, Button, Image, List, Rectangle, Text, TextBox}, widget::{text_box::Event as TextBoxEvent, Button, Image, List, Rectangle, Text, TextBox},
widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, Widget, widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
}; };
use std::sync::Arc;
widget_ids! { widget_ids! {
struct Ids { struct Ids {
@ -68,14 +66,12 @@ impl Imgs {
fn new(ui: &mut Ui) -> Imgs { fn new(ui: &mut Ui) -> Imgs {
let load_img = |filename, ui: &mut Ui| { let load_img = |filename, ui: &mut Ui| {
let fullpath: String = ["/voxygen/", filename].concat(); let fullpath: String = ["/voxygen/", filename].concat();
let image = assets::load::<image::DynamicImage>(fullpath.as_str()) let image = assets::load::<image::DynamicImage>(fullpath.as_str()).unwrap();
.unwrap();
ui.add_graphic(Graphic::Image(image)) ui.add_graphic(Graphic::Image(image))
}; };
let load_vox = |filename, ui: &mut Ui| { let load_vox = |filename, ui: &mut Ui| {
let fullpath: String = ["/voxygen/", filename].concat(); let fullpath: String = ["/voxygen/", filename].concat();
let dot_vox = assets::load::<dot_vox::DotVoxData>(fullpath.as_str()) let dot_vox = assets::load::<dot_vox::DotVoxData>(fullpath.as_str()).unwrap();
.unwrap();
ui.add_graphic(Graphic::Voxel(dot_vox)) ui.add_graphic(Graphic::Voxel(dot_vox))
}; };
Imgs { Imgs {
@ -131,10 +127,10 @@ impl MainMenuUi {
let fullpath: String = ["/voxygen/font", filename].concat(); let fullpath: String = ["/voxygen/font", filename].concat();
ui.new_font(Arc::new( ui.new_font(Arc::new(
conrod_core::text::Font::from_bytes( conrod_core::text::Font::from_bytes(
assets::load_from_path(fullpath.as_str()).expect("Error loading file") assets::load_from_path(fullpath.as_str()).expect("Error loading file"),
) )
.unwrap()), .unwrap(),
) ))
}; };
let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui); let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui);
let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui); let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui);

View File

@ -19,9 +19,9 @@ use common::{
figure::Segment, figure::Segment,
msg, msg,
}; };
use dot_vox::DotVoxData;
use specs::{Component, Entity as EcsEntity, Join, VecStorage}; use specs::{Component, Entity as EcsEntity, Join, VecStorage};
use std::{collections::HashMap, f32}; use std::{collections::HashMap, f32};
use dot_vox::DotVoxData;
use vek::*; use vek::*;
pub struct FigureCache { pub struct FigureCache {
@ -101,9 +101,7 @@ impl FigureCache {
fn load_mesh(filename: &str, position: Vec3<f32>) -> Mesh<FigurePipeline> { fn load_mesh(filename: &str, position: Vec3<f32>) -> Mesh<FigurePipeline> {
let fullpath: String = ["/voxygen/voxel/", filename].concat(); let fullpath: String = ["/voxygen/voxel/", filename].concat();
Segment::from( Segment::from(assets::load_expect::<DotVoxData>(fullpath.as_str()).as_ref())
assets::load_expect::<DotVoxData>(fullpath.as_str()).as_ref()
)
.generate_mesh(position) .generate_mesh(position)
} }

View File

@ -1,8 +1,8 @@
use std::sync::Arc; use dot_vox::DotVoxData;
use fnv::FnvHashMap; use fnv::FnvHashMap;
use guillotiere::{size2, Allocation, AtlasAllocator}; use guillotiere::{size2, Allocation, AtlasAllocator};
use image::DynamicImage; use image::DynamicImage;
use dot_vox::DotVoxData; use std::sync::Arc;
use vek::*; use vek::*;
pub enum Graphic { pub enum Graphic {

View File

@ -1,7 +1,7 @@
use super::Graphic; use super::Graphic;
use common::assets::{load, Error};
use dot_vox::DotVoxData; use dot_vox::DotVoxData;
use image::DynamicImage; use image::DynamicImage;
use common::assets::{Error, load};
pub struct BlankGraphic; pub struct BlankGraphic;
pub struct ImageGraphic; pub struct ImageGraphic;
@ -20,13 +20,13 @@ impl<'a> GraphicCreator<'a> for BlankGraphic {
impl<'a> GraphicCreator<'a> for ImageGraphic { impl<'a> GraphicCreator<'a> for ImageGraphic {
type Specifier = &'a str; type Specifier = &'a str;
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> { fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
Ok(Graphic::Image(load::<DynamicImage>(specifier)?)) Ok(Graphic::Image(load::<DynamicImage>(specifier)?))
} }
} }
impl<'a> GraphicCreator<'a> for VoxelGraphic { impl<'a> GraphicCreator<'a> for VoxelGraphic {
type Specifier = &'a str; type Specifier = &'a str;
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> { fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?)) Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?))
} }
} }
@ -43,7 +43,7 @@ impl<'a> GraphicCreator<'a> for VoxelGraphic {
/// ///
/// <ImageGraphic> /// <ImageGraphic>
/// background: "background.png", /// background: "background.png",
/// ///
/// <BlankGraphic> /// <BlankGraphic>
/// blank: (), /// blank: (),
/// } /// }

View File

@ -1,14 +1,11 @@
mod graphic; mod graphic;
mod util; mod util;
mod widgets; mod widgets;
#[macro_use] mod img_ids; #[macro_use]
#[macro_use] mod font_ids; mod img_ids;
#[macro_use]
mod font_ids;
use std::sync::Arc;
pub use graphic::Graphic;
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::{ use crate::{
render::{ render::{
create_ui_quad, create_ui_tri, Mesh, Model, RenderError, Renderer, Texture, UiMode, create_ui_quad, create_ui_tri, Mesh, Model, RenderError, Renderer, Texture, UiMode,
@ -19,16 +16,21 @@ use crate::{
}; };
use conrod_core::{ use conrod_core::{
event::Input, event::Input,
graph::Graph,
image::{Id as ImgId, Map}, image::{Id as ImgId, Map},
input::{touch::Touch, Button, Motion, Widget}, input::{touch::Touch, Button, Motion, Widget},
graph::Graph,
render::Primitive, render::Primitive,
text::{font::Id as FontId, Font, GlyphCache}, text::{font::Id as FontId, Font, GlyphCache},
widget::{id::Generator, Id as WidgId}, widget::{id::Generator, Id as WidgId},
Ui as CrUi, UiBuilder, UiCell, Ui as CrUi, UiBuilder, UiCell,
}; };
pub use graphic::Graphic;
use graphic::{GraphicCache, Id as GraphicId}; use graphic::{GraphicCache, Id as GraphicId};
pub use img_ids::{BlankGraphic, GraphicCreator, ImageGraphic, VoxelGraphic};
use std::sync::Arc;
pub(self) use util::{linear_to_srgb, srgb_to_linear};
use vek::*; use vek::*;
pub use widgets::toggle_button::ToggleButton;
#[derive(Debug)] #[derive(Debug)]
pub enum UiError { pub enum UiError {