persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
UIMenu.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <etl/span.h>
4#include <etl/stack.h>
5#include <maxmod9.h>
6#include <nds.h>
7#include <string>
8
10#include "types/UITypes.hpp"
12
14
15template <typename Method> constexpr MenuOptionFunc menuBind(Method method)
16{
17 return static_cast<MenuOptionFunc>(method);
18}
19
20class UIMenu
21{
22 protected:
23 std::string pauseMessage = "Pause";
24 bool isActive = false;
25 TextComponent* text = nullptr;
26
27 // options
28 etl::span<MenuOption> options;
30 int startIndex = 0;
31
38 ViewState changeMenu(etl::span<MenuOption> newOptions);
39
40 private:
41 friend class UISystem;
42
43 // options
46 const bool customRender;
47 etl::stack<MenuState, 5> prevOptions;
49 int selectionX = 0;
51
52 void animateSelection();
53
59 virtual void prevOption();
60
64 virtual void resetHook() = 0;
65
69 virtual void closeHook() = 0;
70
71 public:
77 UIMenu(bool iCustomRender = false) : customRender(iCustomRender)
78 {
79 }
80
84 virtual void resetMenu();
85
91 virtual ViewState updateHook();
92
93 void updateAnimation();
94 int selectionOffset() const;
95
102 {
103 return selectedOption;
104 }
105
111 int getStartIndex() const
112 {
113 return startIndex;
114 }
115
121 etl::span<MenuOption> getOptions() const
122 {
123 return options;
124 }
125
131 void setVisibleOptions(int count)
132 {
133 visibleOptions = count;
134 }
135};
ViewState
Definition StateTypes.hpp:4
Orchestrates rendering text from a bitmap.
Runs a fixed-capacity set of concurrent UI animations.
ViewState(UIMenu::*)() MenuOptionFunc
Definition UIMenu.hpp:13
constexpr MenuOptionFunc menuBind(Method method)
Definition UIMenu.hpp:15
Owns and ticks active UI animations. Safe against cancel-during-tick.
void animateSelection()
Definition UIMenu.cpp:41
etl::span< MenuOption > options
Definition UIMenu.hpp:28
etl::stack< MenuState, 5 > prevOptions
Definition UIMenu.hpp:47
int visibleOptions
Definition UIMenu.hpp:45
virtual void prevOption()
Changes the current options to the previous options.
Definition UIMenu.cpp:70
void setVisibleOptions(int count)
Sets the visible option count of a custom render menu, as UISystem only sets it for the menus it draw...
Definition UIMenu.hpp:131
int selectionOffset() const
Definition UIMenu.cpp:36
friend class UISystem
Definition UIMenu.hpp:41
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
const bool customRender
Definition UIMenu.hpp:46
int getSelectedOption() const
Gets the index of the selected option.
Definition UIMenu.hpp:101
int selectedOption
Definition UIMenu.hpp:29
ViewState nextViewState
Definition UIMenu.hpp:48
UIMenu(bool iCustomRender=false)
Construct a new UIMenu.
Definition UIMenu.hpp:77
etl::span< MenuOption > getOptions() const
Gets the options of the active menu.
Definition UIMenu.hpp:121
int startIndex
Definition UIMenu.hpp:30
int getStartIndex() const
Gets the index of the first visible option.
Definition UIMenu.hpp:111
virtual void closeHook()=0
Execute logic after the root menu is exited.
std::string pauseMessage
Definition UIMenu.hpp:23
int selectionX
Definition UIMenu.hpp:49