persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
UIMenu.cpp
Go to the documentation of this file.
1#include "UIMenu.hpp"
2#include "core/logger.hpp"
3
6
8{
9 options = {};
11 startIndex = 0;
12 isActive = false;
14 selectionX = 0;
15 animator.cancelAll();
16
17 if (text != nullptr)
18 {
19 text->clearScreen();
20 }
21
22 resetHook();
23
24 while (!prevOptions.empty())
25 {
26 prevOptions.pop();
27 }
28}
29
31{
32 const ae::q20_12_t dt = MathManager::getInstance().div(ae::q20_12_t{1}, ae::q20_12_t{60});
33 animator.update(dt);
34}
35
37{
38 return selectionX;
39}
40
42{
43 animator.cancelAll();
44 selectionX = -8;
45 animator.animate(selectionX).from(-8).to(0).duration(140).ease(UIEase::OutBack).start();
46}
47
48ViewState UIMenu::changeMenu(etl::span<MenuOption> newOptions)
49{
50 if (prevOptions.full())
51 {
52 logMessage(LogSeverity::WARNING, "prevOptions stack is full");
54 }
55
56 // add to prevOptions
57 MenuState currentState = {options, selectedOption, startIndex};
58 prevOptions.push(currentState);
59
60 logMessage(LogSeverity::DEBUG, "Menu options changed, count: " + std::to_string(newOptions.size()));
61
62 // set new options
63 options = newOptions;
65 startIndex = 0;
66
68}
69
71{
72 // if we're in a submenu, return to main menu
73 if (!prevOptions.empty())
74 {
75 MenuState prevState = prevOptions.top();
76 prevOptions.pop();
77
78 options = prevState.options;
80 startIndex = prevState.startIndex;
81 }
82 else
83 {
84 // otherwise, close the menu
85 closeHook();
86 }
87}
88
ViewState
Definition StateTypes.hpp:4
Easing mode alias for UI property animations.
void animateSelection()
Definition UIMenu.cpp:41
etl::span< MenuOption > options
Definition UIMenu.hpp:28
etl::stack< MenuState, 5 > prevOptions
Definition UIMenu.hpp:47
virtual void prevOption()
Changes the current options to the previous options.
Definition UIMenu.cpp:70
int selectionOffset() const
Definition UIMenu.cpp:36
TextComponent * text
Definition UIMenu.hpp:25
virtual ViewState updateHook()
Optional hook to call during the update loop.
Definition UIMenu.cpp:89
UIAnimator animator
Definition UIMenu.hpp:50
void updateAnimation()
Definition UIMenu.cpp:30
virtual void resetMenu()
Resets the menu to its initial state.
Definition UIMenu.cpp:7
virtual void resetHook()=0
Used to set the default pauseMessage and options values.
ViewState changeMenu(etl::span< MenuOption > newOptions)
Changes the active menu.
Definition UIMenu.cpp:48
bool isActive
Definition UIMenu.hpp:24
int selectedOption
Definition UIMenu.hpp:29
ViewState nextViewState
Definition UIMenu.hpp:48
int startIndex
Definition UIMenu.hpp:30
virtual void closeHook()=0
Execute logic after the root menu is exited.
int selectionX
Definition UIMenu.hpp:49
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.
int selectedOption
Definition UITypes.hpp:18
int startIndex
Definition UITypes.hpp:19
etl::span< MenuOption > options
Definition UITypes.hpp:17