persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
PauseMenuScreen.cpp
Go to the documentation of this file.
1#include "PauseMenuScreen.hpp"
2#include "core/globals.hpp"
5
7
9{
10 if (instance == nullptr)
11 {
13 }
14}
15
17{
18 if (instance != nullptr)
19 {
20 delete instance;
21 instance = nullptr;
22 }
23}
24
26{
27 if (instance == nullptr)
28 {
30 }
31 return instance;
32}
33
34void PauseMenuScreen::setYenText(const std::string& yen, TextColor color)
35{
36 yenText = yen;
37 yenColor = color;
38}
39
40void PauseMenuScreen::setPersonaText(const std::string& persona, TextColor color)
41{
42 personaText = persona;
43 personaColor = color;
44}
45
46void PauseMenuScreen::setArcanaText(const std::string& arcana, TextColor color)
47{
48 arcanaText = arcana;
49 arcanaColor = color;
50}
51
52void PauseMenuScreen::setLevelText(const std::string& level, TextColor color)
53{
54 levelText = level;
55 levelColor = color;
56}
57
58void PauseMenuScreen::setDescriptionText(const std::string& description, TextColor color)
59{
60 descriptionText = description;
61 descriptionColor = color;
62}
63
65{
66 // load background into ram
67 bgPauseMenu = graphics->loadGraphic(bgPath + "pause/pause");
68}
69
71{
72 // load palette
73 dmaCopy(bgPauseMenu.pal, BG_PALETTE_SUB, bgPauseMenu.palLen);
74
75 // draw background (copy into vram)
76 dmaCopy(bgPauseMenu.tiles, bgGetGfxPtr(bgId), bgPauseMenu.tilesLen);
77 dmaCopy(bgPauseMenu.map, bgGetMapPtr(bgId), bgPauseMenu.mapLen);
78}
79
81{
82 // unload background from ram
83 graphics->unloadGraphic(bgPauseMenu);
84 bgPauseMenu = {};
85}
86
88{
89 // description (top bar)
90 text->clearArea(72, 5, 176, 14);
91 text->drawText(descriptionText, 72, 8, descriptionColor);
92
93 text->clearArea(138, 89, 82, 73);
94
95 // yen
96 text->drawText(yenText, 138, 89, yenColor);
97
98 // active persona name
99 text->drawText(personaText, 138, 113, personaColor);
100
101 // active persona arcana
102 text->drawText(arcanaText, 138, 132, arcanaColor);
103
104 // active persona level
105 text->drawText(levelText, 138, 151, levelColor);
106
108}
109
111{
112 if (menu == nullptr)
113 {
114 return;
115 }
116
117 etl::span<MenuOption> options = menu->getOptions();
118 if (options.empty())
119 {
120 return;
121 }
122
123 int startIndex = menu->getStartIndex();
124 int selectedOption = menu->getSelectedOption();
125
126 for (int i = 0; i < visibleOptions && startIndex + i < int(options.size()); i++)
127 {
128 int option = startIndex + i;
129 TextColor color = option == selectedOption ? selectedOptionColor : optionColor;
130 optionsText->drawText(options[option].name, optionsStartX, optionsStartY + optionsRowHeight * i, color);
131 }
132
133 selectedBarBaseY = optionsStartY + optionsRowHeight * (selectedOption - startIndex) + selectedBarYOffset;
136}
137
139{
141
142 etl::array<SpriteRenderState*, 4> barPieces = {&srs1, &srs2, &srs3, &srs4};
143 for (int i = 0; i < 4; i++)
144 {
145 barPieces[i]->y = y;
146 if (isLoaded)
147 {
148 moveSprite(i + 1, barPieces[i]->x, y);
149 }
150 }
151}
152
154{
156
157 auto seq = animator.sequence();
158 seq.append(animator.animate(jiggleOffsetY).from(0).to(-2).duration(40).ease(UIEase::OutQuad));
159 seq.append(animator.animate(jiggleOffsetY).from(-2).to(2).duration(70).ease(UIEase::InOutQuad));
160 seq.append(animator.animate(jiggleOffsetY).from(2).to(-1).duration(50).ease(UIEase::InOutQuad));
161 seq.append(animator.animate(jiggleOffsetY).from(-1).to(0).duration(40).ease(UIEase::OutQuad));
162 selectionAnimation = seq.start();
163}
164
166{
167 const ae::q20_12_t dt = MathManager::getInstance().div(ae::q20_12_t{1}, ae::q20_12_t{60});
168 updateAnimation(dt);
169}
170
172{
173 bool wasAnimating = selectionAnimation.isPlaying();
174 animator.update(dt);
175
176 if (isLoaded && (wasAnimating || selectionAnimation.isPlaying()))
177 {
179 }
180}
181
183{
184 return selectionAnimation.isPlaying();
185}
186
188{
189 animator.cancelAll();
190 jiggleOffsetY = 0;
191}
192
194{
195 // load palettes
196 dmaCopy(bgPauseMenu.pal, SPRITE_PALETTE_SUB, bgPauseMenu.palLen);
197
198 // perform transformations
200 int i = 1;
202 {
203 oamRotateScale(oam, i++, st.angle, st.sx, st.sy);
204 }
205
206 // draw sprites
207 int j = 0;
208 for (SpritePayload& sp : spritePayloads)
209 {
210 // use alias for easy referencing
211 Sprite& sprite = sp.srs.sprite;
212 GraphicAsset& graphic = sp.ga;
213 SpriteRenderState& srs = sp.srs;
214
215 // copy sprite into vram
216 dmaCopy(graphic.tiles, sprite.gfx, graphic.tilesLen);
217
218 oamSet(oam,
219 j++,
220 srs.x,
221 srs.y,
222 srs.priority,
224 srs.sprite.size,
225 srs.sprite.format,
226 srs.sprite.gfx,
227 srs.affineIndex,
228 srs.sizeDouble,
229 srs.hide,
230 srs.hflip,
231 srs.vflip,
232 srs.mosaic);
233 }
234
235 // draw background
237}
238
239int PauseMenuScreen::onTouch(touchPosition* touch)
240{
241 return -1;
242}
243
245{
246 this->text = text;
247}
248
253
255{
256 this->menu = menu;
257}
258
263
265{
266 // create relevant entities, components
267 if (pauseMenu == nullptr)
268 {
269 pauseMenu = engine.createEntity();
270 graphics = engine.createComponent<GraphicsComponent>();
271 pauseMenu->addComponent(graphics);
272 }
273
274 // load sprites
275 for (SpritePayload& sp : spritePayloads)
276 {
277 // use alias for easy referencing
278 Sprite& sprite = sp.srs.sprite;
279 GraphicAsset& graphic = sp.ga;
280
281 // load graphic if not already loaded
282 if (graphic.id <= -1)
283 {
284 // allocating space for sprite
285 sprite.gfx = oamAllocateGfx(oam, sprite.size, sprite.format);
286
287 // load sprite into ram
288 graphic = graphics->loadSpriteGraphic(sp.spritePath, sp.spriteType, sp.spriteVariant);
289 }
290 }
291
292 // load background
294};
295
297{
299
300 // hide sprites
302
303 // free sprites
304 for (SpritePayload& sp : spritePayloads)
305 {
306 // use alias for easy referencing
307 Sprite& sprite = sp.srs.sprite;
308 GraphicAsset& graphic = sp.ga;
309
310 // free sprite vram
311 if (sprite.gfx != nullptr)
312 {
313 oamFreeGfx(oam, sprite.gfx);
314 sprite.gfx = nullptr;
315 }
316
317 // unload graphic if not already unloaded
318 if (graphic.id > -1)
319 {
320 // unload sprite
321 graphics->unloadGraphic(graphic);
322
323 // reset data
324 graphic = {};
325 }
326 }
327
328 // unload background
330
331 if (pauseMenu != nullptr)
332 {
333 engine.destroyEntity(pauseMenu);
334
335 pauseMenu = nullptr;
336 graphics = nullptr;
337 }
338}
Pause menu screen.
TextColor
Human Readable enum for text colors.
Definition TextTypes.hpp:11
Easing mode alias for UI property animations.
TextComponent * optionsText
static void destroy()
SpriteRenderState srs1
UIAnimationHandle selectionAnimation
void setTextComponent(TextComponent *text)
Set the Text Component object.
int onTouch(touchPosition *touch) override
Hook to allow touch response.
void setYenText(const std::string &yen, TextColor color)
Set the Yen Text object (info panel).
std::string personaText
GraphicsComponent * graphics
const std::string bgPath
void updateSelectionSpritePosition()
Updates the positions of the selected option bar sprites (including jiggle offset).
SpriteRenderState srs3
void setMenu(const UIMenu *menu)
Set the menu whose options are drawn on this screen.
void renderText() override
Draws the text.
void cancelAnimation()
Cancels all animations.
bool isAnimating() const
Checks if the selection sprite is currently animating.
int getVisibleOptions()
Gets how many option rows the screen shows.
static PauseMenuScreen * instance
void load()
Loads graphics data into memory & pushes to VRAM.
void setDescriptionText(const std::string &description, TextColor color)
Set the Description Text object (top bar).
const UIMenu * menu
void setLevelText(const std::string &level, TextColor color)
Set the Level Text object (info panel).
etl::array< SpritePayload, 5 > spritePayloads
static void create()
static PauseMenuScreen * getInstance()
SpriteRenderState srs2
void setOptionsTextComponent(TextComponent *optionsText)
Set the Text Component used to draw the menu options.
GraphicAsset bgPauseMenu
void setArcanaText(const std::string &arcana, TextColor color)
Set the Arcana Text object (info panel).
void renderOptions()
Draws the visible options of the active menu and moves the selection bar to the selected one.
void renderSprites() override
Applys sprite colour palette & draws sprites to screen.
etl::array< SpriteTransform, 0 > spriteTransforms
void animateSelection()
Starts the jiggle animation on the selected option sprite.
const int selectedBarYOffset
SpriteRenderState srs4
void unload()
Unloads graphics data from memory.
void setPersonaText(const std::string &persona, TextColor color)
Set the Persona Text object (info panel).
std::string descriptionText
ae::Entity * pauseMenu
TextComponent * text
void updateAnimation()
Updates active UI animations.
TextColor selectedOptionColor
void removeSprites()
Clears the displayed sprites from the screen.
Definition UIScreen.cpp:11
OamState * oam
Definition UIScreen.hpp:12
bool isLoaded
Definition UIScreen.hpp:13
void moveSprite(int spriteId, int x, int y)
Moves the specified sprite to the specified position on the screen.
Definition UIScreen.cpp:25
Holds global variables used game-wide.
GameEngine engine
Definition main.cpp:31
Holds loaded graphics data.
Data to manage the lifecycle of a sprite.
Data to render a Sprite.
Data to perform a transformation on a Sprite.
A simple sprite structure.
SpriteColorFormat format
int paletteAlpha
SpriteSize size