Package tripleplay.game
Class ScreenStack
java.lang.Object
tripleplay.game.ScreenStack
Manages a stack of screens. The stack supports useful manipulations: pushing a new screen onto
the stack, replacing the screen at the top of the stack with a new screen, popping a screen from
the stack.
Care is taken to preserve stack invariants even in the face of errors thrown by screens when
being added, removed, shown or hidden. Users can override handleError(java.lang.RuntimeException)
and either simply
log the error, or rethrow it if they would prefer that a screen failure render their entire
screen stack unusable.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Used to operate on screens.static class
Displays and manages the lifecycle for a single game screen.static class
Implements a particular screen transition.static class
AScreenStack.Screen
with anInterface
for doing UI stuff. -
Field Summary
Modifier and TypeFieldDescriptionstatic final ScreenStack.Transition
Simply puts the new screen in place and removes the old screen.float
The x-coordinate at which screens are located.float
The y-coordinate at which screens are located. -
Constructor Summary
ConstructorDescriptionScreenStack
(Game game, GroupLayer rootLayer) Creates a screen stack that manages screens forgame
onrootLayer
. -
Method Summary
Modifier and TypeMethodDescriptionfind
(ScreenStack.Predicate pred) Searches from the top-most screen to the bottom-most screen for a screen that matches the predicate, returning the first matching screen.flip()
Creates a flip transition.boolean
Returns true if we're currently transitioning between screens.pageTurn()
Creates a page turn transition.void
popTo
(ScreenStack.Screen newTopScreen) popTo(Screen,Transition)
with the default transition.void
popTo
(ScreenStack.Screen newTopScreen, ScreenStack.Transition trans) Pops the top screen from the stack until the specified screen has become the topmost/visible screen.void
push
(Iterable<? extends ScreenStack.Screen> screens) push(Iterable,Transition)
with the default transition.void
push
(Iterable<? extends ScreenStack.Screen> screens, ScreenStack.Transition trans) Pushes the supplied set of screens onto the stack, in order.void
push
(ScreenStack.Screen screen) push(Screen,Transition)
with the default transition.void
push
(ScreenStack.Screen screen, ScreenStack.Transition trans) Pushes the supplied screen onto the stack, making it the visible screen.void
remove
(ScreenStack.Predicate pred) remove(Predicate,Transition)
with the default transition.void
remove
(ScreenStack.Predicate pred, ScreenStack.Transition trans) Removes all screens that match the supplied predicate, from lowest in the stack to highest.boolean
remove
(ScreenStack.Screen screen) remove(Screen,Transition)
with the default transition.boolean
remove
(ScreenStack.Screen screen, ScreenStack.Transition trans) Removes the specified screen from the stack.void
replace
(ScreenStack.Screen screen) replace(Screen,Transition)
with the default transition.void
replace
(ScreenStack.Screen screen, ScreenStack.Transition trans) Pops the current screen from the top of the stack and pushes the supplied screen on as its replacement.int
size()
Returns the number of screens on the stack.slide()
Creates a slide transition.top()
Returns the top screen on the stack, or null if the stack contains no screens.
-
Field Details
-
NOOP
Simply puts the new screen in place and removes the old screen. -
originX
public float originXThe x-coordinate at which screens are located. Defaults to 0. -
originY
public float originYThe y-coordinate at which screens are located. Defaults to 0.
-
-
Constructor Details
-
ScreenStack
Creates a screen stack that manages screens forgame
onrootLayer
.
-
-
Method Details
-
slide
Creates a slide transition. -
pageTurn
Creates a page turn transition. -
flip
Creates a flip transition. -
push
push(Screen,Transition)
with the default transition. -
push
Pushes the supplied screen onto the stack, making it the visible screen. The currently visible screen will be hidden.- Throws:
IllegalArgumentException
- if the supplied screen is already in the stack.
-
push
push(Iterable,Transition)
with the default transition. -
push
Pushes the supplied set of screens onto the stack, in order. The last screen to be pushed will also be shown, using the supplied transition. Note that the transition will be from the screen that was on top prior to this call. -
popTo
popTo(Screen,Transition)
with the default transition. -
popTo
Pops the top screen from the stack until the specified screen has become the topmost/visible screen. If newTopScreen is null or is not on the stack, this will remove all screens. -
replace
replace(Screen,Transition)
with the default transition. -
replace
Pops the current screen from the top of the stack and pushes the supplied screen on as its replacement.- Throws:
IllegalArgumentException
- if the supplied screen is already in the stack.
-
remove
remove(Screen,Transition)
with the default transition. -
remove
Removes the specified screen from the stack. If it is the currently visible screen, it will first be hidden, and the next screen below in the stack will be made visible.- Returns:
- true if the screen was found in the stack and removed, false if the screen was not in the stack.
-
remove
remove(Predicate,Transition)
with the default transition. -
remove
Removes all screens that match the supplied predicate, from lowest in the stack to highest. If the top screen is removed (as the last action), the supplied transition will be used. -
top
Returns the top screen on the stack, or null if the stack contains no screens. -
find
Searches from the top-most screen to the bottom-most screen for a screen that matches the predicate, returning the first matching screen.null
is returned if no matching screen is found. -
isTransiting
public boolean isTransiting()Returns true if we're currently transitioning between screens. -
size
public int size()Returns the number of screens on the stack.
-