Character Creation Randomization Fix

This commit is contained in:
Scott Williams 2021-03-27 15:58:34 +00:00 committed by Marcel
parent da5c73c84b
commit 9ca0388561
3 changed files with 51 additions and 20 deletions

View File

@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Seperated character randomization buttons into appearance and name.
### Removed ### Removed
### Fixed ### Fixed

View File

@ -64,7 +64,8 @@ Is the client up to date?"#,
"common.weapons.hammer": "Hammer", "common.weapons.hammer": "Hammer",
"common.weapons.general": "General Combat", "common.weapons.general": "General Combat",
"common.weapons.sceptre": "Healing Sceptre", "common.weapons.sceptre": "Healing Sceptre",
"common.rand_appearance": "Random appearance and name", "common.rand_appearance": "Random appearance",
"common.rand_name": "Random name",
}, },

View File

@ -159,7 +159,8 @@ enum Mode {
name_input: text_input::State, name_input: text_input::State,
back_button: button::State, back_button: button::State,
create_button: button::State, create_button: button::State,
randomize_button: button::State, rand_character_button: button::State,
rand_name_button: button::State,
}, },
} }
@ -200,7 +201,8 @@ impl Mode {
name_input: Default::default(), name_input: Default::default(),
back_button: Default::default(), back_button: Default::default(),
create_button: Default::default(), create_button: Default::default(),
randomize_button: Default::default(), rand_character_button: Default::default(),
rand_name_button: Default::default(),
} }
} }
} }
@ -244,6 +246,7 @@ enum Message {
Species(humanoid::Species), Species(humanoid::Species),
Tool(&'static str), Tool(&'static str),
RandomizeCharacter, RandomizeCharacter,
RandomizeName,
CancelDeletion, CancelDeletion,
ConfirmDeletion, ConfirmDeletion,
ClearCharacterListError, ClearCharacterListError,
@ -548,7 +551,7 @@ impl Controls {
]) ])
.height(Length::Fill); .height(Length::Fill);
let right_column = Column::with_children(vec![server.into(), characters.into()]) let left_column = Column::with_children(vec![server.into(), characters.into()])
.spacing(10) .spacing(10)
.width(Length::Units(322)) // TODO: see if we can get iced to work with settings below .width(Length::Units(322)) // TODO: see if we can get iced to work with settings below
//.max_width(360) //.max_width(360)
@ -556,7 +559,7 @@ impl Controls {
.height(Length::Fill); .height(Length::Fill);
let top = Row::with_children(vec![ let top = Row::with_children(vec![
right_column.into(), left_column.into(),
MouseDetector::new(&mut self.mouse_detector, Length::Fill, Length::Fill).into(), MouseDetector::new(&mut self.mouse_detector, Length::Fill, Length::Fill).into(),
]) ])
.padding(15) .padding(15)
@ -699,7 +702,8 @@ impl Controls {
ref mut name_input, ref mut name_input,
ref mut back_button, ref mut back_button,
ref mut create_button, ref mut create_button,
ref mut randomize_button, ref mut rand_character_button,
ref mut rand_name_button,
} => { } => {
let unselected_style = style::button::Style::new(imgs.icon_border) let unselected_style = style::button::Style::new(imgs.icon_border)
.hover_image(imgs.icon_border_mo) .hover_image(imgs.icon_border_mo)
@ -1038,14 +1042,30 @@ impl Controls {
.max_width(200) .max_width(200)
.padding(5); .padding(5);
const CHAR_DICE_SIZE: u16 = 50;
let rand_character = Button::new(
rand_character_button,
Space::new(Length::Units(CHAR_DICE_SIZE), Length::Units(CHAR_DICE_SIZE)),
)
.style(
style::button::Style::new(imgs.dice)
.hover_image(imgs.dice_hover)
.press_image(imgs.dice_press),
)
.on_press(Message::RandomizeCharacter)
.with_tooltip(tooltip_manager, move || {
tooltip::text(i18n.get("common.rand_appearance"), tooltip_style)
});
let column_content = vec![ let column_content = vec![
body_type.into(), body_type.into(),
species.into(), species.into(),
tool.into(), tool.into(),
slider_options.into(), slider_options.into(),
rand_character.into(),
]; ];
let right_column = Container::new( let left_column = Container::new(
Scrollable::new(scroll) Scrollable::new(scroll)
.push( .push(
Column::with_children(column_content) Column::with_children(column_content)
@ -1066,8 +1086,8 @@ impl Controls {
//.width(Length::Fill) //.width(Length::Fill)
.height(Length::Fill); .height(Length::Fill);
let right_column = Column::with_children(vec![ let left_column = Column::with_children(vec![
Container::new(right_column) Container::new(left_column)
.style(style::container::Style::color(Rgba::from_translucent( .style(style::container::Style::color(Rgba::from_translucent(
0, 0,
BANNER_ALPHA, BANNER_ALPHA,
@ -1084,7 +1104,7 @@ impl Controls {
.height(Length::Fill); .height(Length::Fill);
let top = Row::with_children(vec![ let top = Row::with_children(vec![
right_column.into(), left_column.into(),
MouseDetector::new(&mut self.mouse_detector, Length::Fill, Length::Fill).into(), MouseDetector::new(&mut self.mouse_detector, Length::Fill, Length::Fill).into(),
]) ])
.padding(10) .padding(10)
@ -1099,19 +1119,19 @@ impl Controls {
Some(Message::Back), Some(Message::Back),
); );
const DICE_SIZE: u16 = 35; const NAME_DICE_SIZE: u16 = 35;
let randomize = Button::new( let rand_name = Button::new(
randomize_button, rand_name_button,
Space::new(Length::Units(DICE_SIZE), Length::Units(DICE_SIZE)), Space::new(Length::Units(NAME_DICE_SIZE), Length::Units(NAME_DICE_SIZE)),
) )
.style( .style(
style::button::Style::new(imgs.dice) style::button::Style::new(imgs.dice)
.hover_image(imgs.dice_hover) .hover_image(imgs.dice_hover)
.press_image(imgs.dice_press), .press_image(imgs.dice_press),
) )
.on_press(Message::RandomizeCharacter) .on_press(Message::RandomizeName)
.with_tooltip(tooltip_manager, move || { .with_tooltip(tooltip_manager, move || {
tooltip::text(i18n.get("common.rand_appearance"), tooltip_style) tooltip::text(i18n.get("common.rand_name"), tooltip_style)
}); });
let name_input = BackgroundContainer::new( let name_input = BackgroundContainer::new(
@ -1131,9 +1151,10 @@ impl Controls {
let bottom_center = Container::new( let bottom_center = Container::new(
Row::with_children(vec![ Row::with_children(vec![
randomize.into(), rand_name.into(),
name_input.into(), name_input.into(),
Space::new(Length::Units(DICE_SIZE), Length::Units(DICE_SIZE)).into(), Space::new(Length::Units(NAME_DICE_SIZE), Length::Units(NAME_DICE_SIZE))
.into(),
]) ])
.align_items(Align::Center) .align_items(Align::Center)
.spacing(5) .spacing(5)
@ -1270,9 +1291,9 @@ impl Controls {
); );
} }
}, },
//Todo: Add species and body type to randomization.
Message::RandomizeCharacter => { Message::RandomizeCharacter => {
if let Mode::Create { name, body, .. } = &mut self.mode { if let Mode::Create { body, .. } = &mut self.mode {
use common::npc;
use rand::Rng; use rand::Rng;
let body_type = body.body_type; let body_type = body.body_type;
let species = body.species; let species = body.species;
@ -1284,12 +1305,19 @@ impl Controls {
body.skin = rng.gen_range(0..species.num_skin_colors()); body.skin = rng.gen_range(0..species.num_skin_colors());
body.eye_color = rng.gen_range(0..species.num_eye_colors()); body.eye_color = rng.gen_range(0..species.num_eye_colors());
body.eyes = rng.gen_range(0..species.num_eyes(body_type)); body.eyes = rng.gen_range(0..species.num_eyes(body_type));
}
},
Message::RandomizeName => {
if let Mode::Create { name, body, .. } = &mut self.mode {
use common::npc;
*name = npc::get_npc_name( *name = npc::get_npc_name(
npc::NpcKind::Humanoid, npc::NpcKind::Humanoid,
npc::BodyType::from_body(comp::Body::Humanoid(*body)), npc::BodyType::from_body(comp::Body::Humanoid(*body)),
); );
} }
}, },
Message::ConfirmDeletion => { Message::ConfirmDeletion => {
if let Mode::Select { info_content, .. } = &mut self.mode { if let Mode::Select { info_content, .. } = &mut self.mode {
if let Some(InfoContent::Deletion(idx)) = info_content { if let Some(InfoContent::Deletion(idx)) = info_content {