mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Make fonts work, Remove style
Former-commit-id: 53d158aff30d8c53b86deb62f7079ba06b5119ce
This commit is contained in:
parent
53a78e1c2f
commit
f695973bb2
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2284,6 +2284,7 @@ name = "veloren-common"
|
|||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bincode 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"conrod_core 0.63.0 (git+https://gitlab.com/veloren/conrod.git)",
|
||||||
"dot_vox 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"dot_vox 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"image 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"image 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -9,6 +9,7 @@ sphynx = { git = "https://gitlab.com/veloren/sphynx.git", features = ["serde1"]
|
|||||||
|
|
||||||
specs = { version = "0.14", features = ["serde", "nightly"] }
|
specs = { version = "0.14", features = ["serde", "nightly"] }
|
||||||
vek = { version = "0.9", features = ["serde"] }
|
vek = { version = "0.9", features = ["serde"] }
|
||||||
|
conrod_core = { git = "https://gitlab.com/veloren/conrod.git" }
|
||||||
dot_vox = "4.0"
|
dot_vox = "4.0"
|
||||||
image = "0.21"
|
image = "0.21"
|
||||||
threadpool = "1.7"
|
threadpool = "1.7"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
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,7 +42,7 @@ 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
|
||||||
@ -60,7 +61,7 @@ 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)
|
||||||
@ -75,8 +76,8 @@ 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()
|
load_from_path(specifier)?.as_slice()
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -85,15 +86,24 @@ impl Asset for DynamicImage {
|
|||||||
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()
|
load_from_path(specifier)?.as_slice()
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Asset for Font {
|
||||||
|
fn load(specifier: &str) -> Result<Self, Error> {
|
||||||
|
Ok(Font::from_bytes(
|
||||||
|
load_from_path(specifier)?).unwrap()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: System to load file from specifiers (eg "core.ui.backgrounds.city")
|
// TODO: System to load file from specifiers (eg "core.ui.backgrounds.city")
|
||||||
fn try_open_with_path(name: &str) -> Option<File> {
|
fn try_open_with_path(name: &str) -> Option<File> {
|
||||||
|
debug!("Trying to access \"{}\"", name);
|
||||||
// TODO: don't do this?
|
// TODO: don't do this?
|
||||||
// if it's stupid and it works..,
|
// if it's stupid and it works..,
|
||||||
[
|
[
|
||||||
|
@ -4,14 +4,15 @@ use conrod_core::{
|
|||||||
widget::{self, Button, Image, Rectangle, Text},
|
widget::{self, Button, Image, Rectangle, Text},
|
||||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
imgs::Imgs,
|
img_ids::Imgs,
|
||||||
WindowStyle, XP_COLOR,
|
font_ids::Fonts,
|
||||||
|
TEXT_COLOR,
|
||||||
|
XP_COLOR,
|
||||||
};
|
};
|
||||||
|
|
||||||
widget_ids! {
|
widget_ids! {
|
||||||
struct Ids {
|
pub struct Ids {
|
||||||
charwindow,
|
charwindow,
|
||||||
charwindow_bg,
|
charwindow_bg,
|
||||||
charwindow_close,
|
charwindow_close,
|
||||||
@ -35,32 +36,23 @@ widget_ids! {
|
|||||||
pub struct CharacterWindow<'a> {
|
pub struct CharacterWindow<'a> {
|
||||||
xp_percentage: f64,
|
xp_percentage: f64,
|
||||||
imgs: &'a Imgs,
|
imgs: &'a Imgs,
|
||||||
|
fonts: &'a Fonts,
|
||||||
|
|
||||||
#[conrod(common_builder)]
|
#[conrod(common_builder)]
|
||||||
common: widget::CommonBuilder,
|
common: widget::CommonBuilder,
|
||||||
style: WindowStyle,
|
style: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CharacterWindow<'a> {
|
impl<'a> CharacterWindow<'a> {
|
||||||
pub fn new(imgs: &'a Imgs) -> Self {
|
pub fn new(imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
||||||
Self {
|
Self {
|
||||||
xp_percentage: 0.4,
|
xp_percentage: 0.4,
|
||||||
imgs,
|
imgs,
|
||||||
|
fonts,
|
||||||
common: widget::CommonBuilder::default(),
|
common: widget::CommonBuilder::default(),
|
||||||
style: WindowStyle::default(),
|
style: (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn font_id(mut self, font_id: font::Id) -> Self {
|
|
||||||
self.style.font_id = Some(Some(font_id));
|
|
||||||
self
|
|
||||||
}
|
|
||||||
builder_methods! {
|
|
||||||
pub text_color { style.text_color = Some(Color) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct State {
|
|
||||||
ids: Ids,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
@ -68,18 +60,16 @@ pub enum Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for CharacterWindow<'a> {
|
impl<'a> Widget for CharacterWindow<'a> {
|
||||||
type State = State;
|
type State = Ids;
|
||||||
type Style = WindowStyle;
|
type Style = ();
|
||||||
type Event = Option<Event>;
|
type Event = Option<Event>;
|
||||||
|
|
||||||
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||||
State {
|
Ids::new(id_gen)
|
||||||
ids: Ids::new(id_gen),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn style(&self) -> Self::Style {
|
fn style(&self) -> Self::Style {
|
||||||
self.style.clone()
|
()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||||
@ -91,99 +81,95 @@ impl<'a> Widget for CharacterWindow<'a> {
|
|||||||
..
|
..
|
||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
let font_id = style.font_id(&ui.theme).or(ui.fonts.ids().next());
|
|
||||||
let text_color = style.text_color(&ui.theme);
|
|
||||||
|
|
||||||
// Frame
|
// Frame
|
||||||
Image::new(self.imgs.window_frame)
|
Image::new(self.imgs.window_frame)
|
||||||
.middle_of(id)
|
.middle_of(id)
|
||||||
.set(state.ids.charwindow_frame, ui);
|
.set(state.charwindow_frame, ui);
|
||||||
|
|
||||||
// BG
|
// BG
|
||||||
Image::new(self.imgs.window_bg)
|
Image::new(self.imgs.window_bg)
|
||||||
.w_h(348.0, 404.0)
|
.w_h(348.0, 404.0)
|
||||||
.mid_top_with_margin_on(state.ids.charwindow_frame, 48.0)
|
.mid_top_with_margin_on(state.charwindow_frame, 48.0)
|
||||||
.set(state.ids.charwindow_bg, ui);
|
.set(state.charwindow_bg, ui);
|
||||||
|
|
||||||
// Overlay
|
// Overlay
|
||||||
Image::new(self.imgs.charwindow)
|
Image::new(self.imgs.charwindow)
|
||||||
.middle_of(state.ids.charwindow_bg)
|
.middle_of(state.charwindow_bg)
|
||||||
.set(state.ids.charwindow, ui);
|
.set(state.charwindow, ui);
|
||||||
|
|
||||||
// Icon
|
// Icon
|
||||||
//Image::new(self.imgs.charwindow_icon)
|
//Image::new(self.imgs.charwindow_icon)
|
||||||
//.w_h(224.0 / 3.0, 224.0 / 3.0)
|
//.w_h(224.0 / 3.0, 224.0 / 3.0)
|
||||||
//.top_left_with_margins_on(state.ids.charwindow_frame, -10.0, -10.0)
|
//.top_left_with_margins_on(state.charwindow_frame, -10.0, -10.0)
|
||||||
//.set(state.ids.charwindow_icon, ui);
|
//.set(state.charwindow_icon, ui);
|
||||||
|
|
||||||
// X-Button
|
// X-Button
|
||||||
if Button::image(self.imgs.close_button)
|
if Button::image(self.imgs.close_button)
|
||||||
.w_h(244.0 * 0.22 / 4.0, 244.0 * 0.22 / 4.0)
|
.w_h(244.0 * 0.22 / 4.0, 244.0 * 0.22 / 4.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.charwindow_frame, 4.0, 4.0)
|
.top_right_with_margins_on(state.charwindow_frame, 4.0, 4.0)
|
||||||
.set(state.ids.charwindow_close, ui)
|
.set(state.charwindow_close, ui)
|
||||||
.was_clicked() {
|
.was_clicked() {
|
||||||
return Some(Event::Close);
|
return Some(Event::Close);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Title
|
// Title
|
||||||
Text::new("Character Name") // Add in actual Character Name
|
Text::new("Character Name") // Add in actual Character Name
|
||||||
.mid_top_with_margin_on(state.ids.charwindow_frame, 7.0)
|
.mid_top_with_margin_on(state.charwindow_frame, 7.0)
|
||||||
.color(text_color)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.charwindow_title, ui);
|
.set(state.charwindow_title, ui);
|
||||||
|
|
||||||
// Tab BG
|
// Tab BG
|
||||||
Image::new(self.imgs.charwindow_tab_bg)
|
Image::new(self.imgs.charwindow_tab_bg)
|
||||||
.w_h(205.0, 412.0)
|
.w_h(205.0, 412.0)
|
||||||
.mid_left_with_margin_on(state.ids.charwindow_frame, -205.0)
|
.mid_left_with_margin_on(state.charwindow_frame, -205.0)
|
||||||
.set(state.ids.charwindow_tab_bg, ui);
|
.set(state.charwindow_tab_bg, ui);
|
||||||
|
|
||||||
// Tab Rectangle
|
// Tab Rectangle
|
||||||
Rectangle::fill_with([192.0, 371.0], color::rgba(0.0, 0.0, 0.0, 0.8))
|
Rectangle::fill_with([192.0, 371.0], color::rgba(0.0, 0.0, 0.0, 0.8))
|
||||||
.top_right_with_margins_on(state.ids.charwindow_tab_bg, 20.0, 0.0)
|
.top_right_with_margins_on(state.charwindow_tab_bg, 20.0, 0.0)
|
||||||
.set(state.ids.charwindow_rectangle, ui);
|
.set(state.charwindow_rectangle, ui);
|
||||||
|
|
||||||
// Tab Button
|
// Tab Button
|
||||||
Button::image(self.imgs.charwindow_tab)
|
Button::image(self.imgs.charwindow_tab)
|
||||||
.w_h(65.0, 23.0)
|
.w_h(65.0, 23.0)
|
||||||
.top_left_with_margins_on(state.ids.charwindow_tab_bg, -18.0, 2.0)
|
.top_left_with_margins_on(state.charwindow_tab_bg, -18.0, 2.0)
|
||||||
.label("Stats")
|
.label("Stats")
|
||||||
.label_color(text_color)
|
.label_color(TEXT_COLOR)
|
||||||
.and_then(font_id, Button::label_font_id)
|
|
||||||
.label_font_size(14)
|
.label_font_size(14)
|
||||||
.set(state.ids.charwindow_tab1, ui);
|
.set(state.charwindow_tab1, ui);
|
||||||
|
|
||||||
Text::new("1") //Add in actual Character Level
|
Text::new("1") //Add in actual Character Level
|
||||||
.mid_top_with_margin_on(state.ids.charwindow_rectangle, 10.0)
|
.mid_top_with_margin_on(state.charwindow_rectangle, 10.0)
|
||||||
.and_then(font_id, Text::font_id)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(30)
|
.font_size(30)
|
||||||
.color(text_color)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.charwindow_tab1_level, ui);
|
.set(state.charwindow_tab1_level, ui);
|
||||||
|
|
||||||
// Exp-Bar Background
|
// Exp-Bar Background
|
||||||
Rectangle::fill_with([170.0, 10.0], color::BLACK)
|
Rectangle::fill_with([170.0, 10.0], color::BLACK)
|
||||||
.mid_top_with_margin_on(state.ids.charwindow_rectangle, 50.0)
|
.mid_top_with_margin_on(state.charwindow_rectangle, 50.0)
|
||||||
.set(state.ids.charwindow_exp_rectangle, ui);
|
.set(state.charwindow_exp_rectangle, ui);
|
||||||
|
|
||||||
// Exp-Bar Progress
|
// Exp-Bar Progress
|
||||||
Rectangle::fill_with([170.0 * (self.xp_percentage), 6.0], XP_COLOR) // 0.8 = Experience percantage
|
Rectangle::fill_with([170.0 * (self.xp_percentage), 6.0], XP_COLOR) // 0.8 = Experience percentage
|
||||||
.mid_left_with_margin_on(state.ids.charwindow_tab1_expbar, 1.0)
|
.mid_left_with_margin_on(state.charwindow_tab1_expbar, 1.0)
|
||||||
.set(state.ids.charwindow_exp_progress_rectangle, ui);
|
.set(state.charwindow_exp_progress_rectangle, ui);
|
||||||
|
|
||||||
// Exp-Bar Foreground Frame
|
// Exp-Bar Foreground Frame
|
||||||
Image::new(self.imgs.progress_frame)
|
Image::new(self.imgs.progress_frame)
|
||||||
.w_h(170.0, 10.0)
|
.w_h(170.0, 10.0)
|
||||||
.middle_of(state.ids.charwindow_exp_rectangle)
|
.middle_of(state.charwindow_exp_rectangle)
|
||||||
.set(state.ids.charwindow_tab1_expbar, ui);
|
.set(state.charwindow_tab1_expbar, ui);
|
||||||
|
|
||||||
// Exp-Text
|
// Exp-Text
|
||||||
Text::new("120/170") // Shows the Exp / Exp to reach the next level
|
Text::new("120/170") // Shows the Exp / Exp to reach the next level
|
||||||
.mid_top_with_margin_on(state.ids.charwindow_tab1_expbar, 10.0)
|
.mid_top_with_margin_on(state.charwindow_tab1_expbar, 10.0)
|
||||||
.and_then(font_id, Text::font_id)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(15)
|
.font_size(15)
|
||||||
.color(text_color)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.charwindow_tab1_exp, ui);
|
.set(state.charwindow_tab1_exp, ui);
|
||||||
|
|
||||||
// Stats
|
// Stats
|
||||||
Text::new(
|
Text::new(
|
||||||
@ -195,11 +181,11 @@ impl<'a> Widget for CharacterWindow<'a> {
|
|||||||
\n\
|
\n\
|
||||||
Intelligence",
|
Intelligence",
|
||||||
)
|
)
|
||||||
.top_left_with_margins_on(state.ids.charwindow_rectangle, 100.0, 20.0)
|
.top_left_with_margins_on(state.charwindow_rectangle, 100.0, 20.0)
|
||||||
.and_then(font_id, Text::font_id)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(16)
|
.font_size(16)
|
||||||
.color(text_color)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.charwindow_tab1_statnames, ui);
|
.set(state.charwindow_tab1_statnames, ui);
|
||||||
|
|
||||||
Text::new(
|
Text::new(
|
||||||
"1234\n\
|
"1234\n\
|
||||||
@ -210,11 +196,11 @@ impl<'a> Widget for CharacterWindow<'a> {
|
|||||||
\n\
|
\n\
|
||||||
124124",
|
124124",
|
||||||
)
|
)
|
||||||
.right_from(state.ids.charwindow_tab1_statnames, 10.0)
|
.right_from(state.charwindow_tab1_statnames, 10.0)
|
||||||
.and_then(font_id, Text::font_id)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(16)
|
.font_size(16)
|
||||||
.color(text_color)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.charwindow_tab1_stats, ui);
|
.set(state.charwindow_tab1_stats, ui);
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use crate::ui::Ui;
|
use crate::ui::Ui;
|
||||||
|
use super::img_ids::Imgs;
|
||||||
|
use super::font_ids::Fonts;
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
color,
|
color,
|
||||||
input::Key,
|
input::Key,
|
||||||
@ -74,8 +76,8 @@ impl Chat {
|
|||||||
pub(super) fn update_layout(
|
pub(super) fn update_layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
ui_widgets: &mut UiCell,
|
ui_widgets: &mut UiCell,
|
||||||
font: FontId,
|
imgs: &Imgs,
|
||||||
imgs: &super::Imgs,
|
fonts: &Fonts,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
// Maintain scrolling
|
// Maintain scrolling
|
||||||
if self.new_messages {
|
if self.new_messages {
|
||||||
@ -96,7 +98,7 @@ impl Chat {
|
|||||||
.restrict_to_height(false)
|
.restrict_to_height(false)
|
||||||
.line_spacing(2.0)
|
.line_spacing(2.0)
|
||||||
.font_size(15)
|
.font_size(15)
|
||||||
.font_id(font);
|
.font_id(fonts.opensans);
|
||||||
let y = match text_edit.get_y_dimension(ui_widgets) {
|
let y = match text_edit.get_y_dimension(ui_widgets) {
|
||||||
Dimension::Absolute(y) => y + 6.0,
|
Dimension::Absolute(y) => y + 6.0,
|
||||||
_ => 0.0,
|
_ => 0.0,
|
||||||
@ -136,7 +138,7 @@ impl Chat {
|
|||||||
let widget = if item.i < self.messages.len() {
|
let widget = if item.i < self.messages.len() {
|
||||||
let text = Text::new(&self.messages[item.i])
|
let text = Text::new(&self.messages[item.i])
|
||||||
.font_size(15)
|
.font_size(15)
|
||||||
.font_id(font)
|
.font_id(fonts.opensans)
|
||||||
.w(470.0)
|
.w(470.0)
|
||||||
.rgba(1.0, 1.0, 1.0, 1.0)
|
.rgba(1.0, 1.0, 1.0, 1.0)
|
||||||
.line_spacing(2.0);
|
.line_spacing(2.0);
|
||||||
@ -149,7 +151,7 @@ impl Chat {
|
|||||||
} 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(font).w(470.0)
|
Text::new("").font_size(6).font_id(fonts.opensans).w(470.0)
|
||||||
};
|
};
|
||||||
item.set(widget, ui_widgets);
|
item.set(widget, ui_widgets);
|
||||||
}
|
}
|
||||||
|
164
voxygen/src/hud/esc_menu.rs
Normal file
164
voxygen/src/hud/esc_menu.rs
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
use conrod_core::{
|
||||||
|
builder_methods, color,
|
||||||
|
text::font,
|
||||||
|
widget::{self, Button, Image, Rectangle, Text},
|
||||||
|
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
imgs::Imgs,
|
||||||
|
Style, XP_COLOR,
|
||||||
|
};
|
||||||
|
|
||||||
|
widget_ids! {
|
||||||
|
struct Ids {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(WidgetCommon)]
|
||||||
|
pub struct EscMenu<'a> {
|
||||||
|
xp_percentage: f64,
|
||||||
|
imgs: &'a Imgs,
|
||||||
|
|
||||||
|
#[conrod(common_builder)]
|
||||||
|
common: widget::CommonBuilder,
|
||||||
|
style: Style,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> CharacterWindow<'a> {
|
||||||
|
pub fn new(imgs: &'a Imgs) -> Self {
|
||||||
|
Self {
|
||||||
|
xp_percentage: 0.4,
|
||||||
|
imgs,
|
||||||
|
common: widget::CommonBuilder::default(),
|
||||||
|
style: Style::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder_methods! {
|
||||||
|
pub text_color { style.text_color = Some(Color) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct State {
|
||||||
|
ids: Ids,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Event {
|
||||||
|
Close,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Widget for CharacterWindow<'a> {
|
||||||
|
type State = State;
|
||||||
|
type Style = Style;
|
||||||
|
type Event = Option<Event>;
|
||||||
|
|
||||||
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||||
|
State {
|
||||||
|
ids: Ids::new(id_gen),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn style(&self) -> Self::Style {
|
||||||
|
self.style.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||||
|
let widget::UpdateArgs {
|
||||||
|
id,
|
||||||
|
state,
|
||||||
|
ui,
|
||||||
|
style,
|
||||||
|
..
|
||||||
|
} = args;
|
||||||
|
|
||||||
|
let font_id = style.font_id(&ui.theme).or(ui.fonts.ids().next());
|
||||||
|
let text_color = style.text_color(&ui.theme);
|
||||||
|
|
||||||
|
if self.menu_open {
|
||||||
|
Image::new(self.imgs.esc_bg)
|
||||||
|
.w_h(228.0, 450.0)
|
||||||
|
.middle_of(ui_widgets.window)
|
||||||
|
.set(self.ids.esc_bg, ui_widgets);
|
||||||
|
|
||||||
|
Image::new(self.imgs.fireplace)
|
||||||
|
.w_h(180.0, 60.0)
|
||||||
|
.mid_top_with_margin_on(self.ids.esc_bg, 50.0)
|
||||||
|
.set(self.ids.fireplace, ui_widgets);
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
if Button::image(self.imgs.button_dark)
|
||||||
|
.mid_top_with_margin_on(self.ids.esc_bg, 115.0)
|
||||||
|
.w_h(170.0, 50.0)
|
||||||
|
.hover_image(self.imgs.button_dark_hover)
|
||||||
|
.press_image(self.imgs.button_dark_press)
|
||||||
|
.label("Settings")
|
||||||
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
||||||
|
.label_color(TEXT_COLOR)
|
||||||
|
.label_font_size(17)
|
||||||
|
.set(self.ids.menu_button_1, ui_widgets)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
self.menu_open = false;
|
||||||
|
self.open_windows = Windows::Settings;
|
||||||
|
};
|
||||||
|
// Controls
|
||||||
|
if Button::image(self.imgs.button_dark)
|
||||||
|
.mid_top_with_margin_on(self.ids.esc_bg, 175.0)
|
||||||
|
.w_h(170.0, 50.0)
|
||||||
|
.hover_image(self.imgs.button_dark_hover)
|
||||||
|
.press_image(self.imgs.button_dark_press)
|
||||||
|
.label("Controls")
|
||||||
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
||||||
|
.label_color(TEXT_COLOR)
|
||||||
|
.label_font_size(17)
|
||||||
|
.set(self.ids.menu_button_2, ui_widgets)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
//self.menu_open = false;
|
||||||
|
};
|
||||||
|
// Servers
|
||||||
|
if Button::image(self.imgs.button_dark)
|
||||||
|
.mid_top_with_margin_on(self.ids.esc_bg, 235.0)
|
||||||
|
.w_h(170.0, 50.0)
|
||||||
|
.hover_image(self.imgs.button_dark_hover)
|
||||||
|
.press_image(self.imgs.button_dark_press)
|
||||||
|
.label("Servers")
|
||||||
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
||||||
|
.label_color(TEXT_COLOR)
|
||||||
|
.label_font_size(17)
|
||||||
|
.set(self.ids.menu_button_3, ui_widgets)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
//self.menu_open = false;
|
||||||
|
};
|
||||||
|
// Logout
|
||||||
|
if Button::image(self.imgs.button_dark)
|
||||||
|
.mid_top_with_margin_on(self.ids.esc_bg, 295.0)
|
||||||
|
.w_h(170.0, 50.0)
|
||||||
|
.hover_image(self.imgs.button_dark_hover)
|
||||||
|
.press_image(self.imgs.button_dark_press)
|
||||||
|
.label("Logout")
|
||||||
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
||||||
|
.label_color(TEXT_COLOR)
|
||||||
|
.label_font_size(17)
|
||||||
|
.set(self.ids.menu_button_4, ui_widgets)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
events.push(Event::Logout);
|
||||||
|
};
|
||||||
|
// Quit
|
||||||
|
if Button::image(self.imgs.button_dark)
|
||||||
|
.mid_top_with_margin_on(self.ids.esc_bg, 355.0)
|
||||||
|
.w_h(170.0, 50.0)
|
||||||
|
.hover_image(self.imgs.button_dark_hover)
|
||||||
|
.press_image(self.imgs.button_dark_press)
|
||||||
|
.label("Quit")
|
||||||
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
||||||
|
.label_color(TEXT_COLOR)
|
||||||
|
.label_font_size(17)
|
||||||
|
.set(self.ids.menu_button_5, ui_widgets)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
events.push(Event::Quit);
|
||||||
|
};
|
||||||
|
}
|
8
voxygen/src/hud/font_ids.rs
Normal file
8
voxygen/src/hud/font_ids.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
use conrod_core::text::Font;
|
||||||
|
|
||||||
|
font_ids! {
|
||||||
|
pub struct Fonts {
|
||||||
|
opensans: "/voxygen/font/Metamorphous-Regular.ttf",
|
||||||
|
metamorph: "/voxygen/font/OpenSans-Regular.ttf",
|
||||||
|
}
|
||||||
|
}
|
@ -4,10 +4,10 @@ use conrod_core::{
|
|||||||
widget::{self, Button, Image, Rectangle, Text},
|
widget::{self, Button, Image, Rectangle, Text},
|
||||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
imgs::Imgs,
|
img_ids::Imgs,
|
||||||
WindowStyle, XP_COLOR,
|
font_ids::Fonts,
|
||||||
|
TEXT_COLOR,
|
||||||
};
|
};
|
||||||
|
|
||||||
widget_ids! {
|
widget_ids! {
|
||||||
@ -25,29 +25,22 @@ widget_ids! {
|
|||||||
#[derive(WidgetCommon)]
|
#[derive(WidgetCommon)]
|
||||||
pub struct Map<'a> {
|
pub struct Map<'a> {
|
||||||
imgs: &'a Imgs,
|
imgs: &'a Imgs,
|
||||||
|
fonts: &'a Fonts,
|
||||||
|
|
||||||
#[conrod(common_builder)]
|
#[conrod(common_builder)]
|
||||||
common: widget::CommonBuilder,
|
common: widget::CommonBuilder,
|
||||||
style: WindowStyle,
|
style: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Map<'a> {
|
impl<'a> Map<'a> {
|
||||||
pub fn new(imgs: &'a Imgs) -> Self {
|
pub fn new(imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
||||||
Self {
|
Self {
|
||||||
imgs,
|
imgs,
|
||||||
|
fonts,
|
||||||
common: widget::CommonBuilder::default(),
|
common: widget::CommonBuilder::default(),
|
||||||
style: WindowStyle::default(),
|
style: (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn font_id(mut self, font_id: font::Id) -> Self {
|
|
||||||
self.style.font_id = Some(Some(font_id));
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
builder_methods! {
|
|
||||||
pub text_color { style.text_color = Some(Color) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
@ -60,7 +53,7 @@ pub enum Event {
|
|||||||
|
|
||||||
impl<'a> Widget for Map<'a> {
|
impl<'a> Widget for Map<'a> {
|
||||||
type State = State;
|
type State = State;
|
||||||
type Style = WindowStyle;
|
type Style = ();
|
||||||
type Event = Option<Event>;
|
type Event = Option<Event>;
|
||||||
|
|
||||||
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||||
@ -70,7 +63,7 @@ impl<'a> Widget for Map<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn style(&self) -> Self::Style {
|
fn style(&self) -> Self::Style {
|
||||||
self.style.clone()
|
()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||||
@ -82,9 +75,6 @@ impl<'a> Widget for Map<'a> {
|
|||||||
..
|
..
|
||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
let font_id = style.font_id(&ui.theme).or(ui.fonts.ids().next());
|
|
||||||
let text_color = style.text_color(&ui.theme);
|
|
||||||
|
|
||||||
// BG
|
// BG
|
||||||
Image::new(self.imgs.map_bg)
|
Image::new(self.imgs.map_bg)
|
||||||
.w_h(824.0, 488.0)
|
.w_h(824.0, 488.0)
|
||||||
@ -124,7 +114,7 @@ impl<'a> Widget for Map<'a> {
|
|||||||
Text::new("Map")
|
Text::new("Map")
|
||||||
.mid_top_with_margin_on(state.ids.map_bg, -7.0)
|
.mid_top_with_margin_on(state.ids.map_bg, -7.0)
|
||||||
.font_size(50)
|
.font_size(50)
|
||||||
.color(text_color)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.map_title, ui);
|
.set(state.ids.map_title, ui);
|
||||||
|
|
||||||
None
|
None
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
mod chat;
|
mod chat;
|
||||||
mod character_window;
|
mod character_window;
|
||||||
mod map;
|
mod map;
|
||||||
mod imgs;
|
mod img_ids;
|
||||||
|
mod font_ids;
|
||||||
|
|
||||||
use character_window::CharacterWindow;
|
use character_window::CharacterWindow;
|
||||||
use map::Map;
|
use map::Map;
|
||||||
use imgs::Imgs;
|
use img_ids::Imgs;
|
||||||
|
use font_ids::Fonts;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
render::Renderer,
|
render::Renderer,
|
||||||
@ -16,35 +18,16 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
color,
|
color,
|
||||||
text::font::Id as FontId,
|
text::{Font, font::Id as FontId},
|
||||||
widget::{Button, Image, Rectangle, Scrollbar, Text},
|
widget::{Button, Image, Rectangle, Scrollbar, Text},
|
||||||
WidgetStyle, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
|
WidgetStyle, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
|
||||||
};
|
};
|
||||||
use common::assets;
|
use common::assets;
|
||||||
|
|
||||||
// TODO: Use styles?
|
const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0);
|
||||||
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0);
|
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0);
|
||||||
const HP_COLOR: Color = Color::Rgba(0.33, 0.63, 0.0, 1.0);
|
const HP_COLOR: Color = Color::Rgba(0.33, 0.63, 0.0, 1.0);
|
||||||
const MANA_COLOR: Color = Color::Rgba(0.42, 0.41, 0.66, 1.0);
|
const MANA_COLOR: Color = Color::Rgba(0.42, 0.41, 0.66, 1.0);
|
||||||
const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0);
|
|
||||||
|
|
||||||
|
|
||||||
/// Styling for windows
|
|
||||||
#[derive(Copy, Clone, Debug, Default, PartialEq, WidgetStyle)]
|
|
||||||
pub struct WindowStyle {
|
|
||||||
/// Color of the text in the window
|
|
||||||
#[conrod(default = "theme.label_color")]
|
|
||||||
pub text_color: Option<conrod_core::Color>,
|
|
||||||
/// Specify a unique font for text in the window
|
|
||||||
#[conrod(default = "theme.font_id")]
|
|
||||||
pub font_id: Option<Option<FontId>>,
|
|
||||||
// Color of the button.
|
|
||||||
//#[conrod(default = "theme.shape_color")]
|
|
||||||
//pub color: Option<conrod_core::Color>,
|
|
||||||
// Font size of the button's label.
|
|
||||||
//#[conrod(default = "theme.font_size_medium")]
|
|
||||||
//pub label_font_size: Option<conrod_core::FontSize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
widget_ids! {
|
widget_ids! {
|
||||||
struct Ids {
|
struct Ids {
|
||||||
@ -217,9 +200,8 @@ pub struct Hud {
|
|||||||
ui: Ui,
|
ui: Ui,
|
||||||
ids: Ids,
|
ids: Ids,
|
||||||
imgs: Imgs,
|
imgs: Imgs,
|
||||||
|
fonts: Fonts,
|
||||||
chat: chat::Chat,
|
chat: chat::Chat,
|
||||||
font_metamorph: FontId,
|
|
||||||
font_opensans: FontId,
|
|
||||||
show_help: bool,
|
show_help: bool,
|
||||||
show_debug: bool,
|
show_debug: bool,
|
||||||
bag_open: bool,
|
bag_open: bool,
|
||||||
@ -245,26 +227,17 @@ impl Hud {
|
|||||||
// Generate ids
|
// Generate ids
|
||||||
let ids = Ids::new(ui.id_generator());
|
let ids = Ids::new(ui.id_generator());
|
||||||
// Load images
|
// Load images
|
||||||
let imgs = Imgs::load(&mut ui).unwrap();
|
let imgs = Imgs::load(&mut ui).expect("Failed to load images");
|
||||||
// Load fonts
|
// Load fonts
|
||||||
let load_font = |filename, ui: &mut Ui| {
|
dbg!("Loading fonts...");
|
||||||
let fullpath: String = ["/voxygen/font", filename].concat();
|
let fonts = Fonts::load(&mut ui).expect("Failed to load fonts");
|
||||||
// TODO: use Asset trait to load font
|
|
||||||
ui.new_font(
|
|
||||||
conrod_core::text::Font::from_bytes(
|
|
||||||
assets::load_from_path(fullpath.as_str()).expect("Error loading file")
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui);
|
|
||||||
let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui);
|
|
||||||
// Chat box
|
// Chat box
|
||||||
let chat = chat::Chat::new(&mut ui);
|
let chat = chat::Chat::new(&mut ui);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
ui,
|
ui,
|
||||||
imgs,
|
imgs,
|
||||||
|
fonts,
|
||||||
ids,
|
ids,
|
||||||
chat,
|
chat,
|
||||||
settings_tab: SettingsTab::Interface,
|
settings_tab: SettingsTab::Interface,
|
||||||
@ -278,8 +251,6 @@ impl Hud {
|
|||||||
inventorytest_button: false,
|
inventorytest_button: false,
|
||||||
inventory_space: 0,
|
inventory_space: 0,
|
||||||
open_windows: Windows::None,
|
open_windows: Windows::None,
|
||||||
font_metamorph,
|
|
||||||
font_opensans,
|
|
||||||
xp_percentage: 0.4,
|
xp_percentage: 0.4,
|
||||||
hp_percentage: 1.0,
|
hp_percentage: 1.0,
|
||||||
mana_percentage: 1.0,
|
mana_percentage: 1.0,
|
||||||
@ -309,7 +280,7 @@ impl Hud {
|
|||||||
Text::new(&format!("FPS: {:.1}", tps))
|
Text::new(&format!("FPS: {:.1}", tps))
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.down_from(self.ids.version, 5.0)
|
.down_from(self.ids.version, 5.0)
|
||||||
.font_id(self.font_opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(14)
|
.font_size(14)
|
||||||
.set(self.ids.fps_counter, ui_widgets);
|
.set(self.ids.fps_counter, ui_widgets);
|
||||||
}
|
}
|
||||||
@ -333,7 +304,7 @@ impl Hud {
|
|||||||
// Chat box
|
// Chat box
|
||||||
if let Some(msg) = self
|
if let Some(msg) = self
|
||||||
.chat
|
.chat
|
||||||
.update_layout(ui_widgets, self.font_opensans, &self.imgs)
|
.update_layout(ui_widgets, &self.imgs, &self.fonts)
|
||||||
{
|
{
|
||||||
events.push(Event::SendMessage(msg));
|
events.push(Event::SendMessage(msg));
|
||||||
}
|
}
|
||||||
@ -347,7 +318,7 @@ impl Hud {
|
|||||||
Text::new(get_help_text(&self.settings.controls).as_str())
|
Text::new(get_help_text(&self.settings.controls).as_str())
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.top_left_with_margins_on(self.ids.help_bg, 20.0, 20.0)
|
.top_left_with_margins_on(self.ids.help_bg, 20.0, 20.0)
|
||||||
.font_id(self.font_opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(18)
|
.font_size(18)
|
||||||
.set(self.ids.help, ui_widgets);
|
.set(self.ids.help, ui_widgets);
|
||||||
// X-button
|
// X-button
|
||||||
@ -852,7 +823,7 @@ impl Hud {
|
|||||||
Text::new("Show Help")
|
Text::new("Show Help")
|
||||||
.right_from(self.ids.button_help, 10.0)
|
.right_from(self.ids.button_help, 10.0)
|
||||||
.font_size(14)
|
.font_size(14)
|
||||||
.font_id(self.font_opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.graphics_for(self.ids.button_help)
|
.graphics_for(self.ids.button_help)
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.set(self.ids.show_help_label, ui_widgets);
|
.set(self.ids.show_help_label, ui_widgets);
|
||||||
@ -871,7 +842,7 @@ impl Hud {
|
|||||||
Text::new("Show Inventory Test Button")
|
Text::new("Show Inventory Test Button")
|
||||||
.right_from(self.ids.inventorytest_button, 10.0)
|
.right_from(self.ids.inventorytest_button, 10.0)
|
||||||
.font_size(14)
|
.font_size(14)
|
||||||
.font_id(self.font_opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.graphics_for(self.ids.inventorytest_button)
|
.graphics_for(self.ids.inventorytest_button)
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.set(self.ids.inventorytest_button_label, ui_widgets);
|
.set(self.ids.inventorytest_button_label, ui_widgets);
|
||||||
@ -887,7 +858,7 @@ impl Hud {
|
|||||||
Text::new("Show Debug Window")
|
Text::new("Show Debug Window")
|
||||||
.right_from(self.ids.debug_button, 10.0)
|
.right_from(self.ids.debug_button, 10.0)
|
||||||
.font_size(14)
|
.font_size(14)
|
||||||
.font_id(self.font_opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.graphics_for(self.ids.debug_button)
|
.graphics_for(self.ids.debug_button)
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.set(self.ids.debug_button_label, ui_widgets);
|
.set(self.ids.debug_button_label, ui_widgets);
|
||||||
@ -1181,7 +1152,7 @@ impl Hud {
|
|||||||
// Title
|
// Title
|
||||||
Text::new("Social")
|
Text::new("Social")
|
||||||
.mid_top_with_margin_on(self.ids.social_frame, 17.0)
|
.mid_top_with_margin_on(self.ids.social_frame, 17.0)
|
||||||
.font_id(self.font_metamorph)
|
.font_id(self.fonts.metamorph)
|
||||||
.font_size(14)
|
.font_size(14)
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.set(self.ids.social_title, ui_widgets);
|
.set(self.ids.social_title, ui_widgets);
|
||||||
@ -1286,10 +1257,9 @@ impl Hud {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Character Window
|
||||||
if let Windows::CharacterAnd(small) = self.open_windows {
|
if let Windows::CharacterAnd(small) = self.open_windows {
|
||||||
match CharacterWindow::new(&self.imgs)
|
match CharacterWindow::new(&self.imgs, &self.fonts)
|
||||||
.font_id(self.font_opensans)
|
|
||||||
.text_color(TEXT_COLOR)
|
|
||||||
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
|
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
|
||||||
.w_h(103.0 * 4.0, 122.0 * 4.0) // TODO: replace this with default_width() / height() overrides
|
.w_h(103.0 * 4.0, 122.0 * 4.0) // TODO: replace this with default_width() / height() overrides
|
||||||
.set(self.ids.character_window, ui_widgets)
|
.set(self.ids.character_window, ui_widgets)
|
||||||
@ -1302,10 +1272,9 @@ impl Hud {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2 Map
|
// Map
|
||||||
if self.map_open {
|
if self.map_open {
|
||||||
match Map::new(&self.imgs)
|
match Map::new(&self.imgs, &self.fonts)
|
||||||
.text_color(TEXT_COLOR)
|
|
||||||
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
|
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
|
||||||
.set(self.ids.map, ui_widgets)
|
.set(self.ids.map, ui_widgets)
|
||||||
{
|
{
|
||||||
@ -1316,96 +1285,6 @@ impl Hud {
|
|||||||
|
|
||||||
// ESC-MENU
|
// ESC-MENU
|
||||||
// Background
|
// Background
|
||||||
if self.menu_open {
|
|
||||||
Image::new(self.imgs.esc_bg)
|
|
||||||
.w_h(228.0, 450.0)
|
|
||||||
.middle_of(ui_widgets.window)
|
|
||||||
.set(self.ids.esc_bg, ui_widgets);
|
|
||||||
|
|
||||||
Image::new(self.imgs.fireplace)
|
|
||||||
.w_h(180.0, 60.0)
|
|
||||||
.mid_top_with_margin_on(self.ids.esc_bg, 50.0)
|
|
||||||
.set(self.ids.fireplace, ui_widgets);
|
|
||||||
|
|
||||||
// Settings
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.mid_top_with_margin_on(self.ids.esc_bg, 115.0)
|
|
||||||
.w_h(170.0, 50.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label("Settings")
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_size(17)
|
|
||||||
.set(self.ids.menu_button_1, ui_widgets)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
self.menu_open = false;
|
|
||||||
self.open_windows = Windows::Settings;
|
|
||||||
};
|
|
||||||
// Controls
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.mid_top_with_margin_on(self.ids.esc_bg, 175.0)
|
|
||||||
.w_h(170.0, 50.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label("Controls")
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_size(17)
|
|
||||||
.set(self.ids.menu_button_2, ui_widgets)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
self.menu_open = false;
|
|
||||||
self.settings_tab = SettingsTab::Controls;
|
|
||||||
self.open_windows = Windows::Settings;
|
|
||||||
};
|
|
||||||
// Servers
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.mid_top_with_margin_on(self.ids.esc_bg, 235.0)
|
|
||||||
.w_h(170.0, 50.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label("Servers")
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_size(17)
|
|
||||||
.set(self.ids.menu_button_3, ui_widgets)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
//self.menu_open = false;
|
|
||||||
};
|
|
||||||
// Logout
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.mid_top_with_margin_on(self.ids.esc_bg, 295.0)
|
|
||||||
.w_h(170.0, 50.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label("Logout")
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_size(17)
|
|
||||||
.set(self.ids.menu_button_4, ui_widgets)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
events.push(Event::Logout);
|
|
||||||
};
|
|
||||||
// Quit
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.mid_top_with_margin_on(self.ids.esc_bg, 355.0)
|
|
||||||
.w_h(170.0, 50.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label("Quit")
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_size(17)
|
|
||||||
.set(self.ids.menu_button_5, ui_widgets)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
events.push(Event::Quit);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
events
|
events
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
use crate::{
|
use crate::{
|
||||||
render::Renderer,
|
render::Renderer,
|
||||||
ui::{self, Graphic, ScaleMode, Ui},
|
ui::{self, Graphic, ScaleMode, Ui},
|
||||||
@ -373,10 +374,10 @@ 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(conrod_core::text::Font::from_bytes(
|
ui.new_font(Arc::new(conrod_core::text::Font::from_bytes(
|
||||||
assets::load_from_path(fullpath.as_str())
|
assets::load_from_path(fullpath.as_str())
|
||||||
.expect("Error loading file")
|
.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);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
use crate::{
|
use crate::{
|
||||||
render::Renderer,
|
render::Renderer,
|
||||||
ui::{self, Graphic, ScaleMode, Ui},
|
ui::{self, Graphic, ScaleMode, Ui},
|
||||||
@ -128,11 +129,11 @@ impl MainMenuUi {
|
|||||||
// 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(
|
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);
|
||||||
|
30
voxygen/src/ui/font_ids.rs
Normal file
30
voxygen/src/ui/font_ids.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/// This macro will automatically load all specified assets, get the corresponding FontIds and
|
||||||
|
/// create a struct with all of them
|
||||||
|
///
|
||||||
|
/// Example usage:
|
||||||
|
/// ```
|
||||||
|
/// image_ids! {
|
||||||
|
/// pub struct Imgs {
|
||||||
|
/// font1: "filename1.vox",
|
||||||
|
/// font2: "filename2.vox",
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! font_ids {
|
||||||
|
($($v:vis struct $Ids:ident { $( $name:ident: $specifier:expr $(,)? )* })*) => {
|
||||||
|
$(
|
||||||
|
$v struct $Ids {
|
||||||
|
$( $v $name: conrod_core::text::font::Id, )*
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $Ids {
|
||||||
|
pub fn load(ui: &mut crate::ui::Ui) -> Result<Self, common::assets::Error> {
|
||||||
|
Ok(Self {
|
||||||
|
$( $name: ui.new_font(common::assets::load($specifier)?), )*
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
};
|
||||||
|
}
|
@ -49,7 +49,6 @@ impl<'a> GraphicCreator<'a> for VoxelGraphic {
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
// TODO: will this work with shorter name paths? eg not rate::ui::Graphic::
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! image_ids {
|
macro_rules! image_ids {
|
||||||
($($v:vis struct $Ids:ident { $( <$T:ty> $( $name:ident: $specifier:expr ),* $(,)? )* })*) => {
|
($($v:vis struct $Ids:ident { $( <$T:ty> $( $name:ident: $specifier:expr ),* $(,)? )* })*) => {
|
||||||
@ -68,4 +67,4 @@ macro_rules! image_ids {
|
|||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
mod graphic;
|
mod graphic;
|
||||||
mod util;
|
mod util;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
#[macro_use]
|
#[macro_use] mod img_ids;
|
||||||
mod img_ids;
|
#[macro_use] mod font_ids;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
pub use graphic::Graphic;
|
pub use graphic::Graphic;
|
||||||
pub use widgets::toggle_button::ToggleButton;
|
pub use widgets::toggle_button::ToggleButton;
|
||||||
pub use img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic, GraphicCreator};
|
pub use img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic, GraphicCreator};
|
||||||
pub(self) use util::{srgb_to_linear, linear_to_srgb};
|
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,
|
||||||
@ -254,8 +254,8 @@ impl Ui {
|
|||||||
self.image_map.insert(self.cache.add_graphic(graphic))
|
self.image_map.insert(self.cache.add_graphic(graphic))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_font(&mut self, font: Font) -> FontId {
|
pub fn new_font(&mut self, mut font: Arc<Font>) -> FontId {
|
||||||
self.ui.fonts.insert(font)
|
self.ui.fonts.insert(Arc::make_mut(&mut font).clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id_generator(&mut self) -> Generator {
|
pub fn id_generator(&mut self) -> Generator {
|
||||||
|
Loading…
Reference in New Issue
Block a user