Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a refactoring of how the screen state is "restored" when you want to hide something that was previously drawn.
Before this PR, the
overlayDisplayBuffer
optionally provided anrbuf
parameter, which would be filled with the "old" screen. Then, later, a caller could "revert" to this version of the screen by drawing it over the current screen.Obviously, this pattern worked, but it hides the real structure of the game's interface from the platform. In order to make it possible to enrich the display of the world, it should be possible to expose the structure of the layers of UI (e.g. confirmation window on top of inventory on top of dungeon).
This PR makes a partial step in this direction:
pushNewScreenLayer(...)
declares that you're about to draw a new layer of UI onto the screen. In a global variable, it stores the currentdisplayBuffer
, which can be reverted by callingpopScreenLayer(...)
:In order to make debugging mismatched calls a little bit easier, these functions return a
ScreenLayerHandle
, which just tracks the index into the layers. In the future, we might want to include additional information in these. Likewise, each layer is given a name, and there's a (commented out right now - should probably guard with a#define
instead) debug function that prints the current layer stack.The
overlayDisplayBuffer
function has been rewritten to not support therbuf
parameter - all existing callers were rewritten to use thepushNewScreenLayer
abstraction instead. A few of them are still quite messy (displayInventory
in particular is quite complicated).In follow-on PRs, I want to keep refactoring in this direction, of exposing the underlying state of the view to the platform (in addition to the backwards-compatible grid of symbols):
overlayDisplayBuffer
will also store (transparent) versions of each layer, so that they can be composited by the platform directlyscreenDisplayBuffer
should be refactored out, so that layers can be composed "lazily" in the platform - this means you can't make a change todisplayBuffer
that's not also reflected in the transparent ui layerScreenLayerOptions
should provide additional details about the layer, so that different layers can be treated differently by the platform without lots of hard-coding logic