Skip to content

Commit

Permalink
Improve toast event scheduling (#641)
Browse files Browse the repository at this point in the history
All toast events are sent from `Update` base set. This change removes
the need to schedule the sending events
`.before(ToastSet::ProcessEvents)` and reduces the opportunity for
future one-frame-delay errors.
  • Loading branch information
Indy2222 authored Jul 24, 2023
1 parent 7f9d89b commit 264871d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crates/gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use text::TextPlugin;
pub use text::TextProps;
use textbox::TextBoxPlugin;
pub use textbox::{TextBoxCommands, TextBoxQuery};
pub use toast::ToastEvent;
use toast::ToastPlugin;
pub use toast::{ToastEvent, ToastSet};

mod body_text;
mod button;
Expand Down
11 changes: 7 additions & 4 deletions crates/gui/src/toast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@ impl Plugin for ToastPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<ToastQueue>()
.add_event::<ToastEvent>()
.add_system(process_events.in_set(ToastSet::ProcessEvents))
.add_system(
process_events
.in_base_set(CoreSet::PostUpdate)
.in_set(ToastSet::ProcessEvents),
)
.add_system(
spawn_and_despawn
.in_base_set(CoreSet::PostUpdate)
.run_if(not(in_state(AppState::AppLoading)))
.after(ToastSet::ProcessEvents),
);
}
}

#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, SystemSet)]
pub enum ToastSet {
enum ToastSet {
ProcessEvents,
}

/// Send this event to briefly display a UI toast.
///
/// The events are processed by a system labeled [`ToastSet::ProcessEvents`].
pub struct ToastEvent(String);

impl ToastEvent {
Expand Down
8 changes: 2 additions & 6 deletions crates/menu/src/gamelisting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use bevy::{prelude::*, time::Stopwatch};
use de_gui::{ButtonCommands, GuiCommands, LabelCommands, OuterStyle, ToastEvent, ToastSet};
use de_gui::{ButtonCommands, GuiCommands, LabelCommands, OuterStyle, ToastEvent};
use de_lobby_client::{ListGamesRequest, RequestEvent, ResponseEvent};
use de_lobby_model::GamePartial;

Expand All @@ -16,11 +16,7 @@ impl Plugin for GameListingPlugin {
app.add_system(setup.in_schedule(OnEnter(MenuState::GameListing)))
.add_system(cleanup.in_schedule(OnExit(MenuState::GameListing)))
.add_system(refresh_system.run_if(in_state(MenuState::GameListing)))
.add_system(
list_games_system
.run_if(in_state(MenuState::GameListing))
.before(ToastSet::ProcessEvents),
)
.add_system(list_games_system.run_if(in_state(MenuState::GameListing)))
.add_system(button_system.run_if(in_state(MenuState::GameListing)));
}
}
Expand Down
14 changes: 3 additions & 11 deletions crates/menu/src/signin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::prelude::*;
use de_gui::{
ButtonCommands, GuiCommands, LabelCommands, OuterStyle, SetFocusEvent, TextBoxCommands,
TextBoxQuery, ToastEvent, ToastSet,
TextBoxQuery, ToastEvent,
};
use de_lobby_client::{Authentication, LobbyRequest, SignInRequest, SignUpRequest};
use de_lobby_model::{User, UserWithPassword, UsernameAndPassword};
Expand All @@ -25,16 +25,8 @@ impl Plugin for SignInPlugin {
.run_if(resource_exists::<Inputs>())
.run_if(in_state(MenuState::SignIn)),
)
.add_system(
response_system::<SignInRequest>
.run_if(in_state(MenuState::SignIn))
.before(ToastSet::ProcessEvents),
)
.add_system(
response_system::<SignUpRequest>
.run_if(in_state(MenuState::SignIn))
.before(ToastSet::ProcessEvents),
)
.add_system(response_system::<SignInRequest>.run_if(in_state(MenuState::SignIn)))
.add_system(response_system::<SignUpRequest>.run_if(in_state(MenuState::SignIn)))
.add_system(auth_system.run_if(in_state(MenuState::SignIn)));
}
}
Expand Down

0 comments on commit 264871d

Please sign in to comment.