Move skillbar into own file

Former-commit-id: efab633e9b5c1ffc5071a556203490780615cde6
This commit is contained in:
timokoesters 2019-05-04 08:07:23 +02:00 committed by Imbris
parent 08aa8875fd
commit abd960aa48
2 changed files with 194 additions and 96 deletions

View File

@ -1,5 +1,6 @@
mod chat;
mod character_window;
mod skillbar;
mod map;
mod esc_menu;
mod small_window;
@ -10,6 +11,7 @@ mod font_ids;
use chat::Chat;
use character_window::CharacterWindow;
use map::Map;
use skillbar::Skillbar;
use esc_menu::EscMenu;
use small_window::{SmallWindow, SmallWindowType};
use settings_window::SettingsWindow;
@ -159,6 +161,7 @@ widget_ids! {
chat,
map,
character_window,
skillbar,
esc_menu,
small_window,
settings_window,
@ -513,9 +516,8 @@ impl Hud {
.left_from(self.ids.character_button, 10.0)
.hover_image(self.imgs.qlog_hover)
.press_image(self.imgs.qlog_press)
.label(&format!("{:?}", self.settings.controls.quest_log))
.label("L")
.label_font_size(10)
.label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
@ -534,100 +536,6 @@ impl Hud {
}
}
// Skillbar Module
// Experience-Bar
Image::new(self.imgs.xp_bar)
.w_h(2688.0 / 6.0, 116.0 / 6.0)
.mid_bottom_of(ui_widgets.window)
.set(self.ids.xp_bar, ui_widgets);
Rectangle::fill_with([406.0 * (self.xp_percentage), 5.0], XP_COLOR) // "W=406*[Exp. %]"
.top_left_with_margins_on(self.ids.xp_bar, 5.0, 21.0)
.set(self.ids.xp_bar_progress, ui_widgets);
// Left Grid
Image::new(self.imgs.sb_grid)
.w_h(2240.0 / 12.0, 448.0 / 12.0)
.up_from(self.ids.xp_bar, 0.0)
.align_left_of(self.ids.xp_bar)
.set(self.ids.sb_grid_l, ui_widgets);
Image::new(self.imgs.sb_grid_bg)
.w_h(2240.0 / 12.0, 448.0 / 12.0)
.middle_of(self.ids.sb_grid_l)
.set(self.ids.sb_grid_bg_l, ui_widgets);
// Right Grid
Image::new(self.imgs.sb_grid)
.w_h(2240.0 / 12.0, 448.0 / 12.0)
.up_from(self.ids.xp_bar, 0.0)
.align_right_of(self.ids.xp_bar)
.set(self.ids.sb_grid_r, ui_widgets);
Image::new(self.imgs.sb_grid_bg)
.w_h(2240.0 / 12.0, 448.0 / 12.0)
.middle_of(self.ids.sb_grid_r)
.set(self.ids.sb_grid_bg_r, ui_widgets);
// Right and Left Click
Image::new(self.imgs.l_click)
.w_h(224.0 / 6.0, 320.0 / 6.0)
.right_from(self.ids.sb_grid_bg_l, 0.0)
.align_bottom_of(self.ids.sb_grid_bg_l)
.set(self.ids.l_click, ui_widgets);
Image::new(self.imgs.r_click)
.w_h(224.0 / 6.0, 320.0 / 6.0)
.left_from(self.ids.sb_grid_bg_r, 0.0)
.align_bottom_of(self.ids.sb_grid_bg_r)
.set(self.ids.r_click, ui_widgets);
// Health Bar
Image::new(self.imgs.health_bar)
.w_h(1120.0 / 6.0, 96.0 / 6.0)
.left_from(self.ids.l_click, 0.0)
.align_top_of(self.ids.l_click)
.set(self.ids.health_bar, ui_widgets);
// Filling
Rectangle::fill_with([182.0 * (self.hp_percentage), 6.0], HP_COLOR) // "W=182.0 * [Health. %]"
.top_right_with_margins_on(self.ids.health_bar, 5.0, 0.0)
.set(self.ids.health_bar_color, ui_widgets);
// Mana Bar
Image::new(self.imgs.mana_bar)
.w_h(1120.0 / 6.0, 96.0 / 6.0)
.right_from(self.ids.r_click, 0.0)
.align_top_of(self.ids.r_click)
.set(self.ids.mana_bar, ui_widgets);
// Filling
Rectangle::fill_with([182.0 * (self.mana_percentage), 6.0], MANA_COLOR) // "W=182.0 * [Mana. %]"
.top_left_with_margins_on(self.ids.mana_bar, 5.0, 0.0)
.set(self.ids.mana_bar_color, ui_widgets);
// Buffs/Debuffs
// Buffs
// Debuffs
// Level Display
// Insert actual Level here
Text::new("1")
.left_from(self.ids.xp_bar, -15.0)
.font_size(10)
.color(TEXT_COLOR)
.set(self.ids.level_text, ui_widgets);
// Insert next Level here
Text::new("2")
.right_from(self.ids.xp_bar, -15.0)
.font_size(10)
.color(TEXT_COLOR)
.set(self.ids.next_level_text, ui_widgets);
// Bag contents
if self.bag_open {
// Contents
@ -677,6 +585,7 @@ impl Hud {
}
}
// Bag
if !self.map_open && self.show_ui {
self.bag_open = ToggleButton::new(self.bag_open, self.imgs.bag, self.imgs.bag_open)
@ -703,6 +612,11 @@ impl Hud {
.set(self.ids.bag_text, ui_widgets);
}
Skillbar::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.skillbar, ui_widgets);
// Chat box
match Chat::new(&mut self.new_messages, &self.imgs, &self.fonts)
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)

184
voxygen/src/hud/skillbar.rs Normal file
View File

@ -0,0 +1,184 @@
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::{
img_ids::Imgs,
font_ids::Fonts,
TEXT_COLOR, XP_COLOR, HP_COLOR, MANA_COLOR,
};
widget_ids! {
struct Ids {
health_bar,
health_bar_color,
l_click,
level_text,
mana_bar,
mana_bar_color,
next_level_text,
r_click,
sb_grid_bg_l,
sb_grid_bg_r,
sb_grid_l,
sb_grid_r,
test,
xp_bar,
xp_bar_progress,
}
}
#[derive(WidgetCommon)]
pub struct Skillbar<'a> {
imgs: &'a Imgs,
fonts: &'a Fonts,
#[conrod(common_builder)]
common: widget::CommonBuilder,
style: (),
}
impl<'a> Skillbar<'a> {
pub fn new(imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
Self {
imgs,
fonts,
common: widget::CommonBuilder::default(),
style: (),
}
}
}
pub struct State {
ids: Ids,
}
pub enum Event {}
impl<'a> Widget for Skillbar<'a> {
type State = State;
type 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 {
()
}
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs {
id,
state,
ui,
style,
..
} = args;
// TODO: Read from parameter / character struct
let xp_percentage = 0.4;
let hp_percentage = 0.4;
let mana_percentage = 0.4;
// Experience-Bar
Image::new(self.imgs.xp_bar)
.w_h(2688.0 / 6.0, 116.0 / 6.0)
.mid_bottom_of(ui.window)
.set(state.ids.xp_bar, ui);
Rectangle::fill_with([406.0 * (xp_percentage), 5.0], XP_COLOR) // "W=406*[Exp. %]"
.top_left_with_margins_on(state.ids.xp_bar, 5.0, 21.0)
.set(state.ids.xp_bar_progress, ui);
// Left Grid
Image::new(self.imgs.sb_grid)
.w_h(2240.0 / 12.0, 448.0 / 12.0)
.up_from(state.ids.xp_bar, 0.0)
.align_left_of(state.ids.xp_bar)
.set(state.ids.sb_grid_l, ui);
Image::new(self.imgs.sb_grid_bg)
.w_h(2240.0 / 12.0, 448.0 / 12.0)
.middle_of(state.ids.sb_grid_l)
.set(state.ids.sb_grid_bg_l, ui);
// Right Grid
Image::new(self.imgs.sb_grid)
.w_h(2240.0 / 12.0, 448.0 / 12.0)
.up_from(state.ids.xp_bar, 0.0)
.align_right_of(state.ids.xp_bar)
.set(state.ids.sb_grid_r, ui);
Image::new(self.imgs.sb_grid_bg)
.w_h(2240.0 / 12.0, 448.0 / 12.0)
.middle_of(state.ids.sb_grid_r)
.set(state.ids.sb_grid_bg_r, ui);
// Right and Left Click
Image::new(self.imgs.l_click)
.w_h(224.0 / 6.0, 320.0 / 6.0)
.right_from(state.ids.sb_grid_bg_l, 0.0)
.align_bottom_of(state.ids.sb_grid_bg_l)
.set(state.ids.l_click, ui);
Image::new(self.imgs.r_click)
.w_h(224.0 / 6.0, 320.0 / 6.0)
.left_from(state.ids.sb_grid_bg_r, 0.0)
.align_bottom_of(state.ids.sb_grid_bg_r)
.set(state.ids.r_click, ui);
// Health Bar
Image::new(self.imgs.health_bar)
.w_h(1120.0 / 6.0, 96.0 / 6.0)
.left_from(state.ids.l_click, 0.0)
.align_top_of(state.ids.l_click)
.set(state.ids.health_bar, ui);
// Filling
Rectangle::fill_with([182.0 * (hp_percentage), 6.0], HP_COLOR) // "W=182.0 * [Health. %]"
.top_right_with_margins_on(state.ids.health_bar, 5.0, 0.0)
.set(state.ids.health_bar_color, ui);
// Mana Bar
Image::new(self.imgs.mana_bar)
.w_h(1120.0 / 6.0, 96.0 / 6.0)
.right_from(state.ids.r_click, 0.0)
.align_top_of(state.ids.r_click)
.set(state.ids.mana_bar, ui);
// Filling
Rectangle::fill_with([182.0 * (mana_percentage), 6.0], MANA_COLOR) // "W=182.0 * [Mana. %]"
.top_left_with_margins_on(state.ids.mana_bar, 5.0, 0.0)
.set(state.ids.mana_bar_color, ui);
// Buffs/Debuffs
// Buffs
// Debuffs
// Level Display
// Insert actual Level here
Text::new("1")
.left_from(state.ids.xp_bar, -15.0)
.font_size(10)
.color(TEXT_COLOR)
.set(state.ids.level_text, ui);
// Insert next Level here
Text::new("2")
.right_from(state.ids.xp_bar, -15.0)
.font_size(10)
.color(TEXT_COLOR)
.set(state.ids.next_level_text, ui);
None
}
}