Merge branch 'pfau/fix-char-creation' into 'master'

Fixed char select bugs, improved code quality

See merge request veloren/veloren!739
This commit is contained in:
Joshua Barretto 2020-01-20 23:20:22 +00:00
commit 2ddb6d362e
4 changed files with 972 additions and 929 deletions

View File

@ -65,12 +65,14 @@ impl PlayState for CharSelectionState {
return PlayStateResult::Pop; return PlayStateResult::Pop;
} }
ui::Event::Play => { ui::Event::Play => {
let char_data = self
.char_selection_ui
.get_character_data()
.expect("Character data is required to play");
self.client.borrow_mut().request_character( self.client.borrow_mut().request_character(
self.char_selection_ui.character_name.clone(), char_data.name,
comp::Body::Humanoid(self.char_selection_ui.character_body), char_data.body,
self.char_selection_ui char_data.tool,
.character_tool
.map(|specifier| specifier.to_owned()),
); );
return PlayStateResult::Push(Box::new(SessionState::new( return PlayStateResult::Push(Box::new(SessionState::new(
global_state, global_state,
@ -83,23 +85,32 @@ impl PlayState for CharSelectionState {
// Maintain global state. // Maintain global state.
global_state.maintain(clock.get_last_delta().as_secs_f32()); global_state.maintain(clock.get_last_delta().as_secs_f32());
let humanoid_body = self
.char_selection_ui
.get_character_data()
.and_then(|data| match data.body {
comp::Body::Humanoid(body) => Some(body),
_ => None,
});
// Maintain the scene. // Maintain the scene.
self.scene.maintain( self.scene.maintain(
global_state.window.renderer_mut(), global_state.window.renderer_mut(),
&self.client.borrow(), &self.client.borrow(),
self.char_selection_ui.character_body, humanoid_body.clone(),
); );
// Render the scene. // Render the scene.
self.scene.render( self.scene.render(
global_state.window.renderer_mut(), global_state.window.renderer_mut(),
&self.client.borrow(), &self.client.borrow(),
self.char_selection_ui.character_body, humanoid_body.clone(),
&comp::Equipment { &comp::Equipment {
main: self main: self
.char_selection_ui .char_selection_ui
.character_tool .get_character_data()
.and_then(|specifier| assets::load_cloned(&specifier).ok()), .and_then(|data| data.tool)
.and_then(|tool| assets::load_cloned(&tool).ok()),
alt: None, alt: None,
}, },
); );

View File

@ -115,7 +115,12 @@ impl Scene {
} }
} }
pub fn maintain(&mut self, renderer: &mut Renderer, client: &Client, body: humanoid::Body) { pub fn maintain(
&mut self,
renderer: &mut Renderer,
client: &Client,
body: Option<humanoid::Body>,
) {
self.camera.set_focus_pos(Vec3::unit_z() * 1.5); self.camera.set_focus_pos(Vec3::unit_z() * 1.5);
self.camera.update(client.state().get_time()); self.camera.update(client.state().get_time());
self.camera.set_distance(3.0); // 4.2 self.camera.set_distance(3.0); // 4.2
@ -147,6 +152,7 @@ impl Scene {
self.figure_model_cache.clean(client.get_tick()); self.figure_model_cache.clean(client.get_tick());
if let Some(body) = body {
let tgt_skeleton = IdleAnimation::update_skeleton( let tgt_skeleton = IdleAnimation::update_skeleton(
self.figure_state.skeleton_mut(), self.figure_state.skeleton_mut(),
client.state().get_time(), client.state().get_time(),
@ -158,6 +164,7 @@ impl Scene {
&tgt_skeleton, &tgt_skeleton,
client.state().ecs().read_resource::<DeltaTime>().0, client.state().ecs().read_resource::<DeltaTime>().0,
); );
}
self.figure_state.update( self.figure_state.update(
renderer, renderer,
@ -178,11 +185,12 @@ impl Scene {
&mut self, &mut self,
renderer: &mut Renderer, renderer: &mut Renderer,
client: &Client, client: &Client,
body: humanoid::Body, body: Option<humanoid::Body>,
equipment: &Equipment, equipment: &Equipment,
) { ) {
renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals); renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
if let Some(body) = body {
let model = &self let model = &self
.figure_model_cache .figure_model_cache
.get_or_create_model( .get_or_create_model(
@ -203,6 +211,7 @@ impl Scene {
&self.lights, &self.lights,
&self.shadows, &self.shadows,
); );
}
renderer.render_figure( renderer.render_figure(
&self.backdrop_model, &self.backdrop_model,

View File

@ -250,19 +250,31 @@ enum InfoContent {
//Name, //Name,
} }
pub enum Mode {
Select(Option<CharacterData>),
Create {
name: String,
body: humanoid::Body,
tool: Option<&'static str>,
},
}
pub struct CharSelectionUi { pub struct CharSelectionUi {
ui: Ui, ui: Ui,
ids: Ids, ids: Ids,
imgs: Imgs, imgs: Imgs,
rot_imgs: ImgsRot, rot_imgs: ImgsRot,
fonts: Fonts, fonts: Fonts,
character_creation: bool, //character_creation: bool,
info_content: InfoContent, info_content: InfoContent,
selected_language: String, selected_language: String,
//deletion_confirmation: bool, //deletion_confirmation: bool,
/*
pub character_name: String, pub character_name: String,
pub character_body: humanoid::Body, pub character_body: humanoid::Body,
pub character_tool: Option<&'static str>, pub character_tool: Option<&'static str>,
*/
pub mode: Mode,
} }
impl CharSelectionUi { impl CharSelectionUi {
@ -288,12 +300,27 @@ impl CharSelectionUi {
rot_imgs, rot_imgs,
fonts, fonts,
info_content: InfoContent::None, info_content: InfoContent::None,
selected_language: global_state.settings.language.selected_language.clone(),
//deletion_confirmation: false, //deletion_confirmation: false,
/*
character_creation: false, character_creation: false,
selected_language: global_state.settings.language.selected_language.clone(), selected_language: global_state.settings.language.selected_language.clone(),
character_name: "Character Name".to_string(), character_name: "Character Name".to_string(),
character_body: humanoid::Body::random(), character_body: humanoid::Body::random(),
character_tool: Some(STARTER_SWORD), character_tool: Some(STARTER_SWORD),
*/
mode: Mode::Select(None),
}
}
pub fn get_character_data(&self) -> Option<CharacterData> {
match &self.mode {
Mode::Select(data) => data.clone(),
Mode::Create { name, body, tool } => Some(CharacterData {
name: name.clone(),
body: comp::Body::Humanoid(body.clone()),
tool: tool.map(|specifier| specifier.to_string()),
}),
} }
} }
@ -372,6 +399,7 @@ impl CharSelectionUi {
.press_image(self.imgs.button_press) .press_image(self.imgs.button_press)
.label_y(Relative::Scalar(2.0)) .label_y(Relative::Scalar(2.0))
.label(&localized_strings.get("common.yes")) .label(&localized_strings.get("common.yes"))
.label_font_id(self.fonts.cyri)
.label_font_size(18) .label_font_size(18)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
.set(self.ids.info_ok, ui_widgets) .set(self.ids.info_ok, ui_widgets)
@ -384,21 +412,18 @@ impl CharSelectionUi {
} }
} }
// Character Selection ///////////////// // Character Selection /////////////////
if !self.character_creation { match &mut self.mode {
Mode::Select(data) => {
// Set active body // Set active body
self.character_body = if let Some(character) = global_state *data = if let Some(character) = global_state
.meta .meta
.characters .characters
.get(global_state.meta.selected_character) .get(global_state.meta.selected_character)
{ {
match character.body { Some(character.clone())
comp::Body::Humanoid(body) => Some(body.clone()),
_ => None,
}
} else { } else {
None None
} };
.unwrap_or_else(|| humanoid::Body::random());
// Background for Server Frame // Background for Server Frame
Rectangle::fill_with([386.0, 95.0], color::rgba(0.0, 0.0, 0.0, 0.9)) Rectangle::fill_with([386.0, 95.0], color::rgba(0.0, 0.0, 0.0, 0.9))
@ -492,7 +517,7 @@ impl CharSelectionUi {
.w_h(270.0, 50.0) .w_h(270.0, 50.0)
.hover_image(self.imgs.button_hover) .hover_image(self.imgs.button_hover)
.press_image(self.imgs.button_press) .press_image(self.imgs.button_press)
.label(&localized_strings.get("char_selection.create_charater")) .label("Create Character")
.label_font_id(self.fonts.cyri) .label_font_id(self.fonts.cyri)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
.label_font_size(20) .label_font_size(20)
@ -532,13 +557,18 @@ impl CharSelectionUi {
// Character selection // Character selection
for (i, character) in global_state.meta.characters.iter().enumerate() { for (i, character) in global_state.meta.characters.iter().enumerate() {
let character_box = Button::image(if global_state.meta.selected_character == i { let character_box =
Button::image(if global_state.meta.selected_character == i {
self.imgs.selection_hover self.imgs.selection_hover
} else { } else {
self.imgs.selection self.imgs.selection
}); });
let character_box = if i == 0 { let character_box = if i == 0 {
character_box.top_left_with_margins_on(self.ids.charlist_alignment, 0.0, 2.0) character_box.top_left_with_margins_on(
self.ids.charlist_alignment,
0.0,
2.0,
)
} else { } else {
character_box.down_from(self.ids.character_boxes[i - 1], 5.0) character_box.down_from(self.ids.character_boxes[i - 1], 5.0)
}; };
@ -552,11 +582,6 @@ impl CharSelectionUi {
.set(self.ids.character_boxes[i], ui_widgets) .set(self.ids.character_boxes[i], ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_name = character.name.clone();
self.character_body = match &character.body {
comp::Body::Humanoid(body) => body.clone(),
_ => panic!("Unsupported body type!"),
};
global_state.meta.selected_character = i; global_state.meta.selected_character = i;
} }
if Button::image(self.imgs.delete_button) if Button::image(self.imgs.delete_button)
@ -564,7 +589,12 @@ impl CharSelectionUi {
.top_right_with_margins_on(self.ids.character_boxes[i], 15.0, 15.0) .top_right_with_margins_on(self.ids.character_boxes[i], 15.0, 15.0)
.hover_image(self.imgs.delete_button_hover) .hover_image(self.imgs.delete_button_hover)
.press_image(self.imgs.delete_button_press) .press_image(self.imgs.delete_button_press)
.with_tooltip(tooltip_manager, "Delete Character", "", &tooltip_human) .with_tooltip(
tooltip_manager,
&localized_strings.get("char_selection.delete_permanently"),
"",
&tooltip_human,
)
.set(self.ids.character_deletes[i], ui_widgets) .set(self.ids.character_deletes[i], ui_widgets)
.was_clicked() .was_clicked()
{ {
@ -598,7 +628,11 @@ impl CharSelectionUi {
let create_char_button = if character_count > 0 { let create_char_button = if character_count > 0 {
create_char_button.down_from(self.ids.character_boxes[character_count - 1], 5.0) create_char_button.down_from(self.ids.character_boxes[character_count - 1], 5.0)
} else { } else {
create_char_button.top_left_with_margins_on(self.ids.charlist_alignment, 0.0, 2.0) create_char_button.top_left_with_margins_on(
self.ids.charlist_alignment,
0.0,
2.0,
)
}; };
if create_char_button if create_char_button
@ -612,13 +646,16 @@ impl CharSelectionUi {
.set(self.ids.character_box_2, ui_widgets) .set(self.ids.character_box_2, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_creation = true; self.mode = Mode::Create {
self.character_tool = Some(STARTER_SWORD); name: "Character Name".to_string(),
self.character_body = humanoid::Body::random(); body: humanoid::Body::random(),
tool: Some(STARTER_SWORD),
};
} }
} }
// Character_Creation ////////////////////////////////////////////////////////////////////// // Character_Creation //////////////////////////////////////////////////////////////////////
else { Mode::Create { name, body, tool } => {
let mut to_select = false;
// Back Button // Back Button
if Button::image(self.imgs.button) if Button::image(self.imgs.button)
.bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0) .bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0)
@ -633,7 +670,7 @@ impl CharSelectionUi {
.set(self.ids.back_button, ui_widgets) .set(self.ids.back_button, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_creation = false; to_select = true;
} }
// Create Button // Create Button
if Button::image(self.imgs.button) if Button::image(self.imgs.button)
@ -650,11 +687,12 @@ impl CharSelectionUi {
.was_clicked() .was_clicked()
{ {
// TODO: Save character. // TODO: Save character.
self.character_creation = false;
global_state.meta.add_character(CharacterData { global_state.meta.add_character(CharacterData {
name: self.character_name.clone(), name: name.clone(),
body: comp::Body::Humanoid(self.character_body.clone()), body: comp::Body::Humanoid(body.clone()),
tool: tool.map(|tool| tool.to_string()),
}); });
to_select = true;
} }
// Character Name Input // Character Name Input
Rectangle::fill_with([320.0, 50.0], color::rgba(0.0, 0.0, 0.0, 0.97)) Rectangle::fill_with([320.0, 50.0], color::rgba(0.0, 0.0, 0.0, 0.97))
@ -665,7 +703,7 @@ impl CharSelectionUi {
.w_h(337.0, 67.0) .w_h(337.0, 67.0)
.middle_of(self.ids.name_input_bg) .middle_of(self.ids.name_input_bg)
.set(self.ids.name_input, ui_widgets); .set(self.ids.name_input, ui_widgets);
for event in TextBox::new(&self.character_name) for event in TextBox::new(name)
.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)
@ -678,9 +716,7 @@ impl CharSelectionUi {
.set(self.ids.name_field, ui_widgets) .set(self.ids.name_field, ui_widgets)
{ {
match event { match event {
TextBoxEvent::Update(name) => { TextBoxEvent::Update(new_name) => *name = new_name,
self.character_name = name;
}
TextBoxEvent::Enter => {} TextBoxEvent::Enter => {}
} }
} }
@ -725,42 +761,38 @@ impl CharSelectionUi {
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.top_left_with_margins_on(self.ids.creation_buttons_alignment_1, 0.0, 0.0) .top_left_with_margins_on(self.ids.creation_buttons_alignment_1, 0.0, 0.0)
.set(self.ids.male, ui_widgets); .set(self.ids.male, ui_widgets);
if Button::image( if Button::image(if let humanoid::BodyType::Male = body.body_type {
if let humanoid::BodyType::Male = self.character_body.body_type {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
}, })
)
.middle_of(self.ids.male) .middle_of(self.ids.male)
.hover_image(self.imgs.icon_border_mo) .hover_image(self.imgs.icon_border_mo)
.press_image(self.imgs.icon_border_press) .press_image(self.imgs.icon_border_press)
.set(self.ids.body_type_1, ui_widgets) .set(self.ids.body_type_1, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_body.body_type = humanoid::BodyType::Male; body.body_type = humanoid::BodyType::Male;
self.character_body.validate(); body.validate();
} }
// Female // Female
Image::new(self.imgs.female) Image::new(self.imgs.female)
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.top_right_with_margins_on(self.ids.creation_buttons_alignment_1, 0.0, 0.0) .top_right_with_margins_on(self.ids.creation_buttons_alignment_1, 0.0, 0.0)
.set(self.ids.female, ui_widgets); .set(self.ids.female, ui_widgets);
if Button::image( if Button::image(if let humanoid::BodyType::Female = body.body_type {
if let humanoid::BodyType::Female = self.character_body.body_type {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
}, })
)
.middle_of(self.ids.female) .middle_of(self.ids.female)
.hover_image(self.imgs.icon_border_mo) .hover_image(self.imgs.icon_border_mo)
.press_image(self.imgs.icon_border_press) .press_image(self.imgs.icon_border_press)
.set(self.ids.body_type_2, ui_widgets) .set(self.ids.body_type_2, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_body.body_type = humanoid::BodyType::Female; body.body_type = humanoid::BodyType::Female;
self.character_body.validate(); body.validate();
} }
// Alignment for Races and Tools // Alignment for Races and Tools
@ -769,7 +801,7 @@ impl CharSelectionUi {
.set(self.ids.creation_buttons_alignment_2, ui_widgets); .set(self.ids.creation_buttons_alignment_2, ui_widgets);
let (human_icon, orc_icon, dwarf_icon, elf_icon, undead_icon, danari_icon) = let (human_icon, orc_icon, dwarf_icon, elf_icon, undead_icon, danari_icon) =
match self.character_body.body_type { match body.body_type {
humanoid::BodyType::Male => ( humanoid::BodyType::Male => (
self.imgs.human_m, self.imgs.human_m,
self.imgs.orc_m, self.imgs.orc_m,
@ -792,7 +824,7 @@ impl CharSelectionUi {
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.top_left_with_margins_on(self.ids.creation_buttons_alignment_2, 0.0, 0.0) .top_left_with_margins_on(self.ids.creation_buttons_alignment_2, 0.0, 0.0)
.set(self.ids.human, ui_widgets); .set(self.ids.human, ui_widgets);
if Button::image(if let humanoid::Race::Human = self.character_body.race { if Button::image(if let humanoid::Race::Human = body.race {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -807,7 +839,7 @@ impl CharSelectionUi {
&tooltip_human, &tooltip_human,
) )
/*.tooltip_image( /*.tooltip_image(
if let humanoid::BodyType::Male = self.character_body.body_type { if let humanoid::BodyType::Male = body.body_type {
self.imgs.human_m self.imgs.human_m
} else { } else {
self.imgs.human_f self.imgs.human_f
@ -816,8 +848,8 @@ impl CharSelectionUi {
.set(self.ids.race_1, ui_widgets) .set(self.ids.race_1, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_body.race = humanoid::Race::Human; body.race = humanoid::Race::Human;
self.character_body.validate(); body.validate();
} }
// Orc // Orc
@ -825,7 +857,7 @@ impl CharSelectionUi {
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.right_from(self.ids.human, 2.0) .right_from(self.ids.human, 2.0)
.set(self.ids.orc, ui_widgets); .set(self.ids.orc, ui_widgets);
if Button::image(if let humanoid::Race::Orc = self.character_body.race { if Button::image(if let humanoid::Race::Orc = body.race {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -842,15 +874,15 @@ impl CharSelectionUi {
.set(self.ids.race_2, ui_widgets) .set(self.ids.race_2, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_body.race = humanoid::Race::Orc; body.race = humanoid::Race::Orc;
self.character_body.validate(); body.validate();
} }
// Dwarf // Dwarf
Image::new(dwarf_icon) Image::new(dwarf_icon)
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.right_from(self.ids.orc, 2.0) .right_from(self.ids.orc, 2.0)
.set(self.ids.dwarf, ui_widgets); .set(self.ids.dwarf, ui_widgets);
if Button::image(if let humanoid::Race::Dwarf = self.character_body.race { if Button::image(if let humanoid::Race::Dwarf = body.race {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -867,15 +899,15 @@ impl CharSelectionUi {
.set(self.ids.race_3, ui_widgets) .set(self.ids.race_3, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_body.race = humanoid::Race::Dwarf; body.race = humanoid::Race::Dwarf;
self.character_body.validate(); body.validate();
} }
// Elf // Elf
Image::new(elf_icon) Image::new(elf_icon)
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.down_from(self.ids.human, 2.0) .down_from(self.ids.human, 2.0)
.set(self.ids.elf, ui_widgets); .set(self.ids.elf, ui_widgets);
if Button::image(if let humanoid::Race::Elf = self.character_body.race { if Button::image(if let humanoid::Race::Elf = body.race {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -892,15 +924,16 @@ impl CharSelectionUi {
.set(self.ids.race_4, ui_widgets) .set(self.ids.race_4, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_body.race = humanoid::Race::Elf; body.race = humanoid::Race::Elf;
self.character_body.validate(); body.validate();
} }
// Undead // Undead
Image::new(undead_icon) Image::new(undead_icon)
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.right_from(self.ids.elf, 2.0) .right_from(self.ids.elf, 2.0)
.set(self.ids.undead, ui_widgets); .set(self.ids.undead, ui_widgets);
if Button::image(if let humanoid::Race::Undead = self.character_body.race { if Button::image(if let humanoid::Race::Undead = body.race {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -917,15 +950,15 @@ impl CharSelectionUi {
.set(self.ids.race_5, ui_widgets) .set(self.ids.race_5, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_body.race = humanoid::Race::Undead; body.race = humanoid::Race::Undead;
self.character_body.validate(); body.validate();
} }
// Danari // Danari
Image::new(danari_icon) Image::new(danari_icon)
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.right_from(self.ids.undead, 2.0) .right_from(self.ids.undead, 2.0)
.set(self.ids.danari, ui_widgets); .set(self.ids.danari, ui_widgets);
if Button::image(if let humanoid::Race::Danari = self.character_body.race { if Button::image(if let humanoid::Race::Danari = body.race {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -942,17 +975,16 @@ impl CharSelectionUi {
.set(self.ids.race_6, ui_widgets) .set(self.ids.race_6, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_body.race = humanoid::Race::Danari; body.race = humanoid::Race::Danari;
self.character_body.validate(); body.validate();
} }
// Hammer // Hammer
Image::new(self.imgs.hammer) Image::new(self.imgs.hammer)
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.bottom_left_with_margins_on(self.ids.creation_buttons_alignment_2, 0.0, 0.0) .bottom_left_with_margins_on(self.ids.creation_buttons_alignment_2, 0.0, 0.0)
.set(self.ids.hammer, ui_widgets); .set(self.ids.hammer, ui_widgets);
if Button::image(if let Some(STARTER_HAMMER) = self.character_tool { if Button::image(if let Some(STARTER_HAMMER) = tool {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -969,7 +1001,7 @@ impl CharSelectionUi {
.set(self.ids.hammer_button, ui_widgets) .set(self.ids.hammer_button, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_tool = Some(STARTER_HAMMER); *tool = Some(STARTER_HAMMER);
} }
// REMOVE THIS AFTER IMPLEMENTATION // REMOVE THIS AFTER IMPLEMENTATION
/*Rectangle::fill_with([67.0, 67.0], color::rgba(0.0, 0.0, 0.0, 0.8)) /*Rectangle::fill_with([67.0, 67.0], color::rgba(0.0, 0.0, 0.0, 0.8))
@ -977,12 +1009,11 @@ impl CharSelectionUi {
.set(self.ids.hammer_grey, ui_widgets);*/ .set(self.ids.hammer_grey, ui_widgets);*/
// Bow // Bow
Image::new(self.imgs.bow) Image::new(self.imgs.bow)
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.right_from(self.ids.hammer, 2.0) .right_from(self.ids.hammer, 2.0)
.set(self.ids.bow, ui_widgets); .set(self.ids.bow, ui_widgets);
if Button::image(if let Some(STARTER_BOW) = self.character_tool { if Button::image(if let Some(STARTER_BOW) = tool {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -999,7 +1030,7 @@ impl CharSelectionUi {
.set(self.ids.bow_button, ui_widgets) .set(self.ids.bow_button, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_tool = Some(STARTER_BOW); *tool = Some(STARTER_BOW);
} }
// REMOVE THIS AFTER IMPLEMENTATION // REMOVE THIS AFTER IMPLEMENTATION
/*Rectangle::fill_with([67.0, 67.0], color::rgba(0.0, 0.0, 0.0, 0.8)) /*Rectangle::fill_with([67.0, 67.0], color::rgba(0.0, 0.0, 0.0, 0.8))
@ -1010,7 +1041,7 @@ impl CharSelectionUi {
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.right_from(self.ids.bow, 2.0) .right_from(self.ids.bow, 2.0)
.set(self.ids.staff, ui_widgets); .set(self.ids.staff, ui_widgets);
if Button::image(if let Some(STARTER_STAFF) = self.character_tool { if Button::image(if let Some(STARTER_STAFF) = tool {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -1027,7 +1058,7 @@ impl CharSelectionUi {
.set(self.ids.staff_button, ui_widgets) .set(self.ids.staff_button, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_tool = Some(STARTER_STAFF); *tool = Some(STARTER_STAFF);
} }
// REMOVE THIS AFTER IMPLEMENTATION // REMOVE THIS AFTER IMPLEMENTATION
/*Rectangle::fill_with([67.0, 67.0], color::rgba(0.0, 0.0, 0.0, 0.8)) /*Rectangle::fill_with([67.0, 67.0], color::rgba(0.0, 0.0, 0.0, 0.8))
@ -1038,7 +1069,7 @@ impl CharSelectionUi {
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.up_from(self.ids.hammer, 2.0) .up_from(self.ids.hammer, 2.0)
.set(self.ids.sword, ui_widgets); .set(self.ids.sword, ui_widgets);
if Button::image(if let Some(STARTER_SWORD) = self.character_tool { if Button::image(if let Some(STARTER_SWORD) = tool {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -1055,7 +1086,7 @@ impl CharSelectionUi {
.set(self.ids.sword_button, ui_widgets) .set(self.ids.sword_button, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_tool = Some(STARTER_SWORD); *tool = Some(STARTER_SWORD);
} }
// Daggers // Daggers
@ -1063,7 +1094,7 @@ impl CharSelectionUi {
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.right_from(self.ids.sword, 2.0) .right_from(self.ids.sword, 2.0)
.set(self.ids.daggers, ui_widgets); .set(self.ids.daggers, ui_widgets);
if Button::image(if let Some(STARTER_DAGGER) = self.character_tool { if Button::image(if let Some(STARTER_DAGGER) = tool {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -1086,7 +1117,7 @@ impl CharSelectionUi {
.w_h(70.0, 70.0) .w_h(70.0, 70.0)
.right_from(self.ids.daggers, 2.0) .right_from(self.ids.daggers, 2.0)
.set(self.ids.axe, ui_widgets); .set(self.ids.axe, ui_widgets);
if Button::image(if let Some(STARTER_AXE) = self.character_tool { if Button::image(if let Some(STARTER_AXE) = tool {
self.imgs.icon_border_pressed self.imgs.icon_border_pressed
} else { } else {
self.imgs.icon_border self.imgs.icon_border
@ -1103,7 +1134,7 @@ impl CharSelectionUi {
.set(self.ids.axe_button, ui_widgets) .set(self.ids.axe_button, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.character_tool = Some(STARTER_AXE); *tool = Some(STARTER_AXE);
} }
// REMOVE THIS AFTER IMPLEMENTATION // REMOVE THIS AFTER IMPLEMENTATION
/*Rectangle::fill_with([67.0, 67.0], color::rgba(0.0, 0.0, 0.0, 0.8)) /*Rectangle::fill_with([67.0, 67.0], color::rgba(0.0, 0.0, 0.0, 0.8))
@ -1123,7 +1154,7 @@ impl CharSelectionUi {
selected_val, selected_val,
slider_id, slider_id,
ui_widgets: &mut UiCell| { ui_widgets: &mut UiCell| {
Text::new(&text.clone()) Text::new(&text)
.down_from(prev_id, 22.0) .down_from(prev_id, 22.0)
.align_middle_x_of(prev_id) .align_middle_x_of(prev_id)
.font_size(18) .font_size(18)
@ -1144,42 +1175,39 @@ impl CharSelectionUi {
self.ids.creation_buttons_alignment_2, self.ids.creation_buttons_alignment_2,
localized_strings.get("char_selection.hair_style"), localized_strings.get("char_selection.hair_style"),
self.ids.hairstyle_text, self.ids.hairstyle_text,
self.character_body body.race.num_hair_styles(body.body_type) as usize - 1,
.race body.hair_style as usize,
.num_hair_styles(self.character_body.body_type) as usize
- 1,
self.character_body.hair_style as usize,
self.ids.hairstyle_slider, self.ids.hairstyle_slider,
ui_widgets, ui_widgets,
) { ) {
self.character_body.hair_style = new_val as u8; body.hair_style = new_val as u8;
} }
// Hair Color // Hair Color
if let Some(new_val) = char_slider( if let Some(new_val) = char_slider(
self.ids.hairstyle_slider, self.ids.hairstyle_slider,
localized_strings.get("char_selection.hair_color"), localized_strings.get("char_selection.hair_color"),
self.ids.haircolor_text, self.ids.haircolor_text,
self.character_body.race.num_hair_colors() as usize - 1, body.race.num_hair_colors() as usize - 1,
self.character_body.hair_color as usize, body.hair_color as usize,
self.ids.haircolor_slider, self.ids.haircolor_slider,
ui_widgets, ui_widgets,
) { ) {
self.character_body.hair_color = new_val as u8; body.hair_color = new_val as u8;
} }
// Skin // Skin
if let Some(new_val) = char_slider( if let Some(new_val) = char_slider(
self.ids.haircolor_slider, self.ids.haircolor_slider,
localized_strings.get("char_selection.skin"), localized_strings.get("char_selection.skin"),
self.ids.skin_text, self.ids.skin_text,
self.character_body.race.num_skin_colors() as usize - 1, body.race.num_skin_colors() as usize - 1,
self.character_body.skin as usize, body.skin as usize,
self.ids.skin_slider, self.ids.skin_slider,
ui_widgets, ui_widgets,
) { ) {
self.character_body.skin = new_val as u8; body.skin = new_val as u8;
} }
// Eyebrows // Eyebrows
let current_eyebrows = self.character_body.eyebrows; let current_eyebrows = body.eyebrows;
if let Some(new_val) = char_slider( if let Some(new_val) = char_slider(
self.ids.skin_slider, self.ids.skin_slider,
localized_strings.get("char_selection.eyebrows"), localized_strings.get("char_selection.eyebrows"),
@ -1192,56 +1220,45 @@ impl CharSelectionUi {
self.ids.eyebrows_slider, self.ids.eyebrows_slider,
ui_widgets, ui_widgets,
) { ) {
self.character_body.eyebrows = humanoid::ALL_EYEBROWS[new_val]; body.eyebrows = humanoid::ALL_EYEBROWS[new_val];
} }
// EyeColor // EyeColor
if let Some(new_val) = char_slider( if let Some(new_val) = char_slider(
self.ids.eyebrows_slider, self.ids.eyebrows_slider,
localized_strings.get("char_selection.eye_color"), localized_strings.get("char_selection.eye_color"),
self.ids.eyecolor_text, self.ids.eyecolor_text,
self.character_body.race.num_eye_colors() as usize - 1, body.race.num_eye_colors() as usize - 1,
self.character_body.eye_color as usize, body.eye_color as usize,
self.ids.eyecolor_slider, self.ids.eyecolor_slider,
ui_widgets, ui_widgets,
) { ) {
self.character_body.eye_color = new_val as u8; body.eye_color = new_val as u8;
} }
// Accessories // Accessories
let _current_accessory = self.character_body.accessory; let _current_accessory = body.accessory;
if let Some(new_val) = char_slider( if let Some(new_val) = char_slider(
self.ids.eyecolor_slider, self.ids.eyecolor_slider,
localized_strings.get("char_selection.accessories"), localized_strings.get("char_selection.accessories"),
self.ids.accessories_text, self.ids.accessories_text,
self.character_body body.race.num_accessories(body.body_type) as usize - 1,
.race body.accessory as usize,
.num_accessories(self.character_body.body_type) as usize
- 1,
self.character_body.accessory as usize,
self.ids.accessories_slider, self.ids.accessories_slider,
ui_widgets, ui_widgets,
) { ) {
self.character_body.accessory = new_val as u8; body.accessory = new_val as u8;
} }
// Beard // Beard
if self if body.race.num_beards(body.body_type) > 1 {
.character_body
.race
.num_beards(self.character_body.body_type)
> 1
{
if let Some(new_val) = char_slider( if let Some(new_val) = char_slider(
self.ids.accessories_slider, self.ids.accessories_slider,
localized_strings.get("char_selection.beard"), localized_strings.get("char_selection.beard"),
self.ids.beard_text, self.ids.beard_text,
self.character_body body.race.num_beards(body.body_type) as usize - 1,
.race body.beard as usize,
.num_beards(self.character_body.body_type) as usize
- 1,
self.character_body.beard as usize,
self.ids.beard_slider, self.ids.beard_slider,
ui_widgets, ui_widgets,
) { ) {
self.character_body.beard = new_val as u8; body.beard = new_val as u8;
} }
} else { } else {
Text::new(&localized_strings.get("char_selection.beard")) Text::new(&localized_strings.get("char_selection.beard"))
@ -1261,7 +1278,7 @@ impl CharSelectionUi {
.set(self.ids.beard_slider, ui_widgets); .set(self.ids.beard_slider, ui_widgets);
} }
// Chest // Chest
let current_chest = self.character_body.chest; let current_chest = body.chest;
if let Some(new_val) = char_slider( if let Some(new_val) = char_slider(
self.ids.beard_slider, self.ids.beard_slider,
localized_strings.get("char_selection.chest_color"), localized_strings.get("char_selection.chest_color"),
@ -1274,10 +1291,10 @@ impl CharSelectionUi {
self.ids.chest_slider, self.ids.chest_slider,
ui_widgets, ui_widgets,
) { ) {
self.character_body.chest = humanoid::ALL_CHESTS[new_val]; body.chest = humanoid::ALL_CHESTS[new_val];
} }
// Pants // Pants
/*let current_pants = self.character_body.pants; /*let current_pants = body.pants;
if let Some(new_val) = char_slider( if let Some(new_val) = char_slider(
self.ids.chest_slider, self.ids.chest_slider,
"Pants", "Pants",
@ -1290,12 +1307,17 @@ impl CharSelectionUi {
self.ids.pants_slider, self.ids.pants_slider,
ui_widgets, ui_widgets,
) { ) {
self.character_body.pants = humanoid::ALL_PANTS[new_val]; body.pants = humanoid::ALL_PANTS[new_val];
}*/ }*/
Rectangle::fill_with([20.0, 20.0], color::TRANSPARENT) Rectangle::fill_with([20.0, 20.0], color::TRANSPARENT)
.down_from(self.ids.chest_slider, 15.0) .down_from(self.ids.chest_slider, 15.0)
.set(self.ids.space, ui_widgets); .set(self.ids.space, ui_widgets);
if to_select {
self.mode = Mode::Select(None);
}
} // Char Creation fin } // Char Creation fin
}
events events
} }

View File

@ -9,6 +9,7 @@ use std::{fs, io, path::PathBuf};
pub struct CharacterData { pub struct CharacterData {
pub name: String, pub name: String,
pub body: comp::Body, pub body: comp::Body,
pub tool: Option<String>,
} }
#[derive(Clone, Debug, Default, Serialize, Deserialize)] #[derive(Clone, Debug, Default, Serialize, Deserialize)]