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"
|
||||
dependencies = [
|
||||
"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)",
|
||||
"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)",
|
||||
|
@ -9,6 +9,7 @@ sphynx = { git = "https://gitlab.com/veloren/sphynx.git", features = ["serde1"]
|
||||
|
||||
specs = { version = "0.14", features = ["serde", "nightly"] }
|
||||
vek = { version = "0.9", features = ["serde"] }
|
||||
conrod_core = { git = "https://gitlab.com/veloren/conrod.git" }
|
||||
dot_vox = "4.0"
|
||||
image = "0.21"
|
||||
threadpool = "1.7"
|
||||
|
@ -1,5 +1,6 @@
|
||||
use dot_vox::DotVoxData;
|
||||
use image::DynamicImage;
|
||||
use conrod_core::text::Font;
|
||||
use lazy_static::lazy_static;
|
||||
use std::{
|
||||
any::Any,
|
||||
@ -41,7 +42,7 @@ lazy_static! {
|
||||
/// use image::DynamicImage;
|
||||
/// 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> {
|
||||
Ok(ASSETS
|
||||
@ -60,7 +61,7 @@ pub fn load<A: Asset + 'static>(specifier: &str) -> Result<Arc<A>, Error> {
|
||||
/// use image::DynamicImage;
|
||||
/// 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> {
|
||||
load(specifier)
|
||||
@ -75,8 +76,8 @@ pub trait Asset: Send + Sync + Sized {
|
||||
impl Asset for DynamicImage {
|
||||
fn load(specifier: &str) -> Result<Self, Error> {
|
||||
Ok(image::load_from_memory(
|
||||
load_from_path(specifier)?.as_slice()
|
||||
)
|
||||
load_from_path(specifier)?.as_slice()
|
||||
)
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
@ -85,15 +86,24 @@ impl Asset for DynamicImage {
|
||||
impl Asset for DotVoxData {
|
||||
fn load(specifier: &str) -> Result<Self, Error> {
|
||||
Ok(dot_vox::load_bytes(
|
||||
load_from_path(specifier)?.as_slice()
|
||||
)
|
||||
load_from_path(specifier)?.as_slice()
|
||||
)
|
||||
.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")
|
||||
fn try_open_with_path(name: &str) -> Option<File> {
|
||||
debug!("Trying to access \"{}\"", name);
|
||||
// TODO: don't do this?
|
||||
// if it's stupid and it works..,
|
||||
[
|
||||
|
@ -4,14 +4,15 @@ use conrod_core::{
|
||||
widget::{self, Button, Image, Rectangle, Text},
|
||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
|
||||
use super::{
|
||||
imgs::Imgs,
|
||||
WindowStyle, XP_COLOR,
|
||||
img_ids::Imgs,
|
||||
font_ids::Fonts,
|
||||
TEXT_COLOR,
|
||||
XP_COLOR,
|
||||
};
|
||||
|
||||
widget_ids! {
|
||||
struct Ids {
|
||||
pub struct Ids {
|
||||
charwindow,
|
||||
charwindow_bg,
|
||||
charwindow_close,
|
||||
@ -35,32 +36,23 @@ widget_ids! {
|
||||
pub struct CharacterWindow<'a> {
|
||||
xp_percentage: f64,
|
||||
imgs: &'a Imgs,
|
||||
fonts: &'a Fonts,
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: WindowStyle,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> CharacterWindow<'a> {
|
||||
pub fn new(imgs: &'a Imgs) -> Self {
|
||||
pub fn new(imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
||||
Self {
|
||||
xp_percentage: 0.4,
|
||||
imgs,
|
||||
fonts,
|
||||
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 {
|
||||
@ -68,18 +60,16 @@ pub enum Event {
|
||||
}
|
||||
|
||||
impl<'a> Widget for CharacterWindow<'a> {
|
||||
type State = State;
|
||||
type Style = WindowStyle;
|
||||
type State = Ids;
|
||||
type Style = ();
|
||||
type Event = Option<Event>;
|
||||
|
||||
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||
State {
|
||||
ids: Ids::new(id_gen),
|
||||
}
|
||||
Ids::new(id_gen)
|
||||
}
|
||||
|
||||
fn style(&self) -> Self::Style {
|
||||
self.style.clone()
|
||||
()
|
||||
}
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
@ -91,99 +81,95 @@ impl<'a> Widget for CharacterWindow<'a> {
|
||||
..
|
||||
} = args;
|
||||
|
||||
let font_id = style.font_id(&ui.theme).or(ui.fonts.ids().next());
|
||||
let text_color = style.text_color(&ui.theme);
|
||||
|
||||
// Frame
|
||||
Image::new(self.imgs.window_frame)
|
||||
.middle_of(id)
|
||||
.set(state.ids.charwindow_frame, ui);
|
||||
.set(state.charwindow_frame, ui);
|
||||
|
||||
// BG
|
||||
Image::new(self.imgs.window_bg)
|
||||
.w_h(348.0, 404.0)
|
||||
.mid_top_with_margin_on(state.ids.charwindow_frame, 48.0)
|
||||
.set(state.ids.charwindow_bg, ui);
|
||||
.mid_top_with_margin_on(state.charwindow_frame, 48.0)
|
||||
.set(state.charwindow_bg, ui);
|
||||
|
||||
// Overlay
|
||||
Image::new(self.imgs.charwindow)
|
||||
.middle_of(state.ids.charwindow_bg)
|
||||
.set(state.ids.charwindow, ui);
|
||||
.middle_of(state.charwindow_bg)
|
||||
.set(state.charwindow, ui);
|
||||
|
||||
// Icon
|
||||
//Image::new(self.imgs.charwindow_icon)
|
||||
//.w_h(224.0 / 3.0, 224.0 / 3.0)
|
||||
//.top_left_with_margins_on(state.ids.charwindow_frame, -10.0, -10.0)
|
||||
//.set(state.ids.charwindow_icon, ui);
|
||||
//.top_left_with_margins_on(state.charwindow_frame, -10.0, -10.0)
|
||||
//.set(state.charwindow_icon, ui);
|
||||
|
||||
// X-Button
|
||||
if Button::image(self.imgs.close_button)
|
||||
.w_h(244.0 * 0.22 / 4.0, 244.0 * 0.22 / 4.0)
|
||||
.hover_image(self.imgs.close_button_hover)
|
||||
.press_image(self.imgs.close_button_press)
|
||||
.top_right_with_margins_on(state.ids.charwindow_frame, 4.0, 4.0)
|
||||
.set(state.ids.charwindow_close, ui)
|
||||
.top_right_with_margins_on(state.charwindow_frame, 4.0, 4.0)
|
||||
.set(state.charwindow_close, ui)
|
||||
.was_clicked() {
|
||||
return Some(Event::Close);
|
||||
}
|
||||
|
||||
// Title
|
||||
Text::new("Character Name") // Add in actual Character Name
|
||||
.mid_top_with_margin_on(state.ids.charwindow_frame, 7.0)
|
||||
.color(text_color)
|
||||
.set(state.ids.charwindow_title, ui);
|
||||
.mid_top_with_margin_on(state.charwindow_frame, 7.0)
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.charwindow_title, ui);
|
||||
|
||||
// Tab BG
|
||||
Image::new(self.imgs.charwindow_tab_bg)
|
||||
.w_h(205.0, 412.0)
|
||||
.mid_left_with_margin_on(state.ids.charwindow_frame, -205.0)
|
||||
.set(state.ids.charwindow_tab_bg, ui);
|
||||
.mid_left_with_margin_on(state.charwindow_frame, -205.0)
|
||||
.set(state.charwindow_tab_bg, ui);
|
||||
|
||||
// Tab Rectangle
|
||||
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)
|
||||
.set(state.ids.charwindow_rectangle, ui);
|
||||
.top_right_with_margins_on(state.charwindow_tab_bg, 20.0, 0.0)
|
||||
.set(state.charwindow_rectangle, ui);
|
||||
|
||||
// Tab Button
|
||||
Button::image(self.imgs.charwindow_tab)
|
||||
.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_color(text_color)
|
||||
.and_then(font_id, Button::label_font_id)
|
||||
.label_color(TEXT_COLOR)
|
||||
.label_font_size(14)
|
||||
.set(state.ids.charwindow_tab1, ui);
|
||||
.set(state.charwindow_tab1, ui);
|
||||
|
||||
Text::new("1") //Add in actual Character Level
|
||||
.mid_top_with_margin_on(state.ids.charwindow_rectangle, 10.0)
|
||||
.and_then(font_id, Text::font_id)
|
||||
.mid_top_with_margin_on(state.charwindow_rectangle, 10.0)
|
||||
.font_id(self.fonts.opensans)
|
||||
.font_size(30)
|
||||
.color(text_color)
|
||||
.set(state.ids.charwindow_tab1_level, ui);
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.charwindow_tab1_level, ui);
|
||||
|
||||
// Exp-Bar Background
|
||||
Rectangle::fill_with([170.0, 10.0], color::BLACK)
|
||||
.mid_top_with_margin_on(state.ids.charwindow_rectangle, 50.0)
|
||||
.set(state.ids.charwindow_exp_rectangle, ui);
|
||||
.mid_top_with_margin_on(state.charwindow_rectangle, 50.0)
|
||||
.set(state.charwindow_exp_rectangle, ui);
|
||||
|
||||
// Exp-Bar Progress
|
||||
Rectangle::fill_with([170.0 * (self.xp_percentage), 6.0], XP_COLOR) // 0.8 = Experience percantage
|
||||
.mid_left_with_margin_on(state.ids.charwindow_tab1_expbar, 1.0)
|
||||
.set(state.ids.charwindow_exp_progress_rectangle, ui);
|
||||
Rectangle::fill_with([170.0 * (self.xp_percentage), 6.0], XP_COLOR) // 0.8 = Experience percentage
|
||||
.mid_left_with_margin_on(state.charwindow_tab1_expbar, 1.0)
|
||||
.set(state.charwindow_exp_progress_rectangle, ui);
|
||||
|
||||
// Exp-Bar Foreground Frame
|
||||
Image::new(self.imgs.progress_frame)
|
||||
.w_h(170.0, 10.0)
|
||||
.middle_of(state.ids.charwindow_exp_rectangle)
|
||||
.set(state.ids.charwindow_tab1_expbar, ui);
|
||||
.middle_of(state.charwindow_exp_rectangle)
|
||||
.set(state.charwindow_tab1_expbar, ui);
|
||||
|
||||
// Exp-Text
|
||||
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)
|
||||
.and_then(font_id, Text::font_id)
|
||||
.mid_top_with_margin_on(state.charwindow_tab1_expbar, 10.0)
|
||||
.font_id(self.fonts.opensans)
|
||||
.font_size(15)
|
||||
.color(text_color)
|
||||
.set(state.ids.charwindow_tab1_exp, ui);
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.charwindow_tab1_exp, ui);
|
||||
|
||||
// Stats
|
||||
Text::new(
|
||||
@ -195,11 +181,11 @@ impl<'a> Widget for CharacterWindow<'a> {
|
||||
\n\
|
||||
Intelligence",
|
||||
)
|
||||
.top_left_with_margins_on(state.ids.charwindow_rectangle, 100.0, 20.0)
|
||||
.and_then(font_id, Text::font_id)
|
||||
.top_left_with_margins_on(state.charwindow_rectangle, 100.0, 20.0)
|
||||
.font_id(self.fonts.opensans)
|
||||
.font_size(16)
|
||||
.color(text_color)
|
||||
.set(state.ids.charwindow_tab1_statnames, ui);
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.charwindow_tab1_statnames, ui);
|
||||
|
||||
Text::new(
|
||||
"1234\n\
|
||||
@ -210,11 +196,11 @@ impl<'a> Widget for CharacterWindow<'a> {
|
||||
\n\
|
||||
124124",
|
||||
)
|
||||
.right_from(state.ids.charwindow_tab1_statnames, 10.0)
|
||||
.and_then(font_id, Text::font_id)
|
||||
.right_from(state.charwindow_tab1_statnames, 10.0)
|
||||
.font_id(self.fonts.opensans)
|
||||
.font_size(16)
|
||||
.color(text_color)
|
||||
.set(state.ids.charwindow_tab1_stats, ui);
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.charwindow_tab1_stats, ui);
|
||||
|
||||
None
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
use crate::ui::Ui;
|
||||
use super::img_ids::Imgs;
|
||||
use super::font_ids::Fonts;
|
||||
use conrod_core::{
|
||||
color,
|
||||
input::Key,
|
||||
@ -74,8 +76,8 @@ impl Chat {
|
||||
pub(super) fn update_layout(
|
||||
&mut self,
|
||||
ui_widgets: &mut UiCell,
|
||||
font: FontId,
|
||||
imgs: &super::Imgs,
|
||||
imgs: &Imgs,
|
||||
fonts: &Fonts,
|
||||
) -> Option<String> {
|
||||
// Maintain scrolling
|
||||
if self.new_messages {
|
||||
@ -96,7 +98,7 @@ impl Chat {
|
||||
.restrict_to_height(false)
|
||||
.line_spacing(2.0)
|
||||
.font_size(15)
|
||||
.font_id(font);
|
||||
.font_id(fonts.opensans);
|
||||
let y = match text_edit.get_y_dimension(ui_widgets) {
|
||||
Dimension::Absolute(y) => y + 6.0,
|
||||
_ => 0.0,
|
||||
@ -136,7 +138,7 @@ impl Chat {
|
||||
let widget = if item.i < self.messages.len() {
|
||||
let text = Text::new(&self.messages[item.i])
|
||||
.font_size(15)
|
||||
.font_id(font)
|
||||
.font_id(fonts.opensans)
|
||||
.w(470.0)
|
||||
.rgba(1.0, 1.0, 1.0, 1.0)
|
||||
.line_spacing(2.0);
|
||||
@ -149,7 +151,7 @@ impl Chat {
|
||||
} else {
|
||||
// Spacer at bottom of the last message so that it is not cut off
|
||||
// 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);
|
||||
}
|
||||
|
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_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
|
||||
use super::{
|
||||
imgs::Imgs,
|
||||
WindowStyle, XP_COLOR,
|
||||
img_ids::Imgs,
|
||||
font_ids::Fonts,
|
||||
TEXT_COLOR,
|
||||
};
|
||||
|
||||
widget_ids! {
|
||||
@ -25,29 +25,22 @@ widget_ids! {
|
||||
#[derive(WidgetCommon)]
|
||||
pub struct Map<'a> {
|
||||
imgs: &'a Imgs,
|
||||
fonts: &'a Fonts,
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: WindowStyle,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> Map<'a> {
|
||||
pub fn new(imgs: &'a Imgs) -> Self {
|
||||
pub fn new(imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
||||
Self {
|
||||
imgs,
|
||||
fonts,
|
||||
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 {
|
||||
@ -60,7 +53,7 @@ pub enum Event {
|
||||
|
||||
impl<'a> Widget for Map<'a> {
|
||||
type State = State;
|
||||
type Style = WindowStyle;
|
||||
type Style = ();
|
||||
type Event = Option<Event>;
|
||||
|
||||
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 {
|
||||
self.style.clone()
|
||||
()
|
||||
}
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
@ -82,9 +75,6 @@ impl<'a> Widget for Map<'a> {
|
||||
..
|
||||
} = args;
|
||||
|
||||
let font_id = style.font_id(&ui.theme).or(ui.fonts.ids().next());
|
||||
let text_color = style.text_color(&ui.theme);
|
||||
|
||||
// BG
|
||||
Image::new(self.imgs.map_bg)
|
||||
.w_h(824.0, 488.0)
|
||||
@ -124,7 +114,7 @@ impl<'a> Widget for Map<'a> {
|
||||
Text::new("Map")
|
||||
.mid_top_with_margin_on(state.ids.map_bg, -7.0)
|
||||
.font_size(50)
|
||||
.color(text_color)
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.map_title, ui);
|
||||
|
||||
None
|
||||
|
@ -1,11 +1,13 @@
|
||||
mod chat;
|
||||
mod character_window;
|
||||
mod map;
|
||||
mod imgs;
|
||||
mod img_ids;
|
||||
mod font_ids;
|
||||
|
||||
use character_window::CharacterWindow;
|
||||
use map::Map;
|
||||
use imgs::Imgs;
|
||||
use img_ids::Imgs;
|
||||
use font_ids::Fonts;
|
||||
|
||||
use crate::{
|
||||
render::Renderer,
|
||||
@ -16,35 +18,16 @@ use crate::{
|
||||
};
|
||||
use conrod_core::{
|
||||
color,
|
||||
text::font::Id as FontId,
|
||||
text::{Font, font::Id as FontId},
|
||||
widget::{Button, Image, Rectangle, Scrollbar, Text},
|
||||
WidgetStyle, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
|
||||
};
|
||||
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 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 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! {
|
||||
struct Ids {
|
||||
@ -217,9 +200,8 @@ pub struct Hud {
|
||||
ui: Ui,
|
||||
ids: Ids,
|
||||
imgs: Imgs,
|
||||
fonts: Fonts,
|
||||
chat: chat::Chat,
|
||||
font_metamorph: FontId,
|
||||
font_opensans: FontId,
|
||||
show_help: bool,
|
||||
show_debug: bool,
|
||||
bag_open: bool,
|
||||
@ -245,26 +227,17 @@ impl Hud {
|
||||
// Generate ids
|
||||
let ids = Ids::new(ui.id_generator());
|
||||
// Load images
|
||||
let imgs = Imgs::load(&mut ui).unwrap();
|
||||
let imgs = Imgs::load(&mut ui).expect("Failed to load images");
|
||||
// Load fonts
|
||||
let load_font = |filename, ui: &mut Ui| {
|
||||
let fullpath: String = ["/voxygen/font", filename].concat();
|
||||
// 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);
|
||||
dbg!("Loading fonts...");
|
||||
let fonts = Fonts::load(&mut ui).expect("Failed to load fonts");
|
||||
// Chat box
|
||||
let chat = chat::Chat::new(&mut ui);
|
||||
|
||||
Self {
|
||||
ui,
|
||||
imgs,
|
||||
fonts,
|
||||
ids,
|
||||
chat,
|
||||
settings_tab: SettingsTab::Interface,
|
||||
@ -278,8 +251,6 @@ impl Hud {
|
||||
inventorytest_button: false,
|
||||
inventory_space: 0,
|
||||
open_windows: Windows::None,
|
||||
font_metamorph,
|
||||
font_opensans,
|
||||
xp_percentage: 0.4,
|
||||
hp_percentage: 1.0,
|
||||
mana_percentage: 1.0,
|
||||
@ -309,7 +280,7 @@ impl Hud {
|
||||
Text::new(&format!("FPS: {:.1}", tps))
|
||||
.color(TEXT_COLOR)
|
||||
.down_from(self.ids.version, 5.0)
|
||||
.font_id(self.font_opensans)
|
||||
.font_id(self.fonts.opensans)
|
||||
.font_size(14)
|
||||
.set(self.ids.fps_counter, ui_widgets);
|
||||
}
|
||||
@ -333,7 +304,7 @@ impl Hud {
|
||||
// Chat box
|
||||
if let Some(msg) = self
|
||||
.chat
|
||||
.update_layout(ui_widgets, self.font_opensans, &self.imgs)
|
||||
.update_layout(ui_widgets, &self.imgs, &self.fonts)
|
||||
{
|
||||
events.push(Event::SendMessage(msg));
|
||||
}
|
||||
@ -347,7 +318,7 @@ impl Hud {
|
||||
Text::new(get_help_text(&self.settings.controls).as_str())
|
||||
.color(TEXT_COLOR)
|
||||
.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)
|
||||
.set(self.ids.help, ui_widgets);
|
||||
// X-button
|
||||
@ -852,7 +823,7 @@ impl Hud {
|
||||
Text::new("Show Help")
|
||||
.right_from(self.ids.button_help, 10.0)
|
||||
.font_size(14)
|
||||
.font_id(self.font_opensans)
|
||||
.font_id(self.fonts.opensans)
|
||||
.graphics_for(self.ids.button_help)
|
||||
.color(TEXT_COLOR)
|
||||
.set(self.ids.show_help_label, ui_widgets);
|
||||
@ -871,7 +842,7 @@ impl Hud {
|
||||
Text::new("Show Inventory Test Button")
|
||||
.right_from(self.ids.inventorytest_button, 10.0)
|
||||
.font_size(14)
|
||||
.font_id(self.font_opensans)
|
||||
.font_id(self.fonts.opensans)
|
||||
.graphics_for(self.ids.inventorytest_button)
|
||||
.color(TEXT_COLOR)
|
||||
.set(self.ids.inventorytest_button_label, ui_widgets);
|
||||
@ -887,7 +858,7 @@ impl Hud {
|
||||
Text::new("Show Debug Window")
|
||||
.right_from(self.ids.debug_button, 10.0)
|
||||
.font_size(14)
|
||||
.font_id(self.font_opensans)
|
||||
.font_id(self.fonts.opensans)
|
||||
.graphics_for(self.ids.debug_button)
|
||||
.color(TEXT_COLOR)
|
||||
.set(self.ids.debug_button_label, ui_widgets);
|
||||
@ -1181,7 +1152,7 @@ impl Hud {
|
||||
// Title
|
||||
Text::new("Social")
|
||||
.mid_top_with_margin_on(self.ids.social_frame, 17.0)
|
||||
.font_id(self.font_metamorph)
|
||||
.font_id(self.fonts.metamorph)
|
||||
.font_size(14)
|
||||
.color(TEXT_COLOR)
|
||||
.set(self.ids.social_title, ui_widgets);
|
||||
@ -1286,10 +1257,9 @@ impl Hud {
|
||||
}
|
||||
}
|
||||
|
||||
// Character Window
|
||||
if let Windows::CharacterAnd(small) = self.open_windows {
|
||||
match CharacterWindow::new(&self.imgs)
|
||||
.font_id(self.font_opensans)
|
||||
.text_color(TEXT_COLOR)
|
||||
match CharacterWindow::new(&self.imgs, &self.fonts)
|
||||
.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
|
||||
.set(self.ids.character_window, ui_widgets)
|
||||
@ -1302,10 +1272,9 @@ impl Hud {
|
||||
}
|
||||
}
|
||||
|
||||
// 2 Map
|
||||
// Map
|
||||
if self.map_open {
|
||||
match Map::new(&self.imgs)
|
||||
.text_color(TEXT_COLOR)
|
||||
match Map::new(&self.imgs, &self.fonts)
|
||||
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
|
||||
.set(self.ids.map, ui_widgets)
|
||||
{
|
||||
@ -1316,96 +1285,6 @@ impl Hud {
|
||||
|
||||
// ESC-MENU
|
||||
// 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
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use crate::{
|
||||
render::Renderer,
|
||||
ui::{self, Graphic, ScaleMode, Ui},
|
||||
@ -373,10 +374,10 @@ impl CharSelectionUi {
|
||||
// Load fonts
|
||||
let load_font = |filename, ui: &mut Ui| {
|
||||
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())
|
||||
.expect("Error loading file")
|
||||
).unwrap())
|
||||
).unwrap()))
|
||||
};
|
||||
let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui);
|
||||
let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui);
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use crate::{
|
||||
render::Renderer,
|
||||
ui::{self, Graphic, ScaleMode, Ui},
|
||||
@ -128,11 +129,11 @@ impl MainMenuUi {
|
||||
// Load fonts
|
||||
let load_font = |filename, ui: &mut Ui| {
|
||||
let fullpath: String = ["/voxygen/font", filename].concat();
|
||||
ui.new_font(
|
||||
ui.new_font(Arc::new(
|
||||
conrod_core::text::Font::from_bytes(
|
||||
assets::load_from_path(fullpath.as_str()).expect("Error loading file")
|
||||
)
|
||||
.unwrap(),
|
||||
.unwrap()),
|
||||
)
|
||||
};
|
||||
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_rules! image_ids {
|
||||
($($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 util;
|
||||
mod widgets;
|
||||
#[macro_use]
|
||||
mod img_ids;
|
||||
#[macro_use] 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::{
|
||||
render::{
|
||||
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))
|
||||
}
|
||||
|
||||
pub fn new_font(&mut self, font: Font) -> FontId {
|
||||
self.ui.fonts.insert(font)
|
||||
pub fn new_font(&mut self, mut font: Arc<Font>) -> FontId {
|
||||
self.ui.fonts.insert(Arc::make_mut(&mut font).clone())
|
||||
}
|
||||
|
||||
pub fn id_generator(&mut self) -> Generator {
|
||||
|
Loading…
Reference in New Issue
Block a user