From b360143b42ff42f6c5e7fcb95044d4ae8a15e16a Mon Sep 17 00:00:00 2001 From: mdx97 <mathewhorner456@gmail.com> Date: Sat, 10 Apr 2021 16:41:46 +0000 Subject: [PATCH] Use username as default character name in multiplayer character creation. --- voxygen/src/menu/char_selection/ui/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/voxygen/src/menu/char_selection/ui/mod.rs b/voxygen/src/menu/char_selection/ui/mod.rs index bfdf96cdd9..b3f0e5ce05 100644 --- a/voxygen/src/menu/char_selection/ui/mod.rs +++ b/voxygen/src/menu/char_selection/ui/mod.rs @@ -146,7 +146,7 @@ enum Mode { no_button: button::State, }, Create { - name: String, // TODO: default to username + name: String, body: humanoid::Body, inventory: Box<comp::inventory::Inventory>, tool: &'static str, @@ -230,6 +230,7 @@ struct Controls { mode: Mode, // Id of the selected character selected: Option<CharacterId>, + default_name: String, } #[derive(Clone)] @@ -263,7 +264,7 @@ enum Message { } impl Controls { - fn new(fonts: Fonts, imgs: Imgs, selected: Option<CharacterId>) -> Self { + fn new(fonts: Fonts, imgs: Imgs, selected: Option<CharacterId>, default_name: String) -> Self { let version = common::util::DISPLAY_VERSION_LONG.clone(); let alpha = format!("Veloren {}", common::util::DISPLAY_VERSION.as_str()); @@ -277,6 +278,7 @@ impl Controls { mouse_detector: Default::default(), mode: Mode::select(Some(InfoContent::LoadingCharacters)), selected, + default_name, } } @@ -1246,7 +1248,7 @@ impl Controls { }, Message::NewCharacter => { if matches!(&self.mode, Mode::Select { .. }) { - self.mode = Mode::create(String::new()); + self.mode = Mode::create(self.default_name.clone()); } }, Message::CreateCharacter => { @@ -1435,10 +1437,20 @@ impl CharSelectionUi { let fonts = Fonts::load(&i18n.fonts, &mut ui).expect("Impossible to load fonts"); + #[cfg(feature = "singleplayer")] + let default_name = match global_state.singleplayer { + Some(_) => String::new(), + None => global_state.settings.networking.username.clone(), + }; + + #[cfg(not(feature = "singleplayer"))] + let default_name = global_state.settings.networking.username.clone(); + let controls = Controls::new( fonts, Imgs::load(&mut ui).expect("Failed to load images"), selected_character, + default_name, ); Self {