coastline 0.0.4
Loading...
Searching...
No Matches
menuscreen.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <array>
11#include <cstdint>
12#include <filesystem>
13#include <functional>
14#include <memory>
15#include <optional>
16#include <span>
17#include <string>
18#include <string_view>
19#include <vector>
20
21#include "common/types.h"
22#include "scenerenderer.h"
23
24namespace coastline {
25
26class MenuText;
27
29constexpr u32 MENU_ITEM_ADJUSTABLE = 0x01;
30
32constexpr u32 MENU_ITEM_IMMEDIATE = 0x02;
33
35constexpr u32 MENU_ITEM_SPINNING = 0x04;
36
38constexpr u32 MENU_ITEM_UNAVAILABLE = 0x08;
39
42
44constexpr u32 MENU_ITEM_FIRST_PLAYER = 0x20;
45
47constexpr u32 MENU_ITEM_LOCKED = 0x80000000;
48
51 bool left = false;
52 bool right = false;
53 bool up = false;
54 bool down = false;
55 bool choose = false;
56 bool start = false;
57 bool back = false;
58 bool held = false;
59 bool cDown = false;
64};
65
74
76struct MenuItem {
78 u32 flags = 0;
79 const RenderModel *model = nullptr;
80 bool coin = false;
81 bool emptyStage = false;
82};
83
93
96 const RenderTexture *texture = nullptr;
97 int x = 0;
98 int y = 0;
99 int width = 0;
100 int height = 0;
101};
102
105public:
115 static void DrawCoin(SceneRenderer &renderer,
116 float x,
117 float angle,
118 const Matrix4 &projection,
119 bool locked = false);
129 const std::filesystem::path &release);
133 MenuScreen(const MenuScreen &) = delete;
135 MenuScreen &operator=(const MenuScreen &) = delete;
136
147 const std::filesystem::path &directory,
149
158
163 void Reset();
165 bool TimedOut() const;
166
177 float seconds,
179 const MenuSetup &setup);
180
186 void SetPendingSelection(int item);
187
189 int LastActiveIndex() const;
190
196 void SetLastActiveIndex(int item);
197
199 int ChoosingPlayer() const;
200
203
205 const RenderTexture &TitleBar() const;
206
208 const MenuText &Text() const;
209
211 const Lighting &MenuLighting() const;
212
224 static void DrawTexture(
225 SceneRenderer &renderer, const RenderTexture &texture, int x, int y, int width, int height);
226
238 static void
239 DrawFadeOverlay(SceneRenderer &renderer, float level, int x, int y, int width, int height);
240
245 static Matrix4 FlatFor(SceneRenderer &renderer);
246
255 const std::array<int, 3> &top,
256 const std::array<int, 3> &bottom) const;
257
263 void DrawFooter(SceneRenderer &renderer) const;
264
270 void DrawPauseFooter(SceneRenderer &renderer) const;
271
274
277
285 void FadeIn(bool fadeMusic = true, bool fadeSounds = true);
286
288 void FadeOut();
289
295 void FadeSounds(float level);
296
298 bool SoundsFaded() const;
299
305 void UpdateFade(float seconds);
306
308 bool FadingOut() const;
309
311 bool FadeComplete() const;
312
318 void DrawFade(SceneRenderer &renderer) const;
319
321 static void SilenceSounds();
322
324 float idleTimeout = 0.0f;
329
330private:
331 struct State;
332 explicit MenuScreen(std::unique_ptr<State> state);
333 MenuResult Update(float seconds, std::span<const MenuButtons> players, const MenuSetup &setup);
334 void Draw(SceneRenderer &renderer, const MenuSetup &setup) const;
336};
337
338} // namespace coastline
void DrawFooter(SceneRenderer &renderer) const
DrawMenuFooterButtons() of the console: the buttons at the bottom and their names.
bool TimedOut() const
bool SoundsFaded() const
static void DrawCoin(SceneRenderer &renderer, float x, float angle, const Matrix4 &projection, bool locked=false)
Draw the lit coin and its shadow on the menu stage.
bool FadingOut() const
int LastActiveIndex() const
MenuScreen & operator=(const MenuScreen &)=delete
Prevent assignment of shared menu rendering and audio resources.
static void DrawFadeOverlay(SceneRenderer &renderer, float level, int x, int y, int width, int height)
DrawScreenFadeOverlay() of the console under a scissor: darken a rectangle of the 320 by 240 screen.
static Matrix4 FlatFor(SceneRenderer &renderer)
int ChoosingPlayer() const
static void SilenceSounds()
Silence every channel of the sound effects, as a screen does once it has faded out.
void PlaySelectSound()
Play the sound of choosing.
std::optional< MenuTitleImage > titleImage
Definition menuscreen.h:323
MenuResult Process(SceneRenderer &renderer, float seconds, std::span< const MenuButtons > players, const MenuSetup &setup)
Run a frame of a screen and draw it, as ProcessScreenState() of the console.
void DrawBackground(SceneRenderer &renderer, const std::array< int, 3 > &top, const std::array< int, 3 > &bottom) const
Draw the background of a screen, its texels lerping from one colour to another.
void DrawFade(SceneRenderer &renderer) const
Draw the black of the fade, as ApplyScreenFade() of the console.
void UpdateFade(float seconds)
Advance the fades of the screen and the sound effects by a frame.
void PlayScrollSound()
Play the sound of moving the cursor.
void FadeIn(bool fadeMusic=true, bool fadeSounds=true)
Start the fade of a screen that draws itself in, as SetFadeTarget() and FadeSfxTo() of the console fa...
const Lighting & MenuLighting() const
void FadeOut()
Fade the screen and the sound effects out.
const RenderTexture & TitleBar() const
std::function< void(SceneRenderer &, int)> postDraw
The draw after the item under the cursor, with that item, g_pfnScreenPostDrawCallback.
Definition menuscreen.h:326
std::function< void(SceneRenderer &)> preDraw
The draw in place of the stage and the items, g_pfnScreenPreDrawCallback.
Definition menuscreen.h:328
const RenderModel * LoadModel(SceneRenderer &renderer, const std::filesystem::path &path)
Read a model for an item, shared with every other item of the same file.
void SetLastActiveIndex(int item)
Set the item under the cursor on the last frame, as a screen does before it starts.
const MenuText & Text() const
std::optional< std::vector< MenuItem > > LoadItems(SceneRenderer &renderer, const std::filesystem::path &directory, std::span< const char *const > stems)
Read the items of a directory of the import, as LoadMenuItemModels() of the console.
void DrawPauseFooter(SceneRenderer &renderer) const
DrawPauseMenuButtons() of the console: the buttons at the bottom to go on and to exit.
void SetPendingSelection(int item)
SetScreenPendingSelection() of the console: move the cursor to an item on the next frame.
static std::unique_ptr< MenuScreen > Load(SceneRenderer &renderer, const std::filesystem::path &release)
Read the background, the arrows, the title pictures, the fonts, the lights, the choice marker,...
MenuScreen(const MenuScreen &)=delete
Prevent copying shared menu rendering and audio resources.
bool FadeComplete() const
~MenuScreen()
Release shared menu models, textures, and sounds before the renderer and mixer contexts.
static void DrawTexture(SceneRenderer &renderer, const RenderTexture &texture, int x, int y, int width, int height)
Draw a texture stretched over a rectangle of the 320 by 240 screen, as DrawTexturedRect() of the cons...
float idleTimeout
Definition menuscreen.h:324
const RenderTexture & MainMenuTitle() const
void Reset()
ResetAndInitDisplay() of the console: clear the idle timeout and the hooks of the screen before anoth...
void FadeSounds(float level)
Fade the sound effects and the music alone, as FadeSfxTo() and FadeMusicTo() of the console.
The two fonts of the menus, their gradients, and the layout of their glyphs.
Definition menutext.h:63
A converted model on the GPU: its meshes, its parts, and its animations.
Definition scenerenderer.h:252
A texture of the renderer for flat pictures and text.
Definition scenerenderer.h:333
The renderer of a frame.
Definition scenerenderer.h:467
Definition assetimport.h:11
constexpr u32 MENU_ITEM_FIRST_PLAYER
The flag of an item only the first player may choose.
Definition menuscreen.h:44
constexpr u32 MENU_ITEM_SPINNING
The flag of an item drawn as its model spinning round as the items slide.
Definition menuscreen.h:35
constexpr u32 MENU_ITEM_ADJUSTABLE
The flag of an item whose up and down change it in place, as MenuResult::Up and Down.
Definition menuscreen.h:29
MenuResult
What a frame of a menu screen ends with, the results of ProcessScreenState().
Definition menuscreen.h:67
@ Cancelled
Definition menuscreen.h:70
@ Chosen
Definition menuscreen.h:69
@ None
Definition gpu.h:32
constexpr u32 MENU_ITEM_UNAVAILABLE
The flag of an item that cannot be chosen, whose screen explains why.
Definition menuscreen.h:38
std::array< float, 16 > Matrix4
A 4 by 4 matrix, column by column.
Definition scenerenderer.h:28
constexpr u32 MENU_ITEM_MIRRORED_MODEL
The flag of an item whose model is drawn mirrored.
Definition menuscreen.h:41
constexpr u32 MENU_ITEM_IMMEDIATE
The flag of an item chosen at once, without fading the screen out.
Definition menuscreen.h:32
@ Down
Definition setupwizard.h:127
@ Up
Definition setupwizard.h:126
constexpr u32 MENU_ITEM_LOCKED
The flag of an item that cannot be chosen, without a reason shown.
Definition menuscreen.h:47
The renderer of the converted models and of flat pictures and text, on the GPU of SDL.
The lights of a model, an ambient colour and a directional colour from a direction in the space the m...
Definition scenerenderer.h:52
The presses of a controller that act on a menu, each true on the frame it starts.
Definition menuscreen.h:50
bool start
Definition menuscreen.h:56
bool cDown
Definition menuscreen.h:59
bool right
Definition menuscreen.h:52
std::int8_t stickY
Definition menuscreen.h:63
bool back
Definition menuscreen.h:57
bool down
Definition menuscreen.h:54
bool choose
Definition menuscreen.h:55
bool up
Definition menuscreen.h:53
bool left
Definition menuscreen.h:51
std::uint16_t heldButtons
The ControllerButton bits held, without the directions the stick pushes, which the car select screen ...
Definition menuscreen.h:62
bool held
Definition menuscreen.h:58
An item of a menu screen.
Definition menuscreen.h:76
bool coin
Definition menuscreen.h:80
const RenderModel * model
Definition menuscreen.h:79
std::string name
Definition menuscreen.h:77
bool emptyStage
Definition menuscreen.h:81
u32 flags
Definition menuscreen.h:78
What a frame of a screen shows, the arguments of ProcessScreenState().
Definition menuscreen.h:85
std::function< bool(int)> isSelectable
Definition menuscreen.h:89
std::array< int, 3 > bottom
Definition menuscreen.h:91
std::string_view title
Definition menuscreen.h:86
int * selection
Definition menuscreen.h:88
std::span< const MenuItem > items
Definition menuscreen.h:87
std::array< int, 3 > top
Definition menuscreen.h:90
A picture over the title of a screen, and its rectangle on the 320 by 240 screen.
Definition menuscreen.h:95
int y
Definition menuscreen.h:98
int height
Definition menuscreen.h:100
int width
Definition menuscreen.h:99
const RenderTexture * texture
Definition menuscreen.h:96
int x
Definition menuscreen.h:97
The integer and floating-point types of the console, for headers shared with Windows.
unsigned int u32
Definition ultratypes.h:20