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,
@ -46,7 +46,8 @@ lazy_static! {
/// ``` /// ```
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()
@ -64,8 +65,7 @@ pub fn load<A: Asset + 'static>(specifier: &str) -> Result<Arc<A>, Error> {
/// 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,12 +1,9 @@
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! {
struct Ids { struct 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)
@ -99,7 +92,6 @@ impl<'a> Widget for Bag<'a> {
.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
Button::image(self.imgs.inv_slot) Button::image(self.imgs.inv_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,20 +84,18 @@ 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
!= ToggleButton::new(self.show_bag, self.imgs.bag, self.imgs.bag_open)
.bottom_right_with_margins_on(ui.window, 5.0, 5.0) .bottom_right_with_margins_on(ui.window, 5.0, 5.0)
.hover_images(self.imgs.bag_hover, self.imgs.bag_open_hover) .hover_images(self.imgs.bag_hover, self.imgs.bag_open_hover)
.press_images(self.imgs.bag_press, self.imgs.bag_open_press) .press_images(self.imgs.bag_press, self.imgs.bag_open_press)
.w_h(420.0 / 10.0, 480.0 / 10.0) .w_h(420.0 / 10.0, 480.0 / 10.0)
.set(state.ids.bag, ui) { .set(state.ids.bag, ui)
{
return Some(Event::ToggleBag); return Some(Event::ToggleBag);
} }

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,7 +72,7 @@ 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
@ -98,7 +88,8 @@ 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);
} }

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| {
if input_focused {
r.up_from(state.ids.input_bg, 0.0) r.up_from(state.ids.input_bg, 0.0)
} else { } else {
r.bottom_left_with_margins_on(ui.window, 10.0, 10.0) 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);
} }

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 {

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,11 +63,7 @@ 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)
@ -102,7 +95,6 @@ impl<'a> Widget for Map<'a> {
.top_left_with_margins_on(state.ids.map_frame, -10.0, -10.0) .top_left_with_margins_on(state.ids.map_frame, -10.0, -10.0)
.set(state.ids.map_icon, ui); .set(state.ids.map_icon, ui);
// Icon // Icon
Image::new(self.imgs.map_icon) Image::new(self.imgs.map_icon)
.w_h(224.0 / 3.0, 224.0 / 3.0) .w_h(224.0 / 3.0, 224.0 / 3.0)

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;
@ -293,7 +295,13 @@ impl Hud {
}; };
} }
match Buttons::new(&self.show.open_windows, self.show.map, self.show.bag, &self.imgs, &self.fonts) match Buttons::new(
&self.show.open_windows,
self.show.map,
self.show.bag,
&self.imgs,
&self.fonts,
)
.set(self.ids.buttons, ui_widgets) .set(self.ids.buttons, ui_widgets)
{ {
Some(buttons::Event::ToggleBag) => self.show.toggle_bag(), Some(buttons::Event::ToggleBag) => self.show.toggle_bag(),
@ -363,8 +371,7 @@ impl Hud {
} }
} }
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)
@ -403,11 +410,13 @@ impl Hud {
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) => {
self.show.open_windows = match self.show.open_windows {
Windows::Small(_) => Windows::None, Windows::Small(_) => Windows::None,
Windows::CharacterAnd(_) => Windows::CharacterAnd(None), Windows::CharacterAnd(_) => Windows::CharacterAnd(None),
_ => Windows::Settings, _ => Windows::Settings,
}, }
}
None => {} None => {}
} }
} }
@ -417,19 +426,19 @@ impl Hud {
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) => {
self.show.open_windows = match small {
Some(small) => Windows::Small(small), Some(small) => Windows::Small(small),
None => Windows::None, 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,7 +454,7 @@ 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 => {}
} }
} }
@ -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,17 +1,10 @@
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 {
@ -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)
@ -150,8 +139,6 @@ impl<'a> Widget for SettingsWindow<'a> {
.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
@ -226,11 +213,8 @@ 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,
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.inventory_test_button, 7.0) .down_from(state.ids.inventory_test_button, 7.0)
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo) .hover_images(self.imgs.check_checked_mo, self.imgs.check_mo)
@ -248,7 +232,6 @@ 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////////////////

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),
@ -93,12 +84,12 @@ impl<'a> Widget for SmallWindow<'a> {
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,4 +1,3 @@
use std::sync::Arc;
use crate::{ use crate::{
render::Renderer, render::Renderer,
ui::{self, Graphic, ScaleMode, Ui}, ui::{self, Graphic, ScaleMode, Ui},
@ -6,18 +5,7 @@ use crate::{
}; };
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;

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 {