pub struct ScreenStack<G: GameData> { /* private fields */ }Expand description
The stack of open screens. Only the top screen is updated; drawing starts at the top-most opaque screen and goes up through the overlays above it.
Implementations§
Source§impl<G: GameData> ScreenStack<G>
impl<G: GameData> ScreenStack<G>
Sourcepub fn guard_actions(&mut self, on: bool)
pub fn guard_actions(&mut self, on: bool)
Turns the guard on or off: while it is on, a screen that declares
its actions (Screen::actions) is handed only those
(FrameInput::declared), and the others are logged
(undeclared). So a test of a screen that reacts
to an action it didn’t declare fails. The test Harness turns it on;
a game never needs to.
Sourcepub fn undeclared(&self) -> &[(&'static str, G::Action)]
pub fn undeclared(&self) -> &[(&'static str, G::Action)]
Every action held back from a screen that doesn’t declare it while the guard was on, oldest first, with the screen’s name. A player pressing a key the screen has no use for lands here too: it says why a screen didn’t react, not that it is wrong.
Sourcepub fn top_actions(&self) -> Option<Vec<G::Action>>
pub fn top_actions(&self) -> Option<Vec<G::Action>>
The actions the top screen declares it reacts to
(Screen::actions), if it declares them.
Sourcepub fn push(&mut self, screen: Box<dyn Screen<G>>)
pub fn push(&mut self, screen: Box<dyn Screen<G>>)
Puts screen on top, to build a stack: the screen below is not
told (Screen::covered); apply_in with
Transition::Push tells it.
Sourcepub fn find<T: Any>(&self) -> Option<&T>
pub fn find<T: Any>(&self) -> Option<&T>
The top-most screen of type T (one that opts in with
Screen::as_any).
Sourcepub fn state_hash(&self) -> Option<StateHash>
pub fn state_hash(&self) -> Option<StateHash>
The top-most screen’s Screen::state_hash that has one.
Sourcepub fn find_mut<T: Any>(&mut self) -> Option<&mut T>
pub fn find_mut<T: Any>(&mut self) -> Option<&mut T>
The top-most screen of type T, mutable (Screen::as_any_mut).
Sourcepub fn update(
&mut self,
ctx: &mut Ctx<G>,
input: &FrameInput<G::Action>,
) -> bool
pub fn update( &mut self, ctx: &mut Ctx<G>, input: &FrameInput<G::Action>, ) -> bool
Updates the top screen and applies its transition
(apply_in). Returns true if the game should
quit (Transition::Quit, or the last screen popped). Does nothing
and returns true on an empty stack.
Sourcepub fn apply_in(&mut self, ctx: &mut Ctx<G>, transition: Transition<G>) -> bool
pub fn apply_in(&mut self, ctx: &mut Ctx<G>, transition: Transition<G>) -> bool
Applies a transition as if the top screen had returned it, telling
the screens it covers and uncovers: a push calls the old top’s
Screen::covered; a pop calls the new top’s
Screen::uncovered with what the screen popped with, then applies
the transition that returns, and so on. A replace tells nobody.
A screen that leaves (a pop or a replace) takes its sounds with it
(AudioQueue::start_sound). Returns true if the game should
quit.
Sourcepub fn apply(&mut self, transition: Transition<G>) -> bool
pub fn apply(&mut self, transition: Transition<G>) -> bool
Applies a transition as if the top screen had returned it, to the
stack alone: no screen is told it is covered or uncovered, and a
value popped with is dropped (apply_in tells
them). Returns true if the game should quit.
Sourcepub fn draw(&self, ctx: &Ctx<G>, buf: &mut GlyphBuffer)
pub fn draw(&self, ctx: &Ctx<G>, buf: &mut GlyphBuffer)
Draws the top-most opaque screen and every overlay above it, bottom up. If every screen is an overlay, all are drawn.
Sourcepub fn debug_draw(&self, ctx: &Ctx<G>, out: &mut Gizmos)
pub fn debug_draw(&self, ctx: &Ctx<G>, out: &mut Gizmos)
Asks every screen draw draws for its debug view’s
gizmos (Screen::debug_draw), bottom up, so an overlay’s come
after those of the screen under it.