Add debug window, debug window toggle

Former-commit-id: f0eee8c127dab7c6f552e00ca26632fe1798ee5d
This commit is contained in:
sxv20_ 2019-04-22 19:47:22 +01:00
parent 64c97f47fc
commit ded36d7c8d

View File

@ -21,6 +21,13 @@ widget_ids! {
bag_space_add,
inventorytest_button,
inventorytest_button_label,
// Debug
debug_bg,
debug_button,
debug_button_label,
fps_counter,
// Logo
v_logo,
@ -325,7 +332,7 @@ impl Imgs {
check_checked_mo: load("element/buttons/check/yes_mo.png", ui),
slider: load("element/slider/track.png", ui),
slider_indicator: load("element/slider/indicator.png", ui),
button_blank: ui.new_graphic(ui::Graphic::Blank),
button_blank: ui.new_graphic(ui::Graphic::Blank),
button_blue_mo: load("element/buttons/blue_mo.png", ui),
button_blue_press: load("element/buttons/blue_press.png", ui),
@ -410,6 +417,7 @@ pub struct Hud {
font_metamorph: FontId,
font_opensans: FontId,
show_help: bool,
show_debug: bool,
bag_open: bool,
menu_open: bool,
open_windows: Windows,
@ -440,10 +448,12 @@ impl Hud {
// 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(
assets::load(fullpath.as_str())
.expect("Error loading file")
).unwrap())
ui.new_font(
conrod_core::text::Font::from_bytes(
assets::load(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);
@ -457,6 +467,7 @@ impl Hud {
chat,
settings_tab: SettingsTab::Interface,
show_help: true,
show_debug: false,
bag_open: false,
menu_open: false,
map_open: false,
@ -486,7 +497,22 @@ impl Hud {
if !self.show_ui {
return events;
}
// Display debug window
// TODO: move this to a better place?
if self.show_debug {
Image::new(self.imgs.window_frame_2)
.down_from(self.ids.mmap_frame, 20.0)
.w_h(300.0, 350.0)
.set(self.ids.debug_bg, ui_widgets);
Text::new(&format!("FPS: {:.1}", tps))
.color(TEXT_COLOR)
.top_left_with_margins_on(self.ids.debug_bg, 20.0, 20.0)
.font_id(self.font_opensans)
.font_size(18)
.set(self.ids.fps_counter, ui_widgets);
}
// Add Bag-Space Button
if self.inventorytest_button {
if Button::image(self.imgs.mmap_button)
@ -524,21 +550,21 @@ impl Hud {
Text::new(
"Tab = Free Cursor \n\
Esc = Open/Close Menus \n\
\n\
F1 = Toggle this Window \n\
F2 = Toggle Interface \n\
\n\
Enter = Open Chat \n\
Mouse Wheel = Scroll Chat\n\
\n\
M = Map \n\
B = Bag \n\
L = Quest-Log \n\
C = Character Window \n\
O = Social \n\
P = Spellbook \n\
N = Settings",
Esc = Open/Close Menus \n\
\n\
F1 = Toggle this Window \n\
F2 = Toggle Interface \n\
\n\
Enter = Open Chat \n\
Mouse Wheel = Scroll Chat\n\
\n\
M = Map \n\
B = Bag \n\
L = Quest-Log \n\
C = Character Window \n\
O = Social \n\
P = Spellbook \n\
N = Settings",
)
.color(TEXT_COLOR)
.top_left_with_margins_on(self.ids.help_bg, 20.0, 20.0)
@ -968,6 +994,22 @@ impl Hud {
.graphics_for(self.ids.inventorytest_button)
.color(TEXT_COLOR)
.set(self.ids.inventorytest_button_label, ui_widgets);
self.show_debug =
ToggleButton::new(self.show_debug, self.imgs.check, self.imgs.check_checked)
.w_h(288.0 / 24.0, 288.0 / 24.0)
.top_left_with_margins_on(self.ids.rectangle, 65.0, 15.0)
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo)
.press_images(self.imgs.check_press, self.imgs.check_press)
.set(self.ids.debug_button, ui_widgets);
Text::new("Show Debug Window")
.right_from(self.ids.debug_button, 10.0)
.font_size(12)
.font_id(self.font_opensans)
.graphics_for(self.ids.debug_button)
.color(TEXT_COLOR)
.set(self.ids.debug_button_label, ui_widgets);
}
//2 Gameplay////////////////
if Button::image(if let SettingsTab::Gameplay = self.settings_tab {