diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index ecd6f5224a..160bbc7914 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -100,7 +100,7 @@ fn main() { // Set up the initial play state let mut states: Vec> = vec![Box::new(MainMenuState::new( - &mut global_state.window, + &mut global_state, ))]; states.last().map(|current_state| { log::info!("Started game with state '{}'", current_state.name()) diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 9baba60a47..058bad125a 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -21,9 +21,9 @@ pub struct MainMenuState { impl MainMenuState { /// Create a new `MainMenuState` - pub fn new(window: &mut Window) -> Self { + pub fn new(global_state: &mut GlobalState) -> Self { Self { - main_menu_ui: MainMenuUi::new(window), + main_menu_ui: MainMenuUi::new(global_state), } } } @@ -92,6 +92,12 @@ impl PlayState for MainMenuState { username, server_address, } => { + let mut net_settings = &mut global_state.settings.networking; + net_settings.username = username.clone(); + if !net_settings.servers.contains(&server_address) { + net_settings.servers.push(server_address.clone()); + } + global_state.settings.save_to_file(); const DEFAULT_PORT: u16 = 59003; // Don't try to connect if there is already a connection in progress client_init = client_init.or(Some(ClientInit::new( diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index d14e75686e..030d96360d 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -3,6 +3,7 @@ use crate::{ ui::{self, ScaleMode, Ui}, window::Window, DEFAULT_PUBLIC_SERVER, + GlobalState, }; use common::{ assets, @@ -137,7 +138,9 @@ pub struct MainMenuUi { } impl MainMenuUi { - pub fn new(window: &mut Window) -> Self { + pub fn new(global_state: &mut GlobalState) -> Self { + let mut window = &mut global_state.window; + let networking = &global_state.settings.networking; let mut ui = Ui::new(window).unwrap(); // TODO: adjust/remove this, right now it is used to demonstrate window scaling functionality ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into())); @@ -162,8 +165,8 @@ impl MainMenuUi { ids, font_metamorph, font_opensans, - username: "Username".to_string(), - server_address: DEFAULT_PUBLIC_SERVER.to_string(), + username: networking.username.clone(), + server_address, login_error: None, connecting: None, } @@ -352,7 +355,6 @@ impl MainMenuUi { .was_clicked() { singleplayer!(); - login!(); } // Quit if Button::image(self.imgs.button) diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 86d90cb446..9b4205972b 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -14,6 +14,7 @@ use std::default::Default; #[serde(default)] pub struct Settings { pub controls: ControlSettings, + pub networking: NetworkingSettings, } /// ControlSettings contains keybindings @@ -37,6 +38,13 @@ pub struct ControlSettings { pub toggle_interface: VirtualKeyCode, } +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct NetworkingSettings { + pub username: String, + pub servers: Vec, + pub default_server: usize, +} + impl Default for Settings { fn default() -> Self { Settings { @@ -58,6 +66,11 @@ impl Default for Settings { help: VirtualKeyCode::F1, toggle_interface: VirtualKeyCode::F2, }, + networking: NetworkingSettings { + username: "Username".to_string(), + servers: vec!("server.veloren.net".to_string()), + default_server: 0, + }, } }