From e8aa680aadbd41799258f6f34ab0a1827436cacf Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 30 Apr 2019 16:39:19 +0200 Subject: [PATCH] Move map into it's own file Former-commit-id: 5a1b593e3d6b00dad3e3a4d462dfd48592537f64 --- voxygen/src/hud/character_window.rs | 40 +++++---- voxygen/src/hud/map.rs | 132 ++++++++++++++++++++++++++++ voxygen/src/hud/mod.rs | 73 +++------------ 3 files changed, 168 insertions(+), 77 deletions(-) create mode 100644 voxygen/src/hud/map.rs diff --git a/voxygen/src/hud/character_window.rs b/voxygen/src/hud/character_window.rs index d035fd1663..0717d82d4e 100644 --- a/voxygen/src/hud/character_window.rs +++ b/voxygen/src/hud/character_window.rs @@ -117,28 +117,33 @@ impl<'a> Widget for CharacterWindow<'a> { //.set(state.ids.charwindow_icon, ui); // 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) .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) - .was_clicked(); + .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); + // 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); + // 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); + // Tab Button Button::image(self.imgs.charwindow_tab) .w_h(65.0, 23.0) @@ -148,25 +153,30 @@ impl<'a> Widget for CharacterWindow<'a> { .and_then(font_id, Button::label_font_id) .label_font_size(14) .set(state.ids.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) .font_size(30) .color(text_color) .set(state.ids.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); + // 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); + // 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); + // 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) @@ -185,11 +195,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) - .font_size(16) - .color(text_color) - .set(state.ids.charwindow_tab1_statnames, ui); + .top_left_with_margins_on(state.ids.charwindow_rectangle, 100.0, 20.0) + .and_then(font_id, Text::font_id) + .font_size(16) + .color(text_color) + .set(state.ids.charwindow_tab1_statnames, ui); Text::new( "1234\n\ @@ -200,16 +210,12 @@ impl<'a> Widget for CharacterWindow<'a> { \n\ 124124", ) - .right_from(state.ids.charwindow_tab1_statnames, 10.0) - .and_then(font_id, Text::font_id) - .font_size(16) - .color(text_color) - .set(state.ids.charwindow_tab1_stats, ui); + .right_from(state.ids.charwindow_tab1_statnames, 10.0) + .and_then(font_id, Text::font_id) + .font_size(16) + .color(text_color) + .set(state.ids.charwindow_tab1_stats, ui); - if closed { - Some(Event::Close) - } else { - None - } + None } } diff --git a/voxygen/src/hud/map.rs b/voxygen/src/hud/map.rs new file mode 100644 index 0000000000..d27fc7c1a6 --- /dev/null +++ b/voxygen/src/hud/map.rs @@ -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; + + 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::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 + } +} diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index c903287962..5c74812d50 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -1,8 +1,10 @@ mod chat; mod character_window; +mod map; mod imgs; use character_window::CharacterWindow; +use map::Map; use imgs::Imgs; use crate::{ @@ -161,17 +163,6 @@ widget_ids! { social_close, 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 spellbook_frame, spellbook_bg, @@ -179,15 +170,16 @@ widget_ids! { spellbook_close, spellbook_title, - // 4 Charwindow - character_window, - // 5 Quest-Log questlog_frame, questlog_bg, questlog_icon, questlog_close, questlog_title, + + // External + map, + character_window, } } @@ -1306,59 +1298,20 @@ impl Hud { Some(small) => Windows::Small(small), None => Windows::None, }, - None => (), + None => {}, } } // 2 Map if self.map_open { - // BG - Rectangle::fill_with([824.0, 976.0], color::TRANSPARENT) - .mid_top_with_margin_on(ui_widgets.window, 15.0) - .scroll_kids() - .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() + match Map::new(&self.imgs) + .text_color(TEXT_COLOR) + .top_left_with_margins_on(ui_widgets.window, 200.0, 215.0) + .set(self.ids.map, ui_widgets) { - 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