persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
BattleMenu.cpp
Go to the documentation of this file.
1#include "BattleMenu.hpp"
2#include "core/globals.hpp"
3#include "core/logger.hpp"
4#include "events/UIEvents.hpp"
5
7
9{
10 if (instance == nullptr)
11 {
12 instance = new BattleMenu();
13 }
14}
15
17{
18 if (instance != nullptr)
19 {
20 delete instance;
21 }
22 instance = nullptr;
23}
24
26{
27 if (instance == nullptr)
28 {
29 create();
30 }
31 return instance;
32}
33
34// option loaders
35void BattleMenu::loadActionOptions(std::array<ActionBase*, 4>* actions, std::string name)
36{
37 if (actions == nullptr)
38 {
39 logMessage(LogSeverity::WARNING, "Called with null actions");
40 return;
41 }
42
43 // skip if action options have already been loaded
45 {
46 return;
47 };
48
49 text->clearScreen();
50 ae::broadcastEvent(Event::RenderUIText{});
51
52 battleOptions.clear();
54 logMessage(LogSeverity::DEBUG, "Action options loaded for: " + name);
55 pauseMessage = name.c_str();
56 int count = actions->size();
57
58 for (int i = 0; i < count; i++)
59 {
60 MenuOption option = {actions->at(i)->name.c_str(), -1, menuBind(&BattleMenu::battleOptionSelected)};
61 battleOptions.push_back(option);
62 }
63
65}
66
68{
69 if (persona == nullptr)
70 {
71 logMessage(LogSeverity::WARNING, "Called with null persona");
72 return;
73 }
74
75 // skip if action options have already been loaded
77 {
78 return;
79 };
80
81 text->clearScreen();
82 ae::broadcastEvent(Event::RenderUIText{});
83
84 logMessage(LogSeverity::DEBUG, "Skill options loaded for: " + persona->name);
85
86 // set new options
87 battleOptions.clear();
88
89 // indicate we loaded option
91 pauseMessage = "Skills";
92 int count = persona->skillCount;
93
94 for (int i = 0; i < count; i++)
95 {
96 MenuOption option = {persona->skills[i]->name.c_str(), -1, menuBind(&BattleMenu::battleOptionSelected)};
97 battleOptions.push_back(option);
98 }
99
101}
102
103void BattleMenu::loadPersonaOptions(etl::vector<PersonaBase*, 13>* personas)
104{
105 if (personas == nullptr)
106 {
107 logMessage(LogSeverity::WARNING, "Called with null personas");
108 return;
109 }
110
112 {
113 return;
114 }
115
116 text->clearScreen();
117 ae::broadcastEvent(Event::RenderUIText{});
118
119 logMessage(LogSeverity::DEBUG, "Persona menu options loaded");
120
121 battleOptions.clear();
123 pauseMessage = "Persona";
124 int count = (int)personas->size();
125
126 for (int i = 0; i < count; i++)
127 {
128 MenuOption option = {personas->at(i)->name.c_str(), -1, menuBind(&BattleMenu::battleOptionSelected)};
129 battleOptions.push_back(option);
130 }
131
133}
134
135void BattleMenu::loadTargetOptions(etl::vector<BattleParticipant*, 13>* targets, bool healTarget)
136{
137 if (targets == nullptr)
138 {
139 logMessage(LogSeverity::WARNING, "Called with null targets");
140 return;
141 }
142
143 BattleMenuOptions targetLoadedOption =
145
147 {
148 return;
149 }
150
151 text->clearScreen();
152 ae::broadcastEvent(Event::RenderUIText{});
153
154 logMessage(LogSeverity::DEBUG, "Target options loaded");
155
156 battleOptions.clear();
157 loadedOption = targetLoadedOption;
158 pauseMessage = "Target";
159 int count = (int)targets->size();
160
161 for (int i = 0; i < count; i++)
162 {
163 if (targets->at(i)->hp <= 0)
164 {
165 continue;
166 }
167
168 MenuOption option = {targets->at(i)->name.c_str(), -1, menuBind(&BattleMenu::battleOptionSelected)};
169 battleOptions.push_back(option);
170 }
171
173}
174
176{
178 {
179 return;
180 };
181
182 text->clearScreen();
183 ae::broadcastEvent(Event::RenderUIText{});
184
185 logMessage(LogSeverity::DEBUG, "All-Out Attack confirmation prompt loaded");
186
187 battleOptions.clear();
189 pauseMessage = "Confirm All-out-attack?";
190
193 battleOptions.push_back(yes);
194 battleOptions.push_back(no);
195
197}
198
199void BattleMenu::loadAlertOptions(const std::string& text)
200{
202 {
203 return;
204 }
205
206 battleOptions.clear();
210
211 options = {};
212}
213
214bool BattleMenu::isAlertExpired(int durationFrames) const
215{
216 return (frame - alertStartFrame) >= durationFrames;
217}
218
220{
221 pauseMessage = "";
222 options = {};
223
225 messagePrinted = false;
227}
228
230{
232 messagePrinted = false;
233 text->clearScreen();
234
235 pauseMessage = "";
236
237 selectedOption = 0;
238 startIndex = 0;
239}
240
242{
244 {
245 if (!messagePrinted)
246 {
247 text->clearScreen();
248 messagePrinted = true;
249 text->drawText(pauseMessage, 0, 0, TextColor::White);
250 }
252 }
253
254 return ViewState::DEFAULT;
255}
256
257// option handlers
264
266{
267 int battleOption = selectedBattleOption;
269 return battleOption;
270}
271
273{
274 bool result = isCancelled;
275 isCancelled = false;
276 return result;
277}
278
280{
281 //If we're in the root of the menu, cancel out the back input
283 {
284 return;
285 }
286 isCancelled = true;
289}
BattleMenuOptions
ViewState
Definition StateTypes.hpp:4
@ White
Definition TextTypes.hpp:14
Events for UISystem.
constexpr MenuOptionFunc menuBind(Method method)
Definition UIMenu.hpp:15
bool consumeCancel()
bool isAlertExpired(int durationFrames) const
bool isCancelled
int selectedBattleOption
int consumeSelectedBattleOption()
void resetHook() override
Used to set the default pauseMessage and options values.
static BattleMenu * instance
void resetLoadedOptions()
void loadPersonaOptions(etl::vector< PersonaBase *, 13 > *personas)
etl::vector< MenuOption, 10 > battleOptions
void loadSkillOptions(PersonaBase *persona)
void loadActionOptions(std::array< ActionBase *, 4 > *actions, std::string name)
ViewState battleOptionSelected()
void loadTargetOptions(etl::vector< BattleParticipant *, 13 > *targets, bool healTarget)
static BattleMenu * getInstance()
static void destroy()
static void create()
Definition BattleMenu.cpp:8
void prevOption() override
Changes the current options to the previous options.
ViewState updateHook() override
Optional hook to call during the update loop.
int32_t alertStartFrame
bool messagePrinted
void loadAlertOptions(const std::string &text)
BattleMenuOptions loadedOption
void loadAllOutAttackConfirmation()
etl::span< MenuOption > options
Definition UIMenu.hpp:28
TextComponent * text
Definition UIMenu.hpp:25
int selectedOption
Definition UIMenu.hpp:29
int startIndex
Definition UIMenu.hpp:30
std::string pauseMessage
Definition UIMenu.hpp:23
Holds global variables used game-wide.
volatile int32_t frame
Definition main.cpp:35
void logMessage(LogSeverity severity, std::string_view message, std::source_location location)
Logs a diagnostic message and halts only for fatal messages.
Definition logger.cpp:110
Util to handle error logging.
Event to trigger rendering UI text.
Definition UIEvents.hpp:103
std::string name
Skill ** skills
std::string name
Definition Skill.hpp:11