Switch states instead of popping

This commit is contained in:
Capucho 2020-03-08 20:31:27 +00:00
parent 5fe9521233
commit 16e4214a52
3 changed files with 9 additions and 14 deletions

View File

@ -78,8 +78,6 @@ pub struct Client {
loaded_distance: f32,
pending_chunks: HashMap<Vec2<i32>, Instant>,
disconnected: bool,
}
impl Client {
@ -166,8 +164,6 @@ impl Client {
loaded_distance: 0.0,
pending_chunks: HashMap::new(),
disconnected: false,
})
}
@ -722,7 +718,6 @@ impl Client {
);
},
ServerMsg::Disconnect => {
self.disconnected = true;
frontend_events.push(Event::Disconnect);
self.postbox.send_message(ClientMsg::Terminate);
},
@ -737,9 +732,6 @@ impl Client {
Ok(frontend_events)
}
// Get's whether or not the client just disconnected
pub fn disconnected(&self) -> bool { self.disconnected }
/// Get the player's entity.
pub fn entity(&self) -> EcsEntity { self.entity }

View File

@ -39,11 +39,6 @@ impl PlayState for CharSelectionState {
// Set up an fps clock.
let mut clock = Clock::start();
// Check if we just disconnected, if so go to main menu
if self.client.borrow().disconnected() {
return PlayStateResult::Pop;
}
let mut current_client_state = self.client.borrow().get_client_state();
while let ClientState::Pending | ClientState::Registered = current_client_state {
// Handle window events
@ -83,7 +78,7 @@ impl PlayState for CharSelectionState {
char_data.body,
char_data.tool,
);
return PlayStateResult::Push(Box::new(SessionState::new(
return PlayStateResult::Switch(Box::new(SessionState::new(
global_state,
self.client.clone(),
)));

View File

@ -3,6 +3,7 @@ use crate::{
hud::{DebugInfo, Event as HudEvent, Hud},
i18n::{i18n_asset_key, VoxygenLocalization},
key_state::KeyState,
menu::char_selection::CharSelectionState,
render::Renderer,
scene::{camera, Scene, SceneData},
window::{Event, GameInput},
@ -680,6 +681,13 @@ impl PlayState for SessionState {
current_client_state = self.client.borrow().get_client_state();
}
if let ClientState::Registered = current_client_state {
return PlayStateResult::Switch(Box::new(CharSelectionState::new(
global_state,
self.client.clone(),
)));
}
PlayStateResult::Pop
}