Move map into it's own file

Former-commit-id: 5a1b593e3d6b00dad3e3a4d462dfd48592537f64
This commit is contained in:
timokoesters 2019-04-30 16:39:19 +02:00 committed by Imbris
parent cb507ebfa0
commit e8aa680aad
3 changed files with 168 additions and 77 deletions

View File

@ -117,28 +117,33 @@ impl<'a> Widget for CharacterWindow<'a> {
//.set(state.ids.charwindow_icon, ui); //.set(state.ids.charwindow_icon, ui);
// X-Button // X-Button
let closed = 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.ids.charwindow_frame, 4.0, 4.0)
.set(state.ids.charwindow_close, ui) .set(state.ids.charwindow_close, ui)
.was_clicked(); .was_clicked() {
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.ids.charwindow_frame, 7.0)
.color(text_color) .color(text_color)
.set(state.ids.charwindow_title, ui); .set(state.ids.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.ids.charwindow_frame, -205.0)
.set(state.ids.charwindow_tab_bg, ui); .set(state.ids.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.ids.charwindow_tab_bg, 20.0, 0.0)
.set(state.ids.charwindow_rectangle, ui); .set(state.ids.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)
@ -148,25 +153,30 @@ impl<'a> Widget for CharacterWindow<'a> {
.and_then(font_id, Button::label_font_id) .and_then(font_id, Button::label_font_id)
.label_font_size(14) .label_font_size(14)
.set(state.ids.charwindow_tab1, ui); .set(state.ids.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.ids.charwindow_rectangle, 10.0)
.and_then(font_id, Text::font_id) .and_then(font_id, Text::font_id)
.font_size(30) .font_size(30)
.color(text_color) .color(text_color)
.set(state.ids.charwindow_tab1_level, ui); .set(state.ids.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.ids.charwindow_rectangle, 50.0)
.set(state.ids.charwindow_exp_rectangle, ui); .set(state.ids.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 percantage
.mid_left_with_margin_on(state.ids.charwindow_tab1_expbar, 1.0) .mid_left_with_margin_on(state.ids.charwindow_tab1_expbar, 1.0)
.set(state.ids.charwindow_exp_progress_rectangle, ui); .set(state.ids.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.ids.charwindow_exp_rectangle)
.set(state.ids.charwindow_tab1_expbar, ui); .set(state.ids.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.ids.charwindow_tab1_expbar, 10.0)
@ -206,10 +216,6 @@ impl<'a> Widget for CharacterWindow<'a> {
.color(text_color) .color(text_color)
.set(state.ids.charwindow_tab1_stats, ui); .set(state.ids.charwindow_tab1_stats, ui);
if closed {
Some(Event::Close)
} else {
None None
} }
} }
}

132
voxygen/src/hud/map.rs Normal file
View File

@ -0,0 +1,132 @@
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,
WindowStyle, XP_COLOR,
};
widget_ids! {
struct Ids {
map_bg,
map_close,
map_frame,
map_frame_l,
map_frame_r,
map_icon,
map_title,
}
}
#[derive(WidgetCommon)]
pub struct Map<'a> {
imgs: &'a Imgs,
#[conrod(common_builder)]
common: widget::CommonBuilder,
style: WindowStyle,
}
impl<'a> Map<'a> {
pub fn new(imgs: &'a Imgs) -> Self {
Self {
imgs,
common: widget::CommonBuilder::default(),
style: WindowStyle::default(),
}
}
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 {
Close,
}
impl<'a> Widget for Map<'a> {
type State = State;
type Style = WindowStyle;
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);
// BG
Image::new(self.imgs.map_bg)
.w_h(824.0, 488.0)
.middle_of(ui.window)
.set(state.ids.map_bg, ui);
// Frame
Image::new(self.imgs.map_frame_l)
.top_left_with_margins_on(state.ids.map_bg, 0.0, 0.0)
.w_h(412.0, 488.0)
.set(state.ids.map_frame_l, ui);
Image::new(self.imgs.map_frame_r)
.top_right_with_margins_on(state.ids.map_bg, 0.0, 0.0)
.w_h(1648.0 / 4.0, 1952.0 / 4.0)
.set(state.ids.map_frame_r, ui);
// Icon
Image::new(self.imgs.map_icon)
.w_h(224.0 / 3.0, 224.0 / 3.0)
.top_left_with_margins_on(state.ids.map_frame, -10.0, -10.0)
.set(state.ids.map_icon, ui);
// X-Button
if Button::image(self.imgs.close_button)
.w_h(4.0*2.0, 4.0*2.0)
.hover_image(self.imgs.close_button_hover)
.press_image(self.imgs.close_button_press)
.top_right_with_margins_on(state.ids.map_frame_r, 1.0, 1.0)
.set(state.ids.map_close, ui)
.was_clicked()
{
return Some(Event::Close);
}
// Title
Text::new("Map")
.mid_top_with_margin_on(state.ids.map_bg, -7.0)
.font_size(50)
.color(text_color)
.set(state.ids.map_title, ui);
None
}
}

View File

@ -1,8 +1,10 @@
mod chat; mod chat;
mod character_window; mod character_window;
mod map;
mod imgs; mod imgs;
use character_window::CharacterWindow; use character_window::CharacterWindow;
use map::Map;
use imgs::Imgs; use imgs::Imgs;
use crate::{ use crate::{
@ -161,17 +163,6 @@ widget_ids! {
social_close, social_close,
social_title, social_title,
// 2 Map
map_frame,
map_bg,
map_icon,
map_close,
map_title,
map_frame_l,
map_frame_r,
map_frame_bl,
map_frame_br,
// 3 Spellbook // 3 Spellbook
spellbook_frame, spellbook_frame,
spellbook_bg, spellbook_bg,
@ -179,15 +170,16 @@ widget_ids! {
spellbook_close, spellbook_close,
spellbook_title, spellbook_title,
// 4 Charwindow
character_window,
// 5 Quest-Log // 5 Quest-Log
questlog_frame, questlog_frame,
questlog_bg, questlog_bg,
questlog_icon, questlog_icon,
questlog_close, questlog_close,
questlog_title, questlog_title,
// External
map,
character_window,
} }
} }
@ -1306,59 +1298,20 @@ impl Hud {
Some(small) => Windows::Small(small), Some(small) => Windows::Small(small),
None => Windows::None, None => Windows::None,
}, },
None => (), None => {},
} }
} }
// 2 Map // 2 Map
if self.map_open { if self.map_open {
// BG match Map::new(&self.imgs)
Rectangle::fill_with([824.0, 976.0], color::TRANSPARENT) .text_color(TEXT_COLOR)
.mid_top_with_margin_on(ui_widgets.window, 15.0) .top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
.scroll_kids() .set(self.ids.map, ui_widgets)
.scroll_kids_vertically()
.set(self.ids.map_bg, ui_widgets);
// Frame
Image::new(self.imgs.map_frame_l)
.top_left_with_margins_on(self.ids.map_bg, 0.0, 0.0)
.w_h(412.0, 488.0)
.set(self.ids.map_frame_l, ui_widgets);
Image::new(self.imgs.map_frame_r)
.right_from(self.ids.map_frame_l, 0.0)
.w_h(412.0, 488.0)
.set(self.ids.map_frame_r, ui_widgets);
Image::new(self.imgs.map_frame_br)
.down_from(self.ids.map_frame_r, 0.0)
.w_h(412.0, 488.0)
.set(self.ids.map_frame_br, ui_widgets);
Image::new(self.imgs.map_frame_bl)
.down_from(self.ids.map_frame_l, 0.0)
.w_h(412.0, 488.0)
.set(self.ids.map_frame_bl, ui_widgets);
// Icon
Image::new(self.imgs.map_icon)
.w_h(224.0 / 3.0, 224.0 / 3.0)
.top_left_with_margins_on(self.ids.map_frame, -10.0, -10.0)
.set(self.ids.map_icon, ui_widgets);
// X-Button
if Button::image(self.imgs.close_button)
.w_h(28.0, 28.0)
.hover_image(self.imgs.close_button_hover)
.press_image(self.imgs.close_button_press)
.top_right_with_margins_on(self.ids.map_frame_r, 0.0, 0.0)
.set(self.ids.map_close, ui_widgets)
.was_clicked()
{ {
self.map_open = false; Some(map::Event::Close) => self.map_open = false,
None => {},
} }
// Title
//Text::new("Map")
//.mid_top_with_margin_on(self.ids.map_bg, -7.0)
//.font_size(14)
//.color(TEXT_COLOR)
//.set(self.ids.map_title, ui_widgets);
} }
// ESC-MENU // ESC-MENU