mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add networksettings and integrate with main menu ui
Former-commit-id: f04532e03f8262b9751ae4a68259637f7de0344c
This commit is contained in:
parent
f85e3546cf
commit
15c2cdb2ef
@ -100,7 +100,7 @@ fn main() {
|
||||
|
||||
// Set up the initial play state
|
||||
let mut states: Vec<Box<dyn PlayState>> = 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())
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
|
@ -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<String>,
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user