persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
MenuHUDScreen.cpp
Go to the documentation of this file.
1#include "MenuHUDScreen.hpp"
2#include "core/globals.hpp"
3
5
7{
8 if (instance == nullptr)
9 {
10 instance = new MenuHUDScreen();
11 }
12}
13
15{
16 if (instance != nullptr)
17 {
18 delete instance;
19 instance = nullptr;
20 }
21}
22
24{
25 if (instance == nullptr)
26 {
27 instance = new MenuHUDScreen();
28 }
29 return instance;
30}
31
33{
34 // load palette
35 dmaCopy(bgHUD.pal, BG_PALETTE_SUB, bgHUD.palLen);
36
37 // draw background (copy into vram)
38 dmaCopy(bgHUD.tiles, bgGetGfxPtr(bgId), bgHUD.tilesLen);
39 dmaCopy(bgHUD.map, bgGetMapPtr(bgId), bgHUD.mapLen);
40}
41
43{
44 // load palettes
45 dmaCopy(bgHUD.pal, SPRITE_PALETTE_SUB, bgHUD.palLen);
46
47 // perform transformations
49 int i = 1;
51 {
52 oamRotateScale(oam, i++, st.angle, st.sx, st.sy);
53 }
54
55 // draw sprites
56 int j = 0;
58 {
59 // use alias for easy referencing
60 Sprite& sprite = sp.srs.sprite;
61 GraphicAsset& graphic = sp.ga;
62 SpriteRenderState& srs = sp.srs;
63
64 // copy sprite into vram
65 dmaCopy(graphic.tiles, sprite.gfx, graphic.tilesLen);
66
67 oamSet(oam,
68 j++,
69 srs.x,
70 srs.y,
71 srs.priority,
73 srs.sprite.size,
74 srs.sprite.format,
75 srs.sprite.gfx,
76 srs.affineIndex,
77 srs.sizeDouble,
78 srs.hide,
79 srs.hflip,
80 srs.vflip,
81 srs.mosaic);
82 }
83
84 // draw background
86}
87
88int MenuHUDScreen::onTouch(touchPosition* touch)
89{
90 int xPos = 207;
91 int yPos = 173;
92 int width = 41;
93 int height = 14;
94
95 if (touch->px >= xPos && touch->px <= (xPos + width) && touch->py >= yPos && touch->py <= (yPos + height))
96 {
97 return 1;
98 }
99
100 return -1;
101}
102
104{
105 // create relevant entities, components
106 if (menuHUD == nullptr)
107 {
108 menuHUD = engine.createEntity();
109 graphics = engine.createComponent<GraphicsComponent>();
110 menuHUD->addComponent(graphics);
111 }
112
113 // load sprites
114 for (SpritePayload& sp : spritePayloads)
115 {
116 // use alias for easy referencing
117 Sprite& sprite = sp.srs.sprite;
118 GraphicAsset& graphic = sp.ga;
119
120 // load graphic if not already loaded
121 if (graphic.id <= -1)
122 {
123 // allocating space for sprite
124 sprite.gfx = oamAllocateGfx(oam, sprite.size, sprite.format);
125
126 // load sprite into ram
127 graphic = graphics->loadSpriteGraphic(sp.spritePath, sp.spriteType, sp.spriteVariant);
128 }
129 }
130
131 // load background into ram
132 bgHUD = graphics->loadGraphic(bgPath + "menuHUD/menuHUD");
133};
134
136{
137 // hide sprites
139
140 // free sprites
141 for (SpritePayload& sp : spritePayloads)
142 {
143 // use alias for easy referencing
144 Sprite& sprite = sp.srs.sprite;
145 GraphicAsset& graphic = sp.ga;
146
147 // free sprite vram
148 if (sprite.gfx != nullptr)
149 {
150 oamFreeGfx(oam, sprite.gfx);
151 sprite.gfx = nullptr;
152 }
153
154 // unload graphic if not already unloaded
155 if (graphic.id > -1)
156 {
157 // unload sprite
158 graphics->unloadGraphic(graphic);
159
160 // reset data
161 graphic = {};
162 }
163 }
164
165 // unload background from ram
166 graphics->unloadGraphic(bgHUD);
167 bgHUD = {};
168
169 if (menuHUD != nullptr)
170 {
171 engine.destroyEntity(menuHUD);
172
173 menuHUD = nullptr;
174 graphics = nullptr;
175 }
176}
177
179{
180 this->text = text;
181}
182
184{
185 this->textContent = textContent;
186 this->textColor = textColor;
187 renderText();
188}
189
191{
192 // place
193 text->clearArea(3, 3, 134, 19);
194 text->drawText(textContent.c_str(), 5, 6, textColor);
195
196 // date
197 text->drawText("12/31", 208, 5, TextColor::White);
198
199 // day
200 text->drawText("Sa", 243, 5, TextColor::White);
201
202 // days until full moon
203 text->drawText("30", 243, 64, TextColor::White);
204}
Handles the rendering & logic for the menu HUD UI.
TextColor
Human Readable enum for text colors.
Definition TextTypes.hpp:11
@ White
Definition TextTypes.hpp:14
void setTextContent(std::string textContent, TextColor textColor)
Set the Text Content object.
static MenuHUDScreen * getInstance()
GraphicAsset bgHUD
int onTouch(touchPosition *touch) override
Handles touch input.
GraphicsComponent * graphics
void renderSprites() override
Renders the background and sprites text to the screen.
void setTextComponent(TextComponent *text)
Set the Text Component object.
TextComponent * text
etl::array< SpriteTransform, 0 > spriteTransforms
void renderBackground()
Pushes background data into VRAM so that it is rendered on screen.
void load()
Loads graphics data into memory & pushes to VRAM.
TextColor textColor
static void create()
void renderText() override
Prints the text to render on screen.
std::string textContent
const std::string bgPath
static MenuHUDScreen * instance
static void destroy()
etl::array< SpritePayload, 4 > spritePayloads
ae::Entity * menuHUD
void unload()
Unloads graphics data from memory.
void removeSprites()
Clears the displayed sprites from the screen.
Definition UIScreen.cpp:11
OamState * oam
Definition UIScreen.hpp:12
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