Make use of image_ids! in char selection

Former-commit-id: 98a11ae94aa299a8eb9e5e4d69cb99c7753f626b
This commit is contained in:
timokoesters 2019-05-08 20:40:34 +02:00
parent 31ab734f90
commit 854271f321

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
render::Renderer, render::Renderer,
ui::{self, Graphic, ScaleMode, Ui}, ui::{self, Graphic, ScaleMode, Ui,BlankGraphic, ImageGraphic, VoxelGraphic},
window::Window, window::Window,
}; };
use common::{ use common::{
@ -160,158 +160,86 @@ widget_ids! {
} }
} }
struct Imgs { image_ids! {
v_logo: ImgId, struct Imgs {
bg_selection: ImgId, <VoxelGraphic>
bg_creation: ImgId, v_logo: "/voxygen/element/v_logo.vox",
button: ImgId, button: "/voxygen/element/buttons/button.vox",
button_hover: ImgId, button_hover: "/voxygen/element/buttons/button_hover.vox",
button_press: ImgId, button_press: "/voxygen/element/buttons/button_press.vox",
button_red: ImgId, button_red: "/voxygen/element/buttons/button_red.vox",
button_red_hover: ImgId, button_red_hover: "/voxygen/element/buttons/button_red_hover.vox",
button_red_press: ImgId, button_red_press: "/voxygen/element/buttons/button_red_press.vox",
selection_window: ImgId, name_input: "/voxygen/element/misc_bg/textbox.vox",
test_char_l_button: ImgId,
test_char_l_big: ImgId,
name_input: ImgId,
creation_window: ImgId,
creation_window_body: ImgId,
frame_closed: ImgId,
frame_closed_mo: ImgId,
frame_closed_press: ImgId,
frame_open: ImgId,
frame_open_mo: ImgId,
frame_open_press: ImgId,
skin_eyes_window: ImgId,
hair_window: ImgId,
accessories_window: ImgId,
color_picker_bg: ImgId,
slider_range: ImgId,
slider_indicator: ImgId,
window_frame_2: ImgId,
//test_char_m_button: ImgId, <ImageGraphic>
//test_char_r_button: ImgId, bg_selection: "/voxygen/background/bg_selection.png",
// Race Icons bg_creation: "/voxygen/background/bg_creation.png",
male: ImgId, selection_window: "/voxygen/element/frames/selection.png",
female: ImgId, test_char_l_button: "/voxygen/element/misc_bg/test_char_l.png",
human_m: ImgId, test_char_l_big: "/voxygen/element/misc_bg/test_char_l_big.png",
human_f: ImgId, creation_window: "/voxygen/element/frames/char_creation.png",
orc_m: ImgId, creation_window_body: "/voxygen/element/frames/body_creation.png",
orc_f: ImgId, frame_closed: "/voxygen/element/buttons/frame/closed.png",
dwarf_m: ImgId, frame_closed_mo: "/voxygen/element/buttons/frame/closed_mo.png",
dwarf_f: ImgId, frame_closed_press: "/voxygen/element/buttons/frame/closed_press.png",
undead_m: ImgId, frame_open: "/voxygen/element/buttons/frame/open.png",
undead_f: ImgId, frame_open_mo: "/voxygen/element/buttons/frame/open_mo.png",
elf_m: ImgId, frame_open_press: "/voxygen/element/buttons/frame/open_press.png",
elf_f: ImgId, skin_eyes_window: "/voxygen/element/frames/skin_eyes.png",
danari_m: ImgId, hair_window: "/voxygen/element/frames/skin_eyes.png",
danari_f: ImgId, accessories_window: "/voxygen/element/frames/skin_eyes.png",
// Weapon Icons color_picker_bg: "/voxygen/element/misc_bg/color_picker_blank.png",
daggers: ImgId, slider_range: "/voxygen/element/slider/track.png",
sword_shield: ImgId, slider_indicator: "/voxygen/element/slider/indicator.png",
sword: ImgId, window_frame_2: "/voxygen/element/frames/window_2.png",
axe: ImgId,
hammer: ImgId, // Weapon Icons
bow: ImgId, daggers: "/voxygen/element/icons/daggers.png",
staff: ImgId, sword_shield: "/voxygen/element/icons/swordshield.png",
// Arrows sword: "/voxygen/element/icons/sword.png",
arrow_left: ImgId, axe: "/voxygen/element/icons/axe.png",
arrow_left_mo: ImgId, hammer: "/voxygen/element/icons/hammer.png",
arrow_left_press: ImgId, bow: "/voxygen/element/icons/bow.png",
arrow_left_grey: ImgId, staff: "/voxygen/element/icons/staff.png",
arrow_right: ImgId, //test_char_m_button: "/voxygen/test_char_m_button"),
arrow_right_mo: ImgId, //test_char_r_button: "/voxygen/test_char_r_button"),
arrow_right_press: ImgId, // Race Icons
arrow_right_grey: ImgId, male: "/voxygen/element/icons/male.png",
// Icon Borders female: "/voxygen/element/icons/female.png",
icon_border: ImgId, human_m: "/voxygen/element/icons/human_m.png",
icon_border_mo: ImgId, human_f: "/voxygen/element/icons/human_f.png",
icon_border_press: ImgId, orc_m: "/voxygen/element/icons/orc_m.png",
icon_border_pressed: ImgId, orc_f: "/voxygen/element/icons/orc_f.png",
dwarf_m: "/voxygen/element/icons/dwarf_m.png",
dwarf_f: "/voxygen/element/icons/dwarf_f.png",
undead_m: "/voxygen/element/icons/ud_m.png",
undead_f: "/voxygen/element/icons/ud_f.png",
elf_m: "/voxygen/element/icons/elf_m.png",
elf_f: "/voxygen/element/icons/elf_f.png",
danari_m: "/voxygen/element/icons/danari_m.png",
danari_f: "/voxygen/element/icons/danari_f.png",
// Arrows
arrow_left: "/voxygen/element/buttons/arrow/left.png",
arrow_left_mo: "/voxygen/element/buttons/arrow/left_mo.png",
arrow_left_press: "/voxygen/element/buttons/arrow/left_press.png",
arrow_left_grey: "/voxygen/element/buttons/arrow/left_inactive.png",
arrow_right: "/voxygen/element/buttons/arrow/right.png",
arrow_right_mo: "/voxygen/element/buttons/arrow/right_mo.png",
arrow_right_press: "/voxygen/element/buttons/arrow/right_press.png",
arrow_right_grey: "/voxygen/element/buttons/arrow/right_inactive.png",
// Icon Borders
icon_border: "/voxygen/element/buttons/border.png",
icon_border_mo: "/voxygen/element/buttons/border_mo.png",
icon_border_press: "/voxygen/element/buttons/border_press.png",
icon_border_pressed: "/voxygen/element/buttons/border_pressed.png",
}
} }
impl Imgs {
fn new(ui: &mut Ui) -> Imgs {
let load_img = |filename, ui: &mut Ui| {
let fullpath: String = ["/voxygen/", filename].concat();
let image = assets::load::<image::DynamicImage>(fullpath.as_str()).unwrap();
ui.add_graphic(Graphic::Image(image))
};
let load_vox = |filename, ui: &mut Ui| {
let fullpath: String = ["/voxygen/", filename].concat();
let dot_vox = assets::load::<dot_vox::DotVoxData>(fullpath.as_str()).unwrap();
ui.add_graphic(Graphic::Voxel(dot_vox))
};
Imgs {
v_logo: load_vox("element/v_logo.vox", ui),
bg_selection: load_img("background/bg_selection.png", ui),
bg_creation: load_img("background/bg_creation.png", ui),
selection_window: load_img("element/frames/selection.png", ui),
button: load_vox("element/buttons/button.vox", ui),
button_hover: load_vox("element/buttons/button_hover.vox", ui),
button_press: load_vox("element/buttons/button_press.vox", ui),
button_red: load_vox("element/buttons/button_red.vox", ui),
button_red_hover: load_vox("element/buttons/button_red_hover.vox", ui),
button_red_press: load_vox("element/buttons/button_red_press.vox", ui),
test_char_l_button: load_img("element/misc_bg/test_char_l.png", ui),
test_char_l_big: load_img("element/misc_bg/test_char_l_big.png", ui),
name_input: load_vox("element/misc_bg/textbox.vox", ui),
creation_window: load_img("element/frames/char_creation.png", ui),
creation_window_body: load_img("element/frames/body_creation.png", ui),
frame_closed: load_img("element/buttons/frame/closed.png", ui),
frame_closed_mo: load_img("element/buttons/frame/closed_mo.png", ui),
frame_closed_press: load_img("element/buttons/frame/closed_press.png", ui),
frame_open: load_img("element/buttons/frame/open.png", ui),
frame_open_mo: load_img("element/buttons/frame/open_mo.png", ui),
frame_open_press: load_img("element/buttons/frame/open_press.png", ui),
skin_eyes_window: load_img("element/frames/skin_eyes.png", ui),
hair_window: load_img("element/frames/skin_eyes.png", ui),
accessories_window: load_img("element/frames/skin_eyes.png", ui),
color_picker_bg: load_img("element/misc_bg/color_picker_blank.png", ui),
slider_range: load_img("element/slider/track.png", ui),
slider_indicator: load_img("element/slider/indicator.png", ui),
window_frame_2: load_img("element/frames/window_2.png", ui),
// Weapon Icons font_ids! {
daggers: load_img("element/icons/daggers.png", ui), pub struct Fonts {
sword_shield: load_img("element/icons/swordshield.png", ui), opensans: "/voxygen/font/OpenSans-Regular.ttf",
sword: load_img("element/icons/sword.png", ui), metamorph: "/voxygen/font/Metamorphous-Regular.ttf",
axe: load_img("element/icons/axe.png", ui),
hammer: load_img("element/icons/hammer.png", ui),
bow: load_img("element/icons/bow.png", ui),
staff: load_img("element/icons/staff.png", ui),
//test_char_m_button: load_img("test_char_m_button"),
//test_char_r_button: load_img("test_char_r_button"),
// Race Icons
male: load_img("element/icons/male.png", ui),
female: load_img("element/icons/female.png", ui),
human_m: load_img("element/icons/human_m.png", ui),
human_f: load_img("element/icons/human_f.png", ui),
orc_m: load_img("element/icons/orc_m.png", ui),
orc_f: load_img("element/icons/orc_f.png", ui),
dwarf_m: load_img("element/icons/dwarf_m.png", ui),
dwarf_f: load_img("element/icons/dwarf_f.png", ui),
undead_m: load_img("element/icons/ud_m.png", ui),
undead_f: load_img("element/icons/ud_f.png", ui),
elf_m: load_img("element/icons/elf_m.png", ui),
elf_f: load_img("element/icons/elf_f.png", ui),
danari_m: load_img("element/icons/danari_m.png", ui),
danari_f: load_img("element/icons/danari_f.png", ui),
// Arrows
arrow_left: load_img("element/buttons/arrow/left.png", ui),
arrow_left_mo: load_img("element/buttons/arrow/left_mo.png", ui),
arrow_left_press: load_img("element/buttons/arrow/left_press.png", ui),
arrow_left_grey: load_img("element/buttons/arrow/left_inactive.png", ui),
arrow_right: load_img("element/buttons/arrow/right.png", ui),
arrow_right_mo: load_img("element/buttons/arrow/right_mo.png", ui),
arrow_right_press: load_img("element/buttons/arrow/right_press.png", ui),
arrow_right_grey: load_img("element/buttons/arrow/right_inactive.png", ui),
// Icon Borders
icon_border: load_img("element/buttons/border.png", ui),
icon_border_mo: load_img("element/buttons/border_mo.png", ui),
icon_border_press: load_img("element/buttons/border_press.png", ui),
icon_border_pressed: load_img("element/buttons/border_pressed.png", ui),
}
} }
} }
@ -340,8 +268,7 @@ pub struct CharSelectionUi {
ui: Ui, ui: Ui,
ids: Ids, ids: Ids,
imgs: Imgs, imgs: Imgs,
font_metamorph: FontId, fonts: Fonts,
font_opensans: FontId,
character_creation: bool, character_creation: bool,
selected_char_no: Option<i32>, selected_char_no: Option<i32>,
character_name: String, character_name: String,
@ -357,22 +284,16 @@ impl CharSelectionUi {
// Generate ids // Generate ids
let ids = Ids::new(ui.id_generator()); let ids = Ids::new(ui.id_generator());
// Load images // Load images
let imgs = Imgs::new(&mut ui); let imgs = Imgs::load(&mut ui).expect("Failed to load images");
// Load fonts // Load fonts
let load_font = |filename, ui: &mut Ui| { let fonts = Fonts::load(&mut ui).expect("Failed to load fonts");
let fullpath: String = ["/voxygen/font", filename].concat();
ui.new_font(assets::load(fullpath.as_str()).expect("Error loading file"))
};
let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui);
let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui);
// TODO: Randomize initial values // TODO: Randomize initial values
Self { Self {
ui, ui,
imgs,
ids, ids,
font_metamorph, imgs,
font_opensans, fonts,
character_creation: false, character_creation: false,
selected_char_no: None, selected_char_no: None,
character_name: "Character Name".to_string(), character_name: "Character Name".to_string(),
@ -574,7 +495,7 @@ impl CharSelectionUi {
.w_h(300.0, 60.0) .w_h(300.0, 60.0)
.mid_top_with_margin_on(self.ids.name_input, 2.0) .mid_top_with_margin_on(self.ids.name_input, 2.0)
.font_size(26) .font_size(26)
.font_id(self.font_metamorph) .font_id(self.fonts.metamorph)
.center_justify() .center_justify()
.text_color(TEXT_COLOR) .text_color(TEXT_COLOR)
.color(TRANSPARENT) .color(TRANSPARENT)
@ -931,7 +852,7 @@ impl CharSelectionUi {
.mid_top_with_margin_on(self.ids.creation_window, 410.0) .mid_top_with_margin_on(self.ids.creation_window, 410.0)
.w(500.0) .w(500.0)
.font_size(20) .font_size(20)
.font_id(self.font_opensans) .font_id(self.fonts.opensans)
.color(TEXT_COLOR) .color(TEXT_COLOR)
.wrap_by_word() .wrap_by_word()
.set(self.ids.race_description, ui_widgets); .set(self.ids.race_description, ui_widgets);
@ -1105,7 +1026,7 @@ impl CharSelectionUi {
.mid_top_with_margin_on(self.ids.creation_window, 410.0) .mid_top_with_margin_on(self.ids.creation_window, 410.0)
.w(500.0) .w(500.0)
.font_size(20) .font_size(20)
.font_id(self.font_opensans) .font_id(self.fonts.opensans)
.color(TEXT_COLOR) .color(TEXT_COLOR)
.wrap_by_word() .wrap_by_word()
.set(self.ids.race_description, ui_widgets); .set(self.ids.race_description, ui_widgets);